CREATE OR REPLACE VIEW public.view_ent_entradas AS SELECT stq_mov_estoque.filial_for, stq_mov_estoque.data_movimento, stq_mov_estoque.fornecedor, stq_mov_estoque.nota_entrada, stq_mov_estoque.serie, stq_mov_estoque.produto, stq_mov_estoque.vlr_custo, stq_mov_estoque.vlr_bruto, sum( CASE WHEN bas_tipo_mov.operacao::text = 'E'::text THEN stq_mov_estoque.quantidade ELSE stq_mov_estoque.quantidade * '-1'::integer::numeric END) AS quantidade FROM stq_mov_estoque JOIN bas_tipo_mov ON bas_tipo_mov.codigo = stq_mov_estoque.tipo_movimento WHERE stq_mov_estoque.tipo_movimento in (1, 50, 70, 86, 200, 87, 71, 2, 199, 51) GROUP BY stq_mov_estoque.filial_for, stq_mov_estoque.data_movimento, stq_mov_estoque.fornecedor, stq_mov_estoque.nota_entrada, stq_mov_estoque.serie, stq_mov_estoque.produto, stq_mov_estoque.vlr_custo, stq_mov_estoque.vlr_bruto ORDER BY stq_mov_estoque.filial_for, stq_mov_estoque.data_movimento DESC, stq_mov_estoque.fornecedor DESC, stq_mov_estoque.nota_entrada DESC, stq_mov_estoque.serie DESC; ALTER TABLE public.view_ent_nota_entrada OWNER TO postgres; COMMENT ON VIEW public.view_ent_nota_entrada IS 'View do historico de entradas do produto';