2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 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/gpl-3.0.html>.
11 ***********************************************************************/
12 function write_item_unit($selected, $abbr, $description, $decimals)
15 $sql = "UPDATE ".TB_PREF."item_units SET
16 abbr = ".db_escape($abbr).",
17 name = ".db_escape($description).",
18 decimals = ".db_escape($decimals)."
19 WHERE abbr = ".db_escape($selected);
21 $sql = "INSERT INTO ".TB_PREF."item_units
22 (abbr, name, decimals) VALUES( ".db_escape($abbr).",
23 ".db_escape($description).", ".db_escape($decimals).")";
25 db_query($sql,"an item unit could not be updated");
28 function delete_item_unit($unit)
30 $sql="DELETE FROM ".TB_PREF."item_units WHERE abbr=".db_escape($unit);
32 db_query($sql,"an unit of measure could not be deleted");
35 function get_item_unit($unit)
37 $sql="SELECT * FROM ".TB_PREF."item_units WHERE abbr=".db_escape($unit);
39 $result = db_query($sql,"an unit of measure could not be retrieved");
41 return db_fetch($result);
44 function get_unit_descr($unit)
46 $sql = "SELECT description FROM ".TB_PREF."item_units WHERE abbr=".db_escape($unit);
48 $result = db_query($sql, "could not unit description");
50 $row = db_fetch_row($result);
54 function item_unit_used($unit) {
55 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE units=".db_escape($unit);
56 $result = db_query($sql, "could not query stock master");
57 $myrow = db_fetch_row($result);
58 return ($myrow[0] > 0);
61 function get_all_item_units($all=false) {
62 $sql = "SELECT * FROM ".TB_PREF."item_units";
63 if (!$all) $sql .= " WHERE !inactive";
64 $sql .= " ORDER BY name";
65 return db_query($sql, "could not get stock categories");
67 // 2008-06-15. Added Joe Hunt to get a measure of unit by given stock_id
68 function get_unit_dec($stock_id)
70 $sql = "SELECT decimals FROM ".TB_PREF."item_units, ".TB_PREF."stock_master
71 WHERE abbr=units AND stock_id=".db_escape($stock_id)." LIMIT 1";
72 $result = db_query($sql, "could not get unit decimals");
74 $row = db_fetch_row($result);