Move adicionalCabecera as nested json of cabecera.
Add support for Leyendas using a temp table mensaje.
This commit is contained in:
parent
e4684a023c
commit
020b6c53dc
|
@ -2,6 +2,16 @@
|
||||||
-- a JSON document for submitting through the FACTURADOR SUNAT application.
|
-- a JSON document for submitting through the FACTURADOR SUNAT application.
|
||||||
-- FACTURADOR SUNAT is a free application for generating Facturas Electronicas SUNAT.
|
-- FACTURADOR SUNAT is a free application for generating Facturas Electronicas SUNAT.
|
||||||
|
|
||||||
|
create temp table if not exists mensaje (
|
||||||
|
codigo varchar(4),
|
||||||
|
mens varchar(100)
|
||||||
|
);
|
||||||
|
truncate mensaje;
|
||||||
|
insert into mensaje (codigo, mens)
|
||||||
|
values ('1000','motary value in text'),
|
||||||
|
('2006','Operación sujeta a detracción'),
|
||||||
|
('NNNN','Any other required legend');
|
||||||
|
|
||||||
with
|
with
|
||||||
ventas as (
|
ventas as (
|
||||||
|
|
||||||
|
@ -19,7 +29,8 @@ taxinvoice.name,
|
||||||
c_invoicelinetax.taxbaseamt as linetaxbaseamt,c_invoicelinetax.taxamt as linetaxtaxamt,
|
c_invoicelinetax.taxbaseamt as linetaxbaseamt,c_invoicelinetax.taxamt as linetaxtaxamt,
|
||||||
taxline.name,
|
taxline.name,
|
||||||
fin_payment_schedule.amount as cuota, fin_payment_schedule.duedate, fin_payment_schedule.fin_payment_schedule_id,
|
fin_payment_schedule.amount as cuota, fin_payment_schedule.duedate, fin_payment_schedule.fin_payment_schedule_id,
|
||||||
concat(c_location.address1,' ',c_location.address2,' ',c_location.city,' ',c_location.postal,' ',c_country.name) as direccioncliente
|
concat(c_location.address1,' ',c_location.address2,' ',c_location.city,' ',c_location.postal,' ',c_country.name) as direccioncliente,
|
||||||
|
codigo, mens
|
||||||
|
|
||||||
|
|
||||||
from
|
from
|
||||||
|
@ -43,7 +54,7 @@ left join fin_payment_schedule on fin_payment_schedule.c_invoice_id = c_invoice.
|
||||||
left join c_bpartner_location on c_bpartner_location.c_bpartner_location_id = c_invoice.c_bpartner_location_id
|
left join c_bpartner_location on c_bpartner_location.c_bpartner_location_id = c_invoice.c_bpartner_location_id
|
||||||
left join c_location on c_location.c_location_id = c_bpartner_location.c_location_id
|
left join c_location on c_location.c_location_id = c_bpartner_location.c_location_id
|
||||||
left join c_country on c_country.c_country_id = c_location.c_country_id
|
left join c_country on c_country.c_country_id = c_location.c_country_id
|
||||||
|
full outer join mensaje on true
|
||||||
|
|
||||||
|
|
||||||
where
|
where
|
||||||
|
@ -71,7 +82,7 @@ select
|
||||||
'cabecera', jsonb_agg(DISTINCT
|
'cabecera', jsonb_agg(DISTINCT
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'ivoiceid',c_invoice_id,
|
'ivoiceid',c_invoice_id,
|
||||||
'tipOperacion','0101',
|
'tipOperacion','1001',
|
||||||
'fecEmision',dateinvoiced::date,
|
'fecEmision',dateinvoiced::date,
|
||||||
'horEmision',dateinvoiced::time,
|
'horEmision',dateinvoiced::time,
|
||||||
'codLocalEmisor','0001',
|
'codLocalEmisor','0001',
|
||||||
|
@ -102,26 +113,21 @@ select
|
||||||
'sumTotalAnticipos','0.00',
|
'sumTotalAnticipos','0.00',
|
||||||
'sumImpVenta',grandtotal::varchar,
|
'sumImpVenta',grandtotal::varchar,
|
||||||
'ublVersionId','2.1',
|
'ublVersionId','2.1',
|
||||||
'customizationId','2.0'
|
'customizationId','2.0',
|
||||||
)
|
'adicionalCabecera', jsonb_build_object(
|
||||||
)->0
|
'invoiceid',c_invoice_id,
|
||||||
)
|
'codPaisCliente','PE',
|
||||||
||
|
'codUbigeoCliente','150140',
|
||||||
jsonb_build_object(
|
'desDireccionCliente',direccioncliente,
|
||||||
'adicionalCabecera', jsonb_agg(DISTINCT
|
'codPaisEntrega','PE',
|
||||||
jsonb_build_object(
|
'codUbigeoEntrega','150140',
|
||||||
'invoiceid',c_invoice_id,
|
'desDireccionEntrega',direccioncliente,
|
||||||
'codPaisCliente','PE',
|
'ctaBancoNacionDetraccion','11111111111',
|
||||||
'codUbigeoCliente','150140',
|
'codBienDetraccion','037',
|
||||||
'desDireccionCliente',direccioncliente,
|
'porDetraccion','10.0',
|
||||||
'codPaisEntrega','PE',
|
'mtoDetraccion',round(grandtotal*0.1,2)::varchar,
|
||||||
'codUbigeoEntrega','150140',
|
'codMedioPago','003'
|
||||||
'desDireccionEntrega',direccioncliente,
|
)
|
||||||
'ctaBancoNacionDetraccion','11111111111',
|
|
||||||
'codBienDetraccion','037',
|
|
||||||
'porDetraccion','10.0',
|
|
||||||
'mtoDetraccion','0.00',
|
|
||||||
'codMedioPago','003'
|
|
||||||
)
|
)
|
||||||
)->0
|
)->0
|
||||||
)
|
)
|
||||||
|
@ -195,8 +201,8 @@ select
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'leyendas', jsonb_agg(DISTINCT
|
'leyendas', jsonb_agg(DISTINCT
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'codLeyenda','1000',
|
'codLeyenda', codigo,
|
||||||
'desLeyenda', concat(grandtotal::varchar,' ',iso_code)
|
'desLeyenda', mens
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue