project QadFinancials > class BBudget > method AdditionalUpdCreateSafStructureLink

Description

This method will create Saf Structure Link records.


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBudget.AdditionalUpdates


program code (program4/bbudget.p)

/* =============================================================================================== */
    /* SafStructureLinkSkipCreation; temp-table that is used as input by method ApiCopyBudget.         */
    /* For every BudgetWBS on a project- or a cost-centre budget, the link between the safstructure    */
    /* and the project/cost-centre is created (when it does not yet exist in he db) in a submethod     */
    /* of AddtionalUpdates.                                                                            */
    /* When method ApiCopyBudget is executed from BProject, then BProject has already done the same.   */
    /* This leads to double created link records.                                                      */
    /* Solution: BProject passes a list of the SafStructureLinks it has already created itself and     */
    /* we check this list before we create the links.                                                  */
    /* Note: empty this temp-table at the end of this method to avoid problems with the next instances */
    /* =============================================================================================== */
    
    /* ===================================================================================== */
    /* Compose a temp-table that contains the SafStructures that have not yet been linked to */
    /* the correct project of cost-centre. Then call a method on BSafStructure link that     */
    /* will create the new records for the BSafStructure records                             */
    /* ===================================================================================== */
    empty temp-table tSafStructureLinkBudget.
    empty temp-table tSafStructureLinkBudgetConv.
    for each tBudget where 
             tBudget.tc_Status <> "D":U and 
             ((tBudget.Project_ID <> 0 and 
               tBudget.Project_ID <> ?) or
              (tBudget.CostCentre_ID <> 0 and 
               tBudget.CostCentre_ID <> 0)),
        each tBudgetWBS where 
             tBudgetWBS.tc_Status        = "N":U and 
             tBudgetWBS.SafStructure_ID <> 0     and 
             tBudgetWBS.SafStructure_ID <> ?     and 
             tBudgetWBS.BudgetFDSType    = {&BUDGETFDSTYPE-SAF} : 
        if can-find (first tSafStructureLinkBudget where 
                           tSafStructureLinkBudget.CostCentre_ID   = tBudget.CostCentre_ID and 
                           tSafStructureLinkBudget.Project_ID      = tBudget.Project_ID    and
                           tSafStructureLinkBudget.SafStructure_ID = tBudgetWBS.SafStructure_ID) or
           can-find (first tSafStructureLinkSkipCreation where 
                           tSafStructureLinkSkipCreation.tc_Status      <> "D":U                 and
                           tSafStructureLinkSkipCreation.CostCentre_ID   = tBudget.CostCentre_ID and 
                           tSafStructureLinkSkipCreation.Project_ID      = tBudget.Project_ID    and
                           tSafStructureLinkSkipCreation.SafStructure_ID = tBudgetWBS.SafStructure_ID)
        then next.
        <Q-1 assign vlFcQueryRecordsAvailable = SafStructureLinkByAllIDs (Cache)
          (input ?, (SafStructureLinkID)
           input tBudgetWBS.SafStructure_ID, (SafStructureID)
           input ?, (GLID)
           input tBudget.Project_ID, (ProjectID)
           input tBudget.CostCentre_ID, (CostCentreID)) in BSafStructureLink >
        if vlFcQueryRecordsAvailable = false
        then do :
            create tSafStructureLinkBudget.
            assign tSafStructureLinkBudget.CostCentre_ID        = tBudget.CostCentre_ID
                   tSafStructureLinkBudget.Project_ID           = tBudget.Project_ID
                   tSafStructureLinkBudget.SafStructure_ID      = tBudgetWBS.SafStructure_ID  /* Needed for can-find above */
                   tSafStructureLinkBudget.tcSafStructureCode   = tBudgetWBS.tcSafStructureCode /* Needed because now RKBF in SafStructureLink */
                   tSafStructureLinkBudget.tc_Status            = "N":U
                   tSafStructureLinkBudget.SafStructureLink_ID  = tBudgetWBS.BudgetWBS_ID /* just something unique */
                   tSafStructureLinkBudget.GL_ID                = 0
                   tSafStructureLinkBudget.tc_Rowid             = string(tSafStructureLinkBudget.SafStructureLink_ID).
        end. /* if vlFcQueryRecordsAvailable = false */
    end. /* for each */
    if can-find (first tSafStructureLinkBudget) 
    then do :
        if viBSafStructureLinkBudgetID = 0 or
           viBSafStructureLinkBudgetID = ?     
        then do :
            <I-9 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BSafStructureLink"}>
        end. /* if viBSafStructureLinkBudgetID = 0 or */
        else do:
            <I-10 {bFcOpenInstance
            &CLASS           = "BSafStructureLink"}>
        end. /* not if viBSafStructureLinkBudgetID = 0 or */
        <M-11 run UpdateSafStructureLink (input  tSafStructureLinkBudget (t_sSafStructureLinkRef), 
                                          output tSafStructureLinkBudgetConv (tSafStructureLinkConversion), 
                                          output viFcReturnSuper (oiReturnStatus)) in BSafStructureLink>
        if viFcReturnSuper <> 0
        then assign oiReturnStatus = viFcReturnSuper.
        <I-12 {bFcCloseInstance
            &CLASS           = "BSafStructureLink"}>
        if oiReturnStatus < 0
        then return.
    end. /* if can-find (first tSafStructureLinkBudget) */