#Limpia una bodega insert into inv_detmovimiento (COD_CIA,SUCURSAL,TIP_MOVTO,COD_MOVTO,NUM_DOCTO,COD_BODEGA, COD_LOTE,COD_ARTICULO,MEDIDA,DOC_REFEREN,CAN_ARTICULO,CAN_DESPACHADA, CAN_BONIFICADA,LOCALIZA,CCOSTO,IMPUESTO_VTAS,SUB_TOTAL,CODMOVTO_REF) select '001', '001', 'S', '08', 2430, lb.cod_bodega, lb.cod_lote, lb.cod_articulo, medida, null, lb.can_existe, lb.can_existe, 0, lb.localiza,'0',0,lb.can_existe*ab.cos_promedio, null from inv_lote_artic_bodega lb, inv_articulo a, inv_artic_bodega ab where lb.cod_cia='001' and lb.cod_bodega='057' --and lb.cod_lote!='001' and a.cod_cia='001' and a.cod_articulo=ab.cod_articulo and ab.cod_cia='001' and ab.cod_bodega='057' and lb.can_existe>0 and lb.can_existe*ab.cos_promedio>0 and lb.cod_articulo=ab.cod_articulo; insert into inv_detmovimiento (COD_CIA,SUCURSAL,TIP_MOVTO,COD_MOVTO,NUM_DOCTO,COD_BODEGA, COD_LOTE,COD_ARTICULO,MEDIDA,DOC_REFEREN,CAN_ARTICULO,CAN_DESPACHADA, CAN_BONIFICADA,LOCALIZA,CCOSTO,IMPUESTO_VTAS,SUB_TOTAL,CODMOVTO_REF) select '001', '001', 'E', '03', 2490, '055', lb.cod_lote, lb.cod_articulo, medida, null, lb.can_existe, lb.can_existe, 0, lb.localiza,'0',0,lb.can_existe*ab.cos_promedio, null from inv_lote_artic_bodega lb, inv_articulo a, inv_artic_bodega ab where lb.cod_cia='001' and lb.cod_bodega='057' --and lb.cod_lote!='001' and a.cod_cia='001' and a.cod_articulo=ab.cod_articulo and ab.cod_cia='001' and ab.cod_bodega='057' and lb.can_existe>0 and lb.can_existe*ab.cos_promedio>0 and lb.cod_articulo=ab.cod_articulo; update inv_lote_artic_bodega lb set can_existe=0, can_apartado= 0 where lb.cod_cia='001' and lb.cod_bodega='057'; --and lb.cod_lote!='001'; update inv_artic_bodega lb set can_existe=0 where lb.cod_cia='001' and lb.cod_bodega='057'; update inv_encabmovimiento set estado='D' where cod_cia='001' and sucursal='001' and tip_movto='S' and cod_movto='08' and num_docto=2430; #Cambia de departamento update inv_articulo set cod_depto='055' where cod_depto='057'; #Otras utilidades delete inv_detmovimiento where cod_cia='001' and sucursal='001' and tip_movto='S' and cod_movto='08' and num_docto=x; select lb.cod_articulo, lb.cod_lote, lb.can_existe from inv_lote_artic_bodega lb, inv_articulo a, inv_artic_bodega ab where lb.cod_cia='001' and lb.cod_bodega='700' --and lb.cod_lote!='001' and a.cod_cia='001' and a.cod_articulo=ab.cod_articulo and ab.cod_cia='001' and ab.cod_bodega='700' and lb.cod_articulo=ab.cod_articulo and lb.can_existe>0 and lb.can_existe*ab.cos_promedio>0 --and lb.can_apartado>0 order by cod_articulo; update inv_artic_bodega b set can_existe=(select sum(can_existe) from inv_lote_artic_bodega lb where lb.cod_cia='001' and lb.cod_bodega=b.cod_bodega and lb.cod_articulo=b.cod_articulo) where b.cod_cia='001' and b.cod_bodega='700' and exists (select 1 from inv_lote_artic_bodega lb where lb.cod_cia='001' and lb.cod_bodega=b.cod_bodega and lb.cod_articulo=b.cod_articulo); -- Reubicacion select codigo, descripcio, bodega, cantidad, costo from bodestdb d where not exists (select 1 from inv_articulo i where i.cod_cia='001' and i.cod_articulo=codigo); create table bodmap as select codigo, codigo nuevo from bodestdb d where not exists (select 1 from inv_articulo i where i.cod_cia='001' and i.cod_articulo=codigo); select codigo, nuevo from bodmap d where not exists (select 1 from inv_articulo i where i.cod_cia='001' and i.cod_articulo=nuevo); update bodestdb d set codigo=(select nuevo from bodmap m where m.codigo=d.codigo) where not exists (select 1 from inv_articulo i where i.cod_cia='001' and i.cod_articulo=codigo); select bodega, count(*) from bodestdb d group by bodega; select cod_depto, count(*) from inv_articulo d group by cod_depto; select cod_articulo, des_articulo from inv_articulo d where cod_depto is null; set verify off define bodsal='''051''' define codmovsal='''10''' define nummovsal=2897 define bodent='''052''' define codmovent='''05''' define nummovent=1900 -- Salida por mapeo (bodestdb) insert into inv_detmovimiento (COD_CIA,SUCURSAL,TIP_MOVTO,COD_MOVTO,NUM_DOCTO,COD_BODEGA, COD_LOTE,COD_ARTICULO,MEDIDA,DOC_REFEREN,CAN_ARTICULO,CAN_DESPACHADA, CAN_BONIFICADA,LOCALIZA,CCOSTO,IMPUESTO_VTAS,SUB_TOTAL,CODMOVTO_REF) select '001', '001', 'S', &codmovsal, &nummovsal, lb.cod_bodega, lb.cod_lote, lb.cod_articulo, a.medida, null, lb.can_existe, lb.can_existe, 0, lb.localiza,'0',0,lb.can_existe*ab.cos_promedio, null from inv_lote_artic_bodega lb, bodestdb a, inv_artic_bodega ab where lb.cod_cia='001' and lb.cod_bodega='051' --and a.cod_cia='001' and a.codigo=ab.cod_articulo and ab.cod_cia='001' and ab.cod_bodega=&bodsal and a.bodega not in ('700','051') and lb.can_existe>0 and lb.can_existe*ab.cos_promedio>0 and lb.cod_articulo=ab.cod_articulo; -- Entrada por mapeo (bodestdb) insert into inv_detmovimiento (COD_CIA,SUCURSAL,TIP_MOVTO,COD_MOVTO,NUM_DOCTO,COD_BODEGA, COD_LOTE,COD_ARTICULO,MEDIDA,DOC_REFEREN,CAN_ARTICULO,CAN_DESPACHADA, CAN_BONIFICADA,LOCALIZA,CCOSTO,IMPUESTO_VTAS,SUB_TOTAL,CODMOVTO_REF) select '001', '001', 'E', &codmovent, &nummovent, a.bodega, lb.cod_lote, lb.cod_articulo, a.medida, null, lb.can_existe, lb.can_existe, 0, lb.localiza,'0',0,lb.can_existe*ab.cos_promedio, null from inv_lote_artic_bodega lb, bodestdb a, inv_artic_bodega ab where lb.cod_cia='001' and lb.cod_bodega='051' --and a.cod_cia='001' and a.codigo=ab.cod_articulo and ab.cod_cia='001' and ab.cod_bodega=&bodsal and a.bodega not in ('700','051') and lb.can_existe>0 and lb.can_existe*ab.cos_promedio>0 and lb.cod_articulo=ab.cod_articulo; delete inv_detmovimiento where cod_cia='001' and sucursal='001' and tip_movto='S' and cod_movto=&codmovsal and num_docto=&nummovsal; delete inv_detmovimiento where cod_cia='001' and sucursal='001' and tip_movto='E' and cod_movto=&codmovent and num_docto=&nummovent; update inv_articulo a set cod_depto=(select bodega from bodestdb db where db.codigo=a.cod_articulo) where cod_cia='001' and exists (select 1 from bodestdb b where b.codigo=a.cod_articulo); select num_docto, fec_movto, estado from inv_encabmovimiento where cod_cia='001' and sucursal='001' and ((tip_movto='E' and cod_movto=&codmovent and num_docto=&nummovent) or (tip_movto='S' and cod_movto=&codmovsal and num_docto=&nummovsal)); select sum(can_articulo), sum(sub_total) from inv_detmovimiento where cod_cia='001' and sucursal='001' and tip_movto='S' and cod_movto=&codmovsal and num_docto=&nummovsal; select sum(can_articulo), sum(sub_total) from inv_detmovimiento where cod_cia='001' and sucursal='001' and tip_movto='E' and cod_movto=&codmovent and num_docto=&nummovent; -- Verificacion de lotes-existencia drop table x2; create table x2 as select cod_cia, cod_bodega, cod_articulo, sum(can_existe) can_existe from inv_lote_artic_bodega where cod_bodega='051' group by cod_cia, cod_bodega, cod_articulo; select x2.cod_cia, x2.cod_bodega, x2.cod_articulo, x2.can_existe lot_existe, b.can_existe bod_existe from x2, inv_artic_bodega b where x2.cod_cia=b.cod_cia and x2.cod_bodega=b.cod_bodega and x2.cod_articulo=b.cod_articulo and x2.can_existe!=b.can_existe; select cod_articulo, cod_lote, can_existe from inv_lote_artic_bodega where cod_bodega='051' and cod_articulo in ('7441117264894','603076211075'); select cod_articulo, can_articulo, sub_total from inv_detmovimiento where cod_cia='001' and sucursal='001' and tip_movto='S' and cod_movto=&codmovsal and num_docto=&nummovsal and cod_lote in ('C','F'); select cod_articulo, can_articulo, sub_total from inv_detmovimiento where cod_cia='001' and sucursal='001' and tip_movto='E' and cod_movto=&codmovent and num_docto=&nummovent and cod_lote in ('C','F'); update inv_artic_bodega p set p.fec_ultcosto=(select fec_ultcosto from inv_artic_bodega s where s.cod_cia=p.cod_cia and s.cod_bodega='051' and s.cod_articulo=p.cod_articulo) where p.cod_bodega in ('052','053','054','055','056','057','058','059','060','061','062') and exists (select 'x' from inv_artic_bodega s where s.cod_cia=p.cod_cia and s.cod_bodega='051' and s.cod_articulo=p.cod_articulo and s.fec_ultcosto