project QadFinancials > class BPeriod > method LoadAndUpdateInstanceData
Description
LoadAndUpdateInstanceData; This method receives a dataset-handle witht he same structure as the class-dataset but the content is from a db-instance of the same class but belonging to another company.
The goal is to Load the similar object in the currenct company and to adapt most of the properties of the loaded object with the data of the input dataset-handle.
This method will act like a api-method meaning it will hold calsl to ValidateBC, AdditionalUpdates and DataSave.
NOTE: before the actual processing of the Multi-entity is started (and this method is executed), method MultiCompanyVerifications in this class should be called first.
Parameters
icActivityCode | input | character | ActivityCode: this shoudl be the current activity on this method |
ivBPeriod | input | dataset | InstanceDatasetHandle: dataset-handle with the same structure as the class-dataset but the content is from a db-instance of the same class but belonging to another company |
icUnmanagedData | input | character | UnmanagedData: optional parameter that allowes callers to pass in any data that is not covered in the class-dataset - not used by default |
ocUnmanagedData | output | character | UnmanagedData: optional parameter - not used by default |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFitnesse
program code (program7/bperiod.p)
/* ================================================================================================================ */
/* Method LoadAndUpdateInstanceData; */
/* This method receives a dataset (BPeriodS) holding the t_s-tables of the class-dataset. The content can be either */
/* of a db-instance of the same class but belonging to another company - either belonging to the current company. */
/* The goal is to Load the similar object in the currenct company and to adapt most of the properties of the */
/* loaded object with the data of the input dataset-handle. */
/* This method will act like a api-method meaning it will hold calls to ValidateBC, AdditionalUpdates and DataSave. */
/* Note: this method uses the new exception handling so add 'on error undo, throw' to the for-, do- ... statements */
/* ================================================================================================================ */
/*================== */
/* Start major block */
/*================== */
MAINLOADANDUPDATEBLOCK: Do on error undo, throw :
/* ================================================================================================= */
/* Assign the ActivityCode in this class when still empty and it was passed as input for this method */
/* ================================================================================================= */
if icActivityCode <> "":U and
icActivityCode <> ? and
(vcActivityCode = "":U or
vcActivityCode = ?)
then assign vcActivityCode = icActivityCode.
/* =========================================================================================================================== */
/* Perform some checks against the input data that is in parameter BPeriodS (note that this holds the t_s-tables of the class) */
/* =========================================================================================================================== */
Find t_sPeriod no-lock no-error. /* no first option added as we should have exact 1 record in here */
if not available t_sPeriod
then do :
assign vcMessage = trim(substitute(#T-41'Unable to find any instance in the input dataset passed to this method (&1)':255(266426511)T-41#,"LoadAndUpdateInstanceData":U))
oiReturnStatus = -3.
<M-30 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-450783':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
Leave MAINLOADANDUPDATEBLOCK.
end. /* if not available t_sPeriod */
/* =========================================================================================================================== */
/* Find the db-instance in the db that we need to load based upon the logical key-fields from the input and the current company */
/* Then Load that db-instance - of the current company - into the class as we are going to update it */
/* ============================================================================================================================ */
<Q-55 run PeriodPrim (first) (Read) (NoCache)
(input viCompanyID, (CompanyId)
input ?, (PeriodId)
input t_sPeriod.PeriodYear, (PeriodYear)
input t_sPeriod.PeriodPeriod, (PeriodPeriod)
output dataset tqPeriodPrim) in BPeriod>
Find tqPeriodPrim where
tqPeriodPrim.tiCompany_ID = viCompanyID and
tqPeriodPrim.tiPeriodYear = t_sPeriod.PeriodYear and
tqPeriodPrim.tiPeriodPeriod = t_sPeriod.PeriodPeriod
no-lock no-error. /* no first option added as we should have exact 1 record in here */
if not available tqPeriodPrim
then do :
assign vcMessage = trim(substitute(#T-31'The selected GL period &1 does not exist for entitiy &2':255(167330121)T-31#,string(t_sPeriod.PeriodYear) + "/":U + string(t_sPeriod.PeriodPeriod),vcCompanyCode))
oiReturnStatus = -3.
<M-96 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-561843':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
Leave MAINLOADANDUPDATEBLOCK.
end. /* if not available tqPeriodPrim */
<M-15 run DataLoad
(input '':U (icRowids),
input string(tqPeriodPrim.tiPeriod_ID) (icPkeys),
input '':U (icObjectIds),
input '':U (icFreeform),
input false (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave MAINLOADANDUPDATEBLOCK.
Find tPeriod where
tPeriod.Period_ID = tqPeriodPrim.tiPeriod_ID
no-lock no-error. /* no first option added as we should have exact 1 record in here */
if not available tPeriod
then do :
assign vcMessage = trim(substitute(#T-35'Unable to load the Period in the current entity (&1/&2) based upon its ID (&3). Logical unique key-fields: &4.':255(116041796)T-35#,vcCompanyCode,string(viCompanyID),string(tqPeriodPrim.tiPeriod_ID),string(t_sPeriod.PeriodYear) + "/":U + string(t_sPeriod.PeriodPeriod)))
oiReturnStatus = -3.
<M-92 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-232919':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
Leave MAINLOADANDUPDATEBLOCK.
end. /* if not available tPeriod */
/* ================================================================================= */
/* Some extra validations */
/* ================================================================================= */
/* When the user wants to LOCK a period, that is already closed, we don't need to do */
/* anything */
if vcActivityCode = "LockAccountingPeriod":U and
tPeriod.PeriodStatus = {&PERIODSTATUS-LOCKED}
then do:
assign vcMessage = #T-76'Period &1/&2 in the Entity &3 is already locked.':255(194722171)T-76#
vcMessage = substitute(vcMessage, tPeriod.PeriodYear, tPeriod.PeriodPeriod, vcCompanyCode).
<M-34 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-728205':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
if oiReturnStatus = 0 then assign oiReturnStatus = 1.
leave MAINLOADANDUPDATEBLOCK.
end.
/* ================================================================================= */
/* Update the loaded db-instance based upon the content of the input */
/* If the Company in the input is the same as the CurrentCompany (and the ID-field) */
/* then the loaded Period should completely get the values of the input */
/* else only some fields (depending on the activity) should be copied from the input */
/* ================================================================================= */
if icActivityCode = "LockAccountingPeriod":U or
icActivityCode = "ReportAccountingPeriod":U
then /* Do not assign tPeriod.tcPeriodMarkCode or tPeriod.PeriodMark_ID as they will be updated automatically by the program-code in ValidateComponent and AdditionalUpdates - and their submethods */
assign tPeriod.tc_Status = t_sPeriod.tc_Status
tPeriod.PeriodStatus = t_sPeriod.PeriodStatus
tPeriod.PeriodClosingDate = t_sPeriod.PeriodClosingDate
tPeriod.PeriodIsPostingPurchAllow = t_sPeriod.PeriodIsPostingPurchAllow
tPeriod.PeriodIsPostingGLAllowed = t_sPeriod.PeriodIsPostingGLAllowed
tPeriod.PeriodIsPostingSalesAllow = t_sPeriod.PeriodIsPostingSalesAllow
tPeriod.PeriodIsPostingOtherAllow = t_sPeriod.PeriodIsPostingOtherAllow
tPeriod.PeriodIsPostingInvAllowed = t_sPeriod.PeriodIsPostingInvAllowed
tPeriod.PeriodIsPostingPCAllowed = t_sPeriod.PeriodIsPostingPCAllowed.
else if icActivityCode = "LockJournalPeriod":U
then assign tPeriod.tc_Status = t_sPeriod.tc_Status
tPeriod.CMask_ID = t_sPeriod.CMask_ID
tPeriod.tcCMaskCode = t_sPeriod.tcCMaskCode.
/* ==================================================================================================================================== */
/* Empty the dataset BPeriodS holding the t_s-tables as we don't need it anymore and it is used by the methods called from here onwards */
/* ==================================================================================================================================== */
dataset BPeriodS:handle:empty-dataset().
/* ================================================================================================================ */
/* Call ValidateBC, AdditionalUpdates and DataSave to complete the normal flow and to make sure the data gets saved */
/* ================================================================================================================ */
<M-61 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave MAINLOADANDUPDATEBLOCK.
<M-54 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave MAINLOADANDUPDATEBLOCK.
<M-67 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave MAINLOADANDUPDATEBLOCK.
END. /* MAINLOADANDUPDATEBLOCK */
/* ================================================ */
/* Finally actions that should be done in ALL cases */
/* ================================================ */
FINALLY:
END FINALLY.