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()
123 echo "Importing SQL from module $m\n";
125 $dirmethod = 'importpgsqldir';
127 // if init has been called
129 if (!empty($this->opts['init'])) {
130 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
136 $fd = $this->rootDir. "/Pman/$m/DataObjects";
138 $this->{$dirmethod}($dburl, $fd);
140 // new -- sql directory..
141 // new style will not support migrate ... they have to go into mysql-migrate.... directories..
142 // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
144 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
145 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
149 if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
150 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
152 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
153 $this->{'fixSequences'. $dbtype}();
160 function updateData($k='') {
161 //DB_DataObject::debugLevel(1);
162 $tables = empty($k) ? array(
164 // 'curr_symbol', //?? fixme
174 // accounts - fixme - we need a better 'base set'
175 // 'costcat' -- fixme - we need to init this..
179 // 'location', //?? just check hat one exists.
183 $core_opts = HTML_FlexyFramework::get()->page->opts;
184 if (!empty($core_opts['init'])) {
185 DB_DataObject::factory('curr_symbol')->setBase($this, $core_opts['base']);
191 foreach($tables as $t) {
192 $cs = DB_DataObject::factory($t);
193 $cs->initDatabase($this);
197 // update data is called from main
199 $this->updateMetricValue();
203 function updateMetricValue()
206 $d = DB_DataObject::Factory('shipvia');
207 if($d->get('shipvia_code', 'UPS-Ground')){
208 $metric = DB_DataObject::Factory('metric');
209 $metric->query("SELECT setmetric('DefaultShipViaId', '{$d->pid()}')");
212 $d = DB_DataObject::Factory('accnt');
213 if($d->get('accnt_descrip', 'Currency Gain Loss')){
214 $metric = DB_DataObject::Factory('metric');
215 $metric->query("SELECT setmetric('CurrencyGainLossAccount', '{$d->pid()}')");
218 $d = DB_DataObject::Factory('salesrep');
222 salesrep_number IS NOT NULL
224 salesrep_number != ''
226 $d->orderBy('salesrep_id ASC');
228 $metric = DB_DataObject::Factory('metric');
229 $metric->query("SELECT setmetric('DefaultSalesRep', '{$d->pid()}')");
232 $d = DB_DataObject::Factory('shipform');
233 $d->orderBy('shipform_id ASC');
235 $metric = DB_DataObject::Factory('metric');
236 $metric->query("SELECT setmetric('DefaultShipFormId', '{$d->pid()}')");