Add all remaining elements of json for Facturador SUNAT app
This commit is contained in:
parent
7a9b50f591
commit
29c3a58f24
|
@ -6,7 +6,8 @@ with
|
|||
ventas as (
|
||||
|
||||
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,
|
||||
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,
|
||||
|
@ -41,12 +42,12 @@ left join fin_payment_schedule on fin_payment_schedule.c_invoice_id = c_invoice.
|
|||
|
||||
|
||||
where
|
||||
--c_invoice.documentno = 'E001-27' and
|
||||
c_invoice.documentno = '1000052' 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 ='Locate & Grow'
|
||||
ad_client.name ='BLB'
|
||||
--ad_client.name ='Locate & Grow'
|
||||
)
|
||||
|
||||
-- Above this line is the full query select all the required invoice data
|
||||
|
@ -56,7 +57,7 @@ ad_client.name ='Locate & Grow'
|
|||
--select *
|
||||
|
||||
|
||||
|
||||
--/*
|
||||
select
|
||||
|
||||
jsonb_build_object(
|
||||
|
@ -64,7 +65,7 @@ select
|
|||
jsonb_build_object(
|
||||
'ivoiceid',c_invoice_id,
|
||||
'tipoOperacion','0101',
|
||||
'fecEmision',date(dateinvoiced),
|
||||
'fecEmision',dateinvoiced::date,
|
||||
'horEmision',dateinvoiced::time,
|
||||
'codLocalEmisor','0001',
|
||||
'tipDocUsuario','6',
|
||||
|
@ -104,15 +105,15 @@ select
|
|||
'invoiceline',c_invoiceline_id,
|
||||
'codUnidadMedida','BX',
|
||||
'ctdUnidadItem',qtyinvoiced,
|
||||
'codProducto','10001',
|
||||
'codProducto',productcode,
|
||||
'codProductoSUNAT','50161813',
|
||||
'desItem','PRODUCTO 1',
|
||||
'mtoValorUnitario','10.00',
|
||||
'sumTotTributosItem','9.00',
|
||||
'desItem',productname,
|
||||
'mtoValorUnitario',priceactual,
|
||||
'sumTotTributosItem',linetaxtaxamt,
|
||||
|
||||
'codTriIGV','1000',
|
||||
'mtoIgvItem','9.00',
|
||||
'mtoBaseIgvItem','50.00',
|
||||
'mtoIgvItem',linetaxtaxamt,
|
||||
'mtoBaseIgvItem',linetaxbaseamt,
|
||||
'nomTributoIgvItem','IGV',
|
||||
'codTipTributoIgvItem','VAT',
|
||||
'tipAfeIGV','10',
|
||||
|
@ -140,8 +141,8 @@ select
|
|||
'codTipTributoIcbperItem','OTH',
|
||||
'mtoTriIcbperUnidad','0.30',
|
||||
|
||||
'mtoPrecioVentaUnitario','11.80',
|
||||
'mtoValorVentaItem','50.00',
|
||||
'mtoPrecioVentaUnitario',round((linenetamt+linetaxtaxamt)/qtyinvoiced,2),
|
||||
'mtoValorVentaItem',linenetamt,
|
||||
'mtoValorReferencialUnitario','0.00'
|
||||
)
|
||||
)
|
||||
|
@ -154,20 +155,21 @@ select
|
|||
jsonb_build_object(
|
||||
'tributos', jsonb_agg(DISTINCT
|
||||
jsonb_build_object(
|
||||
'invoiceid',c_invoice_id,
|
||||
'ideTributo','1000',
|
||||
'nomTributo','IGV',
|
||||
'codTipTributo','VAT',
|
||||
'mtoBaseImponible','100.00',
|
||||
'mtoTributo','18.00'
|
||||
'mtoBaseImponible',invoicetaxbaseamt,
|
||||
'mtoTributo',invoicetaxtaxamt
|
||||
)
|
||||
)
|
||||
)
|
||||
||
|
||||
jsonb_build_object(
|
||||
'leyendas', jsonb_build_object(
|
||||
'leyendas', jsonb_agg(DISTINCT
|
||||
jsonb_build_object(
|
||||
'codLeyenda','1000',
|
||||
'desLeyenda','CIENTO DIECIOCHO SOLES'
|
||||
'desLeyenda', concat(grandtotal::varchar,' ',iso_code)
|
||||
)
|
||||
)
|
||||
)
|
||||
||
|
||||
|
@ -180,31 +182,36 @@ select
|
|||
)
|
||||
||
|
||||
jsonb_build_object(
|
||||
'datoPago', jsonb_build_object(
|
||||
'datoPago', jsonb_agg(DISTINCT
|
||||
jsonb_build_object(
|
||||
'formaPago','Credito',
|
||||
'mtoNetoPendientePago','118.00',
|
||||
'tipMonedaMtoNetoPendientePago','PEN'
|
||||
'mtoNetoPendientePago',grandtotal,
|
||||
'tipMonedaMtoNetoPendientePago',iso_code
|
||||
)
|
||||
)
|
||||
)
|
||||
||
|
||||
jsonb_build_object(
|
||||
'detallePago', jsonb_agg(DISTINCT
|
||||
jsonb_build_object(
|
||||
'mtoCuotaPago','100.00',
|
||||
'fecCuotaPago','2021-11-30',
|
||||
'tipMonedaCuotaPago','PEN'
|
||||
'cuotaid',fin_payment_schedule_id,
|
||||
'mtoCuotaPago',cuota,
|
||||
'fecCuotaPago',duedate::date,
|
||||
'tipMonedaCuotaPago',iso_code
|
||||
)
|
||||
)
|
||||
)
|
||||
||
|
||||
jsonb_build_object(
|
||||
'retencion', jsonb_build_object(
|
||||
'impOperacion','118.00',
|
||||
'retencion', jsonb_agg(DISTINCT
|
||||
jsonb_build_object(
|
||||
'impOperacion',grandtotal,
|
||||
'porRetencion','0.00',
|
||||
'impRetencion','0.00'
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
from ventas;
|
||||
|
|
Loading…
Reference in a new issue