/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Plans(); $region = PlanRegion::model()->findAll(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Plans'])) { // pre($_POST,true); $plan_price = $_POST['PlanPrice']; $plan_adv = $_POST['PlanAdvantage']; $model->attributes = $_POST['Plans']; if ($model->save()) { for ($i = 0; $i < count($plan_price['age_group']); $i++) { $planPrice = new PlanPrice(); $planPrice->plan = $model->id; $planPrice->age_group = $plan_price['age_group'][$i]; $planPrice->policy_tenure = $plan_price['policy_tenure'][$i]; $planPrice->policy_amount = $plan_price['policy_amount'][$i]; $planPrice->premium = $plan_price['policy_premium'][$i]; $planPrice->region = $plan_price['region'][$i]; $planPrice->save(); } for ($j = 0; $j < count($plan_adv['advantage']); $j++) { $planAdv = new PlanAdvantage(); $planAdv->plan = $model->id; $planAdv->advantage = $plan_adv['advantage'][$j]; $planAdv->tooltip = $plan_adv['policy_tooltip'][$j]; $planAdv->save(); } $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model, 'region' => $region)); }
public function actionPurchase() { if (isset($_POST['Policy'])) { $model = new Policy(); $model->attributes = $_POST['Policy']; $model->proposal_no = uniqid(); $model->is_purchased = 'q'; if ($model->save()) { $parent = Plans::model()->findByPk($_POST['Policy']['parent_plan']); $region = PlanRegion::model()->findByPk($_POST['Policy']['region']); $amount = $_POST['Policy']['policy_amount']; $premium = $_POST['Policy']['policy_premium']; $tenure = $_POST['Policy']['tenure']; $first_name = $_POST['Policy']['first_name']; $age = $_POST['Policy']['age']; $plan = Plans::model()->findByPk($model->plan); $this->render("purchase", array("model" => $model, "parent" => $parent, "plan" => $plan, "region" => $region, "premium" => $premium, "amount" => $amount, "first_name" => $first_name, "age" => $age, "tenure" => $tenure)); } else { pre($model->getErrors(), true); } } else { $this->redirect(array('quotation')); } }