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 ***********************************************************************/
13 function add_item_purchasing_data($supplier_id, $stock_id, $price,
14 $suppliers_uom, $conversion_factor, $supplier_description)
16 $supp_desc = db_escape($supplier_description);
17 if (strlen($supp_desc) > 50) // to be fixed and removed in 2.5
18 $supp_desc = substr($supp_desc, 0, 50)."'";
19 $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom,
20 conversion_factor, supplier_description) VALUES (";
21 $sql .= db_escape($supplier_id).", ".db_escape($stock_id). ", "
22 .$price . ", ".db_escape($suppliers_uom ). ", "
23 .$conversion_factor . ", "
26 db_query($sql,"The supplier purchasing details could not be added");
29 function update_item_purchasing_data($selected_id, $stock_id, $price,
30 $suppliers_uom, $conversion_factor, $supplier_description)
32 $supp_desc = db_escape($supplier_description);
33 if (strlen($supp_desc) > 50) // to be fixed and removed in 2.5
34 $supp_desc = substr($supp_desc, 0, 50) ."'";
35 $sql = "UPDATE ".TB_PREF."purch_data SET price=" . $price . ",
36 suppliers_uom=".db_escape($suppliers_uom) . ",
37 conversion_factor=" . $conversion_factor . ",
38 supplier_description=" . $supp_desc . "
39 WHERE stock_id=".db_escape($stock_id) . " AND
40 supplier_id=".db_escape($selected_id);
41 db_query($sql,"The supplier purchasing details could not be updated");
44 function delete_item_purchasing_data($selected_id, $stock_id)
46 $sql = "DELETE FROM ".TB_PREF."purch_data WHERE supplier_id=".db_escape($selected_id)."
47 AND stock_id=".db_escape($stock_id);
48 db_query($sql,"could not delete purchasing data");
51 function get_items_purchasing_data($stock_id)
53 $sql = "SELECT pdata.*, supplier.supp_name, supplier.curr_code
54 FROM ".TB_PREF."purch_data pdata
55 INNER JOIN ".TB_PREF."suppliers supplier ON pdata.supplier_id=supplier.supplier_id
56 WHERE stock_id = ".db_escape($stock_id);
58 return db_query($sql, "The supplier purchasing details for the selected part could not be retrieved");
61 function get_item_purchasing_data($selected_id, $stock_id)
63 $sql = "SELECT pdata.*, supplier.supp_name
64 FROM ".TB_PREF."purch_data pdata
65 INNER JOIN ".TB_PREF."suppliers supplier ON pdata.supplier_id=supplier.supplier_id
66 WHERE pdata.supplier_id=".db_escape($selected_id)."
67 AND pdata.stock_id=".db_escape($stock_id);
69 $result = db_query($sql, "The supplier purchasing details for the selected supplier and item could not be retrieved");
71 return db_fetch($result);