Old ineffective sql_trail superseded by new improved db_trail logging only calls...
[fa-stable.git] / sales / includes / db / sales_points_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_point($name, $location, $account, $cash, $credit)
13 {
14         begin_transaction(__FUNCTION__, func_get_args());
15         $sql = "INSERT INTO ".TB_PREF."sales_pos (pos_name, pos_location, pos_account, cash_sale, credit_sale) VALUES (".db_escape($name)
16                         . ",".db_escape($location).",".db_escape($account)
17                         . ",$cash,$credit)";
18         db_query($sql, "could not add point of sale");
19         commit_transaction();
20 }
21
22 function update_sales_point($id, $name, $location, $account, $cash, $credit)
23 {
24         begin_transaction(__FUNCTION__, func_get_args());
25
26         $sql = "UPDATE ".TB_PREF."sales_pos SET pos_name=".db_escape($name)
27                                 .",pos_location=".db_escape($location)
28                                 .",pos_account=".db_escape($account)
29                                 .",cash_sale =$cash"
30                                 .",credit_sale =$credit"
31                                 ." WHERE id = ".db_escape($id);
32         
33         db_query($sql, "could not update sales type");
34         commit_transaction();
35 }
36
37 function get_all_sales_points($all=false)
38 {
39         $sql = "SELECT pos.*, loc.location_name, acc.bank_account_name FROM "
40                 .TB_PREF."sales_pos as pos
41                 LEFT JOIN ".TB_PREF."locations as loc on pos.pos_location=loc.loc_code
42                 LEFT JOIN ".TB_PREF."bank_accounts as acc on pos.pos_account=acc.id";
43         if (!$all) $sql .= " WHERE !pos.inactive";
44         
45         return db_query($sql, "could not get all POS definitions");
46
47
48 function get_sales_point($id)
49 {
50         $sql = "SELECT pos.*, loc.location_name, acc.bank_account_name FROM "
51                 .TB_PREF."sales_pos as pos
52                 LEFT JOIN ".TB_PREF."locations as loc on pos.pos_location=loc.loc_code
53                 LEFT JOIN ".TB_PREF."bank_accounts as acc on pos.pos_account=acc.id
54                 WHERE pos.id=".db_escape($id);
55         
56         $result = db_query($sql, "could not get POS definition");
57         
58         return db_fetch($result);
59 }
60
61 function get_sales_point_name($id)
62 {
63         $sql = "SELECT pos_name FROM ".TB_PREF."sales_pos WHERE id=".db_escape($id);
64         
65         $result = db_query($sql, "could not get POS name");
66         
67         $row = db_fetch_row($result);
68         return $row[0];
69 }
70
71 function delete_sales_point($id)
72 {
73         begin_transaction(__FUNCTION__, func_get_args());
74         $sql="DELETE FROM ".TB_PREF."sales_pos WHERE id=".db_escape($id);
75         db_query($sql,"The point of sale record could not be deleted");
76         commit_transaction();
77 }
78