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_location($loc_code, $location_name, $delivery_address, $phone, $fax, $email, $contact)
14 $sql = "INSERT INTO ".TB_PREF."locations (loc_code, location_name, delivery_address, phone, fax, email, contact)
15 VALUES (".db_escape($loc_code).", ".db_escape($location_name).", ".db_escape($delivery_address).", ".db_escape($phone).", ".db_escape($fax).", ".db_escape($email).", ".db_escape($contact).")";
17 db_query($sql,"a location could not be added");
19 /* Also need to add loc_stock records for all existing items */
20 $sql = "INSERT INTO ".TB_PREF."loc_stock (loc_code, stock_id, reorder_level)
21 SELECT '$loc_code', ".TB_PREF."stock_master.stock_id, 0 FROM ".TB_PREF."stock_master";
23 db_query($sql,"a location could not be added");
26 //------------------------------------------------------------------------------------
28 function update_item_location($loc_code, $location_name, $delivery_address, $phone, $fax, $email, $contact)
31 $sql = "UPDATE ".TB_PREF."locations SET location_name=".db_escape($location_name).",
32 delivery_address=".db_escape($delivery_address).",
33 phone=".db_escape($phone).", fax=".db_escape($fax).",
34 email=".db_escape($email).", contact=".db_escape($contact)."
35 WHERE loc_code = '$loc_code'";
37 db_query($sql,"a location could not be updated");
40 //------------------------------------------------------------------------------------
42 function delete_item_location($item_location)
44 $sql="DELETE FROM ".TB_PREF."locations WHERE loc_code='$item_location'";
45 db_query($sql,"a location could not be deleted");
47 $sql = "DELETE FROM ".TB_PREF."loc_stock WHERE loc_code ='$item_location'";
48 db_query($sql,"a location could not be deleted");
51 //------------------------------------------------------------------------------------
53 function get_item_location($item_location)
55 $sql="SELECT * FROM ".TB_PREF."locations WHERE loc_code='$item_location'";
57 $result = db_query($sql,"a location could not be retrieved");
59 return db_fetch($result);
62 //------------------------------------------------------------------------------------
64 function set_reorder_level($stock_id, $loc_code, $reorder_level)
66 $sql = "UPDATE ".TB_PREF."loc_stock SET reorder_level = $reorder_level
67 WHERE stock_id = '$stock_id' AND loc_code = '$loc_code'";
69 db_query($sql,"an item reorder could not be set");
72 //------------------------------------------------------------------------------------
74 function get_loc_details($stock_id)
76 $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name
77 FROM ".TB_PREF."loc_stock, ".TB_PREF."locations
78 WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code
79 AND ".TB_PREF."loc_stock.stock_id = '" . $stock_id . "' ORDER BY ".TB_PREF."loc_stock.loc_code";
80 return db_query($sql,"an item reorder could not be retreived");
83 //------------------------------------------------------------------------------------