SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_claim_account_by_actor_id]
	@actor_id int,
	@operation_code ais_code_short = '%',			-- filtre sur le code opération 
	@currency_code ais_code_short,					-- code devise (ou '%')
	@show_disable_accounting BIT					-- retourner les lignes "disable accounting"
as


	/*
	DGE

	Obtenir l'ensemble de règlements & recupération de recours d'un acteur
	*/

	set nocount on;

	select	a.a_account_id,
			
			c.cl_internal_reference,
			rs.riss_number,

			v.nmpv_variable_code,
			ca.clacc_operation_code,
			a_amount = -(a.a_amount),
			a.a_currency_code,
			a.a_actor_id,
			ca.clacc_user_code, 
			a.a_operation_utc_date,
			adr.act_type_code,
			adr.act_internal_reference,
			adr.adr_complete_name,
			a.a_type_code,
			ca.clacc_disable_accounting
	from	claim_variables_accounts ca
			inner join claim_claims c on c.cl_claim_id = ca.clacc_claim_id
			inner join ris_risks_situations rs on rs.riss_risk_situation_id = c.cl_risk_situation_id
			inner join acc_accounts a on a.a_account_id = ca.clacc_account_id
			inner join vw_claim_variables v on	v.clv_claim_id = ca.clacc_claim_id
											and v.clv_variable_id = ca.clacc_variable_id
			inner join vw_act_actors_adresses adr	on	adr.act_actor_id = a.a_actor_id
	where	a.a_actor_id = @actor_id
	and		(@operation_code = '%' or ca.clacc_operation_code = @operation_code)
	and		(@currency_code = '%' or a_currency_code = @currency_code)
	AND		(@show_disable_accounting <> 0 OR ca.clacc_disable_accounting = 0 )
GO
