Delimiter //
/**
 * Provided entry doesn"t exist
 * 
 * -> Message d'erreur : "L'écriture #reference_externe du compte #ref_compte n'existe pas"
 * 
 * @param int batchnum
 * @author Jean-François
 * @ticket #3944, #4221
 */ 
Drop Procedure if Exists LOADER_MATCHINGCODE_NORMALIZE_CHECK_ENTRY_EXISTS//
 
Create Procedure LOADER_MATCHINGCODE_NORMALIZE_CHECK_ENTRY_EXISTS (
    In batchnum int
)
Begin

    Set @idEntities = GET_LOADER_INFO('ID_ENTITIES', batchnum);


    -- Entry does not exist
    Update
        LOADER_MATCHINGCODES LM
        Inner Join LOADER_STATUS S
            On S.ID_LOADER_STATUS = LM.LOADER_STATUS_ID_LOADER_STATUS
-- --         Left Join ACCOUNTS A
-- --             On A.ACCOUNTS_REF = LM.ACCOUNTS_REF
-- --         Left Join ENTRIES_has_ACCOUNTS EHA
-- --             On EHA.ENTRIES_ACC_EXT_REF = LM.ENTRIES_ACC_EXT_REF
-- --             And EHA.ACCOUNTS_ID_ACCOUNTS = A.ID_ACCOUNTS
    Set
        S.LOADER_STATUS_ERRCOUNT = Coalesce(S.LOADER_STATUS_ERRCOUNT,0) + 1
-- --             Case When Coalesce(EHA.ACCOUNTS_ID_ACCOUNTS,EHA.ENTRIES_ID_ENTRIES) Is Null
-- --                 Then Coalesce(S.LOADER_STATUS_ERRCOUNT,0) + 1
-- --                 Else S.LOADER_STATUS_ERRCOUNT
-- --             End
        , S.LOADER_STATUS_ERRMSGS = LOADER_CONCAT_ERR(S.LOADER_STATUS_ERRMSGS, CONCAT('L écriture ',Coalesce(LM.ENTRIES_ACC_EXT_REF, '[vide]'), ' du compte ',Coalesce(LM.ACCOUNTS_REF,'[vide]'), ' n''existe pas' ) ) 
--             Case When Coalesce(EHA.ACCOUNTS_ID_ACCOUNTS,EHA.ENTRIES_ID_ENTRIES) Is Null
--                 Then LOADER_CONCAT_ERR(S.LOADER_STATUS_ERRMSGS, CONCAT('L écriture ',Coalesce(LM.ENTRIES_ACC_EXT_REF, '[vide]'), ' du compte ',Coalesce(LM.ACCOUNTS_REF,'[vide]'), ' n''existe pas' ) ) 
--                 Else S.LOADER_STATUS_ERRMSGS
--             End
    Where 
        S.LOADER_STATUS_BATCH_NUM = batchnum
		And LM.ID_ENTRIES Is Null
--         And A.ENTITIES_ID_ENTITIES = @idEntities
    ;

End //
Delimiter ;