project QadFinancials > class BPaymentSelection > method GetToPayObjectsForCInvoiceWhtMultBanks
Description
This method calculates WHT amount, that can be allocated by this payment. This is needed in case, we have multiple bank numbers for one supplier invoice.
Parameters
idInitiallyAllocatedWHTAmntTC | input | decimal | |
bdCInvoiceAmountWhtTC | input-output | decimal | Wht amount that can be allocated by the payment. At the beggining there is total pending Wht amount of the invoice. After execution of this procedure, there is assigned a WHT amount that can be allocated by this CInvoiceBank record. |
bdCInvoiceBankToPayTC | input-output | decimal | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bpaymentselection.p)
/* ======================================================================================================== *
* Method : GetToPayObjectsForCInvoiceWhtMultBanks *
* Description: This method calculates WHT amount, that can be allocated by this payment. This is needed in *
* case, we have multiple bank numbers for one supplier invoice. *
* Parameters : *
* ======================================================================================================== */
/* Get all supplier invoice bank records of the supplier invoice */
if not can-find(first tqCInvoiceBankByCInvoiceID where
tqCInvoiceBankByCInvoiceID.tiCInvoice_ID = tqCInvoiceBankForPaymentV01.tiCInvoice_ID)
then do:
<Q-62 run CInvoiceBankByCInvoiceID (all) (Read) (NoCache)
(input tqCInvoiceBankForPaymentV01.tiCInvoice_ID, (CInvoiceId)
output dataset tqCInvoiceBankByCInvoiceID) in BCInvoice>
end.
/* Go through the CInvoice bank records and try to allocate the WHT from beggining */
for each tqCInvoiceBankByCInvoiceID where
tqCInvoiceBankByCInvoiceID.tiCInvoice_ID = tqCInvoiceBankForPaymentV01.tiCInvoice_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.
/* ==================================================================================== *
* 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 tqCInvoiceBankForPaymentV01.tiCInvoiceBank_ID = tqCInvoiceBankByCInvoiceID.tiCInvoiceBank_ID
then do:
assign bdCInvoiceAmountWhtTC = vdAppliedWht
bdCInvoiceBankToPayTC = bdCInvoiceBankToPayTC - vdAppliedInitWht.
leave.
end.
/* This CInvoiceBank redord is not the one to be payed */
else assign bdCInvoiceAmountWhtTC = bdCInvoiceAmountWhtTC - vdAppliedWht.
end.