*
*/
-require_once 'Pman.php';
-class Pman_Xtuple_UpdateDatabase extends Pman
+require_once 'Pman/Core/UpdateDatabase.php';
+class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
{
static $cli_desc = "Update SQL - Beta";
}
- function get($k = '',$opts)
+ function get($k = '',$opts=array())
{
$k = strtolower($k);
}
+ function importModuleSQL($dburl)
+ {
+
+ $dbtype = $dburl['scheme'];
+ $dirmethod = 'import' . $dburl['scheme'] . 'dir';
+
+ $m = 'Xtuple';
+ echo "Xtyple:Importing SQL\n";
+
+
+ // if init has been called
+ // look in pgsql.ini -- This creates all the tables....
+
+ if (!empty($this->opts['init'])) {
+ // it should really use xtuple... but it's not very well organized...
+ //$this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
+
+ // ?? use dbscripts/misc/postbooks_empty.backup ???
+
+ $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/440_schema.sql");
+
+ foreach(array(
+ 'public/types',
+ 'public/tables',
+ 'public/views',
+ 'public/functions',
+ 'public/trigger_functions',
+ 'public/indexes',
+ 'api/functions',
+ 'api/views',
+
+
+ ) as $dir) {
+ $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/Xtuple/xtuple-database/" . $dir);
+ }
+ */
+ // first try the standard from xtuple-database
+
+
+ // new -- sql directory..
+ // new style will not support migrate ... they have to go into mysql-migrate.... directories..
+ // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
+
+
+
+
+ $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
+
+
+
+ if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
+ HTML_FlexyFramework::get()->generateDataobjectsCache(true);
+
+ $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
+ // fixSequences does nto appar to work on postgres anymore
+ //$this->{'fixSequences'. $dbtype}();
+
+ }
+
+ }
-
- function updateData($k='') {
+ function updateData($k='')
+ {
+ $ff = HTML_Flexyframework::get();
+ $dburl = parse_url($ff->DB_DataObject['database']);
+
+
+// $this->importpgsqldir($dburl, $this->rootDir. "/Pman/Xtuple/xtuple-database/empty_data.sql");
+
//DB_DataObject::debugLevel(1);
$tables = empty($k) ? array(
'taxzone',
'taxtype',
'expcat',
- 'salesrep',
+
+ '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..
// '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']);
}
$this->updateMetricValue();
+ $this->addAccounts();
+
+
+
}
function updateMetricValue()
{
- $d = DB_DataObject::Factory('custtype');
- if($d->get('custtype_code', 'NORMAL')){
+ $d = DB_DataObject::Factory('shipvia');
+ if($d->get('shipvia_code', 'UPS-Ground')){
+ $metric = DB_DataObject::Factory('metric');
+ $metric->query("SELECT setmetric('DefaultShipViaId', '{$d->pid()}')");
+ }
+
+ $d = DB_DataObject::Factory('accnt');
+ if($d->get('accnt_descrip', 'Currency Gain Loss')){
$metric = DB_DataObject::Factory('metric');
- $metric->query("SELECT setmetric('DefaultCustType', '{$d->pid()}')");
+ $metric->query("SELECT setmetric('CurrencyGainLossAccount', '{$d->pid()}')");
}
$d = DB_DataObject::Factory('salesrep');
salesrep_active
AND
salesrep_number IS NOT NULL
+ AND
+ salesrep_number != ''
");
$d->orderBy('salesrep_id ASC');
-
if($d->find(true)){
$metric = DB_DataObject::Factory('metric');
$metric->query("SELECT setmetric('DefaultSalesRep', '{$d->pid()}')");
}
+
+ $d = DB_DataObject::Factory('shipform');
+ $d->orderBy('shipform_id ASC');
+ if($d->find(true)){
+ $metric = DB_DataObject::Factory('metric');
+ $metric->query("SELECT setmetric('DefaultShipFormId', '{$d->pid()}')");
+ }
+
+ }
+
+
+
+
+
+
+ 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