public function actionIndex()
 {
     ini_set('memory_limit', '650M');
     set_time_limit(0);
     $tyresForm = new ImportForm();
     $result = array();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ImportForm'])) {
         $tyresForm->attributes = $_POST['ImportForm'];
         if ($tyresForm->validate()) {
             # Вот тут начинается импорт
             /* вторая страница
              * 1. CAI
              * 2. Профиль(мм)
              * 3. Высота (%)
              * 4. Диаметр (,R)
              * 5. Индекс
              * 6. Модель
              * 7. Производитель
              * 8. Сезон
              * 9. Кол-во (ОПТ)
              * 10. Цена (ОПТ)
              * 11. Кол-во (ИМ)
              * 12. Цена (ИМ) 
             */
             TyreSizes::model()->updateAll(array('rest' => 0, 'price' => 0));
             $uploaded = Yii::app()->file->set('ImportForm[file]');
             Yii::app()->file->set(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id))->createDir();
             $newfile = $uploaded->copy(strtolower(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id)) . '/' . $uploaded->basename);
             $newfile->filename = $newfile->filename . '.' . date('YmdHis');
             Yii::import('ext.phpexcelreader.EPhpExcelReader');
             $data = new EPhpExcelReader($newfile->realpath, false);
             $sheet = 0;
             $rowcount = $data->rowcount($sheet);
             $result['rowcount'] = $rowcount;
             $result['count'] = 0;
             #$colcount = $data->colcount();
             #$rowcount = 5;
             $r = 2;
             while ($r <= $rowcount) {
                 $cai = $data->val($r, 1, $sheet);
                 if ($size = TyreSizes::model()->find('code=:code', array(':code' => $cai))) {
                     $size->price = $data->val($r, 12, $sheet);
                     if (!empty($tyresForm->margin)) {
                         $size->price += $size->price * ($tyresForm->margin / 100);
                     }
                     $rest11 = $data->val($r, 11, $sheet);
                     $rest9 = $data->val($r, 9, $sheet);
                     if (is_int($rest11) && is_int($rest9)) {
                         if ($rest11 > $rest9) {
                             $size->rest = $rest11;
                         } else {
                             $size->rest = $rest9;
                         }
                     } elseif (!is_int($rest11) && is_int($rest9)) {
                         $size->rest = 10;
                     } elseif (is_int($rest11) && !is_int($rest9)) {
                         $size->rest = 20;
                     } else {
                         $size->rest = 20;
                     }
                     if (!$size->save()) {
                         $result['errors']['size:' . $data->val($r, 1, $sheet)] = $size->errors;
                     }
                     $result['count']++;
                 } else {
                     echo '<p>' . $cai . ' ' . $data->val($r, 7, $sheet) . ' ' . $data->val($r, 6, $sheet) . ' not found</p>';
                 }
                 $r++;
             }
             #$this->redirect(array('view','id'=>$model->id));
         }
     }
     $this->render('index', array('model' => $tyresForm, 'results' => $result));
 }
 public function actionIndex()
 {
     ini_set('memory_limit', '650M');
     set_time_limit(0);
     $form = new ImportForm();
     $result = array();
     if (isset($_POST['ImportForm'])) {
         $form->attributes = $_POST['ImportForm'];
         if ($form->validate()) {
             # Вот тут начинается импорт
             /* Первая страница
              * 1. CAI
              * 2. J
              * 3. R
              * 4. /
              * 5. X
              * 6. ET
              * 7. Ø
              * 8. Модель
              * 9. Производитель
              * 10.Кол-во (ОПТ)
              * 11.Цена (ОПТ)
              * 12.Кол-во (ИМ)
              * 13.Цена (ИМ)
             */
             DiskSizes::model()->updateAll(array('rest' => 0, 'price' => 0));
             $sheet = 1;
             $uploaded = Yii::app()->file->set('ImportForm[file]');
             Yii::app()->file->set(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id))->createDir();
             $newfile = $uploaded->copy(strtolower(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id)) . '/' . $uploaded->basename);
             $newfile->filename = $newfile->filename . '.' . date('YmdHis');
             Yii::import('ext.phpexcelreader.EPhpExcelReader');
             $data = new EPhpExcelReader($newfile->realpath, false);
             $rowcount = $data->rowcount($sheet);
             $result['rowcount'] = $rowcount;
             $result['count'] = 0;
             #$colcount = $data->colcount();
             #$rowcount = 5;
             $r = 2;
             while ($r <= $rowcount) {
                 $cai = $data->val($r, 1, $sheet);
                 if ($size = DiskSizes::model()->find('code=:code', array(':code' => $cai))) {
                     $size->price = $data->val($r, 13, $sheet);
                     if (!empty($form->margin)) {
                         $size->price += $size->price * ($form->margin / 100);
                     }
                     $rest10 = $data->val($r, 10, $sheet);
                     $rest12 = $data->val($r, 12, $sheet);
                     if (is_int($rest12) && is_int($rest10)) {
                         if ($rest12 > $rest10) {
                             $size->rest = $rest12;
                         } else {
                             $size->rest = $rest10;
                         }
                     } elseif (!is_int($rest12) && is_int($rest10)) {
                         $size->rest = 10;
                     } elseif (is_int($rest12) && !is_int($rest10)) {
                         $size->rest = 20;
                     } else {
                         $size->rest = 20;
                     }
                     if (!$size->save()) {
                         $result['errors']['size:' . $data->val($r, 1, $sheet)] = $size->errors;
                     }
                     $result['count']++;
                 } else {
                     echo '<p>' . $cai . ' ' . $data->val($r, 9, $sheet) . ' ' . $data->val($r, 8, $sheet) . ' not found</p>';
                 }
                 $r++;
             }
             #$this->redirect(array('view','id'=>$model->id));
         }
     }
     $this->render('index', array('model' => $form, 'results' => $result));
 }