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(_("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='$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='$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'));
99 //-----------------------------------------------------------------------------------
101 $result = get_all_work_centres();
104 start_table("$table_style width=50%");
105 $th = array(_("Name"), _("description"), "", "");
109 while ($myrow = db_fetch($result))
112 alt_table_row_color($k);
114 label_cell($myrow["name"]);
115 label_cell($myrow["description"]);
116 edit_button_cell("Edit".$myrow['id'], _("Edit"));
117 delete_button_cell("Delete".$myrow['id'], _("Delete"));
124 //-----------------------------------------------------------------------------------
128 start_table($table_style2);
130 if ($selected_id != -1)
132 if ($Mode == 'Edit') {
133 //editing an existing status code
134 $myrow = get_work_centre($selected_id);
136 $_POST['name'] = $myrow["name"];
137 $_POST['description'] = $myrow["description"];
139 hidden('selected_id', $selected_id);
142 text_row_ex(_("Name:"), 'name', 40);
143 text_row_ex(_("Description:"), 'description', 50);
147 submit_add_or_update_center($selected_id == -1, '', true);
151 //------------------------------------------------------------------------------------