project QadFinancials > class BMfgAddress > method MaintainDataBusinessRelation


Parameters


tAddressesToUpdateinputtemp-table
tContactsToUpdateinputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program1/bmfgaddress.p)

assign oiReturnStatus = -98.

<M-11 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then Return.

empty temp-table tAddress.

/* Start queries */
<Q-12 run AddressByFinancialAddress
   (Start) in BMfgAddress >

Address:
for each tAddressesToUpdate where tAddressesToUpdate.tc_status = "C":U:

    empty temp-table tAddress.
    
    /* Copy the record from tAddressesToUpdate to tAddress since this temp-table is used 
     * in the generic code to update the record in MFG/PRO
     */
    create tAddress.
    buffer-copy tAddressesToUpdate to tAddress.
    
    /* Get all the ad_mstr records in MFG/PRO that are linked to the this Address record */
    <Q-6 run AddressByFinancialAddress (all) (Read) (NoCache)
       (input tAddressesToUpdate.Address_ID, (AddressID)
        output dataset tqAddressByFinancialAddress) in BMfgAddress >
    for each tqAddressByFinancialAddress:
        /* set the values for the key fields (ad_domain and ad_addr).
         * set also the address type. This field is needed in UpdateMfgData
         */
        assign vcDomain       = tqAddressByFinancialAddress.tcad_domain
               vcRelationCode = tqAddressByFinancialAddress.tcad_addr
               vcRelationType = tqAddressByFinancialAddress.tcad_type
               vcRelatedCustomer = tqAddressByFinancialAddress.tcad_ref.

        /* update the MFG/PRO record */
        <M-14 run ProcessMaintainData (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then leave Address.

    end.
end.

/* Stop queries */
<Q-13 run AddressByFinancialAddress
   (Stop) in BMfgAddress >

if oiReturnStatus = -98 or oiReturnStatus > 0
then do:
    <M-15 run ProcessMaintainDataSave (output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 then Return.
end.

/* Replicate to MFG/PRO employee records */

<Q-37 run EmployeeByBusinessRelationID  (Start) in BEmployee >

for each tAddressesToUpdate where 
    tAddressesToUpdate.tc_status = "C":U and
    tAddressesToUpdate.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}:
    <Q-30 run EmployeeByBusinessRelationID (all) (Read) (NoCache)
        (input ?, (CompanyId)
         input tAddressesToUpdate.BusinessRelation_ID, (BusinessRelationId)
         output dataset tqEmployeeByBusinessRelationID) in BEmployee >
    Employee:
    for each tqEmployeeByBusinessRelationID where
        tqEmployeeByBusinessRelationID.tiBusinessRelation_ID = tAddressesToUpdate.BusinessRelation_ID:
        create tEmployee.
        assign
            tEmployee.EmployeeCode = tqEmployeeByBusinessRelationID.tcEmployeeCode
            tEmployee.EmployeeJobTitle = tqEmployeeByBusinessRelationID.tcEmployeeJobTitle
            tEmployee.EmployeeStartDate = tqEmployeeByBusinessRelationID.ttEmployeeStartDate
            tEmployee.EmployeeEndDate = tqEmployeeByBusinessRelationID.ttEmployeeEndDate
            tEmployee.EmployeeDepartmentCode = tqEmployeeByBusinessRelationID.tcEmployeeDepartmentCode
            tEmployee.EmployeeIsActive = tqEmployeeByBusinessRelationID.tlEmployeeIsActive
            tEmployee.BusinessRelation_ID = tqEmployeeByBusinessRelationID.tiBusinessRelation_ID
            tEmployee.tc_status = 'C':U.
        <I-31 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BMfgEmployee"}>
         <M-34 run MaintainDataForBusinessRelation
            (input  tEmployee (tMfgEmployee), 
             input  tAddressesToUpdate (tMfgAddress), 
             input  tContactsToUpdate (tMfgContact), 
             output viFcReturnSuper (oiReturnStatus)) in BMfgEmployee>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
         <I-36 {bFcCloseInstance
              &CLASS           = "BMfgEmployee"}>
        if oiReturnStatus < 0 then leave Employee.
    end. /* for first tqEmployeeForAddress */
end. /* for each tAddressesToUpdate... */

<Q-38 run EmployeeByBusinessRelationID  (Stop) in BEmployee >
        
/* ======================== */
/* Set ReturnStatus = OK    */
/* ======================== */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.