project QadFinancials > class BMfgAddressListDetail > method MaintainDataDebtor


Parameters


tDebtorsToUpdate2inputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bmfgaddresslistdetail.p)

assign oiReturnStatus = -98.
   
<M-13 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
empty temp-table tAddress2.

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

/* start queries */
<Q-9 run AddressByType  (Start) in BBusinessRelation >
<Q-10 run CompanyBySharedSet  (Start) in BCompany >

for each tDebtorsToUpdate2 
    where tDebtorsToUpdate2.tc_status = "N":U
       or tDebtorsToUpdate2.tc_status = "D":U:

    empty temp-table tAddress2.
    /* Select the HEADOFFICE address */
    <Q-7 run AddressByType (all) (Read) (NoCache)
       (input tDebtorsToUpdate2.BusinessRelation_ID, (BusinessRelationID)
        input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (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.BusinessRelation_ID   = tqAddressByType.tiBusinessRelation_ID
              tAddress2.AddressType_ID        = tqAddressByType.tiAddressType_ID
              tAddress2.AddressLogicKeyString = tqAddressByType.tcAddressLogicKeyString
              tAddress2.AddressStreet1        = tqAddressByType.tcAddressStreet1
              tAddress2.AddressStreet2        = tqAddressByType.tcAddressStreet2
              tAddress2.AddressStreet3        = tqAddressByType.tcAddressStreet3
              tAddress2.AddressZip            = tqAddressByType.tcAddressZip
              tAddress2.AddressCity           = tqAddressByType.tcAddressCity
              tAddress2.AddressState          = tqAddressByType.tcAddressState
              tAddress2.LastModifiedDate      = tqAddressByType.ttLastModifiedDate
              tAddress2.LastModifiedTime      = tqAddressByType.tiLastModifiedTime
              tAddress2.LastModifiedUser      = tqAddressByType.tcLastModifiedUser
              tAddress2.tc_status =  tDebtorsToUpdate2.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 = tDebtorsToUpdate2.DebtorCode
           vcRelationType2 = "customer":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 tDebtorsToUpdate2.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 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-14 run ProcessMaintainData (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then Return.
        
    end.
end.

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

<M-17 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.