From 4cdd49c280b3988a05f5c4639979106aff778237 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Thu, 24 Dec 2015 12:19:01 +0100 Subject: [PATCH] Fixes in upgrade procedures. --- sql/alter2.4.php | 9 ++++++++- sql/alter2.4.sql | 6 ------ sql/alter2.4rc1.php | 48 +++++++++++++++++++++++++++++++++++++++++++++ sql/alter2.4rc1.sql | 11 ++++++----- 4 files changed, 62 insertions(+), 12 deletions(-) diff --git a/sql/alter2.4.php b/sql/alter2.4.php index 0dfdbfac..61b47ffa 100644 --- a/sql/alter2.4.php +++ b/sql/alter2.4.php @@ -101,6 +101,13 @@ class fa2_4 extends fa_patch { $pref = $this->companies[$company]['tbpref']; db_query("DROP TABLE IF EXISTS " . $pref . 'wo_costing'); db_query("DROP TABLE IF EXISTS " . $pref . 'stock_fa_class'); + db_query("DELETE FROM ".$pref."sys_prefs + WHERE `name` in ( + 'gl_closing_date', 'deferred_income_act', 'no_zero_lines_amount', 'accounts_alpha', + 'tax_algorithm', 'grn_clearing_act', 'default_receival_required', + 'default_quote_valid_days', 'no_zero_lines_amount', 'show_po_item_codes', 'accounts_alpha', + 'loc_notification', 'print_invoice_no', 'allow_negative_prices', 'print_item_images_on_quote', + 'bcc_email', 'alternative_tax_include_on_docs', 'suppress_tax_rates')"); } function update_workorders() @@ -108,7 +115,7 @@ class fa2_4 extends fa_patch { global $db; $sql = "SELECT DISTINCT type, type_no, tran_date, person_id FROM ".TB_PREF."gl_trans WHERE `type`=".ST_WORKORDER - ." AND person_type_id=1"; + ." AND person_type_id=1"; $res = db_query($sql); if (!$res) return $this->log_error(sprintf(_("Cannot update work orders costs:\n%s"), db_error_msg($db))); diff --git a/sql/alter2.4.sql b/sql/alter2.4.sql index 09ab36f7..e8389310 100644 --- a/sql/alter2.4.sql +++ b/sql/alter2.4.sql @@ -208,15 +208,9 @@ UPDATE `0_trans_tax_details` reg INSERT IGNORE INTO `0_sys_prefs` VALUES ('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, 0), - ('default_receival_required', 'glsetup.purchase', 'smallint', 6, '10'), ('default_quote_valid_days', 'glsetup.sales', 'smallint', 6, 30), ('no_zero_lines_amount', 'glsetup.sales', 'tinyint', 1, '1'), - ('show_po_item_codes', 'glsetup.purchase', 'tinyint', 1, '0'), ('accounts_alpha', 'glsetup.general', 'tinyint', 1, '0'), - ('loc_notification', 'glsetup.inventory', 'tinyint', 1, '0'), - ('print_invoice_no', 'glsetup.sales', 'tinyint', 1, '0'), - ('allow_negative_prices', 'glsetup.inventory', 'tinyint', 1, '1'), - ('print_item_images_on_quote', 'glsetup.inventory', 'tinyint', 1, '0'), ('bcc_email', 'setup.company', 'varchar', 100, ''), ('alternative_tax_include_on_docs', 'setup.company', 'tinyint', 1, '0'), ('suppress_tax_rates', 'setup.company', 'tinyint', 1, '0'); diff --git a/sql/alter2.4rc1.php b/sql/alter2.4rc1.php index 02e17122..984acde8 100644 --- a/sql/alter2.4rc1.php +++ b/sql/alter2.4rc1.php @@ -22,6 +22,35 @@ class fa2_4rc1 extends fa_patch { $this->description = _('Upgrade from version 2.4beta to 2.4RC1'); } + /* + Shows parameters to be selected before upgrade (if any) + */ + function show_params($comp) + { + display_note(_('Set optimal parameters and start upgrade:')); + start_table(TABLESTYLE); + start_row(); + table_section_title(_("Fixed Assets Defaults")); + gl_all_accounts_list_row(_("Loss On Asset Disposal Account:"), 'default_loss_on_asset_disposal_act', '5660', + true, false, _("None (will be set later)")); + + table_section_title(_("Manufacturing")); + gl_all_accounts_list_row(_("Work In Progress Account:"), 'wip_act', '1530', + true, false, _("None (will be set later)")); + end_row(); + end_table(); + br(); + } + + /* + Fetches selected upgrade parameters. + */ + function prepare() + { + $this->wip_account = get_post('wip_act'); + $this->fixed_disposal_act = get_post('default_loss_on_asset_disposal_act'); + return true; + } // // Install procedure. All additional changes // not included in sql file should go here. @@ -36,6 +65,17 @@ class fa2_4rc1 extends fa_patch { 'SA_DEPRECIATION', 'SA_ASSETSANALYTIC'), ); $result = $this->update_security_roles($sec_updates); + + $pref = $this->companies[$company]['tbpref']; + + if ($result) + if (!db_query("UPDATE ".$pref."sys_prefs SET value=".db_escape($this->wip_act) + ." WHERE name='wip_act'") + || !db_query("UPDATE ".$pref."sys_prefs SET value=".db_escape($this->fixed_disposal_act) + ." WHERE name='default_loss_on_asset_disposal_act'") + ) + return $this->log_error(sprintf(_("Cannot update sys prefs setting:\n%s"), db_error_msg($db))); + return $result; } @@ -46,6 +86,14 @@ class fa2_4rc1 extends fa_patch { { $pref = $this->companies[$company]['tbpref']; db_query("DROP TABLE IF EXISTS " . $pref . 'stock_fa_class'); + + db_query("DELETE FROM ".$pref."sys_prefs " + ."WHERE `name` in ( + 'default_loss_on_asset_disposal_act', + 'depreciation_period', + 'use_manufacturing', + 'use_fixed_assets', + 'wip_act')"); } } diff --git a/sql/alter2.4rc1.sql b/sql/alter2.4rc1.sql index c0d3c928..5753ab79 100644 --- a/sql/alter2.4rc1.sql +++ b/sql/alter2.4rc1.sql @@ -19,8 +19,9 @@ ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_date` date NOT NULL DEFAUL ALTER TABLE `0_stock_master` ADD COLUMN `fa_class_id` varchar(20) NOT NULL DEFAULT '' AFTER `depreciation_date`; ALTER TABLE `0_stock_master` CHANGE `actual_cost` `purchase_cost` double NOT NULL default 0; -INSERT INTO `0_sys_prefs` VALUES ('default_loss_on_asset_disposal_act', 'glsetup.items', 'varchar', '15', '5660'); -INSERT INTO `0_sys_prefs` VALUES ('depreciation_period', 'glsetup.company', 'tinyint', '1', '1'); - -INSERT INTO `0_sys_prefs` VALUES ('use_manufacturing','setup.company', 'tinyint', 1, '1'); -INSERT INTO `0_sys_prefs` VALUES ('use_fixed_assets','setup.company', 'tinyint', 1, '1'); +INSERT IGNORE INTO `0_sys_prefs` VALUES + ('default_loss_on_asset_disposal_act', 'glsetup.items', 'varchar', '15', '5660'), + ('depreciation_period', 'glsetup.company', 'tinyint', '1', '1'), + ('use_manufacturing','setup.company', 'tinyint', 1, '1'), + ('use_fixed_assets','setup.company', 'tinyint', 1, '1'), + ('wip_act', 'glsetup.manuf', 'varchar', '15', ''); -- 2.30.2