project QadFinancials > class BERSProcessor > method ERSProcessAPMatching

Description

Sub-method for the ERS processor: creates a temp-table record to represent the creation of a set of AP matching records.


Parameters


icERSProcessorRefRowIdinputcharacterRowid input parameter: unique rowid for the temp-table record holding the pending voucher information.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BERSProcessor.ERSProcessLegalDocuments
method BERSProcessor.ERSProcessPORec


program code (program5/bersprocessor.p)

/* =================================================================================================== */
/* Method      : ERSProcessAPMatching                                                                  */
/* Desc        : Create record for creation of receiver matching                                       */
/* --------------------------------------------------------------------------------------------------- */
/* Params:  (I)  ERSProcessorRefRowId Row id of record in temporary table with list of receipts        */
/* =================================================================================================== */

assign oiReturnStatus = -98.

find bERSProcessorRef where
     bERSProcessorRef.tcFcRowid = icERSProcessorRefRowId
     no-error.

/* =================================================================================================== */
/* Validate input parameters                                                                           */
/* =================================================================================================== */
if icERSProcessorRefRowId = ?    or
   icERSProcessorRefRowId = '':U or
   not available bERSProcessorRef
then do:
    assign vcMessage = #T-4'The specified input parameters are invalid.':255(70371)t-4#
           vcContext = 'icERSProcessorRefRowId=&1|available bERSProcessorRef=&2':U
           vcContext = replace(vcContext, '|':U, chr(2))
           vcContext = substitute(vcContext, icERSProcessorRefRowId, available bERSProcessorRef).
    <M-1 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-8386':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
    assign oiReturnStatus = -1.
    return.
end.

/* =================================================================================================== */
/* Create record for Receiver matching creation                                                        */
/* =================================================================================================== */
create tAPMatchingLnRefERS.
assign tAPMatchingLnRefERS.tc_ParentRowid       = tCInvoiceRefERS.tc_RowId
       tAPMatchingLnRefERS.tc_Rowid             = bERSProcessorRef.tcFcRowid
       tAPMatchingLnRefERS.tcDomainCode         = bERSProcessorRef.tcDomainCode
       tAPMatchingLnRefERS.tiPvoId              = bERSProcessorRef.tiPvoId
       tAPMatchingLnRefERS.tiPvodLineId         = bERSProcessorRef.tiPvodLineId
       tAPMatchingLnRefERS.tdMatchQty           = bERSProcessorRef.tdAPMatchingLnMatchQty
       tAPMatchingLnRefERS.tlIsRecalculateTaxes = vlIsRecalculateTaxes
       tAPMatchingLnRefERS.tlIsVarGLPosting     = tqAccountsPayableCtrlByDomain.tlapc_gl_avg_cst
       tAPMatchingLnRefERS.tlIsPvodFinished     = true.

/* =================================================================================================== */
/* Calculate Matching Price - only when not using fiscal receiving.                                    */
/* =================================================================================================== */

if vcGroupBy = {&ERSPROCESSORINVGROUP-RECEIVER}
then do:
    <M-5 run ERSProcessAPMatchingPrice
       (input  bERSProcessorRef.tcFcRowid (icERSProcessorRefRowId), 
        output tAPMatchingLnRefERS.tdMatchUnitPrice (odInvoicePrice), 
        output viFcReturnSuper (oiReturnStatus)) in BERSProcessor>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper <  0 then return.
    
    /* Update also price in original temporary table */
    assign bERSProcessorRef.tdAPMatchingLnMatchUnitPriceTC = tAPMatchingLnRefERS.tdMatchUnitPrice
           bERSProcessorRef.tdAPMatchingLnMatchUnitPriceTC = bERSProcessorRef.tdAPMatchingLnMatchUnitPriceLC
                                                           * tqPendingVoucherForERSDetail.tdpvod_ex_rate
                                                           / tqPendingVoucherForERSDetail.tdpvod_ex_rate2
           bERSProcessorRef.tdAPMatchingLnExtendedCostLC   = bERSProcessorRef.tdAPMatchingLnMatchQty
                                                           * bERSProcessorRef.tdAPMatchingLnMatchUnitPriceLC
           bERSProcessorRef.tdAPMatchingLnExtendedCostLC   = <M-6 RoundAmount
                                                                (input  bERSProcessorRef.tdAPMatchingLnExtendedCostLC (idUnroundedAmount), 
                                                                 input  viCompanyLCId (iiCurrencyID), 
                                                                 input  vcCompanyLC (icCurrencyCode)) in BERSProcessor>
           bERSProcessorRef.tdAPMatchingLnExtendedCostTC   = bERSProcessorRef.tdAPMatchingLnMatchQty
                                                           * bERSProcessorRef.tdAPMatchingLnMatchUnitPriceTC
           bERSProcessorRef.tdAPMatchingLnExtendedCostTC   = <M-7 RoundAmount
                                                                (input  bERSProcessorRef.tdAPMatchingLnExtendedCostTC (idUnroundedAmount), 
                                                                 input  ? (iiCurrencyID), 
                                                                 input  bERSProcessorRef.tcCInvoiceCurrencyCode (icCurrencyCode)) in BERSProcessor>.
    /* Substract tax included in the price */
    assign vdTaxIncludedInPriceLC = 0.

    <Q-19 run PendingVoucherForDetails (all) (Read) (NoCache)
       (input bERSProcessorRef.tcDomainCode, (Domain)
        input bERSProcessorRef.tiPvoId, (PvoID)
        input bERSProcessorRef.tiPvodLineId, (PvodIdLine)
        output dataset tqPendingVoucherForDetails) in BMfgPendingVoucher>

    find first tqPendingVoucherForDetails where
               tqPendingVoucherForDetails.tcpvo_domain   = bERSProcessorRef.tcDomainCode and
               tqPendingVoucherForDetails.tipvo_id       = bERSProcessorRef.tiPvoId      and
               tqPendingVoucherForDetails.tipvod_id_line = bERSProcessorRef.tiPvodLineId
               no-error.
    if available tqPendingVoucherForDetails
    then do:
        assign vcTx2dReference = tqPendingVoucherForDetails.tcpvo_internal_ref
               viTx2dLine      = tqPendingVoucherForDetails.tipvod_order_line
               vcTx2dOrder     = if tAPMatchingLnRefERS.tlIsLgCharge
                                 then tqPendingVoucherForDetails.tcpvo_lc_charge
                                 else tqPendingVoucherForDetails.tcpvo_order.
        <Q-85 run TaxDetailByKey (all) (Read) (NoCache)
           (input tqPendingVoucherForDetails.tcpvo_domain, (Tx2dDomain)
            input vcTx2dReference, (Tx2dReference)
            input vcTx2dOrder, (Tx2dNumber)
            input viTx2dLine, (Tx2dLine)
            input ?, (Tx2dTrailer)
            input ?, (Tx2dTransactionType)
            input ?, (Tx2dTaxCode)
            output dataset tqTaxDetailByKey) in BMfgTaxDetail>

        /* Go through all tax records of receiver and substract it from the price entered on receiver */
        for each tqTaxDetailByKey where
                 tqTaxDetailByKey.tctx2d_domain = tqPendingVoucherForDetails.tcpvo_domain                   AND
                 tqTaxDetailByKey.tctx2d_ref    = vcTx2dReference                                           AND
                 tqTaxDetailByKey.tctx2d_nbr    = vcTx2dOrder                                               AND
                 (tqTaxDetailByKey.tctx2d_tr_type = '45' or
                  tqTaxDetailByKey.tctx2d_tr_type = '43' or
                  tqTaxDetailByKey.tctx2d_tr_type = '21' or
                  tqTaxDetailByKey.tctx2d_tr_type = '27' or 
                  tqTaxDetailByKey.tctx2d_tr_type = '25' or
                  tqTaxDetailByKey.tctx2d_tr_type = '60' or
                  tqTaxDetailByKey.tctx2d_tr_type = '30' or
                  tqTaxDetailByKey.tctx2d_tr_type = '17') /* Legal document for PO Return */                AND
                  tqTaxDetailByKey.titx2d_line = viTx2dLine:
                   
            if tqTaxDetailByKey.tltx2d_tax_in
            then assign vdTaxIncludedInPriceLC = vdTaxIncludedInPriceLC
                                               + tqTaxDetailByKey.tdtx2d_cur_tax_amt.
        end.
    end.
    if tqPendingVoucherForDetails.tcpvo_curr = vcCompanyLC
    then assign vdTaxIncludedInPriceTC = vdTaxIncludedInPriceLC.
    else assign vdTaxIncludedInPriceTC = vdTaxIncludedInPriceLC * tqPendingVoucherForDetails.tdpvod_ex_rate / tqPendingVoucherForDetails.tdpvod_ex_rate2
                vdTaxIncludedInPriceTC = <M-90 RoundAmount
                                            (input  vdTaxIncludedInPriceTC (idUnroundedAmount), 
                                             input  ? (iiCurrencyID), 
                                             input  bERSProcessorRef.tcCInvoiceCurrencyCode (icCurrencyCode)) in BERSProcessor>.

    assign tAPMatchingLnRefERS.tdMatchUnitPrice = tAPMatchingLnRefERS.tdMatchUnitPrice 
                                                     - (if bERSProcessorRef.tlIsLogCharge
                                                        then vdTaxIncludedInPriceTC
                                                        else vdTaxIncludedInPriceTC / bERSProcessorRef.tdAPMatchingLnMatchQty).
end. /* if vcGroupBy = {&ERSPROCESSORINVGROUP-RECEIVER} */
else if vcGroupBy = {&ERSPROCESSORINVGROUP-LEGALDOC}
then assign tAPMatchingLnRefERS.tdMatchUnitPrice = bERSProcessorRef.tdAPMatchingLnMatchUnitPriceTC
            tAPMatchingLnRefERS.tlIsLgCharge     = bERSProcessorRef.tlIsLogCharge
            tAPMatchingLnRefERS.tdMatchUnitPrice = bERSProcessorRef.tdAPMLnMatchUnitPriceBaseTC.


/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.