IF EXISTS ( SELECT * fROM INFORMATION_SCHEMA.TABLES
				WHERE
					TABLE_NAME ='V_PDV_VD_CUPONS_CANCELAMENTO')
BEGIN
	DROP VIEW  [dbo].[V_PDV_VD_CUPONS_CANCELAMENTO] 
END
GO
--SELECT * FROM V_PDV_VD_CUPONS_CANCELAMENTO WHERE CD_EMP =1 AND CD_FILIAL = 2 AND DT_VD = '2018-06-21' ORDER BY CD_CX,NR_ECF
CREATE VIEW V_PDV_VD_CUPONS_CANCELAMENTO AS
SELECT
	E.CD_EMP,
	E.CD_FILIAL,
	E.NR_ECF,
	E.CD_CX,
	E.DT_VD,
	0 AS VLR_LIQ_VD_LOJA,
	0 AS VLR_LIQ_VD_MTZ,
	0 AS VLR_DIF ,
	'' AS ST_VD_LOJA,
	'' AS ST_VD_MTZ,
	'SIM' AS ST_VD_DIF,
	E.DT_CAD,
	E.DT_CAD AS DT_CONSD,
	0 AS CD_VD,
	DT_CAD AS DT_VD_HORA_VENDA,
	0 AS ST_VD,
	'CANCELAMENTO' AS DS_TIPO_OPERACAO,
	0 AS TIPO_OPERACAO,
	0 AS CONSD_PEND,
	ISNULL(e.CD_CONTROLE,0) AS ERRO,
	ISNULL(e.LAUDO,'') AS LAUDO,
	'' AS CD_CTR_NCC,
	E.NR_ECF_UUID
FROM
	ADM_ERRO_PDV_VD_INTEGRACOES e 
WHERE
	TP_CUPOM = 3
