project QadFinancials > class BDInvoice > method CreateDInvoiceStageUpdate
Description
This method will create DInvoiceStagePayment records to correspond to the total invoice payment amount. This will have the result of updation the amount applied on the individual DInvoiceStage records.
Parameters
iiDInvoiceID | input | integer | |
itPaymentDate | input | date | |
idMovementAmountTC | input | decimal | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program7/bdinvoice.p)
/* Retrieve the DI stage records for the current invoice that are inside the processing date */
<Q-1 run DInvoiceStageByDueDate (all) (Read) (NoCache)
(input iiDInvoiceID, (DInvoiceID)
input itPaymentDate, (DueDate)
output dataset tqDInvoiceStageByDueDate) in BDInvoice >
/* reset count variable */
assign viCount = 0.
STAGEBLOCK:
for each tqDInvoiceStageByDueDate
break by tqDInvoiceStageByDueDate.ttDInvoiceStageDueDate:
/* reset discount variable */
assign vlApplyDiscount = false
viCount = viCount + 1.
create tDInvoiceStageUpdates.
assign tDinvoiceStageUpdates.DDocInvoiceXrefStage_ID = viCount
tDinvoiceStageUpdates.tc_rowid = string(viCount)
tDInvoiceStageUpdates.DInvoiceStage_ID = tqDInvoiceStageByDueDate.tiDInvoiceStage_ID
tDinvoiceStageUpdates.tiDInvoice_ID = iiDinvoiceID.
assign vdStageOpenAmount = tqDInvoiceStageByDueDate.tdDInvoiceStageAmountTC - tqDInvoiceStageByDueDate.tdDInvoiceStageAmtAppliedTC.
/* check if we shoudl apply a discount */
if itPaymentDate < tqDInvoiceStageByDueDate.ttDInvoiceStageDiscDate
then assign vlApplyDiscount = true.
/* There is more leave on the stage than the current payment - allocate the current payment and then leave */
if vdStageOpenAmount >= idMovementAmountTC
then do:
if vlApplyDiscount
then assign tDinvoiceStageUpdates.DDocInvoiceXrefStageDiscTC = (idMovementAmountTC * tqDInvoiceStageByDueDate.tdPaymentConditionPercentage) / 100.
assign tDinvoiceStageUpdates.DDocInvoiceXrefStageAlloTC = idMovementAmountTC.
leave STAGEBLOCK.
end. /* end vdStageOpenAmount >= idMovementAmountTC */
/* If there is less left on the stage than the payment amount. Allocate the amount left on the stage and then subtract that from the payment amount */
else do:
if vlApplyDiscount
then assign tDinvoiceStageUpdates.DDocInvoiceXrefStageDiscTC = (vdStageOpenAmount * tqDInvoiceStageByDueDate.tdPaymentConditionPercentage) / 100.
assign tDinvoiceStageUpdates.DDocInvoiceXrefStageAlloTC = vdStageOpenAmount
idMovementAmountTC = idMovementAmountTC - vdStageOpenAmount.
end.
end. /* end for each tqCinvoiceStageByDueDate */