protected function findItemPriceTier($profit_margin_id, $price_tier_id) { $profit_price_tier = ProfitPriceTier::model()->find('profit_margin_id=:profit_margin_id AND price_tier_id=:price_tier_id', array(':profit_margin_id' => (int) $profit_margin_id, ':price_tier_id' => (int) $price_tier_id)); if (!$profit_price_tier) { $profit_price_tier = new ProfitPriceTier(); } return $profit_price_tier; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $price_tiers = PriceTier::model()->getProfitPriceTierUpdate($id); // 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, 'Profit Margin : <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('update', array('model' => $model, 'price_tiers' => $price_tiers)); }