3 require_once 'Pman/Roo.php';
5 class Pman_Xtuple_Import_Flrpt extends Pman_Roo
8 static $cli_desc = "Copy reports from hk office to other offices...";
14 if (HTML_FlexyFramework::get()->cli) {
17 return parent::getAuth();
20 function get($flhead_id)
22 if (empty($flhead_id)) {
23 print_r(json_decode( file_get_contents('http://localhost/dragon/hk.php/Roo/flhead?_columns=flhead_id,flhead_name')));
25 $this->jerr("pick an available report");
28 $this->transObj = DB_DataObject::Factory('gltrans');
30 $this->transObj->query('BEGIN');
32 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
35 $url = 'http://localhost/dragon/hk.php/Roo/Flhead?flhead_id='.$flhead_id.'&_to_json=1';
36 $res = json_decode(file_get_contents($url),true);
38 if(count($res['data']) < 1) {
39 $this->jerr('no data found');
41 //$res['data']['flhead_name'] = 'TESTING';
42 $flhead = DB_DataObject::factory('flhead');
43 if($flhead->get('flhead_name' , $res['data']['flhead_name'])){
44 $this->jerr('flhead already exists');
47 $flhead->setFrom($res['data']);
51 $this->jerr('error occur on insert flhead');
53 if(!count($res['data']['groups'])){
54 $this->jerr('no groups found');
56 $grp = $res['data']['groups'];
57 $this->walkgrp($grp, $flhead->pid());
59 if(count($res['data']['col'])){
60 $this->walkcol($res['data']['col'], $flhead->pid());
63 $this->transObj->query('COMMIT');
68 function walkgrp($grp, $hid, $pargrp = '-1')
71 $g['flgrp_flhead_id'] = $hid;
72 if($g['flgrp_flgrp_id'] > 0){ // get and parent
73 $g['flgrp_flgrp_id'] = $pargrp;
75 $flgrp = DB_DataObject::factory('flgrp');
80 $this->jerr('error occur on insert group : ' . $g['flgrp_name']);
83 if(count($g['items'])){
84 $this->walkitem($g['items'], $hid, $flgrp->pid());
87 if(count($g['groups'])){
88 $this->walkgrp($g['groups'], $hid, $flgrp->pid());
94 function walkitem($item, $hid, $gid)
97 $i['flitem_flhead_id'] = $hid;
98 $i['flitem_flgrp_id'] = $gid;
99 $flitem = DB_DataObject::factory('flitem');
100 $flitem->setFrom($i);
105 function walkcol($col, $hid)
108 if(!count($c['report'])){
109 $this->jerr('Missing report details');
111 $report = DB_DataObject::factory('report');
113 if(!$report->get('report_name', $c['report']['report_name'])){
114 $report->setFrom($c['report']);
119 $this->jerr('error occur on insert report : ' . $c['report']['report_name']);
122 $c['flcol_flhead_id'] = $hid;
123 $c['flcol_report_id'] = $report->pid();
124 $flcol = DB_DataObject::factory('flcol');