/****** Object:  View [dbo].[V_PAINEL_NFE_EST_PED_VD_PENDENTE_ANALITICO]    Script Date: 03/10/2018 11:00:00 ******/ 
IF EXISTS (SELECT * 
           FROM   SYS.VIEWS 
           WHERE  OBJECT_ID = 
      Object_id(N'[dbo].[V_PAINEL_NFE_EST_PED_VD_PENDENTE_ANALITICO]')) 
  DROP VIEW [dbo].[V_PAINEL_NFE_EST_PED_VD_PENDENTE_ANALITICO] 

GO 

--SELECT * FROM V_PAINEL_NFE_EST_PED_VD_PENDENTE_ANALITICO 
CREATE VIEW V_PAINEL_NFE_EST_PED_VD_PENDENTE_ANALITICO  
AS
SELECT CD_FILIAL    AS filialOrigemId,
       CD_PED       AS numeroPedido,
       CASE
           WHEN CD_FIL_DEST >0 THEN CD_FIL_DEST
           ELSE CD_CLI
       END          AS filialDestinoId,
       NM_FANT      AS filialDestinoNome,
       DT_EMI_PED   AS data,
       VLR_TOT_PED  AS valor,
       STS_PED   + CASE  WHEN FLAG_REALIZAR_FAT IN (1,2) THEN ' AUTOMATICO' ELSE ' MANUAL' END as status,
       CD_RESSUP    AS ressuprimentoNumero
FROM V_EST_PED_VD
WHERE STS_PED = 'PENDENTE'
  AND DT_EMI_PED = CONVERT(CHAR(10), GETDATE(), 112)