project QadFinancials > class BAPMatching > method GetPendingVouchersLogChargesTax

Description

Submethod of GetPendingVouchersLogCharges


Parameters


ilCallGTMinputlogicalShould we call GTM
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.GetPendingVouchersLogCharges


program code (program7/bapmatching.p)

/* ========================================================================================================= */
    /* ALL DATA WE USE IN HERE SHOULD BE AVAILABLE AS THIS METHOD AND ITS CALLING METHOD ARE IN THE SAME SEGMENT */
    /* ========================================================================================================= */
    
    
    /* ====================== */
    /* Default return-status  */
    /* ====================== */
    assign oiReturnStatus = -98.

    /* ============ */
    /* Tax handling */
    /* ============ */
    if tqPendingVoucherForMatchingLC.tctx2_tax_code <> ?    and 
       tqPendingVoucherForMatchingLC.tctx2_domain   <> ?    and
       tqPendingVoucherForMatchingLC.tctx2_tax_code <> "":U and 
       tqPendingVoucherForMatchingLC.tctx2_domain   <> "":U
    then do:
    
        /* ============================================= */
        /* Check the supplier for withholding tax status */
        /* ============================================= */
        <Q-56 run CreditorByCodeForWHT (all) (Read) (Cache)
           (input tAPMatching.Company_ID, (CompanyId)
            input tqPendingVoucherForMatchingLC.tcpvo_supplier, (CreditorCode)
            input true, (CreditorIsWHT)
            output dataset tqCreditorByCodeForWHT) in BCreditor>
        assign vlCreditorIsWht = can-find (tqCreditorByCodeForWHT where 
                                           tqCreditorByCodeForWHT.tcCreditorCode  = tqPendingVoucherForMatchingLC.tcpvo_supplier and 
                                           tqCreditorByCodeForWHT.tlCreditorIsWHT = true).
        
        if tqPendingVoucherForMatchingLC.tctx2d_tr_type = {&VATTAXTRANSACTIONTYPE-APWHT} and
           vlDomainISWHT   = true and 
           vlCreditorIsWht = true
        then do:
            /* ================================ */
            /* everything for withholding taxes */
            /* ================================ */
            <M-2 run GetPendingVouchersLogChargesTaxWHT
               (input  ilCallGTM (ilCallGTM), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then Return.
        end. /* end if tqPendingVoucherForMatchingLC.tctx2d_tr_type = {&VATTAXTRANSACTIONTYPE-APWHT} */
        else if tqPendingVoucherForMatchingLC.tctx2d_tr_type <> {&VATTAXTRANSACTIONTYPE-APWHT}
        then do:
            /* ==================================================================================== */
            /* Always create t_iAPMatchingLnTax records based upon the tx2d_det records as we need  */
            /* this information for reversing the taxes of the receipt.                             */
            /* Note 0: The tc_parentrowid of these records is just the pvoDomain+pvoID+pvodLieID    */
            /* Note 1: we here use the receipt-amounts as we do not yet know the matched-qty        */
            /* Note 2: we only create this record once (even if a pvod is used multiple times)      */
            /* ==================================================================================== */
            if not can-find (first t_iAPMatchingLnTax where 
                                   t_iAPMatchingLnTax.tc_ParentRowid = trim(tPendingVoucherAPM.PvoDomain) + "-":U + trim(string(tPendingVoucherAPM.PvoID)) + "-":U + trim(string(tPendingVoucherAPM.PvodLineID)) and 
                                   t_iAPMatchingLnTax.tcVatCode      = tqPendingVoucherForMatchingLC.tctx2_tax_code)
            then do :
                create t_iAPMatchingLnTax. 
                assign t_iAPMatchingLnTax.tcDomainCode               = tqPendingVoucherForMatchingLC.tctx2_domain
                       t_iAPMatchingLnTax.tcVatCode                  = tqPendingVoucherForMatchingLC.tctx2_tax_code
                       t_iAPMatchingLnTax.tcVatInOut                 = {&VATINOUT-INPUT}
                       t_iAPMatchingLnTax.APMatchingLnTaxTaxType     = tqPendingVoucherForMatchingLC.tctx2d_tax_type
                       t_iAPMatchingLnTax.APMatchingLnTaxTaxTrType   = {&VATTAXTRANSACTIONTYPE-APVOUCHER}
                       t_iAPMatchingLnTax.APMatchingLnTaxBaseTC      = tqPendingVoucherForMatchingLC.tdtx2d_tottax 
                       t_iAPMatchingLnTax.APMatchingLnTaxBaseLC      = tqPendingVoucherForMatchingLC.tdtx2d_taxable_amt 
                       t_iAPMatchingLnTax.APMatchingLnTaxTaxTC       = tqPendingVoucherForMatchingLC.tdtx2d_cur_tax_amt 
                       t_iAPMatchingLnTax.APMatchingLnTaxTaxLC       = tqPendingVoucherForMatchingLC.tdtx2d_tax_amt 
                       t_iAPMatchingLnTax.APMatchingLnTaxIsAccrRcp   = (tqPendingVoucherForMatchingLC.tltx2_rcpt_tax_point = true or tqPendingVoucherForMatchingLC.tltx2_usage_tax_point = true)
                       t_iAPMatchingLnTax.APMatchingLnTaxIsDiscAtInv = (tqPendingVoucherForMatchingLC.tltx2_inv_disc = true)
                       t_iAPMatchingLnTax.APMatchingLnTaxIsAbsRet    = (if tqPendingVoucherForMatchingLC.tdtx2d_abs_ret_amt <> 0 and tqPendingVoucherForMatchingLC.tdtx2d_abs_ret_amt <> ? then true else false)
                       t_iAPMatchingLnTax.APMatchingLnTaxIsUpdAllow  = tqPendingVoucherForMatchingLC.tltx2_update_tax
                       t_iAPMatchingLnTax.APMatchingLnTaxIsSuspDel   = tqPendingVoucherForMatchingLC.tltx2_stx_dltx_use
                       t_iAPMatchingLnTax.APMatchingLnTaxTaxPct      = tqPendingVoucherForMatchingLC.tdtx2_tax_pct
                       t_iAPMatchingLnTax.APMatchingLnTaxRecovTaxPct = tqPendingVoucherForMatchingLC.tdtx2_pct_recv
                       t_iAPMatchingLnTax.APMatchingLnTaxARRecTaxTC  = (if t_iAPMatchingLnTax.APMatchingLnTaxIsAccrRcp = true  then tqPendingVoucherForMatchingLC.tdtx2d_cur_recov_amt else 0) 
                       t_iAPMatchingLnTax.APMatchingLnTaxARNRecTaxTC = (if t_iAPMatchingLnTax.APMatchingLnTaxIsAccrRcp = true  then tqPendingVoucherForMatchingLC.tdtx2d_cur_tax_amt - tqPendingVoucherForMatchingLC.tdtx2d_cur_recov_amt else 0)
                       t_iAPMatchingLnTax.APMatchingLnTaxAIRecTaxTC  = (if t_iAPMatchingLnTax.APMatchingLnTaxIsAccrRcp = false then tqPendingVoucherForMatchingLC.tdtx2d_cur_recov_amt else 0) 
                       t_iAPMatchingLnTax.APMatchingLnTaxAINRecTaxTC = (if t_iAPMatchingLnTax.APMatchingLnTaxIsAccrRcp = false then tqPendingVoucherForMatchingLC.tdtx2d_cur_tax_amt - tqPendingVoucherForMatchingLC.tdtx2d_cur_recov_amt else 0)
                       t_iAPMatchingLnTax.APMatchingLnTaxIsRevCharge = tqPendingVoucherForMatchingLC.tltx2_reverse_charge
                       t_iAPMatchingLnTax.tcNormalTaxGLCode          = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                          tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                       then tqPendingVoucherForMatchingLC.tctx2_ap_cn_acct
                                                                       else tqPendingVoucherForMatchingLC.tctx2_ap_acct
                       t_iAPMatchingLnTax.tcNormalTaxDivisionCode    = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                          tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                       then tqPendingVoucherForMatchingLC.tctx2_ap_cn_sub
                                                                       else tqPendingVoucherForMatchingLC.tctx2_ap_sub
                       t_iAPMatchingLnTax.tcAbsRetTaxGLCode          = (if t_iAPMatchingLnTax.APMatchingLnTaxIsAbsRet = true 
                                                                        then if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                                tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                             then tqPendingVoucherForMatchingLC.tctx2_apr_cn_acct 
                                                                             else tqPendingVoucherForMatchingLC.tctx2_apr_acct
                                                                        else "":U)
                       t_iAPMatchingLnTax.tcAbsRetTaxDivisionCode    = (if t_iAPMatchingLnTax.APMatchingLnTaxIsAbsRet = true 
                                                                        then if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                                tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                             then tqPendingVoucherForMatchingLC.tctx2_apr_cn_sub
                                                                             else tqPendingVoucherForMatchingLC.tctx2_apr_sub  
                                                                        else "":U)
                       t_iAPMatchingLnTax.tcSuspDelTaxGLCode         = (if t_iAPMatchingLnTax.APMatchingLnTaxIsSuspDel = true 
                                                                        then if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                                tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                             then tqPendingVoucherForMatchingLC.tctx2_dltx_cn_acct 
                                                                             else tqPendingVoucherForMatchingLC.tctx2_dltx_inv_acct
                                                                        else "":U)
                       t_iAPMatchingLnTax.tcSuspDelTaxDivisionCode   = (if t_iAPMatchingLnTax.APMatchingLnTaxIsSuspDel = true 
                                                                        then if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                                tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                             then tqPendingVoucherForMatchingLC.tctx2_dltx_cn_sub
                                                                             else tqPendingVoucherForMatchingLC.tctx2_dltx_inv_sub
                                                                        else "":U)
                       t_iAPMatchingLnTax.tc_ParentRowid             = trim(tPendingVoucherAPM.PvoDomain) + "-":U + trim(string(tPendingVoucherAPM.PvoID)) + "-":U + trim(string(tPendingVoucherAPM.PvodLineID))
                       t_iAPMatchingLnTax.tc_Rowid                   = string(viRowidPendingVoucherTaxAPM)
                       viRowidPendingVoucherTaxAPM                   = viRowidPendingVoucherTaxAPM + 1.
            end. /* if not can-find (first t_iAPMatchingLnTax where */
            /* =============================================================================== */
            /* Create MatchingLnTax in case GTM does not need to be called                     */
            /* If GTM needs to be called then this is done by the parent-method of this method */
            /* The amounts here do depend upon the fact whether a pvo is selected or not       */
            /* =============================================================================== */
            if ilCallGTM = false 
            then do :
                create tPendingVoucherTaxAPM. 
                assign tPendingVoucherTaxAPM.tcDomainCode               = tqPendingVoucherForMatchingLC.tctx2_domain
                       tPendingVoucherTaxAPM.tcVatCode                  = tqPendingVoucherForMatchingLC.tctx2_tax_code
                       tPendingVoucherTaxAPM.tcVatInOut                 = {&VATINOUT-INPUT}
                       tPendingVoucherTaxAPM.APMatchingLnTaxTaxType     = tqPendingVoucherForMatchingLC.tctx2d_tax_type
                       tPendingVoucherTaxAPM.APMatchingLnTaxTaxTrType   = {&VATTAXTRANSACTIONTYPE-APVOUCHER}
                       tPendingVoucherTaxAPM.APMatchingLnTaxBaseTC      = tqPendingVoucherForMatchingLC.tdtx2d_tottax
                       tPendingVoucherTaxAPM.APMatchingLnTaxBaseLC      = tqPendingVoucherForMatchingLC.tdtx2d_taxable_amt
                       tPendingVoucherTaxAPM.APMatchingLnTaxTaxTC       = tqPendingVoucherForMatchingLC.tdtx2d_cur_tax_amt
                       tPendingVoucherTaxAPM.APMatchingLnTaxTaxLC       = tqPendingVoucherForMatchingLC.tdtx2d_tax_amt
                       tPendingVoucherTaxAPM.APMatchingLnTaxIsAccrRcp   = (tqPendingVoucherForMatchingLC.tltx2_rcpt_tax_point = true or tqPendingVoucherForMatchingLC.tltx2_usage_tax_point = true)
                       tPendingVoucherTaxAPM.APMatchingLnTaxIsDiscAtInv = (tqPendingVoucherForMatchingLC.tltx2_inv_disc = true)
                       tPendingVoucherTaxAPM.APMatchingLnTaxIsAbsRet    = (if tqPendingVoucherForMatchingLC.tdtx2d_abs_ret_amt <> 0 and tqPendingVoucherForMatchingLC.tdtx2d_abs_ret_amt <> ? then true else false)
                       tPendingVoucherTaxAPM.APMatchingLnTaxIsUpdAllow  = tqPendingVoucherForMatchingLC.tltx2_update_tax
                       tPendingVoucherTaxAPM.APMatchingLnTaxIsSuspDel   = tqPendingVoucherForMatchingLC.tltx2_stx_dltx_use
                       tPendingVoucherTaxAPM.APMatchingLnTaxTaxPct      = tqPendingVoucherForMatchingLC.tdtx2_tax_pct
                       tPendingVoucherTaxAPM.APMatchingLnTaxRecovTaxPct = tqPendingVoucherForMatchingLC.tdtx2_pct_recv
                       tPendingVoucherTaxAPM.APMatchingLnTaxARRecTaxTC  = (if tPendingVoucherTaxAPM.APMatchingLnTaxIsAccrRcp = true  then tqPendingVoucherForMatchingLC.tdtx2d_cur_recov_amt else 0) 
                       tPendingVoucherTaxAPM.APMatchingLnTaxARNRecTaxTC = (if tPendingVoucherTaxAPM.APMatchingLnTaxIsAccrRcp = true  then tqPendingVoucherForMatchingLC.tdtx2d_cur_tax_amt - tqPendingVoucherForMatchingLC.tdtx2d_cur_recov_amt else 0)
                       tPendingVoucherTaxAPM.APMatchingLnTaxAIRecTaxTC  = (if tPendingVoucherTaxAPM.APMatchingLnTaxIsAccrRcp = false then tqPendingVoucherForMatchingLC.tdtx2d_cur_recov_amt else 0) 
                       tPendingVoucherTaxAPM.APMatchingLnTaxAINRecTaxTC = (if tPendingVoucherTaxAPM.APMatchingLnTaxIsAccrRcp = false then tqPendingVoucherForMatchingLC.tdtx2d_cur_tax_amt - tqPendingVoucherForMatchingLC.tdtx2d_cur_recov_amt else 0)
                       tPendingVoucherTaxAPM.APMatchingLnTaxIsRevCharge = tqPendingVoucherForMatchingLC.tltx2_reverse_charge
                       tPendingVoucherTaxAPM.tcNormalTaxGLCode          = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                             tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                          then tqPendingVoucherForMatchingLC.tctx2_ap_cn_acct
                                                                          else tqPendingVoucherForMatchingLC.tctx2_ap_acct
                       tPendingVoucherTaxAPM.tcNormalTaxDivisionCode    = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                             tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                          then tqPendingVoucherForMatchingLC.tctx2_ap_cn_sub
                                                                          else tqPendingVoucherForMatchingLC.tctx2_ap_sub
                       tPendingVoucherTaxAPM.tcAbsRetTaxGLCode          = (if tPendingVoucherTaxAPM.APMatchingLnTaxIsAbsRet = true 
                                                                           then if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                                   tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                                then tqPendingVoucherForMatchingLC.tctx2_apr_cn_acct 
                                                                                else tqPendingVoucherForMatchingLC.tctx2_apr_acct
                                                                           else "":U)
                       tPendingVoucherTaxAPM.tcAbsRetTaxDivisionCode    = (if tPendingVoucherTaxAPM.APMatchingLnTaxIsAbsRet = true 
                                                                           then if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                                   tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                                then tqPendingVoucherForMatchingLC.tctx2_apr_cn_sub
                                                                                else tqPendingVoucherForMatchingLC.tctx2_apr_sub  
                                                                           else "":U)
                       tPendingVoucherTaxAPM.tcSuspDelTaxGLCode         = (if tPendingVoucherTaxAPM.APMatchingLnTaxIsSuspDel = true 
                                                                           then if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                                   tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                                then tqPendingVoucherForMatchingLC.tctx2_dltx_cn_acct 
                                                                                else tqPendingVoucherForMatchingLC.tctx2_dltx_inv_acct
                                                                           else "":U)
                       tPendingVoucherTaxAPM.tcSuspDelTaxDivisionCode   = (if tPendingVoucherTaxAPM.APMatchingLnTaxIsSuspDel = true 
                                                                           then if tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                                                   tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} 
                                                                                then tqPendingVoucherForMatchingLC.tctx2_dltx_cn_sub
                                                                                else tqPendingVoucherForMatchingLC.tctx2_dltx_inv_sub
                                                                           else "":U)
                       tPendingVoucherTaxAPM.tc_ParentRowid             = tPendingVoucherAPM.tc_Rowid
                       tPendingVoucherTaxAPM.tc_Rowid                   = string(viRowidPendingVoucherTaxAPM)
                       tPendingVoucherTaxAPM.tc_Status                  = "N":U
                       viRowidPendingVoucherTaxAPM                      = viRowidPendingVoucherTaxAPM + 1.
            end. /* if ilCallGTM = false and  */
        end. /* end else if tqPendingVoucherForMatchingLC.tctx2d_tr_type = {&VATTAXTRANSACTIONTYPE-APWHT} */
    end. /* if tqPendingVoucherForMatchingLC.tctx2_tax_code <> ? and  */
    
    /* =================== */
    /* Return-status = OK  */
    /* =================== */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.