/*==============================================================*/
/* Database name:  ESTADISTICAS                                 */
/* DBMS name:      ORACLE Version 7                             */
/* Created on:     4/28/03 4:32:05 PM                           */
/*==============================================================*/


create or replace view est_genlinea as
   select a.cia,a.sucursal,b.cod_linea,a.periodo,a.moneda,
          sum(a.cantidadven) cantidadven,sum(a.montoven) montoven
   from estdet a,inv_articulo b
   where a.cia=b.cod_cia
   and   a.articulo=b.cod_articulo
   group by a.cia,a.sucursal,b.cod_linea,a.periodo,a.moneda;


create or replace view est_genclient as
   select a.cia,a.sucursal,a.cliente,a.periodo,a.moneda,
          sum(a.cantidadven) cantidadven,sum(a.montoven) montoven
   from estdet a
   group by a.cia,a.sucursal,a.cliente,a.periodo,a.moneda;


create or replace view est_genagente as
   select a.cia,a.sucursal,a.agente,a.periodo,a.moneda,
          sum(a.montodev) montodev,sum(a.montoven) montoven
   from estdet a
   group by a.cia,a.sucursal,a.agente,a.periodo,a.moneda;

create or replace view est_genartic as
   SELECT CIA, SUCURSAL, ARTICULO, PERIODO, MONEDA,
       SUM(a.MONTOVEN) MON_VENDIDO, SUM(a.CANTIDADVEN) CAN_UNIDADES,
       SUM(a.MONTODEV) MON_DEVUELTO, SUM(a.CANTIDADDEV) CAN_DEVUELTAS
   FROM ESTDET A
   GROUP BY CIA, SUCURSAL, ARTICULO, PERIODO, MONEDA;


create or replace view est_detartic as
   select a.cia,a.sucursal,a.cliente,a.articulo,a.periodo,a.moneda,
          sum(a.cantidadven) cantidadven,sum(a.montoven) montoven
   from estdet a
   group by a.cia,a.sucursal,a.cliente,a.articulo,a.periodo,a.moneda;


create or replace view est_detlinea as
   select a.cia,a.sucursal,b.cod_linea,a.articulo,b.des_articulo,a.periodo,a.moneda,
          sum(a.cantidadven) cantidadven,sum(a.montoven) montoven
   from estdet a,inv_articulo b
   where a.cia=b.cod_cia
   and   a.articulo=b.cod_articulo
   group by a.cia,a.sucursal,b.cod_linea,a.articulo,b.des_articulo,a.periodo,a.moneda;


create or replace view est_detagente as
   select a.cia,a.sucursal,a.agente,a.articulo,a.periodo,a.moneda,
          sum(a.cantidadven) cantidadven,sum(a.montoven) montoven
   from estdet a
   group by a.cia,a.sucursal,a.agente,a.articulo,a.periodo,a.moneda;

