-CREATE OR REPLACE FUNCTION calculatetaxdetailline(text, integer)
+CREATE OR REPLACE FUNCTION calculatetaxdetailline(text, integer)
RETURNS SETOF taxdetail AS
$BODY$
--- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
-- See www.xtuple.com/CPAL for the full text of the software license.
DECLARE
pOrderType ALIAS FOR $1;
_totaltax numeric;
_y RECORD;
_table text;
-
+
BEGIN
_totaltax=0.0;
ELSIF pOrderType = 'AP' THEN
_table := 'apopentax';
END IF;
-
+
_qry := 'SELECT taxhist_tax_id as tax_id, tax_code, tax_descrip, taxhist_tax, COALESCE(taxhist_sequence,0) AS taxhist_sequence
- FROM taxhist
- JOIN tax ON (taxhist_tax_id=tax_id)
- JOIN pg_class ON (pg_class.oid=taxhist.tableoid)
- WHERE ( (taxhist_parent_id = ' || pOrderId || ')
- AND (relname=''' || _table || ''') );';
-
+ FROM ' || _table || '
+ JOIN tax ON (taxhist_tax_id=tax_id)
+ WHERE ( (taxhist_parent_id = ' || pOrderId || ') );';
+
FOR _y IN EXECUTE _qry
LOOP
_row.taxdetail_tax_id=_y.tax_id;