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(_($help_context = "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 if (key_in_foreign_table($selected_id, 'bom', 'workcentre_added'))
61 display_error(_("Cannot delete this work centre because BOMs have been created referring to it."));
65 if (key_in_foreign_table($selected_id, 'wo_requirements', 'workcentre'))
67 display_error(_("Cannot delete this work centre because work order requirements have been created referring to it."));
75 //-----------------------------------------------------------------------------------
77 if ($Mode == 'Delete')
80 if (can_delete($selected_id))
82 delete_work_centre($selected_id);
83 display_notification(_('Selected work center has been deleted'));
91 $sav = get_post('show_inactive');
93 $_POST['show_inactive'] = $sav;
95 //-----------------------------------------------------------------------------------
97 $result = get_all_work_centres(check_value('show_inactive'));
100 start_table(TABLESTYLE, "width=50%");
101 $th = array(_("Name"), _("description"), "", "");
102 inactive_control_column($th);
106 while ($myrow = db_fetch($result))
109 alt_table_row_color($k);
111 label_cell($myrow["name"]);
112 label_cell($myrow["description"]);
113 inactive_control_cell($myrow["id"], $myrow["inactive"], 'workcentres', 'id');
114 edit_button_cell("Edit".$myrow['id'], _("Edit"));
115 delete_button_cell("Delete".$myrow['id'], _("Delete"));
119 inactive_control_row($th);
121 //-----------------------------------------------------------------------------------
123 start_table(TABLESTYLE2);
125 if ($selected_id != -1)
127 if ($Mode == 'Edit') {
128 //editing an existing status code
129 $myrow = get_work_centre($selected_id);
131 $_POST['name'] = $myrow["name"];
132 $_POST['description'] = $myrow["description"];
134 hidden('selected_id', $selected_id);
137 text_row_ex(_("Name:"), 'name', 40);
138 text_row_ex(_("Description:"), 'description', 50);
142 submit_add_or_update_center($selected_id == -1, '', 'both');
146 //------------------------------------------------------------------------------------