project QadFinancials > class BPosting > method Calculate

Description

Add code here to initialize the calculated fields of the class temp-tables after loading existing records from the application database.


Parameters


oiReturnStatusoutputinteger


Internal usage


QadFinancials
method BPosting.MassReversePeriodicCostingPostings
method BPosting.MyDataLoad


program code (program/bposting.p)

/* When doing multiple dataloads without clearing the instance, the code within the loop is performed much too many times. */
/* We will add the possibility to run the calculate method logic only once to gain performance.                            */
/* An example of this can be seen in DataLoadByInput.  Setting the class data item will determine whether to run the logic */
    <ANCESTOR-CODE>
    
    assign viLocalReturnStatus           = oiReturnStatus
           oiReturnStatus                = -98
           vlQueryStartedPostingTemplate = false
           vlJournalAccessAllowed        = true.
    
    POSTINGBLOCK:
    do:
        for each tPosting,
            each t_iPosting where
                 t_iPosting.tc_Rowid = tPosting.tc_Rowid:
            
            if vlDataLoadKeepPrevious and 
               can-find (tAlreadyCalculatedRecords where
                         tAlreadyCalculatedRecords.tcTableName = "Posting" and
                         tAlreadyCalculatedRecords.tc_Rowid    = tPosting.tc_Rowid)
            then next.

            if tPosting.PostingSystemDate = ?
            then assign tPosting.PostingSystemDate = today.
        
            /*set base currency and statutory currency code by company_id */
            <M-91 run GetBaseAndStatCurrecyByCompanyID
               (input  tPosting.Company_ID (iiCompanyID), 
                output vcBaseCurrencyCode (ocBaseCurrencyCode), 
                output vcStatutoryCurrencyCode (ocStatutoryCurrencyCode), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            if viFcReturnSuper < 0 then do:
                assign tPosting.tcLocalCurrency             = vcCompanyLC
                       tPosting.tcStatutoryCurrency         = vcCompanyCC
                       tPosting.tlJournalAccessAllowed      = vlJournalAccessAllowed.  
            end.
            else do:
                assign tPosting.tcLocalCurrency             = vcBaseCurrencyCode
                       tPosting.tcStatutoryCurrency         = vcStatutoryCurrencyCode
                       tPosting.tlJournalAccessAllowed      = vlJournalAccessAllowed.
            end.  
            
            for each tPostingLine where
                     tPostingLine.tc_ParentRowid = tPosting.tc_Rowid,
                each t_iPostingLine where
                     t_iPostingLine.tc_Rowid = tPostingLine.tc_Rowid:
             
                assign tPostingLine.tlPostingLineIsLocalCurrency = ?.
                
                if tPostingLine.Currency_ID = viCompanyLCId
                then do:
                    assign tPostingLine.tlPostingLineIsLocalCurrency    = true
                           t_iPostingLine.tlPostingLineIsLocalCurrency  = tPostingLine.tlPostingLineIsLocalCurrency.
                    next.
                end.        
                
                /* Set the calculated fields in t_iPostingLine */
                assign tPostingLine.tlPostingLineIsLocalCurrency   = false
                       t_iPostingLine.tlPostingLineIsLocalCurrency = tPostingLine.tlPostingLineIsLocalCurrency.
            end.
            
            /* State the template-code */
            if vlQueryStartedPostingTemplate = false
            then do:
                <Q-8 run PostingTemplateByCyPostingID  (Start) in BPostingTemplate >
                assign vlQueryStartedPostingTemplate = true.
            end. /* if vlQueryStartedPostingTemplate = false */
        
            <Q-7 run PostingTemplateByCyPostingID (all) (Read) (NoCache)
               (input tPosting.Company_ID, (CompanyId)
                input tPosting.Posting_ID, (PostingId)
                output dataset tqPostingTemplateByCyPostingID) in BPostingTemplate >
            find tqPostingTemplateByCyPostingID where
                 tqPostingTemplateByCyPostingID.tiCompany_ID = tPosting.Company_ID and
                 tqPostingTemplateByCyPostingID.tiPosting_ID = tPosting.Posting_ID
                 no-lock no-error.
            if available tqPostingTemplateByCyPostingID
            then assign tPosting.tcTemplateCode   = tqPostingTemplateByCyPostingID.tcPostingTemplateCode
                        tPosting.tlSaveAsTemplate = true.
        
            /* Set the calculated fields in t_iPosting */
            assign t_iPosting.tcLocalCurrency             = tPosting.tcLocalCurrency 
                   t_iPosting.tcStatutoryCurrency         = tPosting.tcStatutoryCurrency          
                   t_iPosting.tcTemplateCode              = tPosting.tcTemplateCode
                   t_iPosting.tlSaveAsTemplate            = tPosting.tlSaveAsTemplate.

            /* Check the Journal Access */
            if tPosting.tcJournalTypeCode = {&JOURNALTYPE-JOURNALENTRY} or
               tPosting.tcJournalTypeCode = {&JOURNALTYPE-CONSOLIDATION} or
               tPosting.tcJournalTypeCode = {&JOURNALTYPE-CIREC}
            then do:   
                assign vhFcComponent = ?.
                <M-32 run CheckJournalRole
                   (input  viUsrId (iiUserID), 
                    input  ? (icUserCode), 
                    input  tPosting.Journal_ID (iiJournalID), 
                    input  ? (icJournalCode), 
                    input  tPosting.Company_ID (iiCompanyID), 
                    input  ? (icCompanyCode), 
                    input  viSessionID (iiSessionID), 
                    output vcMessage (ocErrorMessage), 
                    output vlJournalAccessAllowed (olJournalAccessAllowed), 
                    output viFcReturnSuper (oiReturnStatus)) in TJournalRole>
                if viFcReturnSuper <> 0
                then assign viLocalReturnStatus = viFcReturnSuper.

                run gipr_DeleteProcedure in vhFcComponent.
                delete procedure vhFcComponent.        
                
                if viLocalReturnStatus <> 0
                then do:
                    assign vcMsgExplanation = <M-6 GetErrorExplanation
                                                 (input  tPosting.tc_Rowid (icPostingRowId), 
                                                  input  ? (icPostingLineRowId), 
                                                  output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                                  
                    <M-15 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  'tPosting.tcJournalCode':U (icFieldName), 
                        input  tPosting.tcJournalCode (icFieldValue), 
                        input  'E':U (icType), 
                        input  1 (iiSeverity), 
                        input  tPosting.tc_Rowid (icRowid), 
                        input  'QadFin-471404':U (icFcMsgNumber), 
                        input  vcMsgExplanation (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BPosting>
                end.
                
                assign tPosting.tlJournalAccessAllowed = vlJournalAccessAllowed.        
                
                if tPosting.tlJournalAccessAllowed  <> true
                then do:
                    assign vcMessage           = #T-42'You are not authorized to modify, delete or reverse records in daybook &1':100(14551823)T-42#
                           vcMessage           = substitute(vcMessage, tPosting.tcJournalCode)
                           viLocalReturnStatus = 1.  
                    <M-21 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  'tPosting.tcJournalCode':U (icFieldName), 
                        input  tPosting.tcJournalCode (icFieldValue), 
                        input  'W':U (icType), 
                        input  3 (iiSeverity), 
                        input  tPosting.tc_Rowid (icRowid), 
                        input  'QadFin-629401':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BPosting>
                end.          
            end. /* if tPosting.tcJournalTypeCode = {&JOURNALTYPE-JOURNALENTRY} */              
                   
        end.
            
        /* ============================================================================== */
        /* Due to changed functionality the value of PostingSafParentType can still be    */
        /* in lower-case allthough the UI (that may be case sensitive) requires the value */
        /* in uppercase;                                                                  */
        /* ============================================================================== */
        for each tPostingSaf :
            assign tPostingSaf.PostingSafParentType = Caps(tPostingSaf.PostingSafParentType) no-error.    
        end. /* for each tPostingSaf */
        
        <M-3 run CalculateOpenItems (output viFcReturnSuper (oiReturnStatus)) in BPosting>
        if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then leave POSTINGBLOCK.
        
        <M-5 run CalculateCrossCy (output viFcReturnSuper (oiReturnStatus)) in BPosting>
        if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then leave POSTINGBLOCK.
    end. /* POSTINGBLOCK */
    
    if vlQueryStartedPostingTemplate = true
    then do:
        <Q-10 run PostingTemplateByCyPostingID  (Stop) in BPostingTemplate >
        assign vlQueryStartedPostingTemplate = false.
    end. /* if vlQueryStartedPostingTemplate = true */
    
    assign oiReturnStatus = viLocalReturnStatus.