Add all remaining elements of json for Facturador SUNAT app

This commit is contained in:
Enrique Barcelli 2021-12-03 23:54:45 +08:00
parent 7a9b50f591
commit 29c3a58f24

View file

@ -6,7 +6,8 @@ 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 as client,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 as productcode,m_product.name as productname,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 as bpname,c_bpartner.taxid,c_uom.name as uom,c_doctype.name as doctype, c_bpartner.name as bpname,c_bpartner.taxid,c_uom.name as uom,c_doctype.name as doctype,
@ -41,12 +42,12 @@ 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.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' --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
@ -56,7 +57,7 @@ ad_client.name ='Locate & Grow'
--select * --select *
--/*
select select
jsonb_build_object( jsonb_build_object(
@ -64,7 +65,7 @@ select
jsonb_build_object( jsonb_build_object(
'ivoiceid',c_invoice_id, 'ivoiceid',c_invoice_id,
'tipoOperacion','0101', 'tipoOperacion','0101',
'fecEmision',date(dateinvoiced), 'fecEmision',dateinvoiced::date,
'horEmision',dateinvoiced::time, 'horEmision',dateinvoiced::time,
'codLocalEmisor','0001', 'codLocalEmisor','0001',
'tipDocUsuario','6', 'tipDocUsuario','6',
@ -104,15 +105,15 @@ select
'invoiceline',c_invoiceline_id, 'invoiceline',c_invoiceline_id,
'codUnidadMedida','BX', 'codUnidadMedida','BX',
'ctdUnidadItem',qtyinvoiced, 'ctdUnidadItem',qtyinvoiced,
'codProducto','10001', 'codProducto',productcode,
'codProductoSUNAT','50161813', 'codProductoSUNAT','50161813',
'desItem','PRODUCTO 1', 'desItem',productname,
'mtoValorUnitario','10.00', 'mtoValorUnitario',priceactual,
'sumTotTributosItem','9.00', 'sumTotTributosItem',linetaxtaxamt,
'codTriIGV','1000', 'codTriIGV','1000',
'mtoIgvItem','9.00', 'mtoIgvItem',linetaxtaxamt,
'mtoBaseIgvItem','50.00', 'mtoBaseIgvItem',linetaxbaseamt,
'nomTributoIgvItem','IGV', 'nomTributoIgvItem','IGV',
'codTipTributoIgvItem','VAT', 'codTipTributoIgvItem','VAT',
'tipAfeIGV','10', 'tipAfeIGV','10',
@ -140,8 +141,8 @@ select
'codTipTributoIcbperItem','OTH', 'codTipTributoIcbperItem','OTH',
'mtoTriIcbperUnidad','0.30', 'mtoTriIcbperUnidad','0.30',
'mtoPrecioVentaUnitario','11.80', 'mtoPrecioVentaUnitario',round((linenetamt+linetaxtaxamt)/qtyinvoiced,2),
'mtoValorVentaItem','50.00', 'mtoValorVentaItem',linenetamt,
'mtoValorReferencialUnitario','0.00' 'mtoValorReferencialUnitario','0.00'
) )
) )
@ -154,20 +155,21 @@ select
jsonb_build_object( jsonb_build_object(
'tributos', jsonb_agg(DISTINCT 'tributos', jsonb_agg(DISTINCT
jsonb_build_object( jsonb_build_object(
'invoiceid',c_invoice_id,
'ideTributo','1000', 'ideTributo','1000',
'nomTributo','IGV', 'nomTributo','IGV',
'codTipTributo','VAT', 'codTipTributo','VAT',
'mtoBaseImponible','100.00', 'mtoBaseImponible',invoicetaxbaseamt,
'mtoTributo','18.00' 'mtoTributo',invoicetaxtaxamt
) )
) )
) )
|| ||
jsonb_build_object( jsonb_build_object(
'leyendas', jsonb_build_object( 'leyendas', jsonb_agg(DISTINCT
'codLeyenda','1000', jsonb_build_object(
'desLeyenda','CIENTO DIECIOCHO SOLES' 'codLeyenda','1000',
'desLeyenda', concat(grandtotal::varchar,' ',iso_code)
)
) )
) )
|| ||
@ -180,31 +182,36 @@ select
) )
|| ||
jsonb_build_object( jsonb_build_object(
'datoPago', jsonb_build_object( 'datoPago', jsonb_agg(DISTINCT
'formaPago','Credito', jsonb_build_object(
'mtoNetoPendientePago','118.00', 'formaPago','Credito',
'tipMonedaMtoNetoPendientePago','PEN' 'mtoNetoPendientePago',grandtotal,
'tipMonedaMtoNetoPendientePago',iso_code
)
) )
) )
|| ||
jsonb_build_object( jsonb_build_object(
'detallePago', jsonb_agg(DISTINCT 'detallePago', jsonb_agg(DISTINCT
jsonb_build_object( jsonb_build_object(
'mtoCuotaPago','100.00', 'cuotaid',fin_payment_schedule_id,
'fecCuotaPago','2021-11-30', 'mtoCuotaPago',cuota,
'tipMonedaCuotaPago','PEN' 'fecCuotaPago',duedate::date,
'tipMonedaCuotaPago',iso_code
) )
) )
) )
|| ||
jsonb_build_object( jsonb_build_object(
'retencion', jsonb_build_object( 'retencion', jsonb_agg(DISTINCT
'impOperacion','118.00', jsonb_build_object(
'porRetencion','0.00', 'impOperacion',grandtotal,
'impRetencion','0.00' 'porRetencion','0.00',
'impRetencion','0.00'
)
) )
) )
--*/
from ventas; from ventas;