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).",
19 WHERE abbr = '$selected'";
21 $sql = "INSERT INTO ".TB_PREF."item_units
22 (abbr, name, decimals) VALUES( ".db_escape($abbr).",
23 ".db_escape($description).", $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='$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='$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='$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='$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() {
62 $sql = "SELECT * FROM ".TB_PREF."item_units ORDER BY name";
63 return db_query($sql, "could not get stock categories");
65 // 2008-06-15. Added Joe Hunt to get a measure of unit by given stock_id
66 function get_unit_dec($stock_id)
68 $sql = "SELECT decimals FROM ".TB_PREF."item_units, ".TB_PREF."stock_master
69 WHERE abbr=units AND stock_id='$stock_id' LIMIT 1";
70 $result = db_query($sql, "could not get unit decimals");
72 $row = db_fetch_row($result);