Fix #7123 - getting abra ready to test
[Pman.Xtuple] / UpdateDatabase.php
index 745593c..91b91e5 100644 (file)
@@ -103,7 +103,7 @@ class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
     }
     
     
-    function get($k = '',$opts)
+    function get($k = '',$opts=array())
     {
         $k = strtolower($k);
         
@@ -136,11 +136,12 @@ class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
                 
                 // ?? use dbscripts/misc/postbooks_empty.backup ???
                 
-                //$this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
+                $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
                 
             }
+            /*
             // let's see if this works.. -- not very flexible... - hardcoding schema...
-            $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/Xtuple/xtuple-database/404_schema.sql");
+            $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/Xtuple/xtuple-database/440_schema.sql");
             
             foreach(array(
                 'public/types',
@@ -156,7 +157,7 @@ class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
             ) as $dir) {
                 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/Xtuple/xtuple-database/" . $dir);   
             }
-            
+            */
             // first try the standard from xtuple-database
             
             
@@ -175,7 +176,8 @@ class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
                 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
                 
                 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
-                $this->{'fixSequences'. $dbtype}();
+                // fixSequences does nto appar to work on postgres anymore
+                //$this->{'fixSequences'. $dbtype}();
                 
             }
               
@@ -188,7 +190,7 @@ class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
         $dburl = parse_url($ff->DB_DataObject['database']);
        
         
-        $this->importpgsqldir($dburl, $this->rootDir. "/Pman/Xtuple/xtuple-database/empty_data.sql");
+//        $this->importpgsqldir($dburl, $this->rootDir. "/Pman/Xtuple/xtuple-database/empty_data.sql");
         
         //DB_DataObject::debugLevel(1);
         $tables = empty($k) ? array(
@@ -203,6 +205,11 @@ class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
                 'taxzone',
                 'taxtype',
                 'expcat',
+                
+                'custinfo', // create a base customer based on company.
+                'location', // default warehouse.
+                'period', // adds years and months -1 to +10 from now.
+                
                 // accounts - fixme - we need a better 'base set'
                 // 'costcat' -- fixme - we need to init this..
             
@@ -211,9 +218,11 @@ class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
 //                'location', //?? just check hat one exists.
         ) : array($k);
         
-        
-        $core_opts = HTML_FlexyFramework::get()->page->opts;
-        if (!empty($core_opts['init'])) {
+         $core_opts = HTML_FlexyFramework::get()->page->opts;
+         
+         if (!empty($core_opts['base'])) {
+            DB_DataObject::DebugLevel(1);
+            DB_DataObject::factory('curr_symbol')->importFromArray($this, array($core_opts['base']));
             DB_DataObject::factory('curr_symbol')->setBase($this, $core_opts['base']);
         }
         
@@ -230,6 +239,10 @@ class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
         
         $this->updateMetricValue();
         
+        $this->addAccounts();
+         
+        
+        
     }
     
     function updateMetricValue()
@@ -271,4 +284,31 @@ class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
     }
     
     
+    
+     
+    
+     
+    function addAccounts()
+    {
+        $ac = DB_DataObject::factory('accnt');
+        if ($ac->count()) {
+            return;
+        }
+        
+        // this might want to be configurable -- so that we could use different 'base files' for the accounts..
+        require_once 'File/Convert.php';
+        $cp = $this->tempName('xls');
+        copy(dirname(__FILE__).'/Setup/accounts_sample.xls', $cp);
+        $fc = new File_Convert($cp, 'application/vnd.ms-excel');
+        //var_Dump($img->getStoreName());
+        $csv = $fc->convert('text/csv');
+        unlink($cp);
+        //var_dump($csv);
+        require_once 'Pman/Xtuple/Import/Accounts.php';
+        $ia = new Pman_Xtuple_Import_Accounts();
+        $ia->importCsv($csv);
+    }
+    
+   
+    
 }
\ No newline at end of file