iiPeriodID | input | integer | ID of the Period that is currently on the screen |
icCompanyGroupCode | input | character | CompanyGroupCode: CompanyGroup that is specified on the UI |
icActivityCode | input | character | ActivityCode: this should be the current activity on this method |
ocErrorWarningString | output | character | ErrorWarningString: This parameter will hold the error-message or the warnign-message is applicable. To distinguish a warning from an error you can use the return-status |
oiReturnStatus | output | integer | Return status of the method. |
define buffer bSharedSet for SharedSet. /* =================================================================================================================================== */ /* MultiCompanyVerifications; */ /* This method should be called from the UI as the first action when save is pressed but only in case the MutliEntity field is filled. */ /* - When an error is returned the save-action should be aborted. */ /* - When a warning is returned the user shoudl have the option to either complete the save-process, either stop the save-process. */ /* =================================================================================================================================== */ /* Notes: */ /* - This method should be called before the actual processing in the different entities is started (by calling BMultiCyProcessor) */ /* - As the processing in BMultiCyProcessor is done in different transactions, this method returns the warning- or error-msg as an */ /* output parameter because it makes no sense to raise a warning after the trransaction has been commited */ /* =================================================================================================================================== */ /*================== */ /* Start major block */ /*================== */ MAINVERIFICATIONEBLOCK: Do on error undo, throw : /* ================================================================================================= */ /* Raise an error in these cases: */ /* - PeriodID is not filled or is not in the db or is not in the current company */ /* - CompanyGroupCode is not filled or invalid */ /* - The current-company does not belong to the CompanyGroup */ /* ================================================================================================= */ if iiPeriodID = 0 or iiPeriodID = ? then assign oiReturnStatus = -1 ocErrorWarningString = trim(substitute(#T-95'Internal error: parameter &1 is mandatory for method &2 but was not provided.':255(797059068)T-95#,"iiPeriodID":U,"BPeriod.MultiCompanyVerifications":U)). if oiReturnStatus < 0 then Leave MAINVERIFICATIONEBLOCK. <Q-24 run PeriodByYearPeriod (all) (Read) (NoCache) (input ?, (CompanyId) input ?, (PeriodYear) input ?, (PeriodPeriod) input iiPeriodID, (PeriodId) output dataset tqPeriodByYearPeriod) in BPeriod> find tqPeriodByYearPeriod where tqPeriodByYearPeriod.tiPeriod_ID = iiPeriodID no-lock no-error. if not available tqPeriodByYearPeriod then assign oiReturnStatus = -1 ocErrorWarningString = trim(substitute(#T-17'Internal error: Unable to find the period based upon its ID (&1).':255(622600841)T-17#,string(iiPeriodID))) + chr(10) + trim(substitute(#T-34'Method: &1':255(809651004)T-34#,"BPeriod.MultiCompanyVerifications":U)). if oiReturnStatus < 0 then Leave MAINVERIFICATIONEBLOCK. if tqPeriodByYearPeriod.tiCompany_ID <> viCompanyID then assign oiReturnStatus = -1 ocErrorWarningString = trim(substitute(#T-49'Internal error: The entity of the period (&1) differs from the current-entity (&2).':255(975573360)T-49#,string(tqPeriodByYearPeriod.tiPeriodYear) + "/":U + string(tqPeriodByYearPeriod.tiPeriodPeriod),vcCompanyCode)) + chr(10) + trim(substitute(#T-23'Method: &1':255(809651004)T-23#,"BPeriod.MultiCompanyVerifications":U)). if oiReturnStatus < 0 then Leave MAINVERIFICATIONEBLOCK. if icCompanyGroupCode = "":U or icCompanyGroupCode = ? then assign oiReturnStatus = -1 ocErrorWarningString = trim(substitute(#T-81'Internal error: parameter &1 is mandatory for method &2 but was not provided.':255(797059068)T-81#,"icCompanyGroupCode":U,"BPeriod.MultiCompanyVerifications":U)). if oiReturnStatus < 0 then Leave MAINVERIFICATIONEBLOCK. <Q-13 run CyGroupCompanyByGrpCy (all) (Read) (NoCache) (input ?, (CompanyId) input ?, (GroupID) input icCompanyGroupCode, (GroupCode) output dataset tqCyGroupCompanyByGrpCy) in BCompanyGroup> if not can-find (tqCyGroupCompanyByGrpCy where tqCyGroupCompanyByGrpCy.tcCyGroupCode = icCompanyGroupCode and tqCyGroupCompanyByGrpCy.tiCompany_ID = viCompanyID) then assign oiReturnStatus = -1 ocErrorWarningString = trim(substitute(#T-73'The current entity (&1) should belong to the specified entity-group (&2).':255(490312612)T-73#,vcCompanyCode,icCompanyGroupCode)) + chr(10) + trim(substitute(#T-64'Method: &1':255(809651004)T-64#,"BPeriod.MultiCompanyVerifications":U)). if oiReturnStatus < 0 then Leave MAINVERIFICATIONEBLOCK. /* ================================================================================================= */ /* Raise a warning in these cases: */ /* - The main properties of the similar periods in the companies of the CompanyGroup differ */ /* ================================================================================================= */ if oiReturnStatus >= 0 and (ocErrorWarningString = "":U or ocErrorWarningString = ?) then do : assign ocErrorWarningString = "":U viWarningCounter = 0. for each tqCyGroupCompanyByGrpCy where tqCyGroupCompanyByGrpCy.tcCyGroupCode = icCompanyGroupCode and tqCyGroupCompanyByGrpCy.tiCompany_ID <> viCompanyID no-lock : <Q-31 run PeriodForStartEndDateYearPd (all) (Read) (NoCache) (input tqCyGroupCompanyByGrpCy.tiCompany_ID, (CompanyId) input tqPeriodByYearPeriod.tiPeriodYear, (PeriodYear) input tqPeriodByYearPeriod.tiPeriodPeriod, (PeriodPeriod) output dataset tqPeriodForStartEndDateYearPd) in BPeriod> Find first tqPeriodForStartEndDateYearPd where tqPeriodForStartEndDateYearPd.tiCompany_ID = tqCyGroupCompanyByGrpCy.tiCompany_ID and tqPeriodForStartEndDateYearPd.tiPeriodYear = tqPeriodByYearPeriod.tiPeriodYear and tqPeriodForStartEndDateYearPd.tiPeriodPeriod = tqPeriodByYearPeriod.tiPeriodPeriod and (tqPeriodForStartEndDateYearPd.ttPeriodStartDate <> tqPeriodByYearPeriod.ttPeriodStartDate or tqPeriodForStartEndDateYearPd.ttPeriodEndDate <> tqPeriodByYearPeriod.ttPeriodEndDate ) no-lock no-error. if available tqPeriodForStartEndDateYearPd then do : assign oiReturnStatus = +1 viWarningCounter = viWarningCounter + 1. if viWarningCounter < 4 /* This viWarningCounter is to limit the size of the warning in case there are many companies with this issue */ then ocErrorWarningString = ocErrorWarningString + chr(10) + trim(substitute(#T-74'The period in entity &1 is defined with start-date &2 and end-date &3.':255(434590287)T-74#,tqPeriodForStartEndDateYearPd.tcCompanyCode,tqPeriodForStartEndDateYearPd.ttPeriodStartDate,tqPeriodForStartEndDateYearPd.ttPeriodEndDate)). else if viWarningCounter = 4 /* This viWarningCounter is to limit the size of the warning in case there are many companies with this issue */ then ocErrorWarningString = ocErrorWarningString + chr(10) + trim(substitute(#T-30'More entities having the same issue.':255(690016344)T-30#)). else leave. end. /* if available tqPeriodForStartEndDateYearPd */ end. /* for each tqCyGroupCompanyByGrpCy where */ if ocErrorWarningString <> "":U then assign ocErrorWarningString = trim(substitute(#T-89'The start and end dates of the period are different in some entities for the selected entity group.':255(226807066)T-89#)) + chr(10) + trim(substitute(#T-75'Period &1 in the current entity is defined with start-date &2 and end-date &3.':255(500947615)T-75#,string(tqPeriodByYearPeriod.tiPeriodYear) + "/":U + string(tqPeriodByYearPeriod.tiPeriodPeriod),tqPeriodByYearPeriod.ttPeriodStartDate,tqPeriodByYearPeriod.ttPeriodEndDate)) + chr(10) + ocErrorWarningString + chr(10) + chr(10) + trim(substitute(#T-79'Do you want to continue?':255(598860433)T-79#)). end. /* if oiReturnStatus >= 0 */ /* ================================================================================================= */ /* Raise an error if the user is trying to assign Daybook mask to a entity/period, that has */ /* Dayook shared set then the Daybook mask */ /* ================================================================================================= */ if oiReturnStatus >= 0 and icActivityCode = "LockJournalPeriod":U then do: /* Get the closing mask shared set. It is the same as Daybook shared set */ assign vhFcComponent = vhCacher. <M-55 run GetIntegerValueFromSession (input viSessionID (iiSessionId), input 'SharedSetForJournal':U (icDataItemName), output viSharedSetJournalId (oiValue), output viFcReturnSuper (oiReturnStatus)) in Cacher> /* Go through all entities of the entity group and check, if they have the same journal shared set as current entity */ for each tqCyGroupCompanyByGrpCy where tqCyGroupCompanyByGrpCy.tcCyGroupCode = icCompanyGroupCode on error undo, throw: for each bSharedSet fields (SharedSetTypeCode SharedSet_ID) no-lock where bSharedSet.SharedSet_ID <> viSharedSetJournalId and bSharedSet.SharedSetTypeCode = {&SHAREDSETTYPE-JOURNAL} on error undo, throw: if can-find (first CompanySharedSet where CompanySharedSet.SharedSet_ID = bSharedSet.SharedSet_ID and CompanySharedSet.Company_ID = tqCyGroupCompanyByGrpCy.tiCompany_ID) then do: assign vcMessage = #T-61'Entity group &1 contains entities with different daybook shared set. Closing of the daybook(s) in the entity group cannot be done.':255(533140834)T-61# vcMessage = substitute(vcMessage, icCompanyGroupCode) ocErrorWarningString = substitute("&1&2&3", ocErrorWarningString, if ocErrorWarningString = "":U then "":U else chr(10), vcMessage) oiReturnStatus = -1. leave. end. /* can-find */ end. /* for each bSharedSet */ end. /* for each tqCyGroupCompanyByGrpCy where */ end. /* if oiReturnStatus >= 0 and */ END. /* MAINVERIFICATIONEBLOCK */ /* ================================================ */ /* Finally actions that should be done in ALL cases */ /* ================================================ */ FINALLY: END FINALLY.