From 8f6a69375300aacb93b4a91cdde8e369265f60fc Mon Sep 17 00:00:00 2001 From: Edward Date: Fri, 22 Mar 2013 12:23:19 +0800 Subject: [PATCH] ExcelToJson.php --- ExcelToJson.php | 88 +------------------------------------------------ 1 file changed, 1 insertion(+), 87 deletions(-) diff --git a/ExcelToJson.php b/ExcelToJson.php index 27675cfd..cad6033f 100644 --- a/ExcelToJson.php +++ b/ExcelToJson.php @@ -34,90 +34,4 @@ class Pman_Core_ExcelToJson extends Pman_Roo $this->jdata($data); } - - function importCsv($csv) - { - ini_set("auto_detect_line_endings", true); - - $fh = fopen($csv, 'r'); - if (!$fh) { - $this->jerr("invalid file"); - } - - - $cols = false; - $header = false; - $rows = array(); - $ret = array(); - - while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) { - if(!array_filter($n)){ - $header = true; - continue; - } - - if(!$header){ - $ret[preg_replace(array('/\s/', '/\:/'), '', $n[0])] = $n[1]; - continue; - } - - if(!$cols){ - $cols = array(); - foreach($n as $k) { - $cols[] = strtoupper(trim($k)); - } - - if (empty($cols)) { - continue; - } - - - continue; - } - - foreach($cols as $i=>$k) { - $row[$k] = $n[$i]; - } - $rows[] = $row; - - } - - - - fclose($fh); - - $lc = DB_DataObject::factory('location'); - if(!$lc->get('location_name', $ret['From'])){ - $this->jerr('error occur on getting location with reference ' . $ret['From']); - } - $ret['invhist_transfer_from'] = $lc->pid(); - $ret['invhist_transfer_from_location_name'] = $lc->location_name; - - $lt = DB_DataObject::factory('location'); - if(!$lt->get('location_name', $ret['To'])){ - $this->jerr('error occur on getting location with reference ' . $ret['From']); - } - $ret['invhist_transfer_to'] = $lt->pid(); - $ret['invhist_transfer_to_location_name'] = $lt->location_name; - - foreach ($rows as $r){ - $itemsite = DB_DataObject::factory('itemsite'); - $itemsite->autoJoin(); - $itemsite->whereAdd("join_itemsite_item_id_item_id.item_number = '{$itemsite->escape($r['ITEM CODE'])}'"); - if(!$itemsite->find(true)){ - $this->jerr("error occur on getting item with reference " . $r['ITEM CODE']); - } - - $ret['data'][] = array( - 'itemsite_item_id' => $itemsite->itemsite_item_id, - 'itemsite_id' => $itemsite->pid(), - 'itemsite_item_id_item_number' => $r['ITEM CODE'], - 'itemsite_item_id_item_descrip1' => $r['DESCRIPTION'], - 'itemsite_qty' => $r['QUANTITY'] - ); - } - return $ret; - - } - -} +} \ No newline at end of file -- 2.39.2