Small fixes to db upgrade for quotations
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 8 Sep 2009 14:27:24 +0000 (14:27 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 8 Sep 2009 14:27:24 +0000 (14:27 +0000)
sql/alter2.2.php
sql/alter2.2.sql

index 85a00be5ecc3eceda398d49ce72e6bdca6229393..21fa6822c7f5492f927e7a05739811b0e65c9c9d 100644 (file)
@@ -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;
        }
 };
 
index 25a406f1c7588d4ef8086f0b3ecf5ac84559cf91..486b1f50d758bb91d747662262a3231ad302aff5 100644 (file)
@@ -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