From 22a3c4f6476f3925627d1a4c96d6ac3e515381f6 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 8 Sep 2009 14:27:24 +0000 Subject: [PATCH] Small fixes to db upgrade for quotations --- sql/alter2.2.php | 45 +++++++++++++++++++++++++++++++++++++-------- sql/alter2.2.sql | 2 +- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/sql/alter2.2.php b/sql/alter2.2.php index 85a00be5..21fa6822 100644 --- a/sql/alter2.2.php +++ b/sql/alter2.2.php @@ -81,7 +81,27 @@ class fa2_2 { } } } -*/ +*/ + + if (!($ret = db_query("SELECT MAX(`order_no`) FROM `{$pref}sales_orders`")) || + !db_num_rows($ret)) + { + display_error(_('Cannot query max sales order number.')); + return false; + } + $row = db_fetch($ret); + $max_order = $row[0]; + $next_ref = $max_order+1; + $sql = "UPDATE `{$pref}sys_types` + SET `type_no`='$max_order', + `next_reference`='$next_ref' + WHERE `type_id`=30"; + if(!db_query($sql)) + { + display_error(_('Cannot store next sales order reference.')); + return false; + } + return convert_roles($pref); } // @@ -96,13 +116,22 @@ class fa2_2 { // Test if patch was applied before. // function installed($pref) { - if (check_table($pref, 'company', 'login_tout')) return false; - if (check_table($pref, 'stock_category', 'dflt_dim2')) return false; - if (check_table($pref, 'users', 'sticky_doc_date')) return false; - if (check_table($pref, 'audit_trail')) return false; - if (check_table($pref, 'stock_master','no_sale')) return false; - if (check_table($pref, 'users', 'role_id')) return false; - return true; + $n = 14; // number of features to be installed + if (check_table($pref, 'company', 'custom1_name')) $n--; + if (!check_table($pref, 'company', 'profit_loss_year_act')) $n--; + if (!check_table($pref, 'company', 'login_tout')) $n--; + if (!check_table($pref, 'stock_category', 'dflt_no_sale')) $n--; + if (!check_table($pref, 'users', 'sticky_doc_date')) $n--; + if (!check_table($pref, 'users', 'startup_tab')) $n--; + if (!check_table($pref, 'cust_branch', 'inactive')) $n--; + if (!check_table($pref, 'chart_class', 'ctype')) $n--; + if (!check_table($pref, 'audit_trail')) $n--; + if (!check_table($pref, 'currencies', 'auto_update')) $n--; + if (!check_table($pref, 'stock_master','no_sale')) $n--; + if (!check_table($pref, 'suppliers', 'supp_ref')) $n--; + if (!check_table($pref, 'users', 'role_id')) $n--; + if (!check_table($pref, 'sales_orders', 'reference')) $n--; + return $n == 0 ? true : 14 - $n; } }; diff --git a/sql/alter2.2.sql b/sql/alter2.2.sql index 25a406f1..486b1f50 100644 --- a/sql/alter2.2.sql +++ b/sql/alter2.2.sql @@ -104,5 +104,5 @@ ALTER TABLE `0_sales_orders` ADD COLUMN `trans_type` SMALLINT(6) NOT NULL DEFAUL ALTER TABLE `0_sales_orders` ADD COLUMN `reference` varchar(100) NOT NULL DEFAULT '' AFTER `branch_code`; ALTER TABLE `0_sales_orders` DROP PRIMARY KEY; ALTER TABLE `0_sales_orders` ADD PRIMARY KEY ( `trans_type` , `order_no` ); -UPDATE `0_sys_types` SET `type_no`=(SELECT MAX(`order_no`) FROM `0_sales_orders`), `next_reference`=(SELECT MAX(`order_no`)+1 FROM `0_sales_orders`) WHERE `type_id`=30; +UPDATE `0_sales_orders` SET `reference`=`order_no` WHERE 1; INSERT INTO `0_sys_types` (`type_id`, `type_no`, `next_reference`) VALUES (32, 0, '1'); \ No newline at end of file -- 2.30.2