2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
11 ***********************************************************************/
12 //--------------------------------------------------------------------------------------------------
14 function get_reference($type, $id)
16 $sql = "SELECT * FROM ".TB_PREF."refs WHERE type=$type AND id=$id";
18 return db_query($sql, "could not query reference table");
21 //--------------------------------------------------------------------------------------------------
23 function add_reference($type, $id, $reference)
25 $sql = "INSERT INTO ".TB_PREF."refs (type, id, reference)
26 VALUES ($type, $id, " . db_escape(trim($reference)) . ")";
28 db_query($sql, "could not add reference entry");
31 //--------------------------------------------------------------------------------------------------
33 function delete_reference($type, $id)
35 $sql = "DELETE FROM ".TB_PREF."refs WHERE type=$type AND id=$id";
37 return db_query($sql, "could not delete from reference table");
40 //--------------------------------------------------------------------------------------------------
42 function find_reference($type, $reference)
44 $sql = "SELECT id FROM ".TB_PREF."refs WHERE type=$type AND reference='$reference'";
46 $result = db_query($sql, "could not query reference table");
48 return (db_num_rows($result) > 0);
51 //--------------------------------------------------------------------------------------------------
53 function save_next_reference($type, $reference)
55 $sql = "UPDATE ".TB_PREF."sys_types SET next_reference=" . db_escape(trim($reference)) . " WHERE type_id = $type";
57 db_query($sql, "The next transaction ref for $type could not be updated");
60 //--------------------------------------------------------------------------------------------------
62 function get_next_reference($type)
64 $sql = "SELECT next_reference FROM ".TB_PREF."sys_types WHERE type_id = $type";
66 $result = db_query($sql,"The last transaction ref for $type could not be retreived");
68 $row = db_fetch_row($result);