SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_rep_trn_ck_bdx_header]
	@branch_id			int,
	@user_code			ais_code_medium,
	@bordereau_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 bordereau
			bdr.*
	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_trn_bordereaux b
								where	b.trnb_bordereau_id = @bordereau_id ) as bdr on 1 = 1
	



GO
