SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[p_claim_provision_add]
	@claim_id int,
	@variable_id int, 
	@amount ais_decimal2,
	@user_code ais_code_medium,
	@repr bit,						-- mandataire oui/non
	@injury bit
AS

	/*
	DGE
	Ajouter une ligne de provision

	*/

	insert into claim_variables_provisions(clvp_claim_id, clvp_variable_id, clvp_date, clvp_amount, clvp_user_code, clvp_repr, clvp_injury)
	values (@claim_id, @variable_id, GETDATE(), @amount, @user_code, @repr, @injury)


	if @repr != 0
	begin
		update	claim_variables
		set		clv_provision_repr = @amount
		where	clv_claim_id = @claim_id
		and		clv_variable_id = @variable_id
	end
	else if @injury != 0
	begin
		update	claim_variables
		set		clv_provision_injury = @amount
		where	clv_claim_id = @claim_id
		and		clv_variable_id = @variable_id
	end
	else
	begin
		update	claim_variables
		set		clv_provision = @amount
		where	clv_claim_id = @claim_id
		and		clv_variable_id = @variable_id
	end



GO
