IF OBJECT_ID('V_CUPOMNAOFISCAL_TEF') IS NOT NULL 
	DROP VIEW V_CUPOMNAOFISCAL_TEF 
GO 

CREATE VIEW V_CUPOMNAOFISCAL_TEF
AS
SELECT	CUPOM.CD_EMP,CUPOM.CD_FILIAL,CUPOM.DT_CUPOM,CUPOM.CD_CX,CUPOM.CD_CTR,CUPOM.NR_COO
	,TEF.CD_RECTO_TEF,TEF.CD_ADM_CARTAO AS CD_CONV,ADM.NM_USUAL AS NM_CONV
	,TEF.VL_CARTAO AS VLR_CARTAO, TEF.VL_SAQUE_CARTAO AS VLR_SAQUE,ADM.PARC AS QT_PARC
	,TEF.COD_REDE,TEF.COD_BANDEIRA,TEF.COD_MODALIDADE 
	,TEF.NSU_SITEF AS NR_TRANSACAO,TEF.NR_AUTORIZACAO
	,CASE WHEN TEF.TRN_POS = 1 THEN 'POS' ELSE 'SITEF' END AS TEF_GATEWAY, ADM.NM_USUAL AS BANDEIRA
FROM 	PDV_CUPOM_NAO_FISCAL CUPOM
INNER 	JOIN PDV_CUPOM_NAO_FISCAL_TEF CUPOMTEF ON CUPOM.CD_EMP = CUPOMTEF.CD_EMP AND CUPOM.CD_FILIAL = CUPOMTEF.CD_FILIAL  AND CUPOM.CD_CTR = CUPOMTEF.CD_CTR
INNER	JOIN PDV_RECBTO_TEF TEF ON CUPOMTEF.CD_EMP = TEF.CD_EMP AND CUPOMTEF.CD_FILIAL = TEF.CD_FILIAL AND CUPOMTEF.CD_RECTO_TEF = TEF.CD_RECTO_TEF
LEFT 	JOIN RC_ADM_CARTAO ADM ON TEF.CD_EMP = ADM.CD_EMP AND TEF.CD_ADM_CARTAO = ADM.CD_ADM_CARTAO