project QadFinancials > class BBankEntry > method AdditionalUpdatesInvDiscountCurrDiff
Description
Posting on discount
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program4/bbankentry.p)
/* ================================================================================================== *
* Method: AddiitonalUpdatesInvDiscountCurrDiff *
* 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 *
* =================================================================================================== */
/* Set default ReturnStatus */
assign oiReturnStatus = -98
viBlockError = 0.
assign vcExchangeRateType = <M-34 GetExchangeRateType () in BBankEntry>.
/* Start block */
BLOCKBANKSTATEALLOC: DO :
/* Go through all allocated records which has discount amount */
for each tBankStateAlloc where
tBankStateAlloc.tc_ParentRowid = tBankStateLine.tc_Rowid and
(tBankStateAlloc.tc_Status = "N":U or
tBankStateAlloc.tc_Status = "C":U) and
((tBankStateAlloc.CInvoice_ID <> 0 and
tBankStateAlloc.CInvoice_ID <> ?) or
tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NCINV} or
(tBankStateAlloc.DInvoice_ID <> 0 and
tBankStateAlloc.DInvoice_ID <> ?) or
tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-NDINV} or
tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-CCOLL} or
tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-DCOLL}):
/* Skip processing if there is not any discount */
if tBankStateAlloc.BankStateAllocDiscountTC = 0 or
tBankStateAlloc.BankStateAllocDiscountTC = ?
then next.
/* Cumulate 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 = tBankStateAlloc.BankStateAllocDiscountTC
vdDiscountRatio = abs(tBankStateAlloc.BankStateAllocDiscountTC / tBankStateAlloc.tdDocOriginal).
/* Get discount account from Bank GL account definition */
<M-62 run AdditionalUpdatesInvDiscountAccount
(input-output vlQStartedGetGLIDBasedOnGLCode (blQStartedGetGLIDBasedOnGLCode),
output vcDiscountCode (ocDiscountGLCode),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viBlockError < 0 then leave BLOCKBANKSTATEALLOC.
/* Get exchange rate between currency of invoice and banking entry */
if tBankStateAlloc.tcDocCurrencyCode = vcCompanyLC
then assign vdExchangeRate = 1
vdExchangeRateScale = 1.
else do :
<M-5 run GetExchangeRate
(input tBankStateLine.Company_ID (iiCompanyID),
input ? (iiFromCurrencyID),
input tBankStateAlloc.tcDocCurrencyCode (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input vcExchangeRateType (icExchangeRateTypeCode),
input tBankStateLine.BankStateLineValueDate (itValidityDate),
output vdExchangeRate (odExchangeRate),
output vdExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viBlockError < 0 then leave BLOCKBANKSTATEALLOC.
end.
if tBankStateAlloc.tcDocCurrencyCode = vcCompanyCC
then assign vdCCExchangeRate = 1
vdCCExchangeRateScale = 1.
else if vcCompanyCC = vcCompanyLC
then assign vdCCExchangeRate = vdExchangeRate
vdCCExchangeRateScale = vdExchangeRateScale.
else do:
<M-64 run GetExchangeRate
(input tBankStateLine.Company_ID (iiCompanyID),
input ? (iiFromCurrencyID),
input tBankStateAlloc.tcDocCurrencyCode (icFromCurrencyCode),
input viCompanyCCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode),
input tBankStateLine.BankStateLineValueDate (itValidityDate),
output vdCCExchangeRate (odExchangeRate),
output vdCCExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viBlockError < 0 then leave BLOCKBANKSTATEALLOC.
end.
empty temp-table tVatData.
/* Make a posting of discount to the tax account if appropriate */
<M-58 run AdditionalUpdatesInvDiscountCurrDiffTax
(input vdDiscountRatio (idDiscountRatio),
input vcExchangeRateType (icExchangeRateType),
input vdExchangeRate (idLCExchangeRate),
input vdExchangeRateScale (idLCExchangeRateScale),
input vdCCExchangeRate (idCCExchangeRate),
input vdCCExchangeRateScale (idCCExchangeRateScale),
input vcDiscountCode (icDiscountGLCode),
input-output vdDiscountedAmountTC (bdDiscountedAmountTC),
output viBlockError (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0 then assign viBlockError = viFcReturnSuper.
if viBlockError < 0 then leave BLOCKBANKSTATEALLOC.
/* 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:
assign vcVatDiscGLCode = ""
vcVatDiscSub = ""
vcVatDiscCC = "".
find first tVatData no-lock no-error.
if available tVatData then do:
/* Get discount account from tax definition */
<Q-14 run MfgTaxCodeByTaxCode (all) (Read) (NoCache)
(input tVatData.tctaxcode, (TaxCode)
input tVatData.tcdomcode, (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-18'The Tax Rate code &1 does not exist in domain &2':150(999890459)T-18#, tVatData.tctaxcode, tVatData.tcdomcode)).
oiReturnStatus = -1.
<M-2 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-300316':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
assign oiReturnStatus = -1.
leave BLOCKBANKSTATEALLOC.
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.
end. /* if available tVatData */
/* posting on discount account */
if tBankStateAlloc.tcDocCurrencyCode = vcCompanyLC
then assign vdDiscountLC = vdDiscountedAmountTC.
else assign vdDiscountLC = if tBankStateLine.BankStateLineExtBankRate <> 0 and tBankStateLine.BankStateLineExtBankRate <> ? and tBankStateLine.BankStateLineExtBankRate <> 1
then <M-99 RoundAmount
(input vdDiscountedAmountTC * tBankStateLine.BankStateLineExtBankRate * tBankStateLine.BankStateLineExtRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BBankEntry>
else <M-124 RoundAmount
(input vdDiscountedAmountTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BBankEntry>.
/* Create the discount Posting-Line */
empty temp-table tBankDefaultSafs.
if tBankStateAlloc.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then assign vdDebitTC = 0
vdCreditTC = vdDiscountedAmountTC
vdDebitLC = 0
vdCreditLC = vdDiscountLC.
else assign vdDebitTC = vdDiscountedAmountTC
vdCreditTC = 0
vdDebitLC = vdDiscountLC
vdCreditLC = 0.
/* Make posting */
<M-98 run AddStandardPosting
(input tBankStateLine.tcPostingRowId (icPostingtcRowid),
input if vcVatDiscGLCode = '':U or vcVatDiscGLCode = ? then vcDiscountCode 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 vdDebitTC (idDebitTC),
input vdDebitLC (idDebitLC),
input ? (idDebitCC),
input ? (idDebitPC),
input vdCreditTC (idCreditTC),
input vdCreditLC (idCreditLC),
input ? (idCreditCC),
input ? (idCreditPC),
input 0 (idQty),
input tBankStateLine.BankStateLineDescription (icLineText),
input '':U (icSafText),
input tBankDefaultSafs (tDefaultSafs),
input vcExchangeRateType (icExchangeRateType),
input vdExchangeRate (idExchangeRate),
input vdExchangeRateScale (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 viBlockError = viFcReturnSuper.
if viBlockError < 0 then leave BLOCKBANKSTATEALLOC.
end. /* of if vdDiscountedAmountTC <> 0 */
end. /* for each tBankStateAlloc where */
END. /* stop block BLOCKBANKSTATEALLOC */
if vlQStartedGetGLIDBasedOnGLCode = true
then do :
<Q-65 run GetGLIDBasedOnGLCode (Stop) in BGL >
end. /* if */
if vlQStartedPostingVatByPosting = true
then do :
<Q-70 run PostingVatByPostingLineId (Stop) in BPosting >
end. /* if */
/* Capture the errors produced in the BankStateALLOCBlock */
if viBlockError <> 0 then assign oiReturnStatus = viBlockError.
if viBlockError < 0 then return.
/* Set ReturnStatus = OK */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.