project QadFinancials > class BPosting > method AddTaxPosting

Description

add a Tax posting to the journal entry


Parameters


icPostingtcRowidinputcharactertposting.tc_Rowid
icPostingLineTcRowidinputcharacterField-value of tc_rowid of the tpostingline you are creating tax-information for.
This field can be left empty when you do not have a PostingLine yet.
itTaxPointDateinputdatetax point date
icDescriptioninputcharacter
icCurrencyCodeinputcharacterCurrency Code
iiCurrencyIdinputintegercurrency id
icExchangeRateTypeinputcharacter
idExchangeRateinputdecimalexchange rate
idExchangeRateScaleinputdecimal
idCCRateinputdecimal
idCCRateScaleinputdecimal
idBaseDebitinputdecimalbase TC
idBaseCreditinputdecimalbase TC
idFullDebitinputdecimalfull TC
idFullCreditinputdecimalfull TC
icInvoiceTypeinputcharacterInvoice Type : must be Invoice or Credit Note
ilCalculateVatinputlogicaldo you want to calculate the vat(yes) or do you want to work on input temptable (false) ?
tTaxDetailPostinginput-outputtemp-tableTax Detail Posting temp table, so not recalculate the tax amounts but work with this ...
icCallerinputcharacter
ilIsVatDelayinputlogical
icDivisionCodeinputcharacter
icVatCurrencyCodeinputcharacter
iiVatCurrencyIdinputinteger
idVatExchangeRateinputdecimalExchange rate between Transactional currency and Vat currency.
idVatExchangeRateScaleinputdecimal
icTransactionTypeinputcharacterTransaction Type
icTxclTaxClsinputcharacterTax Class
icTxuTaxUsageinputcharacterTax Usage
icFromTxzTaxZoneinputcharacterfrom Tax Zone
icToTxzTaxZoneinputcharacterTo Tax Zone
icTxenvTaxEnvinputcharacterTax Environment
icDocumentReferenceinputcharacterDocument Reference
icDocumentNumberinputcharacterDocument Number
icPaymentConditioninputcharacterPayment Condition
ilIsTaxInCityFromCompanyinputlogicaltax in city flag of the company
ilIsTaxInCityFromShipToinputlogicaltax in city flag of the ship to address
ilCustomerInvoiceinputlogicalindication if we work with a customer invoice or a supplier invoice, necessary to know if it is debit or credit
icControlGLCodeinputcharactercontrol GL Account
iiMasterIdinputintegerID of customer, supplier, ...
iiTransactionIdinputintegerid of customer invoice, supplier invoice,....
icTaxGLCodeinputcharacterGL Code for tax : if linked to po where accrue tax at receipt or accrue tax at usage is set, then purchase order receipt account
ilIsTaxableinputlogicalIs Taxable flag
idAdjustmentFactorinputdecimalAdjustment Factor
icCostCentreCodeinputcharacter
icProjectCodeinputcharacter
iiShipFromAddressIdinputintegerShip From Address ID : necessary to fill the federal tax, state tax, misc .... Not needed for manual journal entries
iiShipToAddressIdinputintegerShip To Address ID : necessary to fill the federal tax, state tax, misc .... Not needed for manual journal entries
icTaxTransactionTypeinputcharactertax transaction type
icSoldToDebtorCodeinputcharacterSold To Debtor Code : only passed when it is the same as the ship to code, then the tax id fields, must be defaulted from the sold to debtor code for customer invoices
biFirstVatPostingLineIdinput-outputinteger
oiSecondVatPostingLineIdoutputintegerSecondVatPostingLineId: In case an additional posting-line with a postng-tax was created, this field will contain the postinglineID of the second postingline
ocPostingLineIdsoutputcharacterlist of all postingline ids that are made here, necessary for manual journal entry, separated by comma
ilLinkedCrCyDaemonReqExistsinputlogical
icTaxTypeCodeinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BConsolid.AdditionalUpdatesPostingTaxAccount
method BJournalEntry.CreateTaxPosting
method BYearClosing.AdditionalUpdatesPostingTaxAccount


program code (program6/bposting.p)

assign oiReturnStatus = -98.

if icPostingtcRowid     = ? then assign icPostingtcRowid    = "":U.
if icPostingLineTcRowid = ? then assign icPostingLineTcRowid = "":U.
if icDescription       = ? then assign icDescription       = "":U.
if icCurrencyCode      = ? then assign icCurrencyCode      = "":U.
if iiCurrencyID        = ? then assign iiCurrencyID        = 0.
if icExchangeRateType  = ? then assign icExchangeRateType  = "":U.
if idExchangeRate      = ? then assign idExchangeRate      = 0.
if idExchangeRateScale = ? or idExchangeRateScale <= 0 then assign idExchangeRateScale = 1.
if idBaseDebit         = ? then assign idBaseDebit         = 0.
if idBaseCredit        = ? then assign idBaseCredit        = 0.
if idFullDebit         = ? then assign idFullDebit         = 0.
if idFullCredit        = ? then assign idFullCredit        = 0.
if icInvoiceType       = ? then assign icInvoiceType       = "":U.
if icControlGLCode     = ? then assign icControlGLCode     = "":U.
if icTaxGLCode         = ? then assign icTaxGLCode         = "":U.
if idAdjustmentFactor  = ? then assign idAdjustmentFactor  = 0.
if iiShipFromAddressId = ? then assign iiShipFromAddressId = 0.
if iiShipToAddressId   = ? then assign iiShipToAddressId   = 0.
if icTaxTransactionType = ? then assign icTaxTransactionType = "":U.
if icSoldToDebtorCode  = ? then assign icSoldToDebtorCode  = "":U.
if ilCalculateVat      = ? then assign ilCalculateVat      = false.

find tPosting where tPosting.tc_Rowid = icPostingtcRowid no-error.
if not available tPosting
then do:
    assign vcMessage      = trim(substitute(#T-35'Internal error: posting record not found for row ID &1.':150(3199)t-35#, icPostingtcRowid))
           oiReturnStatus = -1.
    <M-78 run AddTaxPostingSetMessage
       (input  vcMessage (icMessage), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    return.
end. /* end not available tPosting */

if icInvoiceType <> {&INVOICETYPE-INVOICE} and icInvoiceType <> {&INVOICETYPE-FINANCECHARGE} and icInvoiceType <> {&INVOICETYPE-CREDITNOTE} and icInvoiceType <> {&INVOICETYPE-INVOICECORRECTION} and icInvoiceType <> {&INVOICETYPE-CREDITNOTECORRECTION}
then do:
    assign vcMessage      = trim(substitute(#T-36'The invoice must be of type &1, &2, &3, &4 or &5.':255(57309)t-36#,{&INVOICETYPE-INVOICE-TR},{&INVOICETYPE-FINANCECHARGE-TR},{&INVOICETYPE-CREDITNOTE-TR},{&INVOICETYPE-INVOICECORRECTION-TR},{&INVOICETYPE-CREDITNOTECORRECTION-TR}))
           oiReturnStatus = -3.
    <M-79 run AddTaxPostingSetMessage
       (input  vcMessage (icMessage), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    return.
end. /* end icInvoiceType */

<Q-15 run VatPeriodByStartEndDate (all) (Read) (NoCache)
   (input tPosting.Company_ID, (CompanyId)
    input itTaxPointDate, (Date)
    input {&VATPERIODSTATUS-OPEN}, (Status)
    output dataset tqVatPeriodByStartEndDate) in BVATPeriod >
find first tqVatPeriodByStartEndDate no-error.
if not available tqVatPeriodByStartEndDate
then do:
    assign vcMessage      = trim(substitute(#T-37'No tax period can be found for this tax point date (&1).':150(3229)t-37#, trim(string(itTaxPointDate,"99/99/9999":U)) ))
           oiReturnStatus = -3.
    <M-85 run AddTaxPostingSetMessage
       (input  vcMessage (icMessage), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    return.        
end. /* end not available tqVatPeriodByStartEndDate */

if icCurrencyCode <> "":U and (iiCurrencyId = 0 or iiCurrencyId = ?)
then do:
    <Q-26 run CurrencyByCode (all) (Read) (NoCache)
       (input icCurrencyCode, (CurrencyCode)
        output dataset tqCurrencyByCode) in BCurrency >
    find first tqCurrencyByCode no-error.
    if available tqCurrencyByCode
    then assign iiCurrencyId = tqCurrencyByCode.tiCurrency_ID.
end. /* end icCurrencyCode */

<M-103 run AddTaxPostingGetExchRates
   (input  tPosting.Company_ID (iiCompanyID), 
    input  iiCurrencyId (iiCurrencyId), 
    input  icExchangeRateType (icExchangeRateType), 
    input  itTaxPointDate (itTaxPointDate), 
    input-output idExchangeRate (bdExchangeRateLC), 
    input-output idExchangeRateScale (bdExchangeRateScaleLC), 
    input-output vdRateCC (bdExchangeRateCC), 
    input-output vdRateScaleCC (bdExchangeRateScaleCC), 
    output viLocalReturnStatus (oiReturnStatus)) in BPosting>
if viLocalReturnStatus < 0 or (viLocalReturnStatus > 0 and oiReturnStatus = -98)
then assign oiReturnStatus = viLocalReturnStatus.
if viLocalReturnStatus < 0 then return.

/* =============================================================================== */
/* Get the Next Free Sequence Number                                               */
/* We use a find last + internal index to get the highest PostingLineSequence used */
/* =============================================================================== */
assign viCounter = 0.
for last tPostingLine where 
         tPostingLine.tc_Status   <> "D":U and 
         tPostingLine.Posting_ID  = tPosting.Posting_ID 
         use-index PostingIDLineSeq:
    assign viCounter = tPostingLine.PostingLineSequence.
end. /* for last tPostingLine where */

if ilCalculateVat
then do:
    assign vhFcComponent        = ?
           vdAmount             = if idFullDebit <> 0 then idFullDebit else if idFullCredit <> 0 then idFullCredit else if idBaseDebit <> 0 then idBaseDebit else if idBaseCredit <> 0 then idBaseCredit else 0
           icTaxTransactionType = if icTaxTransactionType = "":U 
                                  then if ilCustomerInvoice 
                                       then {&VATTAXTRANSACTIONTYPE-ARPAYMENT} 
                                       else {&VATTAXTRANSACTIONTYPE-APPAYMENT} 
                                  /* if transaction type is WHT, then change send AP Trans type to calculate tax */
                                  else if icTaxTransactionType = {&VATTAXTRANSACTIONTYPE-APWHT}
                                  then {&VATTAXTRANSACTIONTYPE-APTRANS}
                                  else icTaxTransactionType.
    <M-38 run CalculateTax
       (input  true (ilStartAndOpenPGTM), 
        input  icCurrencyCode (icCurrencyCode), 
        input  icTaxTransactionType (icTransactionType), 
        input  icDocumentReference (icDocumentReference), 
        input  icDocumentNumber (icDocumentNumber), 
        input  if idFullCredit = 0 and idfullDebit = 0 then false else true (ilTaxIsIncluded), 
        input  itTaxPointDate (itTaxPointDate), 
        input  today (itPostingDate), 
        input  icTxenvTaxEnv (icTaxEnvCode), 
        input  icFromTxzTaxZone (icFromTaxZoneCode), 
        input  icToTxzTaxZone (icToTaxZoneCode), 
        input  icTxclTaxCls (icTaxClassCode), 
        input  icTxuTaxUsage (icTaxUsageCode), 
        input  vdAmount (idAmountTC), 
        input  idExchangeRateScale (idExchangeRateScale), 
        input  idExchangeRate (idExchangeRate), 
        input  vcCompanyCode (icCompanyCode), 
        input  icPaymentCondition (icPaymentCondition), 
        input  ilIsTaxInCityFromCompany (ilIsTaxInCityFromCompany), 
        input  ilIsTaxInCityFromShipTo (ilIsTaxInCityFromShipTo), 
        input  ilIsTaxable (ilIsTaxable), 
        input  idAdjustmentFactor (idAdjustmentFactor), 
        input  ? (iiShipToAddressID), 
        input  ? (iiShipFromAddressID), 
        input  ? (icCustomerCode), 
        input  icInvoiceType (icInvoiceType), 
        input-output tTaxDetailPosting (tTaxDetail), 
        output tTaxParamExtPosting (tTaxParametersExtVAT), 
        output viFcReturnSuper (oiReturnStatus)) in BVAT>
    if viFcReturnSuper <> 0
    then do:
        assign oiReturnStatus = viFcReturnSuper.
        return.
    end. /* end viFcReturnSuper */

    if not can-find(first tTaxDetailPosting)
    then do:
        assign vcMessage      = trim(#T-106'No Tax Rate found for entered specifications.':150(999890120)T-106#) + chr(10) +
                                trim(substitute(#T-107'Tax Class : &1':255(999890121)T-107#, icTxclTaxCls)) + chr(10) +
                                trim(substitute(#T-108'Tax Usage : &2':255(999890122)T-108#, icTxuTaxUsage)) + chr(10) +
                                trim(substitute(#T-109'From Tax Zone and To Tax Zone : &1 and &2':255(999890123)T-109#, icFromTxzTaxZone, icToTxzTaxZone)) + chr(10) +
                                trim(substitute(#T-110'Tax Environment : &1':255(999890124)T-110#, icTxenvTaxEnv)) + chr(10) +
                                trim(substitute(#T-111'Tax Date : &1, Tax Transaction Type : &2, Tax Amount : &3':255(999890125)T-111#, string(itTaxPointDate, "99/99/9999":U), icTaxTransactionType, string(vdAmount)))
               oiReturnStatus = -1.
        <M-105 run AddTaxPostingSetMessage
           (input  vcMessage (icMessage), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        return.
    end. /* end not can-find */
end. /* end ilCalculateVat */

/* get the tax id's based on ship form and ship to address */
<M-77 run AddTaxPostingAddress
   (input  iiShipFromAddressId (iiShipFromAddressId), 
    input  iiShipToAddressId (iiShipToAddressId), 
    input  ilCustomerInvoice (ilCustomerInvoice), 
    input  iiMasterId (iiCreditorId), 
    input  icSoldToDebtorCode (icSoldToDebtorCode), 
    output vcOwnTaxIdFederal (ocOwnTaxIdFederal), 
    output vcOwnTaxIdState (ocOwnTaxIdState), 
    output vcOwnTaxIdMisc1 (ocOwnTaxIdMisc1), 
    output vcOwnTaxIdMisc2 (ocOwnTaxIdMisc2), 
    output vcOwnTaxIdMisc3 (ocOwnTaxIdMisc3), 
    output viOwnTaxDeclaration (oiOwnTaxDeclaration), 
    output vcPostingVatTaxIdFederal (ocTaxIdFederal), 
    output vcPostingVatTaxIdState (ocTaxIdState), 
    output vcPostingVatTaxIdMisc1 (ocTaxIdMisc1), 
    output vcPostingVatTaxIdMisc2 (ocTaxIdMisc2), 
    output vcPostingVatTaxIdMisc3 (ocTaxIdMisc3), 
    output viLocalReturnStatus (oiReturnStatus)) in BPosting>
if viLocalReturnStatus < 0 or (viLocalReturnStatus > 0 and oiReturnStatus = -98)
then assign oiReturnStatus = viLocalReturnStatus.
if viLocalReturnStatus < 0 then return.

for each tTaxDetailPosting where tTaxDetailPosting.tx2d_tr_type <> {&VATTAXTRANSACTIONTYPE-APWHT}:
    assign vdTotalDB = vdTotalDB + (if ilCustomerInvoice
                                    then if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then 0 else if tTaxDetailPosting.tx2d_cur_recov_amt <> 0 then tTaxDetailPosting.tx2d_cur_recov_amt  else tTaxDetailPosting.tx2d_tottax
                                    else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then tTaxDetailPosting.tx2d_cur_recov_amt else 0)
           vdTotalCR = vdTotalCR + (if ilCustomerInvoice
                                    then if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then if tTaxDetailPosting.tx2d_cur_recov_amt <> 0 then tTaxDetailPosting.tx2d_cur_recov_amt else tTaxDetailPosting.tx2d_tottax else 0
                                    else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then 0 else tTaxDetailPosting.tx2d_cur_recov_amt).
end. /* end for each tTaxDetailPosting */

<Q-62 run MfgTaxCodeByTaxCode
   (Start) in BMfgTaxCode >
<Q-64 run GLByIDCode
   (Start) in BGL >
<Q-68 run VatRuleByVatIDCode
   (Start) in BVAT >

FOREACHTAXDETAILBLOCK :
for each tTaxDetailPosting:

    /* -If icTaxTypeCode is not empty, then try to find the same tax type code from tTaxDetailPosting. */
    /* -If icTaxTypeCode is empty, then find the first tax type code from tTaxDetailPosting            */
    /*  which is not WHT type to generate tax posting detail.                                          */
    if icTaxTypeCode <> '':U and icTaxTypeCode <> ? then
    do:
        if tTaxDetailPosting.tx2d_tax_type <> icTaxTypeCode 
        then next.

        if tTaxDetailPosting.tx2d_tr_type = {&VATTAXTRANSACTIONTYPE-APWHT}
        then do:
             assign ilCustomerInvoice = no
                    icTransactionType = {&VATTRANSACTIONTYPE-IMPORT}.
        end.
    end.
    else if tTaxDetailPosting.tx2d_tr_type = {&VATTAXTRANSACTIONTYPE-APWHT} 
    then next.

    <M-104 run AddTaxPostingDetail
       (input  icPostingLineTcRowid (icPostingLineTcRowid), 
        input  itTaxPointDate (itTaxPointDate), 
        input  icDescription (icDescription), 
        input  icCurrencyCode (icCurrencyCode), 
        input  iiCurrencyId (iiCurrencyId), 
        input  idExchangeRate (idExchangeRate), 
        input  idExchangeRateScale (idExchangeRateScale), 
        input  idBaseDebit (idBaseDebit), 
        input  idBaseCredit (idBaseCredit), 
        input  idFullDebit (idFullDebit), 
        input  idFullCredit (idFullCredit), 
        input  icInvoiceType (icInvoiceType), 
        input  ilCalculateVat (ilCalculateVat), 
        input  icDivisionCode (icDivisionCode), 
        input  icVatCurrencyCode (icVatCurrencyCode), 
        input  iiVatCurrencyId (iiVatCurrencyId), 
        input  idVatExchangeRate (idVatExchangeRate), 
        input  idVatExchangeRateScale (idVatExchangeRateScale), 
        input  icTransactionType (icTransactionType), 
        input  icTxclTaxCls (icTxclTaxCls), 
        input  ilCustomerInvoice (ilCustomerInvoice), 
        input  icControlGLCode (icControlGLCode), 
        input  icTaxGLCode (icTaxGLCode), 
        input  icCostCentreCode (icCostCentreCode), 
        input  icProjectCode (icProjectCode), 
        input  icTaxTransactionType (icTaxTransactionType), 
        input  viCounter (iiCounter), 
        input  vdTotalDB (idTotalDB), 
        input  vdTotalCR (idTotalCR), 
        input  vcOwnTaxIdFederal (icOwnTaxIDFederal), 
        input  vcOwnTaxIdState (icOwnTaxIDState), 
        input  vcOwnTaxIdMisc1 (icOwnTaxIDMisc1), 
        input  vcOwnTaxIdMisc2 (icOwnTaxIDMisc2), 
        input  vcOwnTaxIdMisc3 (icOwnTaxIDMisc3), 
        input  viOwnTaxDeclaration (iiOwnTaxDeclaration), 
        input  vcPostingVatTaxIdFederal (icPostingVatTaxIdFederal), 
        input  vcPostingVatTaxIdState (icPostingVatTaxIdState), 
        input  vcPostingVatTaxIdMisc1 (icPostingVatTaxIdMisc1), 
        input  vcPostingVatTaxIdMisc2 (icPostingVatTaxIdMisc2), 
        input  vcPostingVatTaxIdMisc3 (icPostingVatTaxIdMisc3), 
        input  idCCRate (idRateCC), 
        input  idCCRateScale (idRateScaleCC), 
        input-output biFirstVatPostingLineId (biFirstVatPostingLineId), 
        output oiSecondVatPostingLineId (oiSecondVatPostingLineId), 
        output ocPostingLineIds (ocPostingLineIds), 
        input  ilLinkedCrCyDaemonreqExists (ilLinkedCrCyDaemonReqExists), 
        output viLocalReturnStatus (oiReturnStatus)) in BPosting>
    if viLocalReturnStatus < 0 or (viLocalReturnStatus > 0 and oiReturnStatus = -98)
    then assign oiReturnStatus = viLocalReturnStatus.
    if viLocalReturnStatus < 0 then leave.

    leave FOREACHTAXDETAILBLOCK.
end. /* end for each tTaxDetailPosting */

<Q-63 run MfgTaxCodeByTaxCode
   (Stop) in BMfgTaxCode >
<Q-65 run GLByIDCode
   (Stop) in BGL >
<Q-69 run VatRuleByVatIDCode
   (Stop) in BVAT >

if oiReturnStatus < 0 and oiReturnStatus <> -98 then return.
assign oiReturnStatus = 0.