project QadFinancials > class BCInvoice > method CreateCIPostingTax

Description

Create the tax posting for the di


Parameters


icRowIdinputcharacterRow ID
iiPostingIdinputintegerPosting ID
itTaxPointDateinputdateTax Point Date
icCInvoiceRowIdinputcharacter
icCITextinputcharacterCI Text
icCurrencyCodeinputcharacterCurrency Code
iiCurrencyIdinputintegerCurrency ID
icExchangeRateTypeinputcharacterExchange Rate Type
idExchangeRateinputdecimalExchange Rate
idExchangeRateScaleinputdecimalScale factor of exchange rate
idVatFullDebitTCinputdecimalVat Full Debit TC
idVatFullCreditTCinputdecimalVat Fiull Credit TC
icCInvoiceTypeinputcharacterCinvoice Type
icDivisionCodeinputcharacterDivision Code
icVatCurrencyCodeinputcharacterVat Currency Code
iiVatCurrencyIdinputintegerVat Currency ID
idVatExchangeRateinputdecimalVat Exchange Rate
idVatExchangeRateScaleinputdecimalVat Exchange Rate Scale
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 creditor, or if the tax class on the tax tab is filled, then this one
icTxuTaxUsageinputcharacterTax usage of the creditor, or if the tax usage on the tax tab is filled, then this one
icCreditorTxzTaxZoneinputcharacterTax zone of Creditor
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, ....
icPoNbrinputcharacter
ilIsTaxableinputlogicalIs taxable flag
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
ilIsLogisticMatchinginputlogicalIs Logistic Matching ?
idInvoiceAmountTCinputdecimalInvoice Amount TC
icShipFromTaxIDFederinputcharacterTax ID Federal 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
icShipToTaxIDFederinputcharacterTax ID Federal of 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
itInvoiceDateinputdate
idCCExchangeRateinputdecimal
idCCExchangeRateScaleinputdecimal
icCInvoiceReferenceinputcharacter
ilCInvoiceIsERSinputlogical
ilCInvoiceIsForLegalDocinputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.ApiStdMaintainTTWithIntPost
method BCInvoice.CreateCIPosting


program code (program3/bcinvoice.p)

if vlCompanyPropertyIsAPUseInvDate = true
then
    assign vtExchangeRateDate = itInvoiceDate.
else
    assign vtExchangeRateDate = ?.

if icPoNbr <> "":U and  icPoNbr <> ? 
then do:
     <Q-2 run PurchaseOrderDetailForTax (all) (Read) (NoCache)
        (input vcDomainCode, (Domain)
         input icPoNbr, (PoNbr)
         output dataset tqPurchaseOrderDetailForTax) in BMfgPO >
     for each tqPurchaseOrderDetailForTax where
              tqPurchaseOrderDetailForTax.tcpo_domain          = vcDomainCode and
              tqPurchaseOrderDetailForTax.tcpo_nbr             = icPoNbr      and
             (tqPurchaseOrderDetailForTax.tctx2d_tr_type       = {&VATTAXTRANSACTIONTYPE-PO} or
              tqPurchaseOrderDetailForTax.tctx2d_tr_type       = {&VATTAXTRANSACTIONTYPE-PORECEIPT}) and
             (tqPurchaseOrderDetailForTax.tltx2_rcpt_tax_point = true         or
              tqPurchaseOrderDetailForTax.tltx2_usage_tax_point = true) :
         <Q-3 run GLByGLSystemType (all) (Read) (NoCache)
            (input viCompanyId, (CompanyId)
             input {&GLSYSTEMTYPE-VOUPAY}, (GLSystemTypeCode)
             input {&GLTYPECODE-SYST}, (GlTypeCode)
             input ?, (GlIsDivisionAccount)
             output dataset tqGLByGLSystemType) in BGL >
         find first tqGLByGLSystemType
               no-error.
         if not available tqGLByGLSystemType
         then do:
             assign oiReturnStatus = -1.
             <M-5 run SetMessage
                (input  trim(#T-4'PO Receipt Account &1 is not defined in the system.':250(55212)T-4#) (icMessage), 
                 input  '':U (icArguments), 
                 input  '':U (icFieldName), 
                 input  '':U (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  '':U (icRowid), 
                 input  'QadFin-5490':U (icFcMsgNumber), 
                 input  '':u (icFcExplanation), 
                 input  '':U (icFcIdentification), 
                 input  '':U (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
             leave.
         end.
         assign vcGLCode = tqGLByGLSystemType.tcGLCode.
         leave.
     end.
end.

if oiReturnStatus < 0 then return.

if idInvoiceAmountTC <> 0 and
    not can-find ( first tApiCInvoiceVat where
                         tApiCInvoiceVat.tc_ParentRowid = icCInvoiceRowId and
                         tApiCInvoiceVat.tc_Status     <> "D":U and 
                         (tApiCInvoiceVat.CInvoiceVatVatDebitTC  <> 0 or
                          tApiCInvoiceVat.CInvoiceVatVatCreditTC <> 0))                and 
    not can-find ( first tApiCInvoiceVat where
                         tApiCInvoiceVat.tc_ParentRowid          = icCInvoiceRowId and
                         tApiCInvoiceVat.tc_Status              <> "D":U           and 
                         tApiCInvoiceVat.CInvoiceVatVatDebitTC   = 0               and
                         tApiCInvoiceVat.CInvoiceVatVatCreditTC  = 0               and
                         tApiCInvoiceVat.TxtyTaxType            <> {&VATTAXTYPE-NONTAX})
then return.

for each tApiCInvoiceVat where 
         tApiCInvoiceVat.tc_ParentRowid = icCInvoiceRowId and
         tApiCInvoiceVat.tc_Status     <> "D":U
    break by tApiCInvoiceVat.TxclTaxCls
          by tApiCInvoiceVat.TxuTaxUsage
          by tApiCInvoiceVat.TxenvTaxEnv
          by tApiCInvoiceVat.TxtyTaxType
          by tApiCInvoiceVat.tcVatCode :
    if first-of (tApiCInvoiceVat.tcVatCode)
    then do:
        assign vdDebitAmountTC  = 0
               vdCreditAmountTC = 0.
        empty temp-table tTaxDetailCInvoice.
    end.

    /* initialise it here, and it will be correctly filled in last-of */
    assign tApiCInvoiceVat.PostingVat_ID = 0.
    
    /* Because we can now change the SC exchange rate per tax line on the supplier invoice tax tab 
      (by editing the sc tax amounts DR/CR) - use the tax line SC rate to calculate amounts */ 
    if tApiCInvoiceVat.tdCInvoiceVatExchangeRateCC <> ? and tApiCInvoiceVat.tdCInvoiceVatExchangeRateCC <> 0
    then do: 
        if tApiCInvoiceVat.tdCInvoiceVatExchangeRateCC <> idCCExchangeRate
            then assign idCCExchangeRate = tApiCInvoiceVat.tdCInvoiceVatExchangeRateCC.
    end.

    if last-of(tApiCInvoiceVat.tcVatCode)     and 
       tApiCInvoiceVat.CInvoiceVatIsAccrRcpUs = false
    then do:
        
        /* When we call the integration for BCInvoice and we pass in all information about the taxes etc then - in some very odd configuration of the addresses -  then we run  */
        /* into an error that the TransactionType is unknown. The solution is to set it to the most common value for BCInvoice ('Purchase') when this is unknown at this point  */
        if icShipFromCountryCode = icShipToCountryCode and
           ilShipFromCountryIsEUCountry = ilShipToCountryIsEUCountry
        then assign vcTransactionType = {&VATTRANSACTIONTYPE-PURCHASE}.
        else if icShipFromCountryCode <> icShipToCountryCode
             then assign vcTransactionType = if ilShipFromCountryIsEUCountry = yes and
                                                ilShipFromCountryIsEUCountry = ilShipToCountryIsEUCountry
                                             then {&VATTRANSACTIONTYPE-ACQUISITION}
                                             else {&VATTRANSACTIONTYPE-IMPORT}.
             else assign vcTransactionType = "":U.
        if vcTransactionType = "":U or 
           vcTransactionType = ?
        then assign vcTransactionType = {&VATTRANSACTIONTYPE-PURCHASE}.                      
        
        assign vdVatNonRecTaxAmtTC = tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC
               vdVatNonRecTaxAmtLC = vdVatNonRecTaxAmtTC * idExchangeRate * idExchangeRateScale
               vdVatNonRecTaxAmtCC = vdVatNonRecTaxAmtTC * idCCExchangeRate * idCCExchangeRateScale.
        
        if icCInvoiceType = {&INVOICETYPE-INVOICE} or 
           icCInvoiceType = {&INVOICETYPE-INVOICECORRECTION} 
        then assign vdVatDebitTC  = tApiCInvoiceVat.CInvoiceVatVatDebitTC - vdVatNonRecTaxAmtTC
                    vdVatCreditTC = 0
                    vdVatDebitLC  = <M-30 GetAmountPreferencingExpected
                                       (input  if ilCInvoiceIsERS then tApiCInvoiceVat.CInvoiceVatVatDebitLC - vdVatNonRecTaxAmtLC else 0 (idExpectedAmount), 
                                        input  vdVatDebitTC * idExchangeRate * idExchangeRateScale (idCalculatedAmount), 
                                        input  viCompanyLCId (iiCurrencyId)) in BCInvoice>
                    vdVatCreditLC = 0
                    vdVatDebitCC  = <M-91 GetAmountPreferencingExpected
                                       (input  if ilCInvoiceIsERS then tApiCInvoiceVat.CInvoiceVatVatDebitCC - vdVatNonRecTaxAmtCC else 0 (idExpectedAmount), 
                                        input  vdVatDebitTC * idCCExchangeRate * idCCExchangeRateScale (idCalculatedAmount), 
                                        input  viCompanyCCId (iiCurrencyId)) in BCInvoice>
                    vdVatCreditCC = 0.
        else assign vdVatDebitTC  = 0
                    vdVatCreditTC = tApiCInvoiceVat.CInvoiceVatVatCreditTC - vdVatNonRecTaxAmtTC
                    vdVatDebitLC  = 0
                    vdVatCreditLC = <M-72 GetAmountPreferencingExpected
                                       (input  if ilCInvoiceIsERS then tApiCInvoiceVat.CInvoiceVatVatCreditLC - vdVatNonRecTaxAmtLC else 0 (idExpectedAmount), 
                                        input  vdVatCreditTC * idExchangeRate * idExchangeRateScale (idCalculatedAmount), 
                                        input  viCompanyLCId (iiCurrencyId)) in BCInvoice>
                    vdVatDebitCC  = 0
                    vdVatCreditCC = <M-34 GetAmountPreferencingExpected
                                       (input  if ilCInvoiceIsERS then tApiCInvoiceVat.CInvoiceVatVatCreditCC - vdVatNonRecTaxAmtCC else 0 (idExpectedAmount), 
                                        input  vdVatCreditTC * idCCExchangeRate * idCCExchangeRateScale (idCalculatedAmount), 
                                        input  viCompanyCCId (iiCurrencyId)) in BCInvoice>.

        <M-6 run AddPostingLineTax
           (input  icRowId (icPostingTcRowid), 
            input  itTaxPointDate (itTaxPointDate), 
            input  icCIText (icPostingLineText), 
            input  icCurrencyCode (icCurrencyCode), 
            input  tApiCInvoiceVat.tcVatInOut (icPostingVatInOut), 
            input  tApiCInvoiceVat.tcVatCode (icPostingVatCode), 
            input  tApiCInvoiceVat.tcDomainCode (icPostingVatDomain), 
            input  idExchangeRate (idExchangeRate), 
            input  idExchangeRateScale (idExchangeRateScale), 
            input  icExchangeRateType (icExchangeRateType), 
            input  idCCExchangeRate (idCCExchangeRate), 
            input  idCCExchangeRateScale (idCCExchangeRateScale), 
            input  vcTransactionType (icTransactionType), 
            input  tApiCInvoiceVat.CInvoiceVatTaxTrType (icTaxTransactionType), 
            input  tApiCInvoiceVat.CInvoiceVatVatBaseDebitTC (idBaseDebitTC), 
            input  tApiCInvoiceVat.CInvoiceVatVatBaseCreditTC (idBaseCreditTC), 
            input  tApiCInvoiceVat.CInvoiceVatVatBaseDebitLC (idBaseDebitLC), 
            input  tApiCInvoiceVat.CInvoiceVatVatBaseCreditLC (idBaseCreditLC), 
            input  tApiCInvoiceVat.CInvoiceVatVatBaseDebitCC (idBaseDebitCC), 
            input  tApiCInvoiceVat.CInvoiceVatVatBaseCreditCC (idBaseCreditCC), 
            input  vdVatDebitTC (idVatDebitTC), 
            input  vdVatCreditTC (idVatCreditTC), 
            input  vdVatDebitLC (idVatDebitLC), 
            input  vdVatCreditLC (idVatCreditLC), 
            input  vdVatDebitCC (idVatDebitCC), 
            input  vdVatCreditCC (idVatCreditCC), 
            input  if tApiCInvoiceVat.CInvoiceVatIsSuspDel = true then tApiCInvoiceVat.tcSuspDelTaxGLCode else tApiCInvoiceVat.tcNormalTaxGLCode (icNormalTaxGLCode), 
            input  if tApiCInvoiceVat.CInvoiceVatIsSuspDel = true then tApiCInvoiceVat.tcSuspDelTaxDivisionCode else tApiCInvoiceVat.tcNormalTaxDivisionCode (icNormalTaxDivisionCode), 
            input  false (ilNormalTaxIsAlreadyAbsRet), 
            input  if tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC = 0 then tApiCInvoiceVat.tcAbsRetTaxGLCode else ? (icAbsRetTaxGLCode), 
            input  if tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC = 0 then tApiCInvoiceVat.tcAbsRetTaxDivisionCode else ? (icAbsRetTaxDivisionCode), 
            input  icCreditorTxzTaxZone (icFromTaxZone), 
            input  icshipToTxzTaxZone (icToTaxZone), 
            input  tApiCInvoiceVat.TxenvTaxEnv (icTaxEnvrionment), 
            input  tApiCInvoiceVat.CInvoiceVatIsTaxable (ilIsTaxable), 
            input  tApiCInvoiceVat.TxclTaxCls (icTaxClass), 
            input  tApiCInvoiceVat.TxuTaxUsage (icTaxUsage), 
            input  tApiCInvoiceVat.TxtyTaxType (icTaxType), 
            input  tApiCInvoiceVat.CInvoiceVatIsRevCharge (ilTaxIsReverseChargeDomestic), 
            input  iiShipFromAddressId (iiTaxAddressID), 
            input  icShipFromTaxIDFeder (icTaxIDFeder), 
            input  icShipFromTaxIDState (icTaxIDState), 
            input  icShipFromTaxIDMisc1 (icTaxIDMisc1), 
            input  icShipFromTaxIDMisc2 (icTaxIDMisc2), 
            input  icShipFromTaxIDMisc3 (icTaxIDMisc3), 
            input  iiShipToAddressId (iiOwnAddressID), 
            input  icShipToTaxIDFeder (icOwnTaxIDFeder), 
            input  icShipToTaxIDState (icOwnTaxIDState), 
            input  icShipToTaxIDMisc1 (icOwnTaxIDMisc1), 
            input  icShipToTaxIDMisc2 (icOwnTaxIDMisc2), 
            input  icShipToTaxIDMisc3 (icOwnTaxIDMisc3), 
            input  iiShipToTaxDeclaration (iiOwnTaxIDDeclarat), 
            input  tApiCInvoiceVat.CInvoiceVatIsSuspDel (ilIsSuspDel), 
            output viVatPostingLineId (oiNormalTaxPostingLineID), 
            output vcDummy (ocNormalTaxPostingLineTcRowid), 
            output viDummyPostingLineID (oiAbsRetTaxPostingLineID), 
            output vcDummy (ocAbsRetTaxPostingLineTcRowid), 
            output tApiCInvoiceVat.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 tApiCInvoiceVat.tc_Status = "":U and
           tApiCInvoiceVat.PostingVat_ID <> 0 
        then assign tApiCInvoiceVat.tc_Status = "C":U.    
        
        
        /* I19 requirement for Brazil ============================================================== */
        /* Update posting line to contain legal document number filled in                            */
        /* ========================================================================================= */
        if ilCInvoiceIsForLegalDoc = true
        then do:
            <M-51 run SetPostingLineLegalDocNumber
               (input  ? (icPostingLineTcRowID), 
                input  viVatPostingLineId (iiPostingLineID), 
                input  entry(1, icCInvoiceReference) (icLegalDocumentNumber), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
            then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then return.
        end. /* if ilCInvoiceIsForLegalDoc */            
            
            

        /* if retained taxes, accrue at receipt yes and % recoverable <> 100 */
        if tApiCInvoiceVat.CInvoiceVatIsAbsRet and tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC <> 0
        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 */
            /* from the integration point LC values can be calcualted already. So try to used them when they have expected value                  */
            /* This can prevent some rounding issues                                                                                              */
            if icCInvoiceType = {&INVOICETYPE-INVOICE} or icCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
            then assign vdVatDebitTC  = 0
                        vdVatCreditTC = tApiCInvoiceVat.CInvoiceVatVatCreditTC
                        vdVatDebitLC  = 0
                        vdVatCreditLC = <M-94 GetAmountPreferencingExpected
                                           (input  if ilCInvoiceIsERS then tApiCInvoiceVat.CInvoiceVatVatCreditLC else 0 (idExpectedAmount), 
                                            input  vdVatCreditTC * idExchangeRate * idExchangeRateScale (idCalculatedAmount), 
                                            input  viCompanyLCId (iiCurrencyId)) in BCInvoice>
                        vdVatDebitCC  = 0
                        vdVatCreditCC = <M-80 GetAmountPreferencingExpected
                                           (input  if ilCInvoiceIsERS then tApiCInvoiceVat.CInvoiceVatVatCreditCC else 0 (idExpectedAmount), 
                                            input  vdVatCreditTC * idCCExchangeRate * idCCExchangeRateScale (idCalculatedAmount), 
                                            input  viCompanyCCId (iiCurrencyId)) in BCInvoice>.
            else assign vdVatDebitTC  = tApiCInvoiceVat.CInvoiceVatVatDebitTC
                        vdVatCreditTC = 0
                        vdVatDebitLC  = <M-87 GetAmountPreferencingExpected
                                           (input  if ilCInvoiceIsERS then tApiCInvoiceVat.CInvoiceVatVatDebitLC else 0 (idExpectedAmount), 
                                            input  vdVatDebitTC * idExchangeRate * idExchangeRateScale (idCalculatedAmount), 
                                            input  viCompanyLCId (iiCurrencyId)) in BCInvoice>
                        vdVatCreditLC = 0
                        vdVatDebitCC  = <M-57 GetAmountPreferencingExpected
                                           (input  if ilCInvoiceIsERS then tApiCInvoiceVat.CInvoiceVatVatDebitCC else 0 (idExpectedAmount), 
                                            input  vdVatDebitTC * idCCExchangeRate * idCCExchangeRateScale (idCalculatedAmount), 
                                            input  viCompanyCCId (iiCurrencyId)) in BCInvoice>
                        vdVatCreditCC = 0.
            
            <M-11 run AddPostingLineTax
               (input  icRowId (icPostingTcRowid), 
                input  itTaxPointDate (itTaxPointDate), 
                input  icCIText (icPostingLineText), 
                input  icCurrencyCode (icCurrencyCode), 
                input  tApiCInvoiceVat.tcVatInOut (icPostingVatInOut), 
                input  tApiCInvoiceVat.tcVatCode (icPostingVatCode), 
                input  tApiCInvoiceVat.tcDomainCode (icPostingVatDomain), 
                input  idExchangeRate (idExchangeRate), 
                input  idExchangeRateScale (idExchangeRateScale), 
                input  icExchangeRateType (icExchangeRateType), 
                input  idCCExchangeRate (idCCExchangeRate), 
                input  idCCExchangeRateScale (idCCExchangeRateScale), 
                input  vcTransactionType (icTransactionType), 
                input  tApiCInvoiceVat.CInvoiceVatTaxTrType (icTaxTransactionType), 
                input  tApiCInvoiceVat.CInvoiceVatVatBaseCreditTC (idBaseDebitTC), 
                input  tApiCInvoiceVat.CInvoiceVatVatBaseDebitTC (idBaseCreditTC), 
                input  tApiCInvoiceVat.CInvoiceVatVatBaseCreditLC (idBaseDebitLC), 
                input  tApiCInvoiceVat.CInvoiceVatVatBaseDebitLC (idBaseCreditLC), 
                input  tApiCInvoiceVat.CInvoiceVatVatBaseCreditCC (idBaseDebitCC), 
                input  tApiCInvoiceVat.CInvoiceVatVatBaseDebitCC (idBaseCreditCC), 
                input  vdVatDebitTC (idVatDebitTC), 
                input  vdVatCreditTC (idVatCreditTC), 
                input  vdVatDebitLC (idVatDebitLC), 
                input  vdVatCreditLC (idVatCreditLC), 
                input  vdVatDebitCC (idVatDebitCC), 
                input  vdVatCreditCC (idVatCreditCC), 
                input  tApiCInvoiceVat.tcAbsRetTaxGLCode (icNormalTaxGLCode), 
                input  tApiCInvoiceVat.tcAbsRetTaxDivisionCode (icNormalTaxDivisionCode), 
                input  true (ilNormalTaxIsAlreadyAbsRet), 
                input  ? (icAbsRetTaxGLCode), 
                input  ? (icAbsRetTaxDivisionCode), 
                input  icCreditorTxzTaxZone (icFromTaxZone), 
                input  icshipToTxzTaxZone (icToTaxZone), 
                input  tApiCInvoiceVat.TxenvTaxEnv (icTaxEnvrionment), 
                input  tApiCInvoiceVat.CInvoiceVatIsTaxable (ilIsTaxable), 
                input  tApiCInvoiceVat.TxclTaxCls (icTaxClass), 
                input  tApiCInvoiceVat.TxuTaxUsage (icTaxUsage), 
                input  tApiCInvoiceVat.TxtyTaxType (icTaxType), 
                input  tApiCInvoiceVat.CInvoiceVatIsRevCharge (ilTaxIsReverseChargeDomestic), 
                input  iiShipFromAddressId (iiTaxAddressID), 
                input  icShipFromTaxIDFeder (icTaxIDFeder), 
                input  icShipFromTaxIDState (icTaxIDState), 
                input  icShipFromTaxIDMisc1 (icTaxIDMisc1), 
                input  icShipFromTaxIDMisc2 (icTaxIDMisc2), 
                input  icShipFromTaxIDMisc3 (icTaxIDMisc3), 
                input  iiShipToAddressId (iiOwnAddressID), 
                input  icShipToTaxIDFeder (icOwnTaxIDFeder), 
                input  icShipToTaxIDState (icOwnTaxIDState), 
                input  icShipToTaxIDMisc1 (icOwnTaxIDMisc1), 
                input  icShipToTaxIDMisc2 (icOwnTaxIDMisc2), 
                input  icShipToTaxIDMisc3 (icOwnTaxIDMisc3), 
                input  iiShipToTaxDeclaration (iiOwnTaxIDDeclarat), 
                input  ? (ilIsSuspDel), 
                output viVatPostingLineId (oiNormalTaxPostingLineID), 
                output vcDummy (ocNormalTaxPostingLineTcRowid), 
                output viDummyPostingLineID (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.
            
            /* I19 requirement for Brazil ============================================================== */
            /* Update posting line to contain legal document number filled in                            */
            /* ========================================================================================= */
            if ilCInvoiceIsForLegalDoc = true
            then do:
                <M-48 run SetPostingLineLegalDocNumber
                   (input  ? (icPostingLineTcRowID), 
                    input  viVatPostingLineId (iiPostingLineID), 
                    input  entry(1, icCInvoiceReference) (icLegalDocumentNumber), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
                then assign oiReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0 then return.
            end. /* if ilCInvoiceIsForLegalDoc */
        end.
    end.
end.