project QadFinancials > class BDDocument > method GetPossibleAllocationStages
Parameters
iiDInvoiceID | input | integer | |
icParentRowID | input | character | |
itDDocumentDueDate | input | date | |
icDInvoiceCurrencyCode | input | character | Currency code of customer invoice |
idInvoiceOriginalAmountTC | input | decimal | |
idInvoiceNonDiscAmountTC | input | decimal | |
idInvoiceVatTC | input | decimal | |
ilIsDiscountTaxAtPayment | input | logical | |
odInvoiceTotalPaymentAmountTC | output | decimal | |
odInvoiceTotalDiscountAmountTC | output | decimal | |
idNonDiscountableAmountTC | input | decimal | Non Discountable Amount |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bddocument.p)
<Q-45 run DInvoiceStageByDueDate (all) (Read) (NoCache)
(input iiDInvoiceID, (DInvoiceID)
input ?, (DueDate)
output dataset tqDInvoiceStageByDueDate) in BDInvoice>
assign viCount = 0
odInvoiceTotalPaymentAmountTC = 0
odInvoiceTotalDiscountAmountTC = 0
vdInvoiceDiscountableAmountTC = (if ilIsDiscountTaxAtPayment
then idInvoiceOriginalAmountTC - idInvoiceNonDiscAmountTC
else idInvoiceOriginalAmountTC - idInvoiceNonDiscAmountTC - idInvoiceVatTC).
for last tDDocPossibleAllocationStages where
tDDocPossibleAllocationStages.tc_ParentRowid = icParentRowID /* Fin-2913: This condition is needed to avoid that we get duplicate records (tc_rowid) in tDDocPossibleAllocationStages */ :
assign viCount = integer(tDDocPossibleAllocationStages.tc_Rowid) no-error.
end.
/* Overtake all Invoice stages and propose payemnt for it */
for each tqDInvoiceStageByDueDate:
/* Check, if there is still free amount on the stage, which can be allocated */
if tqDInvoiceStageByDueDate.tdDInvoiceStageAmountTC = tqDInvoiceStageByDueDate.tdDInvoiceStageAmtAppliedTC
then next.
assign viCount = viCount + 1.
create tDDocPossibleAllocationStages.
assign tDDocPossibleAllocationStages.tc_ParentRowid = icParentRowID
tDDocPossibleAllocationStages.tc_rowid = string(icParentRowID,"X(20)") + string(viCount) /* Fin-2913: This combination of the parent-rowid and the count is needed to avoid that we get duplicate records (tc_rowid) in tDDocPossibleAllocationStages */
tDDocPossibleAllocationStages.DInvoiceStage_ID = tqDInvoiceStageByDueDate.tiDInvoiceStage_ID
tDDocPossibleAllocationStages.tiDInvoice_ID = tqDInvoiceStageByDueDate.tiDInvoice_ID
tDDocPossibleAllocationStages.tdDefaultDiscountPerc = tqDInvoiceStageByDueDate.tdDInvoiceStageDiscPerc
tDDocPossibleAllocationStages.ttDefaultDueDate = tqDInvoiceStageByDueDate.ttDInvoiceStageDueDate
tDDocPossibleAllocationStages.ttDefaultDiscDate = tqDInvoiceStageByDueDate.ttDInvoiceStageDiscDate
tDDocPossibleAllocationStages.tdDefaultAllocAmountTC = tqDInvoiceStageByDueDate.tdDInvoiceStageAmountTC
- tqDInvoiceStageByDueDate.tdDInvoiceStageAmtAppliedTC.
/* Calculate Payment and discount amount */
/* Currently Discount Tax at Payment is not considered for staged credit terms */
if itDDocumentDueDate <= tqDInvoiceStageByDueDate.ttDInvoiceStageDiscDate
then assign tDDocPossibleAllocationStages.tdDefaultDiscountAmountTC = vdInvoiceDiscountableAmountTC
* (tDDocPossibleAllocationStages.tdDefaultAllocAmountTC / idInvoiceOriginalAmountTC)
* (tqDInvoiceStageByDueDate.tdDInvoiceStageDiscPerc / 100)
tDDocPossibleAllocationStages.tdDefaultDiscountAmountTC = <M-2 RoundAmount
(input tDDocPossibleAllocationStages.tdDefaultDiscountAmountTC (idUnroundedAmount),
input ? (iiCurrencyID),
input icDInvoiceCurrencyCode (icCurrencyCode)) in BDDocument>
tDDocPossibleAllocationStages.tdDefaultPaymentAmountTC = tDDocPossibleAllocationStages.tdDefaultAllocAmountTC
- tDDocPossibleAllocationStages.tdDefaultDiscountAmount.
else assign tDDocPossibleAllocationStages.tdDefaultDiscountAmountTC = 0
tDDocPossibleAllocationStages.tdDefaultPaymentAmountTC = tDDocPossibleAllocationStages.tdDefaultAllocAmountTC.
/* keep track of the total amounts for the invoice */
assign odInvoiceTotalDiscountAmountTC = odInvoiceTotalDiscountAmountTC + tDDocPossibleAllocationStages.tdDefaultDiscountAmountTC
odInvoiceTotalPaymentAmountTC = odInvoiceTotalPaymentAmountTC + tDDocPossibleAllocationStages.tdDefaultPaymentAmountTC.
end. /* for each tqDInvoiceStageDueDate */