Add some extra required fields
This commit is contained in:
parent
26faf4a2ed
commit
3e131b74b9
|
@ -8,7 +8,8 @@ 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,
|
ad_client.name as client,documentno,c_invoice.description,dateinvoiced,totallines,grandtotal,
|
||||||
qtyinvoiced,priceactual,
|
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,
|
||||||
|
c_invoiceline.description as productdesc, 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,
|
||||||
c_paymentterm.name as paymentterm,c_paymentterm.netdays,
|
c_paymentterm.name as paymentterm,c_paymentterm.netdays,
|
||||||
|
@ -17,7 +18,8 @@ c_invoicetax.taxbaseamt as invoicetaxbaseamt,c_invoicetax.taxamt as invoicetaxta
|
||||||
taxinvoice.name,
|
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
|
||||||
|
|
||||||
|
|
||||||
from
|
from
|
||||||
|
@ -38,6 +40,9 @@ left join ad_org as division on division.ad_org_id = c_invoice.ad_org_id
|
||||||
left join ad_org as parent on parent.ad_org_id = division.ad_legalentity_org_id
|
left join ad_org as parent on parent.ad_org_id = division.ad_legalentity_org_id
|
||||||
left join ad_orginfo on ad_orginfo.ad_org_id = parent.ad_org_id
|
left join ad_orginfo on ad_orginfo.ad_org_id = parent.ad_org_id
|
||||||
left join fin_payment_schedule on fin_payment_schedule.c_invoice_id = c_invoice.c_invoice_id
|
left join fin_payment_schedule on fin_payment_schedule.c_invoice_id = c_invoice.c_invoice_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_country on c_country.c_country_id = c_location.c_country_id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +51,7 @@ 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
|
||||||
|
c_invoice.docstatus = 'CO' and
|
||||||
ad_client.name ='BLB'
|
ad_client.name ='BLB'
|
||||||
--ad_client.name ='Locate & Grow'
|
--ad_client.name ='Locate & Grow'
|
||||||
--ad_client.name ='Uchu Wasi'
|
--ad_client.name ='Uchu Wasi'
|
||||||
|
@ -69,10 +75,25 @@ select
|
||||||
'fecEmision',dateinvoiced::date,
|
'fecEmision',dateinvoiced::date,
|
||||||
'horEmision',dateinvoiced::time,
|
'horEmision',dateinvoiced::time,
|
||||||
'codLocalEmisor','0001',
|
'codLocalEmisor','0001',
|
||||||
'tipDocUsuario','6',
|
'tipDocUsuario',case
|
||||||
|
when length(taxid)=11 then '6'
|
||||||
|
when length(taxid)=8 then '1'
|
||||||
|
else '0' end,
|
||||||
'numDocUsuario',taxid,
|
'numDocUsuario',taxid,
|
||||||
'rznSocialUsuario',bpname,
|
'rznSocialUsuario',bpname,
|
||||||
'tipMoneda',iso_code,
|
'tipMoneda',iso_code,
|
||||||
|
'codMotivo',case
|
||||||
|
when substring(doctype,1,4)='Nota' then '01'
|
||||||
|
else '-' end,
|
||||||
|
'desMotivo',case
|
||||||
|
when substring(doctype,1,4)='Nota' then 'Anulacion de operacion'
|
||||||
|
else '-' end,
|
||||||
|
'tipDocAfectado',case
|
||||||
|
when substring(doctype,1,4)='Nota' then '01'
|
||||||
|
else '-' end,
|
||||||
|
'numDocAfectado',case
|
||||||
|
when substring(doctype,1,4)='Nota' then description
|
||||||
|
else '-' end,
|
||||||
'sumTotTributos',(grandtotal-totallines)::varchar,
|
'sumTotTributos',(grandtotal-totallines)::varchar,
|
||||||
'sumTotValVenta',totallines::varchar,
|
'sumTotValVenta',totallines::varchar,
|
||||||
'sumPrecioVenta',grandtotal::varchar,
|
'sumPrecioVenta',grandtotal::varchar,
|
||||||
|
@ -92,10 +113,15 @@ select
|
||||||
'invoiceid',c_invoice_id,
|
'invoiceid',c_invoice_id,
|
||||||
'codPaisCliente','PE',
|
'codPaisCliente','PE',
|
||||||
'codUbigeoCliente','150140',
|
'codUbigeoCliente','150140',
|
||||||
'desDireccionCliente','AV. ANGAMOS 1111, SURCO, LIMA',
|
'desDireccionCliente',direccioncliente,
|
||||||
'codPaisEntrega','PE',
|
'codPaisEntrega','PE',
|
||||||
'codUbigeoEntrega','150140',
|
'codUbigeoEntrega','150140',
|
||||||
'desDireccionEntrega','AV. ANGAMOS 1111, SURCO, LIMA'
|
'desDireccionEntrega',direccioncliente,
|
||||||
|
'ctaBancoNacionDetraccion','11111111111',
|
||||||
|
'codBienDetraccion','037',
|
||||||
|
'porDetraccion','10.0',
|
||||||
|
'mtoDetraccion','0.00',
|
||||||
|
'codMedioPago','003'
|
||||||
)
|
)
|
||||||
)->0
|
)->0
|
||||||
)
|
)
|
||||||
|
@ -106,9 +132,9 @@ select
|
||||||
'invoiceline',c_invoiceline_id,
|
'invoiceline',c_invoiceline_id,
|
||||||
'codUnidadMedida','BX',
|
'codUnidadMedida','BX',
|
||||||
'ctdUnidadItem',qtyinvoiced::varchar,
|
'ctdUnidadItem',qtyinvoiced::varchar,
|
||||||
'codProducto',productcode,
|
'codProducto',coalesce(productcode,'-'),
|
||||||
'codProductoSUNAT','50161813',
|
'codProductoSUNAT','50161813',
|
||||||
'desItem',productname,
|
'desItem',coalesce(productname,productdesc,'-'),
|
||||||
'mtoValorUnitario',priceactual::varchar,
|
'mtoValorUnitario',priceactual::varchar,
|
||||||
'sumTotTributosItem',linetaxtaxamt::varchar,
|
'sumTotTributosItem',linetaxtaxamt::varchar,
|
||||||
|
|
||||||
|
@ -135,7 +161,8 @@ select
|
||||||
'codTipTributoOtroItem','OTH',
|
'codTipTributoOtroItem','OTH',
|
||||||
'porTriOtroItem','0.00',
|
'porTriOtroItem','0.00',
|
||||||
|
|
||||||
'codTriIcbper','7152',
|
-- 'codTriIcbper','7152',
|
||||||
|
'codTriIcbper','-',
|
||||||
'mtoTriIcbperItem','0.00',
|
'mtoTriIcbperItem','0.00',
|
||||||
'ctdBolsasTriIcbperItem','0',
|
'ctdBolsasTriIcbperItem','0',
|
||||||
'nomTributoIcbperItem','ICBPER',
|
'nomTributoIcbperItem','ICBPER',
|
||||||
|
@ -182,26 +209,34 @@ select
|
||||||
'variablesGlobales','[]'::jsonb
|
'variablesGlobales','[]'::jsonb
|
||||||
)
|
)
|
||||||
||
|
||
|
||||||
jsonb_build_object(
|
case
|
||||||
'datoPago', jsonb_agg(DISTINCT
|
when substring(doctype,1,4)='Bole' then jsonb_build_object('datoPagoX','[]'::jsonb)
|
||||||
jsonb_build_object(
|
else
|
||||||
'formaPago','Credito',
|
jsonb_build_object(
|
||||||
'mtoNetoPendientePago',grandtotal::varchar,
|
'datoPago', jsonb_agg(DISTINCT
|
||||||
'tipMonedaMtoNetoPendientePago',iso_code
|
jsonb_build_object(
|
||||||
)
|
'formaPago','Credito',
|
||||||
)->0
|
'mtoNetoPendientePago',grandtotal::varchar,
|
||||||
)
|
'tipMonedaMtoNetoPendientePago',iso_code
|
||||||
|
)
|
||||||
|
)->0
|
||||||
|
)
|
||||||
|
end
|
||||||
||
|
||
|
||||||
jsonb_build_object(
|
case
|
||||||
'detallePago', jsonb_agg(DISTINCT
|
when substring(doctype,1,4)='Bole' then jsonb_build_object('detallePagoX','[]'::jsonb)
|
||||||
jsonb_build_object(
|
else
|
||||||
'cuotaid',fin_payment_schedule_id,
|
jsonb_build_object(
|
||||||
'mtoCuotaPago',cuota::varchar,
|
'detallePago', jsonb_agg(DISTINCT
|
||||||
'fecCuotaPago',duedate::date,
|
jsonb_build_object(
|
||||||
'tipMonedaCuotaPago',iso_code
|
'cuotaid',fin_payment_schedule_id,
|
||||||
|
'mtoCuotaPago',abs(cuota)::varchar,
|
||||||
|
'fecCuotaPago',duedate::date,
|
||||||
|
'tipMonedaCuotaPago',iso_code
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
end
|
||||||
||
|
||
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'retencion', jsonb_agg(DISTINCT
|
'retencion', jsonb_agg(DISTINCT
|
||||||
|
@ -212,8 +247,9 @@ select
|
||||||
)
|
)
|
||||||
)->0
|
)->0
|
||||||
)
|
)
|
||||||
)::varchar
|
)::varchar,doctype,ruc
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
|
|
||||||
from ventas;
|
from ventas
|
||||||
|
group by doctype,ruc;
|
||||||
|
|
Loading…
Reference in a new issue