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.
|
||||
-- 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
|
||||
ventas as (
|
||||
|
||||
|
@ -19,7 +29,8 @@ taxinvoice.name,
|
|||
c_invoicelinetax.taxbaseamt as linetaxbaseamt,c_invoicelinetax.taxamt as linetaxtaxamt,
|
||||
taxline.name,
|
||||
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
|
||||
|
@ -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_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
|
||||
|
||||
full outer join mensaje on true
|
||||
|
||||
|
||||
where
|
||||
|
@ -71,7 +82,7 @@ select
|
|||
'cabecera', jsonb_agg(DISTINCT
|
||||
jsonb_build_object(
|
||||
'ivoiceid',c_invoice_id,
|
||||
'tipOperacion','0101',
|
||||
'tipOperacion','1001',
|
||||
'fecEmision',dateinvoiced::date,
|
||||
'horEmision',dateinvoiced::time,
|
||||
'codLocalEmisor','0001',
|
||||
|
@ -102,14 +113,8 @@ select
|
|||
'sumTotalAnticipos','0.00',
|
||||
'sumImpVenta',grandtotal::varchar,
|
||||
'ublVersionId','2.1',
|
||||
'customizationId','2.0'
|
||||
)
|
||||
)->0
|
||||
)
|
||||
||
|
||||
jsonb_build_object(
|
||||
'adicionalCabecera', jsonb_agg(DISTINCT
|
||||
jsonb_build_object(
|
||||
'customizationId','2.0',
|
||||
'adicionalCabecera', jsonb_build_object(
|
||||
'invoiceid',c_invoice_id,
|
||||
'codPaisCliente','PE',
|
||||
'codUbigeoCliente','150140',
|
||||
|
@ -120,9 +125,10 @@ select
|
|||
'ctaBancoNacionDetraccion','11111111111',
|
||||
'codBienDetraccion','037',
|
||||
'porDetraccion','10.0',
|
||||
'mtoDetraccion','0.00',
|
||||
'mtoDetraccion',round(grandtotal*0.1,2)::varchar,
|
||||
'codMedioPago','003'
|
||||
)
|
||||
)
|
||||
)->0
|
||||
)
|
||||
||
|
||||
|
@ -195,8 +201,8 @@ select
|
|||
jsonb_build_object(
|
||||
'leyendas', jsonb_agg(DISTINCT
|
||||
jsonb_build_object(
|
||||
'codLeyenda','1000',
|
||||
'desLeyenda', concat(grandtotal::varchar,' ',iso_code)
|
||||
'codLeyenda', codigo,
|
||||
'desLeyenda', mens
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue