
Delimiter //
Drop Procedure If Exists LOADER_RECLAIMS_NORMALIZE_MAP_RECLAIMS_CODE//
Create Procedure LOADER_RECLAIMS_NORMALIZE_MAP_RECLAIMS_CODE(
    In batchnum Int
)
Begin
	Set @idEntities = GET_LOADER_INFO('ID_ENTITIES', batchnum);

    Update
        LOADER_STATUS STS
        Inner Join LOADER_RECLAIMS LRD
            On LRD.LOADER_STATUS_ID_LOADER_STATUS = STS.ID_LOADER_STATUS
		Inner Join DF_RECLAIMS DFR
			On LRD.DF_RECLAIMS_CODE = DFR.DF_RECLAIMS_CODE
			And DFR.ENTITIES_ID_ENTITIES = @idEntities
			And DFR.DF_RECLAIMS_TRASH = 0
    Set
        LRD.DF_RCLM_ID_DF_RCLM = DFR.ID_DF_RECLAIMS
		, LRD.RECLAIMS_DETAILS_BLOCKED = DFR.DF_RECLAIMS_LEAVEOUT_MODE
    Where
        STS.LOADER_STATUS_BATCH_NUM = batchnum
-- 		And STS.LOADER_STATUS_ERRCOUNT = 0
    ;


    -- maj des erreur

	call LOADER_BUILD_RECLAIMS_CHECK_BASE_QUERY (
				'DF_RECLAIMS_CODE', batchnum, 'Reclaim code not defined', '', 0, @query
			)
		;
	set @query = Concat(@query
					, ' And DF_RCLM_ID_DF_RCLM Is Null'
				)
			;

	PREPARE stmt FROM @query;
	execute stmt			
		;
	Deallocate prepare stmt;

End//
Delimiter ;