project QadFinancials > class BDInvoice > method AdditionalUpdatesAll
Description
This method holds all program-code and all calls to the major submethods of method AdditionalUpdates
Parameters
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program8/bdinvoice.p)
/* ==================================================================================================== */
/* This method holds all program-code and all calls to the major submethods of method AdditionalUpdates */
/* All submethods should be in the same segment (8) */
/* ==================================================================================================== */
/* ========================= */
/* Set default return status */
/* ========================= */
assign oiReturnStatus = -98
viMaxLength = 255.
empty temp-table tPostingPostingLineInfoDIJE.
/* ======================================================================================================== */
/* Legal document enhancement, in some reports, it need to show shipper info. */
/* Considering the performance, it will duplicate the shipper info into DInvoice by Alban request. */
/* ======================================================================================================== */
if can-find (first tDInvoiceOpInfo where tDInvoiceOpInfo.tc_Status = 'N':U)
then do:
for each tDInvoice where tDInvoice.tc_Status = 'N':U:
assign vlSkipSO = no
vlSkipShipper = no
vlSkipLD = no
vlSkipGT = no.
for each tDInvoiceOpInfo where tDInvoiceOpInfo.tc_ParentRowid = tDInvoice.tc_Rowid
and tDInvoiceOpInfo.tc_Status = 'N':U :
if not vlSkipSO and tDInvoiceOpInfo.DInvoiceOpInfoType = {&DINVOICEOPINFOTYPE-SO}
then do:
if tDInvoice.DInvoiceSalesOrderList = '':U or tDInvoice.DInvoiceSalesOrderList = ?
then do:
if length(tDInvoiceOpInfo.DInvoiceOpInfoCode,"CHARACTER":U) <= viMaxLength
then assign tDInvoice.DInvoiceSalesOrderList = tDInvoiceOpInfo.DInvoiceOpInfoCode.
else assign vlSkipSO = yes.
end. /* if tDInvoice.DInvoiceSalesOrderList = '':U or tDInvoice.DInvoiceSalesOrderList = ? */
else do:
if length(tDInvoice.DInvoiceSalesOrderList + ',':U + tDInvoiceOpInfo.DInvoiceOpInfoCode,"CHARACTER":U) <= viMaxLength
then assign tDInvoice.DInvoiceSalesOrderList = tDInvoice.DInvoiceSalesOrderList + ',':U + tDInvoiceOpInfo.DInvoiceOpInfoCode.
else assign vlSkipSO = yes.
end.
end. /* end if sales order */
else if not vlSkipShipper and tDInvoiceOpInfo.DInvoiceOpInfoType = {&DINVOICEOPINFOTYPE-SHIPPER}
then do:
if tDInvoice.DInvoiceShipperList = '':U or tDInvoice.DInvoiceShipperList = ?
then do:
if length(tDInvoiceOpInfo.DInvoiceOpInfoCode,"CHARACTER":U) <= viMaxLength
then assign tDInvoice.DInvoiceShipperList = tDInvoiceOpInfo.DInvoiceOpInfoCode.
else assign vlSkipShipper = yes.
end. /* if tDInvoice.DInvoiceShipperList = '':U or tDInvoice.DInvoiceShipperList = ? */
else do:
if length(tDInvoice.DInvoiceShipperList + ',':U + tDInvoiceOpInfo.DInvoiceOpInfoCode,"CHARACTER":U) <= viMaxLength
then assign tDInvoice.DInvoiceShipperList = tDInvoice.DInvoiceShipperList + ',':U + tDInvoiceOpInfo.DInvoiceOpInfoCode.
else assign vlSkipShipper = yes.
end.
end. /* end if shipper info */
else if not vlSkipLD and tDInvoiceOpInfo.DInvoiceOpInfoType = {&DINVOICEOPINFOTYPE-LEGALDOC}
then do:
if tDInvoice.DInvoiceLegalDocumentList = '':U or tDInvoice.DInvoiceLegalDocumentList = ?
then do:
if length(tDInvoiceOpInfo.DInvoiceOpInfoCode,"CHARACTER":U) <= viMaxLength
then assign tDInvoice.DInvoiceLegalDocumentList = tDInvoiceOpInfo.DInvoiceOpInfoCode.
else assign vlSkipLD = yes.
end. /* if tDInvoice.DInvoiceLegalDocumentList = '':U or tDInvoice.DInvoiceLegalDocumentList = ? */
else do:
if length(tDInvoice.DInvoiceLegalDocumentList + ',':U + tDInvoiceOpInfo.DInvoiceOpInfoCode,"CHARACTER":U) <= viMaxLength
then assign tDInvoice.DInvoiceLegalDocumentList = tDInvoice.DInvoiceLegalDocumentList + ',':U + tDInvoiceOpInfo.DInvoiceOpInfoCode.
else assign vlSkipLD = yes.
end.
end. /* end if legal doc info */
else if not vlSkipGT and tDInvoiceOpInfo.DInvoiceOpInfoType = {&DINVOICEOPINFOTYPE-GOLDENTAX}
then do:
if tDInvoice.DInvoiceGoldenTaxInvoiceList = '':U or tDInvoice.DInvoiceGoldenTaxInvoiceList = ?
then do:
if length(tDInvoiceOpInfo.DInvoiceOpInfoCode,"CHARACTER":U) <= viMaxLength
then assign tDInvoice.DInvoiceGoldenTaxInvoiceList = tDInvoiceOpInfo.DInvoiceOpInfoCode.
else assign vlSkipGT = yes.
end. /* if tDInvoice.DInvoiceGoldenTaxInvoiceList = '':U or tDInvoice.DInvoiceGoldenTaxInvoiceList = ? */
else do:
if length(tDInvoice.DInvoiceGoldenTaxInvoiceList + ',':U + tDInvoiceOpInfo.DInvoiceOpInfoCode,"CHARACTER":U) <= viMaxLength
then assign tDInvoice.DInvoiceGoldenTaxInvoiceList = tDInvoice.DInvoiceGoldenTaxInvoiceList + ',':U + tDInvoiceOpInfo.DInvoiceOpInfoCode.
else assign vlSkipGT = yes.
end.
end. /* end if golden tax info */
end. /* for each tDInvoiceOpInfo where tDInvoiceOpInfo.tc_ParentRowid = tDInvoice.tc_Rowid */
end. /* end for each tDInvoice where tDInvoice.tc_Status = 'N':U */
end. /* end if can-find (first tDInvoiceOpInfo */
/* ======================================================================================================== */
/* For some reason, there sometimes are tDInvoiceStage with status D allthough it shoudl not be like that */
/* We will look further into the cause of this but this code should already solve the problem */
/* ======================================================================================================== */
for each tDInvoiceStage where
tDInvoiceStage.tc_Status = "D":U :
if not can-find (t_iDInvoiceStage where
t_iDInvoiceStage.tc_Rowid = tDInvoiceStage.tc_Rowid)
then delete tDInvoiceStage.
end. /* for each tDInvoiceStage where */
/* ======================================================================================= */
/* Start/Open BJournalEntry: we do it here once so all submethods can access BJournalEntry */
/* viBJournalEntryDIID shoudl be filled in all cases before this method is executed */
/* ======================================================================================= */
if can-find (first tDInvoiceMovement where
tDInvoiceMovement.tc_Status <> "":U) OR
can-find (first tDInvoice where
tDInvoice.tc_Status = "N":U and
tDInvoice.LinkedDInvoice_ID <> 0 and
tDInvoice.LinkedDInvoice_ID <> ?) OR
can-find (first tDInvoiceOpInfo where
tDInvoiceOpInfo.DInvoiceOpInfoType <> {&DINVOICEOPINFOTYPE-GOLDENTAX} and
tDInvoiceOpInfo.tc_Status <> "":U and /* dll Mar/7/2008 defect 10249-0311 */
tDInvoiceOpInfo.tc_Status <> "D":U) or
(vlBJEIsStartedFromDI = true and
vlBJournalEntryOpenedInThisMeth = false)
then do :
if viBJournalEntryDIID = 0 or
viBJournalEntryDIID = ?
then do :
assign vcMessage = trim(#T-1'Internal error. The system cannot save an invoice when no posting instance is available.':250(17916)T-1#).
<M-3 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-4509':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
Return.
end. /* if viBJournalEntryDIID = 0 or */
<I-14 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
assign vlBJournalEntryOpenedInThisMeth = true.
end. /* if can-find */
/* ============================================================================= */
/* Start block // Errors in this block should result in a value for viBlockError */
/* ============================================================================= */
ADDUPDBLOCK: DO :
/* ====================================================================================== */
/* Call a submethod that will Change Bill Status */
/* ====================================================================================== */
<M-31 run AdditionalUpdatesAllBill (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
/* ====================================================================================== */
/* Call a submethod that will create CA if the linked-CI field in the invoices is filled */
/* ====================================================================================== */
<M-21 run AdditionalUpdatesAllCreateDA (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
/* ====================================================================================== */
/* Call a submethod that will perform some assignments and that calls the BJE.Validations */
/* run this after createDA because in this method, movements are updated, */
/* and in createda there are also movements created */
/* ====================================================================================== */
<M-18 run AdditionalUpdatesAllAssignments (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
/* ====================================================================================== */
/* Call a submethod that will update some fields in Debtor in some situations */
/* this method must be called after AdditionalUpdatesAllAssignments, because temp-table */
/* that is used in this method is created there */
/* ====================================================================================== */
<M-20 run AdditionalUpdatesAllDebtorUpdates
(output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
/* ====================================================================================== */
/* Call a submethod that will update DInvoiceOpInfo for golden tax only */
/* ====================================================================================== */
if vcActivityCode = "Modify":U
then do:
<M-25 run AdditionalUpdatesAllOpInfo (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
end. /* if vcActivityCode = "Modify":U */
/* ======================================================================== */
/* Check if the posting is in balance */
/* When you set the vlPostingMustBeBalanced on false, then you can create */
/* Posting lines in journal entry that are not in balance */
/* and before you write the date you can set it back to true */
/* and you have to call ValidateBC and AdditionalUpdates of journal entry */
/* ======================================================================== */
if viBJournalEntryDIID <> 0 and
viBJournalEntryDIID <> ? and
vlBJEIsStartedFromDI = true and
vlBJournalEntryOpenedInThisMeth = true
then do:
<M-7 run SetPublicData (input 'vlPostingMustBeBalanced':U (icDataList),
input 'true':U (icValueList),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
assign vcMessage = trim(substitute(#T-4'Internal error. The system was unable to set property &1 in the journal entry component.':150(906575812)T-4#, "vlPostingMustBeBalanced":U)).
<M-10 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-4510':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
end. /* if viFcReturnSuper < 0 */
<M-9 run ValidateBCAndAdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
assign vcMessage = trim(substitute(#T-5'Error &1 occurred when validating the journal entry.':150(376)T-5#, string(viFcReturnSuper))).
<M-11 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-4511':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
<M-8 run SetPublicData (input 'vlPostingMustBeBalanced':U (icDataList),
input 'false':U (icValueList),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
Leave ADDUPDBLOCK.
end. /* if viFcReturnSuper < 0 */
end. /* if viBJournalEntryDIID <> 0 and */
/* ====================================================================================== */
/* Call a submethod that will perform some assignments and that calls the BJE.Validations */
/* ====================================================================================== */
<M-22 run AdditionalUpdatesAllQDInvoiceMovement (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
END. /* ADDUPDBLOCK */
/* ======================================================= */
/* Close BJournalEntry */
/* Stop in case of errors in the previous block */
/* Note: StopExternalInstances is run in AdditionalUpdates */
/* ======================================================= */
if vlBJournalEntryOpenedInThisMeth = true
then. /* ========================================================================================================= */
/* Normally we would here close BJournalEntry we will not do it for performance */
/* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it. */
/* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the */
/* appserver that is executed after each call to the appserver */
/* ========================================================================================================= */
if viBlockError <> 0
then assign oiReturnStatus = viBlockError.
if viBlockError < 0
then Return.
/* ========================= */
/* Set default return status */
/* ========================= */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.