project QadFinancials > class BMfgAddressListDetail > method MaintainDataCreditor


Parameters


tCreditorsToUpdate2inputtemp-tabletemp-table with creditors that are added/changed/deleted
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bmfgaddresslistdetail.p)

assign oiReturnStatus = -98.

<M-9 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
/* clear tAddress2 tt*/
empty temp-table tAddress2.

if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then Return.

/* Start the queries */
<Q-16 run AddressByType  (Start) in BBusinessRelation >
<Q-11 run CompanyBySharedSet  (Start) in BCompany >

for each tCreditorsToUpdate2 where tCreditorsToUpdate2.tc_Status = "N":U
     or tCreditorsToUpdate2.tc_status = "D":U:
    empty temp-table tAddress2.
    /* Select the HEADOFFICE address */
    <Q-6 run AddressByType (all) (Read) (NoCache)
          (input tCreditorsToUpdate2.BusinessRelation_ID, (BusinessRelationID)
           input 'HEADOFFICE':U, (AddressType)
           output dataset tqAddressByType) in BBusinessRelation >
    
    /* Copy the resultset into the Address Temp-table */
    /* Using the tqAddressByType temptable to populate the ad_mstr does not work */
    for each tqAddressByType :
        create tAddress2.
        assign tAddress2.Address_ID            = tqAddressByType.tiAddress_ID
               tAddress2.AddressStreet1        = tqAddressByType.tcAddressStreet1
               tAddress2.AddressStreet2        = tqAddressByType.tcAddressStreet2
               tAddress2.AddressStreet3        = tqAddressByType.tcAddressStreet3
               tAddress2.AddressZip            = tqAddressByType.tcAddressZip
               tAddress2.AddressCity           = tqAddressByType.tcAddressCity
               tAddress2.AddressTelephone      = tqAddressByType.tcAddressTelephone
               tAddress2.AddressState          = tqAddressByType.tcAddressState
               tAddress2.AddressPostalZip      = tqAddressByType.tcAddressPostalZip
               tAddress2.LastModifiedDate      = tqAddressByType.ttLastModifiedDate
               tAddress2.LastModifiedTime      = tqAddressByType.tiLastModifiedTime
               tAddress2.LastModifiedUser      = tqAddressByType.tcLastModifiedUser.
                  
        assign tAddress2.tc_status = tCreditorsToUpdate2.tc_status
               tAddress2.tc_Rowid  = string(tqAddressByType.tiAddress_ID).
    end.
    
    /* Store the CreditorCode into a variable, since we the code to put in ad_addr */
    assign vcRelationCode2 = tCreditorsToUpdate2.CreditorCode
           vcRelationType2 = "supplier":U.

    /* Addresses are system wide date, so we need to use the SystemWideToMfg pattern.
     * However, we are processing Creditors, which use the SharedSetToMfg pattern.
     * We need to copy the address information (system wide data) to all domains where the 
     * creditor is added. To achieve this we determine all the companies that uses the creditor 
     * shared set, get the domains and for each domain we run MaintainData and follow
     * the SystemWideToMFG pattern.
     */ 
    <Q-4 run CompanyBySharedSet (all) (Read) (NoCache)
       (input '', (CompanyId)
        input tCreditorsToUpdate2.SharedSet_ID, (SharedSetId)
        output dataset tqCompanyBySharedSet) in BCompany >
    /*
    * Process the Financial Data into each of the domains returned by the above query.   
    */
    DomainLoop:
    for each tqCompanyBySharedSet where
        tqCompanyBySharedSet.tlDomainPropertyIsSetupCompl = true
        break by tqCompanyBySharedSet.tcDomainCode:

        if not first-of(tqCompanyBySharedSet.tcDomainCode) then
           next DomainLoop.

        /* save the domain code which currently being processed */
        assign vcDomain2 = tqCompanyBySharedSet.tcDomainCode.
        
        /* Check if we need to replicate to one domain or to all */  
        <I-18 {bFcOpenInstance
            &CLASS           = "Session"}>
        <M-19 run GetCharacterValue
           (input  'ProcessSharedSetToMFGDomainCode':U (icName), 
            output vcProcessSharedSetToMFGDomain (ocValue), 
            output viSessionReturnStatus (oiReturnStatus)) in Session>
        <I-20 {bFcCloseInstance
            &CLASS           = "Session"}>

        if viSessionReturnStatus <> 0 
        then assign oiReturnStatus = viSessionReturnStatus.
        if viSessionReturnStatus < 0 
        then do :
            /* <Q-21 run DebtorByDebtorIDCode  (Stop) in BDebtor > */
            <Q-22 run CompanyBySharedSet  (Stop) in BCompany >        
            return.
        end. /* if viFcReturnSuper < 0 */
        if vcProcessSharedSetToMFGDomain <> '':U and
           vcProcessSharedSetToMFGDomain <> ?    and
           vcProcessSharedSetToMFGDomain <> tqCompanyBySharedSet.tcDomainCode
        then next DomainLoop.         
        
        /* update the MFG/PRO record */
        <M-12 run ProcessMaintainData (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then Return.
        
    end.
end.

/* stop  queries */
<Q-17 run AddressByType  (Stop) in BBusinessRelation >
<Q-14 run CompanyBySharedSet  (Stop) in BCompany >

<M-15 run ProcessMaintainDataSave (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then Return.

/* ======================== */
/* Set ReturnStatus = OK    */
/* ======================== */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.