5 * Setup the core values in the database
10 require_once 'Pman.php';
11 class Pman_Xtuple_UpdateDatabase extends Pman
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);
123 function updateData($k='') {
124 //DB_DataObject::debugLevel(1);
125 $tables = empty($k) ? array(
127 // 'curr_symbol', //?? fixme
138 // accounts - fixme - we need a better 'base set'
139 // 'costcat' -- fixme - we need to init this..
143 // 'location', //?? just check hat one exists.
147 $core_opts = HTML_FlexyFramework::get()->page->opts;
148 if (!empty($core_opts['init'])) {
149 DB_DataObject::factory('curr_symbol')->setBase($this, $core_opts['base']);
155 foreach($tables as $t) {
156 $cs = DB_DataObject::factory($t);
157 $cs->initDatabase($this);
161 // update data is called from main
163 $this->updateMetricValue();
167 function updateMetricValue()
170 $d = DB_DataObject::Factory('custtype');
171 if($d->get('custtype_code', 'NORMAL')){
172 $metric = DB_DataObject::Factory('metric');
173 $metric->query("SELECT setmetric('DefaultCustType', '{$d->pid()}')");
176 $d = DB_DataObject::Factory('salesrep');
180 salesrep_number IS NOT NULL
182 $d->orderBy('salesrep_id ASC');
185 $metric = DB_DataObject::Factory('metric');
186 $metric->query("SELECT setmetric('DefaultSalesRep', '{$d->pid()}')");
189 $d = DB_DataObject::Factory('shipform');
190 $d->orderBy('shipform_id ASC');
192 $metric = DB_DataObject::Factory('metric');
193 $metric->query("SELECT setmetric('DefaultShipFormId', '{$d->pid()}')");