Description
AdditonalUpdatesDelete; Submethod of AdditionalUpdates
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bqbudgetactual.p)
/* ================================================================ */
/* Set Return-status = Default-error */
/* ================================================================ */
assign oiReturnStatus = -98.
/* ======================================================================= */
/* ToDo: */
/* For every tQBudgetLinkCommit (temporarely records) that gets deleted, */
/* a BudgetLinkActual record will be created and a related QBudgetLink */
/* record will be updated. These BudgetLinkActual records are the */
/* permanent link between the posting-line and the budget (via BudgetLink) */
/* Call an instance-less method on BBudget that returns the involved nodes */
/* ======================================================================= */
/* ===================== */
/* Empty the temp-tables */
/* ===================== */
empty temp-table tBudgetCheckInfoQBA.
empty temp-table tBudgetCheckInfoWBSQBA.
empty temp-table tNewBudgetLinkActualFromBQ.
empty temp-table tNewQBudgetLinkActual.
empty temp-table tApiBudgetLinkAccFromBQ.
empty temp-table tApiBudgetLinkAccDetFromBQ.
/* ======================================= */
/* Start queries when needed */
/* ======================================= */
if can-find (first tQBudgetLinkActual where
tQBudgetLinkActual.BudgetLinkActualSafStruct <> ? and
tQBudgetLinkActual.BudgetLinkActualSafStruct <> "":U)
then do :
<Q-7 run SafConceptCodeByLine (Start) in BSafStructure >
end. /* if can-find (first tQBudgetLinkActual where */
/* ======================================= */
/* Go through all deleted instance records */
/* ======================================= */
for each tQBudgetLinkActual where
tQBudgetLinkActual.tc_Status = "D":U no-lock :
create tBudgetCheckInfoQBA.
assign viBudgetCheckInfoIDCounter = viBudgetCheckInfoIDCounter + 1
tBudgetCheckInfoQBA.tiBudgetCheckInfoID = viBudgetCheckInfoIDCounter
tBudgetCheckInfoQBA.tcParentTcRowid = string(rowid(tQBudgetLinkActual))
tBudgetCheckInfoQBA.tiCompanyId = tQBudgetLinkActual.Company_ID
tBudgetCheckInfoQBA.tcCallerReference = tQBudgetLinkActual.BudgetLinkActualInfo
tBudgetCheckInfoQBA.tiBudgetID = tQBudgetLinkActual.Budget_ID
tBudgetCheckInfoQBA.tiBudgetWBSID = tQBudgetLinkActual.BudgetWBS_ID
tBudgetCheckInfoQBA.ttDate = tQBudgetLinkActual.BudgetLinkActualDate
tBudgetCheckInfoQBA.tiCurrencyID = tQBudgetLinkActual.Currency_ID
tBudgetCheckInfoQBA.tiUnitID = tQBudgetLinkActual.Unit_ID
tBudgetCheckInfoQBA.tcDivisionCode = tQBudgetLinkActual.BudgetLinkActualDivCode
tBudgetCheckInfoQBA.tcGLCode = tQBudgetLinkActual.BudgetLinkActualGLCode
tBudgetCheckInfoQBA.tiGLID = 0
tBudgetCheckInfoQBA.tlGLIsWithBudget = true
tBudgetCheckInfoQBA.tiJournalID = tQBudgetLinkActual.Journal_ID
tBudgetCheckInfoQBA.tcCostCentreCode = tQBudgetLinkActual.BudgetLinkActualCCCode
tBudgetCheckInfoQBA.tiCostCentreID = 0
tBudgetCheckInfoQBA.tcProjectCode = tQBudgetLinkActual.BudgetLinkActualPrjCode
tBudgetCheckInfoQBA.tiProjectID = 0
tBudgetCheckInfoQBA.tdAmountTC = tQBudgetLinkActual.BudgetLinkActualTC
tBudgetCheckInfoQBA.tdQTY = tQBudgetLinkActual.BudgetLinkActualQTY
tBudgetCheckInfoQBA.tcSafStructureCode = tQBudgetLinkActual.BudgetLinkActualSafStruct
tBudgetCheckInfoQBA.tcSafConcept1Code = tQBudgetLinkActual.BudgetLinkActualSaf1Concpt
tBudgetCheckInfoQBA.tcSafConcept2Code = tQBudgetLinkActual.BudgetLinkActualSaf2Concpt
tBudgetCheckInfoQBA.tcSafConcept3Code = tQBudgetLinkActual.BudgetLinkActualSaf3Concpt
tBudgetCheckInfoQBA.tcSafConcept4Code = tQBudgetLinkActual.BudgetLinkActualSaf4Concpt
tBudgetCheckInfoQBA.tcSafConcept5Code = tQBudgetLinkActual.BudgetLinkActualSaf5Concpt
tBudgetCheckInfoQBA.tcSaf1Code = tQBudgetLinkActual.BudgetLinkActualSaf1Code
tBudgetCheckInfoQBA.tcSaf2Code = tQBudgetLinkActual.BudgetLinkActualSaf2Code
tBudgetCheckInfoQBA.tcSaf3Code = tQBudgetLinkActual.BudgetLinkActualSaf3Code
tBudgetCheckInfoQBA.tcSaf4Code = tQBudgetLinkActual.BudgetLinkActualSaf4Code
tBudgetCheckInfoQBA.tcSaf5Code = tQBudgetLinkActual.BudgetLinkActualSaf5Code.
/* ================================================ */
/* Resolve the SafStructureID and the SafConceptIDs */
/* ================================================ */
if tBudgetCheckInfoQBA.tcSafStructureCode <> ? and
tBudgetCheckInfoQBA.tcSafStructureCode <> "":U
then SAFRESOLVINGBLOCK : do :
<Q-4 run SafConceptCodeByLine (all) (Read) (Cache)
(input ?, (SafStructure_ID)
input ?, (SafStructureLineNumber)
input tBudgetCheckInfoQBA.tcSafStructureCode, (SafStructureCode)
output dataset tqSafConceptCodeByLine) in BSafStructure >
find first tqSafConceptCodeByLine no-lock no-error.
if not available tqSafConceptCodeByLine
then do :
assign vhFcComponent = ?
vcMessage = trim(substitute(#T-25'The system cannot find the ID based on the SAF structure code (&1).':200(3452)t-25#,trim(tBudgetCheckInfoQBA.tcSafStructureCode))).
<M-5 run CreateCorruption
(input 'QBudgetLinkActual':U (icTableName),
input string(tQBudgetLinkActual.QBudgetLinkActual_ID) (icKey),
input vcMessage (icDescription),
input ? (ilSkipMessage),
output viFcReturnSuper (oiReturnStatus)) in BCorrLog>
<M-6 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tQBudgetLinkActual.BudgetLinkActualSafStruct':U (icFieldName),
input tQBudgetLinkActual.BudgetLinkActualSafStruct (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tQBudgetLinkActual.tc_Rowid (icRowid),
input 'QADFIN-1809':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BQBudgetActual>
assign viLocalReturnStatus = -3.
Leave SAFRESOLVINGBLOCK.
end. /* if not available tqSafConceptCodeByLine */
assign tBudgetCheckInfoQBA.tiSafStructureID = tqSafConceptCodeByLine.tiSafStructure_ID.
if tBudgetCheckInfoQBA.tcSafConcept1Code <> ? and
tBudgetCheckInfoQBA.tcSafConcept1Code <> "":U
then do :
find first tqSafConceptCodeByLine where
tqSafConceptCodeByLine.tiSafStructureLineNumber = 1
no-lock no-error.
if not available tqSafConceptCodeByLine
then do :
assign vhFcComponent = ?
vcMessage = trim(substitute(#T-26'SAF concept &1 (&2) was expected, but was not found in the SAF structure (&3).':200(3453)T-26#,trim(string(1)),trim(tBudgetCheckInfoQBA.tcSafConcept1Code),trim(tBudgetCheckInfoQBA.tcSafStructureCode))).
<M-9 run CreateCorruption
(input 'QBudgetLinkActual':U (icTableName),
input string(tQBudgetLinkActual.QBudgetLinkActual_ID) (icKey),
input vcMessage (icDescription),
input ? (ilSkipMessage),
output viFcReturnSuper (oiReturnStatus)) in BCorrLog>
<M-10 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tQBudgetLinkActual.BudgetLinkActualSafStruct':U (icFieldName),
input tQBudgetLinkActual.BudgetLinkActualSafStruct (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tQBudgetLinkActual.tc_Rowid (icRowid),
input 'QADFIN-1808':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BQBudgetActual>
assign viLocalReturnStatus = -3.
Leave SAFRESOLVINGBLOCK.
end. /* if not available tqSafConceptCodeByLine */
assign tBudgetCheckInfoQBA.tiSafConcept1ID = tqSafConceptCodeByLine.tiSafConcept_ID.
end. /* if tBudgetCheckInfoQBA.tcSafConcept1Code <> ? and */
if tBudgetCheckInfoQBA.tcSafConcept2Code <> ? and
tBudgetCheckInfoQBA.tcSafConcept2Code <> "":U
then do :
find first tqSafConceptCodeByLine where
tqSafConceptCodeByLine.tiSafStructureLineNumber = 2
no-lock no-error.
if not available tqSafConceptCodeByLine
then do :
assign vhFcComponent = ?
vcMessage = trim(substitute(#T-27'SAF concept &1 (&2) was expected, but was not found in the SAF structure (&3).':200(3453)T-27#,trim(string(2)),trim(tBudgetCheckInfoQBA.tcSafConcept2Code),trim(tBudgetCheckInfoQBA.tcSafStructureCode))).
<M-11 run CreateCorruption
(input 'QBudgetLinkActual':U (icTableName),
input string(tQBudgetLinkActual.QBudgetLinkActual_ID) (icKey),
input vcMessage (icDescription),
input ? (ilSkipMessage),
output viFcReturnSuper (oiReturnStatus)) in BCorrLog>
<M-12 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tQBudgetLinkActual.BudgetLinkActualSafStruct':U (icFieldName),
input tQBudgetLinkActual.BudgetLinkActualSafStruct (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tQBudgetLinkActual.tc_Rowid (icRowid),
input 'QADFIN-1810':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BQBudgetActual>
assign viLocalReturnStatus = -3.
Leave SAFRESOLVINGBLOCK.
end. /* if not available tqSafConceptCodeByLine */
assign tBudgetCheckInfoQBA.tiSafConcept2ID = tqSafConceptCodeByLine.tiSafConcept_ID.
end. /* if tBudgetCheckInfoQBA.tcSafConcept2Code <> ? and */
if tBudgetCheckInfoQBA.tcSafConcept3Code <> ? and
tBudgetCheckInfoQBA.tcSafConcept3Code <> "":U
then do :
find first tqSafConceptCodeByLine where
tqSafConceptCodeByLine.tiSafStructureLineNumber = 3
no-lock no-error.
if not available tqSafConceptCodeByLine
then do :
assign vhFcComponent = ?
vcMessage = trim(substitute(#T-28'SAF concept &1 (&2) was expected, but was not found in the SAF structure (&3).':200(3453)T-28#,trim(string(3)),trim(tBudgetCheckInfoQBA.tcSafConcept3Code),trim(tBudgetCheckInfoQBA.tcSafStructureCode))).
<M-13 run CreateCorruption
(input 'QBudgetLinkActual':U (icTableName),
input string(tQBudgetLinkActual.QBudgetLinkActual_ID) (icKey),
input vcMessage (icDescription),
input ? (ilSkipMessage),
output viFcReturnSuper (oiReturnStatus)) in BCorrLog>
<M-14 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tQBudgetLinkActual.BudgetLinkActualSafStruct':U (icFieldName),
input tQBudgetLinkActual.BudgetLinkActualSafStruct (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tQBudgetLinkActual.tc_Rowid (icRowid),
input 'QADFIN-1811':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BQBudgetActual>
assign viLocalReturnStatus = -3.
Leave SAFRESOLVINGBLOCK.
end. /* if not available tqSafConceptCodeByLine */
assign tBudgetCheckInfoQBA.tiSafConcept3ID = tqSafConceptCodeByLine.tiSafConcept_ID.
end. /* if tBudgetCheckInfoQBA.tcSafConcept3Code <> ? and */
if tBudgetCheckInfoQBA.tcSafConcept4Code <> ? and
tBudgetCheckInfoQBA.tcSafConcept4Code <> "":U
then do :
find first tqSafConceptCodeByLine where
tqSafConceptCodeByLine.tiSafStructureLineNumber = 4
no-lock no-error.
if not available tqSafConceptCodeByLine
then do :
assign vhFcComponent = ?
vcMessage = trim(substitute(#T-29'SAF concept &1 (&2) was expected, but was not found in the SAF structure (&3).':200(3453)T-29#,trim(string(4)),trim(tBudgetCheckInfoQBA.tcSafConcept4Code),trim(tBudgetCheckInfoQBA.tcSafStructureCode))).
<M-15 run CreateCorruption
(input 'QBudgetLinkActual':U (icTableName),
input string(tQBudgetLinkActual.QBudgetLinkActual_ID) (icKey),
input vcMessage (icDescription),
input ? (ilSkipMessage),
output viFcReturnSuper (oiReturnStatus)) in BCorrLog>
<M-16 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tQBudgetLinkActual.BudgetLinkActualSafStruct':U (icFieldName),
input tQBudgetLinkActual.BudgetLinkActualSafStruct (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tQBudgetLinkActual.tc_Rowid (icRowid),
input 'QADFIN-1812':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BQBudgetActual>
assign viLocalReturnStatus = -3.
Leave SAFRESOLVINGBLOCK.
end. /* if not available tqSafConceptCodeByLine */
assign tBudgetCheckInfoQBA.tiSafConcept4ID = tqSafConceptCodeByLine.tiSafConcept_ID.
end. /* if tBudgetCheckInfoQBA.tcSafConcept4Code <> ? and */
if tBudgetCheckInfoQBA.tcSafConcept5Code <> ? and
tBudgetCheckInfoQBA.tcSafConcept5Code <> "":U
then do :
find first tqSafConceptCodeByLine where
tqSafConceptCodeByLine.tiSafStructureLineNumber = 5
no-lock no-error.
if not available tqSafConceptCodeByLine
then do :
assign vhFcComponent = ?
vcMessage = trim(substitute(#T-30'SAF concept &1 (&2) was expected, but was not found in the SAF structure (&3).':200(3453)T-30#,trim(string(5)),trim(tBudgetCheckInfoQBA.tcSafConcept5Code),trim(tBudgetCheckInfoQBA.tcSafStructureCode))).
<M-17 run CreateCorruption
(input 'QBudgetLinkActual':U (icTableName),
input string(tQBudgetLinkActual.QBudgetLinkActual_ID) (icKey),
input vcMessage (icDescription),
input ? (ilSkipMessage),
output viFcReturnSuper (oiReturnStatus)) in BCorrLog>
<M-18 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input 'tQBudgetLinkActual.BudgetLinkActualSafStruct':U (icFieldName),
input tQBudgetLinkActual.BudgetLinkActualSafStruct (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tQBudgetLinkActual.tc_Rowid (icRowid),
input 'QADFIN-1813':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BQBudgetActual>
assign viLocalReturnStatus = -3.
Leave SAFRESOLVINGBLOCK.
end. /* if not available tqSafConceptCodeByLine */
assign tBudgetCheckInfoQBA.tiSafConcept5ID = tqSafConceptCodeByLine.tiSafConcept_ID.
end. /* if tBudgetCheckInfoQBA.tcSafConcept5Code <> ? and */
end. /* if tBudgetCheckInfoQBA.tcSafStructureCode <> ? and */
end. /* for each */
/* ======================================= */
/* Stop queries when needed */
/* ======================================= */
if can-find (first tQBudgetLinkActual where
tQBudgetLinkActual.BudgetLinkActualSafStruct <> ? and
tQBudgetLinkActual.BudgetLinkActualSafStruct <> "":U)
then do :
<Q-8 run SafConceptCodeByLine (Stop) in BSafStructure >
end. /* if can-find (first tQBudgetLinkActual where */
/* ================ */
/* Check for errors */
/* ================ */
if viLocalReturnStatus <> 0
then do :
assign oiReturnStatus = viLocalReturnStatus.
if oiReturnStatus < 0 then return.
end. /* if viLocalReturnStatus <> 0 */
/* ================================================================ */
/* Call an instance-less method in BBudget that will return a table */
/* with the BudgetWBS-nodes that match the deleted instance records */
/* Create tNewBudgetLinkActualFromBQ-records based on the output */
/* ================================================================ */
assign vhFcComponent = ?.
<M-1 run BudgetCheckInfoResolve (input tBudgetCheckInfoQBA (tBudgetCheckInfo),
input ? (ilOnlyHandleCommitOnlineBudgets),
input ? (ilOnlyHandleActualOnlineBudgets),
input false (ilCalledFromBudgetCheck),
output tBudgetCheckInfoWBSQBA (tBudgetCheckInfoWBS),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
if viFcReturnSuper <> 0
then do :
assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end. /* if viFcReturnSuper <> 0 */
/* ======================================================================== */
/* No further processing needed if these are no BudgetLinkActuals to update */
/* ======================================================================== */
if not can-find (first tBudgetCheckInfoWBSQBA)
then do :
assign oiReturnStatus = 0.
return.
end. /* if not can-find (first tBudgetCheckInfoWBSQBA) */
<M-24 run AdditonalUpdatesDeleteSub (output viFcReturnSuper (oiReturnStatus)) in BQBudgetActual>
if viFcReturnSuper <> 0
then do :
assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end. /* if viFcReturnSuper <> 0 */
/* ================================================================ */
/* Call a method in BBudgetLinkAcutal that will create new records */
/* ================================================================ */
if viBBudgetLinkActualBQBudActID = 0 or viBBudgetLinkActualBQBudActID = ?
then do:
<I-31 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BBudgetLinkActual"}>
end. /* if viBBudgetLinkActualBQBudActID = 0 or viBBudgetLinkActualBQBudActID = ? */
else do:
<I-32 {bFcOpenInstance
&CLASS = "BBudgetLinkActual"}>
end. /* not if viBBudgetLinkActualBQBudActID = 0 or viBBudgetLinkActualBQBudActID = ? */
<M-33 run ApiCreateBudgetLinkActual (input tNewBudgetLinkActualFromBQ (tNewBudgetLinkActual),
output viLocalReturnStatus (oiReturnStatus)) in BBudgetLinkActual>
<I-34 {bFcCloseInstance
&CLASS = "BBudgetLinkActual"}>
if viLocalReturnStatus <> 0
then do :
assign oiReturnStatus = viLocalReturnStatus.
if oiReturnStatus < 0 then return.
end. /* if viLocalReturnStatus <> 0 */
/* ================================================================ */
/* Call a method in BBudgetLinkAcc that will create new records */
/* ================================================================ */
if can-find(first tApiBudgetLinkAccFromBQ)
then do:
if viBBudgetLinkAcc7ID = 0 or viBBudgetLinkAcc7ID = ?
then do:
<I-35 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BBudgetLinkAcc"}>
end. /* if viBBudgetLinkAcc = 0 or viBBudgetLinkAcc = ? */
else do:
<I-36 {bFcOpenInstance
&CLASS = "BBudgetLinkAcc"}>
end. /* not if viBBudgetLinkAcc = 0 or viBBudgetLinkAcc = ? */
<M-37 run ApiCreateOrUpdateBudgetLinkAcc (input tApiBudgetLinkAccFromBQ (tApiBudgetLinkAcc),
output viLocalReturnStatus (oiReturnStatus)) in BBudgetLinkAcc>
<I-38 {bFcCloseInstance
&CLASS = "BBudgetLinkAcc"}>
if viLocalReturnStatus <> 0
then do :
assign oiReturnStatus = viLocalReturnStatus.
if oiReturnStatus < 0 then return.
end. /* if viLocalReturnStatus <> 0 */
end. /* if can-find(first tApiBudgetLinkAccFromBQ) */
/* ================================================================ */
/* Call a method in BBudgetLinkAccDet that will create new records */
/* ================================================================ */
if can-find(first tApiBudgetLinkAccDetFromBQ)
then do:
if viBBudgetLinkAccDet6ID = 0 or viBBudgetLinkAccDet6ID = ?
then do:
<I-39 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BBudgetLinkAccDet"}>
end. /* if viBBudgetLinkAccDet = 0 or viBBudgetLinkAccDet = ? */
else do:
<I-40 {bFcOpenInstance
&CLASS = "BBudgetLinkAccDet"}>
end. /* not if viBBudgetLinkAccDet = 0 or viBBudgetLinkAccDet = ? */
<M-43 run ApiCreateOrUpdateBudgetLinkAccDet (input tApiBudgetLinkAccDetFromBQ (tApiBudgetLinkAccDet),
output viLocalReturnStatus (oiReturnStatus)) in BBudgetLinkAccDet>
<I-42 {bFcCloseInstance
&CLASS = "BBudgetLinkAccDet"}>
if viLocalReturnStatus <> 0
then do :
assign oiReturnStatus = viLocalReturnStatus.
if oiReturnStatus < 0 then return.
end. /* if viLocalReturnStatus <> 0 */
end. /* if can-find(first tApiBudgetLinkAccDetFromBQ) */
/* ================================================================ */
/* Set Return-status = OK */
/* ================================================================ */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.