[0004212] Work Order Entry: fixed error when voided WO refence is reused.
[fa-stable.git] / inventory / manage / item_categories.php
index 904afc79d4329006a7f37e601e6bb3109f7293d8..136c0a80eeee6f9907dd79a176c4ebcd31be3299 100644 (file)
@@ -9,11 +9,24 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-$page_security = 11;
-$path_to_root="../..";
+$page_security = 'SA_ITEMCATEGORY';
+$path_to_root = "../..";
 include($path_to_root . "/includes/session.inc");
 
-page(_("Item Categories"));
+if (isset($_GET['FixedAsset'])) {
+  $page_security = 'SA_ASSETCATEGORY';
+  $help_context = "Fixed Assets Categories";
+  $_POST['mb_flag'] = 'F';
+}
+else {
+  $help_context = "Item Categories";
+}
+
+$js = "";
+if ($SysPrefs->use_popup_windows && $SysPrefs->use_popup_search)
+       $js .= get_js_open_window(900, 500);
+
+page(_($help_context), false, false, "", $js);
 
 include_once($path_to_root . "/includes/ui.inc");
 
@@ -42,8 +55,9 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
                    update_item_category($selected_id, $_POST['description'],
                                $_POST['tax_type_id'],  $_POST['sales_account'], 
                                $_POST['cogs_account'], $_POST['inventory_account'], 
-                               $_POST['adjustment_account'], $_POST['assembly_account'],
-                               $_POST['units'], $_POST['mb_flag'],     $_POST['dim1'], $_POST['dim2']);
+                               $_POST['adjustment_account'], $_POST['wip_account'],
+                               $_POST['units'], $_POST['mb_flag'],     $_POST['dim1'], $_POST['dim2'],
+                               check_value('no_sale'), check_value('no_purchase'));
                        display_notification(_('Selected item category has been updated'));
        } 
        else 
@@ -51,9 +65,9 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
                    add_item_category($_POST['description'],
                                $_POST['tax_type_id'],  $_POST['sales_account'], 
                                $_POST['cogs_account'], $_POST['inventory_account'], 
-                               $_POST['adjustment_account'], $_POST['assembly_account'], 
+                               $_POST['adjustment_account'], $_POST['wip_account'], 
                                $_POST['units'], $_POST['mb_flag'],     $_POST['dim1'], 
-                               $_POST['dim2']);
+                               $_POST['dim2'], check_value('no_sale'), check_value('no_purchase'));
                        display_notification(_('New item category has been added'));
        }
                $Mode = 'RESET';
@@ -66,10 +80,7 @@ if ($Mode == 'Delete')
 {
 
        // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
-       $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE category_id='$selected_id'";
-       $result = db_query($sql, "could not query stock master");
-       $myrow = db_fetch_row($result);
-       if ($myrow[0] > 0) 
+       if (key_in_foreign_table($selected_id, 'stock_master', 'category_id'))
        {
                display_error(_("Cannot delete this item category because items have been created using this item category."));
        } 
@@ -84,23 +95,35 @@ if ($Mode == 'Delete')
 if ($Mode == 'RESET')
 {
        $selected_id = -1;
+       $sav = get_post('show_inactive');
+    $mb_flag = get_post('mb_flag');
        unset($_POST);
+       $_POST['show_inactive'] = $sav;
+       if (is_fixed_asset($mb_flag))
+               $_POST['mb_flag'] = 'F';
 }
 if (list_updated('mb_flag')) {
        $Ajax->activate('details');
 }
-//----------------------------------------------------------------------------------
 
-$sql = "SELECT c.*, t.name as tax_name FROM ".TB_PREF."stock_category c, "
-       .TB_PREF."item_tax_types t WHERE c.dflt_tax_type=t.id";
+//----------------------------------------------------------------------------------
+$fixed_asset = is_fixed_asset(get_post('mb_flag'));
 
-$result = db_query($sql, "could not get stock categories");
+$result = get_item_categories(check_value('show_inactive'), $fixed_asset);
 
 start_form();
-start_table("$table_style width=80%");
-$th = array(_("Name"), _("Tax type"), _("Units"), _("Type"), _("Sales Act"),
-_("COGS Account"), _("Inventory Account"), _("Adjustment Account"),
-_("Assembly Account"), "", "");
+start_table(TABLESTYLE, "width='80%'");
+if ($fixed_asset) {
+       $th = array(_("Name"), _("Tax type"), _("Units"), _("Sales Act"),
+               _("Asset Account"), _("Deprecation Cost Account"),
+               _("Depreciation/Disposal Account"), "", "");
+} else {
+       $th = array(_("Name"), _("Tax type"), _("Units"), _("Type"), _("Sales Act"),
+               _("Inventory Account"), _("COGS Account"), _("Adjustment Account"),
+               _("Assembly Account"), "", "");
+}
+inactive_control_column($th);
+
 table_header($th);
 $k = 0; //row colour counter
 
@@ -112,26 +135,27 @@ while ($myrow = db_fetch($result))
        label_cell($myrow["description"]);
        label_cell($myrow["tax_name"]);
        label_cell($myrow["dflt_units"], "align=center");
-       label_cell($stock_types[$myrow["dflt_mb_flag"]]);
+       if (!$fixed_asset)
+               label_cell($stock_types[$myrow["dflt_mb_flag"]]);
        label_cell($myrow["dflt_sales_act"], "align=center");
-       label_cell($myrow["dflt_cogs_act"], "align=center");
        label_cell($myrow["dflt_inventory_act"], "align=center");
+       label_cell($myrow["dflt_cogs_act"], "align=center");
        label_cell($myrow["dflt_adjustment_act"], "align=center");
-       label_cell($myrow["dflt_assembly_act"], "align=center");
-       edit_button_cell("Edit".$myrow[0], _("Edit"));
-       delete_button_cell("Delete".$myrow[0], _("Delete"));
+       if (!$fixed_asset)
+               label_cell($myrow["dflt_wip_act"], "align=center");
+       inactive_control_cell($myrow["category_id"], $myrow["inactive"], 'stock_category', 'category_id');
+       edit_button_cell("Edit".$myrow["category_id"], _("Edit"));
+       delete_button_cell("Delete".$myrow["category_id"], _("Delete"));
        end_row();
 }
 
+inactive_control_row($th);
 end_table();
-end_form();
 echo '<br>';
 //----------------------------------------------------------------------------------
 
-start_form();
-
 div_start('details');
-start_table($table_style2);
+start_table(TABLESTYLE2);
 
 if ($selected_id != -1) 
 {
@@ -146,17 +170,21 @@ if ($selected_id != -1)
                $_POST['cogs_account']  = $myrow["dflt_cogs_act"];
                $_POST['inventory_account']  = $myrow["dflt_inventory_act"];
                $_POST['adjustment_account']  = $myrow["dflt_adjustment_act"];
-               $_POST['assembly_account']  = $myrow["dflt_assembly_act"];
+               $_POST['wip_account']  = $myrow["dflt_wip_act"];
                $_POST['units']  = $myrow["dflt_units"];
                $_POST['mb_flag']  = $myrow["dflt_mb_flag"];
                $_POST['dim1']  = $myrow["dflt_dim1"];
                $_POST['dim2']  = $myrow["dflt_dim2"];
+               $_POST['no_sale']  = $myrow["dflt_no_sale"];
+               $_POST['no_purchase']  = $myrow["dflt_no_purchase"];
        } 
        hidden('selected_id', $selected_id);
        hidden('category_id');
-} else {
+} else if ($Mode != 'CLONE') {
                $_POST['long_description'] = '';
                $_POST['description'] = '';
+               $_POST['no_sale']  = 0;
+               $_POST['no_purchase']  = 0;
 
                $company_record = get_company_prefs();
 
@@ -172,8 +200,8 @@ if ($selected_id != -1)
        if (get_post('adjustment_account') == "")
                $_POST['adjustment_account'] = $company_record["default_adj_act"];
 
-       if (get_post('assembly_account') == "")
-               $_POST['assembly_account'] = $company_record["default_assembly_act"];
+       if (get_post('wip_account') == "")
+               $_POST['wip_account'] = $company_record["default_wip_act"];
 
 }
 
@@ -183,29 +211,46 @@ table_section_title(_("Default values for new items"));
 
 item_tax_types_list_row(_("Item Tax Type:"), 'tax_type_id', null);
 
-stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, true);
+if (is_fixed_asset(get_post('mb_flag')))
+       hidden('mb_flag', 'F');
+else
+       stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, true);
 
 stock_units_list_row(_("Units of Measure:"), 'units', null);
 
-gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']);
+if (is_fixed_asset($_POST['mb_flag'])) 
+       hidden('no_sale', 0);
+else
+       check_row(_("Exclude from sales:"), 'no_sale');
 
-gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']);
+check_row(_("Exclude from purchases:"), 'no_purchase');
 
-if (!is_service($_POST['mb_flag'])) 
+gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']);
+
+if (is_service($_POST['mb_flag']))
 {
        gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
-       gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'adjustment_account', $_POST['adjustment_account']);
+       hidden('inventory_account', $_POST['inventory_account']);
+       hidden('adjustment_account', $_POST['adjustment_account']);
 }
-else 
+elseif (is_fixed_asset($_POST['mb_flag'])) 
 {
-       hidden('cogs_account', $_POST['cogs_account']);
-       hidden('adjustment_account', $_POST['adjustment_account']);
+       gl_all_accounts_list_row(_("Asset account:"), 'inventory_account', $_POST['inventory_account']);
+       gl_all_accounts_list_row(_("Depreciation cost account:"), 'cogs_account', $_POST['cogs_account']);
+       gl_all_accounts_list_row(_("Depreciation/Disposal account:"), 'adjustment_account', $_POST['adjustment_account']);
+}
+else
+{
+       gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']);
+
+       gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
+       gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'adjustment_account', $_POST['adjustment_account']);
 }
 
 if (is_manufactured($_POST['mb_flag']))
-       gl_all_accounts_list_row(_("Item Assembly Costs Account:"), 'assembly_account', $_POST['assembly_account']);
+       gl_all_accounts_list_row(_("Item Assembly Costs Account:"), 'wip_account', $_POST['wip_account']);
 else
-       hidden('assembly_account', $_POST['assembly_account']);
+       hidden('wip_account', $_POST['wip_account']);
 
 $dim = get_company_pref('use_dimension');
 if ($dim >= 1)
@@ -221,10 +266,9 @@ if ($dim < 2)
 
 end_table(1);
 div_end();
-submit_add_or_update_center($selected_id == -1, '', true);
+submit_add_or_update_center($selected_id == -1, '', 'both', true);
 
 end_form();
 
 end_page();
 
-?>