References saved in refs table for all documents for easy access.
[fa-stable.git] / sql / alter2.2.php
index bcd772e1251b8408091f18441f72e8b132705cca..7a4cf751a89f99df0560bbe303ce9734dbf409d4 100644 (file)
@@ -19,7 +19,7 @@ class fa2_2 {
        //
        function install($pref, $force) 
        {
-               global $db;
+               global $db, $systypes_array;
                // set item category dflt accounts to values from company GL setup
                $prefs = get_company_prefs();
                $sql = "UPDATE {$pref}stock_category SET "
@@ -28,8 +28,41 @@ class fa2_2 {
                        ."dflt_inventory_act = '" . $prefs['default_inventory_act'] . "',"
                        ."dflt_adjustment_act = '" . $prefs['default_adj_act'] . "',"
                        ."dflt_assembly_act = '" . $prefs['default_assembly_act']."'";
-               $ret = db_query($sql, "Cannot update category default GL accounts");
-               return $ret;
+               if (db_query($sql)==false) {
+                       display_error("Cannot update category default GL accounts"
+                       .':<br>'. db_error_msg($db));
+                       return false;
+               }
+               // add all references to refs table for easy searching via journal interface
+               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]);
+                       $sql = "SELECT {$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("
+                                               . $row['id'].",".$typeno.",'".$row['ref']."')");
+                                       if (!$res2) {
+                                               display_error(_("Cannot copy references from $tbl")
+                                                       .':<br>'. db_error_msg($db));
+                                               return false;
+                                       }
+                               }
+                       }
+               }
+/*     FIX
+               // add audit_trail data for all transactions
+               $datatbl = array ("gl_trans", "purch_orders", "sales_orders",
+                       "workorders");
+               $sql = "INSERT INTO ".$pref."audit_trail"
+               ." (type, trans_no, user, fiscal_year, gl_date) VALUES ("
+               . "$type,$trans_no,$user,$year,$date)";
+*/
+               return true;
        }
        //
        //      Checking before install
@@ -45,7 +78,8 @@ class fa2_2 {
                if (check_table($pref, 'company', 'default_delivery_required')) return false;
                if (check_table($pref, 'stock_category', 'dflt_dim2')) return false;
                if (check_table($pref, 'users', 'sticky_doc_date')) return false;
-               return true;
+               if (check_table($pref, 'audit_trail')) return false;
+                       return true;
        }
 };