on 09-29-2023 4:01 PM
Hola necesito ayuda ya que actualmente tengo un procedimiento para ver los movimientos que a tenido un lote pero en la consulta me gustaria poder enlazarlos con el numero de documento. es decir que al dar click me mande al documento que genero el movimiento
este es mi qwery
SELECT DISTINCT
T0.ItemCode AS Cod_Item,
T0.ItemName AS Nombre_Item,
T0.BatchNum AS Lote,
T0.WhsCode AS Almacen,
CASE T1.Status
WHEN 0 THEN 'Liberado'
WHEN 1 THEN 'Acceso Denegado'
WHEN 2 THEN 'Bloqueado'
END AS Estado,
T2.Quantity AS Stock_Actual,
CASE T3.BaseType
WHEN 13 THEN 'Factura Clientes'
WHEN 14 THEN 'NC Clientes'
WHEN 15 THEN 'Entrega'
WHEN 16 THEN 'Devolucion'
WHEN 18 THEN 'Factura Proveedor'
WHEN 19 THEN 'NC Proveedores'
WHEN 20 THEN 'Entrada mercaderia OP'
WHEN 21 THEN 'Devolucion mercaderias'
WHEN 59 THEN 'Entrada mercaderias'
WHEN 60 THEN 'Salida de mercaderias'
WHEN 67 THEN 'Traslado stock'
ELSE CONVERT(NVARCHAR(5), T3.BaseType)
END AS Documento,
T3.BaseNum AS NroDocto,
T4.TransId AS Asiento,
T3.DocDate AS Fecha,
T3.WhsCode AS Alm_Docto,
T3.CardName AS SN,
CASE T3.Direction
WHEN 1 THEN T3.Quantity * -1
ELSE T3.Quantity
END AS Cant_Docto,
CASE T3.Direction
WHEN 1 THEN 'Salida'
ELSE 'Entrada'
END AS Sentido,
(
SELECT SUM(CASE
WHEN SubT3.Direction = 1 THEN SubT3.Quantity * -1
ELSE SubT3.Quantity
END)
FROM IBT1 SubT3
WHERE SubT3.ItemCode = T0.ItemCode
AND SubT3.BatchNum = T0.BatchNum
AND SubT3.WhsCode = T0.WhsCode
AND SubT3.DocDate < T3.DocDate
) + CASE T3.Direction
WHEN 1 THEN 0
ELSE T3.Quantity
END AS Saldo
FROM
OIBT T0
INNER JOIN
OBTN T1 ON T1.ItemCode = T0.ItemCode AND T1.DistNumber = T0.BatchNum
INNER JOIN
OBTQ T2 ON T2.ItemCode = T1.ItemCode AND T2.SysNumber = T1.SysNumber AND T2.WhsCode = T0.WhsCode
LEFT JOIN
IBT1 T3 ON T3.ItemCode = T0.ItemCode AND T3.BatchNum = T0.BatchNum AND T3.WhsCode = T0.WhsCode
LEFT JOIN
JDT1 T4 ON T4.TransType = T3.BaseType AND T4.BaseRef = T3.BaseNum AND T4.CreatedBy = T3.BaseEntry
WHERE
T3.ItemCode = 'MM3-0012'
ORDER BY
T3.DocDate ASC;
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.