project QadFinancials > class BAPMatching > method AddAPMatchingLnLC

Description

This method will add logistic charge matching details to the logistic charge.


Parameters


icDomainCodeinputcharacter
ilCallGTMinputlogical
ilFillPendingMatchFieldsinputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AddAPMatchingLn


program code (program7/bapmatching.p)

/* ====================================================== */
/* Raise error in case no tAPMatching record is available */
/* ====================================================== */
if not available tAPMatching
then do :
    assign oiReturnStatus  = -3
           vcMsgAPMatching = trim(substitute(#T-75'Internal error: mandatory information in the program code is not accessible; see below for more details.':255(70321)T-75#)) + chr(10) + 
                             trim(substitute(#T-30'Record for &1 is available: &2.':255(70322)T-30#,"tAPMatching":U,string(available tAPMatching))).
    <M-3 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-443834':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    Return.
end. /* if not available tAPMatching */

/* ================================ */
/* Exception handling - Start Block */
/* ================================ */
assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.
       
LOOPBLOCK: Do :
    
    /* ============================================================================ */
    /* Go through all record in the inst-less temp-table tAPMatchingLnBasedUponPvod */
    /* ============================================================================ */
    for each tAPMatchingLnBasedUponPvod where
             tAPMatchingLnBasedUponPvod.tlIsLgCharge = true:   
    
        /* ================================================================================================================ */
        /* Call the same method that is also called from the UI - First emtpy the temp-table thart are filled by the method */
        /* ================================================================================================================ */
        empty temp-table tPendingVoucherAPM.
        empty temp-table tPendingVoucherTaxAPM.
        empty temp-table tPendingVoucherWHTAPM.
        <M-61 run GetPendingVouchersLogCharges
           (input  tAPMatching.tc_Rowid (icAPMatchingTcRowid), 
            input  ? (icCreditorCode), 
            input  ? (ilIncludeEmptyCreditors), 
            input  tAPMatching.tcCurrencyCode (icCurrencyCode), 
            input  tAPMatching.tdCInvoiceExchangeRate (idCInvoiceTCLCRate), 
            input  tAPMatching.tdCInvoiceRateScale (idCInvoiceTCLCScale), 
            input  tAPMatching.tdCInvoiceCCRate (idCInvoiceTCCCRate), 
            input  tAPMatching.tdCInvoiceCCScale (idCInvoiceTCCCScale), 
            input  tAPMatching.APMatchingTotalAmountTC (idCInvoiceTotalAmountTC), 
            input  tAPMatching.APMatchingARRecTaxTC (idCInvoiceARRecTaxTC), 
            input  tAPMatching.APMatchingARNRecTaxTC (idCInvoiceARNRecTaxTC), 
            input  ? (itTransactionDateFrom), 
            input  ? (itTransactionDateTill), 
            input  ? (itTransactionDate), 
            input  ? (itTransactionDetailDateFrom), 
            input  ? (itTransactionDetailDateTill), 
            input  ? (itTransactionDetailDate), 
            input  ? (icExternalReferenceFrom), 
            input  ? (icExternalReferenceTo), 
            input  ? (icExternalReference), 
            input  ? (icInternalReferenceFrom), 
            input  ? (icInternalReferenceTo), 
            input  ? (icInternalReference), 
            input  ? (icShipToFrom), 
            input  ? (icShipToTo), 
            input  ? (icShipTo), 
            input  ? (icItemNumberFrom), 
            input  ? (icItemNumberTo), 
            input  ? (icItemNumber), 
            input  ? (icLogisticChargeFrom), 
            input  ? (icLogisticChargeTo), 
            input  ? (icLogisticCharge), 
            input  ? (icShipFromFrom), 
            input  ? (icShipFromTo), 
            input  ? (icShipFrom), 
            input  true (ilAutoSelect), 
            input  ? (icOrderFrom), 
            input  ? (icOrderTo), 
            input  ? (icOrder), 
            input  ilCallGTM (ilCallGTM), 
            input  tAPMatchingLnBasedUponPvod.tiPvoID (iiApiPvoId), 
            input  tAPMatchingLnBasedUponPvod.tiPvodLineID (iiApiPvodLineId), 
            input  tAPMatchingLnBasedUponPvod.tdAPMAtchingLnMatchUnitPrice (idApiMatchAmtTC), 
            input  tAPMatchingLnBasedUponPvod.tlIsPvodFinished (ilApiIsPvodFinished), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>        
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
        if viLocalReturnStatus < 0 then leave LOOPBLOCK.

        /* ==================================================================================== */
        /* Go through all created tPendingVoucherAPM records - and calculate the tax if needed  */
        /* ==================================================================================== */
        PGTMCALLINGBLOCK : DO :
            if ilCallGTM
            then do:
                for each tPendingVoucherAPM where 
                         tPendingVoucherAPM.APMatchingLnIsTaxable  = true and 
                         tPendingVoucherAPM.APMatchingLnTaxEnv    <> "":U and 
                         tPendingVoucherAPM.APMatchingLnTaxEnv    <> ?:
                    <M-87 run CreateAPMatchingLNTaxFromGTM
                       (input  tAPMatching.tc_Rowid (icAPMatchingTcRowid), 
                        input  tPendingVoucherAPM.tc_Rowid (icAPMatchingLnTcRowid), 
                        input  tAPMatching.tcCurrencyCode (icCurrencyCode), 
                        input  '':U (icTransactionType), 
                        input  tAPMatching.tiCInvoiceVoucher (icDocumentReference), 
                        input  '':U (icDocumentNumber), 
                        input  tPendingVoucherAPM.APMatchingLnIsTaxable (ilIsTaxable), 
                        input  False (ilIsTaxIncludedInTheAmount), 
                        input  tAPMatching.ttCInvoiceTaxPointDate (itTaxPointDate), 
                        input  tAPMatching.APMatchingDate (itPostingDate), 
                        input  tPendingVoucherAPM.APMatchingLnTaxEnv (icTaxEnvCode), 
                        input  tPendingVoucherAPM.APMatchingLnPvodFromTaxZone (icFromTaxZoneCode), 
                        input  tPendingVoucherAPM.APMatchingLnPvodToTaxZone (icToTaxZoneCode), 
                        input  tPendingVoucherAPM.APMatchingLnTaxClass (icTaxClassCode), 
                        input  tPendingVoucherAPM.APMatchingLnTaxUsage (icTaxUsageCode), 
                        input  tPendingVoucherAPM.APMatchingLnMatchAmtTC (idAmountTC), 
                        input  tAPMatching.tdCInvoiceExchangeRate (idCInvoiceTCLCRate), 
                        input  tAPMatching.tdCInvoiceRateScale (idCInvoiceTCLCScale), 
                        input  tAPMatching.tdCInvoiceCCRate (idCInvoiceTCCCRate), 
                        input  tAPMatching.tdCInvoiceCCScale (idCInvoiceTCCCScale), 
                        input  vcCompanyCode (icCompanyCode), 
                        input  1 (idAdjustmentFactor), 
                        input  tAPMatching.APMatchingCInvoiceDiscPct (idPaymentConditionPercentage), 
                        input  tAPMatching.tlCreditorAddrIsTaxInCity (ilIsTaxInCityOfShipTo), 
                        input  tAPMatching.tlShipToAddrIsTaxInCity (ilIsTaxInCityOfShipFrom), 
                        input  False (ilNeedToStartPGTMFromHere), 
                        output tAPMatchingLnTaxFromGTM (tAPMatchingLnTaxFromGTM), 
                        output tAPMatchingLnWHTFromGTM (tAPMatchingLnWHTFromGTM), 
                        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
                    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0 then leave PGTMCALLINGBLOCK.
                    /* =================================================================================================================================== */
                    /* Store the output in the tPendingVoucherTaxAPM - equivalent for tAPMatchingLnTax and empty tAPMatchingLnTaxFromGTM when it is copied */
                    /* =================================================================================================================================== */
                    for each tAPMatchingLnTaxFromGTM :
                        create tPendingVoucherTaxAPM.
                        buffer-copy tAPMatchingLnTaxFromGTM to tPendingVoucherTaxAPM.
                    end. /* for each tAPMatchingLnTaxFromGTM */
                    empty temp-table tAPMatchingLnTaxFromGTM.
                    /* =================================================================================================================================== */
                    /* Store the output in the tPendingVoucherWHTAPM - equivalent for tAPMatchingLnWHT and empty tAPMatchingLnWHTFromGTM when it is copied */
                    /* =================================================================================================================================== */
                    for each tAPMatchingLnWHTFromGTM :
                        create tPendingVoucherWHTAPM.
                        buffer-copy tAPMatchingLnWHTFromGTM to tPendingVoucherWHTAPM.
                    end. /* for each tAPMatchingLnWHTFromGTM */
                    empty temp-table tAPMatchingLnWHTFromGTM.
                End. /* for each tPendingVoucherAPM */
            end. /* if ilCallGTM */
        END. /* PGTMCALLINGBLOCK */

        /* ============================================================ */
        /* Result of the previous procedure is stored in 3 temp-tables. */
        /* Therefore we have to overtake it and store in the class data */
        /* ============================================================ */
        for each tPendingVoucherAPM:
            
            /* =================================================== */
            /* Create tAPMatchingLn based ulpon the temp-table     */
            /* =================================================== */
            <M-11 run AddDetailLine
               (input  'APMatchingLn':U (icTable), 
                input  tAPMatching.tc_Rowid (icParentRowid), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
            if viLocalReturnStatus < 0 then leave LOOPBLOCK.
            buffer-copy tPendingVoucherAPM 
                           except tc_RowId tc_ParentRowId tc_status APMatchingLn_ID APMatching_ID
                        to tAPMatchingLn.

            /* Store ID of the created APMatchingLn in output temp-table */
            assign tAPMatchingLnBasedUponPvod.tiAPMatchingLnID = tAPMatchingLn.APMatchingLn_ID.
            
            /* ============================================================================================= */
            /* Go through the underlying Taxes and create tAPMatchingLnTax records based upon the temp-table */
            /* ============================================================================================= */
            for each tPendingVoucherTaxAPM where
                     tPendingVoucherTaxAPM.tc_ParentRowid = tPendingVoucherAPM.tc_Rowid:
                    <M-54 run AddDetailLine
                       (input  'APMatchingLnTax':U (icTable), 
                        input  tAPMatchingLn.tc_Rowid (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
                    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
                    if viLocalReturnStatus < 0 then leave LOOPBLOCK.
                    buffer-copy tPendingVoucherTaxAPM
                                    except tc_RowId tc_ParentRowId tc_Status APMatchingLn_ID APMatchingLnTax_ID
                             to tAPMatchingLnTax.
            end. /* for each tPendingVoucherTaxAPM where */
            
            /* ============================================================================================= */
            /* Go through the underlying WHT and create tAPMatchingLnWHT records based upon the temp-table   */
            /* ============================================================================================= */
            for each tPendingVoucherWHTAPM where
                     tPendingVoucherWHTAPM.tc_ParentRowid = tPendingVoucherAPM.tc_Rowid:
                    <M-81 run AddDetailLine
                       (input  'APMatchingLnWHT':U (icTable), 
                        input  tAPMatchingLn.tc_Rowid (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
                    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
                    if viLocalReturnStatus < 0 then leave LOOPBLOCK.
                    buffer-copy tPendingVoucherWHTAPM
                                    except tc_RowId tc_ParentRowId tc_Status APMatchingLn_ID APMatchingLnWHT_ID
                             to tAPMatchingLnWHT.
                             
            end. /* for each tPendingVoucherWHTAPM where */
            
        end. /* for each tPendingVoucherAPM: */
        
    end. /* for each tAPMatchingLnBasedUponPvod where */

    /* ======================================================================= */
    /* There are stored total Logistic Charge amounts by the pending voucher   */
    /* ======================================================================= */
    for each tAPMatchingLn where
             tAPMatchingLn.tc_ParentRowid             = tAPMatching.tc_Rowid and
             tAPMatchingLn.APMatchingLnPvodIsLgCharge = true
        break by tAPMatchingLn.PvoDomain
              by tAPMatchingLn.PvoID:
        if first-of(tAPMatchingLn.PvoID)
        then assign vdLogChargeHeaderMatchedAmount = 0
                    vlLogChargeHeaderIsFinished    = true.
        assign vdLogChargeHeaderMatchedAmount = vdLogChargeHeaderMatchedAmount + tAPMatchingLn.APMatchingLnMatchAmtTC
               vlLogChargeHeaderIsFinished    = vlLogChargeHeaderIsFinished AND tAPMatchingLn.APMatchingLnIsPvodFinished.
        if last-of(tAPMatchingLn.PvoID)
        then do:
            for each bAPMatchingLn where
                     bAPMatchingLn.PvoDomain = tAPMatchingLn.PvoDomain and
                     bAPMatchingLn.PvoID     = tAPMatchingLn.PvoID:
                assign bAPMatchingLn.tdLogChargeHeaderMatchedAmountTC = vdLogChargeHeaderMatchedAmount
                       bAPMatchingLn.tlLogChargeHeaderIsFinished      = vlLogChargeHeaderIsFinished.
            end. /* for each bAPMatchingLn where */
        end. /* if last-of(tAPMatchingLn.PvoID) */
    end. /* for each tAPMatchingLn where */

END. /* LOOPBLOCK */

/* =================== */
/* Exception handling  */
/* =================== */
assign oiReturnStatus = viLocalReturnStatus.