project QadFinancials > class BBudget > method BudgetWBSInsert
Description
This method will create a single budgetWBS-record based on the input informationand return temp-tables that contain the newly created records.
Parameters
icBudgetTcRowid | input | character | Budget; BudgetTcRowid |
icBudgetWBSFDSCode | input | character | BudgetWBSFDSCode; optional value for field tBudgetWBSFDSCode |
icBudgetWBSFDSList | input | character | BudgetWBSFDSList; optional value for field tBudgetWBSFDSList |
icBudgetWBSTcRowid | input | character | BudgetWBSTcRowid; tc_rowid of the current node you are on |
icNewBudgetWBSCode | input | character | BudgetWBSCode; Code of the new WBS-node |
iiNewBudgetWBSLineNumber | input | integer | NewBudgetWBSLineNumber |
tNewBudgetVersionFigure | output | temp-table | Temp-table containing the new BudgetVersionFigure-records |
tNewBudgetVersionGLFig | output | temp-table | Temp-table containing the new BudgetVersionGLFig-records |
tNewBudgetWBS | output | temp-table | Temp-table containing the new BudgetWBS-records |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program7/bbudget.p)
/* ==================================================================================================== */
/* Replace unknown values // Check existance of the tBudget record and the tBudgetWBS rec (conditional) */
/* Validation; when starting from the root-node it is not possible to create a node on the same level */
/* ==================================================================================================== */
if icBudgetWBSTcRowid = ?
then assign icBudgetWBSTcRowid = "":U.
if icNewBudgetWBSCode = ? or icNewBudgetWBSCode = "":U
then assign icNewBudgetWBSCode = trim(#T-44'New Topic':15(579)T-44#).
if icBudgetTcRowid = "":U or icBudgetTcRowid = ?
then do :
assign oiReturnStatus = -3
vcMessage = trim(#T-40'You must enter the budget identification (row ID) for the creation of budget topics.':255(535)T-40#).
<M-27 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-674842':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
Return.
end. /* if icBudgetTcRowid = ? or */
else do :
find tBudget where
tBudget.tc_Rowid = icBudgetTcRowid
no-lock no-error.
if not available tBudget
then do :
assign oiReturnStatus = -3
vcMessage = trim(substitute(#T-18'Cannot find the budget based on its row ID (&1).':255(448)T-18#,string(icBudgetTcRowid))).
<M-12 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-843055':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
Return.
end. /* if not available tBudget */
end. /* not if iiBudgetID = 0 or */
if icBudgetWBSTcRowid = "":U
then do :
assign oiReturnStatus = -3
vcMessage = trim(#T-10'You cannot create a budget WBS topic on the same level as the ROOT node.':255(580)T-10#).
<M-49 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-413214':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
Return.
end. /* if icBudgetWBSTcRowid = 0 or icBudgetWBSTcRowid = ? */
if icBudgetWBSTcRowid <> "":U
then do :
find tBudgetWBS where
tBudgetWBS.tc_ParentRowid = tBudget.tc_Rowid and
tBudgetWBS.tc_Rowid = icBudgetWBSTcRowid and
tBudgetWBS.tc_Status <> "D":U
no-lock no-error.
if not available tBudgetWBS
then do :
assign oiReturnStatus = -3
vcMessage = trim(substitute(#T-77'Cannot find the current budget WBS topic based on its row ID &1.':255(450)T-77#,string(icBudgetWBSTcRowid))).
<M-86 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-573273':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
Return.
end. /* if not available tBudgetWBS */
end. /* if icBudgetWBSTcRowid <> "":U */
/* ==================================================== */
/* No action allowed if the budget is not yet validated */
/* ==================================================== */
if tBudget.BudgetStatus = {&BUDGETSTATUS-INITIAL}
then do :
assign oiReturnStatus = -3
vcMessage = trim(#T-24'You must validate the budget structure before maintaining the WBS.':255(451)T-24#).
<M-36 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-254960':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
Return.
end. /* if tBudget.BudgetStatus = {&BUDGETSTATUS-INITIAL} */
/* ======================================================================================================== */
/* To easy the following of this method-code we make sure that viParentBudgetWBSID and viParentBudgetWBSSeq */
/* always points to the node wherefor we want to create a child (as if ilCreateChildOfCurrentWBSID = true) */
/* When both these data-items contain a value the tBudgetWBS should also point to the parent of the new one */
/* ======================================================================================================== */
/* Get the WBSrecord based on the input */
find bBudgetWBS where
bBudgetWBS.tc_ParentRowid = tBudget.tc_Rowid and
bBudgetWBS.tc_Rowid = icBudgetWBSTcRowid and
bBudgetWBS.tc_Status <> "D":U
no-lock no-error. /* no error-check needed; already done before this */
if available bBudgetWBS
then assign viBudgetWBSID = bBudgetWBS.BudgetWBS_ID.
/* Get the parent of the WBSrecord based on the previous found WBSrecord */
find tBudgetWBS where
tBudgetWBS.tc_ParentRowid = tBudget.tc_Rowid and
tBudgetWBS.BudgetWBS_ID = bBudgetWBS.ParentBudgetWBS_ID and
tBudgetWBS.tc_Status <> "D":U
no-lock no-error.
if available tBudgetWBS
then assign viParentBudgetWBSID = tBudgetWBS.BudgetWBS_ID
vdParentBudgetWBSSeq = tBudgetWBS.BudgetWBSSeq.
else assign viParentBudgetWBSID = 0
vdParentBudgetWBSSeq = 0.
/* =================================================== */
/* Find out the FDS information for the new WBS-record */
/* =================================================== */
if available tBudgetWBS /* tBudgetWBS points to the parent of the new node */
then do :
find tBudgetFDS where
tBudgetFDS.tc_ParentRowid = tBudget.tc_Rowid and
tBudgetFDS.BudgetFDSSeq = tBudgetWBS.BudgetFDSSeq + 1 and
tBudgetFDS.tc_Status <> "D":U
no-error.
if not available tBudgetFDS
then do :
assign oiReturnStatus = -3
vcMessage = trim(substitute(#T-4'The system cannot create a child node for the current budget WBS topic because it is unable to find level &1 of the budget COA.':255(581)T-4#,string(tBudgetWBS.BudgetFDSSeq + 1))).
<M-33 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-87236':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
Return.
end. /* if not available tBudgetFDS */
assign viNewRecordFDSID = tBudgetFDS.BudgetFDS_ID
vcNewRecordFDSType = tBudgetFDS.BudgetFDSType
viNewRecordFDSSeq = tBudgetFDS.BudgetFDSSeq.
end. /* if ilCreateChildOfCurrentWBSID = true */
else do :
find tBudgetFDS where
tBudgetFDS.tc_ParentRowid = tBudget.tc_Rowid and
tBudgetFDS.BudgetFDSSeq = 1 and
tBudgetFDS.tc_Status <> "D":U
no-error.
if not available tBudgetFDS
then do :
assign oiReturnStatus = -3
vcMessage = trim(#T-92'The system cannot create a root budget WBS topic because it cannot find the first level of the budget COA.':255(582)T-92#).
<M-82 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-870836':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
Return.
end. /* if not available tBudgetFDS */
assign viNewRecordFDSID = tBudgetFDS.BudgetFDS_ID
vcNewRecordFDSType = tBudgetFDS.BudgetFDSType
viNewRecordFDSSeq = tBudgetFDS.BudgetFDSSeq.
end. /* not if available tBudgetWBS */
/* ========================================================================== */
/* Reset the output temp-table */
/* ========================================================================== */
empty temp-table tNewBudgetWBS.
empty temp-table tNewBudgetVersionFigure.
empty temp-table tNewBudgetVersionGLFig.
/* ====================================================================================== */
/* Define the SafStructure and the SafConcept in case this is a SafType and it is not the */
/* highest SafLevel. If so, then the SafStructure it taken from the highest level and the */
/* concept is taken from the SafStructure level base on the level within the WBS-tree. */
/* ====================================================================================== */
if vcNewRecordFDSType = {&BUDGETFDSTYPE-SAF} and /* new node is of type SAF */
available(tBudgetWBS) and /* a parent-node exists */
(tBudgetWBS.BudgetFDSType = {&BUDGETFDSTYPE-SAF} or
tBudgetWBS.BudgetFDSType = {&BUDGETFDSTYPE-TOTAL}) /* the parent-code is of type SAF/Total */
then SAFSETTINGSBLOCK : DO :
/* Get the highest SAF-parent; at the end bBudgetWBS contains the highest saf-level */
assign viSAFCyclingBudgetWBSID = tBudgetWBS.BudgetWBS_ID
viSAFCyclingBudgetWBSSAFID = 0
viSAFCyclingCounter = 1.
repeat :
find first bBudgetWBS where
bBudgetWBS.tc_ParentRowid = tBudget.tc_Rowid and
bBudgetWBS.BudgetWBS_ID = viSAFCyclingBudgetWBSID and
bBudgetWBS.tc_Status <> "D":U and
(bBudgetWBS.BudgetFDSType = {&BUDGETFDSTYPE-SAF} or
bBudgetWBS.BudgetFDSType = {&BUDGETFDSTYPE-TOTAL})
no-lock no-error.
if available bBudgetWBS
then do :
assign viSAFCyclingBudgetWBSID = bBudgetWBS.ParentBudgetWBS_ID.
if bBudgetWBS.BudgetFDSType = {&BUDGETFDSTYPE-SAF}
then assign viSAFCyclingBudgetWBSSAFID = bBudgetWBS.BudgetWBS_ID
viSAFCyclingCounter = viSAFCyclingCounter + 1.
end. /* if available bBudgetWBS */
else leave.
end. /* repeat */
if viSAFCyclingBudgetWBSSAFID = 0
then leave SAFSETTINGSBLOCK.
find bBudgetWBS where
bBudgetWBS.tc_ParentRowid = tBudget.tc_Rowid and
bBudgetWBS.BudgetWBS_ID = viSAFCyclingBudgetWBSSAFID and
bBudgetWBS.tc_Status <> "D":U
no-lock no-error.
if not available bBudgetWBS or
bBudgetWBS.SafStructure_ID = 0 or
bBudgetWBS.SafStructure_ID = ?
then leave SAFSETTINGSBLOCK.
/* Get the safstructure of the tBudgetWBS record */
<Q-56 run SafConceptCodeByLine (all) (Read) (NoCache)
(input bBudgetWBS.SafStructure_ID, (SafStructure_ID)
input viSAFCyclingCounter, (SafStructureLineNumber)
input ?, (SafStructureCode)
output dataset tqSafConceptCodeByLine) in BSafStructure >
find first tqSafConceptCodeByLine
no-lock no-error.
if not available tqSafConceptCodeByLine
then do :
assign oiReturnStatus = -3
vcMessage = trim(substitute(#T-79'Cannot define level &1 of the SAF structure &2.':255(583)T-79#,string(viSAFCyclingCounter),string(bBudgetWBS.SafStructure_ID))).
<M-87 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-586217':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
Return.
end. /* if not av. tqSafConceptCodeByLine */
assign viNewRecordSafStructureID = bBudgetWBS.SafStructure_ID
vcNewRecordSafStructureCode = bBudgetWBS.tcSafStructureCode
viNewRecordSafConceptID = tqSafConceptCodeByLine.tiSafConcept_ID
vcNewRecordSafConceptCode = tqSafConceptCodeByLine.tcSafConceptCode.
end. /* if vcNewRecordFDSType = {&BUDGETFDSTYPE-SAF} */
/* ================================================================================================ */
/* Calculate the WBS sequence for new record: */
/* - When parent = root-node then use a fixed jump */
/* - Otherwise: take the average of the highest child and the next WBS on the same or higher level */
/* ================================================================================================ */
<M-93 run BudgetWBSInsertAdjustSequence
(input icBudgetTcRowid (icBudgetTcRowid),
input viBudgetWBSID (iiBudgetWBSID),
output vcNewRecordWBSSeq (ocNewRecordWBSSeq),
input viParentBudgetWBSID (iiParentBudgetWBSID),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
if viFcReturnSuper <> 0
then do :
assign oiReturnStatus = viFcReturnSuper
vcMessage = trim(#T-11'An internal error has occurred while calculating the sequence of the new node.':255(584)T-11#) + chr(10) +
trim(substitute(#T-47'Parent node ID: &1.':255(585)T-47#,string(viParentBudgetWBSID))) + chr(10) +
trim(substitute(#T-55'The COA sequence of the new node is &1.':255(586)T-55#,string(viNewRecordFDSSeq))) + chr(10) +
trim(substitute(#T-74'Return Status: &1.':255(587)T-74#,string(oiReturnStatus))).
<M-89 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-324239':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
Return.
end. /* if viFcReturnSuper <> 0 */
/* =========================================================== */
/* Create the new WBS-record and a corresponding output record */
/* =========================================================== */
<M-78 run AddDetailLine
(input 'BudgetWBS':U (icTable),
input tBudget.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
if viFcReturnSuper < 0
then do :
assign oiReturnStatus = viFcReturnSuper.
return.
end. /* if viFcReturnSuper < 0 */
assign tBudgetWBS.BudgetFDS_ID = viNewRecordFDSID
tBudgetWBS.BudgetFDSType = vcNewRecordFDSType
tBudgetWBS.BudgetFDSSeq = viNewRecordFDSSeq
tBudgetWBS.SafStructure_ID = viNewRecordSafStructureID
tBudgetWBS.SafConcept_ID = viNewRecordSafConceptID
tBudgetWBS.tcSafStructureCode = vcNewRecordSafStructureCode
tBudgetWBS.tcSafConceptCode = vcNewRecordSafConceptCode
tBudgetWBS.BudgetWBSCode = icNewBudgetWBSCode
tBudgetWBS.BudgetWBSLineNumber= iiNewBudgetWBSLineNumber
/* tBudgetWBS.BudgetWBSSeq = vdNewRecordWBSSeq */
tBudgetWBS.BudgetWBSFDSList = icBudgetWBSFDSList
tBudgetWBS.BudgetWBSFDSCode = icBudgetWBSFDSCode
tBudgetWBS.tcBudgetWBSSeqStr = vcNewRecordWBSSeq
tBudgetWBS.ParentBudgetWBS_ID = viParentBudgetWBSID.
create tNewBudgetWBS.
buffer-copy tBudgetWBS except BudgetWBSSeq to tNewBudgetWBS.
/* ============================================================= */
/* Create new VersionFigure-records for the new budgetWBS record */
/* DO the same for the corresponding output records */
/* ============================================================= */
for each tBudgetVersion where
tBudgetVersion.tc_ParentRowid = tBudget.tc_Rowid and
tBudgetVersion.tc_Status <> "D":U
no-lock :
if (tBudget.tcProjectCode <> "":U and tBudget.tcProjectCode <> ?) or
(tBudget.tcCostCentreCode <> "":U and tBudget.tcCostCentreCode <> ?)
then do :
<M-5 run AddDetailLine
(input 'BudgetVersionFigure':U (icTable),
input tBudgetVersion.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
if viFcReturnSuper < 0
then do :
assign oiReturnStatus = viFcReturnSuper.
return.
end. /* if viFcReturnSuper < 0 */
assign tBudgetVersionFig.BudgetWBS_ID = tBudgetWBS.BudgetWBS_ID
tBudgetVersionFig.tiBudgetFDSSeq = tBudgetWBS.BudgetFDSSeq
tBudgetVersionFig.tcBudgetFDSType = tBudgetWBS.BudgetFDSType
tBudgetVersionFig.tcBudgetWBSCode = tBudgetWBS.BudgetWBSCode
tBudgetVersionFig.tcBudgetWBSSeq = tBudgetWBS.tcBudgetWBSSeqStr
tBudgetVersionFig.tiParentBudgetWBS_ID = tBudgetWBS.ParentBudgetWBS_ID.
create tNewBudgetVersionFigure.
buffer-copy tBudgetVersionFig to tNewBudgetVersionFigure.
end. /* Project or CC budget */
else do :
<M-1 run AddDetailLine
(input 'BudgetVersionGLFig':U (icTable),
input tBudgetVersion.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBudget>
if viFcReturnSuper < 0
then do :
assign oiReturnStatus = viFcReturnSuper.
return.
end. /* if viFcReturnSuper < 0 */
assign tBudgetVersionGLFig.BudgetWBS_ID = tBudgetWBS.BudgetWBS_ID
tBudgetVersionGLFig.tiBudgetFDSSeq = tBudgetWBS.BudgetFDSSeq
tBudgetVersionGLFig.tcBudgetFDSType = tBudgetWBS.BudgetFDSType
tBudgetVersionGLFig.tcBudgetWBSCode = tBudgetWBS.BudgetWBSCode
tBudgetVersionGLFig.tiBudgetWBSLineNumber= tBudgetWBS.BudgetWBSLineNumber
tBudgetVersionGLFig.tcBudgetWBSSeq = tBudgetWBS.tcBudgetWBSSeqStr
tBudgetVersionGLFig.tiParentBudgetWBS_ID = tBudgetWBS.ParentBudgetWBS_ID.
create tNewBudgetVersionGLFig.
buffer-copy tBudgetVersionGLFig to tNewBudgetVersionGLFig.
end. /* not Project or CC budget */
end. /* for each */