project QadFinancials > class TSetStatutoryCurrency > method PostingCCBalance

Description

Balance posting in the statutory currency


Parameters


icPostCCBalanceToinputcharacter
ocErrorMessageoutputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method TSetStatutoryCurrency.SetStatutoryCurrencyBasedOnTCPosting


program code (program1/tsetstatutorycurrency.p)

assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.
       
STATCURRBLOCK:
do:   
    /* Calculate balance of the posting */
    assign vdCCBalance               = 0
           viLastPostingLineSequence = 0.

    for each PostingLine of Posting no-lock:
        assign vdCCBalance               = vdCCBalance + PostingLine.PostingLineDebitCC - PostingLine.PostingLineCreditCC
               viLastPostingLineSequence = Max(viLastPostingLineSequence, PostingLine.PostingLineSequence).
    end.


    /* Create additional line to balance SC when needed */
    if vdCCBalance <> 0
    then do:
        if lookup(icPostCCBalanceTo, {&GLSYSTEMTYPE-ROUND} + ",":U + 
                                     {&GLSYSTEMTYPE-EXCHANGEUNREALPROFIT} + ",":U + {&GLSYSTEMTYPE-EXCHANGEUNREALLOSS} + ",":U +
                                     {&GLSYSTEMTYPE-EXCHANGEREALPROFIT} + ",":U + {&GLSYSTEMTYPE-EXCHANGEREALLOSS}) = 0
        then do:
            assign ocErrorMessage = "TSetStatutoryCurrency.PostingSCBalance - input parameter icPostCCBalanceTo is blank or has incorrect value (icPostCCBalanceTo = '"+ icPostCCBalanceTo + "'"
                   oiReturnStatus = -1.
            return.
        end.


        assign viGLAccount = if (icPostCCBalanceTo = {&GLSYSTEMTYPE-ROUND})
                             then viRoundGLID
                             else if icPostCCBalanceTo = {&GLSYSTEMTYPE-EXCHANGEUNREALPROFIT} or
                                     icPostCCBalanceto = {&GLSYSTEMTYPE-EXCHANGEUNREALLOSS}
                             then (if vdCCBalance < 0 
                                   then viExchUnrealProfitGLID
                                   else viExchUnrealLossGLID)
                             else if icPostCCBalanceTo = {&GLSYSTEMTYPE-EXCHANGEREALPROFIT} or
                                     icPostCCBalanceto = {&GLSYSTEMTYPE-EXCHANGEREALLOSS}
                             then (if vdCCBalance < 0 
                                   then viExchRealProfitGLID
                                   else viExchRealLossGLID)
                             else 0.


        create PostingLine.
        assign PostingLine.Posting_ID          = Posting.Posting_ID
               PostingLine.PostingLine_ID      = dynamic-function("GetNextValue":U in vhPersistence,"ObjectNumber":U)
               PostingLine.Currency_ID         = viNewSCID
               PostingLine.GL_ID               = viGLAccount
               PostingLine.PostingLineSequence = viLastPostingLineSequence + 1
               PostingLine.PostingLineText     = "Balanced by Statutory Currency Utility"
               PostingLine.PostingLineDebitTC  = 0
               PostingLine.PostingLineCreditTC = 0
               PostingLine.PostingLineDebitLC  = 0
               PostingLine.PostingLineCreditLC = 0
               PostingLine.PostingLineDebitCC  = (if vdCCBalance < 0 then - vdCCBalance else 0)
               PostingLine.PostingLineCreditCC = (if vdCCBalance > 0 then vdCCBalance   else 0)
               PostingLine.PostingLineCCRate   = 1
               PostingLine.PostingLineCCScale  = 1
               PostingLine.Period_ID           = Posting.Period_ID
               PostingLine.Company_ID          = Posting.Company_ID
               PostingLine.PostingYearPeriod   = Posting.PostingYearPeriod
               PostingLine.PostingDate         = Posting.PostingDate
               PostingLine.LastModifiedDate    = today.
        
        <M-53 run SetStatutoryCurrencyBasedOnTCRound
           (output vcTempErrorMessage (ocErrorMessage), 
            output viFcReturnSuper (oiReturnStatus)) in TSetStatutoryCurrency>
        assign ocErrorMessage = ocErrorMessage + vcTempErrorMessage.
        if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 then leave STATCURRBLOCK.
    end. /* if vdBalanceCC <> 0 */
end. /* STATCURRBLOCK */

assign oiReturnStatus = viLocalReturnStatus.