project QadFinancials > class BCompanyProperty > method ReplicateCompanyFromDomain

Description

This method will update the currency of all companies linked to the passed domains.


Parameters


tAllUpdatesFromDomaininputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDomain.AdditionalUpdates


program code (program6/bcompanyproperty.p)

/* Return if no parameters were passed */
if not can-find(first tAllUpdatesFromDomain)
then return.

/* set default oiReturnStatus */
if oiReturnStatus = 0
then assign oiReturnStatus = -98.

UPDATEBLOCK:                                                    
for each tAllUpdatesFromDomain:
    /* Run query to retrieve all CompanyProperty records for this domain */
    if vlStartCompPropByDomain = false
    then do:
        <Q-3 run CompanyPropertyByDomainID  (Start) in BCompanyProperty >
        assign vlStartCompPropByDomain = true.
    end.    
    <Q-2 run CompanyPropertyByDomainID (all) (Read) (NoCache)
       (input 0, (CompanyId)
        input tAllUpdatesFromDomain.tiDomainID, (DomainID)
        output dataset tqCompanyPropertyByDomainID) in BCompanyProperty >
    
    /* Check if company property is already loaded. */  
    assign vcCompanyPropertyIDList = '':U.
    for each tqCompanyPropertyByDomainID where
             tqCompanyPropertyByDomainID.tiDomain_ID = tAllUpdatesFromDomain.tiDomainID:
        find tCompanyProperty where
             tCompanyProperty.CompanyProperty_ID = tqCompanyPropertyByDomainID.tiCompanyProperty_ID
             no-lock no-error.
        if not available tCompanyProperty
        then assign vcCompanyPropertyIDList = vcCompanyPropertyIDList + chr(4) + string(tqCompanyPropertyByDomainID.tiCompanyProperty_ID).
    end. /* for each tq... */

    /* if vcCompanyPropertyIDList <> '':U --> Dataload */
    if vcCompanyPropertyIDList <> '':U
    then do:
        assign vcCompanyPropertyIDList = substring(vcCompanyPropertyIDList, 2, length(vcCompanyPropertyIDList, "CHARACTER":U) - 1, "CHARACTER":U).
        <M-1 run DataLoad (input  '':U (icRowids), 
                   input  vcCompanyPropertyIDList (icPkeys), 
                   input  '':U (icObjectIds), 
                   input  '':U (icFreeform), 
                   input  true (ilKeepPrevious), 
                   output viFcReturnSuper (oiReturnStatus)) in BCompanyProperty>
    end.                   
    
    /* Update the currencies */
    for each tqCompanyPropertyByDomainID where   
             tqCompanyPropertyByDomainID.tiDomain_ID = tAllUpdatesFromDomain.tiDomainID:
        find tCompanyProperty where
             tCompanyProperty.CompanyProperty_ID = tqCompanyPropertyByDomainID.tiCompanyProperty_ID
             no-lock no-error.
        if not available tCompanyProperty
        then do:
            assign vcMessage      = trim(#T-5'Cannot find entity attribute in instance.':200(46930)t-5#) + chr(10) +
                                    trim(#T-6'Entity Property ID: &1':100(46931)T-6#)
                   oiReturnStatus = -3.
            <M-7 run SetMessage (input  vcMessage (icMessage), 
                     input  '':U (icArguments), 
                     input  '':U (icFieldName), 
                     input  '':U (icFieldValue), 
                     input  'S':U (icType), 
                     input  2 (iiSeverity), 
                     input  '':U (icRowid), 
                     input  'QadFin-5118':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BCompanyProperty>                                                     
            leave UPDATEBLOCK.                     
        end. /* if not available tCompanyProperty */
        assign tCompanyProperty.tcCurrencyCode       = tAllUpdatesFromDomain.tcCurrencyCode
               tCompanyProperty.CompanyPropertyIsWHT = tAllUpdatesFromDomain.tlDomainPropertyIsWHT
               tCompanyProperty.tc_Status            = (if tCompanyProperty.tc_Status = '':U
                                                        then 'C':U
                                                        else tCompanyProperty.tc_Status).
    end. /* for each tqCompanyProperty ... */           
end. /* for each tAllUpdatesFromDomain */

/* Stop queries */
if vlStartCompPropByDomain = true
then do:    
    <Q-4 run CompanyPropertyByDomainID  (Stop) in BCompanyProperty >
    assign vlStartCompPropByDomain = false.
end.
    
/* Reset default oiReturnStatus */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.