5fee90e7c7f47d872e8d86aafdc7452543f0fcc0
[fa-stable.git] / inventory / includes / db / items_prices_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_item_price($stock_id, $sales_type_id, $curr_abrev, $price)
13 {
14         begin_transaction(__FUNCTION__, func_get_args());
15         $sql = "INSERT INTO ".TB_PREF."prices (stock_id, sales_type_id, curr_abrev, price) 
16                 VALUES (".db_escape($stock_id).", ".db_escape($sales_type_id)
17                 .", ".db_escape($curr_abrev).", ".db_escape($price).")";
18
19         db_query($sql,"an item price could not be added");
20         commit_transaction();
21 }
22
23 function update_item_price($price_id, $sales_type_id, $curr_abrev, $price)
24 {
25         begin_transaction(__FUNCTION__, func_get_args());
26         $sql = "UPDATE ".TB_PREF."prices SET sales_type_id=".db_escape($sales_type_id).", 
27                 curr_abrev=".db_escape($curr_abrev).", 
28                 price=".db_escape($price)." WHERE id=".db_escape($price_id);
29
30         db_query($sql,"an item price could not be updated");
31         commit_transaction();
32 }
33
34 function delete_item_price($price_id)
35 {
36         begin_transaction(__FUNCTION__, func_get_args());
37         $sql="DELETE FROM ".TB_PREF."prices WHERE id= ".db_escape($price_id);
38         db_query($sql,"an item price could not be deleted");
39         commit_transaction();
40 }
41
42 function get_prices($stock_id)
43 {
44         $sql = "SELECT pricelist.sales_type, price.* 
45                 FROM ".TB_PREF."prices price, "
46                         .TB_PREF."sales_types pricelist
47                 WHERE price.sales_type_id = pricelist.id
48                 AND stock_id=".db_escape($stock_id)
49                 ." ORDER BY curr_abrev, sales_type_id";
50
51         return db_query($sql,"item prices could not be retreived");
52 }
53
54 function get_stock_price($price_id)
55 {
56         $sql = "SELECT * FROM ".TB_PREF."prices WHERE id=".db_escape($price_id);
57
58         $result = db_query($sql,"price could not be retreived");
59
60         return db_fetch($result);
61 }
62
63 function get_stock_price_type_currency($stock_id, $type, $currency)
64 {
65         $sql = "SELECT * FROM ".TB_PREF."prices WHERE stock_id=".db_escape($stock_id)."
66                 AND sales_type_id=".db_escape($type)."
67                 AND curr_abrev=".db_escape($currency);
68
69         $result = db_query($sql,"price could not be retreived");
70
71         return db_fetch($result);
72 }