Old ineffective sql_trail superseded by new improved db_trail logging only calls...
[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         begin_transaction(__FUNCTION__, func_get_args());
15
16         $sql = "INSERT INTO ".TB_PREF."sales_types (sales_type,tax_included,factor) VALUES (".db_escape($name).","
17                 .db_escape($tax_included).",".db_escape($factor).")";
18         db_query($sql, "could not add sales type");
19         $result = db_insert_id();
20
21         commit_transaction();
22         return $result;
23 }
24
25 function update_sales_type($id, $name, $tax_included, $factor)
26 {
27         begin_transaction(__FUNCTION__, func_get_args());
28         $sql = "UPDATE ".TB_PREF."sales_types SET sales_type = ".db_escape($name).",
29         tax_included =".db_escape($tax_included).", factor=".db_escape($factor)." WHERE id = ".db_escape($id);
30         
31         db_query($sql, "could not update sales type");                  
32         commit_transaction();
33 }
34
35 function get_all_sales_types($all=false)
36 {
37         $sql = "SELECT * FROM ".TB_PREF."sales_types";
38         if (!$all)
39                 $sql .= " WHERE !inactive";
40         
41         return db_query($sql, "could not get all sales types");
42
43
44 function get_sales_type($id)
45 {
46         $sql = "SELECT * FROM ".TB_PREF."sales_types WHERE id=".db_escape($id);
47         
48         $result = db_query($sql, "could not get sales type");
49         
50         return db_fetch($result);
51 }
52
53 function get_sales_type_name($id)
54 {
55         $sql = "SELECT sales_type FROM ".TB_PREF."sales_types WHERE id=".db_escape($id);
56         
57         $result = db_query($sql, "could not get sales type");
58         
59         $row = db_fetch_row($result);
60         return $row[0];
61 }
62
63 function delete_sales_type($id)
64 {
65         begin_transaction(__FUNCTION__, func_get_args());
66         $sql="DELETE FROM ".TB_PREF."sales_types WHERE id=".db_escape($id);
67         db_query($sql,"The Sales type record could not be deleted");
68
69         $sql ="DELETE FROM ".TB_PREF."prices WHERE sales_type_id=".db_escape($id);
70         db_query($sql,"The Sales type prices could not be deleted");
71         commit_transaction();
72 }
73