/****** OBJECT:  TRIGGER [TRG_PDV_VD_CARTAO_CONV]    SCRIPT DATE: 13/10/2014 14:49:06 ******/
IF  EXISTS (SELECT * FROM SYS.TRIGGERS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[TRG_PDV_VD_CARTAO_CONV]'))
DROP TRIGGER [DBO].[TRG_PDV_VD_CARTAO_CONV]
GO
GO
GO
CREATE TRIGGER [dbo].[TRG_PDV_VD_CARTAO_CONV] ON [dbo].[PDV_VD] FOR INSERT AS
BEGIN 
	UPDATE 
		v
	SET 
		v.VLR_CARTAO = 0
    FROM 
		PDV_VD v INNER JOIN INSERTED i ON
		v.CD_EMP = i.CD_EMP AND
		v.CD_VD = i.CD_VD AND
		v.CD_FILIAL = i.CD_FILIAL 
		
		INNER JOIN PDV_VD_TEF T ON
		T.CD_EMP=I.CD_EMP AND
		T.CD_FILIAL=I.CD_FILIAL AND
		T.CD_VD= I.CD_VD

		INNER JOIN RC_ADM_CARTAO C ON
		T.CD_EMP = C.CD_EMP AND
		T.CD_ADM_CARTAO = C.CD_ADM_CARTAO
	WHERE C.TP_ADM=4
END

