project QadFinancials > class BDDocument > method AdditionalUpdates

Description

This empty method allows to do additional updates on class temp-tables after records were received (and validated) from outside, using method SetPublicTables.
You can start instances of other business classes to do those updates.


Parameters


oiReturnStatusoutputinteger


Internal usage


QadFinancials
method BDDocument.ApiSetDDocumentStatusChange
method BDDocument.ValidateBCAndAdditionalUpdates


program code (program/bddocument.p)

DDOCUMENTBLOCK:
do:
    for each tDDocument where
             tDDocument.tc_Status <> "D":U:
        /* Get initial values */
        if tDDocument.tc_Status <> "N":U
        then do:
            find t_iDDocument where
                 t_iDDocument.tc_Rowid = tDDocument.tc_Rowid
                 no-error.
    
            if not available t_iDDocument
            then do:
                <M-9 run SetMessage
                   (input  trim(#T-20'Initial values not found for customer payment with row ID $1.':250(1653)T-20#) (icMessage), 
                    input  tDDocument.tc_Rowid (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QADFIN-2595':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    
                assign oiReturnStatus = -1.
                leave DDOCUMENTBLOCK.
            end.
        end.

        /* All linked invoices/credit notes must have the same currency code as the document */
        if can-find (first tDDocumentInvoiceXref where
                           tDDocumentInvoiceXref.tc_ParentRowid  = tDDocument.tc_Rowid and
                           tDDocument.tc_Status                 <> "D":U               and
                           tDDocumentInvoiceXref.DInvoice_ID    <> 0                   and
                           tDDocumentInvoiceXref.DInvoice_ID    <> ?                   and
                           tDDocumentInvoiceXref.tcCurrencyCode <> tDDocument.tcCurrencyCode)
        then do:
             assign vcMessage = trim(#T-56'All linked invoices and credit notes must have the same currency as the document itself.':250(999890153)T-56#).
             <M-19 run SetMessage
                (input  vcMessage (icMessage), 
                 input  '':U (icArguments), 
                 input  'tDDocument.tcCurrencyCode':U (icFieldName), 
                 input  tDDocument.tcCurrencyCode (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  tDDocument.tc_Rowid (icRowid), 
                 input  'QADFIN-2924':U (icFcMsgNumber), 
                 input  '' (icFcExplanation), 
                 input  '' (icFcIdentification), 
                 input  '' (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    
            assign oiReturnStatus = -1.
            leave DDOCUMENTBLOCK.
        end.
    
        /* Some extra validations for modified records that have invoices linked AND already had invoices linked */
        if tDDocument.tc_Status = "C":U and
           can-find(first tDDocumentInvoiceXref where
                          tDDocumentInvoiceXref.tc_ParentRowid = tDDocument.tc_Rowid and
                          tDDocumentInvoiceXref.tc_Status     <> "D":U) and
           can-find(first t_iDDocumentInvoiceXref where
                          t_iDDocumentInvoiceXref.tc_ParentRowid = tDDocument.tc_Rowid)
        then do:
            /* Amount cannot be changed anymore */
            if t_iDDocument.DDocumentOriginalDebitTC <> tDDocument.DDocumentOriginalDebitTC
            then do:
                <M-10 run SetMessage
                   (input  trim(#T-22'Once invoices are linked, you cannot change the amount.':250(892)T-22#) (icMessage), 
                    input  '':U (icArguments), 
                    input  'tDDocument.DDocumentOriginalDebitTC':U (icFieldName), 
                    input  string(tDDocument.DDocumentOriginalDebitTC) (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tDDocument.tc_Rowid (icRowid), 
                    input  'QADFIN-2590':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    
                assign oiReturnStatus = -1.
                leave DDOCUMENTBLOCK.
            end.
    
            /* Currency code cannot be changed anymore */
            if t_iDDocument.tcCurrencyCode <> tDDocument.tcCurrencyCode
            then do:
                <M-11 run SetMessage
                   (input  trim(#T-23'You cannot change the currency code after invoices are linked.':250(893)T-23#) (icMessage), 
                    input  '':U (icArguments), 
                    input  'tDDocument.tcCurrencyCode':U (icFieldName), 
                    input  tDDocument.tcCurrencyCode (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tDDocument.tc_Rowid (icRowid), 
                    input  'QADFIN-2591':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    
                assign oiReturnStatus = -1.
                leave DDOCUMENTBLOCK.
            end.
        end.
    
        /* If Document Is Saved in Initial status, all allocations are automatically removed */
        /* Fin-2043 shx */
        if (tDDocument.tc_Status <> 'N':U and t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-INIT}
                                          and tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-INIT}) or
           (tDDocument.tc_Status =  'N':U and tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-INIT}) and
           can-find(first tDDocumentInvoiceXref where
                          tDDocumentInvoiceXref.tc_ParentRowid = tDDocument.tc_Rowid and
                          tDDocumentInvoiceXref.tc_Status     <> "D":U)
        then for each tDDocumentInvoiceXref where
                      tDDocumentInvoiceXref.tc_ParentRowid = tDDocument.tc_Rowid:
            delete tDDocumentInvoiceXref.
        end.
    
        /* Status is not INIT and not BOUNCED -> a link is needed */
        if tDDocument.DDocumentStatus <> {&DOCUMENTSTATUS-INIT}    and
           tDDocument.DDocumentStatus <> {&DOCUMENTSTATUS-BOUNCED} and
           not can-find(first tDDocumentInvoiceXref where
                              tDDocumentInvoiceXref.tc_ParentRowid = tDDocument.tc_Rowid and
                              tDDocumentInvoiceXref.tc_Status     <> "D":U)
        then do:
            <M-14 run AddDetailLine
               (input  'DDocumentInvoiceXref':U (icTable), 
                input  tDDocument.tc_Rowid (icParentRowid), 
                output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    
            if viFcReturnSuper < 0 or oiReturnStatus  = 0 then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then leave DDOCUMENTBLOCK.
    
            assign tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC  = tDDocument.DDocumentOriginalDebitTC
                   tDDocumentInvoiceXref.tcAllocAmountCrDt           = {&CREDITDEBITABBREVIATION-CREDIT}
                   tDDocumentInvoiceXref.DInvoice_ID                 = 0
                   tDDocumentInvoiceXref.tcCurrencyCode              = tDDocument.tcCurrencyCode
                   tDDocumentInvoiceXref.tcDInvoiceReference         = <M-15 GetDDocumentTypeTranslation (input  tDDocument.DDocumentType (icType)) in BDDocument> + " ":U +
                                                                       string(tDDocument.DDocumentYear, "9999":U)                                                  + "/":U +
                                                                       string(tDDocument.DDocumentNumber, "999999999":U)
                   tDDocumentInvoiceXref.tcDInvoiceType              = {&INVOICETYPE-PREPAYMENT}
                   tDDocumentInvoiceXref.tcDebtorCode                = tDDocument.tcDebtorCode.
        end.
    
        /* A paid or bounced document cannot be changed anymore                                                    */
        /* Changes to DDocument itself are checked in ValidateComponent, so here, we only have to check changes to */
        /* DDocumentInvoiceXref.                                                                                   */
        if tDDocument.tc_Status = "":U                               and
          (t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-PAID}     or
          (t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-PAIDCON}  and
           t_iDDocument.DDocumentType  <> {&DOCUMENTTYPE-DRAFT})     or
           t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-BOUNCED}) and
           can-find(first tDDocumentInvoiceXref where
                          tDDocumentInvoiceXref.tc_ParentRowid = tDDocument.tc_Rowid and
                          tDDocumentInvoiceXref.tc_Status     <> "":U)
        then do:
            <M-16 run SetMessage
               (input  trim(#T-26'A payment with status $1, $2, or $3 cannot be changed.':250(896)T-26#) (icMessage), 
                input  {&DOCUMENTSTATUS-PAIDCON-TR} + chr(2) + {&DOCUMENTSTATUS-PAID-TR} + chr(2) + {&DOCUMENTSTATUS-BOUNCED-TR} (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  tDDocument.tc_Rowid (icRowid), 
                input  'QADFIN-2594':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    
            assign oiReturnStatus = -1.
            leave DDOCUMENTBLOCK.
        end.
    
        /* Fill DDocumentIsOpen and DDocumentClosingDate */
        assign vlIsOpen = can-do({&DOCUMENTSTATUS-INIT}      + ",":U +
                                 {&DOCUMENTSTATUS-ACCEPT}    + ",":U +
                                 {&DOCUMENTSTATUS-PORTFOLIO} + ",":U +
                                 {&DOCUMENTSTATUS-INCASSO}   + ",":U +
                                 {&DOCUMENTSTATUS-DISCONT},
                                 tDDocument.DDocumentStatus).
                                 
        if tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-PAIDCON} and 
           tDDocument.DDocumentType   = {&DOCUMENTTYPE-DRAFT}
           then vlIsOpen = yes.  
        if tDDocument.tc_Status = "N":U or tDDocument.DDocumentIsOpen <> vlIsOpen 
        then do:
             assign tDDocument.DDocumentIsOpen      = vlIsOpen
                    tDDocument.DDocumentClosingDate = if vlIsOpen
                                                         then date(12, 31, 9999)
                                                         else tDDocument.ttPostingDate.
    
             if tDDocument.tc_Status = "":U
             then assign tDDocument.tc_Status = "C":U.
         end.
 
    end. /* end of for each tDDocument */
    
    <M-50 run AdditionalUpdatesDPaymentSelection
       (output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    if viFcReturnSuper < 0 or oiReturnStatus  = 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 then leave DDOCUMENTBLOCK.
    
    
    if not vlSkipAdditionalUpdatesDDoc
    then do:
        <M-17 run AdditionalUpdatesPosting (output viFcReturnSuper (oiReturnStatus)) in BDDocument>
        if viFcReturnSuper < 0 or oiReturnStatus  = 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then leave DDOCUMENTBLOCK.
    end.
    
    <M-55 run AdditionalUpdatesDInvoice  (output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    if viFcReturnSuper < 0 or oiReturnStatus  = 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 then leave DDOCUMENTBLOCK.
    

    <M-61 run AdditionalUpdatesDeductions  (output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    if viFcReturnSuper < 0 or oiReturnStatus  = 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 then leave DDOCUMENTBLOCK.

    assign viLocalReturn = oiReturnStatus.
    
    <ANCESTOR-CODE>
    
    if oiReturnStatus = 0 then assign oiReturnStatus = viLocalReturn.
    if oiReturnStatus < 0 then leave DDOCUMENTBLOCK.
end. /* of DDOCUMENTBLOCK */

/* Stop external instances when needed */
if oiReturnStatus < 0
then do:
    <M-58 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    if viFcReturnSuper < 0 then assign oiReturnStatus = viFcReturnSuper.
end.

/* Stop all queries */
<M-59 run StopAllQueries  (output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper < 0 or oiReturnStatus = 0 then assign oiReturnStatus = viFcReturnSuper.