project QadFinancials > class BCInvoice > method AdditionalUpdatesAllAPMatching

Description

This submethod of AdditionalUpdatesAll does the update of AP Matching when the invoice is reversed


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.AdditionalUpdatesAll


program code (program8/bcinvoice.p)

    /* ========================================================================== */
    /* No action needed in case the current action is not Reverse and not Replace */
    /* Exception handling                                                         */
    /* ========================================================================== */
    if vcActivityCode <> "Reverse":U and 
       vcActivityCode <> "Replace":U
    then Return.
    assign oiReturnStatus      = -98
           viLocalReturnStatus = 0.
    
    /* =============================================================================== */
    /* Check, if there is any supplier invoice, which was reversed. If not just return */
    /* This means:                                                                     */
    /* - The LinkedInvoice_ID should be filled and should initialy not be filled       */
    /* - The LinkedInvoice it balance should be zero                                   */
    /* - The LinkedCInvoice should have CInvoiceIsLogisticMatching                     */
    /* Compose a list with the IDs of the invoices whose matching needs Cancaltion     */
    /* =============================================================================== */
    for each tCInvoice where
             tCInvoice.LinkedCInvoice_ID <> 0                                   and
             tCInvoice.LinkedCInvoice_ID <> ?                                   and
             (tCInvoice.tc_Status = "N":U or 
              (tCInvoice.tc_Status = "C":U and
               (can-find (t_iCInvoice where 
                          t_iCInvoice.tc_rowid = tCInvoice.tc_rowid and 
                          (t_iCInvoice.LinkedCInvoice_ID = 0 or
                           t_iCInvoice.LinkedCInvoice_ID = ?)))))               and 
             can-find (btCInvoice where 
                       btCInvoice.CInvoice_ID                 = tCInvoice.LinkedCInvoice_ID and
                       btCInvoice.CInvoiceIsLogisticMatching  = true                        and  
                       (btCInvoice.CInvoiceBalanceDebitTC  = 0 or
                        btCInvoice.CInvoiceBalanceDebitTC  = ?) and 
                       (btCInvoice.CInvoiceBalanceCreditTC = 0 or
                        btCInvoice.CInvoiceBalanceCreditTC = ?)) :
        assign vcListCIIDsToCancelTheMatching = vcListCIIDsToCancelTheMatching + ",":U + string(tCInvoice.LinkedCInvoice_ID).
    end. /* for each */     
    
    /* ============================================================================================== */
    /* Return without error in case there is nothing to do, otherwise: clean the prefix from the list */
    /* ============================================================================================== */    
    if vcListCIIDsToCancelTheMatching = "":U
    then do :
        assign oiReturnStatus = 0.
        Return.
    end. /* if vcListCIIDsToCancelTheMatching = "":U */
    else assign vcListCIIDsToCancelTheMatching = substring(vcListCIIDsToCancelTheMatching,2,-1,"character":U).
    
    /* ================ */
    /* Open APMatching  */
    /* ================ */
    if viBAPMatchingCIID = 0 or 
       viBAPMatchingCIID = ?
    then do:
        <I-12 {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION = "true"
             &CLASS              = "BAPMatching"}>
    end. /* if viBAPMatchingCIID = 0 or  */
    else if not valid-handle(vhBAPMatchingCIInst)
         then do:
             <I-13 {bFcOpenInstance
                  &CLASS           = "BAPMatching"}>
         end. /* Not if viBAPMatchingCIID = 0 or  */
    
    /* =========== */
    /* Start Block */
    /* =========== */
    APMCALLINGBLOCK : DO :
        
        /* ================================================== */
        /* Call CancelAPMatching for each invoice in the list */
        /* ================================================== */
        do viCurrentEntry = num-entries(vcListCIIDsToCancelTheMatching) to 1 by -1 :
            assign viCInvoiceID = integer(entry(viCurrentEntry,vcListCIIDsToCancelTheMatching)) no-error.
            if error-status:error
            then do :
                assign viLocalReturnStatus = -3
                       vcMessage           = trim(substitute(#T-17'Internal error. The system was unable to retrieve the invoice ID from the list of IDs (&1).':255(69706)t-17#,vcListCIIDsToCancelTheMatching)).
                if error-status:num-messages > 0
                then assign vcMessage = vcMessage + chr(10) + 
                                        trim(substitute(#T-18'Detailed info: &1 (&2)':252(49824)T-18#,error-status:Get-Message(1),string(error-status:Get-Number(1)))).
                <M-19 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-8262':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                Leave APMCALLINGBLOCK.
            end. /* if error-status:error */
            <M-14 run CancelAPMatching
               (input  viCInvoiceID (iiCInvoiceId), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            if viFcReturnSuper <> 0 
            then assign viLocalReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0  
            then Leave APMCALLINGBLOCK.
        end. /* do viCurrentEntry = num-entries(vcListCIIDsToCancelTheMatching) to 1 by -1 */
        
    END. /* APMCALLINGBLOCK */ 
    
    /* ============================================================= */
    /* Call ValidateBCAndAdditionalUpdates in case no errors occured */
    /* ============================================================= */ 
    if viLocalReturnStatus >= 0 
    then do :   
        <M-24 run ValidateBCAndAdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        if viFcReturnSuper <> 0 
        then assign viLocalReturnStatus = viFcReturnSuper.
    end. /* if viLocalReturnStatus >= 0 */
    
    /* ========================================================================================================= */
    /* Normally we would here close the communication to class BAPMatching 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                                               */
    /* ========================================================================================================= */
    
    /* ============================================================= */
    /* Call StopExternalInstances in case errors occured             */
    /* ============================================================= */ 
    if viLocalReturnStatus < 0 
    then do :   
        <M-26 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    end. /* if viLocalReturnStatus >= 0 */
    
    /* ================== */
    /* Exception handling */
    /* ================== */
    assign oiReturnStatus = viLocalReturnStatus.