Cleanup, $SysPrefs.
[fa-stable.git] / sql / alter2.4.php
index c065ce057820c73771940f7df9c1501caf479da8..481ea817756507284cb1c66328abc1402b61b21f 100644 (file)
@@ -32,10 +32,21 @@ class fa2_4 {
                if (get_company_pref('grn_clearing_act') === null) { // available form 2.3.1, can be not defined on pre-2.4 installations
                        set_company_pref('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, 0);
                }
-               if (get_company_pref('default_receival_required') === null) { // new in 2.4 installations
-                       set_company_pref('default_receival_required', 'glsetup.purchase', 'smallint', 6, 10);
+               if (get_company_pref('default_quote_valid_days') === null) { // new in 2.3.23 installations
+                       set_company_pref('default_quote_valid_days', 'glsetup.sales', 'smallint', 6, 30);
                }
-               $result = $this->update_workorders() && $this->switch_database_to_utf($pref);
+               if (get_company_pref('bcc_email') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations
+                       set_company_pref('bcc_email', 'setup.company', 'varchar', 100, '');
+               }
+               if (get_company_pref('alternative_tax_include_on_docs') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations
+                       set_company_pref('alternative_tax_include_on_docs', 'setup.company', 'tinyint', 1, '0');
+               }
+               if (get_company_pref('suppress_tax_rates') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations
+                       set_company_pref('suppress_tax_rates', 'setup.company', 'tinyint', 1, '0');
+               }
+
+               $result = $this->update_workorders()  && $this->update_grn_rates() && $this->switch_database_to_utf($pref);
+
                if ($result)
                        $result = $this->do_cleanup();
 
@@ -178,6 +189,23 @@ class fa2_4 {
                return true;
        }
 
+       function update_grn_rates()
+       {
+               $sql = "SELECT grn.id, grn.delivery_date, supp.curr_code 
+                       FROM ".TB_PREF."grn_batch grn, ".TB_PREF."suppliers supp
+                       WHERE supp.supplier_id=grn.supplier_id AND supp.curr_code!='".get_company_pref('curr_default')."'";
+               $result = db_query($sql);
+
+               if (!$result)
+                       return false;
+
+               $sql = "UPDATE ".TB_PREF."grn_batch SET rate=%s WHERE id=%d";
+               while ($grn = db_fetch($result))
+                       db_query(sprintf($sql, get_exchange_rate_from_home_currency($grn['curr_code'], sql2date($grn['delivery_date'])), $grn['id']));
+
+               return true;
+       }
+
        function do_cleanup()
        {
                $dropcol = array(