Added inactive records support.
[fa-stable.git] / inventory / manage / item_units.php
1 <?php
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 = 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         $sav = get_post('show_inactive');
78         unset($_POST);
79         $_POST['show_inactive'] = $sav;
80 }
81
82 //----------------------------------------------------------------------------------
83
84 $result = get_all_item_units(check_value('show_inactive'));
85
86 start_form();
87 start_table("$table_style width=40%");
88 $th = array(_('Unit'), _('Description'), _('Decimals'), "", "");
89 inactive_control_column($th);
90
91 table_header($th);
92 $k = 0; //row colour counter
93
94 while ($myrow = db_fetch($result))
95 {
96
97         alt_table_row_color($k);
98
99         label_cell($myrow["abbr"]);
100         label_cell($myrow["name"]);
101         label_cell(($myrow["decimals"]==-1?_("User Quantity Decimals"):$myrow["decimals"]));
102
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"));
106         end_row();
107 }
108
109 inactive_control_row($th);
110 end_table(1);
111
112 //----------------------------------------------------------------------------------
113
114 start_table($table_style2);
115
116 if ($selected_id != '') 
117 {
118         if ($Mode == 'Edit') {
119                 //editing an existing item category
120
121                 $myrow = get_item_unit($selected_id);
122
123                 $_POST['abbr'] = $myrow["abbr"];
124                 $_POST['description']  = $myrow["name"];
125                 $_POST['decimals']  = $myrow["decimals"];
126         }
127         hidden('selected_id', $selected_id);
128 }
129 if ($selected_id != '' && item_unit_used($selected_id)) {
130     label_row(_("Unit Abbreviation:"), $_POST['abbr']);
131     hidden('abbr', $_POST['abbr']);
132 } else
133     text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
134 text_row(_("Descriptive Name:"), 'description', null, 40, 40);
135
136 number_list_row(_("Decimal Places:"), 'decimals', null, 0, 6, _("User Quantity Decimals"));
137
138 end_table(1);
139
140 submit_add_or_update_center($selected_id == '', '', 'both');
141
142 end_form();
143
144 end_page();
145
146 ?>