Rename fields with ambiguos names
This commit is contained in:
parent
9759d2e9bd
commit
7a9b50f591
|
@ -6,17 +6,17 @@ with
|
||||||
ventas as (
|
ventas as (
|
||||||
|
|
||||||
select division.name as organisation,parent.name as parentorg,ad_orginfo.taxid as ruc,
|
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,
|
ad_client.name as client,documentno,c_invoice.description,dateinvoiced,totallines,grandtotal,qtyinvoiced,priceactual,
|
||||||
linenetamt,c_invoiceline.taxbaseamt,m_product.value,m_product.name,iso_code,
|
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_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_paymentterm.name as paymentterm,c_paymentterm.netdays,
|
||||||
c_invoice.isactive,c_invoice.issotrx,
|
c_invoice.isactive,c_invoice.issotrx,
|
||||||
c_invoicetax.taxbaseamt,c_invoicetax.taxamt,
|
c_invoicetax.taxbaseamt as invoicetaxbaseamt,c_invoicetax.taxamt as invoicetaxtaxamt,
|
||||||
taxinvoice.name,
|
taxinvoice.name,
|
||||||
c_invoicelinetax.taxbaseamt,c_invoicelinetax.taxamt,
|
c_invoicelinetax.taxbaseamt as linetaxbaseamt,c_invoicelinetax.taxamt as linetaxtaxamt,
|
||||||
taxline.name,
|
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
|
from
|
||||||
|
@ -41,17 +41,24 @@ left join fin_payment_schedule on fin_payment_schedule.c_invoice_id = c_invoice.
|
||||||
|
|
||||||
|
|
||||||
where
|
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.issotrx = 'Y' and
|
||||||
c_invoice.isactive = '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
|
-- 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.
|
-- Below this line a JSON sturcture is created to be feed into the FACTURADOR SUNAT APP.
|
||||||
|
|
||||||
|
|
||||||
|
--select *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
select
|
select
|
||||||
|
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'cabecera', json_agg(DISTINCT
|
'cabecera', json_agg(DISTINCT
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
|
@ -64,13 +71,13 @@ select
|
||||||
'numDocUsuario',ruc,
|
'numDocUsuario',ruc,
|
||||||
'rznSocialUsuario',parentorg,
|
'rznSocialUsuario',parentorg,
|
||||||
'tipMoneda',iso_code,
|
'tipMoneda',iso_code,
|
||||||
'sumTotTributos','18.00',
|
'sumTotTributos',grandtotal-totallines,
|
||||||
'sumTotValVenta','100.00',
|
'sumTotValVenta',totallines,
|
||||||
'sumPrecioVenta','118.00',
|
'sumPrecioVenta',grandtotal,
|
||||||
'sumDescTotal','0.00',
|
'sumDescTotal','0.00',
|
||||||
'sumOtrosCargos','0.00',
|
'sumOtrosCargos','0.00',
|
||||||
'sumTotalAnticipos','0.00',
|
'sumTotalAnticipos','0.00',
|
||||||
'sumImpVenta','118.00',
|
'sumImpVenta',grandtotal,
|
||||||
'ublVersionId','2.1',
|
'ublVersionId','2.1',
|
||||||
'customizationId','2.0'
|
'customizationId','2.0'
|
||||||
)
|
)
|
||||||
|
@ -96,7 +103,7 @@ select
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'invoiceline',c_invoiceline_id,
|
'invoiceline',c_invoiceline_id,
|
||||||
'codUnidadMedida','BX',
|
'codUnidadMedida','BX',
|
||||||
'ctdUnidadItem','5.00',
|
'ctdUnidadItem',qtyinvoiced,
|
||||||
'codProducto','10001',
|
'codProducto','10001',
|
||||||
'codProductoSUNAT','50161813',
|
'codProductoSUNAT','50161813',
|
||||||
'desItem','PRODUCTO 1',
|
'desItem','PRODUCTO 1',
|
||||||
|
@ -198,4 +205,6 @@ select
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
from ventas;
|
|
||||||
|
|
||||||
|
from ventas;
|
||||||
|
|
Loading…
Reference in a new issue