text: WITH TRANSPORTE_CAMINHAO_PROPRIO AS (
      SELECT A.NUMTRANSVENDA
        FROM PCNFSAID A
        LEFT JOIN PCCLIENT C ON A.CODCLI = C.CODCLI
       WHERE A.DTCANCEL IS NULL
         AND A.CODFILIAL IN (
          1, 2, 5, 6, 7
      )
         AND C.CODCLI NOT IN (
          18633, 17427
      )
       /*RETIRAR VENDA ENTRE EMPRESAS*/
         AND NOT (A.CODFILIAL = 2
         AND C.CODCLI = 82215)
       /*RETIRAR TRANSFERENCIA DA FILIAL 2 PARA FILIAL 7*/
         AND NOT (A.CODFILIAL = 7
         AND C.CODCLI = 7543)
       /*RETIRAR TRANSFERENCIA DA FILIAL 7 PARA FILIAL 2*/
         AND A.CODFORNECFRETE IN (
          1, 8598
      )
  )
  SELECT DTMOV,
         CODFILIAL,
         CODCLI,
         CLIENTE,
         UF,
         NUMNOTA,
         CODUSUR,
         CODFORNECFRETE,
         FORNECEDOR,
         TOTPESO,
         'S' AS TIPO,
         SUM (VALOR) AS VALOR
    FROM (
      SELECT M.DTMOV,
             S.CODFILIAL,
             S.CODCLI,
             C.CLIENTE,
             S.UF,
             S.NUMNOTA,
             S.CODUSUR,
             S.CODFORNECFRETE,
             F.FORNECEDOR,
             S.TOTPESO,
             (
                 CASE
                     WHEN M.CODFISCAL IN (
                         5117, 5923, 6117, 6923, 5910, 5911, 6910, 6911, 5912, 6912, 5949, 6949
                     ) THEN 0
                     ELSE ROUND (M.QTCONT * (M.PUNITCONT + NVL (M.VLFRETE, 0) + NVL (M.VLOUTROS, 0)), 2)
                 END
             ) AS VALOR
        FROM PCMOV M
       INNER JOIN PCNFSAID S ON M.NUMTRANSVENDA = S.NUMTRANSVENDA
        LEFT JOIN VIEW_JC_VENDEDOR V ON S.CODUSUR = V.CODUSUR
        LEFT JOIN PCFORNEC F ON S.CODFORNECFRETE = F.CODFORNEC
        LEFT JOIN PCCLIENT C ON S.CODCLI = C.CODCLI
       INNER JOIN TRANSPORTE_CAMINHAO_PROPRIO P ON S.NUMTRANSVENDA = P.NUMTRANSVENDA
       WHERE M.CODFISCAL IN (
          5102, 5109, 5117, 5119, 5922, 5923, 5120, 5403, 5405, 6102, 6108, 6403, 6117, 6119, 6120, 6922, 6923, 5910, 5911, 6910, 6911
          , 5949, 6949, 5912, 6912
      )
         AND V.CODGERENTE IN (
          1, 2, 5, 8, 9, 10
      )
         AND M.DTMOV >= TO_DATE ('01/01/2015', 'DD/MM/YYYY')
         AND M.DTCANCEL IS NULL
         AND S.UF = 'SP'
  )
   GROUP BY DTMOV,
            CODFILIAL,
            CODCLI,
            CLIENTE,
            UF,
            NUMNOTA,
            CODUSUR,
            CODFORNECFRETE,
            FORNECEDOR,
            TOTPESO;
  /