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 $page_security = 'SA_WORKCENTRES';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_("Work Centres"));
18 include($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
20 include($path_to_root . "/includes/ui.inc");
22 simple_page_mode(true);
23 //-----------------------------------------------------------------------------------
25 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
28 //initialise no input errors assumed initially before we test
31 if (strlen($_POST['name']) == 0)
34 display_error(_("The work centre name cannot be empty."));
38 if ($input_error != 1)
41 if ($selected_id != -1)
43 update_work_centre($selected_id, $_POST['name'], $_POST['description']);
44 display_notification(_('Selected work center has been updated'));
48 add_work_centre($_POST['name'], $_POST['description']);
49 display_notification(_('New work center has been added'));
55 //-----------------------------------------------------------------------------------
57 function can_delete($selected_id)
59 $sql= "SELECT COUNT(*) FROM ".TB_PREF."bom WHERE workcentre_added=".db_escape($selected_id);
60 $result = db_query($sql, "check can delete work centre");
61 $myrow = db_fetch_row($result);
64 display_error(_("Cannot delete this work centre because BOMs have been created referring to it."));
68 $sql= "SELECT COUNT(*) FROM ".TB_PREF."wo_requirements WHERE workcentre=".db_escape($selected_id);
69 $result = db_query($sql, "check can delete work centre");
70 $myrow = db_fetch_row($result);
73 display_error(_("Cannot delete this work centre because work order requirements have been created referring to it."));
81 //-----------------------------------------------------------------------------------
83 if ($Mode == 'Delete')
86 if (can_delete($selected_id))
88 delete_work_centre($selected_id);
89 display_notification(_('Selected work center has been deleted'));
97 $sav = get_post('show_inactive');
99 $_POST['show_inactive'] = $sav;
101 //-----------------------------------------------------------------------------------
103 $result = get_all_work_centres(check_value('show_inactive'));
106 start_table("$table_style width=50%");
107 $th = array(_("Name"), _("description"), "", "");
108 inactive_control_column($th);
112 while ($myrow = db_fetch($result))
115 alt_table_row_color($k);
117 label_cell($myrow["name"]);
118 label_cell($myrow["description"]);
119 inactive_control_cell($myrow["id"], $myrow["inactive"], 'workcentres', 'id');
120 edit_button_cell("Edit".$myrow['id'], _("Edit"));
121 delete_button_cell("Delete".$myrow['id'], _("Delete"));
125 inactive_control_row($th);
127 //-----------------------------------------------------------------------------------
129 start_table($table_style2);
131 if ($selected_id != -1)
133 if ($Mode == 'Edit') {
134 //editing an existing status code
135 $myrow = get_work_centre($selected_id);
137 $_POST['name'] = $myrow["name"];
138 $_POST['description'] = $myrow["description"];
140 hidden('selected_id', $selected_id);
143 text_row_ex(_("Name:"), 'name', 40);
144 text_row_ex(_("Description:"), 'description', 50);
148 submit_add_or_update_center($selected_id == -1, '', 'both');
152 //------------------------------------------------------------------------------------