project QadFinancials > class BPosting > method StdMaintainTTSub11

Description

Sub-method of ApiStdMaintainTTSub1 : WITHOUT Validate, AddUpd and DataSave


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.StdMaintainTTSub1


program code (program7/bposting.p)

/* ===================================================================== */
    /* Prerequisits: a tPosting line record is available and the             */
    /* tApiPostingSafcan be accessed                                         */
    /* ===================================================================== */
    
    empty temp-table tSafStructuresForPosting.
    
    /* ===================================================================== */
    /* Determine SAF structures to be used by the posting                    */
    /* ===================================================================== */
    <M-14 run ApiGetSafStructuresForPosting
       (input  tPosting.Company_ID (iiCompanyId), 
        input  tPostingLine.tcGLCode (icGLCode), 
        input  tPostingLine.tcCostCentreCode (icCostCenterCode), 
        input  tPostingLine.tcProjectCode (icProjectCode), 
        output tSafStructuresForPosting (tApiSafStructuresForPosting), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    
    if viFcReturnSuper <> 0
    then do:
        assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then return.
    end. /* if viFcReturnSuper <> 0 */
    
    
    for each tSafStructuresForPosting:
        assign vlRetrieveSafDefaults = false.

        /* ================================================================= */
        /* Retrieve corresponding SAF concepts for the structures            */
        /* ================================================================= */    
        <Q-11 run GetSafConceptsForStructure (all) (Read) (NoCache)
          (input tSafStructuresForPosting.tiPostingSafStructureId, (SafStructureID)
           output dataset tqSafConceptsForStructure) in BSafStructure >
    
        assign vcSafConceptList     = "":U
               vcComponentList      = "":U
               vcComponentValueList = "":U.
    
        /* ================================================================= */
        /* Create a tPostingSaf record for each SAF concept                  */
        /* ================================================================= */    
        for each tqSafConceptsForStructure
              by tqSafConceptsForStructure.tiSafStructure_ID
              by tqSafConceptsForStructure.tiSafStructureLineNumber:
    
            <M-12 run AddDetailLine (input  'PostingSaf':U (icTable), 
                            input  tPostingLine.tc_Rowid (icParentRowid), 
                            output viFcReturnSuper (oiReturnStatus)) in BPosting>
    
            if viFcReturnSuper <> 0
            then do:
                assign oiReturnStatus = viFcReturnSuper.
                if oiReturnStatus < 0
                then return.
            end. /* if viFcReturnSuper <> 0 */
    
            assign tPostingSaf.PostingLine_ID          = tPostingLine.PostingLine_ID
                   tPostingSaf.PostingSafInputSequence = tqSafConceptsForStructure.tiSafStructureLineNumber
                   tPostingSaf.SafStructure_ID         = tSafStructuresForPosting.tiPostingSafStructureId
                   tPostingSaf.tcSafStructureCode      = tSafStructuresForPosting.tcPostingSafStructureCode
                   tPostingSaf.PostingSafParentType    = tSafStructuresForPosting.tcPostingSafParentType
                   tPostingSaf.tcSafConceptCode        = tqSafConceptsForStructure.tcSafConceptCode.
    
            /* ================================================================= */
            /* Assign SAF code from the interface, if specified.  Otherwise,     */
            /* construct the list of SAF concept so default SAF code can be      */
            /* retrieved.                                                        */
            /* ================================================================= */    
            find first tApiPostingSaf where 
                       tApiPostingSaf.tcSafConceptCode = tPostingSaf.tcSafConceptCode and
                       tApiPostingSaf.PostingLine_ID = tPostingSaf.PostingLine_ID
            no-error.
    
            if available tApiPostingSaf and tApiPostingSaf.tcSafCode <> ? and tApiPostingSaf.tcSafCode <> "":U
            then
                assign tPostingSaf.tcSafCode = tApiPostingSaf.tcSafCode.
            else
                assign vlRetrieveSafDefaults = true                
                       vcSafConceptList      = if vcSafConceptList = "":U then tPostingSaf.tcSafConceptCode
                                               else vcSafConceptList + chr(2) + tPostingSaf.tcSafConceptCode.    
        end. /* for each tqSafConceptsForStructure */
    
        /* ================================================================= */
        /* Retrieve default SAF code in the following order:                 */
        /*      Cost Center/Project                                          */
        /*      GL                                                           */
        /*      SAF Structure                                                */
        /* ================================================================= */    
        if vlRetrieveSafDefaults
        then do:
    
            case tPostingSaf.PostingSafParentType:
                when {&POSTINGSAFPARENTTYPE-COSTCENTRE} then do:
                    if tPostingLine.tcCostCentreCode <> ? and tPostingLine.tcCostCentreCode <> "":U
                    then
                        assign vcComponentList      = "BCostCentre":U
                               vcComponentValueList = tPostingLine.tcCostCentreCode.
                end.
                when {&POSTINGSAFPARENTTYPE-PROJECT} then do:
                    if tPostingLine.tcProjectCode <> ? and tPostingLine.tcProjectCode <> "":U
                    then
                        assign vcComponentList      = "BProject":U
                               vcComponentValueList = tPostingLine.tcProjectCode.
                end.
            end case.
    
            if vcComponentList = "":U
            then
                assign vcComponentList      = "BGL":U
                       vcComponentValueList = tPostingLine.tcGLCode.
            else
                assign vcComponentList      = vcComponentList      + chr(2) + "BGL":U
                       vcComponentValueList = vcComponentValueList + chr(2) + tPostingLine.tcGLCode.
    
            assign vcComponentList      = vcComponentList      + chr(2) + "BSafStructure":U
                   vcComponentValueList = vcComponentValueList + chr(2) + tSafStructuresForPosting.tcPostingSafStructureCode.
    
            /* =================================================================== */
            /* Find the default SAF code from the component in the order specified */
            /* =================================================================== */    
            assign vhFcComponent = ?.
            <M-13 run GetSafDefaults (input  vcComponentList (icComponentList), 
                             input  vcComponentValueList (icComponentValueList), 
                             input  vcSafConceptList (icSafConceptList), 
                             output vcSafList (ocSafList), 
                             output viFcReturnSuper (oiReturnStatus)) in BSafDefault>
    
            if viFcReturnSuper <> 0
            then do:
                assign oiReturnStatus = viFcReturnSuper.
                if oiReturnStatus < 0
                then return.
            end. /* if viFcReturnSuper <> 0 */
    
            /* ================================================================= */
            /* Assign the SAF code from the default value retrieved              */
            /* ================================================================= */    
            for each tPostingSaf where
                     tPostingSaf.tc_ParentRowid = tPostingLine.tc_Rowid and
                     tPostingSaf.SafStructure_ID = tSafStructuresForPosting.tiPostingSafStructureId and
                     tPostingSaf.tcSafCode = "":U:
        
                assign vii = lookup(tPostingSaf.tcSafConceptCode, vcSafConceptList, chr(2)).
                if vii <> 0
                then
                    assign tPostingSaf.tcSafCode = entry(vii, vcSafList, chr(2)).
            end.
        end. /* if vlRetrieveSafDefaults */
    end.  /* for each tSafStructuresForPosting */