create or replace view detallecxp as select cpcabecera.cpca_idprovee AS proveedor, cpcabecera.cpca_tipo AS tipo, cpcabecera.cpca_tipocompro AS docum, cpcabecera.cpca_numero AS numero, cpcabecera.cpca_fecha AS fecha, cpcabecera.cpca_factura AS factura, (case when (cpcabecera.cpca_tipo = 'FA') then cpcabecera.cpca_credito else 0 end) as inicialf, (case when (cpcabecera.cpca_tipo = 'AN') then cpcabecera.cpca_debito else 0 end) AS iniciala, cpdetalle.cpde_debito AS debitos, cpdetalle.cpde_credito AS creditos, ((cpcabecera.cpca_debito - cpcabecera.cpca_credito) + (cpdetalle.cpde_debito - cpdetalle.cpde_credito)) AS saldo, cpcabecera.cpca_detalle AS cadetalle, cpdetalle.cpde_detalle AS dedetalle, cpdetalle.cpde_documento numdeta, cpdetalle.cpde_fecha as fchmovi from (cpcabecera left join cpdetalle on((cpcabecera.cpca_idcabecera = cpdetalle.cpde_idcabecera))) order by cpcabecera.cpca_idprovee, cpcabecera.cpca_tipo, cpcabecera.cpca_tipocompro, cpcabecera.cpca_factura, cpcabecera.cpca_numero create or replace view detallecxc as select cccabecera.ccca_idcliente AS cliente, cccabecera.ccca_tipo AS tipo, cccabecera.ccca_tipocompro AS docum, cccabecera.ccca_numero AS numero, cccabecera.ccca_fecha AS fecha, cccabecera.ccca_factura AS factura, (case when (cccabecera.ccca_tipo = 'FA') then cccabecera.ccca_debito else 0 end) as inicialf, (case when (cccabecera.ccca_tipo = 'AN') then cccabecera.ccca_credito else 0 end) AS iniciala, ccdetalle.ccde_debito AS debitos, ccdetalle.ccde_credito AS creditos, ((cccabecera.ccca_debito - cccabecera.ccca_credito) + (ccdetalle.ccde_debito - ccdetalle.ccde_credito)) AS saldo, cccabecera.ccca_detalle AS cadetalle, ccdetalle.ccde_detalle AS dedetalle, ccdetalle.ccde_documento numdeta, ccdetalle.ccde_fecha as fchmovi from (cccabecera left join ccdetalle on((cccabecera.ccca_idcabecera = ccdetalle.ccde_idcabecera))) order by cccabecera.ccca_idcliente, cccabecera.ccca_tipo, cccabecera.ccca_tipocompro, cccabecera.ccca_factura, cccabecera.ccca_numero 015-002-000001239 3/ABR/2021 3/MAY/2021 522.48 297.48 54.00 19-05-2021 015-002-000001242 6/ABR/2021 1/MAY/2021 470.40 470.40 150.00 19-05-2021 015-002-000001243 7/ABR/2021 7/MAY/2021 465.96 465.96 150.00 19-05-2021 354.00