Added upgrade from 2.3beta to 2.3RC.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 23 Jul 2010 13:07:04 +0000 (13:07 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 23 Jul 2010 13:07:04 +0000 (13:07 +0000)
sql/alter2.3.php
sql/alter2.3.sql
sql/en_US-demo.sql
sql/en_US-new.sql

index 44e161f64585782ae6349dacadb8c5df050ba768..fe455bfb4874a165fd9a4fa0c831528dd7208ba7 100644 (file)
@@ -14,6 +14,7 @@ class fa2_3 {
        var $description;
        var $sql = 'alter2.3.sql';
        var $preconf = true;
+       var $beta = false; // upgrade from 2.2 or 2.3beta;
        
        function fa2_3() {
                $this->description = _('Upgrade from version 2.2 to 2.3');
@@ -25,83 +26,97 @@ class fa2_3 {
        //
        function install($pref, $force) 
        {
-               $sql = "SELECT debtor_no, payment_terms FROM {$pref}debtors_master";
+               global $core_version;
+
+               if (!$this->beta) {
+                       // all specials below are already done on 2.3beta
+
+                       $sql = "SELECT debtor_no, payment_terms FROM {$pref}debtors_master";
                
-               $result = db_query($sql);
-               if (!$result) {
-                       display_error("Cannot read customers"
-                       .':<br>'. db_error_msg($db));
-                       return false;
-               }
-               // update all sales orders and transactions with customer std payment terms
-               while($cust = db_fetch($result)) {
-                       $sql = "UPDATE {$pref}debtor_trans SET "
-                               ."payment_terms = '" .$cust['payment_terms']
-                               ."' WHERE debtor_no='".$cust['debtor_no']."'";
-                       if (db_query($sql)==false) {
-                               display_error("Cannot update cust trans payment"
+                       $result = db_query($sql);
+                       if (!$result) {
+                               display_error("Cannot read customers"
                                .':<br>'. db_error_msg($db));
                                return false;
                        }
-                       $sql = "UPDATE {$pref}sales_orders SET "
-                               ."payment_terms = '" .$cust['payment_terms']
-                               ."' WHERE debtor_no='".$cust['debtor_no']."'";
-                       if (db_query($sql)==false) {
-                               display_error("Cannot update sales order payment"
-                               .':<br>'. db_error_msg($db));
+                       // update all sales orders and transactions with customer std payment terms
+                       while($cust = db_fetch($result)) {
+                               $sql = "UPDATE {$pref}debtor_trans SET "
+                                       ."payment_terms = '" .$cust['payment_terms']
+                                       ."' WHERE debtor_no='".$cust['debtor_no']."'";
+                               if (db_query($sql)==false) {
+                                       display_error("Cannot update cust trans payment"
+                                       .':<br>'. db_error_msg($db));
+                                       return false;
+                               }
+                               $sql = "UPDATE {$pref}sales_orders SET "
+                                       ."payment_terms = '" .$cust['payment_terms']
+                                       ."' WHERE debtor_no='".$cust['debtor_no']."'";
+                               if (db_query($sql)==false) {
+                                       display_error("Cannot update sales order payment"
+                                       .':<br>'. db_error_msg($db));
+                                       return false;
+                               }
+                       }
+                       if (!$this->update_totals($pref)) {
+                               display_error("Cannot update order totals");
                                return false;
                        }
-               }
-               if (!$this->update_totals($pref)) {
-                       display_error("Cannot update order totals");
-                       return false;
-               }
-               if (!$this->update_line_relations($pref)) {
-                       display_error("Cannot update sales document links");
-                       return false;
-               }
-               //remove obsolete and temporary columns.
-               // this have to be done here as db_import rearranges alter query order
-               $dropcol = array(
-                       'crm_persons' => array('tmp_id','tmp_class'),
-                       'debtors_master' => array('email'),
-                       'cust_branch' => array('phone', 'phone2', 'fax', 'email'),
-                       'suppliers' => array('phone', 'phone2', 'fax', 'email'),
-                       'debtor_trans' => array('trans_link')
-               );
-
-               foreach($dropcol as $table => $columns)
-                       foreach($columns as $col) {
-                       if (db_query("ALTER TABLE `{$pref}{$table}` DROP `$col`")==false) {
-                               display_error("Cannot drop {$table}.{$col} column:<br>".db_error_msg($db));
+                       if (!$this->update_line_relations($pref)) {
+                               display_error("Cannot update sales document links");
                                return false;
                        }
-               }
-               // remove old preferences table after upgrade script has been executed
-               $sql = "DROP TABLE IF EXISTS `{$pref}company`";
+                       //remove obsolete and temporary columns.
+                       // this have to be done here as db_import rearranges alter query order
+                       $dropcol = array(
+                               'crm_persons' => array('tmp_id','tmp_class'),
+                               'debtors_master' => array('email'),
+                               'cust_branch' => array('phone', 'phone2', 'fax', 'email'),
+                               'suppliers' => array('phone', 'phone2', 'fax', 'email'),
+                               'debtor_trans' => array('trans_link')
+                       );
 
-               return db_query($sql) && update_company_prefs(array('version_id'=>'2.3'), $pref);
+                       foreach($dropcol as $table => $columns)
+                               foreach($columns as $col) {
+                                       if (db_query("ALTER TABLE `{$pref}{$table}` DROP `$col`")==false) {
+                                               display_error("Cannot drop {$table}.{$col} column:<br>".db_error_msg($db));
+                                               return false;
+                                       }
+                               }
+                       // remove old preferences table after upgrade script has been executed
+                       $sql = "DROP TABLE IF EXISTS `{$pref}company`";
+                       if (!db_query($sql))
+                               return false;
+               }
+               return  update_company_prefs(array('version_id'=>$core_version), $pref);
        }
        //
        //      Checking before install
        //
        function pre_check($pref, $force)
        {
+               if ($this->beta && !$force)
+                       $this->sql = 'alter2.3rc.sql';
+
                return true;
        }
        //
        //      Test if patch was applied before.
        //
        function installed($pref) {
-               $n = 3; // number of patches to be installed
-               $patchcnt = 0;
+               $this->beta = !check_table($pref, 'suppliers', 'tax_included');
 
-               if (!check_table($pref, 'comments', 'type', array('Key'=>'MUL'))) $patchcnt++;
-               if (!check_table($pref, 'sys_prefs')) $patchcnt++;
-               if (!check_table($pref, 'sales_orders', 'payment_terms')) $patchcnt++;
+               $n = 1; // number of patches to be installed
+               $patchcnt = 0;
 
-               $n -= $patchcnt;
-               return $n == 0 ? true : $patchcnt;
+               if (!$this->beta) {
+                       $n += 3;
+                       if (!check_table($pref, 'comments', 'type', array('Key'=>'MUL'))) $patchcnt++;
+                       if (!check_table($pref, 'sys_prefs')) $patchcnt++;
+                       if (!check_table($pref, 'sales_orders', 'payment_terms')) $patchcnt++;
+               }
+               if (!check_table($pref, 'purch_orders', 'tax_included')) $patchcnt++;
+               return $n == $patchcnt ? true : ($patchcnt ? ($patchcnt.'/'. $n) : 0);
        }
        //=========================================================================================
        //      2.3 specific update functions
index 65f1ef4bf02741f797b9d9a41c74314e836a30c2..496144d054f2443e8c480e914c6e1aa77c9442ad 100644 (file)
@@ -247,3 +247,5 @@ INSERT INTO `0_crm_contacts` (`person_id`, `type`, `action`, `entity_id`)
 ALTER TABLE `0_debtor_trans_details` ADD COLUMN `src_id` int(11) default NULL;
 ALTER TABLE `0_debtor_trans_details` ADD KEY (`src_id`);
 ALTER TABLE `0_suppliers` ADD COLUMN `tax_included` tinyint(1) NOT NULL default '0' AFTER `payment_terms`;
+ALTER TABLE `0_supp_trans` ADD COLUMN `tax_included` tinyint(1) NOT NULL default '0';
+ALTER TABLE `0_purch_orders` ADD COLUMN `tax_included` tinyint(1) NOT NULL default '0';
index bdcfcb818c3ecfb52f4a2e510af1f57841e57d64..cd6fc5720ca0d0744949c4c0011b08127f36c88f 100644 (file)
@@ -1332,6 +1332,7 @@ CREATE TABLE IF NOT EXISTS `0_purch_orders` (
   `into_stock_location` varchar(5) NOT NULL default '',
   `delivery_address` tinytext NOT NULL,
   `total` double NOT NULL default '0',
+  `tax_included` tinyint(1) NOT NULL default '0',
   PRIMARY KEY  (`order_no`),
   KEY `ord_date` (`ord_date`)
 ) TYPE=InnoDB  AUTO_INCREMENT=3 ;
@@ -1340,8 +1341,8 @@ CREATE TABLE IF NOT EXISTS `0_purch_orders` (
 -- Dumping data for table `0_purch_orders`
 --
 
-INSERT INTO `0_purch_orders` VALUES(1, 2, '', '2009-06-01', '1', '', 'DEF', 'Delivery 1\nDelivery 2\nDelivery 3', 0);
-INSERT INTO `0_purch_orders` VALUES(2, 3, '', '2009-06-21', '2', '', 'DEF', 'Delivery 1\nDelivery 2\nDelivery 3', 0);
+INSERT INTO `0_purch_orders` VALUES(1, 2, '', '2009-06-01', '1', '', 'DEF', 'Delivery 1\nDelivery 2\nDelivery 3', 0, 0);
+INSERT INTO `0_purch_orders` VALUES(2, 3, '', '2009-06-21', '2', '', 'DEF', 'Delivery 1\nDelivery 2\nDelivery 3', 0, 0);
 
 -- --------------------------------------------------------
 
@@ -1975,6 +1976,7 @@ CREATE TABLE IF NOT EXISTS `0_supp_trans` (
   `ov_gst` double NOT NULL default '0',
   `rate` double NOT NULL default '1',
   `alloc` double NOT NULL default '0',
+  `tax_included` tinyint(1) NOT NULL default '0',
   PRIMARY KEY  (`type`,`trans_no`),
   KEY `supplier_id` (`supplier_id`),
   KEY `SupplierID_2` (`supplier_id`,`supp_reference`),
@@ -1986,9 +1988,9 @@ CREATE TABLE IF NOT EXISTS `0_supp_trans` (
 -- Dumping data for table `0_supp_trans`
 --
 
-INSERT INTO `0_supp_trans` VALUES(7, 20, 2, '1', '5t', '2009-06-21', '2009-07-01', 3300, 0, 165, 1, 3465);
-INSERT INTO `0_supp_trans` VALUES(8, 20, 2, '2', 'cc', '2009-06-21', '2009-07-01', 20, 0, 0, 1, 0);
-INSERT INTO `0_supp_trans` VALUES(4, 22, 2, '1', '', '2009-06-21', '2009-06-21', -3465, 0, 0, 1, 3465);
+INSERT INTO `0_supp_trans` VALUES(7, 20, 2, '1', '5t', '2009-06-21', '2009-07-01', 3300, 0, 165, 1, 3465, 0);
+INSERT INTO `0_supp_trans` VALUES(8, 20, 2, '2', 'cc', '2009-06-21', '2009-07-01', 20, 0, 0, 1, 0, 0);
+INSERT INTO `0_supp_trans` VALUES(4, 22, 2, '1', '', '2009-06-21', '2009-06-21', -3465, 0, 0, 1, 3465, 0);
 
 -- --------------------------------------------------------
 
index e2a761c87b69b7c0ce1b6d8c5e7da2722792e67d..078442bcdb3b0d8fad0a78b9029299dff24a7d12 100644 (file)
@@ -1165,6 +1165,7 @@ CREATE TABLE IF NOT EXISTS `0_purch_orders` (
   `into_stock_location` varchar(5) NOT NULL default '',
   `delivery_address` tinytext NOT NULL,
   `total` double NOT NULL default '0',
+  `tax_included` tinyint(1) NOT NULL default '0',
   PRIMARY KEY  (`order_no`),
   KEY `ord_date` (`ord_date`)
 ) TYPE=InnoDB AUTO_INCREMENT=1 ;
@@ -1739,6 +1740,7 @@ CREATE TABLE IF NOT EXISTS `0_supp_trans` (
   `ov_gst` double NOT NULL default '0',
   `rate` double NOT NULL default '1',
   `alloc` double NOT NULL default '0',
+  `tax_included` tinyint(1) NOT NULL default '0',
   PRIMARY KEY  (`type`,`trans_no`),
   KEY `supplier_id` (`supplier_id`),
   KEY `SupplierID_2` (`supplier_id`,`supp_reference`),