﻿
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[fds__setMFRInvoiceFile]
	@Id varchar(15),
	@filename varchar(100),
	@file varbinary(max)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @now datetime = GETUTCDATE();
	DECLARE @Idnum bigint = TRY_CAST(@id as bigint);
	INSERT INTO [dbo].[fds__admin_activity] ([activity] ,[authuser] ,[info])
		VALUES ('fds__setMFRInvoiceFile' ,'' , (SELECT * FROM (VALUES(@Id, '')) as z ([id],[authuser]) FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER));

    IF @idnum is not null and NOT EXISTS (SELECT 0 FROM [dbo].[fds__mfr_invoicefiles] WHERE [id] = @id)
		BEGIN
			INSERT INTO [dbo].[fds__mfr_invoicefiles]
					   ([Id]
					   ,[filename]
					   ,[file])
				 VALUES
					   (@Id
					   ,@filename 
					   ,@file)
		END;
END