﻿-- Stored procedure
CREATE PROCEDURE [dbo].[WritePDFintoDB_FMS]
	--@CodiceContratto as varchar(11) = null,
	@Rete as varchar(1),
	@CodiceFiscale as varchar(16),
	@NomeCliente as varchar(50),
	@CognomeCliente as varchar(50),
	--@TipoReport as varchar(15),
	@fileReport as image = null,
	@CodicePB as varchar(6)--,
	--@NomePB as varchar(50) = null,
	--@CognomePB as varchar(50) = null,
	--@NumeroPagine as INT
AS
BEGIN
	SET NOCOUNT ON;
		--declare @idReport as int
		INSERT INTO [SEIReport].[dbo].[ReportFMS]
			   ([FileReport])
		 VALUES
			   (@fileReport)
		DECLARE @IdInRep as int
		SET @IdInRep = @@identity
		INSERT INTO [SEIReport].[dbo].[RepositoryMetadati]
			   ([idInrepository]
			   ,[rete]
			   ,[cod_agente]
			   ,[cod_fiscale]
			   ,[cognome]
			   ,[nome]
               ,[idCliente]
			   ,[tipoReport]
			   ,[dataGenerazione]
			   ,[flagLock]
			   ,[flagStoricizzato]
			   ,[flagDefinitivo]
			   ,[repository]
			   ,[CodiceContratto])
		 VALUES
			   (@IdInRep
			   ,@rete
			   ,@CodicePB
			   ,@CodiceFiscale
			   ,@CognomeCliente
			   ,@NomeCliente
               ,999
			   ,6
			   ,getDate()
			   ,1
			   ,0
			   ,1
			   ,5
			   ,null)
		return @IdInRep
END