project QadFinancials > class BAPMatching > method GetPendingVouchersPOShipper

Description

Get pending vouchers which are related to purchase order shipper invoice.


Parameters


icAPMatchingTcRowidinputcharactericAPMatchingTcRowid: Rowid (converted to character) of the matching. This corresponds with field tAPMatching.tc_rowid.
icPOShipperInvoiceinputcharacter
icSupplierinputcharacter
ilAutoSelectinputlogical
idCInvoiceTCLCRateinputdecimal
idCInvoiceTCLCScaleinputdecimal
idCInvoiceTCCCRateinputdecimal
idCInvoiceTCCCScaleinputdecimal
idCInvoiceTotalAmountTCinputdecimal
idCInvoiceARRecTaxTCinputdecimal
idCInvoiceARNRecTaxTCinputdecimal
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
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.GetPendingVouchers


program code (program7/bapmatching.p)

/* ===================================================================================== */
/* Method:    GetPendingVouchersPOShipper                                                */
/* Desc:      Get pending vouchers which are related to purchase order shipper invoice.  */
/*            Pending vouchers linked to POShipper cannot be modified on user interface  */
/*            and therefore all values are defaulted                                     */
/* Result:    Result is stored in temporary table tPendingVoucherAPM                     */
/* ===================================================================================== */

/* ====================== */
/* Default return-status  */
/* ====================== */
if icPOShipperInvoice = '':U then return.
assign oiReturnStatus = -98.
<Q-31 run CheckVertexIsEnabled (all) (Read) (NoCache)
   (input vcDomainCode, (DomainCode)
    input {&VERTEX-MODULE}, (VertexModule)
    input {&VERTEX-FIELD}, (VertexField)
    input TRUE, (VertexLogical)
    output dataset tqCheckVertexIsEnabled) in BMfgControlWorkTable>

assign vlIsVertexEnabled = vlFcQueryRecordsAvailable.
/* ===================================================================== */
/* Check whether for all purchase leger invoice lines                    */
/* exist pending voucher  (these are PLID_DET lines with plid_pvo_id = 0 */
/* Workaround - value -999999 is converted to 0 in query                 */
/* ===================================================================== */
<Q-8 assign vlFcQueryRecordsAvailable = PLInvoiceDetailForMatching (NoCache)
   (input vcDomainCode, (DomainCode)
    input -999999, (PvoID)
    input icPOShipperInvoice, (POShipperInvoice)) in BMfgPLInvoice >
if not (vlFcQueryRecordsAvailable = false)
then do:
    assign vcMessageText = #T-9'There are Accounts Payable invoice lines with missing receipts. You can only perform matching for fully-receipted invoices.':255(56774)T-9#.
    <M-10 run SetMessage
       (input  vcMessageText (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-5792':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    assign oiReturnStatus = -1.
    return.
end.

/* ==================================================== */
/* retrieve all pending vouchers linked with PO Shipper */
/* ==================================================== */
<Q-78 run PLInvoiceForMatchingPvo (all) (Read) (NoCache)
   (input vcDomainCode, (DomainCode)
    input ?, (CompanyId)
    input icPOShipperInvoice, (POShipperInvoice)
    input icSupplier, (Supplier)
    input ?, (PliKeyId)
    output dataset tqPLInvoiceForMatchingPvo) in BMfgPLInvoice>

/* ====================================================================================================== */
/* Specific actions required in case a PVO is originated from the Fiscal Receiving                        */
/* Pending vouchers originated from Fiscal Receiving can be distinguished by this:                        */
/*     pvo_mstr.pvo_external_ref consists of two comma-sep entries (where the first                       */
/*     entry is the LegalDocumentNumber and the second one is the transaction/effective-date)             */
/* For PVO's originated from the Fiscal Receiving this query will only return the taxes belonging to the  */
/* POReceipt that preceeded the Fiscal Receipt.                                                           */
/* As adapting the query to return the correct underlying taxes was not feasible, we will here:           */
/*   1 Query the taxes of the Fiscal Receipt with another query                                           */
/*   2 Create a new record in tqPLInvoiceForMatchingPvo for every record of step 1                        */
/*   3 Remove the ones of the Receipt - but only in case there are taxes for the Fiscal Receipt           */
/* ====================================================================================================== */
/* Sample: We only want the tx2d_det records that actually belong to the pvod, so we delete the ones that */
/*         do not really belong to the pvod                                                               */
/* Sample Data:                                                                                           */
/*     tctx2d_ref: Either just "R0000125",                                                                */
/*                 Either "lorre,X11-LD3,11/10/12" with the date in format YY MM DD (12 October)          */
/*     pvo_external_ref: "X11-LD3,11/10/12" with the date in format YY MM DD (12 October)                 */
/*     pvo_supplier: lorre                                                                                */
/* ====================================================================================================== */

/* We need to manualy define a buffer on tqPLInvoiceForMatchingPvo as CB doesn't support this */
define buffer btqPLInvoiceForMatchingPvo for tqPLInvoiceForMatchingPvo.

/* Go through all pending-voucher-details that relate to fiscal-receipts */
for each tqPLInvoiceForMatchingPvo where
         num-entries(tqPLInvoiceForMatchingPvo.tcpvo_external_ref,',':U) = 2 
         break by tqPLInvoiceForMatchingPvo.tcpvod_domain
               by tqPLInvoiceForMatchingPvo.tipvod_id
               by tqPLInvoiceForMatchingPvo.tipvod_id_line : 
    
    /* Last-of is needed as tqPLInvoiceForMatchingPvo holds a records for every tax-code linked to the pending-voucher-detail */
    if last-of (tqPLInvoiceForMatchingPvo.tipvod_id_line)
    then do :
        
        /* Query on the tax-details: Check if we can find tax-details related to the fiscal-receipt of this pending-voucher-detail */
        /* Note: it was not able to take all conditions into account with this query call and therefore some conditions are there when going through the result-set of this query */
        assign vcTx2dReference = tqPLInvoiceForMatchingPvo.tcpvo_supplier + ',':U +  tqPLInvoiceForMatchingPvo.tcpvo_external_ref
               viTx2dLine      = if tqPLInvoiceForMatchingPvo.tcpvod_order_type = '01':U 
                                 then tqPLInvoiceForMatchingPvo.tipvod_order_line
                                 else tqPLInvoiceForMatchingPvo.tipvod_id_line.
        <Q-37 run TaxDetailByKey (all) (Read) (NoCache)
           (input tqPLInvoiceForMatchingPvo.tcpvo_domain, (Tx2dDomain)
            input vcTx2dReference, (Tx2dReference)
            input tqPLInvoiceForMatchingPvo.tcpvo_order, (Tx2dNumber)
            input viTx2dLine, (Tx2dLine)
            input ?, (Tx2dTrailer)
            input ?, (Tx2dTransactionType)
            input ?, (Tx2dTaxCode)
            output dataset tqTaxDetailByKey) in BMfgTaxDetail>
        
        /* Indicate we have not yet found a tqTaxDetailByKey-record by setting vlFoundtqTaxDetailByKey to false */
        assign vlFoundtqTaxDetailByKey = false.
        
        /* Go through all tqTaxDetailByKey with some additional conditions as the query could not hold all conditions */
        for each tqTaxDetailByKey where
                 tqTaxDetailByKey.tctx2d_domain = tqPLInvoiceForMatchingPvo.tcpvo_domain                    AND
                 tqTaxDetailByKey.tctx2d_ref    = vcTx2dReference                                           AND
                 tqTaxDetailByKey.tctx2d_nbr    = tqPLInvoiceForMatchingPvo.tcpvo_order                     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 = '17' or
                  tqTaxDetailByKey.tctx2d_tr_type = '30')                                                   AND
                 ((tqTaxDetailByKey.titx2d_line = tqPLInvoiceForMatchingPvo.tipvod_order_line and 
                   tqPLInvoiceForMatchingPvo.tcpvod_order_type = '01') or
                  (tqTaxDetailByKey.titx2d_line = tqPLInvoiceForMatchingPvo.tipvod_id_line and
                   tqPLInvoiceForMatchingPvo.tcpvod_order_type = '02' and 
                   tqPLInvoiceForMatchingPvo.tipvod_order_line = 0) or
                  (tqTaxDetailByKey.titx2d_line = 0 and 
                   tqPLInvoiceForMatchingPvo.tcpvod_order_type = '01')) :
            /* Copy the current tqPLInvoiceForMatchingPvo record into a new record and copy and overwrite the tax-info in the new records with the info of tqTaxDetailByKey */
            Create btqPLInvoiceForMatchingPvo.
            Buffer-copy tqPLInvoiceForMatchingPvo to btqPLInvoiceForMatchingPvo.
            Buffer-copy tqTaxDetailByKey to btqPLInvoiceForMatchingPvo.
            /* Indicate we have found a tqTaxDetailByKey-record by setting vlFoundtqTaxDetailByKey to true */
            assign vlFoundtqTaxDetailByKey = true.
        end. /* If can-find (first tqTaxDetailByKey where */
        
        /* If we have created new tqPLInvoiceForMatchingPvo-records in the previous loop on tqTaxDetailByKey    */
        /* then we will now remove the original tqPLInvoiceForMatchingPvo-records that hold the incorrect taxes */
        /* We can distinguish the old ones from the newly created ones as the old ones haven't got 3 entries in field tctctx2d_ref */
        if vlFoundtqTaxDetailByKey = true
        then do :
            for each btqPLInvoiceForMatchingPvo where
                     btqPLInvoiceForMatchingPvo.tcpvod_domain   = tqPLInvoiceForMatchingPvo.tcpvod_domain  and
                     btqPLInvoiceForMatchingPvo.tipvod_id       = tqPLInvoiceForMatchingPvo.tipvod_id      and 
                     btqPLInvoiceForMatchingPvo.tipvod_id_line  = tqPLInvoiceForMatchingPvo.tipvod_id_line and
                     rowid(btqPLInvoiceForMatchingPvo)         <> rowid(tqPLInvoiceForMatchingPvo)         and 
                     num-entries(btqPLInvoiceForMatchingPvo.tctx2d_ref,",":U) <> 3: 
                delete btqPLInvoiceForMatchingPvo.
            end. /* for each btqPLInvoiceForMatchingPvo where */
            delete tqPLInvoiceForMatchingPvo.
        end. /* if vlFoundtqTaxDetailByKey = true */
        
    end. /* if last-of (tqPLInvoiceForMatchingPvo.tipvod_id_line) */
    
end. /* for each tqPLInvoiceForMatchingPvo where*/         

/* ==================================================== */
/* Go through the result set of the query               */
/* ==================================================== */
for each tqPLInvoiceForMatchingPvo
        break by tqPLInvoiceForMatchingPvo.tcpvod_domain
              by tqPLInvoiceForMatchingPvo.tipvod_id
              by tqPLInvoiceForMatchingPvo.tipvod_id_line:
    
    /* =============================================== */
    /* Skip PVO's on companies you dont have access to */
    /* =============================================== */
    if tqPLInvoiceForMatchingPvo.tcPOMstrCompanyCode <> ? and 
       tqPLInvoiceForMatchingPvo.tcPOMstrCompanyCode <> "":U
    then if not can-do(vcListAccessibleCompanyCodes,tqPLInvoiceForMatchingPvo.tcPOMstrCompanyCode)
         then next.
         else.
    else if not can-do(vcListAccessibleCompanyCodes,tqPLInvoiceForMatchingPvo.tcPODDetCompanyCode)
         then next.
    
    /* =========================================================================================== */
    /* 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(tqPLInvoiceForMatchingPvo.tipvod_id_line)
    then do :
        create tPendingVoucherAPM.
        assign tPendingVoucherAPM.APMatchingLnPvodIsLgCharge  = false
               tPendingVoucherAPM.APMatchingLnPvodLgCharge    = "":U
               tPendingVoucherAPM.APMatchingLnIsPvodFinished  = ilAutoSelect
               tPendingVoucherAPM.APMatchingLnIsVarGLPosting  = true
               tPendingVoucherAPM.APMatchingLnPvodCCCode      = tqPLInvoiceForMatchingPvo.tcpvo_accrual_cc
               tPendingVoucherAPM.APMatchingLnPvodPrjCode     = tqPLInvoiceForMatchingPvo.tcpvod_project
               tPendingVoucherAPM.APMatchingLnPvodDivCode     = tqPLInvoiceForMatchingPvo.tcpvo_accrual_sub
               tPendingVoucherAPM.APMatchingLnPvodExchRate    = tqPLInvoiceForMatchingPvo.tdpvod_ex_rate
               tPendingVoucherAPM.APMatchingLnPvodExchRate2   = tqPLInvoiceForMatchingPvo.tdpvod_ex_rate2
               tPendingVoucherAPM.APMatchingLnPvodGLCode      = tqPLInvoiceForMatchingPvo.tcpvo_accrual_acct
               tPendingVoucherAPM.PvodLineID                  = tqPLInvoiceForMatchingPvo.tipvod_id_line
               tPendingVoucherAPM.PvoDomain                   = tqPLInvoiceForMatchingPvo.tcpvo_domain
               tPendingVoucherAPM.PvoID                       = tqPLInvoiceForMatchingPvo.tipvo_id
               tPendingVoucherAPM.tcGLCode                    = tqPLInvoiceForMatchingPvo.tcpvo_accrual_acct
               tPendingVoucherAPM.tcDivisionCode              = tqPLInvoiceForMatchingPvo.tcpvo_accrual_sub
               tPendingVoucherAPM.tcCostCentreCode            = tqPLInvoiceForMatchingPvo.tcpvo_accrual_cc
               tPendingVoucherAPM.tcProjectCode               = tqPLInvoiceForMatchingPvo.tcpvo_project
               tPendingVoucherAPM.APMatchingLnPvodCurrency    = tqPLInvoiceForMatchingPvo.tcpvo_curr
               tPendingVoucherAPM.APMatchingLnPvodExtRef      = substring(tqPLInvoiceForMatchingPvo.tcpvo_external_ref,1,50,'character':U)
               tPendingVoucherAPM.APMatchingLnPvodIntRef      = substring(tqPLInvoiceForMatchingPvo.tcpvo_internal_ref,1,50,'character':U)
               tPendingVoucherAPM.APMatchingLnPvodItem        = tqPLInvoiceForMatchingPvo.tcpvo_part
               tPendingVoucherAPM.APMatchingLnPvodItemDescr1  = substring(tqPLInvoiceForMatchingPvo.tcpt_desc1,1,24,'character':U)
               tPendingVoucherAPM.APMatchingLnPvodItemDescr2  = substring(tqPLInvoiceForMatchingPvo.tcpt_desc2,1,24,'character':U)
               tPendingVoucherAPM.APMatchingLnPvodSupplItem   = tqPLInvoiceForMatchingPvo.tcpod_vpart
               tPendingVoucherAPM.APMatchingLnPvodUoM         = (if tqPLInvoiceForMatchingPvo.tcprh_um = ? then "":U else tqPLInvoiceForMatchingPvo.tcprh_um)
               tPendingVoucherAPM.APMatchingLnPvodUomConv     = (if tqPLInvoiceForMatchingPvo.tdprh_um_conv = ? then 1 else tqPLInvoiceForMatchingPvo.tdprh_um_conv)
               tPendingVoucherAPM.APMatchingLnPvodTransDate   = tqPLInvoiceForMatchingPvo.ttpvod_trans_date
               tPendingVoucherAPM.ttAPMatchingLnPvodEffDate   = tqPLInvoiceForMatchingPvo.ttpvod_eff_date
               tPendingVoucherAPM.APMatchingLnPvodOrder       = tqPLInvoiceForMatchingPvo.tcpvo_order
               tPendingVoucherAPM.APMatchingLnPvodOrderLnNbr  = tqPLInvoiceForMatchingPvo.tipvo_line
               tPendingVoucherAPM.APMatchingLnPvodOrderType   = (if tqPLInvoiceForMatchingPvo.tcpvo_order_type = {&PENDINGVOUCHER-ORDERTYPE-DO}
                                                                then {&APMATCHINGLNPVODORDERTYPE-DISTRIB}
                                                                else if tqPLInvoiceForMatchingPvo.tcpvo_order_type = {&PENDINGVOUCHER-ORDERTYPE-SO}
                                                                     then {&APMATCHINGLNPVODORDERTYPE-SALES}
                                                                     else {&APMATCHINGLNPVODORDERTYPE-PURCHASE})
               tPendingVoucherAPM.APMatchingLnPvodItemType    = if tqPLInvoiceForMatchingPvo.tcprh_type = "":U
                                                                then {&APMATCHINGLNPVODITEMTYPE-NORMAL}
                                                                else if tqPLInvoiceForMatchingPvo.tcprh_type = "S":U
                                                                     then {&APMATCHINGLNPVODITEMTYPE-SUBCONTRACT}
                                                                     else {&APMATCHINGLNPVODITEMTYPE-MEMO}
               tPendingVoucherAPM.APMatchingLnPvodReceiptQty  = tqPLInvoiceForMatchingPvo.tdpvod_trans_qty
               tPendingVoucherAPM.APMatchingLnPvodSite        = (if tqPLInvoiceForMatchingPvo.tcprh_site = ? then "":U else tqPLInvoiceForMatchingPvo.tcprh_site)
               tPendingVoucherAPM.APMatchingLnPvodConvFactor  = (if tqPLInvoiceForMatchingPvo.tdprh_um_conv = ? then 1 else tqPLInvoiceForMatchingPvo.tdprh_um_conv)
               tPendingVoucherAPM.APMatchingLnPvodCompCode    = (if tqPLInvoiceForMatchingPvo.tcPOMstrCompanyCode <> ? and tqPLInvoiceForMatchingPvo.tcPOMstrCompanyCode <> "":U then tqPLInvoiceForMatchingPvo.tcPOMstrCompanyCode else tqPLInvoiceForMatchingPvo.tcPODDetCompanyCode)
               tPendingVoucherAPM.APMatchingLnPvodCompID      = (if tqPLInvoiceForMatchingPvo.tiPOMstrCompanyID <> ? and tqPLInvoiceForMatchingPvo.tiPOMstrCompanyID <> 0 then tqPLInvoiceForMatchingPvo.tiPOMstrCompanyID else tqPLInvoiceForMatchingPvo.tiPODDetCompanyID)
               tPendingVoucherAPM.APMatchingLnPvodPliKeyId    = tqPLInvoiceForMatchingPvo.tiplid_pli_keyid
               tPendingVoucherAPM.APMatchingLnPvodPlidLine    = tqPLInvoiceForMatchingPvo.tiplid_line
               tPendingVoucherAPM.APMatchingLnPvodPackingQty  = tqPLInvoiceForMatchingPvo.tdprh_ps_qty
               tPendingVoucherAPM.APMatchingLnPvodIsTaxable   = (if tqPLInvoiceForMatchingPvo.tlpvo_taxable = ? then false else tqPLInvoiceForMatchingPvo.tlpvo_taxable)
               tPendingVoucherAPM.APMatchingLnPvodTaxEnv      = (if tqPLInvoiceForMatchingPvo.tctx2d_tax_env = ? then "":U else tqPLInvoiceForMatchingPvo.tctx2d_tax_env)
               tPendingVoucherAPM.APMatchingLnPvodTaxClass    = (if tqPLInvoiceForMatchingPvo.tctx2d_taxc = ? then "":U else tqPLInvoiceForMatchingPvo.tctx2d_taxc)
               tPendingVoucherAPM.APMatchingLnPvodTaxUsage    = (if tqPLInvoiceForMatchingPvo.tctx2d_tax_usage = ? then "":U else tqPLInvoiceForMatchingPvo.tctx2d_tax_usage)
               tPendingVoucherAPM.APMatchingLnPvodSupplier    = tqPLInvoiceForMatchingPvo.tcpvo_supplier
               tPendingVoucherAPM.APMatchingLnPvodPayCond     = tqPLInvoiceForMatchingPvo.tcpo_cr_terms
               tPendingVoucherAPM.APMatchingLnIsTaxable       = tPendingVoucherAPM.APMatchingLnPvodIsTaxable
               tPendingVoucherAPM.APMatchingLnTaxEnv          = tPendingVoucherAPM.APMatchingLnPvodTaxEnv
               tPendingVoucherAPM.APMatchingLnTaxClass        = tPendingVoucherAPM.APMatchingLnPvodTaxClass
               tPendingVoucherAPM.APMatchingLnTaxUsage        = tPendingVoucherAPM.APMatchingLnPvodTaxUsage
               tPendingVoucherAPM.APMatchingLnPvodInvoicedTC  = tqPLInvoiceForMatchingPvo.tdpvo_vouchered_amt
               tPendingVoucherAPM.APMatchingLnPvodAccruedTC   = tqPLInvoiceForMatchingPvo.tdpvo_accrued_amt
               tPendingVoucherAPM.tlIsNeededToRecallGTM       = false
               tPendingVoucherAPM.tlIsSelected                = ilAutoSelect
               tPendingVoucherAPM.tc_Status                   = "N":U
               tPendingVoucherAPM.tc_Rowid                    = string(viRowidPendingVoucherAPM)
               tPendingVoucherAPM.APMatchingLnPvodFromTaxZone = (if vlIsVertexEnabled then tqPLInvoiceForMatchingPvo.tctx2d_zone_from else "":U)
               tPendingVoucherAPM.APMatchingLnPvodToTaxZone   = (if vlIsVertexEnabled then tqPLInvoiceForMatchingPvo.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:
            <Q-19 assign vlFcQueryRecordsAvailable = AlMstrByDomainCode (Cache)
               (input tPendingVoucherAPM.PvoDomain, (Domain)
                input tPendingVoucherAPM.tcGLCode, (Code)) in BMfgAllocationAccount>
            if vlFcQueryRecordsAvailable <> false
            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
           (tqPLInvoiceForMatchingPvo.tctx2d_tax_env   = ? or
            tqPLInvoiceForMatchingPvo.tctx2d_tax_env   = "":U)    and
           (tqPLInvoiceForMatchingPvo.tctx2d_taxc      = ? or
            tqPLInvoiceForMatchingPvo.tctx2d_taxc      = "":U)    and 
           (tqPLInvoiceForMatchingPvo.tctx2d_tax_usage = ? or
            tqPLInvoiceForMatchingPvo.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 tqPLInvoiceForMatchingPvo.tipvod_id_line */

    /* ============ */
    /* Tax handling */
    /* ============ */
    if tqPLInvoiceForMatchingPvo.tctx2_tax_code <> ?    and 
       tqPLInvoiceForMatchingPvo.tctx2_domain   <> ?    and
       tqPLInvoiceForMatchingPvo.tctx2_tax_code <> "":U and 
       tqPLInvoiceForMatchingPvo.tctx2_domain   <> "":U 
    then do :      
        /* ========================================================== */
        /* Call submethod that will create the underlying tax records */
        /* ========================================================== */
        <M-11 run GetPendingVouchersPOShipperTax
           (input  ilAutoSelect (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 */
        /* ============================= */
        assign vdSumTaxesWithTaxIncluded = vdSumTaxesWithTaxIncluded  + tqPLInvoiceForMatchingPvo.tdtx2d_cur_tax_amt.
    end. /* if tqPLInvoiceForMatchingPvo.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(tqPLInvoiceForMatchingPvo.tipvod_id_line)
    then do :
        /* ================================ */
        /* Assign the Prices and Quantities */
        /* ================================ */
        assign tPendingVoucherAPM.APMatchingLnPvodOpenQty    = tqPLInvoiceForMatchingPvo.tdpvod_trans_qty  - tqPLInvoiceForMatchingPvo.tdpvod_vouchered_qty
               tPendingVoucherAPM.APMatchingLnMatchQty       = tPendingVoucherAPM.APMatchingLnPvodOpenQty
               tPendingVoucherAPM.APMatchingLnPvodUnitPrice  = tqPLInvoiceForMatchingPvo.tdpvod_pur_cost *
                                                               (if tqPLInvoiceForMatchingPvo.tdprh_um_conv = ? then 1 else tqPLInvoiceForMatchingPvo.tdprh_um_conv) *
                                                                tqPLInvoiceForMatchingPvo.tdpvod_ex_rate /
                                                                tqPLInvoiceForMatchingPvo.tdpvod_ex_rate2.
        if tqPLInvoiceForMatchingPvo.tltx2d_tax_in     = true and 
           tqPLInvoiceForMatchingPvo.tdpvod_trans_qty <> 0 and 
           tqPLInvoiceForMatchingPvo.tdpvod_trans_qty <> ?
        then assign tPendingVoucherAPM.APMatchingLnPvodUnitPrice = tPendingVoucherAPM.APMatchingLnPvodUnitPrice - 
                                                                   (vdSumTaxesWithTaxIncluded  / tqPLInvoiceForMatchingPvo.tdpvod_trans_qty). /* vdSumTaxesWithTaxIncluded is the total tax of the receipt and pvod_trans_qty is the receipt qty */
        assign tPendingVoucherAPM.APMatchingLnMatchUnitPrice = tPendingVoucherAPM.APMatchingLnPvodUnitPrice
               tPendingVoucherAPM.APMatchingLnPvodOpenAmtTC  = <M-48 RoundAmount
                                                                  (input  tPendingVoucherAPM.APMatchingLnPvodOpenQty * tPendingVoucherAPM.APMatchingLnPvodUnitPrice (idUnroundedAmount), 
                                                                   input  ? (iiCurrencyID), 
                                                                   input  tqPLInvoiceForMatchingPvo.tcpvo_curr (icCurrencyCode)) in business>
               tPendingVoucherAPM.APMatchingLnMatchAmtTC     = tPendingVoucherAPM.APMatchingLnPvodOpenAmtTC
               tPendingVoucherAPM.APMatchingLnMatchAmtLC     = <M-85 RoundAmount
                                                                  (input  tPendingVoucherAPM.APMatchingLnMatchAmtTC * tqPLInvoiceForMatchingPvo.tdpvod_ex_rate / tqPLInvoiceForMatchingPvo.tdpvod_ex_rate2 (idUnroundedAmount), 
                                                                   input  viCompanyLCId (iiCurrencyID), 
                                                                   input  ? (icCurrencyCode)) in business>.
        /* =========================================================================== */
        /* Call - via a submethod - method in BCosting the returns the costing methods */
        /* =========================================================================== */
        <M-13 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-34 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 tqPLInvoiceForMatchingPvo.tipvod_id_line */
    
end. /* for each tqPLInvoiceForMatchingPvo */

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