Trigger checking MaintainUsers priv before updating table to avoid bug 24255
[xtuple] / foundation-database / public / functions / detailednnqoh.sql
1 CREATE OR REPLACE FUNCTION detailedNNQOH(INTEGER, BOOLEAN) RETURNS NUMERIC AS '
2 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
3 -- See www.xtuple.com/CPAL for the full text of the software license.
4 DECLARE
5   pItemsiteid ALIAS FOR $1;
6   pABS ALIAS FOR $2;
7   _qoh NUMERIC;
8
9 BEGIN
10
11   IF (pABS) THEN
12     SELECT SUM(noNeg(itemloc_qty)) INTO _qoh
13     FROM itemloc, location
14     WHERE ( (itemloc_location_id=location_id)
15      AND (NOT location_netable)
16      AND (itemloc_itemsite_id=pItemsiteid) );
17   ELSE
18     SELECT SUM(itemloc_qty) INTO _qoh
19     FROM itemloc, location
20     WHERE ( (itemloc_location_id=location_id)
21      AND (NOT location_netable)
22      AND (itemloc_itemsite_id=pItemsiteid) );
23   END IF;
24
25   IF (_qoh IS NULL) THEN
26     _qoh := 0;
27   END IF;
28
29   RETURN _qoh;
30
31 END;
32 ' LANGUAGE 'plpgsql';