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