ExcelToJson.php
[Pman.Core] / ExcelToJson.php
index bfa51d5..dee2f12 100644 (file)
@@ -43,20 +43,22 @@ class Pman_Core_ExcelToJson extends Pman_Roo
         }
         
         $req = array(
-            'LINE', 'ITEM CODE', 'DESCRIPTION', 'QUANTITY', 'AA'
+            'LINE', 'ITEM CODE', 'DESCRIPTION', 'QUANTITY'
         );
         
-        $cols[] = false;
-        $rows = array();
+        $cols = false;
         $header = false;
+        $rows = array();
+        $ret = array();
         
         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;
             }
             
@@ -65,13 +67,13 @@ class Pman_Core_ExcelToJson extends Pman_Roo
                 foreach($n as $k) {
                     $cols[] = strtoupper(trim($k));
                 }
-
+                
                 if (empty($cols)) {
                     continue;
                 }
+               
                 foreach($req as $r) {
                     if (!in_array($r,$cols)) {
-                        print_r($r);
                         $cols = false;
                         break;
                     }
@@ -82,16 +84,28 @@ class Pman_Core_ExcelToJson extends Pman_Roo
             foreach($cols as $i=>$k) {
                 $row[$k] = $n[$i];
             }
-            $rows[] = $row;
+            $rows['TRANSFER ITEMS'][] = $row;
             
         }
-        print_r($cols);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();
+            if(!$itemsite->get('join_itemsite_item_id_item_id.item_number', $r['ITEM CODE'])){
+                $this->jerr("error occur on getting item with reference " . $r['ITEM CODE']);
+            }
+            print_r($itemsite->toArray());
+        }
+        
+        
+        
+        
         exit;
     }