project QadFinancials > class BDebtorShipTo > method ValidateComponentUpdateAllSharedShiptos


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDebtorShipTo.ValidateComponent


program code (program1/bdebtorshipto.p)

if viBBusinessRelation1ID = 0 or
   viBBusinessRelation1ID = ? 
then do:    
     <I-47 {bFcStartAndOpenInstance
          &ADD-TO-TRANSACTION   = "true"
          &CLASS                = "BBusinessRelation"}>       
end.
else do:   
    <I-58 {bFcOpenInstance
         &CLASS           = "BBusinessRelation"}>
    if oiReturnStatus <> 0
    then do:
        assign viBBusinessRelation1ID = 0.
       <I-62 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION   = "true"
            &CLASS                = "BBusinessRelation"}>
    end.        
end.  

shipto:
for each btsDebtorShipto
   where btsDebtorShipto.tc_status = "N":U 
      or btsDebtorShipto.tc_status = "C":U on error undo, throw:
        
   /* first we need to populate the address id with the key fields */
    if btsDebtorShipto.Address_ID = 0 or btsDebtorShipto.Address_ID = ?
    then do:
      
        
    
        <M-29 run GetAddressWithKeyFields
           (input  btsDebtorShipto.tcAddressStreet1 (icAddressStreet1), 
            input  btsDebtorShipto.tcAddressStreet2 (icAddressStreet2), 
            input  btsDebtorShipto.tcAddressCity (icAddressCity), 
            input  btsDebtorShipto.tcAddressStreet3 (icAddressStreet3), 
            input  btsDebtorShipto.tcAddressZip (icAddressZip), 
            input  btsDebtorShipto.tiBusinessRelation_ID (iiBusinessRelationID), 
            input  btsDebtorShipto.tcAddressTypeCode (icAddressTypeCode), 
            output btsDebtorShipto.Address_ID (oiAddressID), 
            output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation>
    
        <I-51 {bFcCloseInstance
             &CLASS           = "BBusinessRelation"}>
                  
         if viFcReturnSuper <> 0 then 
        do:
            assign oiReturnStatus = viFcReturnSuper .     
            <I-12 {bFcCloseInstance
                &CLASS           = "BBusinessRelation"}>  
            Return.
        end. /* if oiReturnStatus < 0  */

       
    end. 
            
    /* if the user (on the Ui) had indicated that they want to redirect all ship-tos that share the original address to the new
     address then we need to load all the other ship-tos into the instance 
     This requires us to build a list of all the shiptos that need to modified and then use dataload to load them in to the instance.
     As we are in validatecomponent already - it means we have to copy the newly loaded instance records from tDebtorShipto into 
    the t_sDebtorShipto buffer.  This will ensure any updates are actually processed to the db*/
    
    if btsDebtorShipto.tc_status = "C":U and 
       btsDebtorShipto.tlAddressIsShared = true and 
       btsDebtorShipto.tlUpdateAllSharedAddRecords = true       
    then do:
    
        find first t_iDebtorShipto
             where t_iDebtorShipto.tc_rowid = btsDebtorShipto.tc_rowid no-error.
             
        if not available t_iDebtorShipto
        then do:
            assign 
                vcMessageText = #T-40'Cannot load original end user record':255(999652831)T-40#
                oiReturnStatus = -1.
            <M-19 run SetMessage
               (input  vcMessageText (icMessage), 
                input  '' (icArguments), 
                input  '' (icFieldName), 
                input  '' (icFieldValue), 
                input  'E' (icType), 
                input  3 (iiSeverity), 
                input  '' (icRowid), 
                input  'qadfin-450334':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDebtorShipTo>
            <I-70 {bFcCloseInstance
                &CLASS           = "BBusinessRelation"}>
            return.
        end.
        
        if btsDebtorShipto.address_id = t_iDebtorShipto.address_id
        then next shipto.       

        <Q-95 run DebtorShiptoByAddress (all) (Read) (NoCache)
            (input viCompanyID, (CompanyId)
             input t_iDebtorShipto.address_id, (AddressID)
             output dataset tqDebtorShiptoByAddress) in BDebtorShipTo >
         
        for each tqDebtorShiptoByAddress
           where tqDebtorShiptoByAddress.tiAddress_ID = t_iDebtorShipto.address_id 
             and tqDebtorShiptoByAddress.tiDebtorShipto_ID <> btsDebtorShipto.DebtorShipto_ID on error undo, throw:            
   
            if vcDebtorShiptoIDs = "" then assign vcDebtorShiptoIDs = string(tqDebtorShiptoByAddress.tiDebtorShipto_ID).
            else assign vcDebtorShiptoIDs = vcDebtorShiptoIDs + chr(4) + string(tqDebtorShiptoByAddress.tiDebtorShipto_ID).

        end. /* end of each end user*/
                 
        if vcDebtorShiptoIDs <> ""
        then do:
        
            <M-43 run DataLoad
               (input  '' (icRowids), 
                input  vcDebtorShiptoIDs (icPkeys), 
                input  '' (icObjectIds), 
                input  '' (icFreeform), 
                input  true (ilKeepPrevious), 
                output viFcReturnSuper (oiReturnStatus)) in BDebtorShipTo>
                
            if viFcReturnSuper < 0  
            then do:
                assign 
                    vcMessageText = #T-91'Unable able to load ship-tos to update to new address':255(568715453)T-91#
                    oiReturnStatus = -1.
                        
                <M-73 run SetMessage
                   (input  vcMessageText (icMessage), 
                    input  '' (icArguments), 
                    input  '' (icFieldName), 
                    input  '' (icFieldValue), 
                    input  'E' (icType), 
                    input  '3' (iiSeverity), 
                    input  '' (icRowid), 
                    input  'qadfin-257417':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDebtorShipTo>
                <I-5 {bFcCloseInstance
                    &CLASS           = "BBusinessRelation"}>
                return.
            end. 
            
            for each tDebtorShipto no-lock on error undo, throw:
                if index(vcDebtorShiptoIDs ,string(tDebtorShipto.DebtorShipto_ID)) > 0
                then do:
                    create t_sDebtorShipto.
                    buffer-copy tDebtorShipto to t_sDebtorShipto.   
                    assign
                        t_sDebtorShipto.tc_status = "C":U 
                        t_sDebtorShipto.address_id = btsDebtorShipto.address_id. 
                end.        
            end.  /* end for each tDebtorSHipto */
                                                     
        end. /* vcDebtorShiptoIDs not "" */       
    end.   /* End tlUpdateAllSharedAddRecords - true */   
end. /* end for each bvatDebtorShipto */ 

 <I-89 {bFcCloseInstance
      &CLASS           = "BBusinessRelation"}>