SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_acc_mpay_bordereaux_set_invoices_status]
	@bordereau_id						int,
	@from_monthly_payment_status_code	ais_code_short,
	@to_monthly_payment_status_code		ais_code_short
as

	set nocount on;

	/*
	DGE 17/01/2017

	MAJ des statuts prélèvement des quittances
	
	*/
	
	update	i
	set		i.inv_monthly_payment_status_code = @to_monthly_payment_status_code
	from	acc_invoices i 
			inner join acc_mpay_bordereaux_details d on d.mpaybd_invoice_id = i.inv_invoice_id
	where	d.mpaybd_bordereau_id = @bordereau_id
	and		(@from_monthly_payment_status_code = '%' or isnull(i.inv_monthly_payment_status_code, '') = @from_monthly_payment_status_code )

GO
