Beispiel #1
0
 function _parse($file, $template = 1)
 {
     switch ($template) {
         case 1:
             $serial_number = 0;
             $type = 1;
             $code = 2;
             $number = 3;
             $description = 4;
             break;
     }
     $this->load->library("cvsreader");
     $filedata = $this->csvreader->parse_file($file["full_path"]);
     $inventoryObject = new Inventory();
     $rownumber = 0;
     foreach ($filedata as $row) {
         foreach ($row as $csvstring) {
             $elements = array_fill(0, 5, "");
             $elements = $this->csvreader->get_csv_values($csvstring);
             if (strlen(trim($elements[$code])) > 0) {
                 $rownumber = $rownumber + 1;
                 // Just a quick check on the number of rows being added
                 $inventoryObject->vendor_id = $elements[$vendor_id];
                 $inventoryObject->type = ucwords(strtolower(trim($elements[$type])));
                 $inventoryObject->code = strtoupper(trim($elements[$code]));
                 $inventoryObject->sale_price = $elements[$number] + 100;
                 $inventoryObject->cost_price = 0.45 * $inventoryObject->sale_price;
                 $inventoryObject->description = $elements[$description];
                 $inventoryObject->status = 1;
                 $inventoryObject->save();
             }
             $inventoryObject->clear();
         }
     }
 }