Merged changes form main trunk since 2.1RC
[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         $sql = "INSERT INTO ".TB_PREF."sales_pos (pos_name, pos_location, pos_account, cash_sale, credit_sale) VALUES (".db_escape($name)
15                         . ",".db_escape($location).",".db_escape($account)
16                         . ",$cash,$credit)";
17         db_query($sql, "could not add point of sale");
18 }
19
20 function update_sales_point($id, $name, $location, $account, $cash, $credit)
21 {
22
23         $sql = "UPDATE ".TB_PREF."sales_pos SET pos_name=".db_escape($name)
24                                 .",pos_location=".db_escape($location)
25                                 .",pos_account=".db_escape($account)
26                                 .",cash_sale =$cash"
27                                 .",credit_sale =$credit"
28                                 ." WHERE id = $id";
29         
30         db_query($sql, "could not update sales type");                  
31 }
32
33 function get_all_sales_points()
34 {
35         $sql = "SELECT pos.*, loc.location_name, acc.bank_account_name FROM "
36                 .TB_PREF."sales_pos as pos
37                 LEFT JOIN ".TB_PREF."locations as loc on pos.pos_location=loc.loc_code
38                 LEFT JOIN ".TB_PREF."bank_accounts as acc on pos.pos_account=acc.id";
39         
40         return db_query($sql, "could not get all POS definitions");
41
42
43 function get_sales_point($id)
44 {
45         $sql = "SELECT pos.*, loc.location_name, acc.bank_account_name FROM "
46                 .TB_PREF."sales_pos as pos
47                 LEFT JOIN ".TB_PREF."locations as loc on pos.pos_location=loc.loc_code
48                 LEFT JOIN ".TB_PREF."bank_accounts as acc on pos.pos_account=acc.id
49                 WHERE pos.id='$id'";
50         
51         $result = db_query($sql, "could not get POS definition");
52         
53         return db_fetch($result);
54 }
55
56 function get_sales_point_name($id)
57 {
58         $sql = "SELECT pos_name FROM ".TB_PREF."sales_pos WHERE id=$id";
59         
60         $result = db_query($sql, "could not get POS name");
61         
62         $row = db_fetch_row($result);
63         return $row[0];
64 }
65
66 function delete_sales_point($id)
67 {
68         $sql="DELETE FROM ".TB_PREF."sales_pos WHERE id=$id";
69         db_query($sql,"The point of sale record could not be deleted");
70 }
71
72 ?>