project QadFinancials > class BCInvoiceAPMatching > method ApiEDICInvoiceAPMatchingImportLC


Parameters


bdTotalAmountInvoiceinput-outputdecimal
biRowidinput-outputinteger
oiReturnStatusoutputinteger


Internal usage


QadFinancials
method BCInvoiceAPMatching.ApiEDICInvoiceAPMatchingImport


program code (program3/bcinvoiceapmatching.p)

/* =================================================================================================== */
/* Method      : ApiEDICInvoiceAPMatchingImport                                                        */
/* Desc        : This method is primarly designed to create  supplier invoices and receiver matchings  */
/*               from EDI                                                                              */
/* --------------------------------------------------------------------------------------------------- */
/* Params:  (I)  izCInvoiceAPMatching Handle to dataset containing data comming from EDI related to    */
/*                                    creation of new Supplier Invoices and Receiver matchings in      */
/*                                    financial application                                             */
/* =================================================================================================== */

assign oiReturnStatus = -98
       viLocalReturn  = 0.

MAIN_BLOCK:
do on error undo, leave:

    /* ==================================================================================== *
     * Matching of Logistical charges                                                       *
     * ==================================================================================== */
    if can-find(first tEDIAPMatchingLcCharge where
                      tEDIAPMatchingLcCharge.tc_ParentRowid = tEDICInvoice.tc_Rowid)
    then do:
        if tEDICInvoice.tcDomainCode          = ?    or
           tEDICInvoice.tcDomainCode          = '':U
        then do:
            assign vcMessage = #T-49'There are missing parameters for retrieving of pending vouchers with logistic charges to be matched.':255(222149402)T-49#
                   vcContext = "Domain=&1":U
                   vcContext = substitute(vcContext, tEDICInvoice.tcDomainCode)
                   vcMessage = substitute("&1 (&2)":U, vcMessage, vcContext)
                   vcContext = replace(vcContext, "|":U, chr(2)).
            <M-47 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  tEDICInvoice.tc_Rowid (icRowid), 
                input  'qadfin-680233':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  vcContext (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoiceAPMatching>
            delete tCInvoiceRef.
            assign viLocalReturn = -1.
            leave MAIN_BLOCK.
        end.
        
        for each tEDIAPMatchingLcCharge where
                 tEDIAPMatchingLcCharge.tc_ParentRowid = tEDICInvoice.tc_Rowid:
            
            /* Is all data defined */
            if ((tEDIAPMatchingLcCharge.tcLcCharge          = ? or tEDIAPMatchingLcCharge.tcLcCharge          = "":U or
                 tEDIAPMatchingLcCharge.tcOrderNumber       = ? or tEDIAPMatchingLcCharge.tcOrderNumber       = "":U or
                 tEDIAPMatchingLcCharge.tiOrderLine         = ? or tEDIAPMatchingLcCharge.tiOrderLine         = 0)       and
                (tEDIAPMatchingLcCharge.tcExternalReference = ? or tEDIAPMatchingLcCharge.tcExternalReference = "":U or
                 tEDIAPMatchingLcCharge.tcLcCharge          = ? or tEDIAPMatchingLcCharge.tcLcCharge          = "":U)    and
                (tEDIAPMatchingLcCharge.tcInternalReference = ? or tEDIAPMatchingLcCharge.tcInternalReference = "":U or
                 tEDIAPMatchingLcCharge.tcLcCharge          = ? or tEDIAPMatchingLcCharge.tcLcCharge          = "":U)    and
                (tEDIAPMatchingLcCharge.tiPvoId             = ? or tEDIAPMatchingLcCharge.tiPvoId             = 0    or
                 tEDIAPMatchingLcCharge.tiPvodLineId        = ? or tEDIAPMatchingLcCharge.tiPvodLineId        = 0))
            then do:
                assign vcMessage = #T-293'There are missing parameters for retrieving of pending vouchers with logistic charges to be matched.':255(222149402)T-293#
                       vcContext = "tcLcCharge=&1|tcOrderNumber=&2|tiOrderLine=&3|tcExternalReference=&4|tcInternalReference=&5|tiPvoId=&6|tiPvodLineId=&7":U
                       vcContext = substitute(vcContext, tEDIAPMatchingLcCharge.tcLcCharge, tEDIAPMatchingLcCharge.tcOrderNumber,tEDIAPMatchingLcCharge.tiOrderLine,tEDIAPMatchingLcCharge.tcExternalReference,tEDIAPMatchingLcCharge.tcInternalReference,tEDIAPMatchingLcCharge.tiPvoId,tEDIAPMatchingLcCharge.tiPvodLineId)
                       vcMessage = substitute("&1 (&2)":U, vcMessage, vcContext)
                       vcContext = replace(vcContext, "|":U, chr(2)).
                <M-51 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tEDICInvoice.tc_Rowid (icRowid), 
                    input  'qadfin-90104':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  vcContext (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoiceAPMatching>
                delete tCInvoiceRef.
                assign viLocalReturn = -1.
                leave MAIN_BLOCK.
            end.
    
            assign vdAmountToMatch = tEDIAPMatchingLcCharge.tdMatchAmountTC.
    
            /* Get pending vouchers */
            <Q-55 run PendingVoucherForAPIMatchLC (all) (Read) (NoCache)
               (input ?, (CompanyId)
                input tEDIAPMatchingLcCharge.tcOrderNumber, (OrderNumber)
                input tEDIAPMatchingLcCharge.tiOrderLine, (OrderLine)
                input tEDIAPMatchingLcCharge.tcExternalReference, (ExternalReference)
                input tEDIAPMatchingLcCharge.tcInternalReference, (InternalReference)
                input tEDIAPMatchingLcCharge.tcLcCharge, (LcCharge)
                input tEDIAPMatchingLcCharge.tiPvoId, (PvoID)
                input tEDIAPMatchingLcCharge.tiPvodLineId, (PvodID)
                input tEDICInvoice.tcDomainCode, (DomainCode)
                output dataset tqPendingVoucherForAPIMatchLC) in BMfgPendingVoucher>
    
            for each tqPendingVoucherForAPIMatchLC
               break by tqPendingVoucherForAPIMatchLC.tcpvo_domain:
    
                create tAPMatchingLnRef.
                assign tAPMatchingLnRef.tcDomainCode         = tqPendingVoucherForAPIMatchLC.tcpvo_domain
                       tAPMatchingLnRef.tiPvoId              = tqPendingVoucherForAPIMatchLC.tipvo_id
                       tAPMatchingLnRef.tiPvodLineId         = tqPendingVoucherForAPIMatchLC.tipvod_id_line
                       tAPMatchingLnRef.tlIsLgCharge         = true
                       tAPMatchingLnRef.tlIsRecalculateTaxes = true
                       tAPMatchingLnRef.tdMatchQty           = 0
                       tAPMatchingLnRef.tc_ParentRowid       = tCInvoiceRef.tc_Rowid
                       tAPMatchingLnRef.tc_Rowid             = string(biRowid)
                       biRowid                               = biRowid - 1.
    
                if last-of(tqPendingVoucherForAPIMatchLC.tcpvo_domain) and
                   tEDIAPMatchingLcCharge.tlIsPvodFinished
                then assign tAPMatchingLnRef.tdMatchUnitPrice = vdAmountToMatch.
                else assign tAPMatchingLnRef.tdMatchUnitPrice = (if tqPendingVoucherForAPIMatchLC.tdpvod_accrued_amt - tqPendingVoucherForAPIMatchLC.tdpvod_vouchered_amt < vdAmountToMatch 
                                                                 then tqPendingVoucherForAPIMatchLC.tdpvod_accrued_amt - tqPendingVoucherForAPIMatchLC.tdpvod_vouchered_amt
                                                                 else vdAmountToMatch).
                                                                     
                assign vdAmountToMatch                        = vdAmountToMatch - tAPMatchingLnRef.tdMatchUnitPrice
                       tAPMatchingLnRef.tlIsPvodFinished      = tEDIAPMatchingLcCharge.tlIsPvodFinished or 
                                                               (tqPendingVoucherForAPIMatchLC.tdpvod_accrued_amt - tqPendingVoucherForAPIMatchLC.tdpvod_vouchered_amt = tAPMatchingLnRef.tdMatchUnitPrice).
    
                                                                 
                /* ====================================================================== */
                /* Calculate the totals for this invoice                                  */
                /* This is needed to see if the invoice has a negative or positive amount */
                /* The Invoice Type will be defaulted based on this.                      */
                /* ====================================================================== */
                assign bdTotalAmountInvoice = bdTotalAmountInvoice + tAPMatchingLnRef.tdMatchUnitPrice.
    
                if vdAmountToMatch = 0 and
                   not tEDIAPMatchingLcCharge.tlIsPvodFinished
                then leave.
            end.
    
            if vdAmountToMatch <> 0
            then do:
                assign vcMessage = #T-62'Cannot match requested amount as there is not enough pending amount on unmatched logistic charges.':255(885905000)T-62#
                       vcContext = "Domain=&1|OrderNumber=&2|OrderLine=&3|ExternalReference=&4|InternalReference=&5|LogisticCharge=&6|Pvo_ID=&7|Pvod_ID=&8":U
                       vcContext = substitute(vcContext, tEDICInvoice.tcDomainCode,tEDIAPMatchingLcCharge.tcOrderNumber,tEDIAPMatchingLcCharge.tiOrderLine,tEDIAPMatchingLcCharge.tcExternalReference,tEDIAPMatchingLcCharge.tcInternalReference,tEDIAPMatchingLcCharge.tcLcCharge,tEDIAPMatchingLcCharge.tiPvoId,tEDIAPMatchingLcCharge.tiPvodLineId)
                       vcMessage = substitute("&1 (&2)":U, vcMessage, vcContext)
                       vcContext = replace(vcContext, "|":U, chr(2)).
                <M-80 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tEDICInvoice.tc_Rowid (icRowid), 
                    input  'QadFin-62804':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  vcContext (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoiceAPMatching>
                delete tCInvoiceRef.
                assign viLocalReturn = -1.
                leave MAIN_BLOCK.
            end. /* if vdAmountToMatch <> 0 */
        end. /* for each tEDIAPMatching where */
    end. /* if can-find(first tEDIAPMatchingLcCharge where */
end.  /* MAIN_BLOCK */

assign oiReturnStatus = viLocalReturn.