2 CREATE OR REPLACE FUNCTION calculatetaxdetailline(text, integer)
3 RETURNS SETOF taxdetail AS
5 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
6 -- See www.xtuple.com/CPAL for the full text of the software license.
8 pOrderType ALIAS FOR $1;
10 _row taxdetail%ROWTYPE;
19 IF pOrderType = 'II' THEN
20 _table := 'invcitemtax';
21 ELSIF pOrderType = 'BI' THEN
22 _table := 'cobilltax';
23 ELSIF pOrderType = 'CI' THEN
24 _table := 'cmitemtax';
25 ELSIF pOrderType = 'VI' THEN
26 _table := 'voitemtax';
27 ELSIF pOrderType = 'TI' THEN
28 _table := 'toitemtax';
29 ELSIF pOrderType = 'AR' THEN
30 _table := 'aropentax';
31 ELSIF pOrderType = 'AP' THEN
32 _table := 'apopentax';
35 _qry := 'SELECT taxhist_tax_id as tax_id, tax_code, tax_descrip, taxhist_tax, COALESCE(taxhist_sequence,0) AS taxhist_sequence
37 JOIN tax ON (taxhist_tax_id=tax_id)
38 JOIN pg_class ON (pg_class.oid=taxhist.tableoid)
39 WHERE ( (taxhist_parent_id = ' || pOrderId || ')
40 AND (relname=''' || _table || ''') );';
42 FOR _y IN EXECUTE _qry
44 _row.taxdetail_tax_id=_y.tax_id;
45 _row.taxdetail_tax_code = _y.tax_code;
46 _row.taxdetail_tax_descrip = _y.tax_descrip;
47 _row.taxdetail_tax = _y.taxhist_tax;
48 _row.taxdetail_level= 0 ;
49 _row.taxdetail_taxclass_sequence= _y.taxhist_sequence;
50 _totaltax = _totaltax + _y.taxhist_tax;
55 LANGUAGE 'plpgsql' VOLATILE;