ExcelToJson.php
[Pman.Core] / ExcelToJson.php
index bce3a6e..9724807 100644 (file)
@@ -42,29 +42,66 @@ class Pman_Core_ExcelToJson extends Pman_Roo
             $this->jerr("invalid file");
         }
         
-        $cols[] = false;
+        $req = array(
+            'LINE', 'ITEM CODE', 'DESCRIPTION', 'QUANTITY'
+        );
+        
+        $cols = false;
         $rows = array();
         $header = false;
         
         while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
             if(!array_filter($n)){
                 $header = true;
+                continue;
             }
+            
             if(!$header){
-               $rows[$n[0]] = $n[1];
+               $rows[strtoupper($n[0])] = $n[1];
                continue;
             }
-            foreach($n as $k) {
-                $cols[] = strtoupper(trim($k));
+            
+            if(!$cols){
+                $cols = array();
+                foreach($n as $k) {
+                    $cols[] = strtoupper(trim($k));
+                }
+                
+                if (empty($cols)) {
+                    continue;
+                }
+               
+                foreach($req as $r) {
+                    if (!in_array($r,$cols)) {
+                        $cols = false;
+                        break;
+                    }
+                }
+                continue;
+            }
+            
+            foreach($cols as $i=>$k) {
+                $row[$k] = $n[$i];
             }
+            $rows['TRANSFER ITEMS'][] = $row;
+            
         }
-        exit;
+        
         if (empty($cols)) {
             $this->jerr("could not find a row with " . implode(' / ', $req));
         }
         
         fclose($fh);
         
+        foreach ($rows['TRANSFER ITEMS'] as $r){
+            $itemsite = DB_DataObject::factory('itemsite');
+            $itemsite->autoJoin();
+            $itemsite->get('item_number', $r['ITEM CODE']);
+        }
+        
+        
+        
+        
         exit;
     }