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(_("Units of Measure"));
18 include_once($path_to_root . "/includes/ui.inc");
20 include_once($path_to_root . "/inventory/includes/db/items_units_db.inc");
22 simple_page_mode(false);
23 //----------------------------------------------------------------------------------
25 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
28 //initialise no input errors assumed initially before we test
31 if (strlen($_POST['abbr']) == 0)
34 display_error(_("The unit of measure code cannot be empty."));
37 if (strlen($_POST['description']) == 0)
40 display_error(_("The unit of measure description cannot be empty."));
41 set_focus('description');
44 if ($input_error !=1) {
45 write_item_unit(htmlentities($selected_id), $_POST['abbr'], $_POST['description'], $_POST['decimals'] );
46 if($selected_id != '')
47 display_notification(_('Selected unit has been updated'));
49 display_notification(_('New unit has been added'));
54 //----------------------------------------------------------------------------------
56 if ($Mode == 'Delete')
59 // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
61 if (item_unit_used($selected_id))
63 display_error(_("Cannot delete this unit of measure because items have been created using this unit."));
68 delete_item_unit($selected_id);
69 display_notification(_('Selected unit has been deleted'));
80 //----------------------------------------------------------------------------------
82 $result = get_all_item_units();
84 start_table("$table_style width=40%");
85 $th = array(_('Unit'), _('Description'), _('Decimals'), "", "");
88 $k = 0; //row colour counter
90 while ($myrow = db_fetch($result))
93 alt_table_row_color($k);
95 label_cell($myrow["abbr"]);
96 label_cell($myrow["name"]);
97 label_cell(($myrow["decimals"]==-1?_("User Quantity Decimals"):$myrow["decimals"]));
99 edit_button_cell("Edit".$myrow[0], _("Edit"));
100 delete_button_cell("Delete".$myrow[0], _("Delete"));
108 //----------------------------------------------------------------------------------
112 start_table($table_style2);
114 if ($selected_id != '')
116 if ($Mode == 'Edit') {
117 //editing an existing item category
119 $myrow = get_item_unit($selected_id);
121 $_POST['abbr'] = $myrow["abbr"];
122 $_POST['description'] = $myrow["name"];
123 $_POST['decimals'] = $myrow["decimals"];
125 hidden('selected_id', $selected_id);
127 if ($selected_id != '' && item_unit_used($selected_id)) {
128 label_row(_("Unit Abbreviation:"), $_POST['abbr']);
129 hidden('abbr', $_POST['abbr']);
131 text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
132 text_row(_("Descriptive Name:"), 'description', null, 40, 40);
134 number_list_row(_("Decimal Places:"), 'decimals', null, 0, 6, _("User Quantity Decimals"));
138 submit_add_or_update_center($selected_id == '', '', true);