Пример #1
0
 public function testRelationSaving()
 {
     $p = new Policy();
     $p->policy_number = '123';
     $a = new PolicyAsset();
     $a->value = '123.13';
     $p->PolicyAssets[] = $a;
     $p->save();
     $this->assertEqual($a->policy_number, '123');
 }
Пример #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Policy();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Policy'])) {
         $model->attributes = $_POST['Policy'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #3
0
 /**
  * [policySaveAction for save policy]
  * @return [none] [redirect to policy page]
  */
 public function policySaveAction()
 {
     Input::flash();
     $data = Input::all();
     if (!isset($data['policy-status'])) {
         $data['policy-status'] = 'off';
     }
     // var_dump($data);exit;
     $rules = array('policy-text' => array('min:30', 'required'), 'policy-author' => array('required'), 'policy-status' => array('required'));
     // Build the custom messages array.
     $messages = array('policy-text.min' => 'กรุณาระบุเนื้อหานโยบายอย่างน้อย :min ตัวอักษร.', 'policy-text.required' => 'กรุณาระบุเนื้อหานโยบายคลังฯ', 'policy-author.required' => 'กรุณาระบุชื่อผู้สร้างนโยบาย');
     $policy_text = trim($data['policy-text']);
     // Create a new validator instance.
     $validator = Validator::make($data, $rules, $messages);
     if ($validator->passes()) {
         // Normally we would do something with the data.
         $policy = new Policy();
         $chk_pol = $policy->ckeckPolicyDuplicate(mb_strlen($policy_text));
         $policy->setTable('policy');
         if ($chk_pol) {
             $policy->policy_content = $policy_text;
             $policy->author = $data['policy-author'];
             $policy->status = $data['policy-status'] == 'on' ? True : False;
             $policy->policy_duty = $data['policy_duty'];
             $policy->save();
             return Redirect::to('policy-add')->with('success', 'บันทึกนโยบายคลังฯ สำเร็จ');
         } else {
             return Redirect::to('policy-add')->withErrors(array('มีนโยบายคลังฯ นี้อยุ่ในระบบแล้ว'));
         }
         // if($chk_pol)
         // {
         // 	return Redirect::to('policy-content')->withErrors('message','Existing Policy.');
         // }else
         // {
         // 	$policy->policy_content = $policy_text;
         // 	$policy->author = $data['policy-author'] ;
         // 	$policy->status = (($data['policy-status'] == 1) ? True : False);
         // 	//$policy->save();
         // 	return Redirect::to('policy-content')->with('success','Policy Added.');
         // }
     } else {
         //$errors = $validator->messages();
         return Redirect::to('policy-add')->withErrors($validator);
     }
 }
Пример #4
0
 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'));
     }
 }