SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_acc_transactions_get_src_dst]
	@account_id int -- id de la transaction
as 

	set nocount on;

	/*

	DGE 19/03/2017
	Renvoie les lignes SOURCE & DESTINATION de la transaction
	*/


	-- lignes source
	select	a.act_internal_reference, a.act_external_reference, a.adr_complete_name, 
			v.a_account_id, v.a_currency_code, v.a_cr, v.a_db, v.a_amount, v.a_operation_utc_date, v.a_lettering
	from	acc_accounts_links l
			INNER JOIN vw_acc_account_clients v on v.a_account_id = l.alnk_account_id__src
			INNER JOIN vw_act_actors_adresses a on a.act_actor_id = v.a_actor_id
	where	l.alnk_account_id__dst = @account_id

	-- lignes destination
	select	a.act_internal_reference, a.act_external_reference, a.adr_complete_name, 
			v.a_account_id, v.a_currency_code, v.a_cr, v.a_db, v.a_amount, v.a_operation_utc_date, v.a_lettering
	from	acc_accounts_links l
			INNER JOIN vw_acc_account_clients v on v.a_account_id = l.alnk_account_id__dst
			INNER JOIN vw_act_actors_adresses a on a.act_actor_id = v.a_actor_id
	where	l.alnk_account_id__src = @account_id

GO
