Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagesql
CREATE OR REPLACE VIEW VIASOFTVTRINA.V_VT_NOTAPEDIDOTRANSP ("IDNOTA", "NUMDOC", "CHVNFE", "SERIE", "DTRECPROTAUT", "NPROTAUTORIZA", "XML", "IGNORA", "PEDCODIGO", "STATUS") AS 
SELECT 
    NF.IDNOTA,
    NF.NUMDOC,
    NF.CHVNFE,
    NF.SERIE,
    NF.DTRECPROTAUT,
    NF.NPROTAUTORIZA,
    NX.XML,
    WP.IGNORA,
    WP.PEDCODIGO,
    CASE WHEN COALESCE(NF.IDNOTA,0) = 0 THEN 'Em Preparação' 
        WHEN (COALESCE(NF.IDNOTA,0) > 0) AND (COALESCE(NF.NPROTAUTORIZA,'0') = '0') THEN 'Em Processamento' 
        WHEN COALESCE(NF.NPROTAUTORIZA,'0') <> '0' THEN 'Faturado' 
    END STATUS
FROM VIASOFTMCP.WECPEDIDO WP
LEFT JOIN VIASOFTMCP.NOTAREFITE NR
    ON NR.IDNOTAREF = WP.IDNOTA
    AND NR.ESTABESTABREF = WP.ESTAB
LEFT JOIN VIASOFTBASE.NOTA NF
    ON NF.ESTAB = NR.ESTAB
    AND NF.IDNOTA = NR.IDNOTA
LEFT JOIN VIASOFTBASE.NOTAXML NX
    ON NX.ESTAB = NF.ESTAB
    AND NX.IDNOTA = NF.IDNOTA

...