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)
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).")";
19 db_query($sql,"an item price could not be added");
23 function update_item_price($price_id, $sales_type_id, $curr_abrev, $price)
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);
30 db_query($sql,"an item price could not be updated");
34 function delete_item_price($price_id)
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");
42 function get_prices($stock_id)
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";
51 return db_query($sql,"item prices could not be retreived");
54 function get_stock_price($price_id)
56 $sql = "SELECT * FROM ".TB_PREF."prices WHERE id=".db_escape($price_id);
58 $result = db_query($sql,"price could not be retreived");
60 return db_fetch($result);
63 function get_stock_price_type_currency($stock_id, $type, $currency)
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);
69 $result = db_query($sql,"price could not be retreived");
71 return db_fetch($result);