
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_acc_trn_bordereaux_find_by_id]
	@bordereau_id		int	
as

	set nocount on;

	/*
	DGE 05/06/2015
	Sélectionne les détails d'un bordereau de transactions
	*/
	

	-- acc_trn_bordereaux
	select	b.*
	from	acc_trn_bordereaux b
	where	b.trnb_bordereau_id = @bordereau_id
	
	-- liste des comptes bancaires
	select	v.*
	from	acc_trn_bordereaux_accounts a
			inner join vw_act_accounts v	on	v.acc_actor_id = a.trnbacc_branch_id 
											and	v.acc_account_number = a.trnbacc_account_number
	where	a.trnbacc_bordereau_id = @bordereau_id

	-- liste des compagnies
	select	v.*
	from	acc_trn_bordereaux_companies a
			inner join vw_act_cies v	on	v.act_actor_id = a.trnbcie_company_id
	where	a.trnbcie_bordereau_id = @bordereau_id

	-- liste des transactions
	select	v.*, 
			a.trnbd_amount_db, 
			a.trnbd_amount_cr
	from	acc_trn_bordereaux_details a
			inner join vw_acc_transactions v	on	v.a_account_id = a.trnbd_transaction_id
	where	a.trnbd_bordereau_id = @bordereau_id

	-- liste des introducers
	select	v.*
	from	acc_trn_bordereaux_introducers a
			inner join vw_act_introducers v		on	v.act_actor_id = a.trnbint_introducer_id
	where	a.trnbint_bordereau_id = @bordereau_id

	-- liste des départements
	select	d.*
	from	acc_trn_bordereaux_departments a
			inner join act_branches_departments d	on	d.brdep_branch_id = a.trnbdep_branch_id
													and	d.brdep_department_code = a.trnbdep_department_code
	where	trnbdep_bordereau_id = @bordereau_id



GO
