
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		marek
-- Create date: 03/06/2009
-- Description:	Ustawia czy prowizje dla danej agencji jest juz zablokowana
-- =============================================
ALTER PROCEDURE [dbo].[sp_SetProvision] 
	@isBlocked bit,
	@agencyId int,
	@year int,
	@month int,
	@userName nvarchar(100)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

IF EXISTS(SELECT * FROM dbo.ProvisionSettings WHERE agencyId=@agencyId AND [year]=@year AND [Month]=@month)
	BEGIN
		PRINT 'UPDATE'
		UPDATE dbo.ProvisionSettings
		SET IsBlocked=@isBlocked, UpdatedOn=GETDATE(), UpdatedBy=@userName
		WHERE agencyId=@agencyId AND [year]=@year AND [Month]=@month 
	END
ELSE
	BEGIN
		INSERT INTO dbo.ProvisionSettings(AgencyId, [Year], [Month], IsBlocked, CreatedOn, CreatedBy, UpdatedOn, UpdatedBy) 
		VALUES(@agencyId, @year, @month, @isBlocked, GETDATE(), @userName, GETDATE(), @userName)
	END

RETURN

END
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

