project BLF > class BCompany > method AdditionalUpdates

Description

This method is part of the SetPublicTables flow.
When executed, data in the input class tables (prefix t_s) is validated and found correct, and copied into the class tables (prefix t_o).
This method can be extended to do updates that do not require a validation or that involve running business methods of other business classes. These classes should be started with ADD-TO-TRANSACTION = 'true'. Also make sure to add these classes in method StopExternalInstances.


Parameters


oiReturnStatusoutputinteger


Internal usage


BLF
method BCompany.ApiSynchronise
method BCompany.SynchronizeSharedSet

QadFinancials
method BCompany.ApiStdMaintainTT
method BCompany.ValidateBCAndAdditionalUpdates


program code (program/bcompany.p)

    /* ================================================================================= */
    /* Validation: for a company there should be an underlaying CompanySharedSet record  */
    /* for every type of SharedSet. The reason that this validation was written here, is */
    /* that this is the first place where you have all records of an instance available. */
    /* In method ValidateComponent, you do not have records with tc_status = "":U        */
    /* ================================================================================= */
    assign vcListSharedSetTypeCode = <M-5 GetSharedSetTypes () in BCompany>.
    for each tCompany where 
             tCompany.tc_Status <> "D":U on error undo, throw:
        do viSharedSetCounter = num-entries(vcListSharedSetTypeCode,chr(2)) to 1 by -2 :
            find tCompanySharedSet where 
                 tCompanySharedSet.tc_ParentRowid        = tCompany.tc_Rowid and
                 tCompanySharedSet.tc_Status            <> "D":U             and
                 tCompanySharedSet.tcSharedSetTypeCode   = entry(viSharedSetCounter,vcListSharedSetTypeCode,chr(2)) 
                 no-lock no-error.
            if not available tCompanySharedSet
            then do :
                assign oiReturnStatus = -1.
                find first tCompanySharedSet where 
                           tCompanySharedSet.tc_ParentRowid        = tCompany.tc_Rowid and
                           tCompanySharedSet.tc_Status            <> "D":U             and
                           tCompanySharedSet.tcSharedSetTypeCode   = entry(viSharedSetCounter,vcListSharedSetTypeCode,chr(2)) 
                           no-lock no-error.
                if not available tCompanySharedSet
                then assign vcMessage = trim(substitute(#T-1'The entity (&1) has no shared set of type '&2'.':100(6601)T-1#,tCompany.CompanyCode,entry(viSharedSetCounter - 1,vcListSharedSetTypeCode,chr(2)))).
                else assign vcMessage = trim(substitute(#T-2'The entity (&1) has multiple shared sets of type '&2'.':100(6602)T-2#,tCompany.CompanyCode,entry(viSharedSetCounter - 1,vcListSharedSetTypeCode,chr(2)))) + chr(10) + trim(#T-3'Only one specification is allowed per shared set type.':255(6603)T-3#).
                <M-4 run SetMessage (input  vcMessage (icMessage), 
                     input  '' (icArguments), 
                     input  '' (icFieldName), 
                     input  '' (icFieldValue), 
                     input  'E':U (icType), 
                     input  3 (iiSeverity), 
                     input  '' (icRowid), 
                     input  'BLF-45':U (icFcMsgNumber), 
                     input  '' (icFcExplanation), 
                     input  '' (icFcIdentification), 
                     input  '' (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BCompany>
            end. /* if not available tCompanySharedSet */
        end. /* do */
    end. /* for each tCompany where */

<ANCESTOR-CODE>

/*link new companies to users that are logins for daemons*/
empty temp-table tLinkCompanyToDaemonUsersCall.
For Each tCompany Where
         tCompany.tc_Status = 'N':U and
         tCompany.CompanyCode <> "999 - SYSADM":U on error undo, throw:
    create tLinkCompanyToDaemonUsersCall.
    Assign tLinkCompanyToDaemonUsersCall.tcCompanyCode = tCompany.CompanyCode
           tLinkCompanyToDaemonUsersCall.tcDomainCode  = tCompany.tcDomainCode
           tLinkCompanyToDaemonUsersCall.tiDomainId    = tCompany.Domain_ID.
End.

If can-find (first tLinkCompanyToDaemonUsersCall)
Then Do:    
    <I-12 {bFcAddToTransaction
         &CLASS           = "BUser"}>
    <M-8 run LinkCompanyToDaemonUsers
       (input  tLinkCompanyToDaemonUsersCall (tLinkCompanyToDaemonUsers), 
        output viFcReturnSuper (oiReturnStatus)) in BUser>    
    <I-9 {bFcCloseInstance
            &CLASS           = "BUser"}>
         
    If viFcReturnSuper <> 0
    Then Assign oiReturnStatus = viFcReturnSuper.
    If viFcReturnSuper < 0
    Then Do:
        <M-11 run StopExternalInstances
           (output viFcReturnSuper (oiReturnStatus)) in BCompany>
        Return.
    End.
End.

/* ================================================================= */
/* When deleting a company also delete all related violations.       */
/* This cannot be done with a cascaded delete in the data model as   */
/* this delete must also trigger a create in the SODLog table.       */
/* ================================================================= */
if can-find (first tCompany where tCompany.tc_Status = "D")
then do:
    <Q-21 assign vlFcQueryRecordsAvailable = SystSODActive (NoCache)  () in BSystem >
    if vlFcQueryRecordsAvailable
    then do:
        <I-13 {bFcAddToTransaction
             &CLASS           = "BSODViolationRule2"}>
    
        for each tCompany where tCompany.tc_Status = "D" on error undo, throw:
            <M-20 run DeleteByUserRoleCompanyCategory
               (input  0 (iiUsrID), 
                input  0 (iiRoleID), 
                input  0 (iiDomainID), 
                input  tCompany.Company_ID (iiCompanyID), 
                input  0 (iiSODCategory1ID), 
                input  0 (iiSODCategory2ID), 
                output viFcReturnSuper (oiReturnStatus)) in BSODViolationRule2>
            if viFcReturnSuper = -4
            then viFcReturnSuper = 0.
            else vlDeletesDone = yes.
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then do:
                <M-15 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BCompany>
                return.
            end.
        end.
    
        if vlDeletesDone
        then do:
            <M-16 run DeleteFinish  (output viFcReturnSuper (oiReturnStatus)) in BSODViolationRule2>
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then do:
                <M-17 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BCompany>
                return.
            end.
            <I-18 {bFcCloseInstance
                 &CLASS           = "BSODViolationRule2"}>
        end.
        else do:
            <I-19 {bFcCloseAndStopInstance
                 &CLASS           = "BSODViolationRule2"}>
        end.
    end.
end.

/* ================================================================= */
/* BLF-1645                                                          */
/* On acticating a company, create folders for the scan daemon.      */
/* ================================================================= */
for each tCompany where
         tCompany.CompanyIsActive = yes and
        (tCompany.tc_Status = "N" or
         tCompany.tc_Status = "C") on error undo, throw:

    if tCompany.tc_Status = "C"
    and can-find (first t_iCompany where
                        t_iCompany.tc_Rowid = tCompany.tc_Rowid and
                        t_iCompany.CompanyIsActive = yes)
    then next.

    <Q-53 run ScanDaemonLocationInfo (all) (Read) (NoCache)
       (input 0, (CompanyId)
        output dataset tqScanDaemonLocationInfo) in BScanDaemon>
    for each tqScanDaemonLocationInfo where
             tqScanDaemonLocationInfo.tiCompany_ID = 0:
        os-create-dir value (tqScanDaemonLocationInfo.tcScanDaemonLocationDir + "/" + tCompany.CompanyCode) no-error.
    end.
end.