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 $path_to_root="../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_("Inventory Locations"));
18 include_once($path_to_root . "/includes/ui.inc");
20 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
22 simple_page_mode(true);
24 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
27 //initialise no input errors assumed initially before we test
30 /* actions to take once the user has clicked the submit button
31 ie the page has called itself with some user input */
33 //first off validate inputs sensible
34 $_POST['loc_code'] = strtoupper($_POST['loc_code']);
36 if (strlen($_POST['loc_code']) > 5)
39 display_error( _("The location code must be five characters or less long."));
40 set_focus('loc_code');
42 elseif (strlen($_POST['location_name']) == 0)
45 display_error( _("The location name must be entered."));
46 set_focus('location_name');
49 if ($input_error != 1)
51 if ($selected_id != -1)
54 update_item_location($selected_id, $_POST['location_name'], $_POST['delivery_address'],
55 $_POST['phone'], $_POST['fax'], $_POST['email'], $_POST['contact']);
56 display_notification(_('Selected location has been updated'));
61 /*selected_id is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new Location form */
63 add_item_location($_POST['loc_code'], $_POST['location_name'], $_POST['delivery_address'],
64 $_POST['phone'], $_POST['fax'], $_POST['email'], $_POST['contact']);
65 display_notification(_('New location has been added'));
72 function can_delete($selected_id)
74 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_moves WHERE loc_code='$selected_id'";
75 $result = db_query($sql, "could not query stock moves");
76 $myrow = db_fetch_row($result);
79 display_error(_("Cannot delete this location because item movements have been created using this location."));
83 $sql= "SELECT COUNT(*) FROM ".TB_PREF."workorders WHERE loc_code='$selected_id'";
84 $result = db_query($sql, "could not query work orders");
85 $myrow = db_fetch_row($result);
88 display_error(_("Cannot delete this location because it is used by some work orders records."));
92 $sql= "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE default_location='$selected_id'";
93 $result = db_query($sql, "could not query customer branches");
94 $myrow = db_fetch_row($result);
97 display_error(_("Cannot delete this location because it is used by some branch records as the default location to deliver from."));
104 //----------------------------------------------------------------------------------
106 if ($Mode == 'Delete')
109 if (can_delete($selected_id))
111 delete_item_location($selected_id);
112 display_notification(_('Selected location has been deleted'));
113 } //end if Delete Location
117 if ($Mode == 'RESET')
123 $sql = "SELECT * FROM ".TB_PREF."locations";
124 $result = db_query($sql, "could not query locations");;
127 start_table("$table_style width=30%");
128 $th = array(_("Location Code"), _("Location Name"), "", "");
130 $k = 0; //row colour counter
131 while ($myrow = db_fetch_row($result))
134 alt_table_row_color($k);
136 label_cell($myrow[0]);
137 label_cell($myrow[1]);
138 edit_button_cell("Edit".$myrow[0], _("Edit"));
139 delete_button_cell("Delete".$myrow[0], _("Delete"));
142 //END WHILE LIST LOOP
144 //end of ifs and buts!
153 start_table($table_style2);
155 $_POST['email'] = "";
156 if ($selected_id != -1)
158 //editing an existing Location
160 if ($Mode == 'Edit') {
161 $myrow = get_item_location($selected_id);
163 $_POST['loc_code'] = $myrow["loc_code"];
164 $_POST['location_name'] = $myrow["location_name"];
165 $_POST['delivery_address'] = $myrow["delivery_address"];
166 $_POST['contact'] = $myrow["contact"];
167 $_POST['phone'] = $myrow["phone"];
168 $_POST['fax'] = $myrow["fax"];
169 $_POST['email'] = $myrow["email"];
171 hidden("selected_id", $selected_id);
173 label_row(_("Location Code:"), $_POST['loc_code']);
176 { //end of if $selected_id only do the else when a new record is being entered
177 text_row(_("Location Code:"), 'loc_code', null, 5, 5);
180 text_row_ex(_("Location Name:"), 'location_name', 50, 50);
181 text_row_ex(_("Contact for deliveries:"), 'contact', 30, 30);
183 textarea_row(_("Address:"), 'delivery_address', null, 35, 5);
185 text_row_ex(_("Telephone No:"), 'phone', 30, 30);
186 text_row_ex(_("Facsimile No:"), 'fax', 30, 30);
187 email_row_ex(_("E-mail:"), 'email', 30);
190 submit_add_or_update_center($selected_id == -1, '', true);