IF NOT OBJECT_ID('TRG_EST_NF_SAI_CANCEL_PEND_NFE') IS NULL
	BEGIN 
		DROP TRIGGER TRG_EST_NF_SAI_CANCEL_PEND_NFE
	END

GO

------------------------------------INSERO EM EST_NF_SAI_NFE_PEND------------------------------------      
CREATE TRIGGER [dbo].[TRG_EST_NF_SAI_CANCEL_PEND_NFE] ON [dbo].[EST_NF_SAI_NFE] FOR INSERT AS      

begin      
	--Solicitando o cancelamento da nota fiscal case seja uma nota denegada.		
	INSERT INTO EST_NF_SAI_CANCEL_SOLIC (CD_EMP, CD_FILIAL, CD_NF, CD_USU, CD_MT_CANCEL, ST_DENEGADA, DT_CANCEL, DT_CAD)
		SELECT 
			I.CD_EMP, I.CD_FILIAL, I.CD_NF, 1, 0, 1, CONVERT(VARCHAR(10), GETDATE(),101), CONVERT(VARCHAR(10), GETDATE(),101)
		FROM INSERTED I
		WHERE I.C_STAT_NFE IN (110,205,233,234,301,302)		
	 
end

GO
 