project BLF > class Session > method SwitchCompany
Description
Switch session to another company while staying logged in with the same name.
Parameters
icCompanyCode | input | character | Entity |
iiCompanyId | input | integer | Entity |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
QadFinancials
program code (program1/session.p)
if (icCompanyCode = "" or icCompanyCode = ?)
and (iiCompanyId = 0 or iiCompanyId = ?)
then do:
/* do not raise an error */
oiReturnStatus = 0.
return.
end.
if vcUserLogin = ""
then do:
find tDataItems where
tDataItems.tcName = "UserLogin" and
tDataItems.tcDataType = "c":U no-error.
if available tDataItems
then vcUserLogin = tDataItems.tcCharValue.
end.
<M-16 run GetIntegerValue
(input 'DomainID' (icName),
output viOldDomainId (oiValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
<Q-1 run CompanyByCodeActiveID (all) (Read) (NoCache)
(input iiCompanyId, (CompanyId)
input icCompanyCode, (CompanyCode)
input ?, (CompanyIsActive)
output dataset tqCompanyByCodeActiveID) in BCompany >
find first tqCompanyByCodeActiveID where
tqCompanyByCodeActiveID.tiCompany_ID = iiCompanyId or
tqCompanyByCodeActiveID.tcCompanyCode = icCompanyCode
no-error.
if not available tqCompanyByCodeActiveID
then do :
<M-2 run SetMessage
(input trim(substitute(#T-9'Unable to log in with this entity ID (&1) or entity code (&2).':255(412)t-9#,(if iiCompanyId = ? then '?':U else string(iiCompanyId)),(if icCompanyCode = ? then '?':U else icCompanyCode))) (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-412':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in Session>
assign oiReturnStatus = -1.
return.
end.
if tqCompanyByCodeActiveID.tlDomainIsActive <> true
then do:
assign vcMsg = trim(subst(#T-45'The entity you specified belongs to an inactive domain (&1).':255(6776)T-45#, tqCompanyByCodeActiveID.tcDomainCode)).
<M-97 run SetMessage
(input vcMsg (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'blf-656325':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in Session>
assign oiReturnStatus = -1.
return.
end.
/* Check if the user has access to the domain */
<Q-66 assign vlFcQueryRecordsAvailable = UsrDomainByDomainLogin (NoCache)
(input vcUserLogin, (UsrLogin)
input tqCompanyByCodeActiveID.tcDomainCode, (DomainCode)) in BUser>
if vlFcQueryRecordsAvailable = false
then do:
assign vcMsg = trim(subst(#T-77'You do not have access to this domain (&1).':255(6778)T-77#, tqCompanyByCodeActiveID.tcDomainCode)).
<M-20 run SetMessage
(input vcMsg (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'blf-940175':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in Session>
assign oiReturnStatus = -1.
return.
end.
/* Check if the user has access to the company */
<Q-18 assign vlFcQueryRecordsAvailable = UserCompanies (NoCache)
(input vcUserLogin, (UserLogin)
input tqCompanyByCodeActiveID.tiCompany_ID, (CyId)
input 0, (DomainId)) in BUser>
if vlFcQueryRecordsAvailable = false
then do:
<M-36 run SetMessage
(input trim(substitute(#T-71'You do not have permission to access this entity (&1).':255(3838843)T-71#, tqCompanyByCodeActiveID.tcCompanyCode )) (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'blf-581648':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in Session>
assign oiReturnStatus = -1.
return.
end.
<M-3 run SetIntegerValue
(input 'CompanyId':U (icName),
input tqCompanyByCodeActiveID.tiCompany_ID (iiValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
assign viCompanyId = tqCompanyByCodeActiveID.tiCompany_ID.
<M-4 run SetCharacterValue (input 'CompanyCode':U (icName),
input tqCompanyByCodeActiveID.tcCompanyCode (icValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
<M-10 run SetCharacterValue (input 'LocalisationCode':U (icName),
input tqCompanyByCodeActiveID.tcLocalisationCode (icValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
<M-11 run SetIntegerValue
(input 'DomainID':U (icName),
input tqCompanyByCodeActiveID.tiDomain_ID (iiValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
<M-12 run SetCharacterValue
(input 'DomainCode':U (icName),
input tqCompanyByCodeActiveID.tcDomainCode (icValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
<M-13 run SetCharacterValue
(input 'DomainLngCode':U (icName),
input (if tqCompanyByCodeActiveID.tlLngIsInstalled then tqCompanyByCodeActiveID.tcLngCode else '') (icValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
/* ================================================================= */
/* Stored shared sets linked to current company as session data */
/* ================================================================= */
<Q-5 run LookupSharedSetForCompany (all) (Read) (NoCache)
(input tqCompanyByCodeActiveID.tiCompany_ID, (CompanyId)
input '', (SharedSetType)
output dataset tqSharedSetForCompany) in BCompany >
for each tqSharedSetForCompany:
<M-6 run SetIntegerValue (input 'SharedSetFor':U + tqSharedSetForCompany.tcSharedSetTypeCode (icName),
input tqSharedSetForCompany.tiSharedSet_ID (iiValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
end.
/* getCurrentTimeZoneOffset function is available on mfgpro from version eB3 - SP7 */
if viMfgproMajor > 3
or (viMfgproMajor = 3 and viMfgproMinor > 6)
then
if viOldDomainId <> tqCompanyByCodeActiveID.tiDomain_ID
then do:
<I-88 {bFcStartAndOpenInstance
&CLASS = "PTimeZone"}>
<M-24 run getCurrentTimeZoneOffset
(input vcUserLogin (icUsrLogin),
input tqCompanyByCodeActiveID.tcDomainCode (icDomainCode),
input tqCompanyByCodeActiveID.tcDomainTimeZone (icTimeZoneCode),
output viTimeOffset (oiTimeOffset),
output viFcReturnSuper (oiReturnStatus)) in PTimeZone>
<I-90 {bFcCloseAndStopInstance
&CLASS = "PTimeZone"}>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
<M-14 run SetIntegerValue
(input 'TimeOffset' (icName),
input viTimeOffset (iiValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
end.
empty temp-table tqSharedSetForCompany.
empty temp-table tqCompanyByCodeActiveID.