project QadFinancials > class BBankEntry > method AdditionalUpdatesInvDiscountCurrDiffTax
Description
Posting on discount
Parameters
idDiscountRatio | input | decimal | |
icExchangeRateType | input | character | |
idLCExchangeRate | input | decimal | |
idLCExchangeRateScale | input | decimal | |
idCCExchangeRate | input | decimal | |
idCCExchangeRateScale | input | decimal | |
icDiscountGLCode | input | character | |
bdDiscountedAmountTC | input-output | decimal | Current value of the discount still to be posted. |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program4/bbankentry.p)
/* ================================================================================================== *
* Method: AddiitonalUpdatesInvDiscountCurrDiffTax *
* Description: This method creates tax posting for discounts calculated at the payment. These disc *
* are calcualted based on Invoice Credit Terms and based on Payment date. These values *
* are already calcualted on UI or can be supplied by end-user. *
* For posting of these taxes system takes definition of discount account from: *
* - Bank account definition - AR or AP discount account *
* - Tax definition - Discount account *
* If tax is discountable at payment tx2_mstr.tx2_pmt_disc then system have to split *
* posting of tax amount itself (partial reversing of original tax posting) and then *
* base amount of this tax is posted to discount account as defined by tax definnition *
* If tax is not discountable at payment, whole full tax amount (base + tax) is posted *
* on discount account defined on tax. *
* =================================================================================================== */
/* Start block */
MAIN_BLOCK:
do on error undo, throw:
/* Go throuch all tax posting of invoice and discount them first */
<Q-77 run PostingVatByPostingLineId (all) (Read) (NoCache)
(input tBankStateAlloc.tiDocPostingID, (PostingID)
input ?, (CompanyId)
output dataset tqPostingVatByPostingLineId) in BPosting >
/* Check, if there are any delayed taxes, in this case we need to know some details from the invoice */
if tBankStateAlloc.CInvoice_ID <> 0 and
tBankStateAlloc.CInvoice_ID <> ? and
can-find(first tqPostingVatByPostingLineId where
tqPostingVatByPostingLineId.tiPosting_ID = tBankStateAlloc.tiDocPostingID and
tqPostingVatByPostingLineId.tlPostingVatIsSuspDel = true)
then do:
<Q-1 run CInvoiceVatForDelTax (all) (Read) (NoCache)
(input ?, (CompanyId)
input tBankStateAlloc.CInvoice_ID, (CInvoiceId)
input true, (CInvoiceVatIsSuspDel)
output dataset tqCInvoiceVatForDelTax) in BCInvoice>
end.
for each tqPostingVatByPostingLineId where
tqPostingVatByPostingLineId.tiPosting_ID = tBankStateAlloc.tiDocPostingID:
/* if tax is discountable at payment, make partial reverse of original tax posting */
if tqPostingVatByPostingLineId.tltx2_pmt_disc = true
then do:
assign vdDiscBaseDebitTC = if tqPostingVatByPostingLineId.tdPostingVatTaxCreditTC <> 0
then tqPostingVatByPostingLineId.tdPostingVatBaseCreditTC * idDiscountRatio
else 0
vdDiscBaseCreditTC = if tqPostingVatByPostingLineId.tdPostingVatTaxDebitTC <> 0
then tqPostingVatByPostingLineId.tdPostingVatBaseDebitTC * idDiscountRatio
else 0
vdDiscTaxDebitTC = tqPostingVatByPostingLineId.tdPostingVatTaxCreditTC * idDiscountRatio
vdDiscTaxCreditTC = tqPostingVatByPostingLineId.tdPostingVatTaxDebitTC * idDiscountRatio
vdDiscBaseDebitTC = <M-4 RoundAmount
(input vdDiscBaseDebitTC (idUnroundedAmount),
input tBankStateAlloc.Currency_ID (iiCurrencyID),
input ? (icCurrencyCode)) in BBankEntry>
vdDiscBaseCreditTC = <M-76 RoundAmount
(input vdDiscBaseCreditTC (idUnroundedAmount),
input tBankStateAlloc.Currency_ID (iiCurrencyID),
input ? (icCurrencyCode)) in BBankEntry>
vdDiscTaxDebitTC = <M-94 RoundAmount
(input vdDiscTaxDebitTC (idUnroundedAmount),
input tBankStateAlloc.Currency_ID (iiCurrencyID),
input ? (icCurrencyCode)) in BBankEntry>
vdDiscTaxCreditTC = <M-59 RoundAmount
(input vdDiscTaxCreditTC (idUnroundedAmount),
input tBankStateAlloc.Currency_ID (iiCurrencyID),
input ? (icCurrencyCode)) in BBankEntry>.
/* for calculation of exchange rate use the one of the banking entry - not from invoice */
if tBankStateAlloc.tcDocCurrencyCode = vcCompanyLC
then assign vdDiscBaseDebitLC = vdDiscBaseDebitTC
vdDiscBaseCreditLC = vdDiscBaseCreditTC
vdDiscTaxDebitLC = vdDiscTaxDebitTC
vdDiscTaxCreditLC = vdDiscTaxCreditTC.
else assign vdDiscBaseDebitLC = vdDiscBaseDebitTC * idLCExchangeRate * idLCExchangeRateScale
vdDiscBaseCreditLC = vdDiscBaseCreditTC * idLCExchangeRate * idLCExchangeRateScale
vdDiscTaxDebitLC = vdDiscTaxDebitTC * idLCExchangeRate * idLCExchangeRateScale
vdDiscTaxCreditLC = vdDiscTaxCreditTC * idLCExchangeRate * idLCExchangeRateScale
vdDiscBaseDebitLC = <M-23 RoundAmount
(input vdDiscBaseDebitLC (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in BBankEntry>
vdDiscBaseCreditLC = <M-75 RoundAmount
(input vdDiscBaseCreditLC (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in BBankEntry>
vdDiscTaxDebitLC = <M-71 RoundAmount
(input vdDiscTaxDebitLC (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in BBankEntry>
vdDiscTaxCreditLC = <M-83 RoundAmount
(input vdDiscTaxCreditLC (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in BBankEntry>.
end. /* if tqPostingVatByPostingLineId.tltx2_pmt_disc = true */
/* Tax is not discountable at payment */
else assign vdDiscBaseDebitTC = 0
vdDiscBaseCreditTC = 0
vdDiscBaseDebitLC = 0
vdDiscBaseCreditLC = 0
vdDiscTaxDebitTC = 0
vdDiscTaxCreditTC = 0
vdDiscTaxDebitLC = 0
vdDiscTaxCreditLC = 0.
/* If there is any tax to be reversed, do it */
if vdDiscTaxDebitTC <> 0 or
vdDiscTaxCreditTC <> 0
then do:
assign vcNormalTaxGLAccount = tqPostingVatByPostingLineId.tcGLCode
vcNormalTaxDivision = tqPostingVatByPostingLineId.tcDivisionCode.
/* ============================================================================================ *
* Check if this is delayed tax, in this case we have to correctly update invoice vat and also *
* generate positng to the delayed ta *
* This delayed tax posting needs to be done in case, the delayed taxes were not already *
* transferred to normal tax account *
* ============================================================================================ */
assign vlDiscTaxAppliedToSuspDelTax = false.
if tqPostingVatByPostingLineId.tlPostingVatIsSuspDel = true
then do:
if tBankStateAlloc.CInvoice_ID <> 0 and
tBankStateAlloc.CInvoice_ID <> ?
then do:
find tqCInvoiceVatForDelTax where
tqCInvoiceVatForDelTax.tiCInvoice_ID = tBankStateAlloc.CInvoice_ID and
tqCInvoiceVatForDelTax.tiPostingVat_ID = tqPostingVatByPostingLineId.tiPostingVat_ID
no-error.
if available tqCInvoiceVatForDelTax
then do:
if tqCInvoiceVatForDelTax.tdCInvoiceVatSuspDelTaxAmtTC <> 0
then do:
create tCInvoiceVatDelayDeltaRef.
assign tCInvoiceVatDelayDeltaRef.tiCInvoice_ID = tBankStateAlloc.CInvoice_ID
tCInvoiceVatDelayDeltaRef.tiCInvoiceVat_ID = tqCInvoiceVatForDelTax.tiCInvoiceVat_ID
tCInvoiceVatDelayDeltaRef.tdDelTaxAmtDeltaTC = vdDiscTaxCreditTC + vdDiscTaxDebitTC
tCInvoiceVatDelayDeltaRef.tdLCExchangeRate = idLCExchangeRate
tCInvoiceVatDelayDeltaRef.tdLCExchangeRateScale = idLCExchangeRateScale
tCInvoiceVatDelayDeltaRef.tdCCExchangeRate = idCCExchangeRate
tCInvoiceVatDelayDeltaRef.tdCCExchangeRateScale = idCCExchangeRateScale
tCInvoiceVatDelayDeltaRef.tlIsGenerateJEDelTax = true
tCInvoiceVatDelayDeltaRef.tlIsGenerateJETax = false
tCInvoiceVatDelayDeltaRef.tcPostingRowId = tBankStateLine.tcPostingRowId.
assign vlDiscTaxAppliedToSuspDelTax = true.
end. /* if tqCInvoiceVatForDelTax.tdCInvoiceVatSuspDelTaxAmtTC <> 0 */
else assign vcNormalTaxGLAccount = tqCInvoiceVatForDelTax.tcNormalTaxGLCode
vcNormalTaxDivision = tqCInvoiceVatForDelTax.tcNormalTaxDivisionCode.
end. /* if available tqCInvoiceVatForDelTax and */
end. /* if tBankStateAlloc.CInvoice_ID <> 0 and */
end. /* if tqPostingVatByPostingLineId.tlPostingVatIsSuspDel = true */
if not vlDiscTaxAppliedToSuspDelTax
then do:
<M-78 run AddPostingLineTax
(input tBankStateLine.tcPostingRowId (icPostingTcRowid),
input tBankStateAlloc.ttDocInvDate (itTaxPointDate),
input tBankStateLine.BankStateLineDescription (icPostingLineText),
input tBankStateAlloc.tcDocCurrencyCode (icCurrencyCode),
input tqPostingVatByPostingLineId.tcPostingVatInOut (icPostingVatInOut),
input tqPostingVatByPostingLineId.tcVatCode (icPostingVatCode),
input tqPostingVatByPostingLineId.tcDomainCode (icPostingVatDomain),
input idLCExchangeRate (idExchangeRate),
input idLCExchangeRateScale (idExchangeRateScale),
input icExchangeRateType (icExchangeRateType),
input ? (idCCExchangeRate),
input ? (idCCExchangeRateScale),
input tqPostingVatByPostingLineId.tcPostingVatTransType (icTransactionType),
input tqPostingVatByPostingLineId.tcPostingVatTaxTransType (icTaxTransactionType),
input vdDiscBaseDebitTC (idBaseDebitTC),
input vdDiscBaseCreditTC (idBaseCreditTC),
input vdDiscBaseDebitLC (idBaseDebitLC),
input vdDiscBaseCreditLC (idBaseCreditLC),
input ? (idBaseDebitCC),
input ? (idBaseCreditCC),
input vdDiscTaxDebitTC (idVatDebitTC),
input vdDiscTaxCreditTC (idVatCreditTC),
input vdDiscTaxDebitLC (idVatDebitLC),
input vdDiscTaxCreditLC (idVatCreditLC),
input ? (idVatDebitCC),
input ? (idVatCreditCC),
input vcNormalTaxGLAccount (icNormalTaxGLCode),
input vcNormalTaxDivision (icNormalTaxDivisionCode),
input tqPostingVatByPostingLineId.tlPostingVatIsAbsRet (ilNormalTaxIsAlreadyAbsRet),
input '':U (icAbsRetTaxGLCode),
input '':U (icAbsRetTaxDivisionCode),
input tqPostingVatByPostingLineId.tcFromTxzTaxZone (icFromTaxZone),
input tqPostingVatByPostingLineId.tcToTxzTaxZone (icToTaxZone),
input tqPostingVatByPostingLineId.tcTxenvTaxEnv (icTaxEnvrionment),
input true (ilIsTaxable),
input tqPostingVatByPostingLineId.tcTxclTaxCls (icTaxClass),
input tqPostingVatByPostingLineId.tcTxuTaxUsage (icTaxUsage),
input tqPostingVatByPostingLineId.tcTxtyTaxType (icTaxType),
input tqPostingVatByPostingLineId.tlPostingVatIsReverseCharge (ilTaxIsReverseChargeDomestic),
input ? (iiTaxAddressID),
input tqPostingVatByPostingLineId.tcPostingVatTaxIDFeder (icTaxIDFeder),
input tqPostingVatByPostingLineId.tcPostingVatTaxIDState (icTaxIDState),
input tqPostingVatByPostingLineId.tcPostingVatTaxIDMisc1 (icTaxIDMisc1),
input tqPostingVatByPostingLineId.tcPostingVatTaxIDMisc2 (icTaxIDMisc2),
input tqPostingVatByPostingLineId.tcPostingVatTaxIDMisc3 (icTaxIDMisc3),
input ? (iiOwnAddressID),
input tqPostingVatByPostingLineId.tcPostingVatOwnTaxIDFeder (icOwnTaxIDFeder),
input tqPostingVatByPostingLineId.tcPostingVatOwnTaxIDState (icOwnTaxIDState),
input tqPostingVatByPostingLineId.tcPostingVatOwnTaxIDMisc1 (icOwnTaxIDMisc1),
input tqPostingVatByPostingLineId.tcPostingVatOwnTaxIDMisc2 (icOwnTaxIDMisc2),
input tqPostingVatByPostingLineId.tcPostingVatOwnTaxIDMisc3 (icOwnTaxIDMisc3),
input tqPostingVatByPostingLineId.tiPostingVatOwnTaxDeclarat (iiOwnTaxIDDeclarat),
input tqPostingVatByPostingLineId.tlPostingVatIsSuspDel (ilIsSuspDel),
output viDummyNormalTaxPostingLineID (oiNormalTaxPostingLineID),
output vcDummy (ocNormalTaxPostingLineTcRowid),
output viDummyAbsRetTaxPostingLineID (oiAbsRetTaxPostingLineID),
output vcDummy (ocAbsRetTaxPostingLineTcRowid),
output viDummy (oiNormalTaxPostingVatID),
input false (ilLinkedCrCyDaemonReqExists),
input no (ilCalledFromMoveSuspDelTax),
input ? (itInvoiceExchangeRateDate),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
assign vcBankPostingLineId = if vcBankPostingLineId = "":U
then string(viDummyNormalTaxPostingLineID)
else vcBankPostingLineId + ",":U + string(viDummyNormalTaxPostingLineID).
assign vcBankPostingLineId = if vcBankPostingLineId = "":U
then string(viDummyAbsRetTaxPostingLineID)
else vcBankPostingLineId + ",":U + string(viDummyAbsRetTaxPostingLineID).
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
end. /* if not vlDiscTaxAppliedToSuspDelTax or */
end. /* if vdDiscTaxDebitTC <> 0 or */
/* post whole non-discountable taxes or base of non-discoutable tax */
if vdDiscBaseCreditTC <> 0 or
vdDiscBaseDebitTC <> 0
then do:
/* Get discount account from tax definition */
<Q-95 run MfgTaxCodeByTaxCode (all) (Read) (NoCache)
(input tqPostingVatByPostingLineId.tctx2_tax_code, (TaxCode)
input tqPostingVatByPostingLineId.tctx2_domain, (DomainCode)
input ?, (DiscountAtPayment)
input ?, (IsTaxByLine)
output dataset tqMfgTaxCodeByTaxCode) in BMfgTaxCode>
find first tqMfgTaxCodeByTaxCode no-error.
if not available tqMfgTaxCodeByTaxCode
then do:
assign vcMessage = trim(substitute(#T-97'The Tax Rate code &1 does not exist in domain &2':150(134081051)T-97#, tVatDiscPostingVat.tcVatCode, tVatDiscPostingVat.tcDomainCode)).
oiReturnStatus = -1.
<M-96 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-9105':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
assign oiReturnStatus = -1.
leave MAIN_BLOCK.
end.
if (tBankStateAlloc.DInvoice_ID <> 0 and tBankStateAlloc.DInvoice_ID <> ?) or
tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NDINV} or
tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-DCOLL}
then assign vcVatDiscGLCode = tqMfgTaxCodeByTaxCode.tctx2_ar_disc_acct
vcVatDiscSub = tqMfgTaxCodeByTaxCode.tctx2_ar_disc_sub
vcVatDiscCC = tqMfgTaxCodeByTaxCode.tctx2_ar_disc_cc.
else assign vcVatDiscGLCode = tqMfgTaxCodeByTaxCode.tctx2_ap_disc_acct
vcVatDiscSub = tqMfgTaxCodeByTaxCode.tctx2_ap_disc_sub
vcVatDiscCC = tqMfgTaxCodeByTaxCode.tctx2_ap_disc_cc.
/* Make posting */
<M-91 run AddStandardPosting
(input tBankStateLine.tcPostingRowId (icPostingtcRowid),
input if vcVatDiscGLCode = '':U or vcVatDiscGLCode = ? then icDiscountGLCode else vcVatDiscGLCode (icGLCode),
input if vcVatDiscGLCode = '':U or vcVatDiscGLCode = ? then '':U else vcVatDiscSub (icDivisionCode),
input if vcVatDiscGLCode = '':U or vcVatDiscGLCode = ? then '':U else vcVatDiscCC (icCostCentreCode),
input '':U (icCostCentreText),
input '':U (icProjectCode),
input '':U (icProjectText),
input '':U (icIntercoBusinessRelationCode),
input tBankStateAlloc.tcDocCurrencyCode (icCurrencyCode),
input vdDiscBaseDebitTC (idDebitTC),
input vdDiscBaseDebitLC (idDebitLC),
input ? (idDebitCC),
input ? (idDebitPC),
input vdDiscBaseCreditTC (idCreditTC),
input vdDiscBaseCreditLC (idCreditLC),
input ? (idCreditCC),
input ? (idCreditPC),
input 0 (idQty),
input tBankStateLine.BankStateLineDescription (icLineText),
input '':U (icSafText),
input tBankDefaultSafs (tDefaultSafs),
input icExchangeRateType (icExchangeRateType),
input idLCExchangeRate (idExchangeRate),
input idLCExchangeRateScale (idExchangeRateScale),
input ? (idPostingLineCCRate),
input ? (idPostingLineCCScale),
output viDummyPostingLineId (oiPostingLineId),
input ? (iiSafStructureId),
input ? (icSafStructureCode),
input ? (icAllocationKey),
input false (ilLinkedCrCyDaemonReqExists),
input ? (itExchangeRateDate),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
assign vcBankPostingLineId = if vcBankPostingLineId = "":U
then string(viDummyPostingLineId)
else vcBankPostingLineId + ",":U + string(viDummyPostingLineId).
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then leave MAIN_BLOCK.
end. /* if vdDiscBaseCreditTC <> 0 or */
/* Decrease already posted discount amount */
if tBankStateAlloc.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then assign bdDiscountedAmountTC = bdDiscountedAmountTC
- (vdDiscBaseCreditTC + vdDiscTaxCreditTC)
+ (vdDiscBaseDebitTC + vdDiscTaxDebitTC).
else assign bdDiscountedAmountTC = bdDiscountedAmountTC
+ (vdDiscBaseCreditTC + vdDiscTaxCreditTC)
- (vdDiscBaseDebitTC + vdDiscTaxDebitTC).
if vdDiscTaxDebitTC = 0 and
vdDiscTaxCreditTC = 0 and
tqPostingVatByPostingLineId.tltx2_pmt_disc = true
then do:
/*Taxable invoice but tax is Zero */
find first tVatdata where
tVatData.tcdomcode = tqPostingVatByPostingLineId.tctx2_domain and
tVatData.tctaxcode = tqPostingVatByPostingLineId.tctx2_tax_code
no-lock no-error.
if not available tVatData
then do:
create tVatData.
assign tVatData.tcdomcode = tqPostingVatByPostingLineId.tctx2_domain
tVatData.tctaxcode = tqPostingVatByPostingLineId.tctx2_tax_code.
end. /* find first tVatdata */
end. /* if vdDiscTaxDebitTC = 0 and */
end. /* of for each tqPostingVatByPostingLineId where */
END. /* MAIN_BLOCK */