SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_claim_account_by_claim_id]
	@claim_id int
as


	/*
	DGE

	Obtenir l'ensemble de règlements & recupération de recours d'un sinistre


	*/

	set nocount on;

	select	a.a_account_id,
			v.nmpv_variable_code,
			a.a_type_code,
			ca.clacc_operation_code,
			
			a_amount =	case 
						-- afficher les règlements en négatif
						when a.a_type_code = 'CP' then - abs(a.a_amount)
						-- afficher les encaissements de recours en positif
						else abs(a.a_amount)
						end,
			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,
			ca.clacc_disable_accounting
	from	claim_variables_accounts ca
			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	ca.clacc_claim_id = @claim_id
GO
