Delimiter //
/**
 * doit être appelé apres LOADER_RECLAIMS_NORMALIZE_MAP_RECLAIMS_CODE
 **/
Drop Procedure If Exists LOADER_RECLAIMS_NORMALIZE_MAP_DEADLINE//
Create Procedure LOADER_RECLAIMS_NORMALIZE_MAP_DEADLINE(
    In batchnum Int
)
Begin

    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_RCLM_ID_DF_RCLM = DFR.ID_DF_RECLAIMS
    Set
        LRD.RECLAIMS_DETAILS_DEAD_LINE = date_add(Coalesce(LRD.RECLAIMS_CREATED, curdate()), interval DFR.DF_RECLAIMS_DEAD_LINE Day)
    Where
        STS.LOADER_STATUS_BATCH_NUM = batchnum
		And STS.LOADER_STATUS_ERRCOUNT = 0
		And DFR.DF_RECLAIMS_DEAD_LINE Is Not Null
    ;

End//
Delimiter ;