project QadFinancials > class BDeductionCat > method ApiGetSafsByGLCodeCostCenter

Description

Get Expense SAFs for the given GL Code and Cost Center


Parameters


icGLCodeinputcharacter
icCostCenterCodeinputcharacter
tApiDeductionCatLineSafinput-outputtemp-table
oiSafStructureIdoutputinteger
iiDomainIDinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDeductionCat.ValidateComponent


program code (program9/bdeductioncat.p)

/*******************************************************************************/
/* this method will get the SafConcept and SafCode base the user input GLCode  */
/* and Cost Center Code */
/*******************************************************************************/

if oiReturnStatus < 0
then return.

/* clear return temp-table first */
empty temp-table tApiDeductionCatLineSaf no-error.

viCurrentCompanyID = 0.

<Q-40 run CompanyByDomainActive (first) (Read) (NoCache)
   (input ?, (CompanyId)
    input iiDomainID, (DomainId)
    input yes, (CompanyIsActive)
    output dataset tqCompanyByDomainActive) in BCompany>

for first tqCompanyByDomainActive:
   viCurrentCompanyID = tqCompanyByDomainActive.tiCompany_ID.
end.

if viCurrentCompanyID = 0 then
do:
   vcMessage =  substitute(#T-94'Invalid Domain ID (&1).':255(70391)T-94# , iiDomainID).
   <M-70 run SetMessage
                (input  vcMessage (icMessage), 
                 input  ? (icArguments), 
                 input  ? (icFieldName), 
                 input  ? (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  ? (icRowid), 
                 input  'qadfin-760911':U (icFcMsgNumber), 
                 input  ? (icFcExplanation), 
                 input  ? (icFcIdentification), 
                 input  ? (icFcContext), 
                 output oiReturnStatus (oiReturnStatus)) in BDeductionCat>
   return.
end.

/* initial local varialbes */
assign vlIsCostCenterAccount      = no
       vlCostCentreIsStructFromGL = no
       viGLId                     = 0
       viCostCenterId             = 0
       viSafStructureId           = 0
       oiSafStructureId           = 0.

/* check if glcode is empty */
if icGLCode = ? or icGLCode = '':U
then return.

/**********************************************************************************/
/* Step 1: Get SafStructure_ID base gl code and cost center code */
/**********************************************************************************/
/* get gl id */
<Q-30 run GLPrim (all) (Read) (NoCache)
   (input viCurrentCompanyID, (CompanyId)
    input icGLCode, (GLCode)
    input ?, (GLId)
    output dataset tqGLPrim) in BGL>
find first tqGLPrim no-lock no-error.
if available tqGLPrim
then do:
    assign
        viGLid                = tqGLPrim.tiGL_ID
        vlIsCostCenterAccount = tqGLPrim.tlGLIsCostCentreAccount.

    if vlIsCostCenterAccount
    then do:
        /* get cost center id and saf structure id */
        if icCostCenterCode = ? or icCostCenterCode = '':U
        then return.
        <Q-1 run CostCentreByCodeID (all) (Read) (NoCache)
           (input viCurrentCompanyID, (CompanyId)
            input icCostCenterCode, (CostCentreCode)
            input ?, (CostCentreID)
            output dataset tqCostCentreByCodeID) in BCostCentre>
        find first tqCostCentreByCodeID no-lock no-error.
        if available tqCostCentreByCodeID
        then do:
            assign vlCostCentreIsStructFromGL = tqCostCentreByCodeID.tlCostCentreIsStructFromGL
                   viCostCenterId             = tqCostCentreByCodeID.tiCostCentre_ID.
            if vlCostCentreIsStructFromGL
            then do: /* get saf structure from gl */
                <Q-68 run SafStructureLinkByAllIDs (all) (Read) (NoCache)
                   (input ?, (SafStructureLinkID)
                    input ?, (SafStructureID)
                    input viGLId, (GLID)
                    input ?, (ProjectID)
                    input ?, (CostCentreID)
                    output dataset tqSafStructureLinkByAllIDs) in BSafStructureLink>
                find first tqSafStructureLinkByAllIDs no-lock no-error.
                if available tqSafStructureLinkByAllIDs
                then assign viSafStructureId = tqSafStructureLinkByAllIDs.tiSafStructure_ID.
            end. /* if vlCostCentreIsStructFromGL */
            else do: /* get saf structure from cost center */
                <Q-17 run SafStructureLinkByAllIDs (all) (Read) (NoCache)
                   (input ?, (SafStructureLinkID)
                    input ?, (SafStructureID)
                    input ?, (GLID)
                    input ?, (ProjectID)
                    input viCostcenterId, (CostCentreID)
                    output dataset tqSafStructureLinkByAllIDs) in BSafStructureLink>
                find first tqSafStructureLinkByAllIDs no-lock no-error.
                if available tqSafStructureLinkByAllIDs
                then assign viSafStructureId = tqSafStructureLinkByAllIDs.tiSafStructure_ID.
            end.
        end. /* if available tqCostCentreByCodeID */
    end. /* if vlIsCostCenterAccount */
    else do:
        /* directly get sufstructure from gl */
        <Q-13 run SafStructureLinkByAllIDs (all) (Read) (NoCache)
           (input ?, (SafStructureLinkID)
            input ?, (SafStructureID)
            input viGLId, (GLID)
            input ?, (ProjectID)
            input ?, (CostCentreID)
            output dataset tqSafStructureLinkByAllIDs) in BSafStructureLink>
        find first tqSafStructureLinkByAllIDs no-lock no-error.
        if available tqSafStructureLinkByAllIDs
        then assign viSafStructureId = tqSafStructureLinkByAllIDs.tiSafStructure_ID.
    end.
end.

/**********************************************************************************/
/* Step 2: Get SafConcept and SafCode base the SafStructure in step 1 */
/**********************************************************************************/
if viSafStructureId <= 0
then return.

find first tDeductionCat no-lock no-error.
if not available tDeductionCat and (vcActivityCode = "Create" or vcActivityCode = "Modify")
then return.

find first tDeductionCatLine no-lock no-error.
if not available tDeductionCatLine and (vcActivityCode = "Create" or vcActivityCode = "Modify")
then return.

/* assign safstructure_id  */
assign oiSafStructureId = viSafStructureId.

/* Get SafStructureLines */
<Q-32 run SafForStrctureLine (all) (Read) (NoCache)
   (input viSafStructureId, (SafStructure_ID)
    input ?, (SafStructureCode)
    input ?, (SafStructureLineNumber)
    output dataset tqSafForStrctureLine) in BSafStructure>

/* Add SafStructureLines to the temp table */
for each tqSafForStrctureLine no-lock:
    if viCostCenterId > 0 and not (vlCostCentreIsStructFromGL)
    then do: /* using cost center saf structure */
        /* get cost center default safconcept and saf code */
        <Q-46 run CostCentreSafDefaultByCostCent (all) (Read) (NoCache)
           (input viCurrentCompanyID, (CompanyId)
            input icCostCenterCode, (CostCentre)
            output dataset tqCostCentreSafDefaultByCostCent) in BCostCentre>
        for each tqCostCentreSafDefaultByCostCent no-lock:
            if tqCostCentreSafDefaultByCostCent.tiSafConcept_ID = tqSafForStrctureLine.tiSafConcept_ID
            then assign tqSafForStrctureLine.tiSaf_ID  = tqCostCentreSafDefaultByCostCent.tiSaf_ID
                        tqSafForStrctureLine.tcSafCode = tqCostCentreSafDefaultByCostCent.tcSafCode.
        end.
    end.
    else if viGLId > 0
    then do: /* using gl saf structure */
        /* get gl default safconcept and saf code */
        <Q-72 run GLSafDefaultByGL (all) (Read) (NoCache)
           (input viCurrentCompanyID, (CompanyId)
            input ?, (GLCode)
            input viGLId, (GLID)
            output dataset tqGLSafDefaultByGL) in BGL>
        for each tqGLSafDefaultByGL no-lock:
            if tqGLSafDefaultByGL.tiSafConcept_ID = tqSafForStrctureLine.tiSafConcept_ID
            then assign tqSafForStrctureLine.tiSaf_ID  = tqGLSafDefaultByGL.tiSaf_ID
                        tqSafForStrctureLine.tcSafCode = tqGLSafDefaultByGL.tcSafCode.
        end.
    end.

    /* get saf concept code and saf code base saf id */
    <Q-80 run SafPrim (all) (Read) (NoCache)
        (input tqSafForStrctureLine.tiSaf_ID, (SafID)
         input ?, (SafCode)
         input ?, (SafConceptCode)
         output dataset tqSafPrim) in BSaf>
    find first tqSafPrim no-lock no-error.
    if available tqSafPrim
    then do:
        if vcActivityCode = "Create" or vcActivityCode = "Modify" then
        do:
            create tApiDeductionCatLineSaf.
            assign tApiDeductionCatLineSaf.DeductionCatLine_ID = tDeductionCatLine.DeductionCatLine_ID
                   tApiDeductionCatLineSaf.Saf_ID              = tqSafForStrctureLine.tiSaf_ID
                   tApiDeductionCatLineSaf.tcSafCode           = tqSafPrim.tcSafCode
                   tApiDeductionCatLineSaf.tcSafConceptCode    = tqSafPrim.tcSafConceptCode
                   tApiDeductionCatLineSaf.tc_ParentRowid      = tDeductionCatLine.tc_Rowid
                   tApiDeductionCatLineSaf.tc_Rowid            = ?
                   tApiDeductionCatLineSaf.tc_Status           = "N":U.
       end.
       else
       do:
            create tApiDeductionCatLineSaf.
            assign tApiDeductionCatLineSaf.DeductionCatLine_ID = 0
                   tApiDeductionCatLineSaf.Saf_ID              = tqSafForStrctureLine.tiSaf_ID
                   tApiDeductionCatLineSaf.tcSafCode           = tqSafPrim.tcSafCode
                   tApiDeductionCatLineSaf.tcSafConceptCode    = tqSafPrim.tcSafConceptCode
                   tApiDeductionCatLineSaf.tc_ParentRowid      = ""
                   tApiDeductionCatLineSaf.tc_Rowid            = ?
                   tApiDeductionCatLineSaf.tc_Status           = "N":U.
       end.
    end.
end. /* for each tqSafForStrctureLine no-lock: */