IF EXISTS (SELECT * FROM SYS.VIEWS	WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[V_GLB_NFCE_ITEM_BENNER]'))
	DROP VIEW [DBO].[V_GLB_NFCE_ITEM_BENNER]

GO

CREATE VIEW V_GLB_NFCE_ITEM_BENNER AS 
SELECT
    -- <v2:valorDesconto>
    PDV_VD_IT.VLR_DESC AS VALORDESCONTO,
    -- <v2:classificacaoTributaria>
    PDV_VD_IT.CD_TRIB_FC AS CLASSIFICACAOTRIBUTARIA,
    -- <v2:descricaoNF>
    EST_PROD.DS_PROD AS DESCRICAONF,
    --<v2:icmsAliquota>
    PDV_VD_IT.ALIQ_EFET_ICMS AS ICMSALIQUOTA,
    --<v2:icmsBaseCalculo>
    PDV_VD_IT.VLR_EFET_BASE_ICMS AS ICMSBASECALCULO,
    --<v2:icmsValor>
    PDV_VD_IT.VLR_EFET_ICMS AS icmsValor,
    --<v2:naturezaFiscalEstrutura>
    GLB_NT_OP.CD_NT_OP_FC AS NATUREZAFISCALESTRUTURA,
    --<v2:numeroSequencia>
    PDV_VD_IT.CD_IT AS NUMEROSEQUENCIA,
    --<v2:codigoProduto>
    PDV_VD_IT.CD_PROD AS CODIGOPRODUTO,
    --<v2:quantidade>
    PDV_VD_IT.QT_IT AS QUANTIDADE,
    --<v2:valorTotal>
    PDV_VD_IT.VLR_IT * PDV_VD_IT.QT_IT AS VALORTOTAL,
	-- Status do Item
	PDV_VD_IT.ST_IT AS STATUSITEM , 
	PDV_VD_PDV_VD_NFCE.CD_VD AS CODIGOVENDA, 
	PDV_VD_PDV_VD_NFCE.CD_NFCE AS CODIGONFCE,
	PDV_VD_PDV_VD_NFCE.CD_FILIAL AS CODIGOFILIAL
FROM
    PDV_VD_IT INNER JOIN PDV_VD_PDV_VD_NFCE ON
        PDV_VD_IT.CD_EMP = PDV_VD_PDV_VD_NFCE.CD_EMP
        AND PDV_VD_IT.CD_FILIAL = PDV_VD_PDV_VD_NFCE.CD_FILIAL
        AND PDV_VD_IT.CD_VD = PDV_VD_PDV_VD_NFCE.CD_VD
	INNER JOIN EST_PROD_CPL
        ON PDV_VD_IT.CD_EMP = EST_PROD_CPL.CD_EMP
        AND PDV_VD_IT.CD_FILIAL = EST_PROD_CPL.CD_FILIAL
        AND PDV_VD_IT.CD_PROD = EST_PROD_CPL.CD_PROD
    INNER JOIN EST_PROD
        ON EST_PROD.CD_EMP = EST_PROD_CPL.CD_EMP
        AND EST_PROD.CD_PROD = EST_PROD_CPL.CD_PROD
    LEFT JOIN PDV_VD_IT_LOTE
        ON PDV_VD_IT.CD_EMP = PDV_VD_IT_LOTE.CD_EMP
        AND PDV_VD_IT.CD_FILIAL = PDV_VD_IT_LOTE.CD_FILIAL
        AND PDV_VD_IT.CD_VD = PDV_VD_IT_LOTE.CD_VD
        AND PDV_VD_IT.CD_IT = PDV_VD_IT_LOTE.CD_IT
    LEFT JOIN EST_PROD_CPL_LOTE
        ON EST_PROD_CPL_LOTE.CD_EMP = PDV_VD_IT_LOTE.CD_EMP
        AND EST_PROD_CPL_LOTE.CD_FILIAL = PDV_VD_IT_LOTE.CD_FILIAL
        AND EST_PROD_CPL_LOTE.CD_LOTE = PDV_VD_IT_LOTE.CD_LOTE
    LEFT JOIN GLB_NT_OP
        ON GLB_NT_OP.CD_NT_OP = PDV_VD_IT.CD_NT_OP
--WHERE
--    PDV_VD_IT.ST_IT = 1 -- Para itens validos
