SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_rep_trn_summary_header]
	@branch_id			int,
	@user_code			ais_code_medium,
	@transaction_id		int
as 

	set nocount on;


	select	-- informations concernant l'utilisateur
			usr.usr_name, usr.usr_mail, 
			-- informations concernant l'entité juridique
			branch_internal_reference = branch.act_internal_reference,
			branch_external_reference = branch.act_external_reference,
			branch_display_name = branch.br_display_name,
			branch_name = branch.adr_complete_name,
			branch_addr1 = branch.adr_address1,
			branch_addr2 = branch.adr_address2,
			branch_addr3 = branch.adr_address3,
			branch_postal_code = branch.adr_postal_code,
			branch_city = branch.adr_city,
			branch_mail = branch.adr_mail,
			branch_home_phone = branch.adr_home_phone,
			-- informations concernant le code devise 
			trn_devise_code = trn.a_currency_code,
			trn_reference = trn.atrn_reference

	from	(	select *
				from	usr_users
				where	usr_user_code = @user_code ) as usr

			inner join	(	select	*
							from	vw_act_branches 
							where	br_actor_id = @branch_id ) as branch	on 1 = 1

			inner join	(		select	*
								from	acc_transactions
										inner join acc_accounts on a_account_id = atrn_transaction_id
								where	atrn_transaction_id = @transaction_id ) as trn on 1 = 1
	
GO
