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_UOM';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_($help_context = "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(db_escape($_POST['abbr']))>(20+2))
40 display_error(_("The unit of measure code is too long."));
43 if (strlen($_POST['description']) == 0)
46 display_error(_("The unit of measure description cannot be empty."));
47 set_focus('description');
50 if ($input_error !=1) {
51 write_item_unit($selected_id, $_POST['abbr'], $_POST['description'], $_POST['decimals'] );
52 if($selected_id != '')
53 display_notification(_('Selected unit has been updated'));
55 display_notification(_('New unit has been added'));
60 //----------------------------------------------------------------------------------
62 if ($Mode == 'Delete')
65 // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
67 if (item_unit_used($selected_id))
69 display_error(_("Cannot delete this unit of measure because items have been created using this unit."));
74 delete_item_unit($selected_id);
75 display_notification(_('Selected unit has been deleted'));
83 $sav = get_post('show_inactive');
85 $_POST['show_inactive'] = $sav;
88 //----------------------------------------------------------------------------------
90 $result = get_all_item_units(check_value('show_inactive'));
93 start_table(TABLESTYLE, "width='40%'");
94 $th = array(_('Unit'), _('Description'), _('Decimals'), "", "");
95 inactive_control_column($th);
98 $k = 0; //row colour counter
100 while ($myrow = db_fetch($result))
103 alt_table_row_color($k);
105 label_cell($myrow["abbr"]);
106 label_cell($myrow["name"]);
107 label_cell(($myrow["decimals"]==-1?_("User Quantity Decimals"):$myrow["decimals"]));
108 $id = htmlentities($myrow["abbr"]);
109 inactive_control_cell($id, $myrow["inactive"], 'item_units', 'abbr');
110 edit_button_cell("Edit".$id, _("Edit"));
111 delete_button_cell("Delete".$id, _("Delete"));
115 inactive_control_row($th);
118 //----------------------------------------------------------------------------------
120 start_table(TABLESTYLE2);
122 if ($selected_id != '')
124 if ($Mode == 'Edit') {
125 //editing an existing item category
127 $myrow = get_item_unit($selected_id);
129 $_POST['abbr'] = $myrow["abbr"];
130 $_POST['description'] = $myrow["name"];
131 $_POST['decimals'] = $myrow["decimals"];
133 hidden('selected_id', $myrow["abbr"]);
135 if ($selected_id != '' && item_unit_used($selected_id)) {
136 label_row(_("Unit Abbreviation:"), $_POST['abbr']);
137 hidden('abbr', $_POST['abbr']);
139 text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
140 text_row(_("Descriptive Name:"), 'description', null, 40, 40);
142 number_list_row(_("Decimal Places:"), 'decimals', null, 0, 6, _("User Quantity Decimals"));
146 submit_add_or_update_center($selected_id == '', '', 'both');