Riacdri

255 palavras 2 páginas
DROP VIEW "public"."val_fiscal_valores_agregados_valor_infomado_calculado";

CREATE VIEW "public"."val_fiscal_valores_agregados_valor_infomado_calculado" ( cod_item, valor_agregado, valor_notas, diferenca)
AS
SELECT b.cod_item, b.valor_agregado, b.valor_notas, b.diferenca
FROM (reg_0000 a JOIN ( SELECT a.cod_item, a.valor AS valor_agregado, b.vl_item AS valor_notas, (a.valor - b.vl_item) AS diferenca, a.fk_0000 FROM (( SELECT reg_1400.fk_0000, reg_1400.cod_item, sum(reg_1400.valor) AS valor FROM reg_1400 GROUP BY reg_1400.fk_0000, reg_1400.cod_item ) a JOIN ( SELECT a.fk_0000, b.cod_item, sum(b.vl_item) AS vl_item FROM (( SELECT reg_c100.reg, reg_c100.id, reg_c100.ind_oper, reg_c100.nivel, reg_c100.ind_emit, reg_c100.cod_part, reg_c100.cod_mod, reg_c100.cod_sit, reg_c100.ser, reg_c100.num_doc, reg_c100.chv_nfe, reg_c100.dt_doc, reg_c100.dt_e_s, reg_c100.vl_doc, reg_c100.ind_pgto, reg_c100.vl_desc, reg_c100.vl_abat_nt, reg_c100.vl_merc, reg_c100.ind_frt, reg_c100.vl_frt, reg_c100.vl_seg, reg_c100.vl_out_da, reg_c100.vl_bc_icms, reg_c100.vl_icms, reg_c100.vl_bc_icms_st, reg_c100.vl_icms_st, reg_c100.vl_ipi, reg_c100.vl_pis, reg_c100.vl_confins, reg_c100.vl_pis_st, reg_c100.vl_confins_st, reg_c100.fk_0000, reg_c100.linha FROM reg_c100 WHERE (reg_c100.cod_mod = '04'::bpchar) ) a JOIN ( SELECT reg_c170.fk_0000, reg_c170.fk_c100, reg_c170.cod_item, sum(reg_c170.vl_item) AS vl_item FROM reg_c170 WHERE (reg_c170.cfop < '5000'::bpchar) GROUP BY reg_c170.fk_0000, reg_c170.fk_c100, reg_c170.cod_item ) b ON (((a.fk_0000 = b.fk_0000) AND (a.id = b.fk_c100)))) GROUP BY

Relacionados