Delimiter //
/**
 * Author:  armen
 * Created: 26 mai 2016
 * #7326
 * "des-activation" des reclaim detail actif qui seront clos par le lettrage
*/
Drop Procedure if exists LOADER_MATCHINGCODES_RECLAIMS_DETAILS_UPDATE//
Create Procedure LOADER_MATCHINGCODES_RECLAIMS_DETAILS_UPDATE (
    In batchnum int
)
Begin

        Update RECLAIMS_DETAILS tar
			Inner Join LOADER_MATCHINGCODES_NEW_RECLAIMS_DETAILS src  
				on tar.ID_RECLAIMS_DETAILS = src.RECLAIMS_DETAILS_PREV_RECLAIM
			Inner Join LOADER_STATUS lst  
				On src.LOADER_STATUS_ID_LOADER_STATUS = lst.ID_LOADER_STATUS
			Inner Join ENTRIES ENT
				On src.ENTRIES_ID_ENTRIES = ENT.ID_ENTRIES
			Inner Join DF_MATCHINGCODE_STATE DMS
				On ENT.DF_MATCH_STAT_ID_DF_MATCH_STAT = DMS.ID_DF_MATCHINGCODE_STATE
		Set
			tar.RECLAIMS_DETAILS_IS_ACTIVE = 0
			, tar.RECLAIMS_DETAILS_LAST_UPDATE = now()
        Where 
            lst.LOADER_STATUS_ERRCOUNT = 0  
			And DMS.DF_MATCHINGCODE_STATE_CLOSED <> 0
--             And lst.LOADER_STATUS_BATCH_NUM =  batchnum
        ;
End //

Delimiter ;
