project QadFinancials > class BPosting > method AdditionalUpdatesTemplate

Description

UpdateTemplate


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.AdditionalUpdates


program code (program5/bposting.p)

    
    /* Exception handling */
    assign oiReturnStatus = -98.
    
    /* Check for any action required to take */
    if (vcTemplateLoadedList = "":U or
        vcTemplateLoadedList = ?)   and (
        not can-find(first tPosting where
                          (tPosting.tc_Status      = "N":U or 
                           tPosting.tc_Status      = "C":U)   and
                           tPosting.tcTemplateCode <> "":U    and
                           tPosting.tcTemplateCode <> ?) and  
        not can-find(first t_iPosting where 
                           t_iPosting.tcTemplateCode <> "":U    and
                           t_iPosting.tcTemplateCode <> ?))
    then do : 
        assign oiReturnStatus = 0.
        return.
    end. /* if (vcTemplateLoadedList = "":U or */
    
    /* Start/Open BPostingTemplate */
    <I-5 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BPostingTemplate"}>
    
    /* Start block: errors are kept in viLocalReturnStatus */
    /* In case of errors, the block is left                */
    TEMPLATEUPDATEBLOCK : DO :
    
        /* Go through all vcTemplateLoadedList-entries (tripple-pipe separated) */
        do viCounter = num-entries(vcTemplateLoadedList,chr(4)) to 1 by -1 : 
            
            /* Get the company-id and the template-code out of the list                                                     */
            /* Structure of vcTemplateLoadedList :                                                                          */
            /* Assign vcTemplateLoadedList :                                                                                */
            /* chr(4) separated list of the Company-id and Template-codes that have been loaded into postings               */
            /* of current business-class-instance. The Company-id and Template-code are chr(2) separated.                   */
            /* (this is used for saving updated template).                                                                  */
            /* Example: 001<chr(2)>TemplateA<chr(4)>002<chr(2)>TemplateB                                                    */
            assign vcEntryPostingTemplateList  = entry(viCounter,vcTemplateLoadedList,chr(4))
                   vcSinglePostingTemplateCode = entry(2,vcEntryPostingTemplateList,chr(2))
                   viSinglePostingTemplateCyID = integer(entry(1,vcEntryPostingTemplateList,chr(2)))
                   no-error.
            if error-status:error
            then do :
                assign vcMessage = trim(#T-13'An internal error occurred while separating the posting template information.':255(62520)t-13#).
                if error-status:num-messages > 0
                then assign vcMessage = vcMessage + chr(10) + 
                                        trim(substitute(#T-12'Detailed info: &1 (&2)':500(62519)T-12#,ERROR-STATUS:GET-MESSAGE(1),string(ERROR-STATUS:GET-NUMBER(1)))).
                assign vcMessage = vcMessage + chr(10) + 
                                   trim(substitute(#T-15'Complete list of template information &1':255(62531)t-15#,vcTemplateLoadedList)) + chr(10) + 
                                   trim(substitute(#T-16'Current entry in the list of template information &1':255(62532)t-16#,vcTemplateLoadedList)) + chr(10) + 
                                   trim(substitute(#T-17'The template code in the current entry in the list of template information is &1.':255(62533)t-17#,vcSinglePostingTemplateCode)) + chr(10) + 
                                   trim(substitute(#T-18'The company ID in the current entry in the list of template information is &1.':255(62534)t-18#,string(viSinglePostingTemplateCyID))) .
                <M-14 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QadFin-6358':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPosting>
                assign viLocalReturnStatus = -1.
                Leave TEMPLATEUPDATEBLOCK.
            end. /* if error-status:error */
            
            /* Update the NumberTimesUsed of the template */
            <M-11 run UpdateTemplateTimesUsed
               (input  viSinglePostingTemplateCyID (iiCompanyId), 
                input  vcSinglePostingTemplateCode (icTemplateCode), 
                output viFcReturnSuper (oiReturnStatus)) in BPostingTemplate>
            if viFcReturnSuper <> 0 
            then assign viLocalReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then Leave TEMPLATEUPDATEBLOCK.
            
        end. /* do viCounter = num-entries(vcTemplateLoadedList,chr(4)) to 1 by -1 */
        /* Go through all posting wherefor a template will be removed. */
        for each t_iPosting where t_iPosting.tcTemplateCode <> '' and 
                                    t_iPosting.tcTemplateCode <> ? and 
                                    t_iPosting.tlSaveAsTemplate = true:
             find first tPosting where  tPosting.tc_Status      <> "D":U   and
                                    tPosting.Posting_ID = t_iPosting.Posting_ID and 
                                    tPosting.tlSaveAsTemplate = false and 
                                    (tPosting.tcTemplateCode = '':U or tPosting.tcTemplateCode = ? ) no-error.
             if available tPosting then
             do:
                /* Update the template */
                <M-57 run UpdateOrCreateTemplate
                   (input  tPosting.Company_ID (iiCompanyId), 
                    input  tPosting.tcTemplateCode (icTemplateCode), 
                    input  tPosting.Posting_ID (iiPostingID), 
                    input  '':U (icBusinessRelationCode), 
                    input  ? (icDivisionCode), 
                    input  ? (icCostCentreCode), 
                    input  ? (icProjectCode), 
                    output viFcReturnSuper (oiReturnStatus)) in BPostingTemplate>
                if viFcReturnSuper <> 0 
                then assign viLocalReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0
                then Leave TEMPLATEUPDATEBLOCK.
             end.
        end.
        /* Go through all posting wherefor a template should be created or updated */
        for each tPosting where
                 tPosting.tc_Status      <> "D":U   and
                 tPosting.tcTemplateCode <> "":U    and
                 tPosting.tcTemplateCode <> ?       and 
                 tPosting.tlSaveAsTemplate = true:

            /* Check for nothing-changed in the parts that are applicable for template-updates */
            if tPosting.tc_Status = "":U and 
               not can-find (first tPostingLine where 
                                   tPostingLine.tc_ParentRowid = tPosting.tc_Rowid and 
                                   (tPostingLine.tc_Status = "N":U or 
                                    tPostingLine.tc_Status = "C":U)) 
            then next.
                  
            /* Validation */
            if tPosting.tc_Status = "C":U
            then do:
                find t_iPosting where
                     t_iPosting.tc_Rowid = tPosting.tc_Rowid
                     no-lock no-error.
                if not available t_iPosting
                then do:
                    <M-9 run SetMessage
          (input  trim(#T-10'Cannot find initial values for posting $1 $2 $3.':250(60966)t-10#) (icMessage), 
           input  string(tPosting.PostingYear) + chr(2) + tPosting.tcJournalCode + chr(2) + string(tPosting.PostingVoucher) (icArguments), 
           input  '':U (icFieldName), 
           input  '':U (icFieldValue), 
           input  'E':U (icType), 
           input  3 (iiSeverity), 
           input  '':U (icRowid), 
           input  'QadFin-6230':U (icFcMsgNumber), 
           input  '':U (icFcExplanation), 
           input  '':U (icFcIdentification), 
           input  '':U (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    assign viLocalReturnStatus = -1.
                    Leave TEMPLATEUPDATEBLOCK.
                end. /* if not available t_iPosting */
                
            end. /* if tPosting.tc_Status = "C":U */
            
            /* Get the division, cost-centre and project if possible */

            assign vcDivision = "":U.
            for each tPostingLine where
                     tPostingLine.tc_ParentRowid  = tPosting.tc_Rowid and
                     tPostingLine.tcDivisionCode <> "":U:
                if vcDivision = "":U
                then assign vcDivision = tPostingLine.tcDivisionCode.
                else
                if vcDivision <> tPostingLine.tcDivisionCode
                then do:
                    assign vcDivision = "":U.
                    leave.
                end.
            end.

            assign vcCostCentre = "":U.
            for each tPostingLine where
                     tPostingLine.tc_ParentRowid    = tPosting.tc_Rowid and
                     tPostingLine.tcCostCentreCode <> "":U:
                if vcCostCentre = "":U
                then assign vcCostCentre = tPostingLine.tcCostCentreCode.
                else
                if vcCostCentre <> tPostingLine.tcCostCentreCode
                then do:
                    assign vcCostCentre = "":U.
                    leave.
                end.
            end.
            assign vcProject = "":U.
            for each tPostingLine where
                     tPostingLine.tc_ParentRowid = tPosting.tc_Rowid and
                     tPostingLine.tcProjectCode <> "":U:
                if vcProject = "":U
                then assign vcProject = tPostingLine.tcProjectCode.
                else
                if vcProject <> tPostingLine.tcProjectCode
                then do:
                    assign vcProject = "":U.
                    leave.
                end.
            end.

            /* Update the template */
            <M-2 run UpdateOrCreateTemplate
               (input  tPosting.Company_ID (iiCompanyId), 
                input  tPosting.tcTemplateCode (icTemplateCode), 
                input  tPosting.Posting_ID (iiPostingID), 
                input  '':U (icBusinessRelationCode), 
                input  vcDivision (icDivisionCode), 
                input  vcCostCentre (icCostCentreCode), 
                input  vcProject (icProjectCode), 
                output viFcReturnSuper (oiReturnStatus)) in BPostingTemplate>
            if viFcReturnSuper <> 0 
            then assign viLocalReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then Leave TEMPLATEUPDATEBLOCK.
            
        end. /* for each tPosting where */
        
        /* Validate the BPostingTemplate class */
        <M-8 run ValidateBCAndAdditionalUpdates
           (output viFcReturnSuper (oiReturnStatus)) in BPostingTemplate>
        if viFcReturnSuper <> 0 
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then Leave TEMPLATEUPDATEBLOCK.
        
    END. /* TEMPLATEUPDATEBLOCK */
    
    /* ========================================================================================================= */
    /* Normally we would here close BPostingTemplate but we will not do it for performance                       */
    /* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it.     */
    /* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the  */
    /* appserver that is executed after each call to the appserver                                               */
    /* ========================================================================================================= */

    /* Check for errors */
    if viLocalReturnStatus < 0
    then do :
        assign oiReturnStatus = viLocalReturnStatus.
        Return.
    end. 
    
    /* Exception handling */
    assign oiReturnStatus = viLocalReturnStatus.