project QadFinancials > class BDInvoice > method CreateDIPostingTax

Description

Create the tax posting for the di


Parameters


icRowIdinputcharacterRow ID
iiPostingIdinputintegerPosting ID
itTaxPointDateinputdateTaxPointDate
icDITextinputcharacterCI Text
icCurrencyCodeinputcharacterCurrency Code
iiCurrencyIdinputintegerCurrencyID
icExchangeRateTypeinputcharacterexchange rate type
idExchangeRateinputdecimalexchange rate
idExchangeRateScaleinputdecimal
idVatFullDebitTCinputdecimalVat Full Debit TC
idVatFullCreditTCinputdecimalVat Full Credit TC
icDInvoiceTypeinputcharacterCInvoiceType
icDivisionCodeinputcharacter
icVatCurrencyCodeinputcharacter
iiVatCurrencyIdinputinteger
idVatExchangeRateinputdecimal
idVatExchangeRateScaleinputdecimal
icShipFromCountryCodeinputcharactercountry code of the ship from address
icShipToCountryCodeinputcharacterCountry code of the ship to address
ilShipFromCountryIsEUCountryinputlogicalIs the country code of the ship from address an EU country ?
ilShipToCountryIsEUCountryinputlogicalIs the country code of the ship to address an EU country ?
icTxclTaxClsinputcharacterTax Class of the debtor, or if the tax class on the tax tab is filled, then this one
icTxuTaxUsageinputcharacterTax usage of the debtor, or if the tax usage on the tax tab is filled, then this one
icShipFromTaxZoneinputcharacterTax zone of Ship From
icShipToTxzTaxZoneinputcharacterTax Zone of the Ship To Address
icTxenvTaxEnvinputcharacterTax Environment of the tax tab, if not filled yet, give the default value then
iiVoucherinputintegervoucher of the invoice
icPaymentConditioninputcharacterPayment condition of the invoice
ilIsTaxInCityFromShipToinputlogicaltax in city flag from the ship to address
icControlGLCodeinputcharacterControl GL Account
iiMasterIdinputintegerMaster Id : id of customer, supplier, ...
iiTransactionIdinputintegerTransaction id : id of customer invoice, supplier invoice, ....
ilIsTaxableinputlogicalIs Taxable flag
icCostCentreCodeinputcharacter
icProjectCodeinputcharacter
iiShipFromAddressIdinputintegerShip From Address ID : necessary for addtaxposting to fill the postingvat fields federal tax id, state tax id, misc .... at manual journal entry fields can be blank
iiShipToAddressIdinputintegerShipTo Address ID : necessary for addtaxposting to fill the postingvat fields federal tax id, state tax id, misc .... at manual journal entry fields can be blank
icSoldToDebtorCodeinputcharacterSold To Debtor Code : only passed when it is the same as the ship to code
idInvoiceAmountTCinputdecimalinvoice amount tc
icShipFromTaxIDFederinputcharacterTax ID Feder of the ship from address
icShipFromTaxIDStateinputcharacterTax ID State of the ship from address
icShipFromTaxIDMisc1inputcharacterTax ID Misc1 of the ship from address
icShipFromTaxIDMisc2inputcharacterTax ID Misc2 of the ship from address
icShipFromTaxIDMisc3inputcharacterTax ID Misc3 of the ship from address
iiShipFromTaxDeclarationinputintegerTax declaration of the ship from address
icShipToTaxIDFederinputcharacterTax ID Feder of the ship to address
icShipToTaxIDStateinputcharacterTax ID State of the ship to address
icShipToTaxIDMisc1inputcharacterTax ID Misc1 of the ship to address
icShipToTaxIDMisc2inputcharacterTax ID Misc2 of the ship to address
icShipToTaxIDMisc3inputcharacterTax ID Misc3 of the ship to address
iiShipToTaxDeclarationinputintegerTax Declaration of the ship to address
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.ApiStdMaintainTTWithIntPost
method BDInvoice.CreateDIPosting
method BDInvoice.StdMaintainTTWithIntPost


program code (program6/bdinvoice.p)

/* necessary when yuo modify the scond line of a vat code that is split up in mulitple lines */
if idInvoiceAmountTC <> 0 and
   not can-find ( first tApiDInvoiceVat where
                        tApiDInvoiceVat.DInvoiceVatVatDebitTC  <> 0 or
                        tApiDInvoiceVat.DInvoiceVatVatCreditTC <> 0) and 
   not can-find ( first tApiDInvoiceVat where
                        tApiDInvoiceVat.DInvoiceVatVatDebitTC = 0 and
                        tApiDInvoiceVat.DInvoiceVatVatCreditTC = 0 and
                        tApiDInvoiceVat.TxtyTaxType           <> {&VATTAXTYPE-NONTAX})
then return.
if vlCompanyPropertyIsARUseTaxDate = true
then
    assign vtExchangeRateDate = itTaxPointDate.
else
    assign vtExchangeRateDate = ?.


for each tApiDInvoiceVat 
    break by tApiDInvoiceVat.TxclTaxCls
          by tApiDInvoiceVat.TxuTaxUsage
          by tApiDInvoiceVat.TxenvTaxEnv
          by tApiDInvoiceVat.TxtyTaxType
          by tApiDInvoiceVat.tcVatCode:
    if first-of (tApiDInvoiceVat.tcVatCode)
    then do:
        assign vdDebitAmountTC  = 0
               vdCreditAmountTC = 0.
        empty temp-table tTaxDetailDInvoice.
    end.

    if last-of (tApiDInvoiceVat.tcVatCode)
    then do:
        if icShipFromCountryCode = icShipToCountryCode and
           ilShipFromCountryIsEUCountry = ilShipToCountryIsEUCountry
        then assign vcTransactionType = {&VATTRANSACTIONTYPE-SALES}.
        else if icShipFromCountryCode <> icShipToCountryCode
             then assign vcTransactionType = if ilShipFromCountryIsEUCountry = yes and
                                                ilShipFromCountryIsEUCountry = ilShipToCountryIsEUCountry
                                             then {&VATTRANSACTIONTYPE-SUPPLY}
                                             else {&VATTRANSACTIONTYPE-EXPORT}.
             else assign vcTransactionType = "":U.

        assign vdVatDebitTC  = if tApiDInvoiceVat.DInvoiceVatIsAbsRet
                               then if icDInvoiceType = {&INVOICETYPE-INVOICE} or icDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or icDInvoiceType = {&INVOICETYPE-FINANCECHARGE}
                                    then 0
                                    else tApiDInvoiceVat.DInvoiceVatVatDebitTC
                               else tApiDInvoiceVat.DInvoiceVatVatDebitTC
               vdVatCreditTC = if tApiDInvoiceVat.DInvoiceVatIsAbsRet
                               then if icDInvoiceType = {&INVOICETYPE-INVOICE} or icDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or icDInvoiceType = {&INVOICETYPE-FINANCECHARGE}
                                    then tApiDInvoiceVat.DInvoiceVatVatCreditTC 
                                    else 0
                               else tApiDInvoiceVat.DInvoiceVatVatCreditTC
               vdVatDebitLC  = <M-5 RoundAmount
                                  (input  vdVatDebitTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount), 
                                   input  viCompanyLCId (iiCurrencyID), 
                                   input  vcCompanyLC (icCurrencyCode)) in BDInvoice>
               vdVatCreditLC  = <M-6 RoundAmount
                                   (input  vdVatCreditTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount), 
                                    input  viCompanyLCId (iiCurrencyID), 
                                    input  vcCompanyLC (icCurrencyCode)) in BDInvoice>.


        <M-7 run AddPostingLineTax
           (input  icRowId (icPostingTcRowid), 
            input  itTaxPointDate (itTaxPointDate), 
            input  icDIText (icPostingLineText), 
            input  icCurrencyCode (icCurrencyCode), 
            input  tApiDInvoiceVat.tcVatInOut (icPostingVatInOut), 
            input  tApiDInvoiceVat.tcVatCode (icPostingVatCode), 
            input  tApiDInvoiceVat.tcDomainCode (icPostingVatDomain), 
            input  idExchangeRate (idExchangeRate), 
            input  idExchangeRateScale (idExchangeRateScale), 
            input  icExchangeRateType (icExchangeRateType), 
            input  ? (idCCExchangeRate), 
            input  ? (idCCExchangeRateScale), 
            input  vcTransactionType (icTransactionType), 
            input  tApiDInvoiceVat.DInvoiceVatTaxTrType (icTaxTransactionType), 
            input  tApiDInvoiceVat.DInvoiceVatVatBaseDebitTC (idBaseDebitTC), 
            input  tApiDInvoiceVat.DInvoiceVatVatBaseCreditTC (idBaseCreditTC), 
            input  tApiDInvoiceVat.DInvoiceVatVatBaseDebitLC (idBaseDebitLC), 
            input  tApiDInvoiceVat.DInvoiceVatVatBaseCreditLC (idBaseCreditLC), 
            input  tApiDInvoiceVat.DInvoiceVatVatBaseDebitCC (idBaseDebitCC), 
            input  tApiDInvoiceVat.DInvoiceVatVatBaseCreditCC (idBaseCreditCC), 
            input  vdVatDebitTC (idVatDebitTC), 
            input  vdVatCreditTC (idVatCreditTC), 
            input  vdVatDebitLC (idVatDebitLC), 
            input  vdVatCreditLC (idVatCreditLC), 
            input  ? (idVatDebitCC), 
            input  ? (idVatCreditCC), 
            input  if tApiDInvoiceVat.DInvoiceVatIsSuspDel = true then tApiDInvoiceVat.tcSuspDelTaxGLCode else tApiDInvoiceVat.tcNormalTaxGLCode (icNormalTaxGLCode), 
            input  if tApiDInvoiceVat.DInvoiceVatIsSuspDel = true then tApiDInvoiceVat.tcSuspDelTaxDivisionCode else tApiDInvoiceVat.tcNormalTaxDivisionCode (icNormalTaxDivisionCode), 
            input  false (ilNormalTaxIsAlreadyAbsRet), 
            input  ? (icAbsRetTaxGLCode), 
            input  ? (icAbsRetTaxDivisionCode), 
            input  icShipFromTaxZone (icFromTaxZone), 
            input  icshipToTxzTaxZone (icToTaxZone), 
            input  tApiDInvoiceVat.TxenvTaxEnv (icTaxEnvrionment), 
            input  tApiDInvoiceVat.DInvoiceVatIsTaxable (ilIsTaxable), 
            input  tApiDInvoiceVat.TxclTaxCls (icTaxClass), 
            input  tApiDInvoiceVat.TxuTaxUsage (icTaxUsage), 
            input  tApiDInvoiceVat.TxtyTaxType (icTaxType), 
            input  tApiDInvoiceVat.DInvoiceVatIsRevCharge (ilTaxIsReverseChargeDomestic), 
            input  ? (iiTaxAddressID), 
            input  icShipToTaxIDFeder (icTaxIDFeder), 
            input  icShipToTaxIDState (icTaxIDState), 
            input  icShipToTaxIDMisc1 (icTaxIDMisc1), 
            input  icShipToTaxIDMisc2 (icTaxIDMisc2), 
            input  icShipToTaxIDMisc3 (icTaxIDMisc3), 
            input  ? (iiOwnAddressID), 
            input  icShipFromTaxIDFeder (icOwnTaxIDFeder), 
            input  icShipFromTaxIDState (icOwnTaxIDState), 
            input  icShipFromTaxIDMisc1 (icOwnTaxIDMisc1), 
            input  icShipFromTaxIDMisc2 (icOwnTaxIDMisc2), 
            input  icShipFromTaxIDMisc3 (icOwnTaxIDMisc3), 
            input  iiShipFromTaxDeclaration (iiOwnTaxIDDeclarat), 
            input  tApiDInvoiceVat.DInvoiceVatIsSuspDel (ilIsSuspDel), 
            output viVatPostingLineId (oiNormalTaxPostingLineID), 
            output vcDummy (ocNormalTaxPostingLineTcRowid), 
            output viDummy (oiAbsRetTaxPostingLineID), 
            output vcDummy (ocAbsRetTaxPostingLineTcRowid), 
            output tApiDInvoiceVat.PostingVat_ID (oiNormalTaxPostingVatID), 
            input  false (ilLinkedCrCyDaemonReqExists), 
            input  no (ilCalledFromMoveSuspDelTax), 
            input  vtExchangeRateDate (itInvoiceExchangeRateDate), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then return.

        /* if retained taxes */
        if tApiDInvoiceVat.DInvoiceVatIsAbsRet
        then do:
            /* recalculate the lc values iso using the lc fields, because when you change manually the base amount, the tax lc are not calculated */
            assign vdVatDebitTC = if icDInvoiceType = {&INVOICETYPE-INVOICE} or icDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or icDInvoiceType = {&INVOICETYPE-FINANCECHARGE}
                                  then tApiDInvoiceVat.DInvoiceVatVatDebitTC
                                  else 0
                   vdVatDebitLC = if icDInvoiceType = {&INVOICETYPE-INVOICE} or icDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or icDInvoiceType = {&INVOICETYPE-FINANCECHARGE}
                                  then <M-8 RoundAmount
                                          (input  vdVatDebitTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount), 
                                           input  viCompanyLCId (iiCurrencyID), 
                                           input  vcCompanyLC (icCurrencyCode)) in BDInvoice>
                                  else 0
                   vdVatCreditTC = if icDInvoiceType = {&INVOICETYPE-INVOICE} or icDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or icDInvoiceType = {&INVOICETYPE-FINANCECHARGE}
                                   then 0
                                   else tApiDInvoiceVat.DInvoiceVatVatCreditTC
                   vdVatCreditLC = if icDInvoiceType = {&INVOICETYPE-INVOICE} or icDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or icDInvoiceType = {&INVOICETYPE-FINANCECHARGE}
                                   then 0
                                   else <M-9 RoundAmount
                                           (input  vdVatCreditTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount), 
                                            input  viCompanyLCId (iiCurrencyID), 
                                            input  vcCompanyLC (icCurrencyCode)) in BDInvoice>.
            <M-10 run AddPostingLineTax
               (input  icRowId (icPostingTcRowid), 
                input  itTaxPointDate (itTaxPointDate), 
                input  icDIText (icPostingLineText), 
                input  icCurrencyCode (icCurrencyCode), 
                input  tApiDInvoiceVat.tcVatInOut (icPostingVatInOut), 
                input  tApiDInvoiceVat.tcVatCode (icPostingVatCode), 
                input  tApiDInvoiceVat.tcDomainCode (icPostingVatDomain), 
                input  idExchangeRate (idExchangeRate), 
                input  idExchangeRateScale (idExchangeRateScale), 
                input  icExchangeRateType (icExchangeRateType), 
                input  ? (idCCExchangeRate), 
                input  ? (idCCExchangeRateScale), 
                input  vcTransactionType (icTransactionType), 
                input  tApiDInvoiceVat.DInvoiceVatTaxTrType (icTaxTransactionType), 
                input  tApiDInvoiceVat.DInvoiceVatVatBaseCreditTC (idBaseDebitTC), 
                input  tApiDInvoiceVat.DInvoiceVatVatBaseDebitTC (idBaseCreditTC), 
                input  tApiDInvoiceVat.DInvoiceVatVatBaseCreditLC (idBaseDebitLC), 
                input  tApiDInvoiceVat.DInvoiceVatVatBaseDebitLC (idBaseCreditLC), 
                input  tApiDInvoiceVat.DInvoiceVatVatBaseCreditCC (idBaseDebitCC), 
                input  tApiDInvoiceVat.DInvoiceVatVatBaseDebitCC (idBaseCreditCC), 
                input  vdVatDebitTC (idVatDebitTC), 
                input  vdVatCreditTC (idVatCreditTC), 
                input  vdVatDebitLC (idVatDebitLC), 
                input  vdVatCreditLC (idVatCreditLC), 
                input  ? (idVatDebitCC), 
                input  ? (idVatCreditCC), 
                input  tApiDInvoiceVat.tcAbsRetTaxGLCode (icNormalTaxGLCode), 
                input  tApiDInvoiceVat.tcAbsRetTaxDivisionCode (icNormalTaxDivisionCode), 
                input  true (ilNormalTaxIsAlreadyAbsRet), 
                input  ? (icAbsRetTaxGLCode), 
                input  ? (icAbsRetTaxDivisionCode), 
                input  icShipFromTaxZone (icFromTaxZone), 
                input  icshipToTxzTaxZone (icToTaxZone), 
                input  tApiDInvoiceVat.TxenvTaxEnv (icTaxEnvrionment), 
                input  tApiDInvoiceVat.DInvoiceVatIsTaxable (ilIsTaxable), 
                input  tApiDInvoiceVat.TxclTaxCls (icTaxClass), 
                input  tApiDInvoiceVat.TxuTaxUsage (icTaxUsage), 
                input  tApiDInvoiceVat.TxtyTaxType (icTaxType), 
                input  tApiDInvoiceVat.DInvoiceVatIsRevCharge (ilTaxIsReverseChargeDomestic), 
                input  ? (iiTaxAddressID), 
                input  icShipToTaxIDFeder (icTaxIDFeder), 
                input  icShipToTaxIDState (icTaxIDState), 
                input  icShipToTaxIDMisc1 (icTaxIDMisc1), 
                input  icShipToTaxIDMisc2 (icTaxIDMisc2), 
                input  icShipToTaxIDMisc3 (icTaxIDMisc3), 
                input  ? (iiOwnAddressID), 
                input  icShipFromTaxIDFeder (icOwnTaxIDFeder), 
                input  icShipFromTaxIDState (icOwnTaxIDState), 
                input  icShipFromTaxIDMisc1 (icOwnTaxIDMisc1), 
                input  icShipFromTaxIDMisc2 (icOwnTaxIDMisc2), 
                input  icShipFromTaxIDMisc3 (icOwnTaxIDMisc3), 
                input  iiShipFromTaxDeclaration (iiOwnTaxIDDeclarat), 
                input  ? (ilIsSuspDel), 
                output viVatPostingLineId (oiNormalTaxPostingLineID), 
                output vcDummy (ocNormalTaxPostingLineTcRowid), 
                output viDummy (oiAbsRetTaxPostingLineID), 
                output vcDummy (ocAbsRetTaxPostingLineTcRowid), 
                output viDummy (oiNormalTaxPostingVatID), 
                input  false (ilLinkedCrCyDaemonReqExists), 
                input  no (ilCalledFromMoveSuspDelTax), 
                input  vtExchangeRateDate (itInvoiceExchangeRateDate), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
            then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then return.
        end.
    end.
end.