IF EXISTS( SELECT * FROM SYS.OBJECTS 
			WHERE NAME ='TRG_EST_NF_ENT_FUSO_HORARIO'AND TYPE = 'TR')
BEGIN
	DROP TRIGGER dbo.TRG_EST_NF_ENT_FUSO_HORARIO 
END

go
CREATE TRIGGER [dbo].[TRG_EST_NF_ENT_FUSO_HORARIO] ON [dbo].[EST_NF_ENT] 
FOR INSERT
AS
begin
	UPDATE
		e
	SET 
		e.HR_EMI_NF=CONVERT(CHAR(8),DATEADD (minute, DIFER_MINUTOS, i.HR_EMI_NF),114)
	FROM
		EST_NF_ENT e INNER JOIN INSERTED i on
		e.CD_EMP = i.CD_EMP AND
		e.CD_FILIAL = i.CD_FILIAL AND
		e.CD_NF = i.CD_NF
		INNER JOIN PRC_FILIAL_GLB_FUSO_HORARIO ON
		i.CD_EMP = PRC_FILIAL_GLB_FUSO_HORARIO.CD_EMP AND
		i.CD_FILIAL = PRC_FILIAL_GLB_FUSO_HORARIO.CD_FILIAL 
		INNER JOIN GLB_FUSO_HORARIO ON
		PRC_FILIAL_GLB_FUSO_HORARIO.CD_FUSO_HORARIO = GLB_FUSO_HORARIO.CD_FUSO_HORARIO
End

