project QadFinancials > class BYearClosing > method CalculateBalanceByDivDIRECT


Parameters


iiCompanyIDinputinteger
icLayerTypeCodeinputcharacter
ilGLIsBalanceAccountinputlogical
iiYearPeriodFrominputinteger
iiYearPeriodTillinputinteger
ilIsInclDivisioninputlogical
oiPostingHistRecordsReadoutputinteger
icLayerCodeinputcharacterInput parameter: Layer Code
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BYearClosing.AdditionalUpdatesPostingTrans


program code (program5/byearclosing.p)

/* ================================================================================== */
/* This method builds up the P&L Balances for each Division                           */
/* It queries PostingHist directly for this                                           */
/* Input:                                                                             */
/*    iiCompanyID                                                                     */
/*    icLayerCode                                                                     */
/*    ilGLIsBalanceAccount                                                            */
/*    iiYearPeriodFrom                                                                */
/*    iiYearPeriodTill                                                                */
/*    ilIsInclDivision                                                                */
/* Output                                                                             */
/*    tPLAmounts                                                                      */
/* ================================================================================== */

/* Ensure, all parameters are passed */
if iiCompanyID      = ? or iiCompanyID      = 0    or
   icLayerTypeCode  = ? or icLayerTypeCode  = "":U or
   iiYearPeriodFrom = ? or iiYearPeriodFrom = 0    or
   iiYearPeriodTill = ? or iiYearPeriodTill = 0    or
   icLayerCode      = ? or icLayerCode      = '':U
then do:
    assign vcMessage = #T-40'Not all mandatory input parameters are populated or they have wrong value.':255(999890330)T-40#
           vcContext = "iiCompanyID=&1|icLayerTypeCode=&2|iiYearPeriodFrom=&3|iiYearPeriodTill=&4|icLayerCode=&5":U
           vcContext = replace(vcContext, "|":U, chr(2))
           vcContext = substitute(vcContext, iiCompanyID, icLayerTypeCode, iiYearPeriodFrom, iiYearPeriodTill, icLayerCode).
    <M-2 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'qadfin-662353':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
    assign oiReturnStatus = -1.
    leave.
end. /* if iiCompanyID = ? or iiCompanyID = 0 or */

empty temp-table tPLAmounts. 

for each Company no-lock where
         Company.Company_ID = iiCompanyID,
    each CompanySharedSet of Company no-lock,
    each SharedSet of CompanySharedSet no-lock where
         SharedSet.SharedSetTypeCode = {&SHAREDSETTYPE-GL},
    first Layer no-lock where
          Layer.LayerTypeCode = icLayerTypeCode and
          Layer.LayerCode     = icLayerCode,
    each GL of SharedSet no-lock where
         GL.GLIsBalanceAccount = if ilGLIsBalanceAccount = ?
                                 then GL.GLIsBalanceAccount
                                 else ilGLIsBalanceAccount :

    for each PostingHist where
             PostingHist.Company_ID                = Company.Company_ID    and
             PostingHist.GL_ID                     = GL.GL_ID              and
             PostingHist.PostingHistYearPeriodFrom >= iiYearPeriodFrom     and
             PostingHist.PostingHistYearPeriodFrom <= iiYearPeriodTill
             no-lock:

        if PostingHist.Layer_ID <> Layer.Layer_ID
        then next.

        assign oiPostingHistRecordsRead = oiPostingHistRecordsRead + 1.

        /* Determine the Division Code */
        assign vcDivisionCode = ''.
        if ilIsInclDivision = True and PostingHist.Division_ID <> 0 and PostingHist.Division_ID <> ?
        then do :
            find Division of PostingHist no-lock no-error.
            if available Division
            then assign vcDivisionCode = Division.DivisionCode.
        end.

        /* Cache the Movements amounts */
        find tPLAmounts where
             tPLAmounts.tcPLAmountsDivisionCode = vcDivisionCode
             no-error.
        if not available tPLAmounts
        then do:
            create tPLAmounts.
            assign tPLAmounts.tcPLAmountsDivisionCode = vcDivisionCode.
        end.
        
        assign tPLAmounts.tdPLAmountsLC = tPLAmounts.tdPLAmountsLC                                  + 
                                          PostingHist.PostingHistMovemntDebitLC -
                                          PostingHist.PostingHistMovemntCreditLC
               tPLAmounts.tdPLAmountsCC = tPLAmounts.tdPLAmountsCC                                  +
                                          PostingHist.PostingHistMovemntDebitCC -
                                          PostingHist.PostingHistMovemntCreditCC.                                           

    end. /* for each PostingHist */

end. /* for each Company */