ExcelToJson.php
[Pman.Core] / ExcelToJson.php
index 059ed0e..9724807 100644 (file)
@@ -17,7 +17,7 @@ class Pman_Core_ExcelToJson extends Pman_Roo
         $this->transObj = DB_DataObject::Factory('invhist_transfer');
         
         $this->transObj->query('BEGIN');
-        print_r('run');exit;
+        
         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
         
         $img = DB_DataObject::Factory('images');
@@ -42,13 +42,26 @@ class Pman_Core_ExcelToJson extends Pman_Roo
             $this->jerr("invalid file");
         }
         
+        $req = array(
+            'LINE', 'ITEM CODE', 'DESCRIPTION', 'QUANTITY'
+        );
         
         $cols = false;
         $rows = array();
+        $header = false;
         
         while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
-            if (!$cols) {
-                
+            if(!array_filter($n)){
+                $header = true;
+                continue;
+            }
+            
+            if(!$header){
+               $rows[strtoupper($n[0])] = $n[1];
+               continue;
+            }
+            
+            if(!$cols){
                 $cols = array();
                 foreach($n as $k) {
                     $cols[] = strtoupper(trim($k));
@@ -57,6 +70,7 @@ class Pman_Core_ExcelToJson extends Pman_Roo
                 if (empty($cols)) {
                     continue;
                 }
+               
                 foreach($req as $r) {
                     if (!in_array($r,$cols)) {
                         $cols = false;
@@ -65,10 +79,12 @@ class Pman_Core_ExcelToJson extends Pman_Roo
                 }
                 continue;
             }
+            
             foreach($cols as $i=>$k) {
                 $row[$k] = $n[$i];
             }
-            $rows[] = $row;
+            $rows['TRANSFER ITEMS'][] = $row;
+            
         }
         
         if (empty($cols)) {
@@ -77,6 +93,15 @@ class Pman_Core_ExcelToJson extends Pman_Roo
         
         fclose($fh);
         
+        foreach ($rows['TRANSFER ITEMS'] as $r){
+            $itemsite = DB_DataObject::factory('itemsite');
+            $itemsite->autoJoin();
+            $itemsite->get('item_number', $r['ITEM CODE']);
+        }
+        
+        
+        
+        
         exit;
     }