Gestion inactivos

Hola, Monial!

En lugar de la consulta de inactivos nosotros usamos una query hecha con las tablas OINM, OITW, OITM y OWHS, con fechas de los últimos movimientos para ver aquellos artículos con baja rotación.

Te la pego a continuación, pero tendrás que revisarla tú porque tenemos Características (QryGroup) activadas en los artículos y algún campo de usuario, pero quizás te sirva. También te advierto que la consulta se toma su tiempo

Suerte!. :four_leaf_clover:

declare     @fechainicio as nvarchar(8)
declare @meses as int

set @fechainicio='20160101'
set @meses=3

select
t0.itemcode as 'Producto',
t1.itemname as 'Descripcion',
t1.glmethod as 'DefiniciónContable',
t1.qrygroup1 as 'RepuestoCliente',
t1.qrygroup2 as 'ModuloReparacion',
t1.qrygroup3 as 'AF',
t1.qrygroup4 as 'Servicios',
t1.qrygroup5 as 'MaterialGasto',
t0.onhand as 'StockActual',
t0.whscode as 'Almacen',
isnull((t0.onhand * t0.avgprice),0) as 'ValorAlmacen',
dateadd(month,@meses*-1,convert(datetime,@fechainicio,112)) as 'Fecha_Inicio_Seleccion',
convert(datetime,@fechainicio,112) as 'Fecha_Fin_Seleccion', 

--isnull((select sum(t100.outqty) from oinm t100 with(nolock) where
--t100.itemcode= t0.itemcode and t100.warehouse = t0.whscode),0) as 'Cantidad_Salidas_Almacen',

isnull((select sum(t100.inqty) from oinm t100  with(nolock) where
t100.itemcode= t0.itemcode and t100.warehouse = t0.whscode),0) as 'Cantidad_Entradas_Almacen',

isnull((select count(*) from oinm t100  with(nolock) where t100.itemcode = t0.itemcode and t100.warehouse = t0.whscode and (t100.inqty<>0 or t100.outqty<>0)),0) as 'Numero_movimientos_Almacéen',

(select top 1 t100.docdate from oinm t100  with(nolock) where t100.inqty<>0 and t100.itemcode = t0.itemcode and t100.warehouse = t0.whscode order by t100.docdate desc) as 'Fecha_Ultima_Entrada_Almacen',

(select top 1 t100.docdate from oinm t100  with(nolock) where t100.outqty<>0 and t100.itemcode = t0.itemcode and t100.warehouse = t0.whscode order by t100.docdate desc) as 'Fecha_Ultima_Salida_Almacen'
from
oitw t0
inner join oitm t1  with(nolock) on t0.itemcode = t1.itemcode
inner join owhs t2  with(nolock) on t0.whscode = t2.whscode
where 
t0.onhand > 0
and t2.location = 40 and t2.u_exo_type = '0'
--and t0.itemcode = 'dpcbmobiletelvend'
--and t0.whscode = 'mov'
and not exists
(
select
top 1 t100.transnum from oinm t100  with(nolock) where t100.itemcode = t0.itemcode and t100.warehouse = t0.whscode
and t100.Comments not like 'Registro Finanzas%'
and (t100.inqty<>0 or t100.outqty <> 0) and convert(datetime,t100.docdate,112) > dateadd(month,@meses*-1,convert(datetime,@fechainicio,112))
)
1 me gusta