project QadFinancials > class BCInvoiceAPMatching > method CreateAPMatchingRun

Description

Create receiver matching records


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoiceAPMatching.CreateCInvoiceAPMatchingAllInOneTran
method BCInvoiceAPMatching.CreateCInvoiceAPMatchingOneInOneTran


program code (program6/bcinvoiceapmatching.p)

/* =================================================================================================== */
/* Method      : CreateAPMatchingRun                                                                   */
/* Desc        : Create receiver matching                                                              */
/*               Method has to be in the same segment as CreateCInvoiceAPMatching                      */
/* --------------------------------------------------------------------------------------------------- */
/* =================================================================================================== */

assign oiReturnStatus = -98
       viLocalReturn  = 0.

APMATCHING_BLOCK:
do on error undo, return:

    /* =============================================================================================== */
    /* If there is nothing to create, just stop                                                        */
    /* =============================================================================================== */
    if not can-find(first tAPMatchingLnBCIAPM)
    then leave APMATCHING_BLOCK.


    /* =============================================================================================== */
    /* Start Supplier invoice Instance                                                                 */
    /* =============================================================================================== */
    if viBAPMatchingFromBCIAPMID = 0 or
       viBAPMatchingFromBCIAPMID = ?
    then do:
        <I-1 {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION   = "true"
             &CLASS                = "BAPMatching"}>    
    end.
    else if not valid-handle(vhBAPMatchingFromBCIAPMInst)
    then do:
        <I-60 {bFcOpenInstance
             &CLASS           = "BAPMatching"}>
    end.
         
    /* =================================================================================================== */
    /* Do not auto-update the invoice when:                                                                */
    /*  1. the invoice is not in status Initial      AND                                                   */
    /*  2. the invoice already existed (so Jrnl, Year and Voucher are filled or RegNr is filled)           */
    /* =================================================================================================== */   
    assign vlIsUpdateCInvoiceAutomatically = true.
    if tCInvoiceRef.tlIsInitialStatus <> true AND 
       ((tCInvoiceRef.tcJournalCode         <> ?    and 
         tCInvoiceRef.tcJournalCode         <> "":U and 
         tCInvoiceRef.tiCInvoicePostingYear <> ?    and 
         tCInvoiceRef.tiCInvoicePostingYear <> 0    and 
         tCInvoiceRef.tiCInvoiceVoucher     <> ?    and 
         tCInvoiceRef.tiCInvoiceVoucher     <> 0 ) or
        (tCInvoiceRef.tiCInvoiceRegistrationNr <> ? and   
         tCInvoiceRef.tiCInvoiceRegistrationNr <> 0))
    then assign vlIsUpdateCInvoiceAutomatically = false.
    
    /* =============================================================================================== */
    /* Create header of receiver matching                                                              */
    /* =============================================================================================== */    
    <M-2 run AddAPMatching
       (input  tCInvoiceRef.tiCInvoice_ID (iiCInvoiceID), 
        input  if tCInvoiceRef.tlAPMatchingIsStatusFinal then {&APMATCHINGSTATUS-FINISHED} else {&APMATCHINGSTATUS-INITIAL} (icAPMatchingStatus), 
        input  tCInvoiceRef.tcAPMatchingJournalCode (icAPMatchingJournalCode), 
        input  vlIsUpdateCInvoiceAutomatically (ilIsUpdateCInvoiceAutomatically), 
        output viMatchingId (oiAPMatchingID), 
        output vcMatchingTcRowid (ocAPMatchingTcRowid), 
        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
    if viFcReturnSuper < 0 then leave APMATCHING_BLOCK.


    /* =============================================================================================== */
    /* Create lines of receiver matching                                                               */
    /* =============================================================================================== */
    assign vlIsRecalculateTaxes = can-find(first tAPMatchingLnRef where
                                                 tAPMatchingLnRef.tc_ParentRowid       = tCInvoiceRef.tc_Rowid and
                                                 tAPMatchingLnRef.tlIsRecalculateTaxes = true).
    
    <M-3 run AddAPMatchingLn
       (input  vcMatchingTcRowid (icAPMatchingTcRowid), 
        input  vcDomainCode (icDomainCode), 
        input  vlIsRecalculateTaxes (ilCallGTM), 
        input  false (ilFillPendingMatchFields), 
        input-output tAPMatchingLnBCIAPM (tAPMatchingLnBasedUponPvod), 
        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
    if viFcReturnSuper < 0 then leave APMATCHING_BLOCK.
    
    /* =============================================================================================== */                                                                                                         
    /* Create additional cost lines                                                                    */
    /* =============================================================================================== */
    for each tAPMatchingCostBCIAPM:
        assign tAPMatchingCostBCIAPM.tc_ParentRowid = vcMatchingTcRowid.
    end. /* for each tAPMatchingCostBCIAPM: */
    
    <M-31 run AddAPMatchingCost
       (input  tAPMatchingCostBCIAPM (tAPMatchingCostFromBCIAPM), 
        input  tAPMatchingCostSafBCIAPM (tAPMatchingCostSafFromBCIAPM), 
        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
    if viFcReturnSuper < 0 then leave APMATCHING_BLOCK.
    
    /* =============================================================================================== */
    /* Store ID of created receiver matching lines                                                     */
    /* =============================================================================================== */
    for each tAPMatchingLnRef where
             tAPMatchingLnRef.tc_ParentRowid = tCInvoiceRef.tc_Rowid:
        
        find tAPMatchingLnBCIAPM where
             tAPMatchingLnBCIAPM.tiPvoID      = tAPMatchingLnRef.tiPvoId and
             tAPMatchingLnBCIAPM.tiPvodLineID = tAPMatchingLnRef.tiPvodLineId
             no-error.
        if available tAPMatchingLnBCIAPM 
        then assign tAPMatchingLnRef.tiAPMatchingLnId = tAPMatchingLnBCIAPM.tiAPMatchingLnID.
    end. /* for each tAPMatchingLnRef where */ 
end. /* APMATCHING_BLOCK: */

/* =================================================================================================== */
/* Error handling                                                                                      */
/* =================================================================================================== */
assign oiReturnStatus = viLocalReturn.