0% found this document useful (0 votes)
26 views4 pages

PROCEDURE SP - DOCUMENTOS - PICKING - DETALLE - Pat1

The stored procedure selects item details from orders or invoices based on an object type and document entry. It retrieves line items where the pending quantity is greater than zero, there is more than one storage location, the warehouse stock is greater than zero, and the stock is greater than the total reserved quantity. The details are inserted into a temporary table for further processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

PROCEDURE SP - DOCUMENTOS - PICKING - DETALLE - Pat1

The stored procedure selects item details from orders or invoices based on an object type and document entry. It retrieves line items where the pending quantity is greater than zero, there is more than one storage location, the warehouse stock is greater than zero, and the stock is greater than the total reserved quantity. The details are inserted into a temporary table for further processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

CREATE PROCEDURE SP_DITECA_DOCUMENTOS_PICKING_DETALLE(

DocEntry INT,
ObjType VARCHAR(20)
)
AS
BEGIN

DECLARE v_count INT;


DECLARE v_i INT;
DECLARE v_2_count INT;
DECLARE v_2_i INT;
DECLARE aux_Ubicacion INT;
DECLARE aux_ArrUbicaciones NVARCHAR(500);
DECLARE aux_Pendiente DECIMAL(19,6);
DECLARE aux_Reservar DECIMAL(19,6);
DECLARE aux_Disponible DECIMAL(19,6);
DECLARE aux_Reservado DECIMAL(19,6);
DECLARE aux_NuevaReserva DECIMAL(19,6);
--DECLARE aux_ReservadoDoc DECIMAL(19,6);
DECLARE aux_TotalUbi DECIMAL(19,6);
DECLARE aux_DocEntry INT;
DECLARE aux_ItemCode NVARCHAR(50);
DECLARE aux_WhsCode NVARCHAR(8);
DECLARE aux_LineNum INT;
DECLARE aux_ObjType NVARCHAR(20);

CREATE LOCAL TEMPORARY TABLE #DETALLE(

LineNum INT,
ItemCode NVARCHAR(50),
WhsCode NVARCHAR(8),
Reservar DECIMAL(19,6),
Pendiente DECIMAL(19,6),
Disponible DECIMAL(19,6),
Reservado DECIMAL(19,6),
--ReservadoDoc DECIMAL(19,6),
TotalUbi DECIMAL(19,6),
Ubicacion INT

);

-- Obtener los items que no son de lote y serie, y estan listos para ser tratados
-- Obtener cuantas ubicaciones tiene aquel item

IF :ObjType = 17 THEN

tmp_result = SELECT * FROM (


SELECT * ,
( "OpenQty" - "TotalReservado" ) AS "Pendiente"
FROM (
SELECT
a."DocEntry",
a."ObjType",
b."LineNum",
b."ItemCode",
b."WhsCode",
b."Quantity",
b."OpenQty",

(
SELECT IFNULL(SUM( t3."RelQtty" + t3."PickQtty" ),0)
FROM OPKL AS t1
INNER JOIN PKL1 AS t2 ON ( t1."AbsEntry" =
t2."AbsEntry" )
INNER JOIN PKL2 AS t3 ON ( t1."AbsEntry" =
t3."AbsEntry" AND t2."PickEntry" = t3."PickEntry" )
INNER JOIN OBIN AS t4 ON ( t3."BinAbs" =
t4."AbsEntry" )
WHERE t1."Status" != 'C'
AND t2."PickStatus" != 'C'
AND t3."ItemCode" = b."ItemCode"
AND t4."WhsCode" = b."WhsCode"
) AS "TotalReservadoBodega",

(
SELECT IFNULL(SUM( t3."RelQtty" + t3."PickQtty" ),0)
FROM OPKL AS t1
INNER JOIN PKL1 AS t2 ON ( t1."AbsEntry" =
t2."AbsEntry" )
INNER JOIN PKL2 AS t3 ON ( t1."AbsEntry" =
t3."AbsEntry" AND t2."PickEntry" = t3."PickEntry" )
WHERE t1."Status" != 'C'
AND t2."PickStatus" != 'C'
AND t2."OrderEntry" = a."DocEntry"
AND t2."OrderLine" = b."LineNum"
AND t2."BaseObject" = a."ObjType"
AND t3."ItemCode" = b."ItemCode"
) AS "TotalReservado",

(
SELECT COUNT(*) FROM OBIN AS t1
INNER JOIN OIBQ AS t2 ON ( t1."AbsEntry" =
t2."BinAbs" )
WHERE t2."ItemCode" = b."ItemCode"
AND t2."OnHandQty" > 0
AND t2."WhsCode" = b."WhsCode"
) AS "TotalUbicaciones",

IFNULL((
SELECT STRING_AGG(t1."AbsEntry", ',' ) FROM OBIN AS
t1
INNER JOIN OIBQ AS t2 ON ( t1."AbsEntry" =
t2."BinAbs" )
WHERE t2."ItemCode" = b."ItemCode"
AND t2."OnHandQty" > 0
AND t2."WhsCode" = b."WhsCode"
),'') AS "Ubicaciones",

IFNULL((
SELECT SUM(t1."OnHand") FROM OITW AS t1
WHERE t1."ItemCode" = b."ItemCode"
AND t1."WhsCode" = b."WhsCode"
),0) AS "StockBodega"

FROM ORDR AS a
INNER JOIN RDR1 AS b ON ( a."DocEntry" = b."DocEntry" )
INNER JOIN OITM AS c ON ( b."ItemCode" = c."ItemCode" )
INNER JOIN OWHS AS d ON ( b."WhsCode" = d."WhsCode" )
WHERE b."LineStatus" = 'O'
AND c."InvntItem" = 'Y'
AND c."EvalSystem" NOT IN ('B') -- No se considera serie y lotes
en la fase 1
AND c."ManBtchNum" = 'N' -- No considerar lotes
AND c."U_Tipo_Venta" IN ('RP')
AND b."WhsCode" NOT IN ('SAMBBF','LOJBF','COCBF','UIOBF','SAMBFA'
,'LOJBFA','COCBFA','UIOBFA') -- No
incluye bodegas NC
AND d."BinActivat" = 'Y' -- Bodegas que tienen ubicacion activa
AND b."DocEntry" = :DocEntry
ORDER BY b."LineNum"
)
) AS x WHERE x."Pendiente" > 0
AND x."TotalUbicaciones" > 0
AND x."StockBodega" > 0
AND x."StockBodega" > x."TotalReservadoBodega";

ELSE

tmp_result = SELECT * FROM (


SELECT * ,
( "OpenQty" - "TotalReservado" ) AS "Pendiente"
FROM (
SELECT
a."DocEntry",
a."ObjType",
b."LineNum",
b."ItemCode",
b."WhsCode",
b."Quantity",
b."OpenQty",

(
SELECT IFNULL(SUM( t3."RelQtty" + t3."PickQtty" ),0)
FROM OPKL AS t1
INNER JOIN PKL1 AS t2 ON ( t1."AbsEntry" =
t2."AbsEntry" )
INNER JOIN PKL2 AS t3 ON ( t1."AbsEntry" =
t3."AbsEntry" AND t2."PickEntry" = t3."PickEntry" )
INNER JOIN OBIN AS t4 ON ( t3."BinAbs" =
t4."AbsEntry" )
WHERE t1."Status" != 'C'
AND t2."PickStatus" != 'C'
AND t3."ItemCode" = b."ItemCode"
AND t4."WhsCode" = b."WhsCode"
) AS "TotalReservadoBodega",

(
SELECT IFNULL(SUM( t3."RelQtty" + t3."PickQtty" ),0)
FROM OPKL AS t1
INNER JOIN PKL1 AS t2 ON ( t1."AbsEntry" =
t2."AbsEntry" )
INNER JOIN PKL2 AS t3 ON ( t1."AbsEntry" =
t3."AbsEntry" AND t2."PickEntry" = t3."PickEntry" )
WHERE t1."Status" != 'C'
AND t2."PickStatus" != 'C'
AND t2."OrderEntry" = a."DocEntry"
AND t2."OrderLine" = b."LineNum"
AND t2."BaseObject" = a."ObjType"
AND t3."ItemCode" = b."ItemCode"
) AS "TotalReservado",

(
SELECT COUNT(*) FROM OBIN AS t1
INNER JOIN OIBQ AS t2 ON ( t1."AbsEntry" =
t2."BinAbs" )
WHERE t2."ItemCode" = b."ItemCode"
AND t2."OnHandQty" > 0
AND t2."WhsCode" = b."WhsCode"
) AS "TotalUbicaciones",

IFNULL((
SELECT STRING_AGG(t1."AbsEntry", ',' ) FROM OBIN AS
t1
INNER JOIN OIBQ AS t2 ON ( t1."AbsEntry" =
t2."BinAbs" )
WHERE t2."ItemCode" = b."ItemCode"
AND t2."OnHandQty" > 0
AND t2."WhsCode" = b."WhsCode"
),'') AS "Ubicaciones",

IFNULL((
SELECT SUM(t1."OnHand") FROM OITW AS t1
WHERE t1."ItemCode" = b."ItemCode"
AND t1."WhsCode" = b."WhsCode"
),0) AS "StockBodega"

FROM OINV AS a
INNER JOIN INV1 AS b ON ( a."DocEntry" = b."DocEntry" )
INNER JOIN OITM AS c ON ( b."ItemCode" = c."ItemCode" )
INNER JOIN OWHS AS d ON ( b."WhsCode" = d."WhsCode" )
WHERE a."isIns" = 'Y' -- Solo facturas de reserva
AND b."LineStatus" = 'O'
AND c."InvntItem" = 'Y'
AND c."EvalSystem" NOT IN ('B') -- No se considera serie y lotes
en la fase 1
AND c."ManBtchNum" = 'N' -- No considerar lotes
AND c."U_Tipo_Venta" IN ('RP')
AND b."WhsCode" NOT IN ('SAMBBF','LOJBF','COCBF','UIOBF','SAMBFA'
,'LOJBFA','COCBFA','UIOBFA') -- No
incluye bodegas NC
AND d."BinActivat" = 'Y' -- Bodegas que tienen ubicacion activa
AND b."DocEntry" = :DocEntry
ORDER BY b."LineNum"
)
) AS x WHERE x."Pendiente" > 0
AND x."TotalUbicaciones" > 0
AND x."StockBodega" > 0
AND x."StockBodega" > x."TotalReservadoBodega";

END IF;

You might also like