project QadFinancials > class BBankImportLine > method GetInvoiceStagesByBankImpLineXref
Description
Create the tInvoiceStage record(s)
Parameters
bdAccumulateAmount | input-output | decimal | |
odDiscountAmount | output | decimal | |
odInvoicePaymentAmount | output | decimal | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bbankimportline.p)
/* =================================================================================================== */
/* if using custom matching logic, then return directly without executing standard matching logic. */
/* =================================================================================================== */
if vlUseCustomMatching = yes
then return.
/* get the tDInvoiceStageDetails records */
find first tDInvoiceStageDetails where tDInvoiceStageDetails.tiDInvoiceId = tqDInvoiceByDebtorRef.tiDInvoice_ID no-error.
if available tDInvoiceStageDetails
then do:
create tInvoiceStageXref.
/* get the stage record from the invoice */
<Q-41 run DInvoiceStageByID (all) (Read) (NoCache)
(input tDInvoiceStageDetails.tiDInvoiceStageID, (DInvoiceStageID)
output dataset tqDInvoiceStageByID) in BDInvoice>
find first tqDInvoiceStageByID where
tqDInvoiceStageByID.tiDInvoiceStage_ID = tDInvoiceStageDetails.tiDInvoiceStageID
no-error.
if available tqDInvoiceStageByID
then do:
assign
vdStageBalanceTC = tqDInvoiceStageByID.tdDInvoiceStageAmountTC - tqDInvoiceStageByID.tdDInvoiceStageAmtAppliedTC
tInvoiceStageXref.tiDInvoiceStageID = tDInvoiceStageDetails.tiDInvoiceStageID
tInvoiceStageXref.tiDInvoiceID = tDInvoiceStageDetails.tiDInvoiceId.
/* if it's fully allocate set values to 0 */
if vdStageBalanceTC = 0
then do:
assign
tInvoiceStageXref.tdDDocInvoiceXrefStageAllocTC = 0.
tInvoiceStageXref.tdDDocInvoiceXrefStageDiscTC = 0.
end.
/* check if it's over allocated - only allocate upto the outstanding balance */
else if vdStageBalanceTC < tBankImpLineDet.BankImpLineAmountTC + tBankImpLineDet.BankImpLineDiscAmtTC - tBankImpLineDet.BankImpLineIntAmtTC
then do:
assign
tInvoiceStageXref.tdDDocInvoiceXrefStageAllocTC = vdStageBalanceTC.
tInvoiceStageXref.tdDDocInvoiceXrefStageDiscTC = tBankImpLineDet.BankImpLineDiscAmtTC.
end.
/* check if it's under allocated - don't allow discount */
else if vdStageBalanceTC > tBankImpLineDet.BankImpLineAmountTC + tBankImpLineDet.BankImpLineDiscAmtTC - tBankImpLineDet.BankImpLineIntAmtTC
then do:
assign
tInvoiceStageXref.tdDDocInvoiceXrefStageDiscTC = 0.
tInvoiceStageXref.tdDDocInvoiceXrefStageAllocTC = tBankImpLineDet.BankImpLineAmountTC + tInvoiceStageXref.tdDDocInvoiceXrefStageDiscTC - tBankImpLineDet.BankImpLineIntAmtTC.
end.
else do:
assign
tInvoiceStageXref.tdDDocInvoiceXrefStageDiscTC = tBankImpLineDet.BankImpLineDiscAmtTC
tInvoiceStageXref.tdDDocInvoiceXrefStageAllocTC = tBankImpLineDet.BankImpLineAmountTC + tInvoiceStageXref.tdDDocInvoiceXrefStageDiscTC - tBankImpLineDet.BankImpLineIntAmtTC.
end. /* else */
assign
tInvoiceStageXref.tdDDocInvoiceXrefStageAllocTC = <M-13 RoundAmount
(input tInvoiceStageXref.tdDDocInvoiceXrefStageAllocTC (idUnroundedAmount),
input ? (iiCurrencyID),
input tqDInvoiceByDebtorRef.tcCurrencyCode (icCurrencyCode)) in BBankImportLine>
tInvoiceStageXref.tdDDocInvoiceXrefStageDiscTC = <M-60 RoundAmount
(input tInvoiceStageXref.tdDDocInvoiceXrefStageDiscTC (idUnroundedAmount),
input ? (iiCurrencyID),
input tqDInvoiceByDebtorRef.tcCurrencyCode (icCurrencyCode)) in BBankImportLine>
odDiscountAmount = tInvoiceStageXref.tdDDocInvoiceXrefStageDiscTC
odInvoicePaymentAmount = tInvoiceStageXref.tdDDocInvoiceXrefStageAllocTC - odDiscountAmount.
end. /* if available*/
end. /* find first tDInvoiceStageDetails */