project QadFinancials > class BPosting > method AddPostingLineTax

Description

Public and non-remoting method to create a posting-line on a tax account without having a temp-table as input.


Parameters


icPostingTcRowidinputcharacterThe tc_rowid of the posting your want a new posting-line for
itTaxPointDateinputdatetax point date of the posting-line
icPostingLineTextinputcharacterPosting-line-text
icCurrencyCodeinputcharacterCurrency Code of the posting-line that will be created
icPostingVatInOutinputcharacterIndicates the direction of the taxes: for supplier invoices this will normaly be the incomming direction.
Use proprocessors: VATINOUT
icPostingVatCodeinputcharacter
icPostingVatDomaininputcharacter
idExchangeRateinputdecimalExchange Rate of the posting-line that will be created.
This is the rate information between TC and LC
idExchangeRateScaleinputdecimalExchange Rate Scale of the posting-line that will be created.
This is the rate information between TC and LC
icExchangeRateTypeinputcharacterType of the exchange rate of the posting-line that will be created.
This is the rate information between TC and LC
idCCExchangeRateinputdecimalStatutory currency exchange rate
idCCExchangeRateScaleinputdecimalStatutory currency exchange rate scale
icTransactionTypeinputcharacterTransaction-Type: corresponds with field PostingVat.PostingVatTransType.
Use following preprocessores to fill this parameter: VATTRANSACTIONTYPES
icTaxTransactionTypeinputcharacterTax-Transaction-Type: corresponds with no specific field in the posting but is used to determine some other information.
Pass following preprocessors for this parameter:
VATTAXTRANSACTIONTYPES
idBaseDebitTCinputdecimalBase-Debit -amount in TC of the posting-line that will be created
idBaseCreditTCinputdecimalBase-Credit-amount in TC of the posting-line that will be created
idBaseDebitLCinputdecimalBase-Debit -amount in LC of the posting-line that will be created
idBaseCreditLCinputdecimalBase-Credit-amount in LC of the posting-line that will be created
idBaseDebitCCinputdecimalBase-Debit-amount in CC of the posting-line that will be created
idBaseCreditCCinputdecimalBase-Credit-amount in CC of the posting-line that will be created
idVatDebitTCinputdecimalVat-Debit-amount in TC of the posting-line that will be created
idVatCreditTCinputdecimalVat-Credit-amount in TC of the posting-line that will be created
idVatDebitLCinputdecimalVat-Debit-amount in LC of the posting-line that will be created
idVatCreditLCinputdecimalVat-Credit-amount in LC of the posting-line that will be created
idVatDebitCCinputdecimalVat-Debit-amount in CC of the posting-line that will be created
idVatCreditCCinputdecimalVat-Credit-amount in CC of the posting-line that will be created
icNormalTaxGLCodeinputcharacterGL-code of the posting-line that will be created
icNormalTaxDivisionCodeinputcharacterDivision-code of the posting-line that will be created
ilNormalTaxIsAlreadyAbsRetinputlogicalNormalTaxIsAlreadyAbsRet: set to true in case the posting-line and posting-vat identified by icNormalTaxGLCode concerns an absorbed or retained tax.
If this parameter is true then icAbsRetTaxGLCode should be empty
icAbsRetTaxGLCodeinputcharacterGL-Code that will be used for the tax-postingline that covers the absorbed or retained taxes
icAbsRetTaxDivisionCodeinputcharacterDivisionCode that will be used for the tax-postingline that covers the absorbed or retained taxes
icFromTaxZoneinputcharacterFrom Tax Zone
icToTaxZoneinputcharacterTo Tax Zone
icTaxEnvrionmentinputcharacterTax Environment
ilIsTaxableinputlogicalIs Taxable flag
icTaxClassinputcharacterTax Class
icTaxUsageinputcharacterTax Usage
icTaxTypeinputcharacterTax Type
ilTaxIsReverseChargeDomesticinputlogicalCorresponds with the taxf-lag: tx2_reverse_charge
iiTaxAddressIDinputintegerShip From Address ID in case of purchasing: this paramater is not indeed if the next 5 parameters about the Tax are specified.
If this field is filled, then the next 5 parameters are not taken into account.
icTaxIDFederinputcharacterTaxIDFeder of the TaxAddress
icTaxIDStateinputcharacterState of the TaxAddress
icTaxIDMisc1inputcharacterMisc1 of the TaxAddress
icTaxIDMisc2inputcharacterMisc2 of the TaxAddress
icTaxIDMisc3inputcharacterMisc3 of the TaxAddress
iiOwnAddressIDinputintegerShip To Address ID (address of our own company) in case of purchasing: this parameter is not indeed if the next 6 parameters about the Own-address are specified.
If this field is filled, then the next 6 parameters are not taken into account.
icOwnTaxIDFederinputcharacterOwnTaxIDFeder: Feder of the own address
icOwnTaxIDStateinputcharacterOwnTaxIDState: State of the own address
icOwnTaxIDMisc1inputcharacterOwnTaxIDMisc1: Misc1 of the own address
icOwnTaxIDMisc2inputcharacterOwnTaxIDMisc2: Misc2 of the own address
icOwnTaxIDMisc3inputcharacterOwnTaxIDMisc3: Misc3 of the own address
iiOwnTaxIDDeclaratinputintegerOwnTaxIDDeclarat: Declarat of the own address
ilIsSuspDelinputlogicalilIsSuspDel: Is the tax marked as Suspended or Delayed tax
oiNormalTaxPostingLineIDoutputintegerPosting-line ID of the posting-line on the normal tax-account
ocNormalTaxPostingLineTcRowidoutputcharacterTcRowid of the Posting-line of the posting-line on the normal tax-account
oiAbsRetTaxPostingLineIDoutputintegerID of the Posting-line of the posting-line for the absorbed or retained tax
ocAbsRetTaxPostingLineTcRowidoutputcharacterTcRowid of the Posting-line of the posting-line for the absorbed or retained tax
oiNormalTaxPostingVatIDoutputintegerPosting Vat ID of the normal tax
ilLinkedCrCyDaemonReqExistsinputlogical
ilCalledFromMoveSuspDelTaxinputlogical
itInvoiceExchangeRateDateinputdateIf this is set then this will be the exchange date used to retrieve the exchange rate
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AdditionalUpdatesAllCosts
method BAPMatching.AdditionalUpdatesAllTaxNewOne
method BAPMatching.AdditionalUpdatesAllTaxNewTwo
method BAPMatching.AdditionalUpdatesAllTaxOldOne
method BAPMatching.AdditionalUpdatesAllTaxOldTwo
method BBankEntry.AdditionalUpdatesInvDiscountCurrDiffTax
method BCDocument.AdditionalUpdatesPostingBankCharge
method BCDocument.AdditionalUpdatesPostingBankChargeCtrl
method BCDocument.AdditionalUpdatesPostingCrossCy
method BCDocument.AdditionalUpdatesPostingXrefCIDiscTax
method BCInvoice.CreateCInvoiceMovementsWHT
method BCInvoice.CreateCIPostingTax
method BCInvoice.UpdateCInvoiceVatDelay
method BDDocument.AdditionalUpdatesPostingXrefDIDisc
method BDInvoice.CreateDIPostingTax
method BPosting.AddPostingLineTaxForSuspDel
method BOpenItemAdjustment.OIAdjCommitSubCInvoiceDiscount
method BOpenItemAdjustment.OIAdjCommitSubDInvoiceDiscount


program code (program6/bposting.p)

/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus       = -98
       viLocalReturnStatus  = 0.

/* ============================== */
/* Start major tax-handling block */
/* ============================== */
MAJORTAXHANDLINGBLOCK: DO :

    /* ============================================================================= */
    /* Call sub-method that will do the defaulting and validations of the parameters */
    /* ============================================================================= */
    <M-145 run AddPostingLineTaxValAndDef
       (input-output icPostingTcRowid (bcPostingTcRowid), 
        input-output itTaxPointDate (btTaxPointDate), 
        input-output icPostingLineText (bcPostingLineText), 
        input-output icCurrencyCode (bcCurrencyCode), 
        input-output icPostingVatInOut (bcPostingVatInOut), 
        input  icPostingVatCode (icPostingVatCode), 
        input  icPostingVatDomain (icPostingVatDomain), 
        input-output idExchangeRate (bdExchangeRate), 
        input-output idExchangeRateScale (bdExchangeRateScale), 
        input-output icExchangeRateType (bcExchangeRateType), 
        input-output icTransactionType (bcTransactionType), 
        input-output icTaxTransactionType (bcTaxTransactionType), 
        input-output idBaseDebitTC (bdBaseDebitTC), 
        input-output idBaseCreditTC (bdBaseCreditTC), 
        input-output idBaseDebitLC (bdBaseDebitLC), 
        input-output idBaseCreditLC (bdBaseCreditLC), 
        input-output idBaseDebitCC (bdBaseDebitCC), 
        input-output idBaseCreditCC (bdBaseCreditCC), 
        input-output idVatDebitTC (bdVatDebitTC), 
        input-output idVatCreditTC (bdVatCreditTC), 
        input-output idVatDebitLC (bdVatDebitLC), 
        input-output idVatCreditLC (bdVatCreditLC), 
        input-output idVatDebitCC (bdVatDebitCC), 
        input-output idVatCreditCC (bdVatCreditCC), 
        input-output icNormalTaxGLCode (bcNormalTaxGLCode), 
        input-output icNormalTaxDivisionCode (bcNormalTaxDivisionCode), 
        input-output ilNormalTaxIsAlreadyAbsRet (blNormalTaxIsAlreadyAbsRet), 
        input-output icAbsRetTaxGLCode (bcAbsRetTaxGLCode), 
        input-output icAbsRetTaxDivisionCode (bcAbsRetTaxDivisionCode), 
        input-output icFromTaxZone (bcFromTaxZone), 
        input-output icToTaxZone (bcToTaxZone), 
        input-output icTaxEnvrionment (bcTaxEnvrionment), 
        input-output ilIsTaxable (blIsTaxable), 
        input-output icTaxClass (bcTaxClass), 
        input-output icTaxUsage (bcTaxUsage), 
        input-output icTaxType (bcTaxType), 
        input  iiTaxAddressID (iiTaxAddressID), 
        input-output icTaxIDFeder (bcTaxIDFeder), 
        input-output icTaxIDState (bcTaxIDState), 
        input-output icTaxIDMisc1 (bcTaxIDMisc1), 
        input-output icTaxIDMisc2 (bcTaxIDMisc2), 
        input-output icTaxIDMisc3 (bcTaxIDMisc3), 
        input  iiOwnAddressID (iiOwnAddressID), 
        input-output icOwnTaxIDFeder (bcOwnTaxIDFeder), 
        input-output icOwnTaxIDState (bcOwnTaxIDState), 
        input-output icOwnTaxIDMisc1 (bcOwnTaxIDMisc1), 
        input-output icOwnTaxIDMisc2 (bcOwnTaxIDMisc2), 
        input-output icOwnTaxIDMisc3 (bcOwnTaxIDMisc3), 
        input-output iiOwnTaxIDDeclarat (biOwnTaxIDDeclarat), 
        input-output ilIsSuspDel (blIsSuspDel), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>

    if viFcReturnSuper <> 0 
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then Leave MAJORTAXHANDLINGBLOCK.
    
    /* ======================= */
    /* Find the posting itself */
    /* ======================= */
    find tPosting where 
         tPosting.tc_Rowid = icPostingTcRowid 
         no-error.
    if not available tPosting
    then do:
        assign vcMessage           = trim(substitute(#T-148'Internal error. The system cannot find the posting based upon its row ID (&1).':255(68738)T-148#,icPostingTcRowid))
               viLocalReturnStatus = -3.
        <M-147 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-7811':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave MAJORTAXHANDLINGBLOCK.
    end. /* if not available tPosting */
    
    /* =============================================================================== */
    /* Create PostingLine and PostingVat and Fill the ID and Rowid in the output       */
    /* We use a find last + internal index to get the highest PostingLineSequence used */
    /* =============================================================================== */
    assign viPostingLineSequence = 0.
    for last tPostingLine where 
             tPostingLine.tc_Status   <> "D":U and 
             tPostingLine.Posting_ID  = tPosting.Posting_ID
             use-index PostingIDLineSeq:
        assign viPostingLineSequence = tPostingLine.PostingLineSequence.                                       
    end. /* for each tPostingLine where */    
    
    /* ====================================== */
    /* Create PostingLine and PostingVat and  */
    /* Fill the ID and Rowid in the output    */
    /* ====================================== */
    <M-146 run AddDetailLine
       (input  'PostingLine':U (icTable), 
        input  tPosting.tc_Rowid (icParentRowid), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then Leave MAJORTAXHANDLINGBLOCK.
    <M-149 run AddDetailLine
       (input  'PostingVat':U (icTable), 
        input  tPostingLine.tc_Rowid (icParentRowid), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then Leave MAJORTAXHANDLINGBLOCK.
    assign oiNormalTaxPostingLineID      = tPostingLine.PostingLine_ID
           ocNormalTaxPostingLineTcRowid = tPostingLine.tc_Rowid
           oiNormalTaxPostingVatID       = tPostingVat.PostingVat_ID.
    
    /* ================= */
    /* Get the CC amount */
    /* ================= */
    assign vdPostingLineCCRate  = idCCExchangeRate
           vdPostingLineCCScale = idCCExchangeRateScale.
    if ilCalledFromMoveSuspDelTax = no or 
       itTaxPointDate             = ? 
    then do:
    /* if the itInvoiceExchangeRate is set then use that date - it could either be
       the tax point date or the invoice date depending on the invoice flag */
       
        if itInvoiceExchangeRateDate = ?
        then assign vtTaxPostingDate = tPosting.PostingDate.
        else assign vtTaxPostingDate = itInvoiceExchangeRateDate.     
    end.
    else do:
         assign vtTaxPostingDate = itTaxPointDate.
    end.
    assign vlCurrFetched = false.
    if (idBaseDebitCC   = ? or  idBaseCreditCC  = ? or
        (idBaseDebitCC  = 0 and idBaseCreditCC  = 0)) and
       ((idBaseDebitTC  <> ? and idBaseDebitTC  <> 0) or
        (idBaseCreditTC <> ? and idBaseCreditTC <> 0))
    then do: 
        <M-165 run CalculateCCAmount
           (input  tPosting.Company_ID (iiCompanyID), 
            input  idBaseCreditLC (idPostingLineCreditLC), 
            input  idBaseCreditTC (idPostingLineCreditTC), 
            input  idBaseDebitLC (idPostingLineDebitLC), 
            input  idBaseDebitTC (idPostingLineDebitTC), 
            input  vtTaxPostingDate (itPostingDate), 
            input  icCurrencyCode (icCurrencyCode), 
            input  vtTaxPostingDate (itInvoiceExchangeRateDate), 
            input-output vdPostingLineCCRate (bdCCExchangeRate), 
            input-output vdPostingLineCCScale (bdCCExchangeRateScale), 
            input-output vlCurrFetched (blCurrencyFetched), 
            output idBaseCreditCC (odPostingLineCreditCC), 
            output idBaseDebitCC (odPostingLineDebitCC), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        if viFcReturnSuper <> 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 
        then Leave MAJORTAXHANDLINGBLOCK.
    end. /* if idBaseDebitCC = ? or idBaseCreditCC = ? */
    
    assign vlCurrFetched = false.
    if (idVatDebitCC    = ? or  idVatCreditCC = ? or
        (idVatDebitCC   = 0 and idVatCreditCC = 0)) and
       ((idVatDebitTC  <> ? and idVatDebitTC <> 0) or
        (idVatCreditTC <> ? and idVatCreditTC <> 0))
    then do:
        <M-166 run CalculateCCAmount
           (input  tPosting.Company_ID (iiCompanyID), 
            input  idVatCreditLC (idPostingLineCreditLC), 
            input  idVatCreditTC (idPostingLineCreditTC), 
            input  idVatDebitLC (idPostingLineDebitLC), 
            input  idVatDebitTC (idPostingLineDebitTC), 
            input  vtTaxPostingDate (itPostingDate), 
            input  icCurrencyCode (icCurrencyCode), 
            input  itInvoiceExchangeRateDate (itInvoiceExchangeRateDate), 
            input-output vdPostingLineCCRate (bdCCExchangeRate), 
            input-output vdPostingLineCCScale (bdCCExchangeRateScale), 
            input-output vlCurrFetched (blCurrencyFetched), 
            output idVatCreditCC (odPostingLineCreditCC), 
            output idVatDebitCC (odPostingLineDebitCC), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        if viFcReturnSuper <> 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 
        then Leave MAJORTAXHANDLINGBLOCK.
    end. /* if idVatDebitCC = ? or idVatCreditCC = ? */

    /* ============================================ */
    /* Assign the PostingLine and PostingVat fields */
    /* ============================================ */
    
    <Q-36 run GLByCode (all) (Read) (NoCache)
       (input tPosting.Company_ID, (CompanyId)
        input icNormalTaxGLCode, (GLCode)
        output dataset tqGLByCode) in BGL>

    find first tqGLByCode where tqGLByCode.tcGLCode = icNormalTaxGLCode no-error.
    if available tqGlByCode
    then assign vcGLDescription = tqGLByCode.tcGLDescription.
    else assign vcGLDescription = "":U.
    
    assign viPostingLineSequence                        = viPostingLineSequence + 1
           tPostingLine.PostingLineSequence             = viPostingLineSequence 
           tPostingLine.Posting_ID                      = tPosting.Posting_ID
           tPostingLine.PostingLineText                 = icPostingLineText
           tPostingLine.tcGLCode                        = icNormalTaxGLCode
           tPostingLine.tcGLDescription                 = vcGLDescription
           tPostingLine.tcGLTypeCode                    = {&GLTYPECODE-VAT}
           tPostingLine.tcDivisionCode                  = icNormalTaxDivisionCode
           tPostingLine.tcCurrencyCode                  = icCurrencyCode
           tPostingLine.PostingLineExchangeRate         = idExchangeRate
           tPostingLine.PostingLineRateScale            = idExchangeRateScale
           tPostingLine.tlPostingLineIsLocalCurrency    = (tPostingLine.tcCurrencyCode = vcCompanyLC)
           tPostingLine.PostingLineDebitTC              = idVatDebitTC
           tPostingLine.PostingLineCreditTC             = idVatCreditTC
           tPostingLine.PostingLineDebitLC              = idVatDebitLC
           tPostingLine.PostingLineCreditLC             = idVatCreditLC
           tPostingLine.PostingLineDebitCC              = idVatDebitCC
           tPostingLine.PostingLineCreditCC             = idVatCreditCC
           tPostingLine.PostingLineCCRate               = vdPostingLineCCRate
           tPostingLine.PostingLineCCScale              = vdPostingLineCCScale
           tPostingLine.tlLinkedCrCyDaemonReqExists = ilLinkedCrCyDaemonreqExists
           tPostingVat.PostingLine_ID                   = tPostingLine.PostingLine_ID
           tPostingVat.tcCurrencyCode                   = tPostingLine.tcCurrencyCode
           tPostingVat.tcVatCode                        = icPostingVatCode
           tPostingVat.tcDomainCode                     = icPostingVatDomain
           tPostingVat.tcVatInOut                       = icPostingVatInOut
           tPostingVat.PostingVatBaseDebitTC            = idBaseDebitTC
           tPostingVat.PostingVatBaseCreditTC           = idBaseCreditTC
           tPostingVat.PostingVatBaseDebitLC            = idBaseDebitLC
           tPostingVat.PostingVatBaseCreditLC           = idBaseCreditLC
           tPostingVat.PostingVatBaseDebitCC            = idBaseDebitCC
           tPostingVat.PostingVatBaseCreditCC           = idBaseCreditCC
           tPostingVat.PostingVatTaxPointDate           = itTaxPointDate
           tPostingVat.PostingVatTaxDebitTC             = tPostingLine.PostingLineDebitTC
           tPostingVat.PostingVatTaxCreditTC            = tPostingLine.PostingLineCreditTC
           tPostingVat.PostingVatTaxDebitLC             = tPostingLine.PostingLineDebitLC
           tPostingVat.PostingVatTaxCreditLC            = tPostingLine.PostingLineCreditLC
           tPostingVat.PostingVatTaxDebitCC             = tPostingLine.PostingLineDebitCC
           tPostingVat.PostingVatTaxCreditCC            = tPostingLine.PostingLineCreditCC
           tPostingVat.PostingVatExchangeRate           = 1 /* Set to 1 to make sure the VAT reports keep working */
           tPostingVat.PostingVatRateScale              = 1
           tPostingVat.TxtyTaxType                      = icTaxType    
           tPostingVat.TxclTaxCls                       = icTaxClass
           tPostingVat.TxuTaxUsage                      = icTaxUsage
           tPostingVat.PostingVatTaxTransType           = icTaxTransactionType
           tPostingVat.PostingVatInOut                  = tPostingVat.tcVatInOut
           tPostingVat.PostingVatTransType              = icTransactionType
           tPostingVat.TxenvTaxEnv                      = icTaxEnvrionment
           tPostingVat.FromTxzTaxZone                   = icFromTaxZone
           tPostingVat.ToTxzTaxZone                     = icToTaxZone
           tPostingVat.PostingVatIsReverseCharge        = ilTaxIsReverseChargeDomestic
           tPostingVat.PostingVatIsAbsRet               = ilNormalTaxIsAlreadyAbsRet
           tPostingVat.PostingVatOwnTaxIDFeder          = icOwnTaxIDFeder
           tPostingVat.PostingVatOwnTaxIDState          = icOwnTaxIdState
           tPostingVat.PostingVatOwnTaxIDMisc1          = icOwnTaxIdMisc1
           tPostingVat.PostingVatOwnTaxIDMisc2          = icOwnTaxIdMisc2
           tPostingVat.PostingVatOwnTaxIDMisc3          = icOwnTaxIdMisc3
           tPostingVat.PostingVatOwnTaxDeclarat         = iiOwnTaxIDDeclarat
           tPostingVat.PostingVatTaxIDFeder             = icTaxIDFeder
           tPostingVat.PostingVatTaxIDState             = icTaxIDState
           tPostingVat.PostingVatTaxIDMisc1             = icTaxIDMisc1
           tPostingVat.PostingVatTaxIDMisc2             = icTaxIDMisc2
           tPostingVat.PostingVatTaxIDMisc3             = icTaxIDMisc3
           tPostingVat.PostingVatIsSuspDel              = ilIsSuspDel.
  
    /* Set the CC Rate */  
    if vdPostingLineCCRate = 0 or vdPostingLineCCScale = 0 or
       vdPostingLineCCRate = ? or vdPostingLineCCScale = ?
    then do:
        if tPostingLine.tcCurrencyCode = vcCompanyCC
        then assign tPostingLine.PostingLineCCRate  = 1
                    tPostingLine.PostingLineCCScale = 1.
        else if vlDomainIsStatutory = false
             then assign tPostingLine.PostingLineCCRate  = vdPostingLineCCRate
                         tPostingLine.PostingLineCCScale = vdPostingLineCCScale.
             else if tPostingLine.PostingLineDebitTC - tPostingLine.PostingLineCreditTC = 0
                  then assign tPostingLine.PostingLineCCRate  = 0
                              tPostingLine.PostingLineCCScale = 0.
                  else assign tPostingLine.PostingLineCCRate  = absolute(round((tPostingLine.PostingLineDebitCC - tPostingLine.PostingLineCreditCC) / (tPostingLine.PostingLineDebitTC - tPostingLine.PostingLineCreditTC), 10)) 
                              tPostingLine.PostingLineCCScale = 1.
    end. /* if vdPostingLineCCRate = 0 or vdPostingLineCCScale = 0 */

    /* ================= */
    /* State the VatRule */
    /* ================= */
    if vlStartedQryVatRuleByVatIDCode = false
    then do :
        <Q-156 run VatRuleByVatIDCode  (Start) in BVAT >
        assign vlStartedQryVatRuleByVatIDCode = true.
    end. /* if vlStartedQryVatRuleByVatIDCode = true */
    <Q-151 run VatRuleByVatIDCode (all) (Read) (NoCache)
       (input tPostingVat.tcVatCode, (VatCode)
        input ?, (VatID)
        input {&VATRULEBASE-FULL}, (VatRuleBaseFull)
        input tPostingVat.tcVatInOut, (VatInOut)
        input tPostingVat.tcDomainCode, (DomainCode)
        output dataset tqVatRuleByVatIDCode) in BVAT >
    if ilNormalTaxIsAlreadyAbsRet = true
    then find last tqVatRuleByVatIDCode no-error.    /* the last one it the one for retained absorbed taxes */
    else find first  tqVatRuleByVatIDCode no-error.  /* the first one it the one for non-retained non-absorbed taxes */  
    if not available tqVatRuleByVatIDCode
    then do:
        assign vcMessage           = trim(substitute(#T-155'Internal error. The system cannot create the tax posting line because the tax rule cannot be found based on the domain (&1), tax code (&2) and tax direction (&3).':255(68753)T-155#,tPostingVat.tcDomainCode,tPostingVat.tcVatCode,tPostingVat.tcVatInOut))
               viLocalReturnStatus = -3.
        <M-154 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-7813':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave MAJORTAXHANDLINGBLOCK.
    end. /* if not available tqVatRuleByVatIDCode */
    assign tPostingVat.VatRule_ID = tqVatRuleByVatIDCode.tiVatRule_ID.
    
    /* ===================================================================== */
    /* Create the absorbed/retained postingline on tax account when needed   */
    /* ===================================================================== */
    if icAbsRetTaxGLCode <> "":U 
    then do :
        /* =============================================================================== */
        /* Hold a buffer to the newly created tPostingLine and tPostingVat as we need them */
        /* further on in this method and we will use tPostingLine for the new record       */
        /* =============================================================================== */
        find btPostingLine where 
             rowid(btPostingLine) = rowid(tPostingLine)
             no-lock no-error.
        find btPostingVat where 
             rowid(btPostingVat) = rowid(tPostingVat)
             no-lock no-error.
        if not available btPostingLine or 
           not available btPostingVat
        then do :
            assign vcMessage           = trim(substitute(#T-158'Internal error. The system cannot find the tax posting line for the retained/absorbed taxes because the originating posting line cannot be found.':255(68754)T-158#))
                   viLocalReturnStatus = -3.
            <M-157 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-7814':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            Leave MAJORTAXHANDLINGBLOCK.
        end. /* if not available btPostingLine or */
        /* ====================================== */
        /* Create PostingLine and PostingVat and  */
        /* Fill the ID and Rowid in the output    */
        /* ====================================== */
        <Q-13 run GLByCode (all) (Read) (NoCache)
           (input tPosting.Company_ID, (CompanyId)
            input icAbsRetTaxGLCode, (GLCode)
            output dataset tqGLByCode) in BGL>
            
        find first tqGLByCode  where tqGLByCode.tcGLCode = icAbsRetTaxGLCode  no-error.   
        if available tqGlByCode
        then assign vcGLDescription = tqGLByCode.tcGLDescription.
        else assign vcGLDescription = "":U.          
        
        <M-159 run AddDetailLine
           (input  'PostingLine':U (icTable), 
            input  tPosting.tc_Rowid (icParentRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        if viFcReturnSuper <> 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 
        then Leave MAJORTAXHANDLINGBLOCK.
        <M-160 run AddDetailLine
           (input  'PostingVat':U (icTable), 
            input  tPostingLine.tc_Rowid (icParentRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        if viFcReturnSuper <> 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 
        then Leave MAJORTAXHANDLINGBLOCK.
        assign oiAbsRetTaxPostingLineID      = tPostingLine.PostingLine_ID
               ocAbsRetTaxPostingLineTcRowid = tPostingLine.tc_Rowid.
        /* =============================================================================================== */
        /* Assign the PostingLine and PostingVat fields based upon the original PostingLine and PostingVat */
        /* The only differences bwteen the absorbed/retained and the first postingline is that the amounts */
        /* are inversed (* -1) in posting-line and posting-vat and that the TaxBase is set to zero         */
        /* =============================================================================================== */
        assign viPostingLineSequence = viPostingLineSequence + 1.
        buffer-copy btPostingLine
                    except tc_rowid tc_parentrowid tc_status PostingLine_ID
                    to tPostingLine
                    assign tPostingLine.PostingLineSequence = viPostingLineSequence
                           tPostingLine.PostingLineDebitTC  = btPostingLine.PostingLineCreditTC
                           tPostingLine.PostingLineCreditTC = btPostingLine.PostingLineDebitTC 
                           tPostingLine.PostingLineDebitLC  = btPostingLine.PostingLineCreditLC 
                           tPostingLine.PostingLineCreditLC = btPostingLine.PostingLineDebitLC
                           tPostingLine.PostingLineDebitCC  = btPostingLine.PostingLineCreditCC
                           tPostingLine.PostingLineCreditCC = btPostingLine.PostingLineDebitCC
                           tPostingLine.tcGLCode            = icAbsRetTaxGLCode
                           tPostingLine.tcGLDescription     = vcGLDescription
                           tPostingLine.tcDivisionCode      = icAbsRetTaxDivisionCode.
        buffer-copy btPostingVat
                    except tc_rowid tc_parentrowid tc_status VatRule_ID PostingLine_ID PostingVat_ID
                    to tPostingVat
                    assign tPostingVat.PostingLine_ID           = tPostingLine.PostingLine_ID
                           tPostingVat.PostingVatBaseDebitTC    = idBaseCreditTC 
                           tPostingVat.PostingVatBaseCreditTC   = idBaseDebitTC 
                           tPostingVat.PostingVatBaseDebitLC    = idBaseCreditLC 
                           tPostingVat.PostingVatBaseCreditLC   = idBaseDebitLC 
                           tPostingVat.PostingVatBaseDebitCC    = idBaseCreditCC
                           tPostingVat.PostingVatBaseCreditCC   = idBaseDebitCC
                           tPostingVat.PostingVatTaxDebitTC     = tPostingLine.PostingLineDebitTC
                           tPostingVat.PostingVatTaxCreditTC    = tPostingLine.PostingLineCreditTC
                           tPostingVat.PostingVatTaxDebitLC     = tPostingLine.PostingLineDebitLC
                           tPostingVat.PostingVatTaxCreditLC    = tPostingLine.PostingLineCreditLC
                           tPostingVat.PostingVatTaxDebitCC     = tPostingLine.PostingLineDebitCC
                           tPostingVat.PostingVatTaxCreditCC    = tPostingLine.PostingLineCreditCC
                           tPostingVat.PostingVatIsAbsRet       = true.
        /* ================= */
        /* State the VatRule */
        /* ================= */
        <Q-162 run VatRuleByVatIDCode (all) (Read) (NoCache)
           (input tPostingVat.tcVatCode, (VatCode)
            input ?, (VatID)
            input {&VATRULEBASE-FULL}, (VatRuleBaseFull)
            input tPostingVat.tcVatInOut, (VatInOut)
            input tPostingVat.tcDomainCode, (DomainCode)
            output dataset tqVatRuleByVatIDCode) in BVAT >
        find last tqVatRuleByVatIDCode no-error. /* the last one it the one for retained-absorbed taxes */
        if not available tqVatRuleByVatIDCode
        then do:
            assign vcMessage           = trim(substitute(#T-164'Internal error. The system cannot create the tax posting line because the tax rule cannot be found based on the domain (&1), tax code (&2) and tax direction (&3).':255(68753)T-164#,tPostingVat.tcDomainCode,tPostingVat.tcVatCode,tPostingVat.tcVatInOut))
                   viLocalReturnStatus = -3.
            <M-163 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-7815':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            Leave MAJORTAXHANDLINGBLOCK.
        end. /* if not available tqVatRuleByVatIDCode */
        assign tPostingVat.VatRule_ID = tqVatRuleByVatIDCode.tiVatRule_ID.
    end. /* if icAbsRetTaxGLCode <> "":U  */
    
END. /* MAJORTAXHANDLINGBLOCK */

/* ================== */
/* Stop Queries       */
/* ================== */
if vlStartedQryVatRuleByVatIDCode = true
then do :
    <Q-150 run VatRuleByVatIDCode  (Stop) in BVAT >
end. /* if vlStartedQryVatRuleByVatIDCode = true */

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