Merged changes from stable branch up to 2.3.23.
[fa-stable.git] / inventory / includes / db / items_purchases_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
13 function add_item_purchasing_data($supplier_id, $stock_id, $price,
14         $suppliers_uom, $conversion_factor, $supplier_description)
15 {
16         $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom,
17                 conversion_factor, supplier_description) VALUES (";
18         $sql .= db_escape($supplier_id).", ".db_escape($stock_id). ", "
19                 .$price . ", ".db_escape($suppliers_uom ). ", "
20                 .$conversion_factor . ", "
21                 .db_escape($supplier_description) . ")";
22
23         db_query($sql,"The supplier purchasing details could not be added");
24 }
25
26 function update_item_purchasing_data($selected_id, $stock_id, $price,
27         $suppliers_uom, $conversion_factor, $supplier_description)
28 {
29         $sql = "UPDATE ".TB_PREF."purch_data SET price=" . $price . ",
30                 suppliers_uom=".db_escape($suppliers_uom) . ",
31                 conversion_factor=" . $conversion_factor . ",
32                 supplier_description=" . db_escape($supplier_description) . "
33                 WHERE stock_id=".db_escape($stock_id) . " AND
34                 supplier_id=".db_escape($selected_id);
35         db_query($sql,"The supplier purchasing details could not be updated");
36 }
37
38 function delete_item_purchasing_data($selected_id, $stock_id)
39 {
40         $sql = "DELETE FROM ".TB_PREF."purch_data WHERE supplier_id=".db_escape($selected_id)."
41                 AND stock_id=".db_escape($stock_id);
42         db_query($sql,"could not delete purchasing data");
43 }
44
45 function get_items_purchasing_data($stock_id)
46 {
47     $sql = "SELECT ".TB_PREF."purch_data.*,".TB_PREF."suppliers.supp_name,"
48         .TB_PREF."suppliers.curr_code
49                 FROM ".TB_PREF."purch_data INNER JOIN ".TB_PREF."suppliers
50                 ON ".TB_PREF."purch_data.supplier_id=".TB_PREF."suppliers.supplier_id
51                 WHERE stock_id = ".db_escape($stock_id);
52
53     return db_query($sql, "The supplier purchasing details for the selected part could not be retrieved");
54 }
55
56 function get_item_purchasing_data($selected_id, $stock_id)
57 {
58         $sql = "SELECT ".TB_PREF."purch_data.*,".TB_PREF."suppliers.supp_name FROM ".TB_PREF."purch_data
59                 INNER JOIN ".TB_PREF."suppliers ON ".TB_PREF."purch_data.supplier_id=".TB_PREF."suppliers.supplier_id
60                 WHERE ".TB_PREF."purch_data.supplier_id=".db_escape($selected_id)."
61                 AND ".TB_PREF."purch_data.stock_id=".db_escape($stock_id);
62
63         $result = db_query($sql, "The supplier purchasing details for the selected supplier and item could not be retrieved");
64
65         return db_fetch($result);
66 }
67
68