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'));
77 $sav = get_post('show_inactive');
79 $_POST['show_inactive'] = $sav;
82 //----------------------------------------------------------------------------------
84 $result = get_all_item_units(check_value('show_inactive'));
87 start_table("$table_style width=40%");
88 $th = array(_('Unit'), _('Description'), _('Decimals'), "", "");
89 inactive_control_column($th);
92 $k = 0; //row colour counter
94 while ($myrow = db_fetch($result))
97 alt_table_row_color($k);
99 label_cell($myrow["abbr"]);
100 label_cell($myrow["name"]);
101 label_cell(($myrow["decimals"]==-1?_("User Quantity Decimals"):$myrow["decimals"]));
103 inactive_control_cell($myrow["abbr"], $myrow["inactive"], 'item_units', 'abbr');
104 edit_button_cell("Edit".$myrow["abbr"], _("Edit"));
105 delete_button_cell("Delete".$myrow["abbr"], _("Delete"));
109 inactive_control_row($th);
112 //----------------------------------------------------------------------------------
114 start_table($table_style2);
116 if ($selected_id != '')
118 if ($Mode == 'Edit') {
119 //editing an existing item category
121 $myrow = get_item_unit($selected_id);
123 $_POST['abbr'] = $myrow["abbr"];
124 $_POST['description'] = $myrow["name"];
125 $_POST['decimals'] = $myrow["decimals"];
127 hidden('selected_id', $selected_id);
129 if ($selected_id != '' && item_unit_used($selected_id)) {
130 label_row(_("Unit Abbreviation:"), $_POST['abbr']);
131 hidden('abbr', $_POST['abbr']);
133 text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
134 text_row(_("Descriptive Name:"), 'description', null, 40, 40);
136 number_list_row(_("Decimal Places:"), 'decimals', null, 0, 6, _("User Quantity Decimals"));
140 submit_add_or_update_center($selected_id == '', '', 'both');