﻿CREATE PROCEDURE [dbo].[writeLogPDF]
@Applicativo as varchar(2),
@Tipo as smallint,
@IDImage as int
AS
BEGIN
	SET NOCOUNT ON;
--declare @Rete as varchar(1)
--declare @Nome as varchar(50)
--declare @PB as varchar(50)
--declare @Cognome as varchar(50)
--declare @cf as varchar(16)
declare @Date as datetime
SET @Date = getDate()
IF (@Applicativo = 'RM')
	BEGIN
		INSERT INTO [dbo].[LogFilePDF]([Applicativo],[Tipo],[Data_inserimento],[IDImage],[Nome],[Cognome],[CodiceFiscale],[Rete],[PB],[Tipo_utente])
		SELECT 
		  @Applicativo as [Applicativo]
		  ,@Tipo as [Tipo]
		  ,@Date as [Data_inserimento]
		  ,@IDImage as [IDImage]
		  ,dbo.Cliente.Nome as [Nome]
		  ,dbo.Cliente.Cognome as [Cognome]
		  ,dbo.Cliente.CodFiscale as [CodiceFiscale]
		  ,substring(dbo.Cliente.Utente,1,1) as [Rete]
		  ,substring(dbo.Cliente.Utente,2,7) as [PB]
		  ,'tipoUtente' as [Tipo_utente]
		FROM [dbo].[REPORTFISICO]
		INNER JOIN dbo.ReportperClienteDati 
			ON dbo.ReportperClienteDati.Identificativo = [dbo].[REPORTFISICO].Identificativo
		INNER JOIN dbo.Cliente 
			ON dbo.ReportperClienteDati.IdCliente = dbo.Cliente.IdCliente
		WHERE [dbo].[REPORTFISICO].Identificativo = @IDImage
	END
ELSE
	BEGIN
		INSERT INTO [dbo].[LogFilePDF]([Applicativo],[Tipo],[Data_inserimento],[IDImage],[Nome],[Cognome],[CodiceFiscale],[Rete],[PB],[Tipo_utente])
		SELECT 
		  @Applicativo as [Applicativo]
		  ,@Tipo as [Tipo]
		  ,@Date as [Data_inserimento]
		  ,@IDImage as [IDImage]
		  ,NomeCliente as [Nome]
		  ,CognomeCliente as [Cognome]
		  ,Cliente as [CodiceFiscale]
		  ,Rete as [Rete]
		  ,CodicePB as [PB]
		  ,'tipoUtente' as [Tipo_utente]
		FROM [dbo].[C6REPORTFISICO]
		WHERE Identificativo = @IDImage
	END
END