jueves, 10 de octubre de 2013

Completed Sales Orders in Adempiere

-- select * from vw_ordenes_ventas_completadas ov limit 100;

drop view if exists vw_ordenes_ventas_completadas;

create view vw_ordenes_ventas_completadas
as
select
    og.ad_org_id as id_organizacion,
    og.name as organizacion,
    o.c_order_id as id_orden,
    o.documentno as num_orden,
    o.dateordered as fecha_orden,
    o.description as descripcion,
    bp.c_bpartner_id as id_tercero,
    bp.value as cod_tercero,
    bp.name as tercero,
    l.c_location_id as id_direccion,
    coalesce(l.address1, l.address2) as direccion,
    u.ad_user_id as id_contacto,
    u.name as contacto,
    w.m_warehouse_id as id_almacen,
    w.name as almacen,
    pl.m_pricelist_id as id_lista_precio,
    pl.name as lista_precio,
    c.c_currency_id as id_moneda,
    c.iso_code as moneda,
    pt.c_paymentterm_id as id_termino_pago,
    pt.name as termino_pago,
    o.totallines as total_lineas,
    o.grandtotal as gran_total,
    o.posted as esta_contabilizado,
    o.processedon as completado,
    cast(to_timestamp(o.processedon/1000) as date) as fecha_completado
from c_order o
    join ad_org og
    on o.ad_org_id = og.ad_org_id
    join c_bpartner bp
    on o.c_bpartner_id = bp.c_bpartner_id
    left outer join c_bpartner_location bl
    on bp.c_bpartner_id = bl.c_bpartner_id
    left outer join c_location l
    on bl.c_location_id = l.c_location_id
    join ad_user u
    on o.ad_user_id = u.ad_user_id
    join m_warehouse w
    on o.m_warehouse_id = w.m_warehouse_id
    join m_pricelist pl
    on o.m_pricelist_id = pl.m_pricelist_id
    join c_currency c
    on o.c_currency_id = c.c_currency_id
    left outer join c_paymentterm pt
    on o.c_paymentterm_id = pt.c_paymentterm_id
where o.ad_client_id = 1000001
    and o.docstatus = 'CO'
    and o.issotrx = 'Y'
    and o.c_doctypetarget_id = 1000039;

No hay comentarios:

Publicar un comentario