Changed all smaller forms and tables to be uniform. Copyright notes.
[fa-stable.git] / inventory / manage / item_units.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU Affero General Public License,
5         AGPL, as published by the Free Software Foundation, either version 
6         3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 11;
13 $path_to_root="../..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_("Units of Measure"));
17
18 include_once($path_to_root . "/includes/ui.inc");
19
20 include_once($path_to_root . "/inventory/includes/db/items_units_db.inc");
21
22 simple_page_mode(false);
23 //----------------------------------------------------------------------------------
24
25 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
26 {
27
28         //initialise no input errors assumed initially before we test
29         $input_error = 0;
30
31         if (strlen($_POST['abbr']) == 0)
32         {
33                 $input_error = 1;
34                 display_error(_("The unit of measure code cannot be empty."));
35                 set_focus('abbr');
36         }
37         if (strlen($_POST['description']) == 0)
38         {
39                 $input_error = 1;
40                 display_error(_("The unit of measure description cannot be empty."));
41                 set_focus('description');
42         }
43
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'));
48                 else
49                         display_notification(_('New unit has been added'));
50                 $Mode = 'RESET';
51         }
52 }
53
54 //----------------------------------------------------------------------------------
55
56 if ($Mode == 'Delete')
57 {
58
59         // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
60
61         if (item_unit_used($selected_id))
62         {
63                 display_error(_("Cannot delete this unit of measure because items have been created using this unit."));
64
65         }
66         else
67         {
68                 delete_item_unit($selected_id);
69                 display_notification(_('Selected unit has been deleted'));
70         }
71         $Mode = 'RESET';
72 }
73
74 if ($Mode == 'RESET')
75 {
76         $selected_id = '';
77         unset($_POST);
78 }
79
80 //----------------------------------------------------------------------------------
81
82 $result = get_all_item_units();
83 start_form();
84 start_table("$table_style width=40%");
85 $th = array(_('Unit'), _('Description'), _('Decimals'), "", "");
86
87 table_header($th);
88 $k = 0; //row colour counter
89
90 while ($myrow = db_fetch($result))
91 {
92
93         alt_table_row_color($k);
94
95         label_cell($myrow["abbr"]);
96         label_cell($myrow["name"]);
97         label_cell(($myrow["decimals"]==-1?_("User Quantity Decimals"):$myrow["decimals"]));
98
99         edit_button_cell("Edit".$myrow[0], _("Edit"));
100         delete_button_cell("Delete".$myrow[0], _("Delete"));
101         end_row();
102 }
103
104 end_table();
105 end_form();
106 echo '<br>';
107
108 //----------------------------------------------------------------------------------
109
110 start_form();
111
112 start_table($table_style2);
113
114 if ($selected_id != '') 
115 {
116         if ($Mode == 'Edit') {
117                 //editing an existing item category
118
119                 $myrow = get_item_unit($selected_id);
120
121                 $_POST['abbr'] = $myrow["abbr"];
122                 $_POST['description']  = $myrow["name"];
123                 $_POST['decimals']  = $myrow["decimals"];
124         }
125         hidden('selected_id', $selected_id);
126 }
127 if ($selected_id != '' && item_unit_used($selected_id)) {
128     label_row(_("Unit Abbreviation:"), $_POST['abbr']);
129     hidden('abbr', $_POST['abbr']);
130 } else
131     text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
132 text_row(_("Descriptive Name:"), 'description', null, 40, 40);
133
134 number_list_row(_("Decimal Places:"), 'decimals', null, 0, 6, _("User Quantity Decimals"));
135
136 end_table(1);
137
138 submit_add_or_update_center($selected_id == '', '', true);
139
140 end_form();
141
142 end_page();
143
144 ?>