f755fed51bebde3fc9b152d4abc4862078a2809b
[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 = '$abbr',
8                 name = '$description',
9                 decimals = $decimals
10                 WHERE    abbr = '$selected'";
11     else
12                 $sql = "INSERT INTO ".TB_PREF."item_units
13                         (abbr, name, decimals) VALUES( '$abbr',
14                         '$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='$id'";
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 ?>