5 * Setup the core values in the database
10 require_once 'Pman/Core/UpdateDatabase.php';
11 class Pman_Xtuple_UpdateDatabase extends Pman_Core_UpdateDatabase
14 static $cli_desc = "Update SQL - Beta";
16 static $cli_opts = array(
18 'desc' => 'Source directory for json files.',
28 'desc' => 'Base Currency',
36 'json-accnt' => array(
37 'desc' => 'Accounts JSON file',
43 'json-curr-symbol' => array(
44 'desc' => 'Currency Symbols JSON file',
51 'json-location' => array(
52 'desc' => 'Location JSON file',
58 'json-terms' => array(
59 'desc' => 'Terms JSON file',
72 $ff = HTML_FlexyFramework::get();
73 if (!empty($ff->cli)) {
80 // called to ensure options are correct.
81 // before any data is imported / started..
82 function checkOpts($opts)
84 $opts = HTML_FlexyFramework::get()->page->opts;
86 (!empty($opts['init']) && empty($opts['base']) )
88 (empty($opts['init']) && !empty($opts['base']) )
91 die("--base=XXX and --init =1 must be used together.");
93 // default to import the terms.
95 (!empty($opts['init']) && empty($opts['json-terms']) ))
97 HTML_FlexyFramework::get()->page->opts['json-terms'] = dirname(__FILE__).'/Setup/terms.json';
106 function get($k = '',$opts)
112 require_once 'Pman/Core/UpdateDatabase.php';
114 Pman_Core_UpdateDatabase::jsonImportFromArray($opts);
116 $this->updateData($k);
120 function importModuleSQL($dburl)
123 $dbtype = $dburl['scheme'];
124 $dirmethod = 'import' . $dburl['scheme'] . '.dir';
127 echo "Xtyple:Importing SQL\n";
130 // if init has been called
131 // look in pgsql.ini -- This creates all the tables....
133 if (!empty($this->opts['init'])) {
134 // it should really use xtuple... but it's not very well organized...
135 //$this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
137 // ?? use dbscripts/misc/postbooks_empty.backup ???
138 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/Xtuple/xtuple-database/empty_data.sql");
139 //$this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
149 'public/trigger_functions',
156 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/Xtuple/xtuple-database/" . $dir);
159 // first try the standard from xtuple-database
162 // new -- sql directory..
163 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
164 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
168 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
169 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
173 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
174 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
176 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
177 $this->{'fixSequences'. $dbtype}();
184 function updateData($k='') {
185 //DB_DataObject::debugLevel(1);
186 $tables = empty($k) ? array(
188 // 'curr_symbol', //?? fixme
198 // accounts - fixme - we need a better 'base set'
199 // 'costcat' -- fixme - we need to init this..
203 // 'location', //?? just check hat one exists.
207 $core_opts = HTML_FlexyFramework::get()->page->opts;
208 if (!empty($core_opts['init'])) {
209 DB_DataObject::factory('curr_symbol')->setBase($this, $core_opts['base']);
215 foreach($tables as $t) {
216 $cs = DB_DataObject::factory($t);
217 $cs->initDatabase($this);
221 // update data is called from main
223 $this->updateMetricValue();
227 function updateMetricValue()
230 $d = DB_DataObject::Factory('shipvia');
231 if($d->get('shipvia_code', 'UPS-Ground')){
232 $metric = DB_DataObject::Factory('metric');
233 $metric->query("SELECT setmetric('DefaultShipViaId', '{$d->pid()}')");
236 $d = DB_DataObject::Factory('accnt');
237 if($d->get('accnt_descrip', 'Currency Gain Loss')){
238 $metric = DB_DataObject::Factory('metric');
239 $metric->query("SELECT setmetric('CurrencyGainLossAccount', '{$d->pid()}')");
242 $d = DB_DataObject::Factory('salesrep');
246 salesrep_number IS NOT NULL
248 salesrep_number != ''
250 $d->orderBy('salesrep_id ASC');
252 $metric = DB_DataObject::Factory('metric');
253 $metric->query("SELECT setmetric('DefaultSalesRep', '{$d->pid()}')");
256 $d = DB_DataObject::Factory('shipform');
257 $d->orderBy('shipform_id ASC');
259 $metric = DB_DataObject::Factory('metric');
260 $metric->query("SELECT setmetric('DefaultShipFormId', '{$d->pid()}')");