X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=ExcelToJson.php;h=e981d32901cb7910e25123b2dcd4a4f95dc6b694;hp=b479036237ba760222f949a5f2f598032e21427d;hb=refs%2Fheads%2Fwip_edward_T5851_download_old_offer_sheet;hpb=e73c5a491a9700d6d65f1fd8e9c7c456f69ac87f diff --git a/ExcelToJson.php b/ExcelToJson.php index b4790362..e981d329 100644 --- a/ExcelToJson.php +++ b/ExcelToJson.php @@ -12,7 +12,7 @@ class Pman_Core_ExcelToJson extends Pman_Roo return parent::getAuth(); } - function post() + function post($v) { $this->transObj = DB_DataObject::Factory('invhist_transfer'); @@ -29,8 +29,13 @@ class Pman_Core_ExcelToJson extends Pman_Roo require_once 'File/Convert.php'; $fc = new File_Convert($img->getStoreName(), $img->mimetype ); - $csv = $fc->convert('text/csv'); - $this->importCsv($csv); + $csv = $fc->convert('text/csv'); + $ret = $this->importCsv($csv); + + + + $this->jdata($ret['data'], false, isset($ret['extra']) ? $ret['extra'] : array() ); + } function importCsv($csv) @@ -42,41 +47,39 @@ class Pman_Core_ExcelToJson extends Pman_Roo $this->jerr("invalid file"); } - $req = array( - 'LINE', 'ITEM CODE', 'DESCRIPTION', 'QUANTITY', 'AA' - ); - - $cols[] = false; - $rows = array(); + + $cols = false; $header = false; + $rows = array(); + $extra = array(); while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) { - if(!array_filter($n)){ + + + if(!strlen(trim(implode('', $n)))){ // blank line; + if ($header) { + continue; + } $header = true; + continue; } if(!$header){ - $rows[$n[0]] = $n[1]; + $extra[preg_replace(array('/\s/', '/\:/'), '', $n[0])] = $n[1]; continue; } - print_r($n);exit; + if(!$cols){ $cols = array(); foreach($n as $k) { $cols[] = strtoupper(trim($k)); } - print_r($cols);exit; + if (empty($cols)) { continue; } - print_r($cols);exit; - foreach($req as $r) { - if (!in_array($r,$cols)) { - print_r($r); - $cols = false; - break; - } - } + + continue; } @@ -86,14 +89,10 @@ class Pman_Core_ExcelToJson extends Pman_Roo $rows[] = $row; } - exit; - if (empty($cols)) { - $this->jerr("could not find a row with " . implode(' / ', $req)); - } - fclose($fh); - exit; + + + return array('extra' => $extra, 'data' => $rows);; } - -} +} \ No newline at end of file