Esempio n. 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new LbEmployee();
     $salaryModel = new LbEmployeeSalary();
     $benefitModel = new LbEmployeeBenefits();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['LbEmployee'])) {
         $employee_birthday = date('Y-m-d', strtotime($_POST['LbEmployee']['employee_birthday']));
         $model->attributes = $_POST['LbEmployee'];
         $model->employee_birthday = $employee_birthday;
         $model->employee_note = $_POST['LbEmployee']['employee_note'];
         $model->employee_bank = $_POST['LbEmployee']['employee_bank'];
         if ($model->save()) {
             $salary_name = $_POST['salary_name'];
             $salary_amount = $_POST['salary_amount'];
             $total_salary = 0;
             for ($i = 0; $i < count($salary_amount); $i++) {
                 $salary = new LbEmployeeSalary();
                 $salary->salary_name = $salary_name[$i];
                 $salary->salary_amount = $salary_amount[$i];
                 $salary->employee_id = $model->lb_record_primary_key;
                 if ($salary->save()) {
                     $total_salary += $salary->salary_amount;
                 }
             }
             //save benefit
             $benefit_name = $_POST['benefit_name'];
             $benefit_amount = $_POST['benefit_amount'];
             $total_benefit = 0;
             for ($i = 0; $i < count($benefit_amount); $i++) {
                 $benefit = new LbEmployeeBenefits();
                 $benefit->benefit_name = $benefit_name[$i];
                 $benefit->benefit_amount = $benefit_amount[$i];
                 $benefit->employee_id = $model->lb_record_primary_key;
                 if ($benefit->save()) {
                     $total_benefit += $benefit->benefit_amount;
                 }
             }
             $model->save();
             $this->redirect(array('update', 'id' => $model->lb_record_primary_key));
         }
     }
     $this->render('create', array('model' => $model, 'salaryModel' => $salaryModel, 'benefitModel' => $benefitModel));
 }