Fixed upgrade routines, reorganized db_export and company preferences related functions.
authorJanusz Dobrowolski <janusz@frontaccouting.eu>
Fri, 1 Apr 2011 13:45:14 +0000 (15:45 +0200)
committerJanusz Dobrowolski <janusz@frontaccouting.eu>
Fri, 1 Apr 2011 13:45:14 +0000 (15:45 +0200)
This removes problems with databases spread over multiply hosts and make possible db_export to
central backup directory.

admin/db/company_db.inc
admin/db/maintenance_db.inc
admin/inst_upgrade.php
purchasing/includes/db/po_db.inc
sql/alter2.1.php
sql/alter2.2.php
sql/alter2.3.php
sql/alter2.4.php

index 0fc0af275783fa487ed282d10a911bf634d2242d..fdb14a63b8590e110d5be377432a565ada94a26f 100644 (file)
@@ -12,9 +12,9 @@
 /*
        Update main or gl company setup.
 */
-function update_company_prefs( $params, $pref = TB_PREF )
+function update_company_prefs($params)
 {
-       $sql = "UPDATE {$pref}sys_prefs SET value = ";
+       $sql = "UPDATE ".TB_PREF."sys_prefs SET value = ";
        foreach($params as $name => $value) {
                if (!db_query($sql. db_escape($value). " WHERE name=".db_escape($name),
                         "The company prefferences could not be updated "))
@@ -30,7 +30,7 @@ function update_company_prefs( $params, $pref = TB_PREF )
        $prefs can be preference name, array of names, or null for all preferences.
        
 */
-function get_company_pref($prefs = null, $tbpref = null)
+function get_company_pref($prefs = null)
 {
        global $SysPrefs, $db_version;
        
@@ -38,10 +38,10 @@ function get_company_pref($prefs = null, $tbpref = null)
 
                $_SESSION['SysPrefs'] = new sys_prefs();
 
-               if (!isset($tbpref))
-                       $tbpref = TB_PREF;
+               if (!isset($company))
+                       $company = user_company();
 
-               $sql = "SELECT name, value FROM {$tbpref}sys_prefs";
+               $sql = "SELECT name, value FROM ".TB_PREF."sys_prefs";
                $result = @db_query($sql); // supress errors before 2.3 db structure upgrade
 
                if(!$result)
@@ -71,9 +71,9 @@ function get_company_pref($prefs = null, $tbpref = null)
                return $ret;
 }
 
-function get_company_prefs($tbpref = TB_PREF)
+function get_company_prefs()
 {
-       return get_company_pref(null, $tbpref);
+       return get_company_pref(null);
 }
 
 function set_company_pref($pref, $category, $type, $length, $value)
index 81fc0abc0f764f8c4d140a13ad3bca26ec65c17d..cf3d60134c7f96172cef6b4f866c18029d4a4b06 100644 (file)
@@ -431,23 +431,27 @@ function db_unzip($mode, $path)
        return explode("\n", $file_data);
 }
 
-function db_backup($conn, $ext='no', $comm='', $tbpref = TB_PREF)
+function db_backup($conn, $ext='no', $comm='', $path=null)
 {
        if ($conn['tbpref'] != "")
                $filename = $conn['dbname'] . "_" . $conn['tbpref'] . date("Ymd_Hi") . ".sql";
        else
                $filename = $conn['dbname'] . "_" . date("Ymd_Hi") . ".sql";
 
-       return db_export($conn, clean_file_name($filename), $ext, $comm, $tbpref);
+       if (!isset($path))
+               $path = BACKUP_PATH;
+
+       return db_export($conn, $path . clean_file_name($filename), $ext, $comm);
 }
 
 // generates a dump of $db database
 // $drop and $zip tell if to include the drop table statement or dry to pack
-function db_export($conn, $filename, $zip='no', $comment='', $tbpref = TB_PREF, $no_default=false)
+function db_export($conn, $filename, $zip='no', $comment='', $no_default=false)
 {
 
        global $app_title, $version, $power_url, $path_to_root;
 
+
     $error = false;
     // set max string size before writing to file
     $max_size = 1048576 * 2; // 2 MB
@@ -462,7 +466,7 @@ function db_export($conn, $filename, $zip='no', $comment='', $tbpref = TB_PREF,
        $backupfile = $filename . ".zip";
     else
        $backupfile = $filename;
-    $company = get_company_pref('coy_name', $tbpref);
+    $company = $conn['name']; // get_company_pref('coy_name');
 
     //create comment
     $out="# MySQL dump of database '".$conn["dbname"]."' on host '".$conn["host"]."'\n";
@@ -587,7 +591,7 @@ function db_export($conn, $filename, $zip='no', $comment='', $tbpref = TB_PREF,
                        }
                        elseif ($error)
                        {
-                               @unlink(BACKUP_PATH . $backupfile);
+                               @unlink($backupfile);
                                return false;
                        }
 
@@ -605,7 +609,7 @@ function db_export($conn, $filename, $zip='no', $comment='', $tbpref = TB_PREF,
        }
        else
        {
-               @unlink(BACKUP_PATH . $backupfile);
+               @unlink($backupfile);
                return false;
        }
 
@@ -617,7 +621,7 @@ function db_export($conn, $filename, $zip='no', $comment='', $tbpref = TB_PREF,
        }
        else
        {
-               @unlink(BACKUP_PATH . $backupfile);
+               @unlink($backupfile);
                return false;
        }
     return $backupfile;
@@ -674,13 +678,15 @@ function order_sql_tables($tables, $fks)
 
 // saves the string in $fileData to the file $backupfile as gz file or not ($zip)
 // returns backup file name if name has changed (zip), else TRUE. If saving failed, return value is FALSE
-function save_to_file($backupfile, $zip, $fileData)
+function save_to_file($path, $zip, $fileData)
 {
        global $path_to_root;
 
+       $backupfile = basename($path);
+
     if ($zip == "gzip")
     {
-        if ($zp = @gzopen(BACKUP_PATH . $backupfile, "a9"))
+        if ($zp = @gzopen($path, "a9"))
         {
                        @gzwrite($zp, $fileData);
                        @gzclose($zp);
@@ -757,7 +763,7 @@ function save_to_file($backupfile, $zip, $fileData)
         // total # of entries "on this disk", total # of entries overall, size of central dir, offset to start of central dir, .zip file comment length
         $fileData .= pack('v', 1) . pack('v', 1) . pack('V', strlen($cdrec)) . pack('V', strlen($fr)) . "\x00\x00";
 
-        if ($zp = @fopen(BACKUP_PATH . $backupfile, "a"))
+        if ($zp = @fopen($path, "a"))
         {
                        @fwrite($zp, $fileData);
                        @fclose($zp);
@@ -772,7 +778,7 @@ function save_to_file($backupfile, $zip, $fileData)
     }
     else
     {
-        if ($zp = @fopen(BACKUP_PATH . $backupfile, "a"))
+        if ($zp = @fopen($path, "a"))
         {
                        @fwrite($zp, $fileData);
                        @fclose($zp);
index 9691b22e0eedeb4aa15bf0f1bf2958d09031b11f..4e7e05b43309b0f6fb1c5ebd69d641712e843646 100644 (file)
@@ -52,7 +52,7 @@ function get_installers()
 //
 //     Apply one differential data set.
 //
-function upgrade_step($index, $conn) 
+function upgrade_step($index, $company, $conn) 
 {
        global $path_to_root, $installers;
 
@@ -75,7 +75,7 @@ function upgrade_step($index, $conn)
                        if ($sql != '')
                                $ret &= db_import($path_to_root.'/sql/'.$sql, $conn, $force);
 
-                       $ret &= $inst->install($pref, $force);
+                       $ret &= $inst->install($company, $force);
 
                        error_log(_("Database upgrade finished."));
 
@@ -104,11 +104,11 @@ if (get_post('Upgrade'))
                        continue;
                }
        // create security backup       
-               db_backup($conn, 'no', 'Security backup before upgrade', $conn['tbpref']);
+               db_backup($conn, 'no', 'Security backup before upgrade');
        // apply all upgrade data
                foreach ($installers as $i => $inst) 
                {
-                       $ret = upgrade_step($i, $conn);
+                       $ret = upgrade_step($i, $comp, $conn);
                        if (!$ret)
                                display_error(
                                sprintf(_("Database upgrade to version %s failed for company '%s'."),
index d8618fb590a6837482567d2d5aa52e8b5660b50b..fd34fef16f0d605fec0b63dd2018b66972206f0e 100644 (file)
@@ -123,8 +123,9 @@ function update_po(&$po_obj)
 
 function read_po_header($order_no, &$order)
 {
-       $sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name, ".TB_PREF."suppliers.tax_group_id,
-               ".TB_PREF."suppliers.curr_code, ".TB_PREF."locations.location_name, ".TB_PREF."suppliers.tax_algorithm
+       $sql = "SELECT ".TB_PREF."purch_orders.*, "
+               .TB_PREF."suppliers.*, "
+               .TB_PREF."locations.location_name 
                FROM ".TB_PREF."purch_orders, ".TB_PREF."suppliers, ".TB_PREF."locations
                WHERE ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
                AND ".TB_PREF."locations.loc_code = into_stock_location
@@ -141,7 +142,7 @@ function read_po_header($order_no, &$order)
        $order->order_no = $order_no;
        
        $order->set_supplier($myrow["supplier_id"], $myrow["supp_name"], $myrow["curr_code"],
-               $myrow['tax_group_id'], $myrow["tax_included"], $myrow["tax_algorithm"]);
+               $myrow['tax_group_id'], $myrow["tax_included"], @$myrow["tax_algorithm"]);
 
                $order->credit = get_current_supp_credit($order->supplier_id);
 
index ff9467a292f4fa1e3446f3008e5cfa7a3c3d3335..869186ac0cd4d671cea0c3dd13592474870124c7 100644 (file)
@@ -21,23 +21,24 @@ class fa2_1 {
        //      Install procedure. All additional changes 
        //      not included in sql file should go here.
        //
-       function install($pref, $force) 
+       function install($company, $force) 
        {
                global $db;
+
        /*
        Statement below is allowed only for MySQL >=4.0.4:
        UPDATE `0_bank_trans`, `0_bank_accounts` 
                SET 0_bank_trans.bank_act=0_bank_accounts.id 
                WHERE 0_bank_trans.bank_act=0_bank_accounts.account_code;
        */
-               $sql = "SELECT id, account_code FROM ".$pref."bank_accounts";
+               $sql = "SELECT id, account_code FROM ".TB_PREF."bank_accounts";
                if(!($res = db_query($sql))) {
                        display_error(_("Cannot retrieve bank accounts codes")
                                .':<br>'. db_error_msg($db));
                        return false;
                }
                while ($acc = db_fetch($res)) {
-                       $sql = "UPDATE ".$pref."bank_trans SET bank_act='"
+                       $sql = "UPDATE ".TB_PREF."bank_trans SET bank_act='"
                                .$acc['id']."' WHERE bank_act=".$acc['account_code'];
                        if (db_query($sql)==false) {
                        display_error(_("Cannot update bank transactions")
@@ -46,7 +47,7 @@ class fa2_1 {
                        }
                }
                // copy all item codes from stock_master into item_codes
-               $sql = "SELECT `stock_id`,`description`,`category_id` FROM ".$pref."stock_master";
+               $sql = "SELECT `stock_id`,`description`,`category_id` FROM ".TB_PREF."stock_master";
                $result = db_query($sql);
                if (!$result) {
                        display_error(_("Cannot select stock identificators")
@@ -55,7 +56,7 @@ class fa2_1 {
                } else {
                        while ($row = db_fetch_assoc($result)) {
                                $sql = "INSERT IGNORE "
-                                       .$pref."item_codes (`item_code`,`stock_id`,`description`,`category_id`)
+                                       .TB_PREF."item_codes (`item_code`,`stock_id`,`description`,`category_id`)
                                        VALUES('".$row['stock_id']."','".$row['stock_id']."','"
                                        .$row['description']."','".$row['category_id']."')";
                                $res2 = db_query($sql);
@@ -81,11 +82,11 @@ class fa2_1 {
                "SELECT tr.tran_date, tr.type, tr.trans_no, dt.tax_type_id, 
                        dt.rate, dt.included_in_price, dt.amount, tr.reference as ref,
                        tr.rate as ex_rate
-               FROM ".$pref."debtor_trans_tax_details dt       
-                       LEFT JOIN ".$pref."trans_tax_details tt
+               FROM ".TB_PREF."debtor_trans_tax_details dt     
+                       LEFT JOIN ".TB_PREF."trans_tax_details tt
                                ON dt.debtor_trans_no=tt.trans_no 
                                AND dt.debtor_trans_type=tt.trans_type,
-                       ".$pref."debtor_trans tr
+                       ".TB_PREF."debtor_trans tr
                WHERE tt.trans_type is NULL
                        AND dt.debtor_trans_no = tr.trans_no 
                        AND dt.debtor_trans_type = tr.type",
@@ -94,8 +95,8 @@ class fa2_1 {
                "SELECT tr.tran_date, tr.type, tr.trans_no, st.tax_type_id, 
                        st.rate, st.included_in_price, st.amount, tr.supp_reference as ref,
                        tr.rate as ex_rate
-                       FROM ".$pref."supp_invoice_tax_items st 
-                               LEFT JOIN ".$pref."trans_tax_details tt
+                       FROM ".TB_PREF."supp_invoice_tax_items st       
+                               LEFT JOIN ".TB_PREF."trans_tax_details tt
                                        ON st.supp_trans_no=tt.trans_no 
                                        AND st.supp_trans_type=tt.trans_type,
                                        ".$pref."supp_trans tr
@@ -104,14 +105,14 @@ class fa2_1 {
                                        AND st.supp_trans_type = tr.type");
 
        foreach ($move_sql as $tbl => $sql) {
-               if (!check_table($pref, $tbl)){
+               if (!check_table(TB_PREF, $tbl)){
                        $res = db_query($sql, "Cannot retrieve trans tax details from $tbl");
                        while ($row = db_fetch($res)) {
                                $net_amount = $row['rate'] == 0 ?
                                        0 : ($row['included_in_price'] ? 
                                                        ($row['amount']/$row['rate']*(100-$row['rate']))
                                                        :($row['amount']/$row['rate']*100));
-                               $sql2 = "INSERT INTO ".$pref."trans_tax_details 
+                               $sql2 = "INSERT INTO ".TB_PREF."trans_tax_details 
                                (trans_type,trans_no,tran_date,tax_type_id,rate,ex_rate,
                                        included_in_price, net_amount, amount, memo)
                                VALUES ('".$row['type']."','".$row['trans_no']."','"
@@ -121,7 +122,7 @@ class fa2_1 {
                                        ."','".$row['amount']."','".$row['ref']."')";
                                db_query($sql2, "Cannot move trans tax details from $tbl");
                        }
-                       db_query("DROP TABLE ".$pref.$tbl, "cannot remove $tbl");
+                       db_query("DROP TABLE ".TB_PREF.$tbl, "cannot remove $tbl");
                }
        }
                
index c5345233f9dad968a351735b71f50b2df0a31924..ee1fca7bec6a92bf21cdcf2bc722272f39359db6 100644 (file)
@@ -28,13 +28,14 @@ class fa2_2 {
        //      Install procedure. All additional changes 
        //      not included in sql file should go here.
        //
-       function install($pref, $force) 
+       function install($company, $force) 
        {
-               global $db, $systypes_array;
+               global $db, $systypes_array, $db_connections;
                
                if (!$this->preconf)
                        return false;
 
+               $pref = $db_connections[$company]['tbpref'];
                // Until 2.2 sanitizing text input with db_escape was not
                // consequent enough. To avoid comparision problems we have to 
                // fix this now.
@@ -45,7 +46,7 @@ class fa2_2 {
 
                // set item category dflt accounts to values from company GL setup
                $prefs = get_company_prefs();
-               $sql = "UPDATE {$pref}stock_category SET "
+               $sql = "UPDATE ".TB_PREF."stock_category SET "
                        ."dflt_sales_act = '" . $prefs['default_inv_sales_act'] . "',"
                        ."dflt_cogs_act = '". $prefs['default_cogs_act'] . "',"
                        ."dflt_inventory_act = '" . $prefs['default_inventory_act'] . "',"
@@ -60,14 +61,14 @@ class fa2_2 {
                foreach($systypes_array as $typeno => $typename) {
                        $info = get_systype_db_info($typeno);
                        if ($info == null || $info[3] == null) continue;
-                       $tbl = str_replace(TB_PREF, $pref, $info[0]);
+                       $tbl = $info[0];
                        $sql = "SELECT DISTINCT {$info[2]} as id,{$info[3]} as ref FROM $tbl";
                        if ($info[1])
                                $sql .= " WHERE {$info[1]}=$typeno";
                        $result = db_query($sql);
                        if (db_num_rows($result)) {
                                while ($row = db_fetch($result)) {
-                                       $res2 = db_query("INSERT INTO {$pref}refs VALUES("
+                                       $res2 = db_query("INSERT INTO ".TB_PREF."refs VALUES("
                                                . $row['id'].",".$typeno.",'".$row['ref']."')");
                                        if (!$res2) {
                                                display_error(_("Cannot copy references from $tbl")
@@ -78,7 +79,7 @@ class fa2_2 {
                        }
                }
 
-               if (!($ret = db_query("SELECT MAX(`order_no`) FROM `{$pref}sales_orders`")) ||
+               if (!($ret = db_query("SELECT MAX(`order_no`) FROM `".TB_PREF."sales_orders`")) ||
                        !db_num_rows($ret))
                {
                                display_error(_('Cannot query max sales order number.'));
@@ -87,7 +88,7 @@ class fa2_2 {
                $row = db_fetch($ret);
                $max_order = $row[0];
                $next_ref = $max_order+1;
-               $sql = "UPDATE `{$pref}sys_types` 
+               $sql = "UPDATE `".TB_PREF."sys_types` 
                        SET `type_no`='$max_order',`next_reference`='$next_ref'
                        WHERE `type_id`=30";
                if(!db_query($sql))
@@ -118,9 +119,13 @@ class fa2_2 {
                $patchcnt = 0;
                if (!$this->beta) {
                        $n = 16;
-                       if (check_table($pref, 'company', 'custom1_name')) $patchcnt++;
-                       if (!check_table($pref, 'company', 'profit_loss_year_act')) $patchcnt++;
-                       if (!check_table($pref, 'company', 'login_tout')) $patchcnt++;
+                       if (check_table($pref, 'company')) // skip in 2.3
+                               $n -= 3;
+                       else {
+                               if (check_table($pref, 'company', 'custom1_name')) $patchcnt++;
+                               if (!check_table($pref, 'company', 'profit_loss_year_act'))     $patchcnt++;
+                               if (!check_table($pref, 'company', 'login_tout')) $patchcnt++;
+                       }
                        if (!check_table($pref, 'stock_category', 'dflt_no_sale')) $patchcnt++;
                        if (!check_table($pref, 'users', 'sticky_doc_date')) $patchcnt++;
                        if (!check_table($pref, 'users', 'startup_tab')) $patchcnt++;
@@ -205,7 +210,7 @@ function convert_roles($pref)
                        }
                        $sections  = array_keys($sections);
                        sort($sections); sort($area_set);
-                       import_security_role($pref, $security_headings[$role_id], $sections, $area_set);
+                       import_security_role($security_headings[$role_id], $sections, $area_set);
                        $new_ids[$role_id] = db_insert_id();
                }
                $result = get_users(true);
@@ -215,7 +220,7 @@ function convert_roles($pref)
                }
                foreach($users as $old_id => $uids)
                        foreach( $uids as $id) {
-                               $sql = "UPDATE {$pref}users set role_id=".$new_ids[$old_id].
+                               $sql = "UPDATE ".TB_PREF."users set role_id=".$new_ids[$old_id].
                                        " WHERE id=$id";
                                $ret = db_query($sql, 'cannot update users roles');
                                if(!$ret) return false;
@@ -223,9 +228,9 @@ function convert_roles($pref)
                return true;
 }
 
-function import_security_role($pref, $name, $sections, $areas)
+function import_security_role($name, $sections, $areas)
 {
-       $sql = "INSERT INTO {$pref}security_roles (role, description, sections, areas)
+       $sql = "INSERT INTO ".TB_PREF."security_roles (role, description, sections, areas)
        VALUES (".db_escape('FA 2.1 '.$name).",".db_escape($name).","
        .db_escape(implode(';',$sections)).",".db_escape(implode(';',$areas)).")";
 
@@ -303,6 +308,9 @@ function sanitize_database($pref, $test = false) {
                        }
                }
 
+               if (empty($keys)) { // comments table have no primary key, so give up
+                       continue;
+               }
                if ($test)
                        error_log("Table $table (".implode(',',$keys)."):(".implode(',',$textcols)."):");
 
index bdeab5c67c88f6374160729bbe82c2818b9a1692..c4071f974556e360b71ac35b89a27b7c2c0f5aaf 100644 (file)
@@ -24,7 +24,7 @@ class fa2_3 {
        //      Install procedure. All additional changes 
        //      not included in sql file should go here.
        //
-       function install($pref, $force) 
+       function install($company, $force) 
        {
                global $db_version, $dflt_lang;
 
@@ -34,7 +34,7 @@ class fa2_3 {
                if (!$this->beta) {
                        // all specials below are already done on 2.3beta
 
-                       $sql = "SELECT debtor_no, payment_terms FROM {$pref}debtors_master";
+                       $sql = "SELECT debtor_no, payment_terms FROM ".TB_PREF."debtors_master";
                
                        $result = db_query($sql);
                        if (!$result) {
@@ -44,7 +44,7 @@ class fa2_3 {
                        }
                        // update all sales orders and transactions with customer std payment terms
                        while($cust = db_fetch($result)) {
-                               $sql = "UPDATE {$pref}debtor_trans SET "
+                               $sql = "UPDATE ".TB_PREF."debtor_trans SET "
                                        ."payment_terms = '" .$cust['payment_terms']
                                        ."' WHERE debtor_no='".$cust['debtor_no']."'";
                                if (db_query($sql)==false) {
@@ -52,7 +52,7 @@ class fa2_3 {
                                        .':<br>'. db_error_msg($db));
                                        return false;
                                }
-                               $sql = "UPDATE {$pref}sales_orders SET "
+                               $sql = "UPDATE ".TB_PREF."sales_orders SET "
                                        ."payment_terms = '" .$cust['payment_terms']
                                        ."' WHERE debtor_no='".$cust['debtor_no']."'";
                                if (db_query($sql)==false) {
@@ -61,11 +61,11 @@ class fa2_3 {
                                        return false;
                                }
                        }
-                       if (!$this->update_totals($pref)) {
+                       if (!$this->update_totals()) {
                                display_error("Cannot update order totals");
                                return false;
                        }
-                       if (!$this->update_line_relations($pref)) {
+                       if (!$this->update_line_relations()) {
                                display_error("Cannot update sales document links");
                                return false;
                        }
@@ -81,18 +81,18 @@ class fa2_3 {
 
                        foreach($dropcol as $table => $columns)
                                foreach($columns as $col) {
-                                       if (db_query("ALTER TABLE `{$pref}{$table}` DROP `$col`")==false) {
+                                       if (db_query("ALTER TABLE `".TB_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`";
+                       $sql = "DROP TABLE IF EXISTS `".TB_PREF."company`";
                        if (!db_query($sql))
                                return false;
                }
                $this->update_lang_cfg();
-               return  update_company_prefs(array('version_id'=>$db_version), $pref);
+               return  update_company_prefs(array('version_id'=>$db_version));
        }
        //
        //      Checking before install
@@ -131,33 +131,33 @@ class fa2_3 {
        /*
                Update order totals
        */
-       function update_totals($pref)
+       function update_totals()
        {
                global $path_to_root;
 
                include_once("$path_to_root/sales/includes/cart_class.inc");
                include_once("$path_to_root/purchasing/includes/po_class.inc");
                $cart = new cart(ST_SALESORDER);
-               $sql = "SELECT order_no, trans_type FROM {$pref}sales_orders";
+               $sql = "SELECT order_no, trans_type FROM ".TB_PREF."sales_orders";
                $orders = db_query($sql);
                if (!$orders)
                        return false;
                while ($order = db_fetch($orders)) {
                        read_sales_order($order['order_no'], $cart, $order['trans_type']);
-                       $result = db_query("UPDATE {$pref}sales_orders 
+                       $result = db_query("UPDATE ".TB_PREF."sales_orders 
                                SET total=".$cart->get_trans_total()
                                ." WHERE order_no=".$order[0]);
                        unset($cart->line_items);
                }
                unset($cart);
                $cart = new purch_order();
-               $sql = "SELECT order_no FROM {$pref}purch_orders";
+               $sql = "SELECT order_no FROM ".TB_PREF."purch_orders";
                $orders = db_query($sql);
                if (!$orders)
                         return false;
                while ($order_no = db_fetch($orders)) {
                        read_po($order_no[0], $cart);
-                       $result = db_query("UPDATE {$pref}purch_orders SET total=".$cart->get_trans_total());
+                       $result = db_query("UPDATE ".TB_PREF."purch_orders SET total=".$cart->get_trans_total());
                        unset($cart->line_items);
                }
                return true;
@@ -200,14 +200,14 @@ class fa2_3 {
                there can be sales documents with lines not properly linked to parents. This rare 
                cases will be described in error log.
        */
-       function update_line_relations($pref)
+       function update_line_relations()
        {
                global $path_to_root, $systypes_array;
 
                require_once("$path_to_root/includes/sysnames.inc");
                
-               $sql =  "SELECT d.type, trans_no, order_ FROM {$pref}debtor_trans d
-                       LEFT JOIN {$pref}voided v ON d.type=v.type AND d.trans_no=v.id
+               $sql =  "SELECT d.type, trans_no, order_ FROM ".TB_PREF."debtor_trans d
+                       LEFT JOIN ".TB_PREF."voided v ON d.type=v.type AND d.trans_no=v.id
                                WHERE ISNULL(v.type) AND 
                                (d.type=".ST_CUSTDELIVERY
                                ." OR d.type=".ST_SALESINVOICE
@@ -251,7 +251,7 @@ class fa2_3 {
                                if ($src_line['stock_id'] == $doc_line['stock_id']
                                        && ($src_line['quantity'] >= $doc_line['quantity'])) {
 
-                                       $sql = "UPDATE {$pref}debtor_trans_details SET src_id = {$src_line['id']}
+                                       $sql = "UPDATE ".TB_PREF."debtor_trans_details SET src_id = {$src_line['id']}
                                                WHERE id = {$doc_line['id']}";
                                        if (!db_query($sql))
                                                return false;
index 2ef35175870e919627f5dc6e6a1fdf7e69602353..898c566ac36c68e76e7f9f34e73d0e3019858f38 100644 (file)
@@ -23,7 +23,7 @@ class fa2_4 {
        //      Install procedure. All additional changes 
        //      not included in sql file should go here.
        //
-       function install($pref, $force) 
+       function install($company, $force) 
        {
                global $db_version;
                
@@ -31,7 +31,7 @@ class fa2_4 {
                        set_company_pref('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, 0);
                }
                if ($this->update_workorders())
-//             return  update_company_prefs(array('version_id'=>$db_version), $pref);
+//             return  update_company_prefs(array('version_id'=>$db_version));
                return true;
        }
        //