project QadFinancials > class BBudget > method CalculateBudgetWBS
Description
This submethod of Method Calculate is to fill some calculated field in the BudgetWBS based on the actual and commitments.
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/bbudget.p)
/* ========================================================================================= */
/* Fill some calculated field in the BudgetWBS based on the actual and commitments */
/* ========================================================================================= */
for each tBudget,
each tBudgetWBS where tBudgetWBS.tc_ParentRowid = tBudget.tc_Rowid:
assign tBudgetWBS.tcBudgetWBSSeqStr = string(tBudgetWBS.BudgetWBSSeq, "999999999999999999999999999999999999999999999999").
assign tBudgetWBS.BudgetWBSSeq = 0.
end.
/* ============================================================ */
/* Return in case this public data-item is not enabled for this */
/* ============================================================ */
if vlShowBudgetWBSActualCommitTC <> true
then Return.
/* ====================== */
/* Go through all budgets */
/* ====================== */
<Q-2 run BudgetLinkByBudgetPerWBS (Start) in BBudgetLink >
<Q-9 run ReportPeriodByAllInfo (Start) in BReportPeriod >
<Q-12 run BudgetLinkActualByBudgetIdDate (Start) in BBudgetLinkActual >
<Q-13 run BudgetLinkCommitByBudgetIdDate (Start) in BBudgetLinkCommitment >
for each tBudget where
tBudget.tc_Status <> "D":U :
if tBudget.BudgetForecastType = {&BUDGETFORECASTTYPE-LTE}
Then do:
/* ======================================================= */
/* Get all Commit- and Actual amounts for the whole budget */
/* ======================================================= */
<Q-1 run BudgetLinkByBudgetPerWBS (all) (Read) (NoCache)
(input ?, (BudgetLinkID)
input tBudget.Budget_ID, (BudgetID)
input ?, (BudgetWBSID)
input ?, (FromBudgetPeriodID)
input ?, (ToBudgetPeriodID)
output dataset tqBudgetLinkByBudgetPerWBS) in BBudgetLink >
/* ==================================================================================== */
/* Raise the calculated fields in the WBS for every entry in tqBudgetLinkByBudgetPerWBS */
/* ==================================================================================== */
for each tqBudgetLinkByBudgetPerWBS where
tqBudgetLinkByBudgetPerWBS.tiBudget_ID = tBudget.Budget_ID,
each tBudgetWBS where
tBudgetWBS.tc_ParentRowid = tBudget.tc_Rowid and
tBudgetWBS.BudgetWBS_ID = tqBudgetLinkByBudgetPerWBS.tiBudgetWBS_ID and
tBudgetWBS.tc_Status <> "D":U :
assign tBudgetWBS.tdBudgetWBSActualTC = tBudgetWBS.tdBudgetWBSActualTC + tqBudgetLinkByBudgetPerWBS.tdBudgetLinkActualTC - tqBudgetLinkByBudgetPerWBS.tdBudgetLinkActualSalesTC
tBudgetWBS.tdBudgetWBSCommitTC = tBudgetWBS.tdBudgetWBSCommitTC + tqBudgetLinkByBudgetPerWBS.tdBudgetLinkCommitTC.
end. /* for each tqBudgetLinkByBudgetPerWBS where */
end. /* if tBudget.BudgetForecastType = {&BUDGETFORECASTTYPE-LTE} */
else do:
find first tBudgetVersion where
tBudgetVersion.tc_ParentRowid = tBudget.tc_ParentRowid and
tBudgetVersion.BudgetVersionIsActive = true and
tBudgetVersion.tc_Status <> "D":U
no-lock no-error.
If not available tBudgetVersion
then next.
<Q-7 run ReportPeriodByAllInfo (all) (Read) (NoCache)
(input tBudgetVersion.ReportPeriod_ID, (ReportPeriodID)
input ?, (ReportPeriodYear)
input ?, (ReportPeriodPeriod)
input ?, (ReportPeriodStartDate)
input ?, (ReportPeriodEndDate)
input ?, (ReportPeriodIsReported)
output dataset tqReportPeriodByAllInfo) in BReportPeriod >
find tqReportPeriodByAllInfo where
tqReportPeriodByAllInfo.tiReportPeriod_ID = tBudgetVersion.ReportPeriod_ID
no-lock no-error.
if not available tqReportPeriodByAllInfo
then next.
/* Get the Actual amounts for this budget */
<Q-10 run BudgetLinkActualByBudgetIdDate (all) (Read) (NoCache)
(input ?, (CompanyId)
input tBudget.Budget_ID, (BudgetId)
input tqReportPeriodByAllInfo.ttReportPeriodEndDate, (BudgetLinkActualDate)
output dataset tqBudgetLinkActualByBudgetIdDate) in BBudgetLinkActual >
for each tqBudgetLinkActualByBudgetIdDate where
tqBudgetLinkActualByBudgetIdDate.tiBudget_ID = tBudget.Budget_ID,
each tBudgetWBS where
tBudgetWBS.tc_ParentRowid = tBudget.tc_Rowid and
tBudgetWBS.BudgetWBS_ID = tqBudgetLinkActualByBudgetIdDate.tiBudgetWBS_ID and
tBudgetWBS.tc_Status <> "D":U :
assign tBudgetWBS.tdBudgetWBSActualTC = tBudgetWBS.tdBudgetWBSActualTC + tqBudgetLinkActualByBudgetIdDate.tdBudgetLinkActualTC - tqBudgetLinkActualByBudgetIdDate.tdBudgetLinkActualSalesTC.
end. /* for each tqBudgetLinkActualByBudgetIdDate where */
/* Get the Commit amounts for this budget */
<Q-11 run BudgetLinkCommitByBudgetIdDate (all) (Read) (NoCache)
(input ?, (CompanyId)
input tBudget.Budget_ID, (BudgetId)
input tqReportPeriodByAllInfo.ttReportPeriodEndDate, (BudgetLinkCommitDate)
output dataset tqBudgetLinkCommitByBudgetIdDate) in BBudgetLinkCommitment >
for each tqBudgetLinkCommitByBudgetIdDate where
tqBudgetLinkCommitByBudgetIdDate.tiBudget_ID = tBudget.Budget_ID,
each tBudgetWBS where
tBudgetWBS.tc_ParentRowid = tBudget.tc_Rowid and
tBudgetWBS.BudgetWBS_ID = tqBudgetLinkCommitByBudgetIdDate.tiBudgetWBS_ID and
tBudgetWBS.tc_Status <> "D":U :
assign tBudgetWBS.tdBudgetWBSCommitTC = tBudgetWBS.tdBudgetWBSCommitTC + tqBudgetLinkCommitByBudgetIdDate.tdBudgetLinkCommitTC.
end. /* for each tqBudgetLinkCommitByBudgetIdDate where */
end. /* NOT if tBudget.BudgetForecastType = {&BUDGETFORECASTTYPE-LTE} */
/* ===================================================================================================== */
/* Go through budgetWBSF and Rollup the Commitments and the Actuals in table tBudgetWBS */
/* Involved fields; tdBudgetWBSActualTC and tdBudgetWBSCommitTC */
/* These fields are only filled in on the lowest nodes in the tree so their values should be propagated */
/* to all parent-nodes in the tree. We will first re-initialise all these fields for the nodes that have */
/* childs and then we will propagete the values of the nodes wihtou childs to allothers */
/* ===================================================================================================== */
for each tBudgetWBS where
tBudgetWBS.Budget_ID = tBudget.Budget_ID :
if can-find (first btBudgetWBS where
btBudgetWBS.ParentBudgetWBS_ID = tBudgetWBS.BudgetWBS_ID)
then assign tBudgetWBS.tdBudgetWBSActualTC = 0
tBudgetWBS.tdBudgetWBSCommitTC = 0.
end. /* for each tBudgetWBS where */
for each tBudgetWBS where
tBudgetWBS.Budget_ID = tBudget.Budget_ID :
if can-find (first btBudgetWBS where
btBudgetWBS.ParentBudgetWBS_ID = tBudgetWBS.BudgetWBS_ID)
then next.
assign viParentBudgetWBSID = tBudgetWBS.ParentBudgetWBS_ID.
repeat :
find btBudgetWBS where
btBudgetWBS.BudgetWBS_ID = viParentBudgetWBSID
no-error.
if not available btBudgetWBS
then leave.
assign viParentBudgetWBSID = btBudgetWBS.ParentBudgetWBS_ID
btBudgetWBS.tdBudgetWBSActualTC = btBudgetWBS.tdBudgetWBSActualTC + tBudgetWBS.tdBudgetWBSActualTC
btBudgetWBS.tdBudgetWBSCommitTC = btBudgetWBS.tdBudgetWBSCommitTC + tBudgetWBS.tdBudgetWBSCommitTC.
if viParentBudgetWBSID = 0 or
viParentBudgetWBSID = ?
then leave.
end. /* repeat */
end. /* for each tBudgetWBS where */
end. /* for each tBudget where */
<Q-3 run BudgetLinkByBudgetPerWBS (Stop) in BBudgetLink >
<Q-8 run ReportPeriodByAllInfo (Stop) in BReportPeriod >
<Q-14 run BudgetLinkActualByBudgetIdDate (Stop) in BBudgetLinkActual >
<Q-15 run BudgetLinkCommitByBudgetIdDate (Stop) in BBudgetLinkCommitment >