project QadFinancials > class BAPMatching > method AdditionalUpdatesAllTaxOldTwo

Description

AdditionalUpdatesAllTaxOldl: submethod of AdditionalUpdatesAll that will reverse the taxes of the matched pvo


Parameters


icAPMatchingPostingRowidIDinputcharacterRowid of the posting
icPostingTextinputcharacterText of the posting
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AdditionalUpdatesAllTax


program code (program6/bapmatching.p)

/* ========================================================================================== */
/* This method creates the posting-lines that will reverse the taxes of the pvod. For every   */
/* posting-line we create in this method, we will also create a record in tAPMatchingLnRevTax */
/* as this is needed to keep track of every posting-line in the matching-posting              */
/* ========================================================================================== */

/* ================== */
/* Exception handling */
/* Start Block        */
/* ================== */
assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.
TAXHANDLINGBLOCK : DO :

    /* ======================================================================== */
    /* First check whether everything is available what is supposed to be avail */
    /* ======================================================================== */
    if not available tAPMatching   or  
       not available tAPMatchingLn or
       not available t_iAPMatchingLnTax
    then do :
        assign viLocalReturnStatus  = -3
               vcMsgAPMatching      = trim(substitute(#T-61'Internal error: information is missing.':255(49818)t-61#)) + chr(10) + 
                                      trim(substitute(#T-62'Available matching header: &1.':234(49819)T-62#,available (tAPMatching)))  + chr(10) + 
                                      trim(substitute(#T-59'Available matching details: &1.':234(49820)T-59#,available (tAPMatchingLn))) + chr(10) + 
                                      trim(substitute(#T-60'Available original matching taxes: &1.':255(68805)T-60#,available (t_iAPMatchingLnTax))).
        <M-54 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-8031':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        Leave TAXHANDLINGBLOCK.
    end. /* if not avail */
    
    /* ===================================================================================================== */
    /* The original-tax-line is AccrueAtReceipt and TaxRetained: PostingLine created on retained tax account */
    /* Taxes are allways posted in the current company: do not use AdditionalUpdatesAllLinesPLAddPostingLine */
    /* Do not pass values that may trigger an additional Retained tax-posting as this is not needed in APM   */
    /* ===================================================================================================== */
    if ((t_iAPMatchingLnTax.APMatchingLnTaxARRecTaxTC  <> 0 and 
         t_iAPMatchingLnTax.APMatchingLnTaxARRecTaxTC  <> ?)    or 
        (t_iAPMatchingLnTax.APMatchingLnTaxARNRecTaxTC <> 0 and 
         t_iAPMatchingLnTax.APMatchingLnTaxARNRecTaxTC <> ?))       and 
       t_iAPMatchingLnTax.APMatchingLnTaxIsAbsRet    = true         and
       t_iAPMatchingLnTax.APMatchingLnTaxIsAccrRcp   = true 
    then do :
        if t_iAPMatchingLnTax.tcAbsRetTaxGLCode = "":U  or
           t_iAPMatchingLnTax.tcAbsRetTaxGLCode = ?
        then do :
            assign viLocalReturnStatus  = -3
                   vcMsgAPMatching      = trim(substitute(#T-63'Tax code &1 is marked as retained tax, but no retained tax account is defined.':255(68807)t-63#,t_iAPMatchingLnTax.tcVatCode)).
            <M-58 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-8032':U (icFcMsgNumber), 
                         input  '':U (icFcExplanation), 
                         input  '':U (icFcIdentification), 
                         input  '':U (icFcContext), 
                         output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            Leave TAXHANDLINGBLOCK.
        end. /* if t_iAPMatchingLnTax.tcAbsRetTaxGLCode = "":U  or */
        assign vdUnroundedTC = (t_iAPMatchingLnTax.APMatchingLnTaxARRecTaxTC + t_iAPMatchingLnTax.APMatchingLnTaxARNRecTaxTC) *
                                (if tAPMatchingLn.APMatchingLnIsPvodFinished = true 
                                 then tAPMatchingLn.APMatchingLnPvodOpenQty 
                                 else tAPMatchingLn.APMatchingLnMatchQty) / 
                               tAPMatchingLn.APMatchingLnPvodReceiptQty
               vdUnroundedLC = vdUnroundedTC * tAPMatchingLn.APMatchingLnPvodExchRate2 / tAPMatchingLn.APMatchingLnPvodExchRate
               vdAmountLC    = <M-56 RoundAmount
                                  (input  vdUnroundedLC (idUnroundedAmount), 
                                   input  viCompanyLCId (iiCurrencyID), 
                                   input  ? (icCurrencyCode)) in BAPMatching>
               vdAmountTC    = <M-52 RoundAmount
                                  (input  vdUnroundedTC (idUnroundedAmount), 
                                   input  tAPMatching.Currency_ID (iiCurrencyID), 
                                   input  ? (icCurrencyCode)) in BAPMatching>
               vdAmountCC    = if viCompanyCCID = viCompanyLCID
                               then vdAmountLC
                               else if viCompanyCCID = tAPMatching.Currency_ID
                                    then vdAmountTC 
                                    else <M-64 RoundAmount
                                            (input  vdUnroundedLC * tAPMatchingLn.APMatchingLnPvodCCRate * tAPMatchingLn.APMatchingLnPvodCCScale (idUnroundedAmount), 
                                             input  viCompanyCCId (iiCurrencyID), 
                                             input  ? (icCurrencyCode)) in BAPMatching>
               vdDebitTC     = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                                  tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                               then if vdAmountTC > 0 then vdAmountTC       else 0
                               else if vdAmountTC < 0 then vdAmountTC       else 0
               vdDebitLC     = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                                  tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                               then if vdAmountLC > 0 then vdAmountLC       else 0
                               else if vdAmountLC < 0 then vdAmountLC       else 0
               vdDebitCC     = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                                  tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                               then if vdAmountCC > 0 then vdAmountCC       else 0
                               else if vdAmountCC < 0 then vdAmountCC       else 0
               vdCreditTC    = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                                  tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                               then if vdAmountTC < 0 then vdAmountTC * -1  else 0
                               else if vdAmountTC > 0 then vdAmountTC * -1  else 0
               vdCreditLC    = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                                  tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                               then if vdAmountLC < 0 then vdAmountLC * -1  else 0
                               else if vdAmountLC > 0 then vdAmountLC * -1  else 0
               vdCreditCC    = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                                  tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                               then if vdAmountCC < 0 then vdAmountCC * -1  else 0
                               else if vdAmountCC > 0 then vdAmountCC * -1  else 0.
        if tAPMatching.tcCreditorAddrCountryCode = tAPMatching.tcShipToAddrCountryCode and
           tAPMatching.tlCreditorAddrIsEUCountry = tAPMatching.tlShipToAddrIsEUCountry
        then assign vcTransactionType = {&VATTRANSACTIONTYPE-PURCHASE}.
        else if tAPMatching.tcCreditorAddrCountryCode <> tAPMatching.tcShipToAddrCountryCode
             then assign vcTransactionType = if tAPMatching.tlCreditorAddrIsEUCountry = true and
                                                tAPMatching.tlCreditorAddrIsEUCountry = tAPMatching.tlShipToAddrIsEUCountry
                                             then {&VATTRANSACTIONTYPE-ACQUISITION}
                                             else {&VATTRANSACTIONTYPE-IMPORT}.
        <M-48 run AddPostingLineTax
           (input  icAPMatchingPostingRowidID (icPostingTcRowid), 
            input  tAPMatching.ttCInvoiceTaxPointDate (itTaxPointDate), 
            input  icPostingText (icPostingLineText), 
            input  tAPMatching.tcCurrencyCode (icCurrencyCode), 
            input  t_iAPMatchingLnTax.tcVatInOut (icPostingVatInOut), 
            input  t_iAPMatchingLnTax.tcVatCode (icPostingVatCode), 
            input  t_iAPMatchingLnTax.tcDomainCode (icPostingVatDomain), 
            input  tAPMatching.tdCInvoiceExchangeRate (idExchangeRate), 
            input  tAPMatching.tdCInvoiceRateScale (idExchangeRateScale), 
            input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType), 
            input  ? (idCCExchangeRate), 
            input  ? (idCCExchangeRateScale), 
            input  vcTransactionType (icTransactionType), 
            input  t_iAPMatchingLnTax.APMatchingLnTaxTaxTrType (icTaxTransactionType), 
            input  0 (idBaseDebitTC), 
            input  0 (idBaseCreditTC), 
            input  0 (idBaseDebitLC), 
            input  0 (idBaseCreditLC), 
            input  0 (idBaseDebitCC), 
            input  0 (idBaseCreditCC), 
            input  vdDebitTC (idVatDebitTC), 
            input  vdCreditTC (idVatCreditTC), 
            input  vdDebitLC (idVatDebitLC), 
            input  vdCreditLC (idVatCreditLC), 
            input  vdDebitCC (idVatDebitCC), 
            input  vdCreditCC (idVatCreditCC), 
            input  t_iAPMatchingLnTax.tcAbsRetTaxGLCode (icNormalTaxGLCode), 
            input  t_iAPMatchingLnTax.tcAbsRetTaxDivisionCode (icNormalTaxDivisionCode), 
            input  true (ilNormalTaxIsAlreadyAbsRet), 
            input  '':U (icAbsRetTaxGLCode), 
            input  '':U (icAbsRetTaxDivisionCode), 
            input  '':U (icFromTaxZone), 
            input  '':U (icToTaxZone), 
            input  tAPMatchingLn.APMatchingLnPvodTaxEnv (icTaxEnvrionment), 
            input  tAPMatchingLn.APMatchingLnPvodIsTaxable (ilIsTaxable), 
            input  tAPMatchingLn.APMatchingLnPvodTaxClass (icTaxClass), 
            input  tAPMatchingLn.APMatchingLnPvodTaxUsage (icTaxUsage), 
            input  t_iAPMatchingLnTax.APMatchingLnTaxTaxType (icTaxType), 
            input  t_iAPMatchingLnTax.APMatchingLnTaxIsRevCharge (ilTaxIsReverseChargeDomestic), 
            input  ? (iiTaxAddressID), 
            input  tAPMatching.tcCreditorAddrTaxIDFederal (icTaxIDFeder), 
            input  tAPMatching.tcCreditorAddrTaxIDState (icTaxIDState), 
            input  tAPMatching.tcCreditorAddrTaxIDMisc1 (icTaxIDMisc1), 
            input  tAPMatching.tcCreditorAddrTaxIDMisc2 (icTaxIDMisc2), 
            input  tAPMatching.tcCreditorAddrTaxIDMisc3 (icTaxIDMisc3), 
            input  ? (iiOwnAddressID), 
            input  tAPMatching.tcShipToAddrTaxIDFederal (icOwnTaxIDFeder), 
            input  tAPMatching.tcShipToAddrTaxIDState (icOwnTaxIDState), 
            input  tAPMatching.tcShipToAddrTaxIDMisc1 (icOwnTaxIDMisc1), 
            input  tAPMatching.tcShipToAddrTaxIDMisc2 (icOwnTaxIDMisc2), 
            input  tAPMatching.tcShipToAddrTaxIDMisc3 (icOwnTaxIDMisc3), 
            input  tAPMatching.tiShipToAddrTaxDeclaration (iiOwnTaxIDDeclarat), 
            input  t_iAPMatchingLnTax.APMatchingLnTaxIsSuspDel (ilIsSuspDel), 
            output viPostingLineID (oiNormalTaxPostingLineID), 
            output vcDummy (ocNormalTaxPostingLineTcRowid), 
            output viDummy (oiAbsRetTaxPostingLineID), 
            output vcDummy (ocAbsRetTaxPostingLineTcRowid), 
            output viNormalTaxPostingVatID (oiNormalTaxPostingVatID), 
            input  false (ilLinkedCrCyDaemonReqExists), 
            input  no (ilCalledFromMoveSuspDelTax), 
            input  ? (itInvoiceExchangeRateDate), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        if viFcReturnSuper <> 0 
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 
        then Leave TAXHANDLINGBLOCK.
        
        /* I19 requirement for Brazil =============================================================== */
        /* If the AP matching is for the Legal document, all posting lines needs to contain reference */
        /* to this legal document                                                                     */
        /* ========================================================================================== */
        if vcLegalDocNbr <> ?
        then do:
            <M-51 run SetPostingLineLegalDocNumber
               (input  ? (icPostingLineTcRowID), 
                input  viPostingLineID (iiPostingLineID), 
                input  vcLegalDocNbr (icLegalDocumentNumber), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper <> 0 and oiReturnStatus >= 0 then assign viLocalReturnStatus = viFcReturnSuper.
            if viFcReturnSuper <  0 then Leave TAXHANDLINGBLOCK.
        end. /* if vcLegalDocNbr <> ? */
        
        
        /* ======================================================================================== */
        /* Create a tAPMatchingLnRevTax to keep track of every posting-line in the matching-posting */
        /* ======================================================================================== */
        <M-57 run AddDetailLine
           (input  'APMatchingLnRevTax':U (icTable), 
            input  tAPMatchingLn.tc_Rowid (icParentRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        if viFcReturnSuper <> 0 
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 
        then Leave TAXHANDLINGBLOCK.
        assign tAPMatchingLnRevTax.APMatching_ID   = tAPMatching.APMatching_ID
               tAPMatchingLnRevTax.PostingLine_ID  = viPostingLineID.
    end. /* if t_iAPMatchingLnTax.APMatchingLnTaxARRecTaxTC <> 0    and */ 
    
END. /* TAXHANDLINGBLOCK */

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