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 $this->importCsv($csv);
36 function importCsv($csv)
38 ini_set("auto_detect_line_endings", true);
40 $fh = fopen($csv, 'r');
42 $this->jerr("invalid file");
51 while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
52 if(!array_filter($n)){
58 $ret[preg_replace(array('/\s/', '/\:/'), '', $n[0])] = $n[1];
65 $cols[] = strtoupper(trim($k));
76 foreach($cols as $i=>$k) {
87 $lc = DB_DataObject::factory('location');
88 if(!$lc->get('location_name', $ret['From'])){
89 $this->jerr('error occur on getting location with reference ' . $ret['From']);
91 $ret['invhist_transfer_from'] = $lc->pid();
92 $ret['invhist_transfer_from_location_name'] = $lc->location_name;
94 $lt = DB_DataObject::factory('location');
95 if(!$lt->get('location_name', $ret['To'])){
96 $this->jerr('error occur on getting location with reference ' . $ret['From']);
98 $ret['invhist_transfer_to'] = $lt->pid();
99 $ret['invhist_transfer_to_location_name'] = $lt->location_name;
101 foreach ($rows as $r){
102 $itemsite = DB_DataObject::factory('itemsite');
103 $itemsite->autoJoin();
104 $itemsite->whereAdd("join_itemsite_item_id_item_id.item_number = '{$itemsite->escape($r['ITEM CODE'])}'");
105 if(!$itemsite->find(true)){
106 $this->jerr("error occur on getting item with reference " . $r['ITEM CODE']);
109 $ret['data'][] = array(
110 'itemsite_item_id' => $itemsite->itemsite_item_id,
111 'itemsite_id' => $itemsite->pid(),
112 'itemsite_item_id_item_number' => $r['ITEM CODE'],
113 'itemsite_item_id_item_descrip1' => $r['DESCRIPTION'],
114 'itemsite_qty' => $r['QUANTITY']