SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_acc_invoices_update_commission_sharing_deduced]
	@invoice_id int,					-- identifiant de la quittance
	@table_id type_table_id READONLY	-- liste des apporteurs
AS

	set nocount on;

	/*
	DGE: mise à jour des champs 
		acc_invoices_policies_variables_introducers.invpolvi_commission_sharing_deduced
		acc_invoices_risks_variables_introducers.invrisvi_commission_sharing_deduced

	après l'encaissement d'une quittance (rétrocession déduite).

	Le traitement s'exécute pour toutes les variables.
	*/

	update	a
	set		a.invpolvi_commission_sharing_deduced = 1
	from	acc_invoices_policies_variables_introducers a
			inner join @table_id t	on	t.id = a.invpolvi_introducer_id
									and	a.invpolvi_invoice_id = @invoice_id


	update	a
	set		a.invrisvi_commission_sharing_deduced = 1
	from	acc_invoices_risks_variables_introducers a
			inner join @table_id t	on	t.id = a.invrisvi_introducer_id
									and	a.invrisvi_invoice_id = @invoice_id
GO
