project QadFinancials > class BDebtorEndUser > method ValidateComponentUpdateAllSharedEndusers


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDebtorEndUser.ValidateComponent


program code (program1/bdebtorenduser.p)

if viBBusinessRelation6ID = 0 or
   viBBusinessRelation6ID = ? 
then do:    
    <I-76 {bFcStartAndOpenInstance
         &ADD-TO-TRANSACTION   = "true"
         &CLASS                = "BBusinessRelation"}>
end. /* if viBBusinessRelation6ID = 0 or */
else do:   
    <I-96 {bFcOpenInstance
         &CLASS           = "BBusinessRelation"}>
end. /* NOT if viBBusinessRelation6ID = 0 or */


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

    /* 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 btsDebtorEndUser.tc_status = "C":U and 
       btsDebtorEndUser.tlAddressIsShared = true and 
       btsDebtorEndUser.tlUpdateAllSharedAddRecords = true       
    then do:
    
        find first t_iDebtorEndUser 
             where t_iDebtorEndUser.tc_rowid = btsDebtorEndUser.tc_rowid no-error.
             
        if not available t_iDebtorEndUser
        then do:
            assign 
                vcMessageText = #T-82'Cannot load original end user record':255(999652831)T-82#
                oiReturnStatus = -1.
            <M-54 run SetMessage
               (input  vcMessageText (icMessage), 
                input  '' (icArguments), 
                input  '' (icFieldName), 
                input  '' (icFieldValue), 
                input  'E' (icType), 
                input  3 (iiSeverity), 
                input  '' (icRowid), 
                input  'qadfin-297182':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>

           <I-41 {bFcCloseInstance
                  &CLASS           = "BBusinessRelation"}>
            return.
        end.
        
        if btsDebtorEndUser.address_id = t_iDebtorEndUser.address_id
        then next enduser.

        <Q-58 run DebtorEndUserByAddress (all) (Read) (NoCache)
           (input viCompanyID, (CompanyId)
            input t_iDebtorEndUser.address_id, (AddressID)
            output dataset tqDebtorEndUserByAddress) in BDebtorEndUser >
         
        for each tqDebtorEndUserByAddress
           where tqDebtorEndUserByAddress.tiAddress_ID = t_iDebtorEndUser.address_id 
             and tqDebtorEndUserByAddress.tiDebtorEndUser_ID <> btsDebtorEndUser.DebtorEndUser_ID on error undo, throw:            
   
            if vcDebtorEndUserIDs = "" then assign vcDebtorEndUserIDs = string(tqDebtorEndUserByAddress.tiDebtorEndUser_ID).
            else assign vcDebtorEndUserIDs = vcDebtorEndUserIDs + chr(4) + string(tqDebtorEndUserByAddress.tiDebtorEndUser_ID).

        end. /* end of each end user*/
                 
        if vcDebtorEndUserIDs <> ""
        then do:
        
            <M-21 run DataLoad
               (input  '' (icRowids), 
                input  vcDebtorEndUserIDs (icPkeys), 
                input  '' (icObjectIds), 
                input  '' (icFreeform), 
                input  true (ilKeepPrevious), 
                output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
                
            if viFcReturnSuper < 0  
            then do:
                assign 
                    vcMessageText = #T-46'Unable able to load end users to update to new address':255(508738376)T-46#
                    oiReturnStatus = -1.
                        
                <M-45 run SetMessage
                   (input  vcMessageText (icMessage), 
                    input  '' (icArguments), 
                    input  '' (icFieldName), 
                    input  '' (icFieldValue), 
                    input  'E' (icType), 
                    input  '3' (iiSeverity), 
                    input  '' (icRowid), 
                    input  'qadfin-729887':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDebtorEndUser>
            <I-16 {bFcCloseInstance
                &CLASS           = "BBusinessRelation"}>
                return.
            end. 
            
            for each tDebtorEndUser no-lock on error undo, throw:
                if index(vcDebtorEndUserIDs ,string(tDebtorEndUser.DebtorEndUser_ID)) > 0
                then do:
                    create t_sDebtorEndUser.
                    buffer-copy tDebtorEndUser to t_sDebtorEndUser.   
                    assign
                        t_sDebtorEndUser.tc_status = "C":U 
                        t_sDebtorEndUser.address_id = btsDebtorEndUser.address_id. 
                end.        
            end.  /* end for each tDebtorEndUSer */
                                                     
        end. /* vcDebtorEndUserIDs not "" */       
    end.   /* End tlUpdateAllSharedAddRecords - true */    
end. /* end for each bvatDebtorEnduser */


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