Пример #1
0
 /**
  * [agencyAdd description]
  * @return [type] [description]
  */
 public function agencyAdd($flag = null)
 {
     if (!$flag) {
         $ministry = new Ministry();
         $ministry_list = $ministry->getAllMinistry('get');
         return View::make('agency.add')->with('ministry_list', $ministry_list);
     } else {
         $data = Input::all();
         $rules = array('ministry_id' => 'required', 'department_id' => 'required');
         // Build the custom messages array.
         $messages = array('ministry_id.required' => 'กรุณาระบุชื่อกระทรวง', 'department_id.required' => 'กรุณาระบุชื่อกรม');
         // Create a new validator instance.
         $validator = Validator::make($data, $rules, $messages);
         if ($validator->passes()) {
             $dep_obj = new Department();
             $agency = new Agency();
             $code = $dep_obj->getDepartmentCodeById($data['department_id']);
             $rs_check = $agency->checkAgency($code);
             if ($rs_check) {
                 $dep_info = $dep_obj->getDeparmentInfoById($data['department_id']);
                 $agency->tname = $dep_info[0]['full_th_name'];
                 $agency->ministry_id = $dep_info[0]['ministry_id'];
                 $agency->status = true;
                 $agency->code = $dep_info[0]['department_code'];
                 $agency->save();
                 return Redirect::to('agency/list')->with('success', 'บันทึกสำเร็จ');
             } else {
                 return Redirect::to('agency/add')->with('warning', 'มีชื่อข้อมูลอยู่ในระบบแล้ว');
             }
         } else {
             // $errors = $validator->messages();
             return Redirect::to('agency/add')->withErrors($validator);
         }
     }
     //end else
 }