Moving 2.0 development version to main trunk.
[fa-stable.git] / inventory / includes / db / items_units_db.inc
1 <?php
2
3 function write_item_unit($selected, $abbr, $description, $decimals)
4 {
5     if($selected!='')
6                 $sql = "UPDATE ".TB_PREF."item_units SET
7                 abbr = ".db_escape($abbr).",
8                 name = ".db_escape($description).",
9                 decimals = $decimals
10                 WHERE    abbr = '$selected'";
11     else
12                 $sql = "INSERT INTO ".TB_PREF."item_units
13                         (abbr, name, decimals) VALUES( ".db_escape($abbr).",
14                         ".db_escape($description).", $decimals)";
15
16         db_query($sql,"an item unit could not be updated");
17 }
18
19 function delete_item_unit($unit)
20 {
21         $sql="DELETE FROM ".TB_PREF."item_units WHERE abbr='$unit'";
22
23         db_query($sql,"an unit of measure could not be deleted");
24 }
25
26 function get_item_unit($unit)
27 {
28         $sql="SELECT * FROM ".TB_PREF."item_units WHERE abbr='$unit'";
29
30         $result = db_query($sql,"an unit of measure could not be retrieved");
31
32         return db_fetch($result);
33 }
34
35 function get_unit_descr($unit)
36 {
37         $sql = "SELECT description FROM ".TB_PREF."item_units WHERE abbr='$unit'";
38
39         $result = db_query($sql, "could not unit description");
40
41         $row = db_fetch_row($result);
42         return $row[0];
43 }
44
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);
50 }
51
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");
55 }
56 // 2008-06-15. Added Joe Hunt to get a measure of unit by given stock_id
57 function get_unit_dec($stock_id)
58 {
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");
62
63         $row = db_fetch_row($result);
64         return $row[0];
65 }
66
67 ?>