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)
14 begin_transaction(__FUNCTION__, func_get_args());
17 $sql = "UPDATE ".TB_PREF."item_units SET
18 abbr = ".db_escape($abbr).",
19 name = ".db_escape($description).",
20 decimals = ".db_escape($decimals)."
21 WHERE abbr = ".db_escape($selected);
23 $sql = "INSERT INTO ".TB_PREF."item_units
24 (abbr, name, decimals) VALUES( ".db_escape($abbr).",
25 ".db_escape($description).", ".db_escape($decimals).")";
27 db_query($sql,"an item unit could not be updated");
31 function delete_item_unit($unit)
33 begin_transaction(__FUNCTION__, func_get_args());
34 $sql="DELETE FROM ".TB_PREF."item_units WHERE abbr=".db_escape($unit);
36 db_query($sql,"an unit of measure could not be deleted");
40 function get_item_unit($unit)
42 $sql="SELECT * FROM ".TB_PREF."item_units WHERE abbr=".db_escape($unit);
44 $result = db_query($sql,"an unit of measure could not be retrieved");
46 return db_fetch($result);
49 function get_unit_descr($unit)
51 $sql = "SELECT name FROM ".TB_PREF."item_units WHERE abbr=".db_escape($unit);
53 $result = db_query($sql, "could not retrieve unit description");
55 $row = db_fetch_row($result);
59 function item_unit_used($unit) {
60 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE units=".db_escape($unit);
61 $result = db_query($sql, "could not query stock master");
62 $myrow = db_fetch_row($result);
63 return ($myrow[0] > 0);
66 function get_all_item_units($all=false) {
67 $sql = "SELECT * FROM ".TB_PREF."item_units";
68 if (!$all) $sql .= " WHERE !inactive";
69 $sql .= " ORDER BY name";
70 return db_query($sql, "could not get stock categories");
72 // 2008-06-15. Added to get a measure of unit by given stock_id
73 function get_unit_dec($stock_id)
75 $sql = "SELECT decimals FROM ".TB_PREF."item_units, ".TB_PREF."stock_master
76 WHERE abbr=units AND stock_id=".db_escape($stock_id)." LIMIT 1";
77 $result = db_query($sql, "could not get unit decimals");
79 $row = db_fetch_row($result);