project QadFinancials > class BBankEntry > method AdditionalUpdatesAssignments
Description
AddtionalUpdatesAssignments; method that contains the assignments for a number of instance-fields
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program4/bbankentry.p)
/* ======================================================= */
/* Set default return-status */
/* ======================================================= */
assign oiReturnStatus = -98
viLocalReturn = 0.
MAIN_BLOCK:
do on error undo, leave:
/* ============================================================================= */
/* Set the status of the line based on the data of the allocations */
/* If the amount (line<->sum-of-allocs) differs then Allocated else NotAllocated */
/* Set the status of the header based on the status and data of the lines */
/* If all lines=ALLOC then header=ALLOC */
/* else if all line=UNALLOC then header=UNALLOC */
/* else header=PARTALLOC */
/* ============================================================================= */
assign vdTotalDebitTC = 0
vdTotalCreditTC = 0.
/* Go through all new-changed lines */
for each tBankState where
tBankState.tc_Status <> "D":U
no-lock,
each tBankStateLine where
tBankStateLine.tc_ParentRowid = tBankState.tc_Rowid and
(tBankStateLine.tc_Status = "N":U or
tBankStateLine.tc_Status = "C":U)
by tBankStateLine.BankStateLineNumber :
/* Reset totals */
assign vdTotalDebitTC = 0
vdTotalCreditTC = 0.
/* Get the journal entry balance only if you have a posting available */
if tBankStateLine.Posting_ID <> 0 and
tBankStateLine.Posting_ID <> ?
then do:
/* ===================================================================== */
/* Go through all allocations of the BE-Line and sum the posting-amounts */
/* Get the posting-amounts of the posting linked to the BE-Line */
/* Post the difference on the Bank-GL account */
/* ===================================================================== */
for each tBankStateAlloc where
tBankStateAlloc.tc_ParentRowid = tBankStateLine.tc_Rowid:
assign vdAmountTC = if tBankStateAlloc.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then vdAmountTC + tBankStateAlloc.BankStateAllocBankAmountTC - tBankStateAlloc.BankStateAllocBankDiscTC
else vdAmountTC - (tBankStateAlloc.BankStateAllocBankAmountTC - tBankStateAlloc.BankStateAllocBankDiscTC)
vdAmountLC = if tBankStateAlloc.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then vdAmountLC + tBankStateAlloc.BankStateAllocBankAmountLC - tBankStateAlloc.BankStateAllocBankDiscLC
else vdAmountLC - (tBankStateAlloc.BankStateAllocBankAmountLC - tBankStateAlloc.BankStateAllocBankDiscLC)
vdAmountCC = if tBankStateAlloc.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then vdAmountCC + tBankStateAlloc.tdBankStateAllocBankAmountCC - tBankStateAlloc.tdBankStateAllocBankDiscCC
else vdAmountCC - (tBankStateAlloc.tdBankStateAllocBankAmountCC - tBankStateAlloc.tdBankStateAllocBankDiscCC).
end. /* for each tbankstatealloc where */
<M-1 run GetJournalEntryBalance
(input tBankState.tcCurrencyCode (icBankCurrencyCode),
input tBankStateLine.Posting_ID (iiPostingId),
input tBankStateLine.BankStateLineValueDate (itBankStateLineValueDate),
input false (ilCloseJournalEntryInstance),
input tBankStateLine.BankStateLineAmountTC (idBankStateLineAmountTC),
input tBankStateLine.tdBankStateLineAmountLC (idBankStateLineAmountLC),
input vdAmountTC (idAllocatedAmountTC),
input vdAmountLC (idAllocatedAmountLC),
output vdTotalDebitTC (odPostingAmountDebitTC),
output vdTotalCreditTC (odPostingAmountCreditTC),
output vdDummy (odPostingAmountDebitLC),
output vdDummy (odPostingAmountCreditLC),
output vdDummy (odPostingAmountDebitCC),
output vdDummy (odPostingAmountCreditCC),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
end. /* if tBankStateLine.Posting_ID <> 0 and */
/* Go through all Allocations of the Line and compute the totals */
for each tBankStateAlloc where
tBankStateAlloc.tc_ParentRowid = tBankStateLine.tc_Rowid and
(tBankStateAlloc.tc_Status = "N":U or
tBankStateAlloc.tc_Status = "C":U):
if tBankStateAlloc.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
then assign vdTotalCreditTC = vdTotalCreditTC + <M-14 RoundAmount
(input tBankStateAlloc.BankStateAllocBankAmountTC (idUnroundedAmount),
input 0 (iiCurrencyID),
input tBankStateAlloc.tcCurrencyCode (icCurrencyCode)) in business>
vdTotalDebittc = vdTotalDebitTC + <M-15 RoundAmount
(input tBankStateAlloc.BankStateAllocBankDiscTC (idUnroundedAmount),
input 0 (iiCurrencyID),
input tBankStateAlloc.tcCurrencyCode (icCurrencyCode)) in business>.
else if tBankStateAlloc.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then assign vdTotalDebittC = vdTotalDebitTC + <M-16 RoundAmount
(input tBankStateAlloc.BankStateAllocBankAmountTC (idUnroundedAmount),
input 0 (iiCurrencyID),
input tBankStateAlloc.tcCurrencyCode (icCurrencyCode)) in business>
vdTotalCreditTC = vdTotalCreditTC + <M-17 RoundAmount
(input tBankStateAlloc.BankStateAllocBankDiscTC (idUnroundedAmount),
input 0 (iiCurrencyID),
input tBankStateAlloc.tcCurrencyCode (icCurrencyCode)) in business>.
end. /* for each tBankStateAlloc where */
assign tBankStateLine.BankStateLineAmountTC = <M-18 RoundAmount
(input tBankStateLine.BankStateLineAmountTC (idUnroundedAmount),
input 0 (iiCurrencyID),
input tBankState.tcCurrencyCode (icCurrencyCode)) in business>.
if tBankStateLine.BankStateLineStatus <> {&BANKSTATELINESTATUS-ALLOCPOST}
then /* Use absolute values so it works for DI and CI */
assign tBankStateLine.BankStateLineStatus = if tBankStateLine.CustomShort0 = 'CONVERSION':U /* needed by conversion programs - woa 8 aug 2007 */
then {&BANKSTATELINESTATUS-ALLOC}
else
if tBankStateLine.BankStateLineAmountTC = 0 or tBankStateLine.BankStateLineStatus = {&BANKSTATELINESTATUS-UNALLOC}
then {&BANKSTATELINESTATUS-UNALLOC}
else {&BANKSTATELINESTATUS-ALLOC}
tBankStateLine.CustomShort0 = if tBankStateLine.CustomShort0 = 'CONVERSION':U
then '':U
else tBankStateLine.CustomShort0
tBankStateLine.tc_Status = if tBankStateline.tc_Status = "":U
then "C":U
else tBankStateline.tc_Status.
end. /* for each tBankState, each tBankStateLine of */
/* ====================================================================================== */
/* At this place we 'calculate' the correct status of the BankState. For this we use the */
/* status of the BankStateLines, but we need to get them both from our instance as from */
/* the database. Reason for this is that the status of a bankline can be changed by */
/* multiple users at the same time. So we need to be sure we are using the correct status */
/* Note the optimistic lock was disabled for the BankStateStatus field */
/* ====================================================================================== */
for each tBankState where
tBankState.tc_Status <> "D":U and
tBankState.BankState_ID <> 0 and
tBankState.BankState_ID <> ? :
/* Initialiaxe flags */
assign vlUnallocatedLineFound = false.
vlAllocatedLineFound = false.
/* Read all BE-lines in the Database */
empty temp-table tqBankStateLinesByBankState.
if tBankState.tc_Status <> 'N'
then do :
<Q-22 run BankStateLinesByBankState (all) (Read) (NoCache)
(input ?, (CompanyId)
input tBankState.BankState_ID, (BankState_ID)
output dataset tqBankStateLinesByBankState) in BBankEntry>
end. /* if tBankState.tc_Status <> 'N' */
/* ======================================================================================= */
/* Check if there is a single unallocated lines - either in the instance, either in the db */
/* ======================================================================================= */
for each tBankStateLine where
tBankStateLine.tc_ParentRowid = tBankState.tc_Rowid and
tBankStateLine.BankStateLineStatus = {&BANKSTATELINESTATUS-UNALLOC} and
tBankStateLine.tc_status <> 'D':U :
if not can-find (tqBankStateLinesByBankState where
tqBankStateLinesByBankState.tiBankStateLine_ID = tBankStateLine.BankStateLine_ID and
tqBankStateLinesByBankState.tcBankStateLineStatus <> {&BANKSTATELINESTATUS-UNALLOC})
then do :
assign vlUnallocatedLineFound = true.
Leave.
end. /* if not can-find (tqBankStateLinesByBankState where */
end. /* for each tBankStateLine where */
if vlUnallocatedLineFound = false
then do :
for each tqBankStateLinesByBankState where
tqBankStateLinesByBankState.tiBankStateLine_ID = tBankStateLine.BankStateLine_ID and
tqBankStateLinesByBankState.tcBankStateLineStatus = {&BANKSTATELINESTATUS-UNALLOC} :
if can-find (tBankStateLine where
tBankStateLine.tc_ParentRowid = tBankState.tc_Rowid and
tBankStateLine.BankStateLine_ID = tqBankStateLinesByBankState.tiBankStateLine_ID and
tBankStateLine.tc_status = 'D':U)
then next.
if not can-find (tBankStateLine where
tBankStateLine.tc_ParentRowid = tBankState.tc_Rowid and
tBankStateLine.BankStateLine_ID = tqBankStateLinesByBankState.tiBankStateLine_ID and
tBankStateLine.BankStateLineStatus <> {&BANKSTATELINESTATUS-UNALLOC})
then do :
assign vlUnallocatedLineFound = true.
Leave.
end. /* if not can-find (tBankStateLine where */
end. /* for each tqBankStateLinesByBankState where */
end. /* if vlUnallocatedLineFound = false */
/* ======================================================================================= */
/* Check if there is a single allocated lines - either in the instance, either in the db */
/* ======================================================================================= */
for each tBankStateLine where
tBankStateLine.tc_ParentRowid = tBankState.tc_Rowid and
tBankStateLine.BankStateLineStatus <> {&BANKSTATELINESTATUS-UNALLOC} and
tBankStateLine.tc_status <> 'D':U :
assign vlAllocatedLineFound = true.
Leave.
end. /* for each tBankStateLine where */
if vlAllocatedLineFound = false
then do :
for each tqBankStateLinesByBankState where
tqBankStateLinesByBankState.tcBankStateLineStatus <> {&BANKSTATELINESTATUS-UNALLOC} :
assign vlAllocatedLineFound = true.
Leave.
end. /* for each tqBankStateLinesByBankState where */
end. /* if vlAllocatedLineFound = false */
/* ========================== */
/* Set status of BankingState */
/* ========================== */
assign vcBankStateStatus = if vlAllocatedLineFound = true
then if vlUnallocatedLineFound = true
then {&BANKSTATESTATUS-PARTALLOC}
else {&BANKSTATESTATUS-ALLOC}
else {&BANKSTATESTATUS-UNALLOC}.
if tBankState.BankStateStatus <> vcBankStateStatus
then assign tBankState.BankStateStatus = vcBankStateStatus
tBankState.tc_Status = if tBankState.tc_Status = "":U
then "C":U
else tBankState.tc_Status.
end. /* for each tBankState where */
end. /* MAIN_BLOCK */
/* ========================================================================================================= */
/* Normally we would here close BJournalEntry but we will not do it for performance */
/* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it. */
/* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the */
/* appserver that is executed after each call to the appserver */
/* ========================================================================================================= */
/* ================================================================================= *
* Error handling *
* ================================================================================= */
assign oiReturnStatus = viLocalReturn.