3 function write_item_unit($selected, $abbr, $description, $decimals)
6 $sql = "UPDATE ".TB_PREF."item_units SET
7 abbr = ".db_escape($abbr).",
8 name = ".db_escape($description).",
10 WHERE abbr = '$selected'";
12 $sql = "INSERT INTO ".TB_PREF."item_units
13 (abbr, name, decimals) VALUES( ".db_escape($abbr).",
14 ".db_escape($description).", $decimals)";
16 db_query($sql,"an item unit could not be updated");
19 function delete_item_unit($unit)
21 $sql="DELETE FROM ".TB_PREF."item_units WHERE abbr='$unit'";
23 db_query($sql,"an unit of measure could not be deleted");
26 function get_item_unit($unit)
28 $sql="SELECT * FROM ".TB_PREF."item_units WHERE abbr='$unit'";
30 $result = db_query($sql,"an unit of measure could not be retrieved");
32 return db_fetch($result);
35 function get_unit_descr($unit)
37 $sql = "SELECT description FROM ".TB_PREF."item_units WHERE abbr='$unit'";
39 $result = db_query($sql, "could not unit description");
41 $row = db_fetch_row($result);
45 function item_unit_used($unit) {
46 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE units='$unit'";
47 $result = db_query($sql, "could not query stock master");
48 $myrow = db_fetch_row($result);
49 return ($myrow[0] > 0);
52 function get_all_item_units() {
53 $sql = "SELECT * FROM ".TB_PREF."item_units ORDER BY name";
54 return db_query($sql, "could not get stock categories");
56 // 2008-06-15. Added Joe Hunt to get a measure of unit by given stock_id
57 function get_unit_dec($stock_id)
59 $sql = "SELECT decimals FROM ".TB_PREF."item_units, ".TB_PREF."stock_master
60 WHERE abbr=units AND stock_id='$stock_id' LIMIT 1";
61 $result = db_query($sql, "could not get unit decimals");
63 $row = db_fetch_row($result);