Delimiter //
/**
 * Author:  armen
 * Created: 26 mai 2016
 * #7326
*/
Drop Procedure if exists LOADER_MATCHINGCODES_RECLAIMS_DETAILS_INSERT//
Create Procedure LOADER_MATCHINGCODES_RECLAIMS_DETAILS_INSERT (
    In batchnum int
)
Begin

        Insert Into RECLAIMS_DETAILS (
			ENTRIES_ID_ENTRIES, DF_RCLM_STT_ID_DF_RCLM_STT, DF_RCLM_ID_DF_RCLM
			, RECLAIMS_ID_RECLAIMS, RECLAIMS_DETAILS_OPINION
			, RECLAIMS_DETAILS_LAST_UPDATE, RECLAIMS_DETAILS_BLOCKED, RECLAIMS_DETAILS_DEAD_LINE
			, RECLAIMS_DETAILS_CLOSED, RECLAIMS_DETAILS_AMOUNT, RECLAIMS_DETAILS_PREV_RECLAIM
			, RECLAIMS_DETAILS_IS_ACTIVE, RECLAIMS_DETAILS_IS_TMP, RECLAIMS_DETAILS_NOTES
        )  
        Select 
			src.ENTRIES_ID_ENTRIES, src.DF_RCLM_STT_ID_DF_RCLM_STT, src.DF_RCLM_ID_DF_RCLM
			, src.RECLAIMS_ID_RECLAIMS, src.RECLAIMS_DETAILS_OPINION
			, src.RECLAIMS_DETAILS_LAST_UPDATE, src.RECLAIMS_DETAILS_BLOCKED, src.RECLAIMS_DETAILS_DEAD_LINE
			, src.RECLAIMS_DETAILS_CLOSED, src.RECLAIMS_DETAILS_AMOUNT, src.RECLAIMS_DETAILS_PREV_RECLAIM
			, src.RECLAIMS_DETAILS_IS_ACTIVE, src.RECLAIMS_DETAILS_IS_TMP, src.RECLAIMS_DETAILS_NOTES
        From  
            LOADER_MATCHINGCODES_NEW_RECLAIMS_DETAILS src
            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
        Where 
            lst.LOADER_STATUS_ERRCOUNT = 0  
			And DMS.DF_MATCHINGCODE_STATE_CLOSED <> 0
--             And lst.LOADER_STATUS_BATCH_NUM =  batchnum

        ;
End //

Delimiter ;
