project QadFinancials > class BAPMatching > method GetPendingVouchersNoLogCharges

Description

Submethod of GetPendingVouchers


Parameters


icAPMatchingTcRowidinputcharactericAPMatchingTcRowid: Rowid (converted to character) of the matching. This corresponds with field tAPMatching.tc_rowid.
icCreditorCodeinputcharacter
idCInvoiceTCLCRateinputdecimal
idCInvoiceTCLCScaleinputdecimal
idCInvoiceTCCCRateinputdecimal
idCInvoiceTCCCScaleinputdecimal
icCurrencyCodeinputcharacter
idCInvoiceTotalAmountTCinputdecimal
idCInvoiceARRecTaxTCinputdecimal
idCInvoiceARNRecTaxTCinputdecimal
itTransactionDateFrominputdate
itTransactionDateTillinputdate
itTransactionDateinputdate
itTransactionDetailDateFrominputdate
itTransactionDetailDateTillinputdate
itTransactionDetailDateinputdate
icExternalReferenceFrominputcharacter
icExternalReferenceToinputcharacter
icExternalReferenceinputcharacter
icInternalReferenceFrominputcharacter
icInternalReferenceToinputcharacter
icInternalReferenceinputcharacter
icShipToFrominputcharacter
icShipToToinputcharacter
icShipToinputcharacter
icItemNumberFrominputcharacter
icItemNumberToinputcharacter
icItemNumberinputcharacter
icBuyerinputcharacter
icApprovedByinputcharacter
icLogisticChargeFrominputcharacter
icLogisticChargeToinputcharacter
icLogisticChargeinputcharacter
icShipFromFrominputcharacter
icShipFromToinputcharacter
icShipFrominputcharacter
ilAutoSelectinputlogical
icPOShipperInvoiceinputcharacter
icOrderListinputcharacter
ilCallGTMinputlogicalilCallGTM: Set to true in case you want this method to call GTM to recalculate the taxes. If false, then the taxes will just be taken from the pending-voucher
iiApiPvodIDinputintegerPending voucher ID (in case of API integration)
iiApiPvodLineIdinputintegerPending voucher line ID (in case of API integration)
idApiMatchUnitPriceinputdecimalMatched unit price (in case of API integration)
idApiMatchQtyinputdecimalMatch quantity (in case of API integration)
ilApiIsPvodFinishedinputlogicalIs Pending voucher finished (in case of API integration)
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AddAPMatchingLnNoLC
method BAPMatching.GetPendingVouchers


program code (program7/bapmatching.p)

define variable doLegalDocByPvo as com.qad.eefin.bmfglegaldocument.GetLegalDocumentByPendVouch.


/* ============================================================================ */
/* Method:  GetPendingVouchersNoLogCharges                                      */
/* Desc:    Sub-method of GetPendingVouchers that handles no Logistic Charges   */
/* ============================================================================ */

/* ====================== */
/* Default return-status  */
/* ====================== */
assign oiReturnStatus = -98. 

<Q-5 assign vlFcQueryRecordsAvailable = CheckVertexIsEnabled (NoCache)
   (input vcDomainCode, (DomainCode)
    input {&VERTEX-MODULE}, (VertexModule)
    input {&VERTEX-FIELD}, (VertexField)
    input TRUE, (VertexLogical)) in BMfgControlWorkTable>
    
assign vlIsVertexEnabled = vlFcQueryRecordsAvailable.
/* =================================================================================================================== */
/* GetPendingVouchersNoLogChargesQuery: submethod of GetPendingVouchersNoLogCharges that holds the query-call to query */
/* BMfgPendingVoucher:PendingVoucherForMatchingNoLC(). This metthod can be used for customisations and thus provides   */
/* customers to take actions to extend the content of tqPendingVoucherForMatchingNoLC                                  */
/* After calling this submethod, temp-table tqPendingVoucherForMatchingNoLC will be filled                             */
/* =================================================================================================================== */
<M-65 run GetPendingVouchersNoLogChargesQuery
   (input  icAPMatchingTcRowid (icAPMatchingTcRowid), 
    input  icCreditorCode (icCreditorCode), 
    input  idCInvoiceTCLCRate (idCInvoiceTCLCRate), 
    input  idCInvoiceTCLCScale (idCInvoiceTCLCScale), 
    input  idCInvoiceTCCCRate (idCInvoiceTCCCRate), 
    input  idCInvoiceTCCCScale (idCInvoiceTCCCScale), 
    input  icCurrencyCode (icCurrencyCode), 
    input  idCInvoiceTotalAmountTC (idCInvoiceTotalAmountTC), 
    input  idCInvoiceARRecTaxTC (idCInvoiceARRecTaxTC), 
    input  idCInvoiceARNRecTaxTC (idCInvoiceARNRecTaxTC), 
    input  itTransactionDateFrom (itTransactionDateFrom), 
    input  itTransactionDateTill (itTransactionDateTill), 
    input  itTransactionDate (itTransactionDate), 
    input  itTransactionDetailDateFrom (itTransactionDetailDateFrom), 
    input  itTransactionDetailDateTill (itTransactionDetailDateTill), 
    input  itTransactionDetailDate (itTransactionDetailDate), 
    input  icExternalReferenceFrom (icExternalReferenceFrom), 
    input  icExternalReferenceTo (icExternalReferenceTo), 
    input  icExternalReference (icExternalReference), 
    input  icInternalReferenceFrom (icInternalReferenceFrom), 
    input  icInternalReferenceTo (icInternalReferenceTo), 
    input  icInternalReference (icInternalReference), 
    input  icShipToFrom (icShipToFrom), 
    input  icShipToTo (icShipToTo), 
    input  icShipTo (icShipTo), 
    input  icItemNumberFrom (icItemNumberFrom), 
    input  icItemNumberTo (icItemNumberTo), 
    input  icItemNumber (icItemNumber), 
    input  icBuyer (icBuyer), 
    input  icApprovedBy (icApprovedBy), 
    input  icLogisticChargeFrom (icLogisticChargeFrom), 
    input  icLogisticChargeTo (icLogisticChargeTo), 
    input  icLogisticCharge (icLogisticCharge), 
    input  icShipFromFrom (icShipFromFrom), 
    input  icShipFromTo (icShipFromTo), 
    input  icShipFrom (icShipFrom), 
    input  ilAutoSelect (ilAutoSelect), 
    input  icPOShipperInvoice (icPOShipperInvoice), 
    input  icOrderList (icOrderList), 
    input  ilCallGTM (ilCallGTM), 
    input  iiApiPvodID (iiApiPvodID), 
    input  iiApiPvodLineId (iiApiPvodLineId), 
    input  idApiMatchUnitPrice (idApiMatchUnitPrice), 
    input  idApiMatchQty (idApiMatchQty), 
    input  ilApiIsPvodFinished (ilApiIsPvodFinished), 
    output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then Return.

/* =============================================== */
/* Go through the query its result-set             */
/* =============================================== */
for each tqPendingVoucherForMatchingNoLC
        break by tqPendingVoucherForMatchingNoLC.tcpvod_domain
              by tqPendingVoucherForMatchingNoLC.tipvod_id
              by tqPendingVoucherForMatchingNoLC.tipvod_id_line
              by tqPendingVoucherForMatchingNoLC.tltx2_tax_in:

    /* =============================================== */
    /* Skip PVO's on companies you dont have access to */
    /* =============================================== */
    if (tqPendingVoucherForMatchingNoLC.tcPOMstrCompanyCode <> ?              and 
        tqPendingVoucherForMatchingNoLC.tcPOMstrCompanyCode <> "":U           and
        not can-do(vcListAccessibleCompanyCodes,tqPendingVoucherForMatchingNoLC.tcPOMstrCompanyCode)) or
       (tqPendingVoucherForMatchingNoLC.tcPOMstrCompanyCode <> ?              and 
        tqPendingVoucherForMatchingNoLC.tcPOMstrCompanyCode <> "":U           and
        not can-do(vcListAccessibleCompanyCodes,tqPendingVoucherForMatchingNoLC.tcPODDetCompanyCode))
    then do:
        if iiApiPvodID <> ? and /* in case of API integration, raise an error */
           iiApiPvodID <> 0
        then do:                   
            assign oiReturnStatus  = -3
                   vcMsgAPMatching = trim(substitute(#T-7'The system cannot create a matching line because the pending invoice (&1/&2/&3) references an entity (&4) that you do not have access to.':255(70326)T-7#,tqPendingVoucherForMatchingNoLC.tcpvo_domain,string(tqPendingVoucherForMatchingNoLC.tipvo_id),string(tqPendingVoucherForMatchingNoLC.tipvod_id_line),(if tqPendingVoucherForMatchingNoLC.tcPOMstrCompanyCode <> ? and tqPendingVoucherForMatchingNoLC.tcPOMstrCompanyCode <> "":U then tqPendingVoucherForMatchingNoLC.tcPOMstrCompanyCode else tqPendingVoucherForMatchingNoLC.tcPODDetCompanyCode))).
            <M-63 run SetMessage
               (input  vcMsgAPMatching (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-789000':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        end. /* if iiApiPvodID <> ? and */
        next.
    end. /* if (tqPendingVoucherForMatchingNoLC.tcPOMstrCompanyCode <> ? and  */
    
    /* ======================================================================== */
    /* Retrieved pending vouchers can be linked to purchase ledger invoice      */
    /* Number of this purchase ledger invocie and supplier invoice reference    */
    /* has to match                                                             */
    /* ======================================================================== */
    if tqPendingVoucherForMatchingNoLC.tcpli_invoice <> ?    and
       tqPendingVoucherForMatchingNoLC.tcpli_invoice <> '':U and
       tqPendingVoucherForMatchingNoLC.tcpli_invoice <> icPOShipperInvoice
    then do:
        if iiApiPvodID <> ? and /* in case of API integration, raise an error */
           iiApiPvodID <> 0
        then do:
            assign oiReturnStatus  = -3
                   vcMsgAPMatching = trim(substitute(#T-32'The system cannot create a matching line because the pending invoice (&1/&2/&3) refers to a PL Invoice and the reference of the PL invoice (&4) differs from the reference (&5) of the matched invoice.':255(70328)T-32#,tqPendingVoucherForMatchingNoLC.tcpvo_domain,string(tqPendingVoucherForMatchingNoLC.tipvo_id),string(tqPendingVoucherForMatchingNoLC.tipvod_id_line),tqPendingVoucherForMatchingNoLC.tcpli_invoice,tAPMatching.tcCInvoiceReference)).
            <M-33 run SetMessage
               (input  vcMsgAPMatching (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-769684':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        end. /* if iiApiPvodID <> ? */
        next.
    end. /* if tqPendingVoucherForMatchingNoLC.tcpli_invoice <> ? */

    /* =========================================================================================== */
    /* Create output records for matching line                                                     */
    /* Do not set the Quantities, Prices etc yet as in case of tax-included, the taxes need to be  */
    /* subtracted from the pvod-price to come to the naked value of the goods and that can only be */
    /* done once we have passed all tax-details: this will thus be done with the 'last-of' option  */
    /* The creation and assigment of most other prtoperties assings here already as we need this   */
    /* record to be here when creating the underlaying tax-details                                 */
    /* =========================================================================================== */
    if first-of (tqPendingVoucherForMatchingNoLC.tipvod_id_line)
    then do :            
        /* ======================================== */
        /* Create output records for matching line  */
        /* ======================================== */
        create tPendingVoucherAPM.
        assign tPendingVoucherAPM.APMatchingLnPvodIsLgCharge  = false
               tPendingVoucherAPM.APMatchingLnPvodLgCharge    = "":U
               tPendingVoucherAPM.APMatchingLnIsPvodFinished  = ilAutoSelect
               tPendingVoucherAPM.APMatchingLnIsVarGLPosting  = true
               tPendingVoucherAPM.APMatchingLnPvodCCCode      = tqPendingVoucherForMatchingNoLC.tcpvo_accrual_cc
               tPendingVoucherAPM.APMatchingLnPvodPrjCode     = tqPendingVoucherForMatchingNoLC.tcpvod_project
               tPendingVoucherAPM.APMatchingLnPvodDivCode     = tqPendingVoucherForMatchingNoLC.tcpvo_accrual_sub
               tPendingVoucherAPM.APMatchingLnPvodExchRate    = tqPendingVoucherForMatchingNoLC.tdpvod_ex_rate
               tPendingVoucherAPM.APMatchingLnPvodExchRate2   = tqPendingVoucherForMatchingNoLC.tdpvod_ex_rate2
               tPendingVoucherAPM.APMatchingLnPvodGLCode      = tqPendingVoucherForMatchingNoLC.tcpvo_accrual_acct
               tPendingVoucherAPM.PvodLineID                  = tqPendingVoucherForMatchingNoLC.tipvod_id_line
               tPendingVoucherAPM.PvoDomain                   = tqPendingVoucherForMatchingNoLC.tcpvo_domain
               tPendingVoucherAPM.PvoID                       = tqPendingVoucherForMatchingNoLC.tipvo_id
               tPendingVoucherAPM.tcGLCode                    = tqPendingVoucherForMatchingNoLC.tcpvo_accrual_acct
               tPendingVoucherAPM.tcDivisionCode              = tqPendingVoucherForMatchingNoLC.tcpvo_accrual_sub
               tPendingVoucherAPM.tcCostCentreCode            = tqPendingVoucherForMatchingNoLC.tcpvo_accrual_cc
               tPendingVoucherAPM.tcProjectCode               = tqPendingVoucherForMatchingNoLC.tcpvo_project
               tPendingVoucherAPM.APMatchingLnPvodCurrency    = tqPendingVoucherForMatchingNoLC.tcpvo_curr
               tPendingVoucherAPM.APMatchingLnPvodExtRef      = substring(tqPendingVoucherForMatchingNoLC.tcpvo_external_ref,1,50,'character':U)
               tPendingVoucherAPM.APMatchingLnPvodIntRef      = substring(tqPendingVoucherForMatchingNoLC.tcpvo_internal_ref,1,50,'character':U)
               tPendingVoucherAPM.APMatchingLnPvodItem        = tqPendingVoucherForMatchingNoLC.tcpvo_part
               tPendingVoucherAPM.APMatchingLnPvodItemDescr1  = (if tqPendingVoucherForMatchingNoLC.tcprh_type = "M":U
                                                                then substring(tqPendingVoucherForMatchingNoLC.tcpod_desc,1,24,'character':U)
                                                                else substring(tqPendingVoucherForMatchingNoLC.tcpt_desc1,1,24,'character':U))
               tPendingVoucherAPM.APMatchingLnPvodItemDescr2  = substring(tqPendingVoucherForMatchingNoLC.tcpt_desc2,1,24,'character':U)
               tPendingVoucherAPM.APMatchingLnPvodSupplItem   = tqPendingVoucherForMatchingNoLC.tcpod_vpart
               tPendingVoucherAPM.APMatchingLnPvodUoM         = (if tqPendingVoucherForMatchingNoLC.tcprh_um = ? then "":U else tqPendingVoucherForMatchingNoLC.tcprh_um)
               tPendingVoucherAPM.APMatchingLnPvodUomConv     = (if tqPendingVoucherForMatchingNoLC.tdprh_um_conv = ? then 1 else tqPendingVoucherForMatchingNoLC.tdprh_um_conv)
               tPendingVoucherAPM.APMatchingLnPvodTransDate   = tqPendingVoucherForMatchingNoLC.ttpvod_trans_date
               tPendingVoucherAPM.ttAPMatchingLnPvodEffDate   = tqPendingVoucherForMatchingNoLC.ttpvod_eff_date
               tPendingVoucherAPM.APMatchingLnPvodOrder       = tqPendingVoucherForMatchingNoLC.tcpvo_order
               tPendingVoucherAPM.APMatchingLnPvodOrderLnNbr  = tqPendingVoucherForMatchingNoLC.tipvo_line
               tPendingVoucherAPM.APMatchingLnPvodOrderType   = (if tqPendingVoucherForMatchingNoLC.tcpvo_order_type = {&PENDINGVOUCHER-ORDERTYPE-DO}
                                                                then {&APMATCHINGLNPVODORDERTYPE-DISTRIB}
                                                                else if tqPendingVoucherForMatchingNoLC.tcpvo_order_type = {&PENDINGVOUCHER-ORDERTYPE-SO}
                                                                     then {&APMATCHINGLNPVODORDERTYPE-SALES}
                                                                     else {&APMATCHINGLNPVODORDERTYPE-PURCHASE})
               tPendingVoucherAPM.APMatchingLnPvodItemType    = if tqPendingVoucherForMatchingNoLC.tcprh_type = "":U
                                                               then {&APMATCHINGLNPVODITEMTYPE-NORMAL}
                                                               else if tqPendingVoucherForMatchingNoLC.tcprh_type = "S":U
                                                                    then {&APMATCHINGLNPVODITEMTYPE-SUBCONTRACT}
                                                                    else {&APMATCHINGLNPVODITEMTYPE-MEMO}
               tPendingVoucherAPM.APMatchingLnPvodReceiptQty  = tqPendingVoucherForMatchingNoLC.tdpvod_trans_qty
               tPendingVoucherAPM.APMatchingLnPvodSite        = (if tqPendingVoucherForMatchingNoLC.tcprh_site = ? then "":U else tqPendingVoucherForMatchingNoLC.tcprh_site)
               tPendingVoucherAPM.APMatchingLnPvodConvFactor  = (if tqPendingVoucherForMatchingNoLC.tdprh_um_conv = ? then 1 else tqPendingVoucherForMatchingNoLC.tdprh_um_conv)
               tPendingVoucherAPM.APMatchingLnPvodCompCode    = (if tqPendingVoucherForMatchingNoLC.tcPODDetCompanyCode <> ? and tqPendingVoucherForMatchingNoLC.tcPODDetCompanyCode <> "":U then tqPendingVoucherForMatchingNoLC.tcPODDetCompanyCode else tqPendingVoucherForMatchingNoLC.tcPOMstrCompanyCode)
               tPendingVoucherAPM.APMatchingLnPvodCompID      = (if tqPendingVoucherForMatchingNoLC.tiPOMstrCompanyID <> ? and tqPendingVoucherForMatchingNoLC.tiPOMstrCompanyID <> 0 then tqPendingVoucherForMatchingNoLC.tiPOMstrCompanyID else tqPendingVoucherForMatchingNoLC.tiPODDetCompanyID)
               tPendingVoucherAPM.APMatchingLnPvodPliKeyId    = tqPendingVoucherForMatchingNoLC.tipli_keyid
               tPendingVoucherAPM.APMatchingLnPvodPlidLine    = tqPendingVoucherForMatchingNoLC.tiplid_line
               tPendingVoucherAPM.APMatchingLnPvodPackingQty  = tqPendingVoucherForMatchingNoLC.tdprh_ps_qty
               tPendingVoucherAPM.APMatchingLnPvodIsTaxable   = (if tqPendingVoucherForMatchingNoLC.tlpvo_taxable = ? then false else tqPendingVoucherForMatchingNoLC.tlpvo_taxable)
               tPendingVoucherAPM.APMatchingLnPvodTaxEnv      = (if tqPendingVoucherForMatchingNoLC.tctx2d_tax_env = ? then "":U else tqPendingVoucherForMatchingNoLC.tctx2d_tax_env)
               tPendingVoucherAPM.APMatchingLnPvodTaxClass    = (if tqPendingVoucherForMatchingNoLC.tctx2d_taxc = ? then "":U else tqPendingVoucherForMatchingNoLC.tctx2d_taxc)
               tPendingVoucherAPM.APMatchingLnPvodTaxUsage    = (if tqPendingVoucherForMatchingNoLC.tctx2d_tax_usage = ? then "":U else tqPendingVoucherForMatchingNoLC.tctx2d_tax_usage)
               tPendingVoucherAPM.APMatchingLnPvodSupplier    = tqPendingVoucherForMatchingNoLC.tcpvo_supplier
               tPendingVoucherAPM.APMatchingLnPvodPayCond     = tqPendingVoucherForMatchingNoLC.tcpo_cr_terms
               tPendingVoucherAPM.APMatchingLnIsTaxable       = tPendingVoucherAPM.APMatchingLnPvodIsTaxable
               tPendingVoucherAPM.APMatchingLnTaxEnv          = tPendingVoucherAPM.APMatchingLnPvodTaxEnv
               tPendingVoucherAPM.APMatchingLnTaxClass        = tPendingVoucherAPM.APMatchingLnPvodTaxClass
               tPendingVoucherAPM.APMatchingLnTaxUsage        = tPendingVoucherAPM.APMatchingLnPvodTaxUsage
               tPendingVoucherAPM.tlIsNeededToRecallGTM       = false
               tPendingVoucherAPM.APMatchingLnPvodInvoicedTC  = tqPendingVoucherForMatchingNoLC.tdpvo_vouchered_amt
               tPendingVoucherAPM.APMatchingLnPvodAccruedTC   = tqPendingVoucherForMatchingnoLC.tdpvo_accrued_amt 
               tPendingVoucherAPM.tlIsSelected                = ilautoselect
               tPendingVoucherAPM.tc_Status                   = "N":U
               tPendingVoucherAPM.tc_Rowid                    = string(viRowidPendingVoucherAPM)
               tPendingVoucherAPM.APMatchingLnPvodFromTaxZone = (if vlIsVertexEnabled then tqPendingVoucherForMatchingNoLC.tctx2d_zone_from else "":U)
               tPendingVoucherAPM.APMatchingLnPvodToTaxZone   = (if vlIsVertexEnabled then tqPendingVoucherForMatchingNoLC.tctx2d_zone_to else "":U)
               viRowidPendingVoucherAPM                       = viRowidPendingVoucherAPM + 1. 


        /* ================================================ */
        /* Check if accrual account is not an Op Alloc Code */
        /* tcGLCode and APMatchingLnPvodGLCode are the same */
        /* ================================================ */               
        if tPendingVoucherAPM.tcGLCode <> ? and
           tPendingVoucherAPM.tcGLCode <> "":U
        then do:
            /* check if there is an allocation code for this. We use a find first with caching on */
            <Q-96 run AlMstrByDomainCode (first) (Read) (Cache)
               (input tPendingVoucherAPM.PvoDomain, (Domain)
                input tPendingVoucherAPM.tcGLCode, (Code)
                output dataset tqAlMstrByDomainCode) in BMfgAllocationAccount>
               
            if can-find (first tqAlMstrByDomainCode where
                               tqAlMstrByDomainCode.tcal_domain = tPendingVoucherAPM.PvoDomain and
                               tqAlMstrByDomainCode.tcal_code   = tPendingVoucherAPM.tcGLCode)   
            then assign tPendingVoucherAPM.APMatchingLnPvodOpAllocCode = tPendingVoucherAPM.tcGLCode
                        tPendingVoucherAPM.APMatchingLnOpAllocCode     = tPendingVoucherAPM.tcGLCode
                        tPendingVoucherAPM.tcGLCode                    = "":U
                        tPendingVoucherAPM.APMatchingLnPvodGLCode      = "":U.
            else assign tPendingVoucherAPM.APMatchingLnPvodOpAllocCode = "":U
                        tPendingVoucherAPM.APMatchingLnOpAllocCode     = "":U.
                        
        end. /* if tPendingVoucherAPM.tcGLCode <> ? and */
                       
        /* =============================================== */
        /* Set Taxable to false in case there are no taxes */
        /* =============================================== */
        if tPendingVoucherAPM.APMatchingLnPvodIsTaxable = true          and
           (tqPendingVoucherForMatchingNoLC.tctx2d_tax_env   = ? or
            tqPendingVoucherForMatchingNoLC.tctx2d_tax_env   = "":U)    and
           (tqPendingVoucherForMatchingNoLC.tctx2d_taxc      = ? or
            tqPendingVoucherForMatchingNoLC.tctx2d_taxc      = "":U)    and 
           (tqPendingVoucherForMatchingNoLC.tctx2d_tax_usage = ? or
            tqPendingVoucherForMatchingNoLC.tctx2d_tax_usage = "":U)
        then assign tPendingVoucherAPM.APMatchingLnPvodIsTaxable = false
                    tPendingVoucherAPM.APMatchingLnIsTaxable     = false.
                    
        /* ========================== */
        /* Reset the sum of the taxes */
        /* ========================== */
        assign vdSumTaxesWithTaxIncluded = 0.
        
    end. /* if first-of (tqPendingVoucherForMatchingNoLC.tipvod_id_line) */

    /* ============ */
    /* Tax handling */
    /* ============ */
    if tqPendingVoucherForMatchingNoLC.tctx2_tax_code <> ?    and 
       tqPendingVoucherForMatchingNoLC.tctx2_domain   <> ?    and
       tqPendingVoucherForMatchingNoLC.tctx2_tax_code <> "":U and 
       tqPendingVoucherForMatchingNoLC.tctx2_domain   <> "":U  
    then do :
        /* ============================================================================================================================================= */        
        /* If this method is called from the UI (iiApiPvodID is empty) then we set AutoSelect to true in case it was unknown (this should never happen)  */
        /* If this method is called from EDI or ERS (iiApiPvodID is filled) and AutoSelect is unknown,                                                   */
        /* then: when the Price and Qty of the input match the values of the PVO then we set AutoSelect to true                                          */
        /*       when the Price and Qty of the input differs from the values of the PVO then we set AutoSelect to false - as then GTM aught to be called */
        /* ============================================================================================================================================= */
        if iiApiPvodID = ? or 
           iiApiPvodID = 0
        then assign vlAutoSelectForTheTaxAndWHT = (if ilAutoSelect = ? then true else ilAutoSelect).
        else if ilAutoSelect = ?
             then assign vlAutoSelectForTheTaxAndWHT = TRUE.
             else assign vlAutoSelectForTheTaxAndWHT = ilAutoSelect.

        /* =========================================================== */
        /* Call submethod that will create the underlaying tax-details */
        /* =========================================================== */
        <M-28 run GetPendingVouchersNoLogChargesTax
           (input  vlAutoSelectForTheTaxAndWHT (ilAutoSelect), 
            input  ilCallGTM (ilCallGTM), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then Return.
        /* ============================= */
        /* Increase the sum of the taxes */
        /* ============================= */
        if tqPendingVoucherForMatchingNoLC.tltx2_tax_in = true
        then
        assign vdSumTaxesWithTaxIncluded = vdSumTaxesWithTaxIncluded  + tqPendingVoucherForMatchingNoLC.tdtx2d_cur_tax_amt.
    end. /* if tqPendingVoucherForMatchingNoLC.tctx2_tax_code <> ? and */

    /* ================================================================================================ */
    /* Update details for the output records for the matching line                                      */
    /* Setting the Quantities, Prices etc can only be done here and net on in the 'first-of as in case  */ 
    /* of tax-included, the taxes need to be subtracted from the pvod-price to come to the naked value  */
    /* of the goods and that can only be done once we have passed all tax-details                       */
    /* ================================================================================================ */
    if last-of (tqPendingVoucherForMatchingNoLC.tipvod_id_line)
    then do :
        /* ================================ */
        /* Assign the Prices and Quantities */
        /* ================================ */
        if iiApiPvodID = ? or 
           iiApiPvodID = 0
        then do: /* Data are queried from the UI */
            assign tPendingVoucherAPM.APMatchingLnPvodOpenQty    = tqPendingVoucherForMatchingNoLC.tdpvod_trans_qty - tqPendingVoucherForMatchingNoLC.tdpvod_vouchered_qty
                   tPendingVoucherAPM.APMatchingLnMatchQty       = if ilAutoSelect
                                                                   then tPendingVoucherAPM.APMatchingLnPvodOpenQty
                                                                   else 0
                   tPendingVoucherAPM.APMatchingLnPvodUnitPrice  = if tqPendingVoucherForMatchingNoLC.tdprh_curr_amt <> ? 
                                                                   then tqPendingVoucherForMatchingNoLC.tdprh_curr_amt *
                                                                        (if tqPendingVoucherForMatchingNoLC.tdprh_um_conv = ? then 1 else tqPendingVoucherForMatchingNoLC.tdprh_um_conv) 
                                                                   else tqPendingVoucherForMatchingNoLC.tdpvod_pur_cost *
                                                                        (if tqPendingVoucherForMatchingNoLC.tdprh_um_conv = ? then 1 else tqPendingVoucherForMatchingNoLC.tdprh_um_conv) *
                                                                         tqPendingVoucherForMatchingNoLC.tdpvod_ex_rate /
                                                                         tqPendingVoucherForMatchingNoLC.tdpvod_ex_rate2. 

            if tqPendingVoucherForMatchingNoLC.tltx2d_tax_in     = true and 
               tqPendingVoucherForMatchingNoLC.tdpvod_trans_qty <> 0 and 
               tqPendingVoucherForMatchingNoLC.tdpvod_trans_qty <> ?
            then assign tPendingVoucherAPM.APMatchingLnPvodUnitPrice = tPendingVoucherAPM.APMatchingLnPvodUnitPrice - 
                                                                      (vdSumTaxesWithTaxIncluded  / tqPendingVoucherForMatchingNoLC.tdpvod_trans_qty). /* vdSumTaxesWithTaxIncluded is the total tax of the receipt and pvod_trans_qty is the receipt qty */
            assign tPendingVoucherAPM.APMatchingLnMatchUnitPrice = if ilAutoSelect
                                                                   then tPendingVoucherAPM.APMatchingLnPvodUnitPrice
                                                                   else 0
                   tPendingVoucherAPM.APMatchingLnPvodOpenAmtTC  = <M-64 RoundAmount
                                                                      (input  tPendingVoucherAPM.APMatchingLnPvodOpenQty * tPendingVoucherAPM.APMatchingLnPvodUnitPrice (idUnroundedAmount), 
                                                                       input  ? (iiCurrencyID), 
                                                                       input  tqPendingVoucherForMatchingNoLC.tcpvo_curr (icCurrencyCode)) in business>
                   tPendingVoucherAPM.APMatchingLnMatchAmtTC     = if ilAutoSelect
                                                                   then tPendingVoucherAPM.APMatchingLnPvodOpenAmtTC
                                                                   else 0
                   tPendingVoucherAPM.APMatchingLnMatchAmtLC     = <M-90 RoundAmount
                                                                      (input  tPendingVoucherAPM.APMatchingLnMatchAmtTC * tqPendingVoucherForMatchingNoLC.tdpvod_ex_rate / tqPendingVoucherForMatchingNoLC.tdpvod_ex_rate2 (idUnroundedAmount), 
                                                                       input  viCompanyLCId (iiCurrencyID), 
                                                                       input  ? (icCurrencyCode)) in BApplicationProperty>.                                                                      
        end. /* if iiApiPvodID = ? or iiApiPvodID = 0 */
        else do: /* Data are queried from the API */
            assign tPendingVoucherAPM.APMatchingLnPvodOpenQty    = tqPendingVoucherForMatchingNoLC.tdpvod_trans_qty - tqPendingVoucherForMatchingNoLC.tdpvod_vouchered_qty
                   tPendingVoucherAPM.APMatchingLnMatchQty       = idApiMatchQty
                   tPendingVoucherAPM.APMatchingLnPvodUnitPrice  = if tqPendingVoucherForMatchingNoLC.tdprh_curr_amt <> ? 
                                                                   then tqPendingVoucherForMatchingNoLC.tdprh_curr_amt *
                                                                        (if tqPendingVoucherForMatchingNoLC.tdprh_um_conv = ? then 1 else tqPendingVoucherForMatchingNoLC.tdprh_um_conv) 
                                                                   else tqPendingVoucherForMatchingNoLC.tdpvod_pur_cost *
                                                                        (if tqPendingVoucherForMatchingNoLC.tdprh_um_conv = ? then 1 else tqPendingVoucherForMatchingNoLC.tdprh_um_conv) *
                                                                         tqPendingVoucherForMatchingNoLC.tdpvod_ex_rate /
                                                                         tqPendingVoucherForMatchingNoLC.tdpvod_ex_rate2.                                                                    

                   tPendingVoucherAPM.APMatchingLnMatchUnitPrice = idApiMatchUnitPrice.
                                                                                     
            if tqPendingVoucherForMatchingNoLC.tltx2d_tax_in     = true and 
               tqPendingVoucherForMatchingNoLC.tdpvod_trans_qty <> 0 and 
               tqPendingVoucherForMatchingNoLC.tdpvod_trans_qty <> ?
            then assign tPendingVoucherAPM.APMatchingLnPvodUnitPrice = tPendingVoucherAPM.APMatchingLnPvodUnitPrice - 
                                                                      (vdSumTaxesWithTaxIncluded  / tqPendingVoucherForMatchingNoLC.tdpvod_trans_qty). /* vdSumTaxesWithTaxIncluded is the total tax of the receipt and pvod_trans_qty is the receipt qty */

            assign tPendingVoucherAPM.APMatchingLnPvodOpenAmtTC  = <M-2 RoundAmount
                                                                      (input  tPendingVoucherAPM.APMatchingLnPvodOpenQty * tPendingVoucherAPM.APMatchingLnPvodUnitPrice (idUnroundedAmount), 
                                                                       input  ? (iiCurrencyID), 
                                                                       input  tqPendingVoucherForMatchingNoLC.tcpvo_curr (icCurrencyCode)) in business>
                   tPendingVoucherAPM.APMatchingLnMatchAmtTC     = <M-75 RoundAmount
                                                                      (input   tPendingVoucherAPM.APMatchingLnMatchQty * tpendingvoucherAPM.APMatchingLnMatchUnitPrice (idUnroundedAmount), 
                                                                       input  ? (iiCurrencyID), 
                                                                       input  tqPendingVoucherForMatchingNoLC.tcpvo_curr (icCurrencyCode)) in BApplicationProperty>
                   tPendingVoucherAPM.APMatchingLnMatchAmtLC     = ?
                   tPendingVoucherAPM.APMatchingLnIsPvodFinished = ilApiIsPvodFinished.
            
            /* Get the exchange rate from the legal document if fiscal receiving is active and in case of foreign currency */
            if vlDomainIsFiscalConfirm and
               tqPendingVoucherForMatchingNoLC.tcpvo_curr <> vcCompanyLC
            then do:     
                do on error undo, leave:
                    doLegalDocByPvo = new com.qad.eefin.bmfglegaldocument.GetLegalDocumentByPendVouch(tPendingVoucherAPM.PvoDomain,
                                                                                                      tPendingVoucherAPM.PvoID,
                                                                                                      tPendingVoucherAPM.PvodLineID).
                    if doLegalDocByPvo:available
                    then assign tPendingVoucherAPM.APMatchingLnMatchAmtLC = <M-12 RoundAmount
                                                                               (input  tPendingVoucherAPM.APMatchingLnMatchAmtTC * doLegalDocByPvo:lgd_ex_rate2 / doLegalDocByPvo:lgd_ex_rate (idUnroundedAmount), 
                                                                                input  viCompanyLCId (iiCurrencyID), 
                                                                                input  ? (icCurrencyCode)) in BApplicationProperty>.
                                                                                
                    finally:
                        if valid-object(doLegalDocByPvo) then delete object doLegalDocByPvo no-error.
                    end finally.                                                                                
                end. /* do on error undo, leave: */                                                    
            end.
            
            if tPendingVoucherAPM.APMatchingLnMatchAmtLC = ?
            then assign tPendingVoucherAPM.APMatchingLnMatchAmtLC = <M-91 RoundAmount
                                                                       (input  tPendingVoucherAPM.APMatchingLnMatchAmtTC * tqPendingVoucherForMatchingNoLC.tdpvod_ex_rate2 / tqPendingVoucherForMatchingNoLC.tdpvod_ex_rate (idUnroundedAmount), 
                                                                        input  viCompanyId (iiCurrencyID), 
                                                                        input  ? (icCurrencyCode)) in BAPMatching>.

        end. /* Not if iiApiPvodID = ? or iiApiPvodID = 0 */
        /* =========================================================================== */
        /* Call - via a submethod - method in BCosting the returns the costing methods */
        /* =========================================================================== */
        <M-59 run GetPendingVouchersAssignCostMethodsCCRate
           (input  icAPMatchingTcRowid (icAPMatchingTcRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then Return.
        /* ==================================================================================== */
        /* Compose the Amount and the Qty of this Pvod that is located on other APMatchingLines */
        /* linked to this Pvod and with APMatching.APMatchingStatus = Initial                   */
        /* The field that are assigned here, exist just for informational reasons (no BL-logic) */
        /* ==================================================================================== */
        <M-16 run GetPendingVouchersAssignPendingMatchFields
           (input  icAPMatchingTcRowid (icAPMatchingTcRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then Return.
    end. /* if last-of (tqPendingVoucherForMatchingNoLC.tipvod_id_line) */
    
end. /* for each tqPendingVoucherForMatchingNoLC: */

/* ================================================================================================================ *
 * When this method is called for Fiscal receipts, we have to get correct taxes based on Fiscal receipt             *
 * ================================================================================================================ */
if vlDomainIsFiscalConfirm
then do:
    <M-93 run GetPendingVouchersNoLogChargesTaxFiscal
       (input  true (ilAutoSelect), 
        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    if viFcReturnSuper <> 0 and oiReturnStatus >= 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 then Return.
end. /* if vlDomainIsFiscalConfirm */

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