project QadFinancials > class BDDocument > method AdditionalUpdatesPostingXrefDIDisc
Description
This method creates posting for discounts calculated at the payment. These discounts 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. If there is any amount excluded from taxes, this amount is posted on discount account taken from Bank GL definition For all postings original exchange rate as on Invoice is used
Parameters
icPostingRowid | input | character | |
icDInvoiceType | input | character | Invoice Type |
ilIsUndoPayment | input | logical | Is this undo of the payment |
odMovementDiscountTC | output | decimal | discount amount of the movement in TC |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program5/bddocument.p)
/* ================================================================================================== *
* Method: AddiitonalUpdatesPostingXrefDIDisc *
* Description: This method creates posting for discounts calculated at the payment. These discounts *
* 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. *
* If there is any amount excluded from taxes, this amount is posted on discount account *
* taken from Bank GL definition *
* For all postings original exchange rate as on Invoice is used *
* =================================================================================================== */
/* Set default ReturnStatus */
assign oiReturnStatus = -98
viLocalReturn = 0.
BLOCKBANKSTATEALLOC:
do:
/* Calculate total discount and split it by each tax line. If there is not tax line or part of amount is not *
* included in taxes -> post it on discount account from Bank GL Account definition */
assign vdDiscountedAmountTC = if tDDocumentInvoiceXref.tc_Status = "N":U
then tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC
else if ilIsUndoPayment = true
then - t_iDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC
else tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC -
t_iDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC
vdDiscountRatio = tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC / tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
odMovementDiscountTC = if vdDiscountedAmountTC <> 0
then if icDInvoiceType = {&INVOICETYPE-INVOICE} or icDInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
then vdDiscountedAmountTC
else if icDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or icDInvoiceType = {&INVOICETYPE-CREDITNOTE}
then - vdDiscountedAmountTC
else 0
else 0.
/* If there is not any discount, just skip it */
if vdDiscountedAmountTC = 0
then leave BLOCKBANKSTATEALLOC.
/* Get discount account as it is defined on Bank GL account */
<M-2 run AdditionalUpdatesGetBankGLInfo
(input true (ilErrorIfNoDiscountAccount),
input false (ilErrorIfNoCurrency),
output vcDiscBankGLAccount (ocDiscountGLAccount),
output vcIntBankGLAccount (ocInterestGLAccount),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
if viLocalReturn < 0 then leave BLOCKBANKSTATEALLOC.
/* Go throuch all tax posting of invoice and discount them first */
if vlIsQStartedPostingVatByPosti <> true
then do :
<Q-3 run PostingVatByPostingLineId (Start) in BPosting >
assign vlIsQStartedPostingVatByPosti = true.
end.
if tDDocumentInvoiceXref.tiDInvoicePostingId <> 0 and
tDDocumentInvoiceXref.tiDInvoicePostingId <> ?
then do:
<Q-4 run PostingVatByPostingLineId (all) (Read) (NoCache)
(input tDDocumentInvoiceXref.tiDInvoicePostingId, (PostingID)
input ?, (CompanyId)
output dataset tqPostingVatByPostingLineId) in BPosting >
end.
for each tqPostingVatByPostingLineId where
tqPostingVatByPostingLineId.tiPosting_ID = tDDocumentInvoiceXref.tiDInvoicePostingId:
<M-47 run AdditionalUpdatesPostingXrefDIDisc3
(input vdDiscountRatio (idDiscountRatio),
output vdDiscBaseDebitTC (odDiscBaseDebitTC),
output vdDiscBaseCreditTC (odDiscBaseCreditTC),
output vdDiscBaseDebitCC (odDiscBaseDebitCC),
output vdDiscBaseCreditCC (odDiscBaseCreditCC),
output vdDiscBaseDebitLC (odDiscBaseDebitLC),
output vdDiscBaseCreditLC (odDiscBaseCreditLC),
output vdDiscTaxDebitTC (odDiscTaxDebitTC),
output vdDiscTaxCreditTC (odDiscTaxCreditTC),
output vdDiscTaxDebitCC (odDiscTaxDebitCC),
output vdDiscTaxCreditCC (odDiscTaxCreditCC),
output vdDiscTaxDebitLC (odDiscTaxDebitLC),
output vdDiscTaxCreditLC (odDiscTaxCreditLC),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave BLOCKBANKSTATEALLOC.
/* If there is any tax to be reversed, do it */
if vdDiscTaxDebitTC <> 0 or
vdDiscTaxCreditTC <> 0
then do:
<M-17 run AddPostingLineTax
(input icPostingRowId (icPostingTcRowid),
input tDDocumentInvoiceXref.ttDInvoiceDate (itTaxPointDate),
input tDDocument.tcPostingText (icPostingLineText),
input tDDocumentInvoiceXref.tcCurrencyCode (icCurrencyCode),
input tqPostingVatByPostingLineId.tcPostingVatInOut (icPostingVatInOut),
input tqPostingVatByPostingLineId.tcVatCode (icPostingVatCode),
input tqPostingVatByPostingLineId.tcDomainCode (icPostingVatDomain),
input tDDocumentInvoiceXref.tdLCExchangeRate (idExchangeRate),
input tDDocumentInvoiceXref.tdLCExchangeRateScale (idExchangeRateScale),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType),
input tDDocumentInvoiceXref.tdCCExchangeRate (idCCExchangeRate),
input tDDocumentInvoiceXref.tdCCExchangeRateScale (idCCExchangeRateScale),
input tqPostingVatByPostingLineId.tcPostingVatTransType (icTransactionType),
input tqPostingVatByPostingLineId.tcPostingVatTaxTransType (icTaxTransactionType),
input vdDiscBaseDebitTC (idBaseDebitTC),
input vdDiscBaseCreditTC (idBaseCreditTC),
input vdDiscBaseDebitLC (idBaseDebitLC),
input vdDiscBaseCreditLC (idBaseCreditLC),
input vdDiscBaseDebitCC (idBaseDebitCC),
input vdDiscBaseCreditCC (idBaseCreditCC),
input vdDiscTaxDebitTC (idVatDebitTC),
input vdDiscTaxCreditTC (idVatCreditTC),
input vdDiscTaxDebitLC (idVatDebitLC),
input vdDiscTaxCreditLC (idVatCreditLC),
input vdDiscTaxDebitCC (idVatDebitCC),
input vdDiscTaxCreditCC (idVatCreditCC),
input tqPostingVatByPostingLineId.tcGLCode (icNormalTaxGLCode),
input tqPostingVatByPostingLineId.tcDivisionCode (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 viDummy (oiNormalTaxPostingLineID),
output vcDummy (ocNormalTaxPostingLineTcRowid),
output viDummy (oiAbsRetTaxPostingLineID),
output vcDummy (ocAbsRetTaxPostingLineTcRowid),
output viDummy (oiNormalTaxPostingVatID),
input false (ilLinkedCrCyDaemonReqExists),
input no (ilCalledFromMoveSuspDelTax),
input ? (itInvoiceExchangeRateDate),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave BLOCKBANKSTATEALLOC.
end.
if tqPostingVatByPostingLineId.tlPostingVatIsAbsRet = Yes then do:
/* Decrease already posted discount amount */
if tDDocumentInvoiceXref.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then assign vdDiscountedAmountTC = vdDiscountedAmountTC
- vdDiscTaxCreditTC
+ vdDiscTaxDebitTC.
else assign vdDiscountedAmountTC = vdDiscountedAmountTC
+ vdDiscTaxCreditTC
- vdDiscTaxDebitTC.
end.
else do:
/* post base amount of tax on the discount account taken from tax definition */
if vdDiscBaseCreditTC <> 0 or
vdDiscBaseDebitTC <> 0
then do:
if not vlIsQStartedMfgTaxCodeByTaxC
then do:
<Q-19 run MfgTaxCodeByTaxCode (Start) in BMfgTaxCode>
assign vlIsQStartedMfgTaxCodeByTaxC = true.
end.
/* Get discount account from tax definition */
<Q-18 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-1'The Tax Rate code &1 does not exist in domain &2':150(999890459)T-1#, tqPostingVatByPostingLineId.tctx2_domain, tqPostingVatByPostingLineId.tctx2_tax_code))
vcContext = "tqPostingVatByPostingLineId.tctx2_domain=&1|tqPostingVatByPostingLineId.tctx2_tax_code=&2":U
vcContext = replace(vcContext, "|":U, chr(2))
vcContext = substitute(vcContext, tqPostingVatByPostingLineId.tctx2_domain, tqPostingVatByPostingLineId.tctx2_tax_code)
viLocalReturn = -1.
<M-20 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-9125':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
assign viLocalReturn = -1.
leave BLOCKBANKSTATEALLOC.
end.
if tDDocumentInvoiceXref.DInvoice_ID <> 0 and
tDDocumentInvoiceXref.DInvoice_ID <> ?
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-21 run AddStandardPosting
(input icPostingRowid (icPostingtcRowid),
input if vcVatDiscGLCode = '':U or vcVatDiscGLCode = ? then vcDiscBankGLAccount 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 tDDocument.tcCurrencyCode (icCurrencyCode),
input vdDiscBaseDebitTC (idDebitTC),
input ? (idDebitLC),
input ? (idDebitCC),
input ? (idDebitPC),
input vdDiscBaseCreditTC (idCreditTC),
input ? (idCreditLC),
input ? (idCreditCC),
input ? (idCreditPC),
input 0 (idQty),
input tDDocument.tcPostingText (icLineText),
input '':U (icSafText),
input tDefaultSafsDDoc (tDefaultSafs),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType),
input tDDocumentInvoiceXref.tdLCExchangeRate (idExchangeRate),
input tDDocumentInvoiceXref.tdLCExchangeRateScale (idExchangeRateScale),
input tDDocumentInvoiceXref.tdCCExchangeRate (idPostingLineCCRate),
input tDDocumentInvoiceXref.tdCCExchangeRateScale (idPostingLineCCScale),
output viDummy (oiPostingLineId),
input 0 (iiSafStructureId),
input '':U (icSafStructureCode),
input ? (icAllocationKey),
input false (ilLinkedCrCyDaemonReqExists),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
if viLocalReturn < 0 then leave BLOCKBANKSTATEALLOC.
end. /* if vdDiscBaseCreditTC <> 0 or */
/* Decrease already posted discount amount */
if tDDocumentInvoiceXref.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then assign vdDiscountedAmountTC = vdDiscountedAmountTC
- (vdDiscBaseCreditTC + vdDiscTaxCreditTC)
+ (vdDiscBaseDebitTC + vdDiscTaxDebitTC).
else assign vdDiscountedAmountTC = vdDiscountedAmountTC
+ (vdDiscBaseCreditTC + vdDiscTaxCreditTC)
- (vdDiscBaseDebitTC + vdDiscTaxDebitTC).
end.
end. /* of for each tqPostingVatByPostingLineId where */
/* if there was not any taxes or if part of invoice amount was excluded from taxes, post this amount */
/* to discount account taken from bank gl account definition */
if vdDiscountedAmountTC <> 0
then do:
/* Create the discount Posting-Line */
empty temp-table tDefaultSafsDDoc.
if tDDocumentInvoiceXref.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then if ilIsUndoPayment
then assign vdDebitTC = - vdDiscountedAmountTC
vdCreditTC = 0.
else assign vdDebitTC = 0
vdCreditTC = vdDiscountedAmountTC.
else if ilIsUndoPayment
then assign vdDebitTC = 0
vdCreditTC = - vdDiscountedAmountTC.
else assign vdDebitTC = vdDiscountedAmountTC
vdCreditTC = 0.
<M-46 run AdditionalUpdatesPostingXrefDIDisc2
(input icPostingRowid (icPostingRowid),
input vcDiscBankGLAccount (icDiscBankGLAccount),
input vdDebitTC (idDebitTC),
input vdCreditTC (idCreditTC),
input ? (idDebitLC),
input ? (idCreditLC),
input ? (idDebitCC),
input ? (idCreditCC),
input tDDocumentInvoiceXref.tdLCExchangeRate (idExchangeRate),
input tDDocumentInvoiceXref.tdLCExchangeRateScale (idExchangeRateSCale),
input tDDocumentInvoiceXref.tdCCExchangeRate (idCCRate),
input tDDocumentInvoiceXref.tdCCExchangeRateScale (idCCSCale),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
if viLocalReturn < 0 then leave BLOCKBANKSTATEALLOC.
end. /* of if vdDiscountedAmountTC <> 0 */
END. /* stop block BLOCKBANKSTATEALLOC */
/* Set ReturnStatus */
assign oiReturnStatus = viLocalReturn.