project QadFinancials > class BCInvoice > method AdditionalUpdatesAll

Description

This Method is submethod of AdditionalUpdates. This method holds all program-code and all calls to the major submethods of method AdditionalUpdates


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.AdditionalUpdates


program code (program8/bcinvoice.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.

    empty temp-table tPostingPostingLineInfoCIJE.
    
    /* ======================================================================================= */
    /* Start/Open BJournalEntry: we do it here once so all submethods can access BJOurnalEntry */
    /* viBJournalEntryCIID should be filled in all cases before this method is executed when   */
    /* there is a changed/new/deleted tCInvoiceMovement or if it concerns a new invoice with a */
    /* link to another invoice or there is a new CInvoicePosting (e.g. Matching).              */
    /* ======================================================================================= */
    /* Make sure method ValidateBCAdnAdditionalUpdates in BJournalEntry-instance is executed   */
    /* when the MF-posting has been validated. This can happen in activity 'Allocate', 'Modify'*/
    /* or 'PrepareForAllocation': in these cases it might happen that nothing on the BCInvocie */
    /* instance is marked as changed/created (all tc_status fields are empty) but the          */
    /* MF-posting in the BJournalInstance is changed/created (tc_status <> empty).             */
    /* ======================================================================================= */
    assign vlNeedToOpenBJournalEntry    = false
           vlNeedToCheckForChangesInBJE = false.
    if can-find (first tCInvoiceMovement where 
                       tCInvoiceMovement.tc_Status <> "":U)     OR
       can-find (first tCInvoice where 
                       tCInvoice.tc_Status          = "N":U and
                       tCInvoice.LinkedCInvoice_ID <> 0     and 
                       tCInvoice.LinkedCInvoice_ID <> ?)        OR
       can-find (first tCInvoicePosting where 
                       tCInvoicePosting.tc_Status <> "":U)
    then assign vlNeedToOpenBJournalEntry    = true
                vlNeedToCheckForChangesInBJE = false.

    if vlNeedToOpenBJournalEntry  = false               and 
       viBJournalEntryCIID       <> ?                   and 
       viBJournalEntryCIID       <> 0                   and  
       (vcActivityCode = "Modify":U              or  
        vcActivityCode = "Approve":U             or
        vcActivityCode = "Allocate":U            or  
        vcActivityCode = "Release For Payment":U or 
        vcActivityCode = "Prepare Allocation":U)        and 
       can-find (first tCInvoice where 
                       tCInvoice.tc_Status = "C":U or 
                       tCInvoice.tc_Status = "":U)      and
       can-find (first tCInvoicePosting where 
                       tCInvoicePosting.tc_Status           = "":U and 
                       tCInvoicePosting.CInvoicePostingType = {&INVOICEPOSTINGTYPE-ALLOCATION})
    then assign vlNeedToOpenBJournalEntry    = true
                vlNeedToCheckForChangesInBJE = true.
    if vlNeedToOpenBJournalEntry
    then do :
        if viBJournalEntryCIID = 0 or
           viBJournalEntryCIID = ?
        then do :
            assign oiReturnStatus = -1.
            <M-19 run SetMessage
               (input  trim(#T-21'Internal error. The system cannot sabe an invoice with invoice activity on it when no posting instance is available.':250(17930)t-21#) (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QADFIN-4487':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
            Return.
        End.
        <I-24 {bFcOpenInstance
            &CLASS           = "BJournalEntry"}>
        /* If the CInvoice-instance itself is not changed, then:                                                          */
        /* - if the MF-posting is changed, then we also need to open the BJournalEntry-instance as we need to validate it */
        /* - if the MF-posting is not changed then we do not have to do anything for it (sinply close BJE again)          */
        if vlNeedToCheckForChangesInBJE = true
        then do :
            assign vlPostingIsCreatedChangedDel = false.
            find first tCInvoicePosting where 
                       tCInvoicePosting.tc_Status           = "":U and 
                       tCInvoicePosting.CInvoicePostingType = {&INVOICEPOSTINGTYPE-ALLOCATION}
                       no-lock no-error.
            if available tCInvoicePosting
            then do :
                <M-25 run GetPostingActionsBasedOnPostingID
                   (input  tCInvoicePosting.Posting_ID (iiPostingID), 
                    output vlPostingIsCreatedChangedDel (olPostingIsCreatedChangedDeleted), 
                    output viExternalReturnStatus (oiReturnStatus)) in BJournalEntry>
                if viExternalReturnStatus <> 0 
                then assign oiReturnStatus = viExternalReturnStatus.
                if viExternalReturnStatus < 0
                then.   /* ========================================================================================================= */
                        /* Normally we would here close the communication to BJournalEntry but 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                                               */
                        /* ========================================================================================================= */
            end. /* if available tCInvoicePosting */
            if vlPostingIsCreatedChangedDel = false
            then. /* ========================================================================================================= */
                  /* Normally we would here close the communication to BJournalEntry but 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                                               */
                  /* ========================================================================================================= */
            else assign vlBJournalEntryOpenedInThisMeth = true. 
        end. /* if vlNeedToCheckForChangesInBJE = true */
        else assign vlBJournalEntryOpenedInThisMeth = true. 
    end. /* if vlNeedToOpenBJournalEntry = 0 or */
    
    /* ============================================================================= */
    /* Start block // Errors in this block should result in a value for viBlockError */
    /* ============================================================================= */
    ADDUPDBLOCK: DO :
        /* ====================================================================================== */
        /* Call a submethod that will create CA if the linked-CI field in the invoices is filled  */
        /* ====================================================================================== */
        <M-29 run AdditionalUpdatesAllCreateCA (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        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 createCA because in this method, movements are updated,                 */
        /* and in createCA there are also movements created                                       */
        /* ====================================================================================== */
        <M-17 run AdditionalUpdatesAllAssignments (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
        if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
        
        /* ======================================================================= */
        /* Call a submethod that will handle all actions regarding the allocations */
        /* ======================================================================= */
        <M-5 run AdditionalUpdatesAllAllocations (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
        if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
        
        /* ================================================================ */
        /* Call a submethod that will handle all actions on the workobjects */
        /* ================================================================ */
        <M-18 run AdditionalUpdatesAllWorkObject (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
        if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
                
        /* =========================================================================== */
        /* Call a submethod that will handle all actions on the reversal of APMatching */
        /* =========================================================================== */
        <M-35 run AdditionalUpdatesAllAPMatching  (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
        if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
        
        /* =========================================================================== */
        /* Call a submethod that will handle all actions on the balancing CC amounts   */        
        /* =========================================================================== */
        <M-660 run AdditionalUpdatesAllCreateSCRounding  (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
        if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
        
        /* ValidateBCAndAdditionalUpdates of BDocumentLink */
        if vlBDocLinkSartedFromCI = true
        then do:
            <I-36 {bFcOpenInstance
                 &CLASS           = "BDocumentLink"}>
            <M-37 run ValidateBCAndAdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BDocumentLink>
            /* ========================================================================================================= */
            /* Normally we would here close the communication to BDocumentLink but 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 viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
            if viFcReturnSuper < 0 then Leave ADDUPDBLOCK.
        end.
        /* ======================================================================== */
        /* 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 viBJournalEntryCIID <> 0         and 
           viBJournalEntryCIID <> ?         and 
           vlBJEIsStartedFromCI = true      and 
           vlBJournalEntryOpenedInThisMeth = true
        then do:
            <M-10 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:
                <M-11 run SetMessage
                   (input  trim(subst(#T-23'Internal error. The system was unable to set property &1 in the journal entry component.':150(906575812)T-23#, 'vlPostingMustBeBalanced':U)) (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QADFIN-4483':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
            end. /* if viFcReturnSuper < 0 */

            <M-12 run ValidateBCAndAdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
            if viFcReturnSuper < 0
            then do:
                <M-13 run SetMessage
                   (input  trim(subst(#T-24'Error &1 occurred when validating the journal entry.':150(376)t-24#, string(viFcReturnSuper))) (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QADFIN-4484':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                <M-14 run SetPublicData (input  'vlPostingMustBeBalanced':U (icDataList), 
                             input  'false':U (icValueList), 
                             output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                Leave ADDUPDBLOCK.
            end. /* if viFcReturnSuper < 0 */
        end. /* if viBJournalEntryCIID <> 0 and */
        
        /* ====================================================================================== */
        /* Call a submethod that will perform some assignments and that calls the BJE.Validations */
        /* ====================================================================================== */
        <M-30 run AdditionalUpdatesAllQCInvoiceMovement (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        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 the communication to BJournalEntry but 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.