Rename fields with ambiguos names

This commit is contained in:
Enrique Barcelli 2021-12-03 22:44:03 +08:00
parent 9759d2e9bd
commit 7a9b50f591

View file

@ -6,17 +6,17 @@ with
ventas as (
select division.name as organisation,parent.name as parentorg,ad_orginfo.taxid as ruc,
ad_client.name,documentno,c_invoice.description,dateinvoiced,totallines,grandtotal,qtyinvoiced,priceactual,
linenetamt,c_invoiceline.taxbaseamt,m_product.value,m_product.name,iso_code,
ad_client.name as client,documentno,c_invoice.description,dateinvoiced,totallines,grandtotal,qtyinvoiced,priceactual,
linenetamt,c_invoiceline.taxbaseamt,m_product.value as productcode,m_product.name as productname,iso_code,
c_invoiceline.line,c_invoice.c_invoice_id,c_invoiceline.c_invoiceline_id,
c_bpartner.name,c_bpartner.taxid,c_uom.name as uom,c_doctype.name,
c_bpartner.name as bpname,c_bpartner.taxid,c_uom.name as uom,c_doctype.name as doctype,
c_paymentterm.name as paymentterm,c_paymentterm.netdays,
c_invoice.isactive,c_invoice.issotrx,
c_invoicetax.taxbaseamt,c_invoicetax.taxamt,
c_invoicetax.taxbaseamt as invoicetaxbaseamt,c_invoicetax.taxamt as invoicetaxtaxamt,
taxinvoice.name,
c_invoicelinetax.taxbaseamt,c_invoicelinetax.taxamt,
c_invoicelinetax.taxbaseamt as linetaxbaseamt,c_invoicelinetax.taxamt as linetaxtaxamt,
taxline.name,
fin_payment_schedule.amount as cuota, fin_payment_schedule.origduedate
fin_payment_schedule.amount as cuota, fin_payment_schedule.duedate, fin_payment_schedule.fin_payment_schedule_id
from
@ -41,17 +41,24 @@ left join fin_payment_schedule on fin_payment_schedule.c_invoice_id = c_invoice.
where
c_invoice.documentno = 'E001-27' and
--c_invoice.documentno = 'E001-27' and
c_invoice.documentno = '1000052' and
c_invoice.issotrx = 'Y' and
c_invoice.isactive = 'Y' and
ad_client.name ='BLB'
--ad_client.name ='BLB'
ad_client.name ='Locate & Grow'
)
-- Above this line is the full query select all the required invoice data
-- Below this line a JSON sturcture is created to be feed into the FACTURADOR SUNAT APP.
--select *
select
jsonb_build_object(
'cabecera', json_agg(DISTINCT
jsonb_build_object(
@ -64,13 +71,13 @@ select
'numDocUsuario',ruc,
'rznSocialUsuario',parentorg,
'tipMoneda',iso_code,
'sumTotTributos','18.00',
'sumTotValVenta','100.00',
'sumPrecioVenta','118.00',
'sumTotTributos',grandtotal-totallines,
'sumTotValVenta',totallines,
'sumPrecioVenta',grandtotal,
'sumDescTotal','0.00',
'sumOtrosCargos','0.00',
'sumTotalAnticipos','0.00',
'sumImpVenta','118.00',
'sumImpVenta',grandtotal,
'ublVersionId','2.1',
'customizationId','2.0'
)
@ -96,7 +103,7 @@ select
jsonb_build_object(
'invoiceline',c_invoiceline_id,
'codUnidadMedida','BX',
'ctdUnidadItem','5.00',
'ctdUnidadItem',qtyinvoiced,
'codProducto','10001',
'codProductoSUNAT','50161813',
'desItem','PRODUCTO 1',
@ -198,4 +205,6 @@ select
)
)
from ventas;