project QadFinancials > class BPosting > method AdditionalUpdatesBQBudgetActual
Description
AdditionalUpdatesBQBudgetActual; Extra method run in additional updates.
This will run an Api-method in BQBudgetActual to create the QBudgetLinkActual records that will be processed by the daemon to keep the actuals for budgets up-to-date..
Parameters
ilSysPropertyIsBudOLCheckGL | input | logical | |
ilSysPropertyIsBudOLCheckPrj | input | logical | |
ilSysPropertyIsBudOLCheckCC | input | logical | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program5/bposting.p)
/* ================================ */
/* Empty the temp-tables */
/* ================================ */
empty temp-table tNewQBudgetLinkAct.
empty temp-table tBudgetCheckInfoPosting.
/* ======================================================================== */
/* If there are only new lines for non-budget GLs then we can simply return */
/* ======================================================================== */
assign vlOnlyNewLinesForNonBudgetGLs = not can-find(first tPosting where
tPosting.tc_Status <> "N":U) and
not can-find(first tPostingLine where
tPostingLine.tc_Status <> "N":U).
if vlOnlyNewLinesForNonBudgetGLs = true
then do:
postinglines:
for each tPostingLine
break by tPostingLine.GL_ID:
if first-of(tPostingLine.GL_ID)
then do:
<Q-68 run GLByCodeIDIsWithBudget (all) (Read) (Cache)
(input tPostingLine.Company_ID, (CompanyId)
input ?, (GLCode)
input tPostingLine.GL_ID, (GLID)
input true, (GLIsWithBudget)
output dataset tqGLByCodeIDIsWithBudget) in BGL >
for first tqGLByCodeIDIsWithBudget
where tqGLByCodeIDIsWithBudget.tigl_id = tPostingLine.GL_ID:
assign vlOnlyNewLinesForNonBudgetGLs = false.
leave postinglines.
end. /* for first tqGLByCodeIDIsWithBudget */
end. /* if first-of(tPostingLine.GL_ID) */
end. /* end of for each */
end. /* if vlOnlyNewLinesForNonBudgetGLs */
/* No further actions are needed in case only new posting-lines are found and the GLs on these posting-lines are all disabled for Budgetting */
If vlOnlyNewLinesForNonBudgetGLs = true
Then return.
/* ======================= */
/* Go through all postings */
/* ======================= */
for each tPosting:
/* ================================================= */
/* Find the original posting */
/* ================================================= */
find t_iPosting where
t_iPosting.tc_Rowid = tPosting.tc_Rowid
no-error.
/* Check if header-information was modified. */
assign vlPostingChanged = tPosting.tc_Status = "C":U and
available t_iPosting and
(tPosting.Journal_ID <> t_iPosting.Journal_ID or
tPosting.PostingDate <> t_iPosting.PostingDate).
/* ================================================= */
/* Go through all lines of the posting */
/* ================================================= */
for each tPostingLine where
tPostingLine.tc_ParentRowid = tPosting.tc_Rowid:
/* ====================================================== */
/* Find the original posting-line */
/* ====================================================== */
find t_iPostingLine where
t_iPostingLine.tc_Rowid = tPostingLine.tc_Rowid
no-error.
/* ====================================================== */
/* Chech if the postingline uses a budget-enabled GL */
/* ====================================================== */
assign vlPostingIsWithBudget = false.
<Q-69 run GLByCodeIDIsWithBudget (all) (Read) (Cache)
(input tPostingLine.Company_ID, (CompanyId)
input ?, (GLCode)
input tPostingLine.GL_ID, (GLID)
input true, (GLIsWithBudget)
output dataset tqGLByCodeIDIsWithBudget) in BGL >
for first tqGLByCodeIDIsWithBudget
where tqGLByCodeIDIsWithBudget.tigl_id = tPostingLine.GL_ID:
assign vlPostingIsWithBudget = true.
end. /* for first tqGLByCodeIDIsWithBudget */
/* =========================================================== */
/* Chech if the original postingline uses a budget-enabled GL */
/* =========================================================== */
if available t_iPostingLine
then do :
if t_iPostingLine.GL_ID = tPostingLine.GL_ID and
t_iPostingLine.Company_ID = tPostingLine.Company_ID
then assign vlIPostingIsWithBudget = vlPostingIsWithBudget.
else do :
assign vlIPostingIsWithBudget = false.
<Q-71 run GLByCodeIDIsWithBudget (all) (Read) (Cache)
(input t_iPostingLine.Company_ID, (CompanyId)
input ?, (GLCode)
input t_iPostingLine.GL_ID, (GLID)
input true, (GLIsWithBudget)
output dataset tqGLByCodeIDIsWithBudget) in BGL >
for first tqGLByCodeIDIsWithBudget
where tqGLByCodeIDIsWithBudget.tigl_id = t_iPostingLine.GL_ID:
assign vlIPostingIsWithBudget = true.
end. /* for first tqGLByCodeIDIsWithBudget */
end. /* else if t_iPostingLine.GL_ID = tPostingLine.GL_ID and */
end. /* if available t_iPostingLine */
else assign vlIPostingIsWithBudget = false.
/* =========================================================== */
/* Create tApiQPostingLine for DELETED lines */
/* =========================================================== */
if tPosting.tc_Status = "D":U or
tPostingLine.tc_Status = "D":U
then do:
if not available t_iPosting or
not available t_iPostingLine or
not vlIPostingIsWithBudget
then next.
<M-2 run AdditionalUpdatesBQBudgetActualD
(input-output viQBudgetLinkActualIDCounter (biQBudgetLinkActualIDCounter),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
next.
end. /* if tPosting.tc_Status = "D":U or */
/* =========================================================== */
/* Create tApiQPostingLine for NEW lines */
/* =========================================================== */
/* Create tApiQPostingLine for NEW lines */
if tPosting.tc_Status <> "D":U and
tPostingLine.tc_Status = "N":U
then do:
if not vlPostingIsWithBudget
then next.
<M-4 run AdditionalUpdatesBQBudgetActualN
(input-output viQBudgetLinkActualIDCounter (biQBudgetLinkActualIDCounter),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
next.
end. /* if tPosting.tc_Status <> "D":U and */
/* =========================================================== */
/* Create tApiQPostingLine for MODIFIED lines */
/* =========================================================== */
if vlPostingChanged and
tPostingLine.tc_status <> "N":U or
tPosting.tc_Status <> "D":U and
(tPostingLine.tc_Status = "C":U or
tPostingLine.tc_Status = "":U and
can-find(first tPostingSaf where
tPostingSaf.tc_ParentRowid = tPostingLine.tc_Rowid and
tPostingSaf.tc_status <> "":U))
then do:
if not available t_iPosting or
not available t_iPostingLine or
not vlPostingIsWithBudget and
not vlIPostingIsWithBudget
then next.
<M-6 run AdditionalUpdatesBQBudgetActualC
(input-output viQBudgetLinkActualIDCounter (biQBudgetLinkActualIDCounter),
input vlPostingIsWithBudget (ilPostingIsWithBudget),
input vlIPostingIsWithBudget (ilIPostingIsWithBudget),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
next.
end. /* if vlPostingChanged and */
end. /* for each tPostingLine where */
end. /* for each tPosting: */
/* =============================== */
/* Return in case there is no data */
/* =============================== */
if not can-find (first tNewQBudgetLinkAct)
then return.
/* ===================================================================== */
/* State the layer-info based on the Journal_ID; Read sorted by Journal! */
/* Create the records for the budget-check */
/* Reset the fields in tNewQBudgetLinkAct that hold multiple data-fields */
/* ===================================================================== */
for each tNewQBudgetLinkAct:
/* Create records for Budget Check */
/* Only needed in case one of the OnLine checks is activated */
/* Skip records that only have impact on the sales figures */
if (ilSysPropertyIsBudOLCheckGL = true or
ilSysPropertyIsBudOLCheckPrj = true or
ilSysPropertyIsBudOLCheckCC = true) and
tNewQBudgetLinkAct.JournalTypeCode <> {&JOURNALTYPE-DEBTORINVOICE} and
tNewQBudgetLinkAct.JournalTypeCode <> {&JOURNALTYPE-DEBTORCREDITNOTE} and
tNewQBudgetLinkAct.JournalTypeCode <> {&JOURNALTYPE-DEBTORPAYMENT} and
tNewQBudgetLinkAct.JournalTypeCode <> {&JOURNALTYPE-STOCKRECEIPT} and
tNewQBudgetLinkAct.JournalTypeCode <> {&JOURNALTYPE-NONSTOCKRECEIPT}
then do:
create tBudgetCheckInfoPosting.
assign viCounter = viCounter + 1
tBudgetCheckInfoPosting.tiBudgetCheckInfoID = viCounter
tBudgetCheckInfoPosting.tiPostingLineID = tNewQBudgetLinkAct.PostingLine_ID
tBudgetCheckInfoPosting.tdAmountTC = tNewQBudgetLinkAct.BudgetLinkActualTC
tBudgetCheckInfoPosting.tdQTY = tNewQBudgetLinkAct.BudgetLinkActualQTY
tBudgetCheckInfoPosting.tiBudgetID = tNewQBudgetLinkAct.Budget_ID
tBudgetCheckInfoPosting.tiBudgetWBSID = tNewQBudgetLinkAct.BudgetWBS_ID
tBudgetCheckInfoPosting.tcCallerReference = tNewQBudgetLinkAct.BudgetLinkActualInfo
tBudgetCheckInfoPosting.tcCompanyCode = "":U
tBudgetCheckInfoPosting.tiCompanyId = tNewQBudgetLinkAct.Company_ID
tBudgetCheckInfoPosting.tcCostCentreCode = entry(1, tNewQBudgetLinkAct.BudgetLinkActualCCCode, chr(2))
tBudgetCheckInfoPosting.tcCurrencyCode = "":U
tBudgetCheckInfoPosting.tiCurrencyID = tNewQBudgetLinkAct.Currency_ID
tBudgetCheckInfoPosting.ttDate = tNewQBudgetLinkAct.BudgetLinkActualDate
tBudgetCheckInfoPosting.tcDivisionCode = tNewQBudgetLinkAct.BudgetLinkActualDivCode
tBudgetCheckInfoPosting.tcGLCode = entry(1, tNewQBudgetLinkAct.BudgetLinkActualGLCode, chr(2))
tBudgetCheckInfoPosting.tiJournalID = tNewQBudgetLinkAct.Journal_ID
tBudgetCheckInfoPosting.tcParentTcRowid = "":U
tBudgetCheckInfoPosting.tcProjectCode = entry(1, tNewQBudgetLinkAct.BudgetLinkActualPrjCode, chr(2))
tBudgetCheckInfoPosting.tcSaf1Code = tNewQBudgetLinkAct.BudgetLinkActualSaf1Code
tBudgetCheckInfoPosting.tcSaf2Code = tNewQBudgetLinkAct.BudgetLinkActualSaf2Code
tBudgetCheckInfoPosting.tcSaf3Code = tNewQBudgetLinkAct.BudgetLinkActualSaf3Code
tBudgetCheckInfoPosting.tcSaf4Code = tNewQBudgetLinkAct.BudgetLinkActualSaf4Code
tBudgetCheckInfoPosting.tcSaf5Code = tNewQBudgetLinkAct.BudgetLinkActualSaf5Code
tBudgetCheckInfoPosting.tcSafConcept1Code = tNewQBudgetLinkAct.BudgetLinkActualSaf1Concpt
tBudgetCheckInfoPosting.tcSafConcept2Code = tNewQBudgetLinkAct.BudgetLinkActualSaf2Concpt
tBudgetCheckInfoPosting.tcSafConcept3Code = tNewQBudgetLinkAct.BudgetLinkActualSaf3Concpt
tBudgetCheckInfoPosting.tcSafConcept4Code = tNewQBudgetLinkAct.BudgetLinkActualSaf4Concpt
tBudgetCheckInfoPosting.tcSafConcept5Code = tNewQBudgetLinkAct.BudgetLinkActualSaf5Concpt
tBudgetCheckInfoPosting.tcSafStructureCode = entry(1, tNewQBudgetLinkAct.BudgetLinkActualSafStruct, chr(2))
tBudgetCheckInfoPosting.tiSafConcept1ID = 0
tBudgetCheckInfoPosting.tiSafConcept2ID = 0
tBudgetCheckInfoPosting.tiSafConcept3ID = 0
tBudgetCheckInfoPosting.tiSafConcept4ID = 0
tBudgetCheckInfoPosting.tiSafConcept5ID = 0
tBudgetCheckInfoPosting.tcUnitCode = "":U
tBudgetCheckInfoPosting.tiUnitID = tNewQBudgetLinkAct.Unit_ID
tBudgetCheckInfoPosting.tiSafStructureID = if tNewQBudgetLinkAct.BudgetLinkActualSafStruct = "":U
then 0
else int(entry(2, tNewQBudgetLinkAct.BudgetLinkActualSafStruct, chr(2)))
tBudgetCheckInfoPosting.tiProjectID = if tNewQBudgetLinkAct.BudgetLinkActualPrjCode = "":U
then 0
else int(entry(2, tNewQBudgetLinkAct.BudgetLinkActualPrjCode, chr(2)))
tBudgetCheckInfoPosting.tiCostCentreID = if tNewQBudgetLinkAct.BudgetLinkActualCCCode = "":U
then 0
else int(entry(2, tNewQBudgetLinkAct.BudgetLinkActualCCCode, chr(2)))
tBudgetCheckInfoPosting.tiGLID = int(entry(2, tNewQBudgetLinkAct.BudgetLinkActualGLCode, chr(2)))
tBudgetCheckInfoPosting.tlGLIsWithBudget = true
no-error.
if error-status:error
then do:
assign vcMessage = trim(subst(#T-41'Internal error &1 has occurred when preparing the amounts for the budget check.':255(16478)t-41#,"00001":U))
oiReturnStatus = -3.
if error-status:num-messages > 0
then assign vcMessage = vcMessage + chr(10) +
trim(subst(#T-42'Detailed info: &1 (&2)':255(16477)T-42#, error-status:get-message(1), string(error-status:get-number(1)))).
<M-43 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-4002':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
return.
end. /* if error-status:error */
end. /* if tNewQBudgetLinkAct.JournalTypeCode <> {&JOURNALTYPE-DEBTORADJUSTMENT} and */
/* Reset the fields in tNewQBudgetLinkAct that hold multiple data-fields */
assign tNewQBudgetLinkAct.BudgetLinkActualSafStruct = entry(1, tNewQBudgetLinkAct.BudgetLinkActualSafStruct, chr(2))
tNewQBudgetLinkAct.BudgetLinkActualPrjCode = entry(1, tNewQBudgetLinkAct.BudgetLinkActualPrjCode, chr(2))
tNewQBudgetLinkAct.BudgetLinkActualCCCode = entry(1, tNewQBudgetLinkAct.BudgetLinkActualCCCode, chr(2))
tNewQBudgetLinkAct.BudgetLinkActualGLCode = entry(1, tNewQBudgetLinkAct.BudgetLinkActualGLCode, chr(2)).
end. /* for each tNewQBudgetLinkAct */
/* =============================== */
/* Perform a budget-check */
/* =============================== */
if can-find(first tBudgetCheckInfoPosting)
then do:
assign vhFcComponent = ?.
<M-35 run ApiCheckBudget (input-output tBudgetCheckInfoPosting (tBudgetCheckInfo),
input true (ilOnlyHandleActualOnlineBudgets),
input ? (ilOnlyHandleCommitOnlineBudgets),
input false (ilAutoAssignTableBudgetWBSID),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end. /* tBudgetCheckInfoPosting */
/* ====================================================================================================================== */
/* IMPORTANT NOTE: */
/* We will not go through the normal approach with Starting&Opening the external instance and then call a method in there */
/* as that decreases the performance too much. In stead, we stop here as we have the required tNewQBudgetLinkAct records */
/* and we will save them in BPosting:POSTSAVE using dynamic buffers as that will be much faster */
/* The program-code in here to call is kep in comments although it should never be executed anymore but we want to keep */
/* it like this so the 'Show Usage' still shows at least the correct calling class. */
/* SO: Please do note uncomment or remove this commented out program-code !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* ====================================================================================================================== */
/* COMMENTED-OUT - See comments Above
/* Update towards BQBudgetLinkActual */
if viBQBudgetActualPostingID = 0 or
viBQBudgetActualPostingID = ?
then do:
<I-7 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BQBudgetActual"}>
end.
else do:
<I-8 {bFcOpenInstance
&CLASS = "BQBudgetActual"}>
end.
<M-10 run ApiCreateQBudgetLinkActual (input tNewQBudgetLinkAct (tNewQBudgetLinkActual),
output viReturn (oiReturnStatus)) in BQBudgetActual>
<I-11 {bFcCloseInstance
&CLASS = "BQBudgetActual"}>
if viReturn < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viReturn.
if oiReturnStatus < 0
then return.
COMMENTED-OUT - See comments Above
*/