project QadFinancials > class BMfgAddressListDetail > method MaintainDataDebtorShipto


Parameters


tDebtorShiptosToUpdate2inputtemp-table
iiBusinessRelationInstanceIDinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDebtorShipTo.ApiReplicateFromDaemon


program code (program1/bmfgaddresslistdetail.p)

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

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

/* store the instance id of the Business Relation */
assign viBBusinessRelation8ID = iiBusinessRelationInstanceID.

/* If an business relation doesn't exist start and open it - otherwise just open the existing isntance */
if viBBusinessRelation8ID = 0 or
   viBBusinessRelation8ID = ? 
then do:   
    <I-17 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BBusinessRelation"}>
end.
else do:
    <I-18 {bFcOpenInstance
            &CLASS           = "BBusinessRelation"}>
end.   

/* Start queries */
<Q-9 run DebtorByDebtorIDCode  (Start) in BDebtor >
<Q-10 run CompanyBySharedSet  (Start) in BCompany >

shiptos:
for each tDebtorShiptosToUpdate2 
    where tDebtorShiptosToUpdate2.tc_status = "N":U
            or tDebtorShiptosToUpdate2.tc_status = "D":U:
                       
    /* clear the tAddres temp table */
      empty temp-table tAddress2.         
             
    /* get the addres details for the current address */
    <M-20 run GetAddressWithID (input  tDebtorShiptosToUpdate2.address_id (iiAddressID), 
                            input-output tAddress2 (tApiAddress), 
                            output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>     
        
    /* find the t_saddress record we just created */
    for first tAddress2 
        where tAddress2.address_id = tDebtorShiptosToUpdate2.address_id:
    end.  
    
    /* We should always be able to find an address but in case we don't then raise an error */
    if not available tAddress2   
    then do:
        assign 
            vcMessageText =#T-19'The address details are not defined in the system.':35(31629)t-19#
            oiReturnStatus = -1.
        <M-21 run SetMessage (input  vcMessageText (icMessage), 
                      input  '' (icArguments), 
                      input  '' (icFieldName), 
                      input  '' (icFieldValue), 
                      input  'E':U (icType), 
                      input  3 (iiSeverity), 
                      input  '' (icRowid), 
                      input  'QadFin-4865':U (icFcMsgNumber), 
                      input  '' (icFcExplanation), 
                      input  '' (icFcIdentification), 
                      input  '' (icFcContext), 
                      output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>          
        leave.
    end.                     
    
    /* Store the debtorshipto into a variable, since we the code to put in ad_addr */
    assign vcRelationCode2 = tDebtorShiptosToUpdate2.DebtorShiptoCode
           vcRelationType2 = "ship-to":U
           tAddress2.tc_status =  tDebtorShiptosToUpdate2.tc_status.

    /* find the debtor related to this record */
    <Q-7 run DebtorByDebtorIDCode (all) (Read) (NoCache)
       (input viCompanyID, (CompanyId)
        input tDebtorShiptosToUpdate2.debtor_ID, (DebtorId)
        input '', (DebtorCode)
        input ?, (AddressType)
        output dataset tqDebtorByDebtorIDCode) in BDebtor >

    /* 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.
     */ 
     for first tqDebtorByDebtorIDCode:
         <Q-3 run CompanyBySharedSet (all) (Read) (NoCache)
            (input '', (CompanyId)
             input tqDebtorByDebtorIDCode.tiSharedSet_ID, (SharedSetId)
             output dataset tqCompanyBySharedSet) in BCompany >
     end.
    /*
    * 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-25 {bFcOpenInstance
            &CLASS           = "Session"}>
        <M-26 run GetCharacterValue
           (input  'ProcessSharedSetToMFGDomainCode':U (icName), 
            output vcProcessSharedSetToMFGDomain (ocValue), 
            output viSessionReturnStatus (oiReturnStatus)) in Session>
        <I-27 {bFcCloseInstance
            &CLASS           = "Session"}>

        if viSessionReturnStatus <> 0 
        then assign oiReturnStatus = viSessionReturnStatus.
        if viSessionReturnStatus < 0 
        then do :         
            leave shiptos.
        end. /* if viFcReturnSuper < 0 */
        if vcProcessSharedSetToMFGDomain <> '':U and
           vcProcessSharedSetToMFGDomain <> ?    and
           vcProcessSharedSetToMFGDomain <> tqCompanyBySharedSet.tcDomainCode
        then next DomainLoop. 

        /* update the MFG/PRO record */
        <M-23 run ProcessMaintainData (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then leave shiptos.
        
    end. /* for each companybysharedset */
end.  /* end of debtorshiptostoupdate for each */

/* stop queries */
<Q-13 run DebtorByDebtorIDCode  (Stop) in BDebtor >
<Q-14 run CompanyBySharedSet  (Stop) in BCompany >

/* If we started the business relation instance then we need to stop it - otherwise just close it */
if iiBusinessRelationInstanceID = 0
then do:
    <I-15 {bFcCloseAndStopInstance
            &CLASS           = "BBusinessRelation"}>    
end.                        
else do:
    <I-16 {bFcCloseInstance
            &CLASS           = "BBusinessRelation"}>    
end.

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

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