/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new ProfitMargin();
     $price_tiers = PriceTier::model()->getListPriceTier();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ProfitMargin'])) {
         $model->attributes = $_POST['ProfitMargin'];
         $model->modified_by = Yii::app()->session['employeeid'];
         if ($model->validate()) {
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 if ($model->save()) {
                     ProfitPriceTier::model()->saveProfitPriceTier($model->id, $price_tiers);
                     $transaction->commit();
                     Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, 'Item Id : <strong>' . $model->name . '</strong> have been saved successfully!');
                     $this->redirect(array('admin'));
                 }
             } catch (Exception $e) {
                 $transaction->rollback();
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_WARNING, 'Oop something wrong : <strong>' . $e);
             }
         }
     }
     $this->render('create', array('model' => $model, 'price_tiers' => $price_tiers));
 }