project QadFinancials > class BDomain > 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.
- Updates towards GL masks
- The domainproperty will be updated for each domain record.
- If one of the shared set codes has changed, synchronise the shared sets of the linked companies
- Update Primary company in CompanyProperty record.
- Replication to the operational tables (dom_mstr)


Parameters


oiReturnStatusoutputinteger


Internal usage


BLF
method BDomain.SetDomainTypeAsSystem
method BDomain.SetPrimaryCompany
method BDomain.SynchronizeSharedSet

QadFinancials
method BDomain.ApiSynchronise
method BDomain.ValidateBCAdditionalUpdates


program code (program/bdomain.p)

/* ============================================================= */
/* !!! The automatic updates of GL Mask was put in comments. !!! */
/* Now, there will only be an error/warning                      */
/* PLEASE DO NOT DELETE THE OLD CODE YET                         */
/* ============================================================= */

assign viLocalReturnStatus = oiReturnStatus
       oiReturnStatus      = -98.

/* ============================================ */
/* Updates towards GL-Mask                      */
/* Replicate Currencychange to company property */
/* ============================================ */
empty temp-table tGLMaskUpdatesFromDomain.
empty temp-table tUpdatesFromDomain.
for each tDomainPropertyRefer where
         tDomainPropertyRefer.tc_Status = "C":U  :
    /*
    find tInitialDomainPropertyRefer where
         tInitialDomainPropertyRefer.DomainProperty_ID = tDomainPropertyRefer.DomainProperty_ID and 
         (tInitialDomainPropertyRefer.DomainPropertyIsMaskCC   <> tDomainPropertyRefer.DomainPropertyIsMaskCC   or
          tInitialDomainPropertyRefer.DomainPropertyIsMaskDiv  <> tDomainPropertyRefer.DomainPropertyIsMaskDiv  or
          tInitialDomainPropertyRefer.DomainPropertyIsMaskProj <> tDomainPropertyRefer.DomainPropertyIsMaskProj
         or
          tInitialDomainPropertyRefer.ObsoleteDomPropGLMaskGL   <> tDomainPropertyRefer.ObsoleteDomPropGLMaskGL)  
          
         no-lock no-error.    
    if available tInitialDomainPropertyRefer
    then do :  
        if tInitialDomainPropertyRefer.DomainPropertyIsMaskCC <> tDomainPropertyRefer.DomainPropertyIsMaskCC and
           tDomainPropertyRefer.DomainPropertyIsMaskCC        <> true
        then assign vlRemoveGLMaskCC = true.
        else assign vlRemoveGLMaskCC = ?.
        if tInitialDomainPropertyRefer.DomainPropertyIsMaskProj <> tDomainPropertyRefer.DomainPropertyIsMaskProj and
           tDomainPropertyRefer.DomainPropertyIsMaskProj        <> true
        then assign vlRemoveGLMaskProj = true.
        else assign vlRemoveGLMaskProj = ?.
        
        if tInitialDomainPropertyRefer.ObsoleteDomPropGLMaskGL <> tDomainPropertyRefer.ObsoleteDomPropGLMaskGL and
           tDomainPropertyRefer.ObsoleteDomPropGLMaskGL        <> true
        then assign vlRemoveGLMaskGL = true.
        else assign vlRemoveGLMaskGL = ?.
        
        if tInitialDomainPropertyRefer.DomainPropertyIsMaskDiv <> tDomainPropertyRefer.DomainPropertyIsMaskDiv and
           tDomainPropertyRefer.DomainPropertyIsMaskDiv        <> true
        then assign vlRemoveGLMaskDiv = true.
        else assign vlRemoveGLMaskDiv = ?.
        
        if vlRemoveGLMaskCC   = true or
           vlRemoveGLMaskDiv  = true or
           vlRemoveGLMaskGL   = true or
           vlRemoveGLMaskProj = true
        then do:
            assign vlCCFound   = false
                   vlGLFound   = false
                   vlProjFound = false
                   vlDivFound  = false.
                        
            if vlRemoveGLMaskCC = true
            then do:
                <Q-50 assign vlFcQueryRecordsAvailable = GLMaskByAnalysisFilled (NoCache)
                   (input vlRemoveGLMaskCC, (CostCentreNotNull)
                    input ?, (ProjectNotNull)
                    input ?, (GLNotNull)
                    input ?, (DivisionNotNull)
                    input tDomainPropertyRefer.Domain_ID, (DomainID)) in BGLMask >
                assign vlCCFound = vlFcQueryRecordsAvailable.
            end.
            
            if vlRemoveGLMaskGL = true
            then do:
                <Q-56 assign vlFcQueryRecordsAvailable = GLMaskByAnalysisFilled (NoCache)
                   (input ?, (CostCentreNotNull)
                    input ?, (ProjectNotNull)
                    input vlRemoveGLMaskGL, (GLNotNull)
                    input ?, (DivisionNotNull)
                    input tDomainPropertyRefer.Domain_ID, (DomainID)) in BGLMask >
                assign vlGLFound = vlFcQueryRecordsAvailable.
            end.
            
            if vlRemoveGLMaskDiv = true
            then do:
                <Q-57 assign vlFcQueryRecordsAvailable = GLMaskByAnalysisFilled (NoCache)
                   (input ?, (CostCentreNotNull)
                    input ?, (ProjectNotNull)
                    input ?, (GLNotNull)
                    input vlRemoveGLMaskDiv, (DivisionNotNull)
                    input tDomainPropertyRefer.Domain_ID, (DomainID)) in BGLMask >
                assign vlDivFound = vlFcQueryRecordsAvailable.
            end.
            if vlRemoveGLMaskProj = true
            then do:
                <Q-58 assign vlFcQueryRecordsAvailable = GLMaskByAnalysisFilled (NoCache)
                   (input ?, (CostCentreNotNull)
                    input vlRemoveGLMaskProj, (ProjectNotNull)
                    input ?, (GLNotNull)
                    input ?, (DivisionNotNull)
                    input tDomainPropertyRefer.Domain_ID, (DomainID)) in BGLMask >
                assign vlProjFound = vlFcQueryRecordsAvailable.
            end.

            if vlCCFound <> false or vlGLFound <> false  or vlDivFound <> false or vlProjFound <> false
            then do:
                assign vcMessage           = trim(#T-51'GL Mask records still exist for the GL Mask options you tried to disable.':100(63163)T-51#) + chr(10) +
                                             trim(#T-52'Please remove them in the GL Mask program first.':100(63165)T-52#)
                       viLocalReturnStatus = -1.
                <M-53 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tDomainPropertyRefer.tc_Rowid (icRowid), 
                    input  'QadFin-6408':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDomain>
            end.
        end. /* GL Mask flags unchecked */
        else do:
            assign vcMessage           = trim(#T-55'You have changed the GL mask settings. Use the GL Mask maintenance to specify the valid combinations.':200(999890814)T-55#)
                   viLocalReturnStatus = 1.
            <M-54 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'W':U (icType), 
                input  3 (iiSeverity), 
                input  tDomainPropertyRefer.tc_Rowid (icRowid), 
                input  'QadFin-6409':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDomain>
        end.                     
    end. /* if available tInitialDomainPropertyRefer */
    */
    
    /* Check if the currency or wht flag was changed - need to replicate to each company */
    find tInitialDomainPropertyRefer where
         tInitialDomainPropertyRefer.DomainProperty_ID   = tDomainPropertyRefer.DomainProperty_ID and
        (tInitialDomainPropertyRefer.tcCurrencyCode      <> tDomainPropertyRefer.tcCurrencyCode or
         tInitialDomainPropertyRefer.DomainPropertyIsWHT <> tDomainPropertyRefer.DomainPropertyIsWHT)
         no-lock no-error.
    if available tInitialDomainPropertyRefer 
    then do:
        create tUpdatesFromDomain.
        assign tUpdatesFromDomain.tiDomainID            = tDomainPropertyRefer.Domain_ID
               tUpdatesFromDomain.tcCurrencyCode        = tDomainPropertyRefer.tcCurrencyCode
               tUpdatesFromDomain.tlDomainPropertyIsWHT = tDomainPropertyRefer.DomainPropertyIsWHT.
    end. /* if available tInitialDomainPropertyRefer */
end. /* for each */

/* ============================== */
/* Updates towards DomainProperty */
/* ============================== */
if viBDomainPropertyDomainID = 0 or
   viBDomainPropertyDomainID = ?
then do:
    <I-12 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BDomainProperty"}>
end. /* if viBDomainPropertyDomainID = 0 */
else do:
    <I-13 {bFcOpenInstance
            &CLASS           = "BDomainProperty"}>
end. /* else do */

/* For proper validation DomainProperty needs also DomainSharedSet definition */
empty temp-table tDomainSharedSetRefer.
for each tDomainSharedSet:
    create tDomainSharedSetRefer.
    buffer-copy tDomainSharedSet to tDomainSharedSetRefer.
end.

<M-14 run UpdateDomainProperty
   (input  tDomainPropertyRefer (tDomainPropertyRef), 
    input  tDomainSharedSetRefer (tDomainSharedSetRef), 
    input  vcActivityCode (icActivityCode), 
    output viReturnRef (oiReturnStatus)) in BDomainProperty>

<I-15 {bFcCloseInstance
            &CLASS           = "BDomainProperty"}>
if viReturnRef < 0 or (viReturnRef > 0 and viLocalReturnStatus >= 0)
then assign viLocalReturnStatus = viReturnRef.
if viLocalReturnStatus < 0    
then do:
    /* error handling */
    <M-60 run StopExternalInstances
       (output viFcReturnSuper (oiReturnStatus)) in BDomain>
    assign oiReturnStatus = viLocalReturnStatus.
    return.
end. /* if viReturnRef < 0 */
    
/* =============================================================================================== */
/* If one of the shared set codes has changed, synchronise the shared sets of the linked companies */
/* =============================================================================================== */
assign vlSharedSetChanged = false.
for each tDomainSharedSet where 
         tDomainSharedSet.tc_Status = "C":U,
    each t_iDomainSharedSet where 
         t_iDomainSharedSet.tc_rowid = tDomainSharedSet.tc_rowid and
         t_iDomainSharedSet.SharedSet_ID <> tDomainSharedSet.SharedSet_ID:
    assign vlSharedSetChanged = true.
    leave.
end. /* for each tDomainSharedSet where */
    
if vlSharedSetChanged = true 
then do:
    if viBCompanyDomainID = 0 or
       viBCompanyDomainID = ?
    then do:           
        <I-1 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BCompany"}>    
    end. /* if vlSharedSetChanged = true */
    else do:
        <I-28 {bFcOpenInstance
            &CLASS           = "BCompany"}>
    end. /* else do */

    <M-2 run SharedSetSynchronise (input  tDomainSharedSet (t_sDomainSharedSet), 
                           output viFcReturnSuper (oiReturnStatus)) in BCompany>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viLocalReturnStatus >= 0)
    then assign viLocalReturnStatus = viFcReturnSuper.                
    if viFcReturnSuper >= 0 
    then do:
         <M-22 run ValidateBCAndAdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BCompany>             
         if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viLocalReturnStatus >= 0)
         then assign viLocalReturnStatus = viFcReturnSuper.
    end. /* if viFcReturnSuper >= 0 */
        
    <I-3 {bFcCloseInstance
            &CLASS           = "BCompany"}>                                                                                    
    if viLocalReturnStatus < 0
    then do:
        <M-61 run StopExternalInstances
           (output viFcReturnSuper (oiReturnStatus)) in BDomain>
        assign oiReturnStatus = viLocalReturnStatus.
        return.
    end. /* if viLocalReturnStatus < 0 */
end. /* if vlSharedSetChanged = true */

assign oiReturnStatus = viLocalReturnStatus.
if oiReturnStatus < 0 then return.

<ANCESTOR-CODE>

if oiReturnStatus < 0 then return.
assign oiReturnStatus = -98.

/* Additional update to set the primary company of the domain & unset the old primary company */
if viBCompanyPropertyDomainID = 0 or
   viBCompanyPropertyDomainID = ?
then do:
    <I-32 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BCompanyProperty"}>
end. /* if viBCompanyPropertyDomainID = 0 */
else do:
    <I-33 {bFcOpenInstance
            &CLASS           = "BCompanyProperty"}>                               
end. /* else do */

/* Update the currencies of the companies that are linked to this domain */
if can-find(first tUpdatesFromDomain)
then do:
    <M-36 run ReplicateCompanyFromDomain
       (input  tUpdatesFromDomain (tCurrUpdatesFromDomain), 
        output viFcReturnSuper (oiReturnStatus)) in BCompanyProperty>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus >= 0)
    then assign viLocalReturnStatus = viFcReturnSuper.
end. /* if can-find(first tUpdatesFromDomain) */
                           
UPDATEPRIMARYCOMPANY:
for each tDomains:
     
    if tDomains.tc_Status = "D":U 
    then leave UPDATEPRIMARYCOMPANY.

    if tDomains.tc_Status = "C":U 
    then do:       
         
        /* Skip out if the Domain hasn't been changed... */
        find t_iDomains where 
             t_iDomains.tc_Rowid = tDomains.tc_Rowid
            no-error.
        if not available t_iDomains
        then next.
                        
        if t_iDomains.PrimaryCompany_ID = tDomains.PrimaryCompany_ID 
        then leave UPDATEPRIMARYCOMPANY.
                
        <M-27 run SwitchPrimaryCompany (input  tDomains.PrimaryCompany_ID (iiNewPrimaryCompany_ID), 
                                input  t_iDomains.PrimaryCompany_ID (iiOldPrimaryCompany_ID), 
                                output viFcReturnSuper (oiReturnStatus)) in BCompanyProperty>        
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viLocalReturnStatus >= 0)
        then do:
            assign viLocalReturnStatus = viFcReturnSuper.
            leave.
        end. /* if viFcReturnSuper < 0 ... */
    end. /* if tDomains.tc_Status = "C":U */
    
    if tDomains.tc_Status = "N":U and
      (tDomains.PrimaryCompany_ID <> 0 and tDomains.PrimaryCompany_ID <> ?) 
    then do:
        <M-34 run SwitchPrimaryCompany (input  tDomains.PrimaryCompany_ID (iiNewPrimaryCompany_ID), 
                                input  ? (iiOldPrimaryCompany_ID), 
                                output viFcReturnSuper (oiReturnStatus)) in BCompanyProperty>        
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viLocalReturnStatus >= 0)
        then do:
            assign viLocalReturnStatus = viFcReturnSuper.
            leave.
        end. /* if viFcReturnSuper < 0 ... */               
    end. /* if tDomains.tc_Status = "N":U */
end. /* for each tDomains */

    
/* ========================================================== */                                                                    
/* Run Validations and additional updated in BCompanyProperty */
/* ========================================================== */
<M-37 run ValidateBCAndAdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BCompanyProperty>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viLocalReturnStatus >= 0)    
then assign viLocalReturnStatus = viFcReturnSuper.
                
<I-35 {bFcCloseInstance
            &CLASS           = "BCompanyProperty"}>        
if viLocalReturnStatus < 0
then do:
    <M-62 run StopExternalInstances
       (output viFcReturnSuper (oiReturnStatus)) in BDomain>
    assign oiReturnStatus = viLocalReturnStatus.
    return.
end. /* if viLocalReturnStatus < 0 */

/* ================================================================= */
/* Replicate the domain to MFG/PRO                                   */
/* ================================================================= */
if viBMfgDomainDomainID = 0 or
   viBMfgDomainDomainID = ?
then do:
    <I-5 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BMfgDomain"}>
end. /* if viBMfgDomainDomainID = 0 ...  */
else do:
    <I-31 {bFcOpenInstance
            &CLASS           = "BMfgDomain"}>
end. /* else do: */

<M-6 run MaintainData (input  tDomains (tCopyDomains), 
                   input  tDomainPropertyRefer (tCopyDomainProperty), 
                   output viReturnRef (oiReturnStatus)) in BMfgDomain>
if viReturnRef < 0 or (viReturnRef > 0 and viLocalReturnStatus >= 0)
then assign viLocalReturnStatus = viReturnRef.    
<I-7 {bFcCloseInstance
            &CLASS           = "BMfgDomain"}>   

/* Check to see if there is a multi-dB MFG/PRO environment */
<I-45 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "false"
            &CLASS              = "BMfgDBConnections"}>
<M-49 run IsMultiDB
   (output vlMultiDB (olisMultiDB), 
    output viFcReturnSuper (oiReturnStatus)) in BMfgDBConnections>

if vlMultiDB
then do:
   /* If there are multiple MFG/PRO dbs then either create the domain connection records */
   /* or update them if the active flag has changed. This is not included in the transaction */
   /* If it fails there is a utility program in MFG/PRO which will create these records */
   <I-42 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "false"
            &CLASS              = "PMultiDB"}>
   for each tDomains:
      /* Create domain connection records in all connected MFG/PRO dBs */
      if tDomains.tc_Status = "N":U then do:
         find tDomainPropertyRefer 
            where tDomainPropertyRefer.Domain_ID = tDomains.Domain_ID 
         no-error.
        <M-43 run createConnectionRecordsbyParams
           (input  tDomains.DomainCode (icdomainCode), 
            input  tDomainPropertyRefer.DomainPropertyName (icdomainName), 
            input  tDomainPropertyRefer.DomainPropertySearchName (icdomainSName), 
            output viFcReturnSuper (oiReturnStatus)) in PMultiDB>
      end.
      /* Modify the domain connection records if the active flag has been modified */
      else if tDomains.tc_Status = "C":U then do:
         /* Find t_iDomains.  */
         find t_iDomains where 
              t_iDomains.tc_rowid = tDomains.tc_rowid
         no-error.
         if not available t_iDomains
         then next.

         if t_iDomains.DomainIsActive <> tDomains.DomainIsActive then do:
            <M-48 run updateActiveFlagByParams
               (input  tDomains.DomainCode (icdomainCode), 
                input  tDomains.DomainIsActive (ildomainIsActive), 
                output viFcReturnSuper (oiReturnStatus)) in PMultiDB>
         end.
      end.
   end.
   <I-41 {bFcCloseAndStopInstance
            &CLASS           = "PMultiDB"}> 
end.    
<I-47 {bFcCloseAndStopInstance
            &CLASS           = "BMfgDBConnections"}>
                                                                      
if viReturnRef < 0
then do:
    <M-63 run StopExternalInstances
       (output viFcReturnSuper (oiReturnStatus)) in BDomain>
    assign oiReturnStatus = viLocalReturnStatus.
    return.
end. /* if viReturnRef < 0 */   

/* ============================================================================= */    
/* Replicate the Shared Sets to MFG/PRO - only do this if replication is enabled */
/* ============================================================================= */
<I-38 {bFcOpenInstance
            &CLASS           = "Session"}>
<M-39 run GetLogicalValue
    (input  'ReplicationEnabled':U (icName), 
     output vlReplicationEnabled (olValue), 
     output viFcReturnSuper (oiReturnStatus)) in Session>
<I-40 {bFcCloseInstance
            &CLASS           = "Session"}>                   
if vlReplicationEnabled <> false 
then do:

    <M-23 run AdditionalUpdatesReplication (output viFcReturnSuper (oiReturnStatus)) in BDomain>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viLocalReturnStatus >= 0)
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viLocalReturnStatus < 0
    then do:
        <M-64 run StopExternalInstances
           (output viFcReturnSuper (oiReturnStatus)) in BDomain>
        assign oiReturnStatus = viLocalReturnStatus.
        return.
    end. /* viLocalReturnStatus < 0 */
end.

assign oiReturnStatus = viLocalReturnStatus.
if oiReturnStatus < 0 then return.