project QadFinancials > class BMfgAllocationAccount > method BuildAllocationAccountStructure

Description

Build the structure to return in GetAllocationAccountStructure.


Parameters


icDomainCodeinputcharacterDomain Code
icAllocationCodeinputcharacterAllocation Code
idTotalPercentageinputdecimalTotal Percentage into which this Allocation Code needs to be spread. The top allocation code always needs to start from 100 percent.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BMfgAllocationAccount.BuildAllocationAccountStructure
method BMfgAllocationAccount.GetAllocationAccountStructure


program code (program1/bmfgallocationaccount.p)

/* Check input variables */
if icDomainCode     = "" or
   icDomainCode     = ?  or
   icAllocationCode = "" or
   icAllocationCode = ?
then do:
    assign vcMessage      = substitute(#T-53'A Domain Code (&1) and an Allocation Code (&2) need to be passed in order to retrieve its structure.':255(640877468)T-53#, icDomainCode, icAllocationCode)
           oiReturnStatus = -1.
    <M-63 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  icAllocationCode (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'qadfin-544597':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BMfgAllocationAccount>
    return.
end. /* if icDomainCode     = "" or */

/* We need to use a dynamic query, because the query temp-table will be cleared with every iteration of the recursive method */
create buffer vhAldDet for table "ald_det".
create query vhQueryHandle.
vhQueryHandle:SET-BUFFERS(vhAldDet).
vhQueryHandle:QUERY-PREPARE("FOR EACH ald_det WHERE ald_det.ald_domain = '" + icDomainCode + "' AND ald_det.ald_code = '" + icAllocationCode + "' NO-LOCK").
vhQueryHandle:QUERY-OPEN().
vhQueryHandle:GET-FIRST().

do while not vhQueryHandle:QUERY-OFF-END:    
    assign vcDomain     = string(vhAldDet::ald_domain)
           vcCode       = string(vhAldDet::ald_code)
           vcAccount    = string(vhAldDet::ald_acc)
           vcSubAccount = string(vhAldDet::ald_sub)
           vcCostCenter = string(vhAldDet::ald_cc)
           vcProject    = string(vhAldDet::ald_project)
           vdPercentage = decimal(vhAldDet::ald_pct).

    /* Check if the GL is not an allocation code, if so run again */
    <Q-55 assign vlFcQueryRecordsAvailable = AlMstrByDomainCode (NoCache)
       (input vcDomain, (Domain)
        input vcAccount, (Code)) in BMfgAllocationAccount>

    if vlFcQueryRecordsAvailable = true
    then do:
        <M-23 run BuildAllocationAccountStructure
           (input  vcDomain (icDomainCode), 
            input  vcAccount (icAllocationCode), 
            input  vdPercentage * idTotalPercentage / 100 (idTotalPercentage), 
            output viFcReturnSuper (oiReturnStatus)) in BMfgAllocationAccount>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then return.
    end. /* if vlFcQueryRecordsAvailable = true */
    else do:
        create tAllocationStruct.
        assign tAllocationStruct.tcGLCode         = vcAccount
               tAllocationStruct.tcDivisionCode   = vcSubAccount
               tAllocationStruct.tcCostCentreCode = vcCostCenter
               tAllocationStruct.tcProjectCode    = vcProject
               tAllocationStruct.tdPercentage     = vdPercentage * (idTotalPercentage / 100).               
    end. /* else do: */  
          
    vhQueryHandle:GET-NEXT().
end. /* do while not vhQueryHandle:query-of-end: */

vhQueryHandle:QUERY-CLOSE().

delete object vhAldDet.
delete object vhQueryHandle.