PROCEDURE SP - DOCUMENTOS - PICKING - DETALLE - Pat2

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

-- Iterar sobre cada ubicacion para saber cuanto comprometido tienen

SELECT COUNT(*) INTO v_count FROM :tmp_result;

FOR v_i IN 1..:v_count DO

aux_DocEntry := :tmp_result."DocEntry"[v_i];
aux_ObjType := :tmp_result."ObjType"[v_i];
aux_Pendiente := :tmp_result."Pendiente"[v_i];
aux_ItemCode := :tmp_result."ItemCode"[v_i];
aux_WhsCode := :tmp_result."WhsCode"[v_i];
aux_LineNum := :tmp_result."LineNum"[v_i];

aux_ArrUbicaciones := :tmp_result."Ubicaciones"[v_i];

tmp_ubicaciones = SELECT "OUTPUT_SPLIT" AS "Ubicacion" FROM


"TF_SPLIT_STRING"(:aux_ArrUbicaciones) ORDER BY "OUTPUT_SPLIT";

SELECT COUNT(*) INTO v_2_count FROM :tmp_ubicaciones;

FOR v_2_i IN 1..:v_2_count DO

aux_Ubicacion := :tmp_ubicaciones."Ubicacion"[v_2_i];

--aux_ReservadoDoc := 0;

-- Obtener la cantidad reservada del item en la ubicacion


/*
SELECT IFNULL(SUM( t3."RelQtty" + t3."PickQtty" ),0)
INTO aux_ReservadoDoc
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 t2."OrderEntry" = :aux_DocEntry
AND t2."OrderLine" = :aux_LineNum
AND t2."BaseObject" = :aux_ObjType
AND t3."ItemCode" = :aux_ItemCode
AND t4."WhsCode" = :aux_WhsCode
AND t4."AbsEntry" = :aux_Ubicacion;
*/

--aux_Pendiente := ( :aux_Pendiente - :aux_ReservadoDoc );

IF :aux_Pendiente > 0 THEN

aux_NuevaReserva := 0;
aux_Reservado := 0;
aux_TotalUbi := 0;

-- Obtener cuantos han sido reservador previamente por items


repetidos

SELECT IFNULL(SUM(Reservar),0)
INTO aux_NuevaReserva
FROM #DETALLE
WHERE LineNum != :aux_LineNum
AND ItemCode = :aux_ItemCode
AND WhsCode = :aux_WhsCode
AND Ubicacion =:aux_Ubicacion;

-- Obtener cuantos estan reservados en la ubicacion

SELECT IFNULL(SUM( t3."RelQtty" + t3."PickQtty" ),0)


INTO aux_Reservado
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" = :aux_ItemCode
AND t4."WhsCode" = :aux_WhsCode
AND t4."AbsEntry" = :aux_Ubicacion;

-- Obtener la cantidad en la ubicación

SELECT t2."OnHandQty"
INTO aux_TotalUbi
FROM OBIN AS t1
INNER JOIN OIBQ AS t2 ON ( t1."AbsEntry" = t2."BinAbs" )
WHERE t2."ItemCode" = :aux_ItemCode
AND t2."WhsCode" = :aux_WhsCode
AND t1."AbsEntry" = :aux_Ubicacion;

-- Restar a lo Pendiente

aux_Disponible := ( :aux_TotalUbi - ( :aux_Reservado


+ :aux_NuevaReserva ) );

IF :aux_Disponible > 0 THEN

aux_Reservar := 0;

IF :aux_Pendiente <= :aux_Disponible THEN

aux_Reservar := :aux_Pendiente;

ELSE

aux_Reservar := :aux_Disponible;

END IF;

IF :aux_Reservar > 0 THEN

aux_Pendiente := ( :aux_Pendiente - :aux_Reservar );

-- Insertar lo que se va a pickear

-- OJO agregar otro item que tenga 2 ubicaciones

INSERT INTO #DETALLE


SELECT :aux_LineNum, :aux_ItemCode, :aux_WhsCode, :aux_Reservar, :aux_Pendiente, :a
ux_Disponible,
:aux_Reservado,
--:aux_ReservadoDoc,
:aux_TotalUbi, :aux_Ubicacion
FROM DUMMY;

END IF;

END IF;

END IF;

END FOR;

END FOR;

-- FIX PARA LAS QUE TIENEN COMPROMETIDOS EN DOCUMENTOS QUE NO SON PICKING

IF :DocEntry = 40589 AND :ObjType = 17 THEN

UPDATE #DETALLE SET


Reservar = 2,
Disponible = 2
WHERE LineNum = 4
AND ItemCode = '01643-31032';

END IF;

-- Generar el resultado final, segmentado por ubicaciones


-- JAMAS QUITAR EL ORDER BY LineNum

SELECT *
FROM #DETALLE AS a ORDER BY LineNum;

DROP TABLE #DETALLE;

END;

You might also like