/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new ComponentSuplier();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ComponentSuplier'])) {
         $model->attributes = $_POST['ComponentSuplier'];
         if ($model->save()) {
             $price = ComponentSuplier::model()->findAllByAttributes(array('component_id' => $model->component_id));
             if ($price != null) {
                 $i = 0;
                 $price_inc = 0;
                 $rate_price = 0;
                 foreach ($price as $dataprice) {
                     $price_inc = $price_inc + floatval($dataprice->price);
                     $i++;
                     //var_dump($dataprice->price)."<br><br>";
                 }
                 $rate_price = intval($price_inc / $i);
                 Components::model()->updateByPk($model->component_id, array('rate_price' => $rate_price));
             } else {
                 $rate_price = $model->price;
                 Components::model()->updateByPk($model->component_id, array('rate_price' => $rate_price));
             }
             //var_dump($price);
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('index', array('model' => $model));
 }