projects
/
Pman.Core
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Process/Php7.php
[Pman.Core]
/
ExcelToJson.php
diff --git
a/ExcelToJson.php
b/ExcelToJson.php
index
9724807
..
e981d32
100644
(file)
--- a/
ExcelToJson.php
+++ b/
ExcelToJson.php
@@
-12,7
+12,7
@@
class Pman_Core_ExcelToJson extends Pman_Roo
return parent::getAuth();
}
return parent::getAuth();
}
- function post()
+ function post(
$v
)
{
$this->transObj = DB_DataObject::Factory('invhist_transfer');
{
$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 );
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)
}
function importCsv($csv)
@@
-42,22
+47,25
@@
class Pman_Core_ExcelToJson extends Pman_Roo
$this->jerr("invalid file");
}
$this->jerr("invalid file");
}
- $req = array(
- 'LINE', 'ITEM CODE', 'DESCRIPTION', 'QUANTITY'
- );
-
+
$cols = false;
$cols = false;
- $rows = array();
$header = false;
$header = false;
+ $rows = array();
+ $extra = array();
while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
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){
$header = true;
continue;
}
if(!$header){
- $
rows[strtoupper(
$n[0])] = $n[1];
+ $
extra[preg_replace(array('/\s/', '/\:/'), '',
$n[0])] = $n[1];
continue;
}
continue;
}
@@
-71,38
+79,20
@@
class Pman_Core_ExcelToJson extends Pman_Roo
continue;
}
continue;
}
- foreach($req as $r) {
- if (!in_array($r,$cols)) {
- $cols = false;
- break;
- }
- }
+
continue;
}
foreach($cols as $i=>$k) {
$row[$k] = $n[$i];
}
continue;
}
foreach($cols as $i=>$k) {
$row[$k] = $n[$i];
}
- $rows[
'TRANSFER ITEMS'][
] = $row;
+ $rows[] = $row;
}
}
-
- if (empty($cols)) {
- $this->jerr("could not find a row with " . implode(' / ', $req));
- }
-
fclose($fh);
fclose($fh);
- foreach ($rows['TRANSFER ITEMS'] as $r){
- $itemsite = DB_DataObject::factory('itemsite');
- $itemsite->autoJoin();
- $itemsite->get('item_number', $r['ITEM CODE']);
- }
+
-
-
-
- exit;
+ return array('extra' => $extra, 'data' => $rows);;
}
}
-
-}
+}
\ No newline at end of file