project QadFinancials > class BBudget > method ValidateComponentBudgetFDSWBS

Description

This method will check the relation between the BudgetWBS records and the BudgetFDS records


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBudget.ValidateComponent


program code (program5/bbudget.p)

/* ==================================================================================== */
    /* Exception: manual definition for buffer on t_sBudget (not possible using data-items) */
    /* ==================================================================================== */
    define buffer btsBudget for t_sBudget.
    
    /* ================================================================================ */
    /* ValidateComponentBudgetFDSWBS; this method will check the relation between the   */
    /* BudgetWbs records and the budgetFds records. This method will also check that    */
    /* there is only a single budget for one Project and one CostCentre                 */
    /* Addtional check: BudgetWBS.Unit_ID (test on the ID: this method is called after  */
    /* the ancestor-code) can only be filled if tBudget.BudgetIsWithQuantityData = true */
    /* ================================================================================ */
    for each t_sBudget where 
             t_sBudget.tc_Status <> "D":U :                               
        
        /* ======================================================== */
        /* Check for un-allowed status-changes and that the project */
        /* is open in case the budget has been set to operational   */
        /* ======================================================== */
        find t_iBudget where
             t_iBudget.tc_Rowid = t_sBudget.tc_Rowid
             no-lock no-error.
        if t_sBudget.Project_ID <> 0 and 
           t_sBudget.Project_ID <> ? and 
           (available t_iBudget                                   and
            t_sBudget.BudgetStatus  = {&BUDGETSTATUS-OPERATIONAL} and 
            t_iBudget.BudgetStatus <> {&BUDGETSTATUS-OPERATIONAL}) or
           (not available t_iBudget                               and
            t_sBudget.BudgetStatus  = {&BUDGETSTATUS-OPERATIONAL})
        then do :
            <Q-13 run ProjectByProjectStatus (all) (Read) (NoCache)
          (input ?, (CompanyId)
           input ?, (ProjectStatusId)
           input t_sBudget.Project_ID, (ProjectID)
           input ?, (ProjectCode)
           output dataset tqProjectByProjectStatus) in BProject >
            find first tqProjectByProjectStatus where
                       tqProjectByProjectStatus.tiProject_ID  = t_sBudget.Project_ID
                       no-error.
            if available tqProjectByProjectStatus and 
               tqProjectByProjectStatus.tcProjectStatusSystemStatus <> {&PROJECTSYSTEMSTATUS-OPEN}
            then do:
                assign oiReturnStatus = +1
                       vcMessage      = trim(substitute(#T-14'Warning. The status of the budget (&1) was set to Operational although the linked project (&2) is no longer open.':255(642)T-14#,t_sBudget.BudgetCode,t_sBudget.tcProjectCode)).
                <M-11 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  'tBudget.BudgetStatus':U (icFieldName),
                     input  t_sBudget.BudgetStatus (icFieldValue),
                     input  'W':U (icType),
                     input  3 (iiSeverity),
                     input  t_sBudget.tc_Rowid (icRowid),
                     input  'QADFIN-1800':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
            end. /* if available tqProjectByProjectStatus and */
        end. /* if t_sBudget.Project_ID <> 0 and */
        assign vcMessage = "":U.
        if available t_iBudget and 
           t_sBudget.tc_Status = "C":U
        then do :
            if t_iBudget.BudgetStatus = {&BUDGETSTATUS-VALID} and 
               t_sBudget.BudgetStatus = {&BUDGETSTATUS-INITIAL}
            then assign vcMessage = trim(substitute(#T-15'The status of a validated budget (&1) cannot be set to &2.':255(643)T-15#,t_sBudget.BudgetCode,{&BUDGETSTATUS-INITIAL-TR})).
            else if t_iBudget.BudgetStatus = {&BUDGETSTATUS-OPERATIONAL} and 
                    (t_sBudget.BudgetStatus = {&BUDGETSTATUS-INITIAL} or
                     t_sBudget.BudgetStatus = {&BUDGETSTATUS-VALID})
                 then assign vcMessage = trim(substitute(#T-16'The status of an operational budget (&1) cannot be set to &2 or &3.':255(644)T-16#,t_sBudget.BudgetCode,{&BUDGETSTATUS-INITIAL-TR},{&BUDGETSTATUS-VALID-TR})).
                 else if t_iBudget.BudgetStatus = {&BUDGETSTATUS-CLOSED} and 
                        (t_sBudget.BudgetStatus = {&BUDGETSTATUS-INITIAL} or
                         t_sBudget.BudgetStatus = {&BUDGETSTATUS-VALID})
                      then assign vcMessage = trim(substitute(#T-17'The status of a closed budget (&1) cannot be set to &2 or &3.':255(645)T-17#,t_sBudget.BudgetCode,{&BUDGETSTATUS-INITIAL-TR},{&BUDGETSTATUS-VALID-TR})).
                      else if t_iBudget.BudgetStatus = {&BUDGETSTATUS-CLOSED} and 
                              t_sBudget.BudgetStatus = {&BUDGETSTATUS-OPERATIONAL}
                           then assign vcMessage = "+":U + trim(substitute(#T-18'If you set a closed budget (&1) to &2, historical figures on commitments and actuals may be incomplete. Use Rebuild to correct this situation.':255(646)T-18#,t_sBudget.BudgetCode,{&BUDGETSTATUS-OPERATIONAL-TR})).
        end. /* if available t_iBudget and */            
        if vcMessage <> "":U
        then do : 
            if substring(vcMessage,1,1,"CHARACTER":U) = "+":U
            then assign oiReturnStatus = +1
                        vcMessage      = substring(vcMessage,2,-1,"CHARACTER":U).
            else assign oiReturnStatus = -1.
            <M-10 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  'tBudget.BudgetStatus':U (icFieldName),
                     input  t_sBudget.BudgetStatus (icFieldValue),
                     input  (if oiReturnStatus < 0 then 'E':U else 'W':U) (icType),
                     input  3 (iiSeverity),
                     input  t_sBudget.tc_Rowid (icRowid),
                     input  'QADFIN-1607':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
        end. /* if available t_iBudget */
        
        /* ========================================= */
        /* Check other budget for the same CC or Prj */
        /* ========================================= */
        if t_sBudget.tcProjectCode <> "":U and 
           t_sBudget.tcProjectCode <> ? and
           t_sBudget.BudgetStatus  = {&BUDGETSTATUS-OPERATIONAL}
        then do :
            find first btsBudget where 
                       btsBudget.tc_Rowid      <> t_sBudget.tc_Rowid          and 
                       btsBudget.tc_status     <> "D":U                       and
                       btsBudget.BudgetStatus   = {&BUDGETSTATUS-OPERATIONAL} and 
                       btsBudget.tcProjectCode  = t_sBudget.tcProjectCode
                       no-lock no-error.
            if available btsBudget
            then do :
                assign oiReturnStatus = -1
                       vcMessage      = trim(substitute(#T-19'Duplicate operational budgets (&1 / &2) detected for a single project (&3).':255(17333)T-19#, t_sBudget.BudgetCode, btsBudget.BudgetCode, t_sBudget.tcProjectCode)).
                <M-3 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  'tBudget.tcProjectCode':U (icFieldName),
                     input  t_sBudget.tcProjectCode (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sBudget.tc_Rowid (icRowid),
                     input  'QADFIN-1183':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
            end. /* if available btsBudget */
            else do :
                <Q-4 run BudgetByProjectCostCentre (first) (Read) (NoCache)
          (input ?, (CompanyId)
           input ?, (CostCentreCode)
           input ?, (CostCentreID)
           input if t_sBudget.Project_ID = ? or t_sBudget.Project_ID = 0 then t_sBudget.tcProjectCode else '':U, (ProjectCode)
           input t_sBudget.Project_ID, (ProjectID)
           input string(t_sBudget.tc_rowid), (RowidToSkip)
           input {&BUDGETSTATUS-OPERATIONAL}, (BudgetStatus)
           output dataset tqBudgetByProjectCostCentre) in BBudget >
                find first tqBudgetByProjectCostCentre no-lock no-error.
                if available tqBudgetByProjectCostCentre
                then do :
                    assign oiReturnStatus = -1
                           vcMessage      = trim(substitute(#T-20'Duplicate operational budgets (&1 / &2) detected for a single project (&3).':255(17333)T-20#, t_sBudget.BudgetCode, tqBudgetByProjectCostCentre.tcBudgetCode, t_sBudget.tcProjectCode)).
                    <M-5 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  'tBudget.tcProjectCode':U (icFieldName),
                     input  t_sBudget.tcProjectCode (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sBudget.tc_Rowid (icRowid),
                     input  'QADFIN-1184':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
                end. /* if available tqBudgetByProjectCostCentre */
            end. /* not if available btsBudget */
        end. /* if t_sBudget.tcProjectCode <> "":U and */
        if t_sBudget.tcCostCentreCode <> "":U and 
           t_sBudget.tcCostCentreCode <> ? and
           t_sBudget.BudgetStatus      = {&BUDGETSTATUS-OPERATIONAL}
        then do :
            find first btsBudget where 
                       btsBudget.tc_Rowid         <> t_sBudget.tc_Rowid          and 
                       btsBudget.tc_status        <> "D":U                       and
                       btsBudget.BudgetStatus      = {&BUDGETSTATUS-OPERATIONAL} and 
                       btsBudget.tcCostCentreCode  = t_sBudget.tcCostCentreCode
                       no-lock no-error.
            if available btsBudget
            then do :
                assign oiReturnStatus = -1
                       vcMessage      = trim(substitute(#T-21'Duplicate operational budgets (&1 / &2) detected for a single cost center (&3).':255(454)T-21#, t_sBudget.BudgetCode, btsBudget.BudgetCode, t_sBudget.tcCostCentreCode)).
                <M-6 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  'tBudget.tcCostCentreCode':U (icFieldName),
                     input  t_sBudget.tcCostCentreCode (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sBudget.tc_Rowid (icRowid),
                     input  'QADFIN-1185':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
            end. /* if available btsBudget */
            else do :
                assign vcCostCentreCode = if t_sBudget.CostCentre_ID = ? or t_sBudget.CostCentre_ID = 0 then t_sBudget.tcCostCentreCode else "":U.
                <Q-7 run BudgetByProjectCostCentre (first) (Read) (NoCache)
          (input ?, (CompanyId)
           input vcCostCentreCode, (CostCentreCode)
           input t_sBudget.CostCentre_ID, (CostCentreID)
           input ?, (ProjectCode)
           input ?, (ProjectID)
           input string(t_sBudget.tc_rowid), (RowidToSkip)
           input {&BUDGETSTATUS-OPERATIONAL}, (BudgetStatus)
           output dataset tqBudgetByProjectCostCentre) in BBudget >
                find first tqBudgetByProjectCostCentre no-lock no-error.
                if available tqBudgetByProjectCostCentre
                then do :
                    assign oiReturnStatus = -1
                           vcMessage      = trim(substitute(#T-22'Duplicate operational budgets (&1 / &2) detected for a single cost center (&3).':255(454)T-22#, t_sBudget.BudgetCode, tqBudgetByProjectCostCentre.tcBudgetCode, t_sBudget.tcCostCentreCode)).
                    <M-8 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  'tBudget.tcCostCentreCode':U (icFieldName),
                     input  t_sBudget.tcCostCentreCode (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sBudget.tc_Rowid (icRowid),
                     input  'QADFIN-1186':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
                end. /* if available tqBudgetByProjectCostCentre */
            end. /* not if available btsBudget */
        end. /* if t_sBudget.tcCostCentreCode <> "":U and */
        
        /* ================================================================================ */
        /* Addtional check: BudgetWBS.Unit_ID (test on the ID: this method is called after  */
        /* the ancestor-code) can only be filled if tBudget.BudgetIsWithQuantityData = true */
        /* ================================================================================ */
        if t_sBudget.BudgetIsWithQuantityData = false
        then do: 
            find first t_sBudgetWBS where 
                       t_sBudgetWBS.tc_ParentRowid  = t_sBudget.tc_Rowid and 
                       t_sBudgetWBS.tc_Status      <> "D":U              and 
                       t_sBudgetWBS.Unit_ID        <> 0                  and
                       t_sBudgetWBS.Unit_ID        <> ?
                       no-lock no-error.
            if available t_sBudgetWBS
            then do :
                assign oiReturnStatus = -1
                       vcMessage      = trim(substitute(#T-23'A WBS node (&2) with a unit of measure was detected. The budget (&1) does not allow quantities on WBS nodes.':255(17341)t-23#,t_sBudget.BudgetCode,t_sBudgetWBS.BudgetWBSCode)).
                <M-9 run SetMessage (input  vcMessage (icMessage),
                         input  '':U (icArguments),
                         input  'tBudget.BudgetIsWithQuantityData':U (icFieldName),
                         input  t_sBudget.BudgetIsWithQuantityData (icFieldValue),
                         input  'E':U (icType),
                         input  3 (iiSeverity),
                         input  t_sBudget.tc_Rowid (icRowid),
                         input  'QADFIN-1322':U (icFcMsgNumber),
                         input  '' (icFcExplanation),
                         input  '' (icFcIdentification),
                         input  '' (icFcContext),
                         output viFcReturnSuper (oiReturnStatus)) in BBudget>
            end. /* if available t_sBudgetWBS */
        end. /* if t_sBudget.BudgetIsWithQuantityData = false and */
                
        /* ============================================================ */
        /* Deleted FDS-records cannot be linked to existing WBS-records */
        /* ============================================================ */
        for each t_sBudgetFDS where 
                 t_sBudgetFDS.tc_ParentRowid = t_sBudget.tc_Rowid and 
                 t_sBudgetFDS.tc_Status      = "D":U :
            find first t_sBudgetWBS where 
                       t_sBudgetWBS.tc_ParentRowid  = t_sBudget.tc_Rowid        and 
                       t_sBudgetWBS.BudgetFDS_ID    = t_sBudgetFDS.BudgetFDS_ID and 
                       t_sBudgetWBS.tc_Status      <> "D":U
                       no-lock no-error.
            if available t_sBudgetWBS
            then do :
                assign oiReturnStatus = -1
                       vcMessage      = trim(#T-24'The Chart of Accounts (COA) is used in the Work Breakdown Structure (WBS) of the budget and cannot be deleted.':255(648)t-24#) + CHR(10) + 
                                        trim(substitute(#T-25'COA sequence and type: &1 / &2.':255(649)T-25#,string(t_sBudgetFDS.BudgetFDSSeq),t_sBudgetFDS.BudgetFDSType)) + CHR(10) + 
                                        trim(substitute(#T-26'WBS node: &1.':255(650)T-26#,string(t_sBudgetWBS.BudgetWBSCode))).
                <M-1 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  'tBudgetWBS.BudgetWBSCode':U (icFieldName),
                     input  t_sBudgetWBS.BudgetWBSCode (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sBudgetWBS.tc_Rowid (icRowid),
                     input  'QADFIN-837':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
            end. /* if available t_sBudgetWBS */
        end. /* for each t_sBudgetFDS where */
        /* ============================================================ */
        /* Wbs-records should have a linke to a non-deleted Fds-record  */
        /* ============================================================ */
        for each t_sBudgetWBS where 
                 t_sBudgetWBS.tc_ParentRowid  = t_sBudget.tc_Rowid and 
                 t_sBudgetWBS.tc_Status      <> "D":U :
            find first t_sBudgetFDS where 
                       t_sBudgetFDS.tc_ParentRowid  = t_sBudget.tc_Rowid        and 
                       t_sBudgetFDS.BudgetFDS_ID    = t_sBudgetWBS.BudgetFDS_ID and 
                       t_sBudgetFDS.tc_Status       = "D":U
                       no-lock no-error.
            if available t_sBudgetFDS
            then do :
                assign oiReturnStatus = -1
                       vcMessage      = trim(#T-27'This WBS node contains a link to a deleted COA type.':255(651)T-27#) + CHR(10) + 
                                        trim(substitute(#T-28'COA sequence and type: &1 / &2.':255(649)T-28#,string(t_sBudgetFDS.BudgetFDSSeq),t_sBudgetFDS.BudgetFDSType)) + CHR(10) + 
                                        trim(substitute(#T-29'WBS node: &1.':255(650)T-29#,string(t_sBudgetWBS.BudgetWBSCode))).
                <M-2 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  'tBudgetWBS.BudgetWBSCode':U (icFieldName),
                     input  t_sBudgetWBS.BudgetWBSCode (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  t_sBudgetWBS.tc_Rowid (icRowid),
                     input  'QADFIN-838':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
            end. /* if available t_sBudgetWBS */
        end. /* for each t_sBudgetFDS where */
    end. /* for each t_sBudget where */
    
    if oiReturnStatus < 0
    then return.