| icPostingRowid | input | character | value of tPosting.tc_Rowid |
| icPostingLineTcRowid | input | character | PostingLineTcRowid: Field-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. |
| itTaxPointDate | input | date | tax point date |
| icDescription | input | character | |
| icCurrency | input | character | Currency Code |
| idExchangeRate | input | decimal | exchange rate |
| idExchangeRateScale | input | decimal | |
| idCCExchangeRate | input | decimal | |
| idCCExchangeRateScale | input | decimal | |
| idBaseDebit | input | decimal | base debit TC |
| idBaseCredit | input | decimal | base credit TC |
| idFullDebit | input | decimal | full debit TC |
| idFullCredit | input | decimal | full credit TC |
| icInvoiceType | input | character | Invoice Type, must be Invoice or Credit Note |
| icTxclTaxCls | input | character | Tax Class |
| icTxuTaxUsage | input | character | Tax usage |
| icFromTxzTaxZone | input | character | From tax zone |
| icToTxzTaxZone | input | character | To Tax Zone |
| icTxenvTaxEnv | input | character | Tax Environment |
| icInOut | input | character | input or output |
| icDocumentNumberReference | input | character | document number reference : identification of the invoice |
| icPaymentNumberReference | input | character | Payment number reference : identification of the payment |
| icCostCentreCode | input | character | |
| icProjectCode | input | character | |
| ilDiscountTax | input | logical | discount tax ? |
| iiPostingVatId | input | integer | just specify that if you work with discount tax |
| icTaxTransactionType | input | character | Tax Transaction Type |
| icTaxGLCode | input | character | Tax Gl Account : pass this if you don't want that he overwrite your code |
| ilTaxRetainedAbsorbed | input | logical | do you work with tax retained or absorbed ? |
| ilIsReversePosting | input | logical | Indication, whether the tax posting is reverse/undo of already posted taxes |
| tUpdatePostingLine | output | temp-table | PostingLine |
| tUpdatePostingVat | output | temp-table | postingvat |
| icDivisionCode | input | character | Sub-Account |
| icTaxTypeCode | input | character | |
| oiReturnStatus | output | integer | Return status of the method. |
QadFinancials
if ilDiscountTax = ? then assign ilDiscountTax = false.
if iiPostingVatId = ? then assign iiPostingVatId = 0.
if icTaxTransactionType = ? then assign icTaxTransactionType = "":U.
if ilTaxRetainedAbsorbed = ? then assign ilTaxRetainedAbsorbed = false.
assign vdAdjustmentFactor = 0
vlIsCalculateVat = true.
empty temp-table tUpdatePostingLine.
empty temp-table tUpdatePostingVat.
empty temp-table tTaxDetailJE.
assign vcVATTAXTRANSACTIONTYPES ={&VATTAXTRANSACTIONTYPES}.
do viIndex = num-entries(vcVATTAXTRANSACTIONTYPES,chr(2)) to 1 by -1 :
if entry(viIndex,vcVATTAXTRANSACTIONTYPES,chr(2)) = icTaxTransactionType
then do :
assign icTaxTransactionType = entry(viIndex + 1,vcVATTAXTRANSACTIONTYPES,chr(2)) no-error.
leave.
end. /* if entry */
end.
if icFromTxzTaxZone <> "":U
then do:
<Q-6 run TaxZoneByTaxZone (all) (Read) (NoCache)
(input icFromTxzTaxZone, (TxzTaxZone)
output dataset tqTaxZoneByTaxZone) in BMfgTaxZone >
find first tqTaxZoneByTaxZone no-error.
if available tqTaxZoneByTaxZone
then assign vcFromCountryCode = tqTaxZoneByTaxZone.tctxz_ctry_code
vlFromCountryIsEUCountry = tqTaxZoneByTaxZone.tlctry_ec_flag.
end.
if icToTxzTaxZone <> "":U
then do:
<Q-7 run TaxZoneByTaxZone (all) (Read) (NoCache)
(input icToTxzTaxZone, (TxzTaxZone)
output dataset tqTaxZoneByTaxZone) in BMfgTaxZone >
find first tqTaxZoneByTaxZone no-error.
if available tqTaxZoneByTaxZone
then assign vcToCountryCode = tqTaxZoneByTaxZone.tctxz_ctry_code
vlToCountryIsEUCountry = tqTaxZoneByTaxZone.tlctry_ec_flag.
end.
if icInOut = {&VATINOUT-OUTPUT}
then do:
if vcFromCountryCode = vcToCountryCode and
vlFromCountryIsEUCountry = vlToCountryIsEUCountry
then assign vcTransactionType = {&VATTRANSACTIONTYPE-SALES}.
else if vcFromCountryCode <> vcToCountryCode
then assign vcTransactionType = if vlFromCountryIsEUCountry = yes and
vlFromCountryIsEUCountry = vlToCountryIsEUCountry
then {&VATTRANSACTIONTYPE-SUPPLY}
else {&VATTRANSACTIONTYPE-EXPORT}.
else assign vcTransactionType = "":U.
end.
else do:
if vcFromCountryCode = vcToCountryCode and
vlFromCountryIsEUCountry = vlToCountryIsEUCountry
then assign vcTransactionType = {&VATTRANSACTIONTYPE-PURCHASE}.
else if vcFromCountryCode <> vcToCountryCode
then assign vcTransactionType = if vlFromCountryIsEUCountry = yes and
vlFromCountryIsEUCountry = vlToCountryIsEUCountry
then {&VATTRANSACTIONTYPE-ACQUISITION}
else {&VATTRANSACTIONTYPE-IMPORT}.
else assign vcTransactionType = "":U.
end.
<Q-8 run CompanyPropertyByBusinessRel (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty >
find first tqCompanyPropertyByBusinessRel no-error.
if ilDiscountTax and iiPostingVatId <> 0
then do:
assign viFcCount1 = 0.
<Q-9 run PostingVatByPostingVatId (all) (Read) (NoCache)
(input iiPostingVatId, (PostingVatId)
output dataset tqPostingVatByPostingVatId) in BPosting >
for each tqPostingVatByPostingVatId where
tqPostingVatByPostingVatId.tiPostingVat_ID = iiPostingVatId :
create tTaxDetailJE.
assign viFcCount1 = viFcCount1 + 1
tTaxDetailJE.tx2d_domain = vcDomainCode
tTaxDetailJE.tx2d_line = viFcCount1
tTaxDetailJE.tx2d_ref = icDocumentNumberReference
tTaxDetailJE.tx2d_tr_type = tqPostingVatByPostingVatId.tcPostingVatTaxTransType
tTaxDetailJE.tx2d_trans_ent = vcCompanyCode
tTaxDetailJE.tx2d_curr = icCurrency
tTaxDetailJE.tx2d_tax_code = tqPostingVatByPostingVatId.tcVatCode
tTaxDetailJE.tx2d_tax_env = tqPostingVatByPostingVatId.tcTxenvTaxEnv
tTaxDetailJE.tx2d_zone_from = tqPostingVatByPostingVatId.tcFromTxzTaxZone
tTaxDetailJE.tx2d_zone_to = tqPostingVatByPostingVatId.tcToTxzTaxZone
tTaxDetailJE.tx2d_tax_type = tqPostingVatByPostingVatId.tcTxtyTaxType
tTaxDetailJE.tx2d_taxc = tqPostingVatByPostingVatId.tcTxclTaxCls
tTaxDetailJE.tx2d_tax_usage = tqPostingVatByPostingVatId.tcTxuTaxUsage
tTaxDetailJE.tx2d_taxable_amt = tqPostingVatByPostingVatId.tdPostingVatBaseDebitTC - tqPostingVatByPostingVatId.tdPostingVatBaseCreditTC
tTaxDetailJE.tx2d_tottax = tTaxDetailJE.tx2d_taxable_amt
tTaxDetailJE.tx2d_cur_tax_amt = tqPostingVatByPostingVatId.tdPostingVatTaxDebitTC - tqPostingVatByPostingVatId.tdPostingVatTaxCreditTC
tTaxDetailJE.tx2d_cur_abs_ret_amt = if ilTaxRetainedAbsorbed then tTaxDetailJE.tx2d_cur_tax_amt else 0
tTaxDetailJE.tx2d_abs_ret_amt = if ilTaxRetainedAbsorbed then tqPostingVatByPostingVatId.tdPostingVatTaxDebitLC - tqPostingVatByPostingVatId.tdPostingVatTaxCreditLC else 0
vdAdjustmentFactor = (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)
vdAdjustmentFactor = abs(vdAdjustmentFactor / tTaxDetailJE.tx2d_taxable_amt)
vlIsCalculateVat = false.
/* WHEN DISCOUNT TAX AT PAYMENT IS SET TO TRUE CALCULATE THE AMOUNTS BASED ON THE ADJUSTMENT FACTOR */
<Q-79 run MfgTaxCodeByTaxCode (all) (Read) (NoCache)
(input tTaxDetailJE.tx2d_tax_code, (TaxCode)
input tTaxDetailJE.tx2d_domain, (DomainCode)
input ?, (DiscountAtPayment)
input ?, (IsTaxByLine)
output dataset tqMfgTaxCodeByTaxCode) in BMfgTaxCode>
find first tqMfgTaxCodeByTaxCode
where tqMfgTaxCodeByTaxCode.tctx2_tax_code = tTaxDetailJE.tx2d_tax_code and
tqMfgTaxCodeByTaxCode.tctx2_domain = tTaxDetailJE.tx2d_domain.
if available tqMfgTaxCodeByTaxCode and tqMfgTaxCodeByTaxCode.tltx2_pmt_disc then
do:
icTaxTransactionType = if icTaxTransactionType = "":U then if IcInOut = {&VATINOUT-OUTPUT} then {&VATTAXTRANSACTIONTYPE-ARPAYMENT} else {&VATTAXTRANSACTIONTYPE-APPAYMENT} else icTaxTransactionType.
assign tTaxDetailJE.tx2d_cur_tax_amt = <M-40 RoundAmount
(input (- tTaxDetailJE.tx2d_cur_tax_amt) * vdAdjustmentFactor (idUnroundedAmount),
input 0 (iiCurrencyID),
input icCurrency (icCurrencyCode)) in BJournalEntry>
tTaxDetailJE.tx2d_tax_amt = <M-49 RoundAmount
(input (- tTaxDetailJE.tx2d_tax_amt) * vdAdjustmentFactor (idUnroundedAmount),
input 0 (iiCurrencyID),
input icCurrency (icCurrencyCode)) in BJournalEntry>
tTaxDetailJE.tx2d_ent_tax_amt = <M-29 RoundAmount
(input (- tTaxDetailJE.tx2d_ent_tax_amt) * vdAdjustmentFactor (idUnroundedAmount),
input 0 (iiCurrencyID),
input icCurrency (icCurrencyCode)) in BJournalEntry>
tTaxDetailJE.tx2d_taxable_amt = <M-93 RoundAmount
(input (- tTaxDetailJE.tx2d_taxable_amt) * vdAdjustmentFactor (idUnroundedAmount),
input 0 (iiCurrencyID),
input icCurrency (icCurrencyCode)) in BJournalEntry>
tTaxDetailJE.tx2d_cur_recov_amt = <M-31 RoundAmount
(input (- tTaxDetailJE.tx2d_cur_recov_amt) * vdAdjustmentFactor (idUnroundedAmount),
input 0 (iiCurrencyID),
input icCurrency (icCurrencyCode)) in BJournalEntry>
tTaxDetailJE.tx2d_recov_amt = <M-4 RoundAmount
(input (- tTaxDetailJE.tx2d_recov_amt) * vdAdjustmentFactor (idUnroundedAmount),
input 0 (iiCurrencyID),
input icCurrency (icCurrencyCode)) in BJournalEntry>
tTaxDetailJE.tx2d_ent_recov_amt = <M-32 RoundAmount
(input (- tTaxDetailJE.tx2d_ent_recov_amt) * vdAdjustmentFactor (idUnroundedAmount),
input 0 (iiCurrencyID),
input icCurrency (icCurrencyCode)) in BJournalEntry>
tTaxDetailJE.tx2d_tottax = <M-59 RoundAmount
(input (- tTaxDetailJE.tx2d_tottax) * vdAdjustmentFactor (idUnroundedAmount),
input 0 (iiCurrencyID),
input icCurrency (icCurrencyCode)) in BJournalEntry>
tTaxDetailJE.tx2d_cur_abs_ret_amt = <M-42 RoundAmount
(input (- tTaxDetailJE.tx2d_cur_abs_ret_amt) * vdAdjustmentFactor (idUnroundedAmount),
input 0 (iiCurrencyID),
input icCurrency (icCurrencyCode)) in BJournalEntry>
tTaxDetailJE.tx2d_abs_ret_amt = <M-73 RoundAmount
(input (- tTaxDetailJE.tx2d_abs_ret_amt) * vdAdjustmentFactor (idUnroundedAmount),
input 0 (iiCurrencyID),
input icCurrency (icCurrencyCode)) in BJournalEntry>.
if ilIsReversePosting
then assign tTaxDetailJE.tx2d_cur_tax_amt = - tTaxDetailJE.tx2d_cur_tax_amt
tTaxDetailJE.tx2d_tax_amt = - tTaxDetailJE.tx2d_tax_amt
tTaxDetailJE.tx2d_ent_tax_amt = - tTaxDetailJE.tx2d_ent_tax_amt
tTaxDetailJE.tx2d_taxable_amt = - tTaxDetailJE.tx2d_taxable_amt
tTaxDetailJE.tx2d_cur_recov_amt = - tTaxDetailJE.tx2d_cur_recov_amt
tTaxDetailJE.tx2d_recov_amt = - tTaxDetailJE.tx2d_recov_amt
tTaxDetailJE.tx2d_ent_recov_amt = - tTaxDetailJE.tx2d_ent_recov_amt
tTaxDetailJE.tx2d_tottax = - tTaxDetailJE.tx2d_tottax
tTaxDetailJE.tx2d_cur_abs_ret_amt = - tTaxDetailJE.tx2d_cur_abs_ret_amt
tTaxDetailJE.tx2d_abs_ret_amt = - tTaxDetailJE.tx2d_abs_ret_amt.
end. /* if available tqMfgTaxCodeByTaxCode and tqMfgTaxCodeByTaxCode.tltx2_pmt_disc*/
end. /* for each tqPostingVatByPostingVatId where */
end. /* if ilDiscountTax and iiPostingVatId <> 0 */
/* If In/Out = OUTPUT then we pass true as ilcustomerinvoice, then the fields is right filled */
<M-3 run AddTaxPosting
(input icPostingRowid (icPostingtcRowid),
input icPostingLineTcRowid (icPostingLineTcRowid),
input itTaxPointDate (itTaxPointDate),
input icDescription (icDescription),
input icCurrency (icCurrencyCode),
input ? (iiCurrencyId),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType),
input idExchangeRate (idExchangeRate),
input idExchangeRateScale (idExchangeRateScale),
input idCCExchangeRate (idCCRate),
input idCCExchangeRateScale (idCCRateScale),
input idBaseDebit (idBaseDebit),
input idBaseCredit (idBaseCredit),
input idFullDebit (idFullDebit),
input idFullCredit (idFullCredit),
input icInvoiceType (icInvoiceType),
input vlIsCalculateVat (ilCalculateVat),
input-output tTaxDetailJE (tTaxDetailPosting),
input ? (icCaller),
input ? (ilIsVatDelay),
input icDivisionCode (icDivisionCode),
input ? (icVatCurrencyCode),
input ? (iiVatCurrencyId),
input ? (idVatExchangeRate),
input ? (idVatExchangeRateScale),
input vcTransactionType (icTransactionType),
input icTxclTaxCls (icTxclTaxCls),
input icTxuTaxUsage (icTxuTaxUsage),
input icFromTxzTaxZone (icFromTxzTaxZone),
input icToTxzTaxZone (icToTxzTaxZone),
input icTxenvTaxEnv (icTxenvTaxEnv),
input icDocumentNumberReference (icDocumentReference),
input icPaymentNumberReference (icDocumentNumber),
input ? (icPaymentCondition),
input if available tqCompanyPropertyByBusinessRel then tqCompanyPropertyByBusinessRel.tlAddressIsTaxInCity else ? (ilIsTaxInCityFromCompany),
input ? (ilIsTaxInCityFromShipTo),
input if IcInOut = {&VATINOUT-OUTPUT} then true else false (ilCustomerInvoice),
input ? (icControlGLCode),
input ? (iiMasterId),
input ? (iiTransactionId),
input icTaxGLCode (icTaxGLCode),
input true (ilIsTaxable),
input vdAdjustmentFactor (idAdjustmentFactor),
input icCostCentreCode (icCostCentreCode),
input icProjectCode (icProjectCode),
input ? (iiShipFromAddressId),
input ? (iiShipToAddressId),
input icTaxTransactionType (icTaxTransactionType),
input ? (icSoldToDebtorCode),
input-output viFirstVatPostingLineID (biFirstVatPostingLineId),
output viSecondVatPostingLineID (oiSecondVatPostingLineId),
output vcPostingLineIds (ocPostingLineIds),
input false (ilLinkedCrCyDaemonReqExists),
input icTaxTypeCode (icTaxTypeCode),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
if viFirstVatPostingLineID <> 0 or viSecondVatPostingLineID <> 0
then for each tPostingLine where
tPostingLine.tc_ParentRowid = icPostingRowid :
if lookup(string(tPostingLine.PostingLine_ID), vcPostingLineIds) <> 0
then do:
if tPostingLine.PostingLine_ID = integer(entry(lookup(string(tPostingLine.PostingLine_ID), vcPostingLineIds), vcPostingLineIds) )
then do:
if can-find (first tPostingVat where
tPostingVat.tc_ParentRowid = tPostingLine.tc_Rowid)
then do:
create tUpdatePostingLine.
raw-transfer tPostingLine to tUpdatePostingLine.
end.
for each tPostingVat where
tPostingVat.tc_ParentRowid = tPostingLine.tc_Rowid:
create tUpdatePostingVat.
raw-transfer tPostingVat to tUpdatePostingVat.
end.
end.
end.
end. /* if viFirstVatPostingLineID <> 0 */