drop table invini;
create table invini as 
select a.cod_articulo,b.des_articulo,sum(monto) monto,sum(cantidad) cantidad
from inv_acum_periodo a,inv_articulo b
where a.cod_cia='001'
and b.cod_cia='001'
and a.cod_articulo=b.cod_articulo
and a.cod_bodega='001'
and a.ano_fiscal=2004
and a.per_proceso=1
and a.clase_movto='EI'
group by a.cod_articulo,b.des_articulo;


insert into invini 
select a.cod_articulo,b.des_articulo,sum(monto) monto,sum(cantidad) cantidad
from inv_acum_periodo a,inv_articulo b
where a.cod_cia='001'
and b.cod_cia='001'
and a.cod_articulo=b.cod_articulo
and a.cod_bodega='002'
and a.ano_fiscal=2004
and a.per_proceso=1
and a.clase_movto='EI'
group by a.cod_articulo,b.des_articulo;

commit;

select COD_ARTICULO||'|'||DES_ARTICULO||'|'||sum(MONTO) monto||'|'||sum(CANTIDAD) cantidad||'|'
from invini
group by cod_articulo,des_articulo;

  drop table detmov;
  create table detmov as
  select c.des_movto,b.fec_movto,a.cod_articulo,
  a.can_articulo,a.sub_total/a.can_articulo cosunidad
  from inv_detmovimiento a,inv_encabmovimiento b,inv_concepmovto c
  where a.cod_cia='001'
  and   b.cod_cia='001'
  and   c.cod_cia='001'
  and   a.sucursal=b.sucursal
  and   a.tip_movto=b.tip_movto
  and   a.num_docto=b.num_docto 
  and   a.tip_movto=c.tip_movto
  and   a.cod_movto=c.cod_movto
  and   b.tip_movto=c.tip_movto
  and   b.cod_movto=c.cod_movto
  and   b.estado='D'
  and   c.clase_movto not in  ('ET','ST')
  and   a.cod_articulo in 
  ('135150','135160','135170','135180','136002','136003','136005','136008',
   '136020','155010','155020','155030','155050','155060','155100','155130',
   '155140','155161','155181','155182')
  order by  a.cod_articulo,b.fec_movto;


  drop table detmova;
 create table detmova as
  select c.des_movto,b.fec_movto,a.cod_articulo,
  a.can_articulo,a.sub_total/a.can_articulo cosunidad
  from carazo.inv_detmovimiento a,carazo.inv_encabmovimiento b,carazo.inv_concepmovto c
  where a.cod_cia='001'
  and   b.cod_cia='001'
  and   c.cod_cia='001'
  and   a.sucursal=b.sucursal
  and   a.tip_movto=b.tip_movto
  and   a.num_docto=b.num_docto 
  and   a.tip_movto=c.tip_movto
  and   a.cod_movto=c.cod_movto
  and   b.tip_movto=c.tip_movto
  and   b.cod_movto=c.cod_movto
  and   b.estado='D'
  and   c.clase_movto not in  ('ET','ST')
  and   a.cod_articulo in 
  ('135150','135160','135170','135180','136002','136003','136005','136008',
   '136020','155010','155020','155030','155050','155060','155100','155130',
   '155140','155161','155181','155182')
  order by  a.cod_articulo,b.fec_movto;

drop table difmov;
create table difmov as
select a.des_movto,a.fec_movto,a.cod_articulo,a.can_articulo,a.cosunidad,b.cosunidad cosueps
from detmov a,detmova b
where a.des_movto=b.des_movto
and   a.fec_movto=b.fec_movto
and   a.cod_articulo=b.cod_articulo;


select des_movto||'|'||to_char(fec_movto,'dd/mm/yyyy')||'|'||cod_articulo||'|'||can_articulo||'|'||
cosunidad||'|'||cosueps||'|'
from difmov
order by cod_articulo,fec_movto;



  select c.des_movto,b.fec_movto,a.cod_articulo,
  a.can_articulo,a.sub_total/a.can_articulo cosunidad
  from inv_detmovimiento a,inv_encabmovimiento b,carazo.inv_concepmovto c
  where a.cod_cia='001'
  and   b.cod_cia='001'
  and   c.cod_cia='001'
  and   a.sucursal=b.sucursal
  and   a.tip_movto=b.tip_movto
  and   a.num_docto=b.num_docto 
  and   a.tip_movto=c.tip_movto
  and   a.cod_movto=c.cod_movto
  and   b.tip_movto=c.tip_movto
  and   b.cod_movto=c.cod_movto
  and   b.estado='D'
  and   c.clase_movto not in  ('ET','ST')
  and   a.cod_articulo ='155185'
  order by  a.cod_articulo,b.fec_movto;

