f52374769a182de5a1079ec91f403d1af9f3bf5a
[fa-stable.git] / sales / includes / db / sales_types_db.inc
1 <?php
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 add_sales_type($name, $tax_included, $factor)
13 {
14         $sql = "INSERT INTO ".TB_PREF."sales_types (sales_type,tax_included,factor) VALUES (".db_escape($name).",'$tax_included',$factor)";
15         db_query($sql, "could not add sales type");             
16 }
17
18 function update_sales_type($id, $name, $tax_included, $factor)
19 {
20
21         $sql = "UPDATE ".TB_PREF."sales_types SET sales_type = ".db_escape($name).",
22         tax_included =$tax_included, factor=$factor WHERE id = $id";
23         
24         db_query($sql, "could not update sales type");                  
25 }
26
27 function get_all_sales_types()
28 {
29         $sql = "SELECT * FROM ".TB_PREF."sales_types";
30         
31         return db_query($sql, "could not get all sales types");
32
33
34 function get_sales_type($id)
35 {
36         $sql = "SELECT * FROM ".TB_PREF."sales_types WHERE id=$id";
37         
38         $result = db_query($sql, "could not get sales type");
39         
40         return db_fetch($result);
41 }
42
43 function get_sales_type_name($id)
44 {
45         $sql = "SELECT sales_type FROM ".TB_PREF."sales_types WHERE id=$id";
46         
47         $result = db_query($sql, "could not get sales type");
48         
49         $row = db_fetch_row($result);
50         return $row[0];
51 }
52
53 function delete_sales_type($id)
54 {
55         $sql="DELETE FROM ".TB_PREF."sales_types WHERE id=$id";
56         db_query($sql,"The Sales type record could not be deleted");
57
58         $sql ="DELETE FROM ".TB_PREF."prices WHERE sales_type_id='$id'";
59         db_query($sql,"The Sales type prices could not be deleted");
60 }
61
62 ?>