SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[p_acc_account_actors_by_actor_id]
	@actor_id int,									-- id de l'acteur
	@operation_code ais_code_short = '%',			-- filtre sur le code opération 
	@show_b bit = 0,								-- afficher les bordereaux de quittances
	@show_t bit = 0,								-- afficher les transactions		
	@show_p_not_taken bit = 0,						-- afficher les paiements non repris
	@show_p_taken bit = 0,							-- afficher les paiements repris
	@show_cp bit = 0,								-- afficher les règlements sinistres
	@show_cr bit = 0,								-- afficher les récupérations de recours
	@show_csd bit = 0,								-- afficher les lignes rétrocession déduite
	@show_cb bit = 0,								-- afficher les lignes bdr crédit sinistre (valable pour les compagnies)
	@currency_code ais_code_short					-- code devise (ou '%')
	
AS


	select	*
	from	vw_acc_account_actors
	where	(@actor_id > 0 AND a_actor_id = @actor_id )
	AND		1 =	CASE
				WHEN a_type_code = 'B' and @show_b != 0 and ( @operation_code = '%' or bdr_operation_code = @operation_code ) THEN 1
				WHEN a_type_code = 'T' and @show_t != 0 THEN 1
				WHEN a_type_code = 'P' and @show_p_not_taken != 0 and pay_taken = 0 THEN 1
				WHEN a_type_code = 'P' and @show_p_taken != 0 and pay_taken != 0 THEN 1
				WHEN a_type_code = 'CP' and @show_cp != 0 and ( @operation_code = '%' or bdr_operation_code = @operation_code ) THEN 1
				WHEN a_type_code = 'CR' and @show_cr != 0 and ( @operation_code = '%' or bdr_operation_code = @operation_code ) THEN 1
				WHEN a_type_code = 'CSD' and @show_csd != 0 then 1
				when a_type_code = 'CB' and @show_cb != 0 and  ( @operation_code = '%' or bdr_operation_code = @operation_code ) THEN 1
				ELSE 0
				END
	and		(@currency_code = '%' or a_currency_code = @currency_code)

GO
