Description
Recalculate the cash report in all currencies. Calculate the balance amount and actual amounts have been split into other methods.
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program4/bcashreport.p)
/* Assign the error status to 'Unknown error' */
assign oiReturnStatus = -98.
<Q-30 run GLByCode (Start) in BGL >
<Q-32 run DInvoiceByControlGL (Start) in BDInvoice >
<Q-24 run CInvoiceMovementByDate (Start) in BCInvoice >
<Q-23 run CInvoiceByControlGL (Start) in BCInvoice >
<Q-33 run CInvoiceMovementByDate (Start) in BCInvoice >
for each tCashReport where
tCashReport.tc_Status <> 'D':U:
/************************************************************************************************/
/* Validate fields that would otherwise only be validated upon saving */
/* by (the Ancestor-Code of) ValidateComponent. */
/************************************************************************************************/
<M-28 run ValidateRecalculateParams (output viDivisionID (oiDivisionID),
output viFcReturnSuper (oiReturnStatus)) in BCashReport>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then next.
end.
assign viPeriod = (tCashReport.tiPeriodYear * 100) + tCashReport.tiPeriodPeriod.
/* Get the list of Interval Dates */
<M-26 run GenerateIntervalDates
(input tCashReport.tiPeriodYear (iiPeriodYear),
input tCashReport.tiPeriodPeriod (iiPeriodPeriod),
input tCashReport.CashReportDaysInterval (iiDaysInterval),
input tCashReport.CashReportNumberOfPeriods (iiNumberOfPeriods),
output vcIntervalDates (ocIntervalDates),
output vtPeriodEndDate (otPeriodEndDate),
output viFcReturnSuper (oiReturnStatus)) in BCashReport>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then next.
end.
assign vtLastIntervalDate = date(entry(tCashReport.CashReportNumberOfPeriods, vcIntervalDates, chr(2))).
assign viLastActualsSeq = 0.
if (tCashReport.CashReportActualsDate = ?)
then
assign vtLastPostingDate = vtPeriodEndDate.
else do:
assign vtLastPostingDate = tCashReport.CashReportActualsDate.
/* Determine last period to contain Actuals Amount. */
/* This the first period whose end date comes after the Actuals Date. */
do while viLastActualsSeq < tCashReport.CashReportNumberOfPeriods and
tCashReport.CashReportActualsDate >= date(entry(viLastActualsSeq + 1, vcIntervalDates, chr(2))):
assign viLastActualsSeq = viLastActualsSeq + 1.
end.
end.
for each tCashReportGL where
tCashReportGL.tc_Status <> 'D':U and
tCashReportGL.tc_ParentRowid = tCashReport.tc_Rowid:
assign tCashReportGL.CashReportGLIsAccount = tCashReportGL.tcAccount = {&CASHREPORTACCOUNT-ACC}
tCashReportGL.CashReportGLIsCumul = tCashReportGL.tcCumul = {&CASHREPORTCUMUL-CUMUL}.
if (tCashReportGL.CashReportGLIsAccount = false)
then assign vcGLTypeCode = ""
vlGLIsBalanceAccount = false.
else do:
<Q-48 run GLByCode (first) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input tCashReportGL.tcGLCode, (GLCode)
output dataset tqGLByCode) in BGL >
find tqGLByCode where
tqGLByCode.tcGLCode = tCashReportGL.tcGLCode
no-lock no-error.
if available(tqGLByCode)
then assign vcGLTypeCode = tqGLByCode.tcGLTypeCode
vlGLIsBalanceAccount = tqGLByCode.tlGLIsBalanceAccount.
else do:
assign vcCashReportMsg = subst(#T-29'GL account (&1) is not defined in the system.':200(868)t-29#, tCashReportGL.tcGLCode)
oiReturnStatus = -1.
<M-4 run SetMessage
(input trim(vcCashReportMsg) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'QADFIN-2832':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCashReport>
next.
end.
/********************************************************************/
/* Calculate the Amounts until the end of the Cut-Off Period. */
/********************************************************************/
assign vdBalanceLC = 0
vdBalanceTC = 0
vdBalanceCC = 0.
if tqGLByCode.tlGLIsDivisionAccount = false
then assign viGLDivisionID = 0.
else assign viGLDivisionID = viDivisionID.
/************************************************************************************/
/* For Balance Accounts (=including Debtor/Creditor Control + Banking Accounts) : */
/* Balance shown = account's total balance this year. */
/* */
/* For Profit&Loss Accounts (= 6- & 7-accounts) : */
/* Balance shown = account's movement in the Cut-Off Period. */
/* The user will enter percentages based on the movement in this period, */
/* not on the balance "so far" this year. */
/************************************************************************************/
/* This logic has been split into a new method due to the size contraints */
/* imposed on this editing control. */
<M-44 run RecalculateGLAmount
(input vlGLIsBalanceAccount (ilGLIsBalanceAccount),
input tqGLByCode.tiGL_ID (iiGLByCodeGL_ID),
input tqGLByCode.tlGLIsBalanceAccount (ilGLByCodeGLIsBalanceAccount),
input tCashReportGL.Currency_ID (iiCashReportGLCurrency_ID),
input tCashReport.tiPeriodYear (iiCashReportPeriodYear),
input viGLDivisionID (iiGLDivisionID),
input viPeriod (iiPeriod),
input-output vdBalanceLC (bdBalanceLC),
input-output vdBalanceTC (bdBalanceTC),
input-output vdBalanceCC (bdBalanceCC),
output viFcReturnSuper (oiReturnStatus)) in BCashReport>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then next.
end.
/* For Balance accounts, the Balance (DB/CR) reflects the effect on the Bank Account */
/* For P&L accounts, reverse the balance : Profit(CR) -> positive ; Loss(DB) -> negatieve */
if vlGLIsBalanceAccount
then do:
if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-LC}
then
assign tCashReportGL.CashReportGLAmountLC = vdBalanceLC.
else if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-TC}
then
assign tCashReportGL.CashReportGLAmountTC = vdBalanceTC.
else if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-CC}
then
assign tCashReportGL.CashReportGLAmountCC = vdBalanceCC.
end.
else do:
if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-LC}
then
assign tCashReportGL.CashReportGLAmountLC = vdBalanceLC * -1.
else if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-TC}
then
assign tCashReportGL.CashReportGLAmountTC = vdBalanceTC * -1.
else if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-CC}
then
assign tCashReportGL.CashReportGLAmountCC = vdBalanceCC * -1.
end.
end. /* if (tCashReportGL.CashReportGLIsAccount) */
/* Initialize GLLines. */
<M-50 run RecalculateInitializeGLLines
(input tCashReportGL.tc_Rowid (icCashReportGLRowid),
input tCashReportGL.CashReportGLCurrencyView (icCashReportGLCurrencyView),
input tCashReportGL.Currency_ID (iiCashReportGLCurrency_ID),
output viFcReturnSuper (oiReturnStatus)) in BCashReport>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then next.
end.
/****************************************/
/* Calculate the Actuals for this G/L */
/****************************************/
assign vdActualsLC = 0
vdActualsTC = 0
vdActualsCC = 0.
<M-45 run RecalculateGLActualAmounts
(input tCashReport.CashReportActualsDate (itCashReportActualsDate),
input tCashReport.Currency_ID (iiCashReportCurrency_ID),
input tCashReportGL.CashReportGLIsAccount (ilCashReportGLIsAccount),
input tCashReportGL.tc_Rowid (icCashReportGLRowid),
input tCashReportGL.CashReportGLCurrencyView (icCashReportGLCurrencyView),
input tCashReportGL.Currency_ID (iiCashReportGLCurrency_ID),
input tqGLByCode.tiGL_ID (iiGLByCodeGL_ID),
input viGLDivisionID (iiGLDivisionID),
input vtPeriodEndDate (itPeriodEndDate),
input viLastActualsSeq (iiLastActualsSeq),
input vlGLIsBalanceAccount (ilGLIsBalanceAccount),
input-output vdActualsLC (bdActualsLC),
input-output vdActualsTC (bdActualsTC),
input-output vdActualsCC (bdActualsCC),
output viFcReturnSuper (oiReturnStatus)) in BCashReport>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then next.
end.
/* For Balance accounts, the Balance (DB/CR) reflects the effect on the Bank Account */
/* For P&L accounts, reverse the balance : Profit(CR) -> positive ; Loss(DB) -> negatieve */
if vlGLIsBalanceAccount
then do:
if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-LC} then
assign tCashReportGL.CashReportGLActualAmountLC = vdActualsLC.
else if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-TC} then
assign tCashReportGL.CashReportGLActualAmountTC = vdActualsTC.
else if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-CC} then
tCashReportGL.CashReportGLActualAmountCC = vdActualsCC.
end.
else do:
if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-LC} then
assign tCashReportGL.CashReportGLActualAmountLC = vdActualsLC * -1.
else if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-TC} then
assign tCashReportGL.CashReportGLActualAmountTC = vdActualsTC * -1.
else if tCashReportGL.CashReportGLCurrencyView = {&CURRENCYTYPE-CC} then
assign tCashReportGL.CashReportGLActualAmountCC = vdActualsCC * -1.
end.
/****************************************************************************************/
/* Calculate the Amounts for the periods after the Actuals Periods */
/* The calculation is dependent on the type of G/L : Debtor/Creditor/All others */
/* For Debtor and Creditor control accounts, we determine the prospected payments for */
/* each interval based on the due dates of the open invoices. */
/****************************************************************************************/
case vcGLTypeCode:
when {&GLTYPECODE-DEBT}
then do:
/********************************************************************************************/
/* Get all the Debtor Invoices that were entered with the specified Debtor Control Account. */
/* Only invoices that were already entered by the ActualsDate and were also still open */
/* after the ActualsDate are taken into consideration. */
/* To further narrow the query, only invoices whose DueDate falls within the range of */
/* the forecast period are considered. */
/********************************************************************************************/
<M-51 run RecalculateGLTypeCodeDebtorAmounts
(input viGLDivisionID (iiGLDivisionID),
input tqGLByCode.tiGL_ID (iiGLByCodeGL_ID),
input vtLastPostingDate (itLastPostingDate),
input vtPeriodEndDate (itPeriodEndDate),
input vtLastIntervalDate (itLastIntervalDate),
input tCashReport.Currency_ID (iiCashReportCurrency_ID),
input tCashReportGL.tc_Rowid (icCashReportGLRowid),
input viLastActualsSeq (iiLastActualsSeq),
input tCashReportGL.CashReportGLCurrencyView (icCashReportGLCurrencyView),
input tCashReportGL.Currency_ID (iiCashReportGLCurrency_ID),
input tCashReport.tc_Rowid (icCashReportRowid),
input tCashReport.CashReportNumberOfPeriods (iiCashReportNumberOfPeriods),
input tCashReportGL.CashReportGLAmountLC (idCashReportGLAmountLC),
input tCashReportGL.CashReportGLAmountTC (idCashReportGLAmountTC),
input tCashReportGL.CashReportGLAmountCC (idCashReportGLAmountCC),
input tCashReportGL.CashReportGLIsCumul (ilCashReportGLIsCumul),
output viFcReturnSuper (oiReturnStatus)) in BCashReport>
end. /* when {&GLTYPECODE-DEBT} */
when {&GLTYPECODE-CRED}
then do:
/********************************************************************************************/
/* Get all the Creditor Invoices that were entered with the specified Debtor Control Account*/
/* Only invoices that were already entered by the ActualsDate and were also still open */
/* after the ActualsDate are taken into consideration. */
/* To further narrow the query, only invoices whose DueDate falls within the range of */
/* the forecast period are considered. */
/********************************************************************************************/
<M-52 run RecalculateGLTypeCodeCreditorAmounts
(input viGLDivisionID (iiGLDivisionID),
input tqGLByCode.tiGL_ID (iiGLByCodeGL_ID),
input vtLastPostingDate (itLastPostingDate),
input vtPeriodEndDate (itPeriodEndDate),
input vtLastIntervalDate (itLastIntervalDate),
input tCashReport.Currency_ID (iiCashReportCurrency_ID),
input tCashReportGL.tc_Rowid (icCashReportGLRowid),
input viLastActualsSeq (iiLastActualsSeq),
input tCashReportGL.CashReportGLCurrencyView (icCashReportGLCurrencyView),
input tCashReportGL.Currency_ID (iiCashReportGLCurrency_ID),
input tCashReport.tc_Rowid (icCashReportRowid),
input tCashReport.CashReportNumberOfPeriods (iiCashReportNumberOfPeriods),
input tCashReportGL.CashReportGLAmountLC (idCashReportGLAmountLC),
input tCashReportGL.CashReportGLAmountTC (idCashReportGLAmountTC),
input tCashReportGL.CashReportGLAmountCC (idCashReportGLAmountCC),
input tCashReportGL.CashReportGLIsCumul (ilCashReportGLIsCumul),
output viFcReturnSuper (oiReturnStatus)) in BCashReport>
end. /* when {&GLTYPECODE-CRED} */
otherwise
do:
/* Calculate the Amounts for the remaining periods (= from the one containing the ActualsDate onwards */
/* based on the Percentages the user entered for each of those periods. */
for each tCashReportGLLine where
tCashReportGLLine.tc_Status <> 'D':U and
tCashReportGLLine.tc_ParentRowid = tCashReportGL.tc_Rowid and
tCashReportGLLine.CashReportGLLineSeq > viLastActualsSeq and
tCashReportGLLine.CashReportGLLineCurrView = tCashReportGL.CashReportGLCurrencyView and
tCashReportGLLine.Currency_ID = tCashReportGL.Currency_ID:
assign tCashReportGLLine.CashReportGLLineLC = (tCashReportGL.CashReportGLAmountLC +
tCashReportGL.CashReportGLActualAmountLC +
tCashReportGL.CashReportGLCorrAmountLC)
* tCashReportGLLine.CashReportGLLinePerc / 100.
assign tCashReportGLLine.CashReportGLLineTC = (tCashReportGL.CashReportGLAmountTC +
tCashReportGL.CashReportGLActualAmountTC +
tCashReportGL.CashReportGLCorrAmountTC)
* tCashReportGLLine.CashReportGLLinePerc / 100.
assign tCashReportGLLine.CashReportGLLineCC = (tCashReportGL.CashReportGLAmountCC +
tCashReportGL.CashReportGLActualAmountCC +
tCashReportGL.CashReportGLCorrAmountCC)
* tCashReportGLLine.CashReportGLLinePerc / 100.
end. /* for each tCashReportGLLine */
if (tCashReportGL.CashReportGLIsCumul)
then do:
<M-7 run ConvertMovementsToBalance
(input tCashReportGL.tc_Rowid (icParentRowid),
input tCashReport.CashReportNumberOfPeriods (iiNumberOfPeriods),
input tCashReportGL.CashReportGLAmountLC (idStartBalanceLC),
input tCashReportGL.CashReportGLAmountTC (idStartBalanceTC),
input tCashReportGL.CashReportGLAmountCC (idStartBalanceCC),
output viFcReturnSuper (oiReturnStatus)) in BCashReport>
end.
end. /* otherwise */
end. /* case tqGLByCode.tcGLTypeCode: */
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then next.
end.
end. /* for each tCashReportGL */
end.
<Q-46 run GLByCode (Stop) in BGL >
<Q-41 run DInvoiceByControlGL (Stop) in BDInvoice >
<Q-40 run DInvoiceMovementByDate (Stop) in BDInvoice >
<Q-42 run CInvoiceByControlGL (Stop) in BCInvoice >
<Q-43 run CInvoiceMovementByDate (Stop) in BCInvoice >
/* If the procedure reaches its end correctly and no validation errors were encountered */
/* then assign the return status 'OK' */
if oiReturnStatus = -98 then
assign oiReturnStatus = 0.