Parameters
idInitiallyAllocatedWHTAmntTC | input | decimal | |
bdCInvoiceAmountWhtTC | input-output | decimal | |
bdCInvoiceBankToPayTC | input-output | decimal | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bpaymentselection.p)
/* ======================================================================================= *
* Method : CalculatePaySelLineWhtMultBanks *
* Description : This method calculates WHT amount, that can be allocated by this payment *
* This is needed in case, we have multiple bank numbers for this invoice *
* --------------------------------------------------------------------------------------- *
* Parameters : *
* ======================================================================================= */
MAIN_BLOCK:
do on error undo, throw:
/* Get all supplier invoice bank records of the supplier invoice */
<Q-7 run CInvoiceBankByCInvoiceID (all) (Read) (NoCache)
(input tPaySelLine.PaySelLineParentObject_ID, (CInvoiceId)
output dataset tqCInvoiceBankByCInvoiceID) in BCInvoice>
/* If there is only one bank number for the supplier invoice, nothing to do */
if can-find(tqCInvoiceBankByCInvoiceID where
tqCInvoiceBankByCInvoiceID.tiCInvoice_ID = tPaySelLine.PaySelLineParentObject_ID)
then leave MAIN_BLOCK.
/* Go through the CInvoice bank records and try to allocate the WHT from beggining */
for each tqCInvoiceBankByCInvoiceID where
tqCInvoiceBankByCInvoiceID.tiCInvoice_ID = tPaySelLine.PaySelLineParentObject_ID
by tqCInvoiceBankByCInvoiceID.tiCInvoiceBank_ID:
/* ==================================================================================== *
* If there is any WHT taxes in Initial status (Created by payment but not yet paid) *
* then these WHT taxes will be used in future for decreasing of the balance of the *
* CInvoiceBankToPayTC amount. An invoice movement will be created for this. *
* ==================================================================================== */
assign vdCInvoiceBankToPayTC = tqCInvoiceBankByCInvoiceID.tdCInvoiceBankToPayTC.
/* Decrease available balance about Init WHT tax */
if vdCInvoiceBankToPayTC >= 0
then assign vdAppliedInitWht = if idInitiallyAllocatedWHTAmntTC > vdCInvoiceBankToPayTC
then vdCInvoiceBankToPayTC
else idInitiallyAllocatedWHTAmntTC.
else assign vdAppliedInitWht = if idInitiallyAllocatedWHTAmntTC < vdCInvoiceBankToPayTC
then vdCInvoiceBankToPayTC
else idInitiallyAllocatedWHTAmntTC.
assign vdCInvoiceBankToPayTC = vdCInvoiceBankToPayTC - vdAppliedInitWht
idInitiallyAllocatedWHTAmntTC = idInitiallyAllocatedWHTAmntTC - vdAppliedInitWht.
if tqCInvoiceBankByCInvoiceID.tiBankNumber_ID = tPaySelLine.BankNumber_ID
then assign bdCInvoiceAmountWhtTC = bdCInvoiceAmountWhtTC - vdAppliedInitWht.
/* ==================================================================================== *
* WHT amount that can be applied till balance of the CInvoiceBant *
* ==================================================================================== */
if vdCInvoiceBankToPayTC >= 0
then assign vdAppliedWht = if bdCInvoiceAmountWhtTC > vdCInvoiceBankToPayTC
then vdCInvoiceBankToPayTC
else bdCInvoiceAmountWhtTC.
else assign vdAppliedWht = if bdCInvoiceAmountWhtTC < vdCInvoiceBankToPayTC
then vdCInvoiceBankToPayTC
else bdCInvoiceAmountWhtTC.
/* This is the CInvoiceBank record that will be paid */
if tqCInvoiceBankByCInvoiceID.tiBankNumber_ID = tPaySelLine.BankNumber_ID
then do:
assign bdCInvoiceAmountWhtTC = vdAppliedWht.
leave.
end.
/* This CInvoiceBank redord is not the one to be payed */
else assign bdCInvoiceAmountWhtTC = bdCInvoiceAmountWhtTC - vdAppliedWht.
end. /* for each tqCInvoiceBankByCInvoiceID where */
end. /* MAIN_BLOCK */