iiCInvoiceID | input | integer | |
iiBankNumberID | input | integer | |
itDueDate | input | date | |
icPaymentSelectionDue | input | character | Parameter indicating, for which invoices payment amount should be proposed. |
icCInvoiceCurrencyCode | input | character | Supplier invoice Currency Code |
idOriginalInvoiceAmountTC | input | decimal | Original invoice amount including Taxes |
idOriginalInvoiceAmountNetTC | input | decimal | Original invoice amount without Taxes |
idOpenInvoiceAmountTC | input | decimal | |
idWhtAmountTC | input | decimal | With-holding tax amount |
idNonDiscountableAmountTC | input | decimal | Non Discount Amount |
ilIsProposePayment | input | logical | Propose payment of that invoice |
ilIsDiscountTaxAtPayment | input | logical | Discount tax at payment |
odLineTotalPaymentAmount | output | decimal | |
odLineTotalDiscountAmount | output | decimal | |
odLineTotalWhtAmount | output | decimal | Total allocated WHT amount |
olIsAllStagesSelected | output | logical | Are all stages selected |
tProposedLineStage | output | temp-table | |
itDisCountRefDueDate | input | date | |
oiReturnStatus | output | integer | Return status of the method. |
/* Default output values */ assign odLineTotalPaymentAmount = 0 odLineTotalDiscountAmount = 0 odLineTotalWhtAmount = 0 olIsAllStagesSelected = true. <Q-1 run CInvoiceStageByDueDate (all) (Read) (NoCache) (input iiCinvoiceID, (CInvoice_ID) input ?, (DueDate) output dataset tqCInvoiceStageByDueDate) in BCInvoice > /* Process all open stages for this invoice that are due */ for each tqCInvoiceStageByDueDate break by tqCInvoiceStageByDueDate.tiCInvoice_ID by tqCInvoiceStageByDueDate.ttCInvoiceStageDueDate: create tProposedLineStage. assign tProposedLineStage.tiObject_ID = iiCInvoiceID tProposedLineStage.tiBankNumber_ID = iiBankNumberID tProposedLineStage.tiProposedLine_ID = tProposedLine.tiProposedLine_ID tProposedLineStage.tdOriginalStageAmounTC = tqCInvoiceStageByDueDate.tdCInvoiceStageAmountTC tProposedLineStage.tdOpenStageAmountTC = tqCInvoiceStageByDueDate.tdCInvoiceStageAmountTC - tqCInvoiceStageByDueDate.tdCInvoiceStageAmtAppliedTC tProposedLineStage.tiCInvoiceStage_ID = tqCInvoiceStageByDueDate.tiCInvoiceStage_ID tProposedLineStage.ttStageDueDate = tqCInvoiceStageByDueDate.ttCInvoiceStageDueDate tProposedLineStage.ttStageDiscountDueDate = tqCInvoiceStageByDueDate.ttCInvoiceStageDiscDate tProposedLineStage.tdStageDiscountPercentage = tqCInvoiceStageByDueDate.tdCInvoiceStageDiscPerc. /* Distribute Wht amount to stages */ if not last-of(tqCInvoiceStageByDueDate.tiCInvoice_ID) then assign tProposedLineStage.tdDefaultWhtAmtTC = idWhtAmountTC * tProposedLineStage.tdOpenStageAmountTC / idOpenInvoiceAmountTC tProposedLineStage.tdDefaultWhtAmtTC = <M-10 RoundAmount (input tProposedLineStage.tdDefaultWhtAmtTC (idUnroundedAmount), input ? (iiCurrencyID), input icCInvoiceCurrencyCode (icCurrencyCode)) in BPaymentSelection> vdTotalWhtAmountTC = vdTotalWhtAmountTC + tProposedLineStage.tdDefaultWhtAmtTC. else assign tProposedLineStage.tdDefaultWhtAmtTC = idWhtAmountTC - vdTotalWhtAmountTC vdTotalWhtAmountTC = 0. /* if we are within the discount due date then apply discount */ if itDueDate < tqCInvoiceStageByDueDate.ttCInvoiceStageDiscDate then do: if ilIsDiscountTaxAtPayment then assign tProposedLineStage.tdDefaultStageDiscountAmountTC = (tProposedLineStage.tdOpenStageAmountTC - (idNonDiscountableAmountTC * (tProposedLineStage.tdOpenStageAmountTC / tProposedLineStage.tdOriginalStageAmounTC) * tqCInvoiceStageByDueDate.tdCInvoiceStagePercent / 100)) * /* part of non-discountable amount for the stage */ (tProposedLineStage.tdStageDiscountPercentage / 100). else assign tProposedLineStage.tdDefaultStageDiscountAmountTC = ((tProposedLineStage.tdOpenStageAmountTC * idOriginalInvoiceAmountNetTC / idOriginalInvoiceAmountTC) - /* Net amount of the stage which can be discounted - stage amount without taxes */ (idNonDiscountableAmountTC * (tProposedLineStage.tdOpenStageAmountTC / tProposedLineStage.tdOriginalStageAmounTC) * tqCInvoiceStageByDueDate.tdCInvoiceStagePercent / 100)) * /* part of non-discountable amount for the stage */ (tProposedLineStage.tdStageDiscountPercentage / 100). assign tProposedLineStage.tdDefaultStageDiscountAmountTC = <M-2 RoundAmount (input tProposedLineStage.tdDefaultStageDiscountAmountTC (idUnroundedAmount), input ? (iiCurrencyID), input icCInvoiceCurrencyCode (icCurrencyCode)) in BPaymentSelection> tProposedLineStage.tdDefaultStagePaymentAmountTC = tProposedLineStage.tdOpenStageAmountTC - tProposedLineStage.tdDefaultStageDiscountAmountTC - tProposedLineStage.tdDefaultWhtAmtTC. end. else assign tProposedLineStage.tdDefaultStageDiscountAmountTC = 0 tProposedLineStage.tdDefaultStagePaymentAmountTC = tProposedLineStage.tdOpenStageAmountTC - tProposedLineStage.tdDefaultWhtAmtTC. /* default the real payment */ if ilIsProposePayment AND ( (icPaymentSelectionDue = {&PAYMENTSELECTION-DUE-ALL}) OR (icPaymentSelectionDue = {&PAYMENTSELECTION-DUE-DUE} and tProposedLineStage.ttStageDueDate <= itDueDate) OR ( icPaymentSelectionDue = {&PAYMENTSELECTION-DUE-DUEORFINDISC} and (tProposedLineStage.ttStageDueDate <= itDueDate or (itDisCountRefDueDate <> ? and tProposedLineStage.ttStageDiscountDueDate <= itDisCountRefDueDate and tProposedLineStage.ttStageDiscountDueDate >= itDueDate and tProposedLineStage.tdStageDiscountPercentage <> 0) or (itDisCountRefDueDate = ? and tProposedLineStage.ttStageDiscountDueDate >= itDueDate and tProposedLineStage.tdStageDiscountPercentage <> 0) ) ) ) then assign tProposedLineStage.tdStageAllocAmountTC = tProposedLineStage.tdOpenStageAmountTC tProposedLineStage.tdStagePaymentAmountTC = tProposedLineStage.tdDefaultStagePaymentAmountTC tProposedLineStage.tdStageDiscountAmountTC = tProposedLineStage.tdDefaultStageDiscountAmountTC tProposedLineStage.tdWHTAmtTC = tProposedLineStage.tdDefaultWhtAmtTC tProposedLineStage.tlIsSelected = true. else assign olIsAllStagesSelected = false. /* keep track of totals for parent */ assign odLineTotalPaymentAmount = odLineTotalPaymentAmount + tProposedLineStage.tdStagePaymentAmountTC odLineTotalDiscountAmount = odLineTotalDiscountAmount + tProposedLineStage.tdStageDiscountAmountTC odLineTotalWhtAmount = odLineTotalWhtAmount + tProposedLineStage.tdWHTAmtTC. end. /* for each tqCInvoiceStageByDueDate: */