Delimiter //
/**
    In batchnum Int : num du lot
*/

Drop Procedure if exists LOADER_REFDATA_COPY//

Create Procedure LOADER_REFDATA_COPY (
    In batchnum int
)
Begin
    Set @idEntities = GET_LOADER_INFO('ID_ENTITIES', batchnum);
    
    -- creation des nouveau référence de compte
    -- obtention de la valeur de l'autoincrment
    call CASH_AUTOINCREMENT_VALUE('ENTITIES_REF_DATAS', @lastid);
    
	call LOADER_REFDATA_REF_DATA_INSERT(batchnum, @lastid);

    --
	call LOADER_REFDATA_DELETE_OLD_ACCOUNTSREFS(batchnum, @idEntities);
	call LOADER_REFDATA_DELETE_OLD_ENTRIESREFS(batchnum, @idEntities);

	call LOADER_REFDATA_REF_DATA_ACCOUNTS_REF_INSERT(batchnum, @lastid);
	call LOADER_REFDATA_REF_DATA_ENTRIES_REF_INSERT(batchnum, @lastid);
    
End //

Delimiter ;