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_ITEMCATEGORY';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_("Item Categories"));
18 include_once($path_to_root . "/includes/ui.inc");
20 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
22 simple_page_mode(true);
23 //----------------------------------------------------------------------------------
25 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
28 //initialise no input errors assumed initially before we test
31 if (strlen($_POST['description']) == 0)
34 display_error(_("The item category description cannot be empty."));
35 set_focus('description');
40 if ($selected_id != -1)
42 update_item_category($selected_id, $_POST['description'],
43 $_POST['tax_type_id'], $_POST['sales_account'],
44 $_POST['cogs_account'], $_POST['inventory_account'],
45 $_POST['adjustment_account'], $_POST['assembly_account'],
46 $_POST['units'], $_POST['mb_flag'], $_POST['dim1'], $_POST['dim2'],
47 check_value('no_sale'));
48 display_notification(_('Selected item category has been updated'));
52 add_item_category($_POST['description'],
53 $_POST['tax_type_id'], $_POST['sales_account'],
54 $_POST['cogs_account'], $_POST['inventory_account'],
55 $_POST['adjustment_account'], $_POST['assembly_account'],
56 $_POST['units'], $_POST['mb_flag'], $_POST['dim1'],
57 $_POST['dim2'], check_value('no_sale'));
58 display_notification(_('New item category has been added'));
64 //----------------------------------------------------------------------------------
66 if ($Mode == 'Delete')
69 // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
70 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE category_id='$selected_id'";
71 $result = db_query($sql, "could not query stock master");
72 $myrow = db_fetch_row($result);
75 display_error(_("Cannot delete this item category because items have been created using this item category."));
79 delete_item_category($selected_id);
80 display_notification(_('Selected item category has been deleted'));
88 $sav = get_post('show_inactive');
90 $_POST['show_inactive'] = $sav;
92 if (list_updated('mb_flag')) {
93 $Ajax->activate('details');
95 //----------------------------------------------------------------------------------
97 $sql = "SELECT c.*, t.name as tax_name FROM ".TB_PREF."stock_category c, "
98 .TB_PREF."item_tax_types t WHERE c.dflt_tax_type=t.id";
99 if (!check_value('show_inactive')) $sql .= " AND !c.inactive";
101 $result = db_query($sql, "could not get stock categories");
104 start_table("$table_style width=80%");
105 $th = array(_("Name"), _("Tax type"), _("Units"), _("Type"), _("Sales Act"),
106 _("Inventory Account"), _("COGS Account"), _("Adjustment Account"),
107 _("Assembly Account"), "", "");
108 inactive_control_column($th);
111 $k = 0; //row colour counter
113 while ($myrow = db_fetch($result))
116 alt_table_row_color($k);
118 label_cell($myrow["description"]);
119 label_cell($myrow["tax_name"]);
120 label_cell($myrow["dflt_units"], "align=center");
121 label_cell($stock_types[$myrow["dflt_mb_flag"]]);
122 label_cell($myrow["dflt_sales_act"], "align=center");
123 label_cell($myrow["dflt_inventory_act"], "align=center");
124 label_cell($myrow["dflt_cogs_act"], "align=center");
125 label_cell($myrow["dflt_adjustment_act"], "align=center");
126 label_cell($myrow["dflt_assembly_act"], "align=center");
127 inactive_control_cell($myrow["category_id"], $myrow["inactive"], 'stock_category', 'category_id');
128 edit_button_cell("Edit".$myrow["category_id"], _("Edit"));
129 delete_button_cell("Delete".$myrow["category_id"], _("Delete"));
133 inactive_control_row($th);
136 //----------------------------------------------------------------------------------
138 div_start('details');
139 start_table($table_style2);
141 if ($selected_id != -1)
143 if ($Mode == 'Edit') {
144 //editing an existing item category
145 $myrow = get_item_category($selected_id);
147 $_POST['category_id'] = $myrow["category_id"];
148 $_POST['description'] = $myrow["description"];
149 $_POST['tax_type_id'] = $myrow["dflt_tax_type"];
150 $_POST['sales_account'] = $myrow["dflt_sales_act"];
151 $_POST['cogs_account'] = $myrow["dflt_cogs_act"];
152 $_POST['inventory_account'] = $myrow["dflt_inventory_act"];
153 $_POST['adjustment_account'] = $myrow["dflt_adjustment_act"];
154 $_POST['assembly_account'] = $myrow["dflt_assembly_act"];
155 $_POST['units'] = $myrow["dflt_units"];
156 $_POST['mb_flag'] = $myrow["dflt_mb_flag"];
157 $_POST['dim1'] = $myrow["dflt_dim1"];
158 $_POST['dim2'] = $myrow["dflt_dim2"];
159 $_POST['no_sale'] = $myrow["dflt_no_sale"];
161 hidden('selected_id', $selected_id);
162 hidden('category_id');
163 } else if ($Mode != 'CLONE') {
164 $_POST['long_description'] = '';
165 $_POST['description'] = '';
166 $_POST['no_sale'] = 0;
168 $company_record = get_company_prefs();
170 if (get_post('inventory_account') == "")
171 $_POST['inventory_account'] = $company_record["default_inventory_act"];
173 if (get_post('cogs_account') == "")
174 $_POST['cogs_account'] = $company_record["default_cogs_act"];
176 if (get_post('sales_account') == "")
177 $_POST['sales_account'] = $company_record["default_inv_sales_act"];
179 if (get_post('adjustment_account') == "")
180 $_POST['adjustment_account'] = $company_record["default_adj_act"];
182 if (get_post('assembly_account') == "")
183 $_POST['assembly_account'] = $company_record["default_assembly_act"];
187 text_row(_("Category Name:"), 'description', null, 30, 30);
189 table_section_title(_("Default values for new items"));
191 item_tax_types_list_row(_("Item Tax Type:"), 'tax_type_id', null);
193 stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, true);
195 stock_units_list_row(_("Units of Measure:"), 'units', null);
197 check_row(_("Exclude from sales:"), 'no_sale');
199 gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']);
201 if (is_service($_POST['mb_flag']))
203 gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
204 hidden('inventory_account', $_POST['inventory_account']);
205 hidden('adjustment_account', $_POST['adjustment_account']);
209 gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']);
211 gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
212 gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'adjustment_account', $_POST['adjustment_account']);
215 if (is_manufactured($_POST['mb_flag']))
216 gl_all_accounts_list_row(_("Item Assembly Costs Account:"), 'assembly_account', $_POST['assembly_account']);
218 hidden('assembly_account', $_POST['assembly_account']);
220 $dim = get_company_pref('use_dimension');
223 dimensions_list_row(_("Dimension")." 1", 'dim1', null, true, " ", false, 1);
225 dimensions_list_row(_("Dimension")." 2", 'dim2', null, true, " ", false, 2);
234 submit_add_or_update_center($selected_id == -1, '', 'both', true);