1 CREATE OR REPLACE FUNCTION calcQuoteAmt(pQuheadid INTEGER) RETURNS NUMERIC STABLE 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.
6 RETURN calcQuoteAmt(pQuheadid, 'T');
11 CREATE OR REPLACE FUNCTION calcQuoteAmt(pQuheadid INTEGER,
12 pType TEXT) RETURNS NUMERIC STABLE AS $$
13 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
14 -- See www.xtuple.com/CPAL for the full text of the software license.
16 _subtotal NUMERIC := 0.0;
19 _freight NUMERIC := 0.0;
21 _amount NUMERIC := 0.0;
25 -- pType: S = line item subtotal
30 SELECT COALESCE(SUM(ROUND((quitem_qtyord * quitem_qty_invuomratio) *
31 (quitem_price / quitem_price_invuomratio), 2)), 0.0),
32 COALESCE(SUM(ROUND((quitem_qtyord * quitem_qty_invuomratio) *
33 (quitem_unitcost / quitem_price_invuomratio), 2)), 0.0)
36 WHERE (quitem_quhead_id=pQuheadid);
38 IF (pType IN ('T', 'X')) THEN
39 SELECT COALESCE(ROUND(SUM(taxdetail_tax), 2), 0.0) INTO _tax
40 FROM calculateTaxDetailSummary('Q', pQuheadid, 'T');
44 SELECT COALESCE(quhead_freight, 0), COALESCE(quhead_misc, 0) INTO _freight, _misc
46 WHERE (quhead_id=pQuheadid);
49 _amount := CASE pType WHEN 'S' THEN (_subtotal)
50 WHEN 'T' THEN (_subtotal + _tax + _freight + _misc)
52 WHEN 'M' THEN (_subtotal - _cost)
59 $$ LANGUAGE 'plpgsql';