project QadFinancials > class BCompany > method AdditionalUpdates

Description

This empty method allows to do additional updates on class temp-tables after records were received (and validated) from outside, using method SetPublicTables.
You can start instances of other business classes to do those updates.
- The companyproperty will be updated for each company record.
- Copy initial periods from domain for each new company
- Create default Period Mark records.
- Replicate the company information to the operational table (en_mstr).


Parameters


oiReturnStatusoutputinteger


Internal usage


BLF
method BCompany.ApiSynchronise
method BCompany.SynchronizeSharedSet

QadFinancials
method BCompany.ApiStdMaintainTT
method BCompany.ValidateBCAndAdditionalUpdates


program code (program/bcompany.p)

/* =============================================================================================== */
    /* Before we update companyproperty, we make sure that tCompanyPropertyRef.CompanyPropertyIsActive */
    /* corresponds with tCompanyPropertyRef.CompanyPropertyIsActive                                    */
    /* =============================================================================================== */
    for each tCompany where 
             tCompany.tc_Status <> "D":U,
        each tCompanyPropertyRef where
             tCompanyPropertyRef.Company_ID              = tCompany.Company_ID and
             (tCompanyPropertyRef.CompanyPropertyIsActive <> tCompany.CompanyIsActive or 
              tCompanyPropertyRef.CompanyPropertyCode     <> tCompany.CompanyCode) :
        assign tCompanyPropertyRef.CompanyPropertyIsActive = tCompany.CompanyIsActive
               tCompanyPropertyRef.CompanyPropertyCode     = tCompany.CompanyCode
               tCompanyPropertyRef.tc_ParentRowid          = "":U /* Reset this field allthough it was set in method calculate (just to ease the relation between company and companyproperty) */.
        if tCompanyPropertyRef.tc_Status = "":U
        then assign tCompanyPropertyRef.tc_Status = "C":U.
    end. /* for each tCompany, */

    /* ========================================================================== */
    /* Updates towards CompanyProperty - we first need to assign the tcDomainCode */
    /* ========================================================================== */
    for each tCompany,
        each tCompanyPropertyRef where tCompanyPropertyRef.Company_ID = tCompany.Company_ID:
        assign tCompanyPropertyRef.tcDomainCode = tCompany.tcDomainCode.
        if tCompanyPropertyRef.tc_Status = "":U
        then assign tCompanyPropertyRef.tc_Status = "C":U.        
    end.
    if viBCompanyPropertyID = 0 or
       viBCompanyPropertyID = ?
    then do:
        <I-1 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BCompanyProperty"}>
    end.
    else do:
        <I-4 {bFcOpenInstance
            &CLASS           = "BCompanyProperty"}>
    end.
    
    <M-3 run UpdateCompanyProperty
          (input  tCompanyPropertyRef (tCompanyPropertyRefForUpdates), 
           input  vcActivityCode (icActivityCode), 
           output viReturnRef (oiReturnStatus)) in BCompanyProperty>

    <I-2 {bFcCloseInstance
            &CLASS           = "BCompanyProperty"}>
    if viReturnRef <> 0
    then do:
        /* error handling */
        <M-69 run StopExternalInstances
           (output viFcReturnSuper (oiReturnStatus)) in BCompany>
        assign oiReturnStatus = -1.
        return.
    end.
    
    /* ===================================================== */
    /* Copy initial periods from domain for each new company */
    /* ===================================================== */
    empty temp-table tCompanyList.
        
    for each tCompany where
             tCompany.tc_Status = 'N':U:
             
        empty temp-table tGLCalendarRef.
        
        /* Retrieve the GLCalendar records for this domain */
        if vlStartGLCalendarByYearPeriod = false
        then do:
            <Q-50 run GLCalendarByYearPeriod
               (Start) in BGLCalendar >
            assign vlStartGLCalendarByYearPeriod = true.
        end. /* if vlStartGLCalendarByYearPeriod = false */
        
        <Q-49 run GLCalendarByYearPeriod (all) (Read) (Cache)
           (input tCompany.Domain_ID, (DomainId)
            input 0, (CalendarYear)
            input 0, (CalendarPeriod)
            input 0, (GLCalendarId)
            output dataset tqGLCalendarByYearPeriod) in BGLCalendar >

        if not can-find (first tqGLCalendarByYearPeriod where
                               tqGLCalendarByYearPeriod.tiDomain_ID = tCompany.Domain_ID )
        then do :
            /* In case there are not GL Calenders defined yet, we keep the company in a temp-table */
            /* We will create one PeriodMark directly after this loop */            
            create tCompanyList.
            assign tCompanyList.tiCompanyId = tCompany.Company_ID.
        end.
        
        /* Fill temp-table with GLCalendar records */                                      
        for each tqGLCalendarByYearPeriod where
                 tqGLCalendarByYearPeriod.tiDomain_ID = tCompany.Domain_ID
                 no-lock:                 
            create tGLCalendarRef.    
            <M-51 run BufferCopy (input  buffer tqGLCalendarByYearPeriod:handle (ihFrom), 
                      input  buffer tGLCalendarRef:handle (ihTo), 
                      output viFcReturnSuper (oiReturnStatus)) in BCompany>   
            assign tGLCalendarRef.tc_Status = 'N':U.   
                                   
        end. /* for each tqGLCalendarByYearPeriod where ... */
        
        if not can-find(first tGLCalendarRef)
        then next.
        
        /* Replicate records in BPeriod */
        if viBPeriodInCompanyID = 0 or
           viBPeriodInCompanyID = ?
        then do:
            <I-52 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BPeriod"}>
        end. /* if viBPeriodInCompanyID = 0 or ... */        
        else do:
            <I-53 {bFcOpenInstance
            &CLASS           = "BPeriod"}>       
        end. /* else do */
        
        <M-54 run SynchronizePeriod (input  tGLCalendarRef (t_sGLCalendarForPeriod), 
                             input  tCompany.Company_ID (iiCompanyId), 
                             input  tCompany.tcDomainCode (icDomainCode), 
                             input  tCompany.CompanyCode (icEntityCode), 
                             output viExternalReturnStatus (oiReturnStatus)) in BPeriod>
                             
        <I-55 {bFcCloseInstance
            &CLASS           = "BPeriod"}>
                        
        if viExternalReturnStatus <> 0
        then do:
            assign oiReturnStatus = viExternalReturnStatus.
            if oiReturnStatus < 0
            then leave.
        end. /* if viExternalReturnStatus <> 0 */
    end. /* for each tCompany where tCompany.tc_Status = 'N':U: */
    
    if vlStartGLCalendarByYearPeriod = true
    then do:
        <Q-58 run GLCalendarByYearPeriod  (Stop) in BGLCalendar >
        assign vlStartGLCalendarByYearPeriod = false.
    end. /* if vlStartGLCalendarByYearPeriod = true */
    
    if oiReturnStatus < 0
    then do:
        <M-68 run StopExternalInstances
           (output viFcReturnSuper (oiReturnStatus)) in BCompany>
        return.
    end. /* if oiReturnStatus < 0 */

    /* =============================== */
    /* Updates towards PeriodMark      */
    /* =============================== */
    if can-find (first tCompanyList)
    then do :
        if viBPeriodMarkID = 0 or
           viBPeriodMarkID = ?
        then do :
           <I-60 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BPeriodMark"}>
        end. /* if viBPeriodMarkID = 0 or */
        else do :
           <I-61 {bFcOpenInstance
            &CLASS           = "BPeriodMark"}>
        end. /* if viBPeriodMarkID <> 0  */
        
         <M-62 run CreateDefaultForNewCompany
            (input  tCompanyList (tCompanyListPeriodMark), 
             output viPeriodMarkReturn (oiReturnStatus)) in BPeriodMark>
             
         <I-63 {bFcCloseInstance
            &CLASS           = "BPeriodMark"}>
              
        if viPeriodMarkReturn <> 0
        then do :
            assign oiReturnStatus = viPeriodMarkReturn.
            /* error handling */
            if oiReturnStatus < 0 
            then do :
                <M-67 run StopExternalInstances
                   (output viFcReturnSuper (oiReturnStatus)) in BCompany>
                return.
            end. /* if oiReturnStatus < 0  */
        end. /* if PeriodMarkReturn */
    end. /* if available tCompany */
 
<ANCESTOR-CODE>
        
    /* ======================= */
    /* Updates towards MfgPro  */
    /* ======================= */
    if viBMfgEntityID = 0 or 
       viBMfgEntityID = ?
    then do:
        <I-42 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BMfgEntity"}>
    end. /* if viBMfgEntityID = 0 or viBMfgEntityID = ? */
    else do:
        <I-43 {bFcOpenInstance
            &CLASS           = "BMfgEntity"}>
    end. /* Not if viBMfgEntityID = 0 or viBMfgEntityID = ? */
    <M-47 run MaintainData (input  tCompany (tCompany), 
                        input  tCompanyPropertyRef (tCompanyProperty), 
                        output viLocalReturnStatus (oiReturnStatus)) in BMfgEntity>
    <I-45 {bFcCloseInstance
            &CLASS           = "BMfgEntity"}>
    if viLocalReturnStatus <> 0 then assign oiReturnStatus = viLocalReturnStatus.
    if viLocalReturnStatus < 0 
    then do :
         <M-48 run StopMFGInstances (output viFcReturnSuper (oiReturnStatus)) in BCompany>
        Return.
    end. /* if viLocalReturnStatus < 0  */
        
    /* ======================== */
    /* Set ReturnStatus = OK    */
    /* ======================== */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.