Permalink
Browse files

Merge pull request #114 from garyhgohoos/22536

Issue #22536:handle relocation of reservations
  • Loading branch information...
2 parents 1ce0821 + fba0717 commit febb3ae1061808250ff51273fea059f5c975c927 @gpazo gpazo committed Feb 11, 2014
Showing with 64 additions and 8 deletions.
  1. +7 −0 dbscripts/functions/deletesoitem.sql
  2. +57 −8 dbscripts/functions/relocateinventory.sql
@@ -120,6 +120,13 @@ BEGIN
WHERE (charass_target_type='SI')
AND (charass_target_id=pSoitemid);
+-- Delete reservations
+ IF (fetchMetricBool('EnableSOReservationsByLocation')) THEN
+ DELETE FROM reserve
+ WHERE (reserve_demand_type='SO')
+ AND (reserve_demand_id=pSoitemid);
+ END IF;
+
-- Delete the coitem
DELETE FROM coitem
WHERE (coitem_id=pSoitemid);
@@ -18,9 +18,13 @@ DECLARE
_GlDistTS TIMESTAMP WITH TIME ZONE := $6;
_targetItemlocid INTEGER;
_invhistid INTEGER;
- _p RECORD;
- _qty NUMERIC;
- _itemlocSeries INTEGER := NEXTVAL('itemloc_series_seq');
+ _p RECORD;
+ _rsrv RECORD;
+ _qty NUMERIC;
+ _qtyunreserved NUMERIC := 0.0;
+ _qtytomove NUMERIC := 0.0;
+ _result INTEGER := -1;
+ _itemlocSeries INTEGER := NEXTVAL('itemloc_series_seq');
BEGIN
@@ -96,11 +100,6 @@ BEGIN
AND (NOT itemsite_freeze)
AND (itemloc_id=pSourceItemlocid) );
--- Check to see if there is anything left at the source Itemloc and delete if not
- DELETE FROM itemloc
- WHERE ( (itemloc_qty=0)
- AND (itemloc_id=pSourceItemlocid) );
-
-- Check to see if any of the current Lot/Serial #/Expiration exists at the target location
SELECT itemloc_id INTO _targetItemlocid
FROM itemloc
@@ -184,6 +183,56 @@ BEGIN
WHERE ( (itemloc_qty=0)
AND (itemloc_id=_targetItemlocid) );
+-- Handle Reservations
+ IF (fetchMetricBool('EnableSOReservationsByLocation')) THEN
+ SELECT CASE WHEN (qtyReservedLocation(itemloc_id) > itemloc_qty)
+ THEN (qtyReservedLocation(itemloc_id) - itemloc_qty)
+ ELSE 0.0
+ END INTO _qtyunreserved
+ FROM itemloc
+ WHERE (itemloc_id=pSourceItemlocid);
+ -- Move reservations as necessary
+ WHILE (_qtyunreserved > 0.0) LOOP
+ SELECT * INTO _rsrv
+ FROM reserve
+ WHERE ((reserve_supply_type='I')
+ AND (reserve_supply_id=pSourceItemlocid))
+ ORDER BY reserve_qty;
+ IF (NOT FOUND) THEN
+ RAISE EXCEPTION 'Cannot find reservation to unreserve.';
+ END IF;
+ IF (_rsrv.reserve_qty > _qtyunreserved) THEN
+ _qtytomove := _qtyunreserved;
+ ELSE
+ _qtytomove := _rsrv.reserve_qty;
+ END IF;
+ -- Unreserve Source Location
+ SELECT unreserveSOLineQty(_rsrv.reserve_demand_id,
+ _qtytomove,
+ pSourceItemlocid) INTO _result;
+ IF (_result < 0) THEN
+ RAISE EXCEPTION 'unreserveSOLineQty failed with result=%, reserve_id=%, qty=%',
+ _result, _rsrv.reserve_id, _qtytomove;
+ END IF;
+ -- Reserve to new Location
+ SELECT reserveSOLineQty(_rsrv.reserve_demand_id,
+ TRUE,
+ _qtytomove,
+ _targetItemlocid) INTO _result;
+ IF (_result < 0) THEN
+ RAISE EXCEPTION 'reserveSOLineQty failed with result=%, reserve_id=%, qty=%',
+ _result, _rsrv.reserve_id, _qtytomove;
+ END IF;
+ -- Calculate running total
+ _qtyunreserved := _qtyunreserved - _qtytomove;
+ END LOOP;
+ END IF;
+
+-- Check to see if there is anything left at the source Itemloc and delete if not
+ DELETE FROM itemloc
+ WHERE ( (itemloc_qty=0)
+ AND (itemloc_id=pSourceItemlocid) );
+
-- Return the invhist_id
RETURN _invhistid;

0 comments on commit febb3ae

Please sign in to comment.