project QadFinancials > class BCInvoice > method CalculateTax

Description

if you create a new CInvoiceVat line,
you have to execute this mehod to calculate the right vat amount
It can result in one or multiple lines


Parameters


icCreditorCodeinputcharacterCreditor Code
icCurrencyCodeinputcharacterCurrency code of the invoice
icDocumentReferenceinputcharacterdocument reference : year+ daybook+voucher for example : 2006CI000000001
itTaxPointDateinputdateTax point date of the invoice
itPostingDateinputdatePosting Date of the invoice
ilTaxIncludedinputlogicalfor the first time, so for defaulting it will be yes, so the invoice amount that will be passes is with taxes, but when you change for example the base amounts, it will be set to false
idAmountTCinputdecimalAmount TC : first time for defaulting it is the invoice amount, afterwards it is one of the base amounts
idExchangeRateinputdecimalExchange Rate of the invoice
idExchangeRateScaleinputdecimalScale factor of the Exchange Rate of the invoice
icPaymentConditioninputcharacterPayment conditon of the invoice
icShipFromTaxZoneinputcharacterTax Zone of the Ship From Address of the Creditor
icShipToTaxZoneinputcharacterTax Zone of the Ship to Address of the creditor
icTxclTaxClsinputcharacterTax Class (of CInvoiceVat)
icTxuTaxUsageinputcharacterTax Usage (of CInvoiceVat)
ilShipToAddressIsTaxInCityinputlogicaltax in city flag of the ship to address
ilIsTaxableinputlogicalIs taxable flag
icCurrentRowIdinputcharacterCurrent row id
idAdjustmentFactorinputdecimaladjustment factor
iiShipToAddressIDinputinteger
iiShipFromAddressIDinputinteger
bcTxenvTaxEnvinput-outputcharacterTax Environment (of CInvoiceVat)
tTaxDetailCInvoiceinput-outputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bcinvoice.p)

/* replace unknown values */
    if icCurrencyCode = ? then assign icCurrencyCode = "":U.
    if icDocumentReference = ? then assign icDocumentReference = "":U.
    if ilTaxIncluded = ? then assign ilTaxIncluded = yes.
    if icShipFromTaxZone = ? then assign icShipFromTaxZone = "":U.
    if icShipToTaxZone = ? then assign icShipToTaxZone = "":U.
    if bcTxenvTaxEnv = ? then assign bcTxenvTaxEnv = "":U.
    if icCreditorCode = ? then assign icCreditorCode = "":U.
    if icTxclTaxCls = ? then assign icTxclTaxCls = "":U.
    if icTxuTaxUsage = ? then assign icTxuTaxUsage = "":U.
    if idAmountTC = ? then assign idAmountTC = 0.
    if idExchangeRateScale = ? then assign idExchangeRateScale = 0.
    if idExchangeRate = ? then assign idExchangeRate = 0.
    if icPaymentCondition = ? then assign icPaymentCondition = "":U.
    if icCurrentRowId = ? then assign icCurrentRowId = "":U.
    if idAdjustmentFactor = ? then assign idAdjustmentFactor = 1.
    
    if icShipFromTaxZone = "":U or icShipToTaxZone = "":U
    then do:
        assign oiReturnStatus = -1.
        <M-3 run SetMessage
           (input  trim(#T-2'You must enter the tax zone of the supplier and the ship-to.':150(56397)t-2#) (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-5656':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        return.
    end.
    
    empty temp-table tTaxDetailCInvoice.

    if bcTxenvTaxEnv = "":U and icShipFromTaxZone <> "":U and icShipToTaxZone <> "":U
    then do:
        /* call the PTax to get the tax environment and calculate the tax */
        assign vhFcComponent = ?.
        <M-5 run GetTaxEnvironmentAndCalculateTax
           (input  icShipFromTaxZone (icShipFromTaxZone), 
            input  icShipToTaxZone (icShipToTaxZone), 
            input  icTxclTaxCls (icTxclTaxCls), 
            input  icCurrencyCode (icCurrencyCode), 
            input  {&VATTAXTRANSACTIONTYPE-APVOUCHER} (icTransactionType), 
            input  icDocumentReference (icDocumentReference), 
            input  ? (icDocumentNumber), 
            input  ilTaxIncluded (ilTaxIsIncluded), 
            input  itTaxPointDate (itTaxPointDate), 
            input  itPostingDate (itPostingDate), 
            input  icTxuTaxUsage (icTaxUsageCode), 
            input  idAmountTC (idAmountTC), 
            input  idExchangeRateScale (idExchangeRateScale), 
            input  idExchangeRate (idExchangeRate), 
            input  vcCompanyCode (icCompanyCode), 
            input  icPaymentCondition (icPaymentCondition), 
            input  vlIsCompanyTaxInCityCI (ilIsTaxInCityFromCompany), 
            input  ilShipToAddressIsTaxInCity (ilIsTaxInCityFromShipTo), 
            input  ilIsTaxable (ilIsTaxable), 
            input  idAdjustmentFactor (idAdjustmentFactor), 
            input  iiShipFromAddressID (iiShipFromAddressID), 
            input  iiShipToAddressID (iiShipToAddressID), 
            input  icCreditorCode (icCustomerCode), 
            input  '' (icInvoiceType), 
            input-output tTaxDetailCInvoice (tTaxDetail), 
            output tTaxParamExtCInv (tTaxParametersExtVAT), 
            output bcTxenvTaxEnv (ocTxenvTaxEnv), 
            output viFcReturnSuper (oiReturnStatus)) in BVAT>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
    end.
    else do:
        /* calculate the taxes */
        assign vhFcComponent = ?.
        <M-1 run CalculateTax
           (input  true (ilStartAndOpenPGTM), 
            input  icCurrencyCode (icCurrencyCode), 
            input  {&VATTAXTRANSACTIONTYPE-APVOUCHER} (icTransactionType), 
            input  icDocumentReference (icDocumentReference), 
            input  ? (icDocumentNumber), 
            input  ilTaxIncluded (ilTaxIsIncluded), 
            input  itTaxPointDate (itTaxPointDate), 
            input  itPostingDate (itPostingDate), 
            input  bcTxenvTaxEnv (icTaxEnvCode), 
            input  icShipFromTaxZone (icFromTaxZoneCode), 
            input  icShipToTaxZone (icToTaxZoneCode), 
            input  icTxclTaxCls (icTaxClassCode), 
            input  icTxuTaxUsage (icTaxUsageCode), 
            input  idAmountTC (idAmountTC), 
            input  idExchangeRateScale (idExchangeRateScale), 
            input  idExchangeRate (idExchangeRate), 
            input  vcCompanyCode (icCompanyCode), 
            input  icPaymentCondition (icPaymentCondition), 
            input  vlIsCompanyTaxInCityCI (ilIsTaxInCityFromCompany), 
            input  ilShipToAddressIsTaxInCity (ilIsTaxInCityFromShipTo), 
            input  ilIsTaxable (ilIsTaxable), 
            input  idAdjustmentFactor (idAdjustmentFactor), 
            input  iiShipToAddressID (iiShipToAddressID), 
            input  iiShipFromAddressID (iiShipFromAddressID), 
            input  icCreditorCode (icCustomerCode), 
            input  '' (icInvoiceType), 
            input-output tTaxDetailCInvoice (tTaxDetail), 
            output tTaxParamExtCInv (tTaxParametersExtVAT), 
            output viFcReturnSuper (oiReturnStatus)) in BVAT>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
    end.

    /* just round the amounts for TC and LC */
    
    assign viSeq = 1.
    
    for each tTaxDetailCInvoice :                
        
        if viSeq > 1               
        then do:
        
            /* call query to get tax base code */
            <Q-15 run MfgTaxCodeForTaxBase (all) (Read) (NoCache)
               (input tTaxDetailCInvoice.tx2d_tax_code, (TaxCode)
                input tTaxDetailCInvoice.tx2d_domain, (DomainCode)
                output dataset tqMfgTaxCodeForTaxBase) in BMfgTaxCode >
            
            find first tqMfgTaxCodeForTaxBase where tqMfgTaxCodeForTaxBase.tctx2_tax_code = tTaxDetailCInvoice.tx2d_tax_code and
                                                    tqMfgTaxCodeForTaxBase.tctx2_domain = tTaxDetailCInvoice.tx2d_domain no-error.
    
            if available tqMfgTaxCodeForTaxBase 
            then assign tTaxDetailCInvoice.tlTx2UpdateTax = false.
                   
        end.
        else
            assign tTaxDetailCInvoice.tlTx2UpdateTax = true.  

        assign tTaxDetailCInvoice.tx2d_tottax          = <M-6 RoundAmount
                                                            (input  tTaxDetailCInvoice.tx2d_tottax (idUnroundedAmount), 
                                                             input  ? (iiCurrencyID), 
                                                             input  icCurrencyCode (icCurrencyCode)) in BCInvoice>
               tTaxDetailCInvoice.tx2d_cur_tax_amt     = <M-7 RoundAmount
                                                            (input  tTaxDetailCInvoice.tx2d_cur_tax_amt (idUnroundedAmount), 
                                                             input  ? (iiCurrencyID), 
                                                             input  icCurrencyCode (icCurrencyCode)) in BCInvoice>
               tTaxDetailCInvoice.tx2d_cur_abs_ret_amt = <M-8 RoundAmount
                                                            (input  tTaxDetailCInvoice.tx2d_cur_abs_ret_amt (idUnroundedAmount), 
                                                             input  ? (iiCurrencyID), 
                                                             input  icCurrencyCode (icCurrencyCode)) in BCInvoice>
               tTaxDetailCInvoice.tx2d_cur_recov_amt   = <M-12 RoundAmount
                                                            (input  tTaxDetailCInvoice.tx2d_cur_recov_amt (idUnroundedAmount), 
                                                             input  ? (iiCurrencyID), 
                                                             input  icCurrencyCode (icCurrencyCode)) in BCInvoice>
               /* LC */
               tTaxDetailCInvoice.tx2d_taxable_amt     = <M-9 RoundAmount
                                                            (input  tTaxDetailCInvoice.tx2d_taxable_amt (idUnroundedAmount), 
                                                             input  viCompanyLCId (iiCurrencyID), 
                                                             input  vcCompanyLC (icCurrencyCode)) in BCInvoice>
               tTaxDetailCInvoice.tx2d_tax_amt         = <M-10 RoundAmount
                                                            (input  tTaxDetailCInvoice.tx2d_tax_amt (idUnroundedAmount), 
                                                             input  viCompanyLCId (iiCurrencyID), 
                                                             input  vcCompanyLC (icCurrencyCode)) in BCInvoice>
               tTaxDetailCInvoice.tx2d_abs_ret_amt     = <M-11 RoundAmount
                                                            (input  tTaxDetailCInvoice.tx2d_abs_ret_amt (idUnroundedAmount), 
                                                             input  viCompanyLCId (iiCurrencyID), 
                                                             input  vcCompanyLC (icCurrencyCode)) in BCInvoice>.
        assign viSeq = viSeq + 1.
        
    end.