project QadFinancials > class BDInvoice > method DefaultValuesTax

Description

default the tax records on the tax tab


Parameters


iiDinvoiceIdinputintegerDInvoice ID
icCurrencyCodeinputcharactercurrency of the invoice
icDocumentReferenceinputcharacteryear/daybook+voucher
itTaxPointDateinputdateTax Point Date of the invoice
icShipFromTaxZoneinputcharacterTax Zone of the Ship to
icShipToTaxZoneinputcharacterTax Zone fo the Ship To address
icDebtorCodeinputcharacterDebtor Code
icTxclTaxClassinputcharacterTax Class from the debtor
icTxuTaxUsageinputcharacterTax Usage of the Debtor
idInvoiceAmountTCinputdecimalInvoice Amount in TC
idExchangeRateinputdecimalexchange rate
idExchangeRateScaleinputdecimalScale Factor of the invoice
icPaymentConditionCodeinputcharacterPayment condtion of the debtor
itPostingDateinputdateposting date
ilTaxableinputlogicalTaxable ?
ilDInvoiceIsTaxExcludedinputlogicalIs the amount exclude tax or not ? pass field from screen to it
icInvoiceTypeinputcharacter
ilShipToAddressIsTaxInCityinputlogicaltax in city flag of the ship to address
idVatExchangeRateinputdecimalVat Exchange Rate
idVatRateScaleinputdecimalScale factor of Vat exchange rate
idCCExchangeRateinputdecimal
idCCExchangeRateScaleinputdecimal
iiShipToAddressIDinputintegerShip To Address ID
iiShipFromAddressIDinputintegerShip From Address ID
ocTxenvTaxEnvoutputcharacterTax Environment
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.ApiStdMaintainTTWithIntPost
method BDInvoice.CreateDInvoices
method BDInvoice.DefaultValuesGeneralInfo
method BDInvoice.StdMaintainTTWithIntPost


program code (program3/bdinvoice.p)

assign oiReturnStatus = -98.

/* replace unknown values */
if iiDinvoiceId = ? then assign iiDinvoiceId = 0.
if icCurrencyCode = ? then assign icCurrencyCode = "":U.
if icDocumentReference = ? then assign icDocumentReference = "":U.
if icShipFromTaxZone = ? then assign icShipFromTaxZone = "":U.
if icShipToTaxZone = ? then assign icShipToTaxZone = "":U.
if icDebtorCode = ? then assign icDebtorCode = "":U.
if icTxclTaxClass = ? then assign icTxclTaxClass = "":U.
if icTxuTaxUsage = ? then assign icTxuTaxUsage = "":U.
if idInvoiceAmountTC = ? then assign idInvoiceAmountTC = 0.
if idExchangeRate = ? then assign idExchangeRate = 0.
if idExchangeRateScale = ? then assign idExchangeRateScale = 0.
if icPaymentConditionCode = ? then assign icPaymentConditionCode = "":U.
if icInvoiceType = ? then assign icInvoiceType = "":U.
if ilShipToAddressIsTaxInCity = ? then assign ilShipToAddressIsTaxInCity = false.
if ilDInvoiceIsTaxExcluded = ? then assign ilDInvoiceIsTaxExcluded = false.
if idCCExchangeRate = ? then assign idCCExchangeRate = 0.
if idCCExchangeRateScale = ? then assign idCCExchangeRateScale = 0.
if iiShipFromAddressID = ? then assign iiShipFromAddressID= 0.
if iiShipToAddressID = ? then assign iiShipToAddressID = 0.

empty temp-table tTaxDetailDInvoice.

if icCurrencyCode = vcCompanyCC   /* TC = SC */
then do:
    assign idCCExchangeRate       = 1
           idCCExchangeRateScale  = 1.
end.               
else if vlDomainIsStatutory = false         /* TC/LC Rate */
then do:
    assign idCCExchangeRate       = idExchangeRate
           idCCExchangeRateScale  = idExchangeRateScale.           
end. 

if iiDInvoiceId <> 0
then find tDInvoice where
          tDInvoice.DInvoice_ID =  iiDinvoiceId no-error.
else find tDInvoice no-error.

if not available tDInvoice
then do:
    assign oiReturnStatus = -1
        vcMessage = substitute(trim(#T-1'Invoice ($1) not found: The system cannot display the default values of the taxes.':255(48976)t-1#), iiDInvoiceID).
    <M-2 run SetMessage
       (input  vcMessage (icMessage), 
        input  ? (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '' (icRowid), 
        input  'QadFin-6922':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    return.
end.

if icInvoiceType <> "":U and icInvoiceType <> ? 
    and icInvoiceType <> {&INVOICETYPE-INVOICE} 
    and icInvoiceType <> {&INVOICETYPE-FINANCECHARGE} 
    and icInvoiceType <> {&INVOICETYPE-CREDITNOTE} 
    and icInvoiceType <> {&INVOICETYPE-INVOICECORRECTION} 
    and icInvoiceType <> {&INVOICETYPE-CREDITNOTECORRECTION} 
    and icInvoiceType <> {&INVOICETYPE-PREPAYMENT} 
    and icInvoiceType <> {&INVOICETYPE-ADJUSTMENT}
    and icInvoiceType <> {&INVOICETYPE-DEDUCTION}
then do:
    assign vcMessage = trim(substitute(#T-3'The invoice type must be &1, &2, &3, &4, &5, &6, &7, or &8.':255(65106)t-3#,
        {&INVOICETYPE-FINANCECHARGE}, {&INVOICETYPE-CREDITNOTE}, {&INVOICETYPE-INVOICECORRECTION}, {&INVOICETYPE-CREDITNOTECORRECTION}, {&INVOICETYPE-PREPAYMENT}, {&INVOICETYPE-ADJUSTMENT}, {&INVOICETYPE-DEDUCTION}))
        oiReturnStatus = -1.
    <M-4 run SetMessage
       (input  vcMessage (icMessage), 
        input  '' (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '' (icRowid), 
        input  'QadFin-6923':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    return.
end.
        
if icShipFromTaxZone = "":U or icShipToTaxZone = "":U
then do:
    assign vcMessage = trim(#T-5'The tax zones of the ship-from and ship-to are mandatory.':150(55956)t-5#)
        oiReturnStatus = -1.
    <M-6 run SetMessage
       (input  vcMessage (icMessage), 
        input  '' (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '' (icRowid), 
        input  'QadFin-6924':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    return.
end.

/* Delete the old records */
for each tDInvoiceVat where
         tDInvoiceVat.tc_ParentRowid = tDInvoice.tc_Rowid :
    if tDInvoiceVat.tc_Status = "N":U
    then delete tDInvoiceVat.
    else assign tDInvoiceVat.tc_Status = "D":U.
end.

assign vhFcComponent = ?.
if ( tDInvoice.DInvoiceType = {&INVOICETYPE-PREPAYMENT} or
     tDInvoice.DInvoiceType = {&INVOICETYPE-ADJUSTMENT} ) and 
   not ilTaxable
then ilDInvoiceIsTaxExcluded = true.

<M-23 run GetTaxEnvironmentAndCalculateTax
   (input  icShipFromTaxZone (icShipFromTaxZone), 
    input  icShipToTaxZone (icShipToTaxZone), 
    input  icTxclTaxClass (icTxclTaxCls), 
    input  icCurrencyCode (icCurrencyCode), 
    input  {&VATTAXTRANSACTIONTYPE-ARDTCRMEMO} (icTransactionType), 
    input  icDocumentReference (icDocumentReference), 
    input  ? (icDocumentNumber), 
    input  not ilDInvoiceIsTaxExcluded (ilTaxIsIncluded), 
    input  itTaxPointDate (itTaxPointDate), 
    input  itPostingDate (itPostingDate), 
    input  icTxuTaxUsage (icTaxUsageCode), 
    input  idInvoiceAmountTC (idAmountTC), 
    input  idExchangeRateScale (idExchangeRateScale), 
    input  idExchangeRate (idExchangeRate), 
    input  vcCompanyCode (icCompanyCode), 
    input  icPaymentConditionCode (icPaymentCondition), 
    input  vlIsCompanyTaxInCity (ilIsTaxInCityFromCompany), 
    input  ilShipToAddressIsTaxInCity (ilIsTaxInCityFromShipTo), 
    input  ilTaxable (ilIsTaxable), 
    input  ? (idAdjustmentFactor), 
    input  iiShipFromAddressID (iiShipFromAddressID), 
    input  iiShipToAddressID (iiShipToAddressID), 
    input  icDebtorCode (icCustomerCode), 
    input  icInvoiceType (icInvoiceType), 
    input-output tTaxDetailDInvoice (tTaxDetail), 
    output tTaxParamExtDInv (tTaxParametersExtVAT), 
    output ocTxenvTaxEnv (ocTxenvTaxEnv), 
    output viLocalReturnStatus (oiReturnStatus)) in BVAT>
if viLocalReturnStatus <> 0
then do:
    assign oiReturnStatus = viLocalReturnStatus.
    if oiReturnStatus < 0
    then return.
end.

/* check if more than one tax record is retrieved from gtm */
assign viNrOfTaxRecords = 0.
for each tTaxDetailDInvoice :
    assign viNrOfTaxRecords = viNrOfTaxRecords + 1.
end.

assign viTaxRecordSeq           = 0
       vcCompanyPropertySuspTax = '':U.

<Q-39 run CompanyPropertyBySuspDelTax (all) (Read) (Cache)
   (input viCompanyId, (CompanyId)
    input ?, (DelTax)
    input {&SUSPDELAYTAX-NOTAPPLICABLE}, (SuspTax)
    output dataset tqCompanyPropertyBySuspDelTax) in BCompanyProperty>
        
find first tqCompanyPropertyBySuspDelTax no-error.
if available tqCompanyPropertyBySuspDelTax 
then assign vlAvailCompPropBySuspDelTax = true
            vcCompanyPropertySuspTax    = tqCompanyPropertyBySuspDelTax.tcCompanyPropertySuspTax.
else assign vlAvailCompPropBySuspDelTax = false.

for each tTaxDetailDInvoice :

    <M-10 run AddDetailLine
       (input  'DInvoiceVat':U (icTable), 
        input  tDInvoice.tc_RowID (icParentRowid), 
        output viLocalReturnStatus (oiReturnStatus)) in BDInvoice>   

    if viLocalReturnStatus <> 0
    then do:
        assign oiReturnStatus = viLocalReturnStatus.
        if oiReturnStatus < 0 then return.
    end.
    
    /* ======================== */
    /* assign the record values */
    /* ======================== */
    assign tDInvoiceVat.DInvoice_ID                  = tDInvoice.DInvoice_ID
           viTaxRecordSeq                            = viTaxRecordSeq + 1   
           tDInvoiceVat.DInvoiceVatSequence          = viTaxRecordSeq
           tDInvoiceVat.DInvoiceVatUILinkedRowID     = "0":U
           tDInvoiceVat.tlIsAvataxTaxLine = tTaxDetailDInvoice.tlIsAvataxLine
           tDInvoiceVat.DInvoiceVatVatBaseDebitTC    = if viNrOfTaxRecords > 1 and
                                                          not ilDInvoiceIsTaxExcluded
                                                       then 0
                                                       else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} 
                                                            then 0 
                                                            else <M-24 RoundAmount
                                                                    (input  tTaxDetailDInvoice.tx2d_tottax (idUnroundedAmount), 
                                                                     input  ? (iiCurrencyID), 
                                                                     input  icCurrencyCode (icCurrencyCode)) in BDInvoice>
           tDInvoiceVat.DInvoiceVatVatBaseCreditTC   = if viNrOfTaxRecords > 1 and
                                                          not ilDInvoiceIsTaxExcluded
                                                       then 0
                                                       else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} 
                                                            then <M-25 RoundAmount
                                                                    (input  tTaxDetailDInvoice.tx2d_tottax (idUnroundedAmount), 
                                                                     input  ? (iiCurrencyID), 
                                                                     input  icCurrencyCode (icCurrencyCode)) in BDInvoice> 
                                                            else 0
           tDInvoiceVat.DInvoiceVatVatBaseDebitLC    = if viNrOfTaxRecords > 1 and
                                                          not ilDInvoiceIsTaxExcluded
                                                       then 0
                                                       else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} 
                                                            then 0 
                                                            else <M-30 RoundAmount
                                                                    (input  tTaxDetailDInvoice.tx2d_taxable_amt (idUnroundedAmount), 
                                                                     input  viCompanyLCId (iiCurrencyID), 
                                                                     input  vcCompanyLC (icCurrencyCode)) in BDInvoice>
           tDInvoiceVat.DInvoiceVatVatBaseCreditLC   = if viNrOfTaxRecords > 1 and
                                                          not ilDInvoiceIsTaxExcluded
                                                       then 0
                                                       else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} 
                                                            then <M-31 RoundAmount
                                                                    (input  tTaxDetailDInvoice.tx2d_taxable_amt (idUnroundedAmount), 
                                                                     input  viCompanyLCId (iiCurrencyID), 
                                                                     input  vcCompanyLC (icCurrencyCode)) in BDInvoice> 
                                                            else 0
            tDInvoiceVat.DInvoiceVatVatBaseDebitCC   = if viNrOfTaxRecords > 1 and
                                                         not ilDInvoiceIsTaxExcluded
                                                      then 0
                                                      else  <M-42 RoundAmount
                                                                     (input  tDInvoiceVat.DInvoiceVatVatBaseDebitTC * idCCExchangeRate * idCCExchangeRateScale (idUnroundedAmount), 
                                                                      input  viCompanyCCId (iiCurrencyID), 
                                                                      input  vcCompanyCC (icCurrencyCode)) in BDInvoice>
            tDInvoiceVat.DInvoiceVatVatBaseCreditCC  = if viNrOfTaxRecords > 1 and
                                                         not ilDInvoiceIsTaxExcluded
                                                       then 0
                                                       else <M-93 RoundAmount
                                                                     (input  tDInvoiceVat.DInvoiceVatVatBaseCreditTC * idCCExchangeRate * idCCExchangeRateScale (idUnroundedAmount), 
                                                                      input  viCompanyCCId (iiCurrencyID), 
                                                                      input  vcCompanyCC (icCurrencyCode)) in BDInvoice>

            tDInvoiceVat.DInvoiceVatNTBaseDebitTC     = if viNrOfTaxRecords > 1 and
                                                           not ilDInvoiceIsTaxExcluded
                                                        then 0
                                                        else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} 
                                                            then 0 
                                                            else <M-40 RoundAmount
                                                                    (input  tTaxDetailDInvoice.tx2d_nontax_amt (idUnroundedAmount), 
                                                                     input  ? (iiCurrencyID), 
                                                                     input  icCurrencyCode (icCurrencyCode)) in BDInvoice>
            tDInvoiceVat.DInvoiceVatNTBaseCreditTC    = if viNrOfTaxRecords > 1 and
                                                          not ilDInvoiceIsTaxExcluded
                                                        then 0
                                                        else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} 
                                                             then <M-41 RoundAmount
                                                                     (input  tTaxDetailDInvoice.tx2d_nontax_amt (idUnroundedAmount), 
                                                                      input  ? (iiCurrencyID), 
                                                                      input  icCurrencyCode (icCurrencyCode)) in BDInvoice> 
                                                             else 0
            tDInvoiceVat.DInvoiceVatVatDebitTC        = if viNrOfTaxRecords > 1 and
                                                           not ilDInvoiceIsTaxExcluded
                                                       then 0
                                                       else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} 
                                                            then - <M-26 RoundAmount
                                                                      (input  tTaxDetailDInvoice.tx2d_cur_abs_ret_amt (idUnroundedAmount), 
                                                                       input  ? (iiCurrencyID), 
                                                                       input  icCurrencyCode (icCurrencyCode)) in BDInvoice> /* defect 10259-0132 ddl */
                                                            else <M-27 RoundAmount
                                                                    (input  tTaxDetailDInvoice.tx2d_cur_tax_amt (idUnroundedAmount), 
                                                                     input  ? (iiCurrencyID), 
                                                                     input  icCurrencyCode (icCurrencyCode)) in BDInvoice>
           tDInvoiceVat.DInvoiceVatVatCreditTC       = if viNrOfTaxRecords > 1 and
                                                          not ilDInvoiceIsTaxExcluded
                                                       then 0
                                                       else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} 
                                                            then <M-28 RoundAmount
                                                                    (input  tTaxDetailDInvoice.tx2d_cur_tax_amt (idUnroundedAmount), 
                                                                     input  ? (iiCurrencyID), 
                                                                     input  icCurrencyCode (icCurrencyCode)) in BDInvoice> 
                                                            else - <M-29 RoundAmount
                                                                      (input  tTaxDetailDInvoice.tx2d_cur_abs_ret_amt (idUnroundedAmount), 
                                                                       input  ? (iiCurrencyID), 
                                                                       input  icCurrencyCode (icCurrencyCode)) in BDInvoice> /* defect 10259-0132 ddl */
            tDInvoiceVat.DInvoiceVatVatDebitLC       = if viNrOfTaxRecords > 1 and
                                                          not ilDInvoiceIsTaxExcluded
                                                       then 0
                                                       else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} 
                                                            then - <M-32 RoundAmount
                                                                      (input  tTaxDetailDInvoice.tx2d_abs_ret_amt (idUnroundedAmount), 
                                                                       input  viCompanyLCId (iiCurrencyID), 
                                                                       input  vcCompanyLC (icCurrencyCode)) in BDInvoice> /* defect 10259-0132 ddl */
                                                            else <M-33 RoundAmount
                                                                    (input  tTaxDetailDInvoice.tx2d_tax_amt (idUnroundedAmount), 
                                                                     input  viCompanyLCId (iiCurrencyID), 
                                                                     input  vcCompanyLC (icCurrencyCode)) in BDInvoice>
           tDInvoiceVat.DInvoiceVatVatCreditLC       = if viNrOfTaxRecords > 1 and
                                                          not ilDInvoiceIsTaxExcluded
                                                       then 0
                                                       else if icInvoiceType = {&INVOICETYPE-INVOICE} or icInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icInvoiceType = {&INVOICETYPE-INVOICECORRECTION} 
                                                            then <M-34 RoundAmount
                                                                    (input  tTaxDetailDInvoice.tx2d_tax_amt (idUnroundedAmount), 
                                                                     input  viCompanyLCId (iiCurrencyID), 
                                                                     input  vcCompanyLC (icCurrencyCode)) in BDInvoice> 
                                                            else - <M-35 RoundAmount
                                                                      (input  tTaxDetailDInvoice.tx2d_abs_ret_amt (idUnroundedAmount), 
                                                                       input  viCompanyLCId (iiCurrencyID), 
                                                                       input  vcCompanyLC (icCurrencyCode)) in BDInvoice> /* defect 10259-0132 ddl */
           tDInvoiceVat.DInvoiceVatVatDebitCC       = if viNrOfTaxRecords > 1 and
                                                         not ilDInvoiceIsTaxExcluded
                                                          then 0
                                                          else <M-81 RoundAmount
                                                                  (input  tDInvoiceVat.DInvoiceVatVatDebitTC * idCCExchangeRate * idccExchangeRateScale (idUnroundedAmount), 
                                                                   input  viCompanyCCId (iiCurrencyID), 
                                                                   input  vcCompanyCC (icCurrencyCode)) in BDInvoice>                              
                                                                               
           tDInvoiceVat.DInvoiceVatVatCreditCC      = if viNrOfTaxRecords > 1 and
                                                         not ilDInvoiceIsTaxExcluded
                                                          then 0
                                                          else <M-7 RoundAmount
                                                                  (input  tDInvoiceVat.DInvoiceVatVatCreditTC * idCCExchangeRate * idCCExchangeRateScale (idUnroundedAmount), 
                                                                   input  viCompanyCCId (iiCurrencyID), 
                                                                   input  vcCompanyCC (icCurrencyCode)) in BDInvoice>  
           tDInvoiceVat.DInvoiceVatIsTaxable         = ilTaxable
           tDInvoiceVat.TxclTaxCls                   = tTaxDetailDInvoice.tx2d_taxc
           tDInvoiceVat.TxenvTaxEnv                  = ocTxenvTaxEnv
           tDInvoiceVat.TxuTaxUsage                  = tTaxDetailDInvoice.tx2d_tax_usage
           tDInvoiceVat.TxtyTaxType                  = tTaxDetailDInvoice.tx2d_tax_type
           tDInvoiceVat.tcVatCode                    = tTaxDetailDInvoice.tx2d_tax_code
           tDInvoiceVat.tcDomainCode                 = tTaxDetailDInvoice.tx2d_domain
           tDInvoiceVat.tcVatInOut                   = {&VATINOUT-OUTPUT}
           tDInvoiceVat.DInvoiceVatIsUpdAllow        = tTaxDetailDInvoice.tlTx2UpdateTax
           tDInvoiceVat.DInvoiceVatIsAbsRet          = tTaxDetailDInvoice.tx2d_abs_ret_amt <> 0
           tDInvoiceVat.DInvoiceVatIsAccrRcpUs       = tTaxDetailDInvoice.tx2d_usage_tax_point
           tDInvoiceVat.DInvoiceVatTaxTrType         = tTaxDetailDInvoice.tx2d_tr_type
           tDInvoiceVat.tcNormalTaxGLCode            = if icInvoiceType = {&INVOICETYPE-INVOICE} or
                                                          icInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                                       then tTaxDetailDInvoice.tcTx2ARGL
                                                       else tTaxDetailDInvoice.tcTx2ARCNGL
           tDInvoiceVat.tcNormalTaxDivisionCode      = if icInvoiceType = {&INVOICETYPE-INVOICE} or
                                                          icInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                                       then tTaxDetailDInvoice.tcTx2ARDivision
                                                       else tTaxDetailDInvoice.tcTx2ARCNDivision
           tDInvoiceVat.tcAbsRetTaxGLCode            = if tDInvoiceVat.DInvoiceVatIsAbsRet then tTaxDetailDInvoice.tcTx2ARAGL else "":U
           tDInvoiceVat.tcAbsRetTaxDivisionCode      = if tDInvoiceVat.DInvoiceVatIsAbsRet then tTaxDetailDInvoice.tcTx2ARADivision else "":U
           tDInvoiceVat.DInvoiceVatIsRevCharge       = tTaxDetailDInvoice.tlTx2ReverseCharge
           .
            
    /* read the mfg tax code to retrieve the absorbed retained flag, because looking at the amount is not a good solution */
    /* when the amount is zero, you don't get the right result                                                            */
    if tTaxDetailDInvoice.tx2d_abs_ret_amt = 0
    then do:
        <Q-56 run MfgTaxCodeByTaxCode (all) (Read) (Cache)
           (input tTaxDetailDInvoice.tx2d_tax_code, (TaxCode)
            input tTaxDetailDInvoice.tx2d_domain, (DomainCode)
            input ?, (DiscountAtPayment)
            input ?, (IsTaxByLine)
            output dataset tqMfgTaxCodeByTaxCode) in BMfgTaxCode>

        find first tqMfgTaxCodeByTaxCode where 
                   tqMfgTaxCodeByTaxCode.tctx2_tax_code = tTaxDetailDInvoice.tx2d_tax_code and
                   tqMfgTaxCodeByTaxCode.tctx2_domain   = tTaxDetailDInvoice.tx2d_domain
                   no-error.
        if available tqMfgTaxCodeByTaxCode
        then assign tDInvoiceVat.DInvoiceVatIsAbsRet = tqMfgTaxCodeByTaxCode.tltx2_ara_use.
     end.

    if vlAvailCompPropBySuspDelTax and vcCompanyPropertySuspTax <> '':U and tTaxDetailDInvoice.tltx2SuspDelayTax
    then assign tDInvoiceVat.tcSuspDelTaxGLCode        = if icInvoiceType = {&INVOICETYPE-INVOICE} or
                                                           icInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                                        then tTaxDetailDInvoice.tctx2SuspARGL
                                                        else tTaxDetailDInvoice.tctx2SuspARCNGL
               tDInvoiceVat.tcSuspDelTaxDivisionCode  = if icInvoiceType = {&INVOICETYPE-INVOICE} or
                                                          icInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                                        then tTaxDetailDInvoice.tctx2SuspARDivision
                                                        else tTaxDetailDInvoice.tctx2SuspARCNDivision
               tDInvoiceVat.DInvoiceVatSuspDelTaxAmtTC= <M-38 RoundAmount
                                                           (input  tTaxDetailDInvoice.tx2d_cur_tax_amt (idUnroundedAmount), 
                                                            input  ? (iiCurrencyID), 
                                                            input  icCurrencyCode (icCurrencyCode)) in BDInvoice>
               tDInvoiceVat.DInvoiceVatIsSuspDel      = true.

    else assign tDInvoiceVat.DInvoiceVatSuspDelTaxAmtTC = 0
                tDInvoiceVat.DInvoiceVatIsSuspDel       = false.

    accumulate tDInvoiceVat.DInvoiceVatVatBaseDebitTC (TOTAL).
    accumulate tDInvoiceVat.DInvoiceVatVatBaseCreditTC (TOTAL).
    accumulate tDInvoiceVat.DInvoiceVatVatDebitTC (TOTAL).
    accumulate tDInvoiceVat.DInvoiceVatVatCreditTC (TOTAL).

end. /* for each tTaxDetailDInvoice : */

if ilDInvoiceIsTaxExcluded = false
then assign vdInvoiceAmountTaxExclTC = abs((accum total tDInvoiceVat.DInvoiceVatVatBaseDebitTC) -
                                           (accum total tDInvoiceVat.DInvoiceVatVatBaseCreditTC)).

else assign vdInvoiceAmountTaxInclTC = idInvoiceAmountTC +
                                        abs((accum total tDInvoiceVat.DInvoiceVatVatDebitTC) -
                                            (accum total tDInvoiceVat.DInvoiceVatVatCreditTC)).
       
if oiReturnStatus = -98 
then assign oiReturnStatus = 0.