project QadFinancials > class BPosting > method AddDefaultSaf

Description

saf's


Parameters


icTypeinputcharactertype
iiObjectIdinputintegerobject
iiSafStructureIdinputintegerSaf Structure ID : necessary for posting on project, cost centre, .. so that you knows which saf structure you must take, if this is blank, then the first one will be taken
icSafStructureCodeinputcharacterSaf Structure Code : necessary for posting on project, cost centre, .. so that you knows which saf structure you must take, if this is blank, then the first one will be taken
iiGLIdinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.AddControlPosting
method BPosting.AddStandardPosting


program code (program1/bposting.p)

case icType:
    when {&POSTINGSAFPARENTTYPE-GL}
    then do:
        <Q-1 run GetSafStructureLinkForGL (all) (Read) (Cache)
           (input iiObjectId, (GL_ID)
            output dataset tqSafStructureLinkForGL) in BSafStructureLink>

        if iiSafStructureId = 0 or
           iiSafStructureId = ?
        then if icSafStructureCode = "":U or
                icSafStructureCode = ?
             then find first tqSafStructureLinkForGL
                             no-error.
             else find first tqSafStructureLinkForGL where
                             tqSafStructureLinkForGL.tcSafStructureCode = icSafStructureCode
                             no-error.
        else find first tqSafStructureLinkForGL where
                        tqSafStructureLinkForGL.tiSafStructure_ID = iiSafStructureId
                        no-error.

        if available tqSafStructureLinkForGL
        then assign viSafStructureId   = tqSafStructureLinkForGL.tiSafStructure_ID
                    vcSafStructureCode = tqSafStructureLinkForGL.tcSafStructureCode.
    end.

    when {&POSTINGSAFPARENTTYPE-COSTCENTRE}
    then do:
        <M-10 run GetSafStructureForCostCentre
           (input  tPosting.Company_ID (iiCompanyId), 
            input  iiGLId (iiGLId), 
            input  ? (icGLCode), 
            input  iiObjectId (iiCostCentreId), 
            input  ? (icCostCentreCode), 
            output viSafStructureId (oiSafStructureId), 
            output vcSafStructureCode (ocSafStructureCode), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>

        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.

        if oiReturnStatus < 0
        then return.

        if iiSafStructureId <> 0 and iiSafStructureId <> ? and iiSafStructureId <> viSafStructureId
        then assign viSafStructureId = 0
                    vcSafStructureCode = "":U.

        if icSafStructureCode <> "":U and icSafStructureCode <> ? and icSafStructureCode <> vcSafStructureCode
        then assign viSafStructureId = 0
                    vcSafStructureCode = "":U.
    end.

    when {&POSTINGSAFPARENTTYPE-PROJECT}
    then do:
        <M-11 run GetSafStructureForProject
           (input  tPosting.Company_ID (iiCompanyId), 
            input  iiGLId (iiGLId), 
            input  ? (icGLCode), 
            input  iiObjectId (iiProjectId), 
            input  ? (icProjectCode), 
            output viSafStructureId (oiSafStructureId), 
            output vcSafStructureCode (ocSafStructureCode), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>

        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.

        if oiReturnStatus < 0
        then return.

        if iiSafStructureId <> 0 and iiSafStructureId <> ? and iiSafStructureId <> viSafStructureId
        then assign viSafStructureId = 0
                    vcSafStructureCode = "":U.

        if icSafStructureCode <> "":U and icSafStructureCode <> ? and icSafStructureCode <> vcSafStructureCode
        then assign viSafStructureId = 0
                    vcSafStructureCode = "":U.
    end.
end case.



if viSafStructureId = 0 or vcSafStructureCode = "":U
then return.

assign vlGetDefaults = false.

<Q-4 run GetSafConceptsForStructure (all) (Read) (Cache)
   (input viSafStructureId, (SafStructureID)
    output dataset tqSafConceptsForStructure) in BSafStructure>

for each tqSafConceptsForStructure
      by tqSafConceptsForStructure.tiSafStructure_ID
      by tqSafConceptsForStructure.tiSafStructureLineNumber:
    <M-7 run AddDetailLine (input  'PostingSaf':U (icTable), 
                        input  tPostingLine.tc_Rowid (icParentRowid), 
                        output oiReturnStatus (oiReturnStatus)) in BPosting>

    if oiReturnStatus < 0
    then return.

    assign tPostingSaf.PostingLine_ID          = tPostingLine.PostingLine_ID
           tPostingSaf.PostingSafInputSequence = tqSafConceptsForStructure.tiSafStructureLineNumber
           tPostingSaf.saf_id                  = 0
           tPostingSaf.SafStructure_ID         = viSafStructureId
           tPostingSaf.tcSafStructureCode      = vcSafStructureCode
           tPostingSaf.PostingSafParentType    = icType
           tPostingSaf.tcSafCode               = "":U
           tPostingSaf.tcSafConceptCode        = tqSafConceptsForStructure.tcSafConceptCode.
        
    find first tDefaultSafs where
               tDefaultSafs.tcSafConceptCode = tqSafConceptsForStructure.tcSafConceptCode
               no-error.

    if available tDefaultSafs
    then do:
        <Q-6 run GetSaf (all) (Read) (Cache)
           (input tDefaultSafs.tcSafCode, (SafCode)
            input tDefaultSafs.tcSafConceptCode, (SafConceptCode)
            input '':U, (SafDescription)
            input ?, (SafIsActive)
            output dataset tqGetSaf) in BSaf>
        find first tqGetSaf no-error.
        if available tqGetSaf
        then assign tPostingSaf.Saf_ID    = tqGetSaf.tiSaf_ID
                    tPostingSaf.tcSafCode = tqGetSaf.tcSafCode.
    end. /* if available tDefaultSafs */
    else assign vlGetDefaults = true.
    
end. /* for each tqSafConceptsForStructure */

if vlGetDefaults
then do:    
    assign vcSafConceptList = "":U.

    if icType                         = {&POSTINGSAFPARENTTYPE-COSTCENTRE} and
       tPostingLine.tcCostCentreCode <> "":U                               and
       tPostingLine.tcCostCentreCode <> ?
    then assign vcComponentList      = "BCostCentre":U
                vcComponentValueList = tPostingLine.tcCostCentreCode.

    if icType                         = {&POSTINGSAFPARENTTYPE-PROJECT} and
       tPostingLine.tcProjectCode <> "":U                               and
       tPostingLine.tcProjectCode <> ?
    then assign vcComponentList      = "BProject":U
                vcComponentValueList = tPostingLine.tcProjectCode.

    if vcComponentList <> "":U and vcComponentList <> ?
    then assign vcComponentList      = vcComponentList      + chr(2) + "BGL":U
                vcComponentValueList = vcComponentValueList + chr(2) + tPostingLine.tcGLCode.
    else assign vcComponentList      = "BGL":U
                vcComponentValueList = tPostingLine.tcGLCode.

    assign
        vcComponentList      = vcComponentList      + chr(2) + "BSafStructure":U
        vcComponentValueList = vcComponentValueList + chr(2) + vcSafStructureCode.

    for each tPostingSaf where
             tPostingSaf.tc_ParentRowid        = tPostingLine.tc_Rowid  and 
             tPostingSaf.PostingSafParentType  = icType
          by tPostingSaf.PostingSafInputSequence:
        if vcSafConceptList <> "":U
        then assign vcSafConceptList = vcSafConceptList + chr(2).

        assign vcSafConceptList = vcSafConceptList + tPostingSaf.tcSafConceptCode.
    end.

    assign vhFcComponent = ?.

    <M-8 run GetSafDefaults (input  vcComponentList (icComponentList), 
                         input  vcComponentValueList (icComponentValueList), 
                         input  vcSafConceptList (icSafConceptList), 
                         output vcSafList (ocSafList), 
                         output viFcReturnSuper (oiReturnStatus)) in BSafDefault>

    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.

    if oiReturnStatus < 0
    then return.


    do viA = num-entries(vcSafList, chr(2)) to 1 by -1:
        if entry(viA, vcSafList, chr(2)) = "":U
        then next.


        find tPostingSaf where
             tPostingSaf.tc_ParentRowid          = tPostingLine.tc_Rowid and
             tPostingSaf.PostingSafInputSequence = viA                   and 
             tPostingSaf.PostingSafParentType    = icType
             no-error.

        if available tPostingSaf        and
          (tPostingSaf.tcSafCode = "":U or
           tPostingSaf.tcSafCode = ?)
        then do:
            <Q-9 run GetSaf (all) (Read) (Cache)
               (input entry(viA, vcSafList, chr(2)), (SafCode)
                input tPostingSaf.tcSafConceptCode, (SafConceptCode)
                input '':U, (SafDescription)
                input ?, (SafIsActive)
                output dataset tqGetSaf) in BSaf>
            find first tqGetSaf no-error.
            if available tqGetSaf
            then assign tPostingSaf.Saf_ID    = tqGetSaf.tiSaf_ID
                        tPostingSaf.tcSafCode = tqGetSaf.tcSafCode.
        end. /* if available tPostingSaf        and */
        
    end. /* do viA = num-entries(vcSafList, chr(2)) to 1 by -1: */
    
end. /* if vlGetDefaults */