3 require_once 'Pman/Roo.php';
5 class Pman_Core_ExcelToJson extends Pman_Roo
9 if (HTML_FlexyFramework::get()->cli) {
12 return parent::getAuth();
17 $this->transObj = DB_DataObject::Factory('invhist_transfer');
19 $this->transObj->query('BEGIN');
21 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
23 $img = DB_DataObject::Factory('images');
26 'ontable' => 'ipshead'
28 $img->onUpload(false);
30 require_once 'File/Convert.php';
31 $fc = new File_Convert($img->getStoreName(), $img->mimetype );
32 $csv = $fc->convert('text/csv');
33 $data = $this->importCsv($csv);
38 function importCsv($csv)
40 ini_set("auto_detect_line_endings", true);
42 $fh = fopen($csv, 'r');
44 $this->jerr("invalid file");
53 while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
54 if(!array_filter($n)){
60 $ret[preg_replace(array('/\s/', '/\:/'), '', $n[0])] = $n[1];
67 $cols[] = strtoupper(trim($k));
78 foreach($cols as $i=>$k) {
89 $lc = DB_DataObject::factory('location');
90 if(!$lc->get('location_name', $ret['From'])){
91 $this->jerr('error occur on getting location with reference ' . $ret['From']);
93 $ret['invhist_transfer_from'] = $lc->pid();
94 $ret['invhist_transfer_from_location_name'] = $lc->location_name;
96 $lt = DB_DataObject::factory('location');
97 if(!$lt->get('location_name', $ret['To'])){
98 $this->jerr('error occur on getting location with reference ' . $ret['From']);
100 $ret['invhist_transfer_to'] = $lt->pid();
101 $ret['invhist_transfer_to_location_name'] = $lt->location_name;
103 foreach ($rows as $r){
104 $itemsite = DB_DataObject::factory('itemsite');
105 $itemsite->autoJoin();
106 $itemsite->whereAdd("join_itemsite_item_id_item_id.item_number = '{$itemsite->escape($r['ITEM CODE'])}'");
107 if(!$itemsite->find(true)){
108 $this->jerr("error occur on getting item with reference " . $r['ITEM CODE']);
111 $ret['data'][] = array(
112 'itemsite_item_id' => $itemsite->itemsite_item_id,
113 'itemsite_id' => $itemsite->pid(),
114 'itemsite_item_id_item_number' => $r['ITEM CODE'],
115 'itemsite_item_id_item_descrip1' => $r['DESCRIPTION'],
116 'itemsite_qty' => $r['QUANTITY']