X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=ExcelToJson.php;h=e981d32901cb7910e25123b2dcd4a4f95dc6b694;hp=8f84f57c41a11807c4060528b9977b448f5b983d;hb=refs%2Fheads%2Fwip_edward_T5851_download_old_offer_sheet;hpb=f1a4c61aea695dc2a68f6835b063e463145e0b73 diff --git a/ExcelToJson.php b/ExcelToJson.php index 8f84f57c..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) @@ -46,16 +51,21 @@ class Pman_Core_ExcelToJson extends Pman_Roo $cols = false; $header = false; $rows = array(); - $ret = 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){ - $ret[preg_replace(array('/\s/', '/\:/'), '', $n[0])] = $n[1]; + $extra[preg_replace(array('/\s/', '/\:/'), '', $n[0])] = $n[1]; continue; } @@ -79,46 +89,10 @@ class Pman_Core_ExcelToJson extends Pman_Roo $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'] - ); - } - - $this->jok($ret); + - - exit; + return array('extra' => $extra, 'data' => $rows);; } - -} +} \ No newline at end of file