/****** Object:  Trigger [TRG_EST_NF_ENT_PRE_ENTRADA_EXCLUI_INCLUI_PENDENCIA]    Script Date: 05/08/2014 14:46:28 ******/
IF EXISTS(SELECT NAME FROM SYS.TRIGGERS WHERE NAME = 'TRG_EST_NF_ENT_PRE_ENTRADA_EXCLUI_INCLUI_PENDENCIA')
BEGIN
	DROP TRIGGER [dbo].[TRG_EST_NF_ENT_PRE_ENTRADA_EXCLUI_INCLUI_PENDENCIA]
END
GO
GO
GO
--------------------------------------INSERCAO EM EST_NF_ENT_PRE_ENTRADA_EST_NF_ENT--------------------------------------
CREATE TRIGGER [dbo].[TRG_EST_NF_ENT_PRE_ENTRADA_EXCLUI_INCLUI_PENDENCIA] ON [dbo].[EST_NF_ENT_PRE_ENTRADA_EST_NF_ENT] FOR DELETE AS
DELETE FROM p FROM EST_NF_ENT_PRE_ENTRADA_PENDENCIA p WHERE EXISTS
    (SELECT * FROM DELETED 
     WHERE CD_EMP=p.CD_EMP AND CD_CTR_PRE_ENTRADA=p.CD_CTR_PRE_ENTRADA)
--Pendencia de entrada pre-faturas transferencias (SEPARADO NO ESTOQUE)
INSERT INTO EST_NF_ENT_PRE_ENTRADA_PENDENCIA (
		CD_EMP, 
		CD_CTR_PRE_ENTRADA, 
		DT_CAD)
	SELECT 
		d.CD_EMP, 
		d.CD_CTR_PRE_ENTRADA, 
		GETDATE() 
    FROM 
		DELETED d
