SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[p_grid_nm_payment_modes_2]
	@payment_code AS ais_code_short  = '%' 
AS
BEGIN
	/*
	Afficher uniquement les modes de paiement 
	pour lesquels on a des transactions à valider 
	*/

	SET NOCOUNT ON

	SELECT	*
	FROM	dbo.nm_payment_modes pm
	WHERE	(@payment_code = '%' OR pm.pm_payment_code = @payment_code)
	AND		EXISTS	(	SELECT	1
						FROM	dbo.acc_transactions t 
						WHERE	t.atrn_payment_code = pm.pm_payment_code
						AND		NOT EXISTS(	SELECT	1
											FROM	dbo.acc_trn_bordereaux_details d
											WHERE	d.trnbd_transaction_id = t.atrn_transaction_id) 
					)
END
GO
