Issue #23903:add missing currrate and amount arguments
[xtuple] / foundation-database / public / functions / togglebankreccleared.sql
1
2 CREATE OR REPLACE FUNCTION toggleBankrecCleared(INTEGER, TEXT, INTEGER, NUMERIC, NUMERIC) RETURNS BOOLEAN AS $$
3 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
4 -- See www.xtuple.com/CPAL for the full text of the software license.
5 DECLARE
6   pBankrecid ALIAS FOR $1;
7   pSource    ALIAS FOR $2;
8   pSourceid  ALIAS FOR $3;
9   pCurrrate  ALIAS FOR $4;
10   pAmount    ALIAS FOR $5;
11
12 BEGIN
13   RETURN toggleBankrecCleared(pBankrecid, pSource, pSourceid, pCurrrate, pAmount, NULL);
14 END;
15 $$ LANGUAGE 'plpgsql';
16
17 CREATE OR REPLACE FUNCTION toggleBankrecCleared(INTEGER, TEXT, INTEGER, NUMERIC, NUMERIC, DATE) RETURNS BOOLEAN AS $$
18 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
19 -- See www.xtuple.com/CPAL for the full text of the software license.
20 DECLARE
21   pBankrecid ALIAS FOR $1;
22   pSource    ALIAS FOR $2;
23   pSourceid  ALIAS FOR $3;
24   pCurrrate  ALIAS FOR $4;
25   pAmount    ALIAS FOR $5;
26   pDate      ALIAS FOR $6;
27   _cleared BOOLEAN;
28   _r RECORD;
29
30 BEGIN
31   SELECT bankrecitem_id, bankrecitem_cleared INTO _r
32     FROM bankrecitem
33    WHERE ( (bankrecitem_bankrec_id=pBankrecid)
34      AND   (bankrecitem_source=pSource)
35      AND   (bankrecitem_source_id=pSourceid) );
36   IF ( NOT FOUND ) THEN
37     _cleared := TRUE;
38     INSERT INTO bankrecitem
39     (bankrecitem_bankrec_id, bankrecitem_source,
40      bankrecitem_source_id, bankrecitem_cleared,
41      bankrecitem_curr_rate, bankrecitem_amount,
42      bankrecitem_effdate)
43     VALUES
44     (pBankrecid, pSource,
45      pSourceid, _cleared,
46      pCurrrate, pAmount,
47      pDate);
48   ELSE
49     _cleared := FALSE;
50     DELETE FROM bankrecitem 
51     WHERE bankrecitem_id = _r.bankrecitem_id;
52   END IF;
53
54   RETURN _cleared;
55 END;
56 $$ LANGUAGE 'plpgsql';
57