PHP 8 rerun of number_format fix.
[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         $sql = "INSERT INTO ".TB_PREF."prices (stock_id, sales_type_id, curr_abrev, price) 
15                 VALUES (".db_escape($stock_id).", ".db_escape($sales_type_id)
16                 .", ".db_escape($curr_abrev).", ".db_escape($price).")";
17
18         db_query($sql,"an item price could not be added");
19 }
20
21 function update_item_price($price_id, $sales_type_id, $curr_abrev, $price)
22 {
23         $sql = "UPDATE ".TB_PREF."prices SET sales_type_id=".db_escape($sales_type_id).", 
24                 curr_abrev=".db_escape($curr_abrev).", 
25                 price=".db_escape($price)." WHERE id=".db_escape($price_id);
26
27         db_query($sql,"an item price could not be updated");
28 }
29
30 function delete_item_price($price_id)
31 {
32         $sql="DELETE FROM ".TB_PREF."prices WHERE id= ".db_escape($price_id);
33         db_query($sql,"an item price could not be deleted");
34 }
35
36 function get_prices($stock_id)
37 {
38         $sql = "SELECT pricelist.sales_type, price.* 
39                 FROM ".TB_PREF."prices price, "
40                         .TB_PREF."sales_types pricelist
41                 WHERE price.sales_type_id = pricelist.id
42                 AND stock_id=".db_escape($stock_id)
43                 ." ORDER BY curr_abrev, sales_type_id";
44
45         return db_query($sql,"item prices could not be retreived");
46 }
47
48 function get_stock_price($price_id)
49 {
50         $sql = "SELECT * FROM ".TB_PREF."prices WHERE id=".db_escape($price_id);
51
52         $result = db_query($sql,"price could not be retreived");
53
54         return db_fetch($result);
55 }
56
57 function get_stock_price_type_currency($stock_id, $type, $currency)
58 {
59         $sql = "SELECT * FROM ".TB_PREF."prices WHERE stock_id=".db_escape($stock_id)."
60                 AND sales_type_id=".db_escape($type)."
61                 AND curr_abrev=".db_escape($currency);
62
63         $result = db_query($sql,"price could not be retreived");
64
65         return db_fetch($result);
66 }