project QadFinancials > class BBankEntry > method GetJournalEntryBalance
Description
Get the balance of the journal entry
Parameters
icBankCurrencyCode | input | character | Bank Currency Code |
iiPostingId | input | integer | Posting ID |
itBankStateLineValueDate | input | date | Value date of bank state line |
ilCloseJournalEntryInstance | input | logical | CloseJournalEntryInstance |
idBankStateLineAmountTC | input | decimal | |
idBankStateLineAmountLC | input | decimal | |
idAllocatedAmountTC | input | decimal | |
idAllocatedAmountLC | input | decimal | |
odPostingAmountDebitTC | output | decimal | Debit Posting Amount in TC |
odPostingAmountCreditTC | output | decimal | Credit Posting Amount in TC |
odPostingAmountDebitLC | output | decimal | Debit Posting Amount in LC |
odPostingAmountCreditLC | output | decimal | Credit Posting Amount in LC |
odPostingAmountDebitCC | output | decimal | |
odPostingAmountCreditCC | output | decimal | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bbankentry.p)
/* =========================================================== *
* Error handling *
* =========================================================== */
assign oiReturnStatus = -98
viLocalReturn = 0.
MAIN_BLOCK:
do on error undo, leave:
assign vcExchangeRateType = <M-20 GetExchangeRateType () in BBankEntry>.
/* ================================================= */
/* Check whether the JE-Instance was already started */
/* ================================================= */
if viBJournalEntryBEID = 0 or
viBJournalEntryBEID = ?
then do:
assign vcMessage = trim(#T-8'System error: the Journal Entry component was not started. Unable to retrieve data from it.':150(361)T-8#).
<M-7 run SetMessage
(input vcMessage (icMessage),
input '':u (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-1944':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end. /* if viBJournalEntryBEID = 0 or */
/* ========================================== */
/* Open the BJE-instance when not yet opened */
/* ========================================== */
if vhBJournalEntryBEInst = ? or
valid-handle(vhBJournalEntryBEInst) <> true
then do :
<I-2 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
end. /* if vhBJournalEntryBEInst = ? or */
/* ============================================ */
/* get the posting amounts of the journal entry */
/* ============================================ */
<M-3 run GetPostingAmount
(input iiPostingId (iiPostingId),
output odPostingAmountDebitLC (odPostingAmountDebitLC),
output odPostingAmountCreditLC (odPostingAmountCreditLC),
output odPostingAmountCreditTC (odPostingAmountCreditTC),
output odPostingAmountCreditCC (odPostingAmountCreditCC),
output odPostingAmountDebitTC (odPostingAmountDebitTC),
output odPostingAmountDebitCC (odPostingAmountDebitCC),
output vcCurrencyCode (ocCurrencyCode),
output viExternalError (oiReturnStatus)) in BJournalEntry>
/* ============================================ */
/* Check for errors in the call to BJE */
/* ============================================ */
if viExternalError <> 0 then assign oiReturnStatus = viExternalError.
if viExternalError < 0
then do:
<I-10 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
assign vcMessage = trim(substitute(#T-9'An error occurred when retrieving the posting balance of the journal entry: &1.':150(362)T-9#,string(viFcReturnSuper))).
<M-5 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-828':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
assign viLocalReturn = viExternalError.
leave MAIN_BLOCK.
end. /* if viExternalError < 0 */
/* ============================================ */
/* close the journal entry instance when needed */
/* ============================================ */
if ilCloseJournalEntryInstance
then do:
<I-12 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
end.
/* ============================================ */
/* Get posted amount */
/* ============================================ */
/* If posting was created in the same currency as banking entry - we have values */
if icBankCurrencyCode = vcCurrencyCode
then leave MAIN_BLOCK.
/* Try to calculate TC based on the expected LC */
assign vdExpectedTC = idBankStateLineAmountTC + idAllocatedAmountTC
vdExpectedLC = idBankStateLineAmountLC + idAllocatedAmountLC.
assign vdBalanceLC = odPostingAmountCreditLC - odPostingAmountDebitLC.
if (vdBalanceLC < 0 and vdBalanceLC = vdExpectedLC)
then do:
assign odPostingAmountDebitTC = abs(vdExpectedTC)
odPostingAmountCreditTC = 0.
leave MAIN_BLOCK.
end.
else if (vdBalanceLC > 0 and vdBalanceLC = vdExpectedLC)
then do:
assign odPostingAmountCreditTC = vdExpectedTC
odPostingAmountDebitTC = 0.
leave MAIN_BLOCK.
end.
/* Calculate TC from LC using the exchange rate */
if icBankCurrencyCode <> vcCompanyLC
then do:
<M-26 run GetExchangeRate
(input viCompanyId (iiCompanyID),
input viCompanyLCId (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input ? (iiToCurrencyID),
input icBankCurrencyCode (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input vcExchangeRateType (icExchangeRateTypeCode),
input itBankStateLineValueDate (itValidityDate),
output vdExchangeRate (odExchangeRate),
output vdExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
assign odPostingAmountCreditTC = <M-80 RoundAmount
(input odPostingAmountCreditLC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input 0 (iiCurrencyID),
input icBankCurrencyCode (icCurrencyCode)) in business>
odPostingAmountDebitTC = <M-62 RoundAmount
(input odPostingAmountDebitLC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input 0 (iiCurrencyID),
input icBankCurrencyCode (icCurrencyCode)) in business>.
end. /* if icBankCurrencyCode <> vcCompanyLC */
else assign odPostingAmountCreditTC = odPostingAmountCreditLC
odPostingAmountDebitTC = odPostingAmountDebitLC.
end. /* MAIN_BLOCK */
/* ======================================================================== *
* Error handling *
* ======================================================================== */
assign oiReturnStatus = viLocalReturn.