コード例 #1
0
 public function submit_create_sot()
 {
     if (Auth::check()) {
         $data["inside_url"] = Config::get('app.inside_url');
         $data["user"] = Session::get('user');
         // Verifico si el usuario es un Webmaster
         if ($data["user"]->idrol == 1 || $data["user"]->idrol == 2 || $data["user"]->idrol == 7 || $data["user"]->idrol == 8 || $data["user"]->idrol == 9) {
             // Validate the info, create rules for the inputs
             $attributes = array('cod_pat' => 'Código Patrimonial', 'fecha_solicitud' => 'Fecha de Solicitud', 'especificacion_servicio' => 'Especificación de Servicio', 'motivo' => 'Motivo', 'justificacion' => 'Justificación');
             $messages = array();
             $rules = array('cod_pat' => 'required|numeric', 'fecha_solicitud' => 'required', 'especificacion_servicio' => 'required|max:100|alpha_num_spaces_colon', 'motivo' => 'required|max:200|alpha_num_spaces_colon', 'justificacion' => 'required|max:200|alpha_num_spaces_colon');
             // Run the validation rules on the inputs from the form
             $validator = Validator::make(Input::all(), $rules, $messages, $attributes);
             // If the validator fails, redirect back to the form
             if ($validator->fails()) {
                 return Redirect::to('sot/create_sot')->withErrors($validator)->withInput(Input::all());
             } else {
                 $cod_pat = Input::get('cod_pat');
                 $equipo = Activo::searchActivosByCodigoPatrimonial($cod_pat)->get();
                 if (!$equipo->isEmpty()) {
                     $equipo = $equipo[0];
                     $tabla = Tabla::getTablaByNombre(self::$nombre_tabla)->get();
                     $estado = Estado::where('idtabla', '=', $tabla[0]->idtabla)->first();
                     //El primer estado siempre es pendiente
                     // Algoritmo para añadir numeros correlativos
                     $string = $this->getCorrelativeReportNumber();
                     $sot = new SolicitudOrdenTrabajo();
                     $sot->sot_tipo_abreviatura = "SOT";
                     $sot->sot_correlativo = $string;
                     $sot->sot_activo_abreviatura = "TS";
                     $sot->fecha_solicitud = date('Y-m-d H:i:s', strtotime(Input::get('fecha_solicitud')));
                     $sot->especificacion_servicio = Input::get('especificacion_servicio');
                     $sot->idestado = $estado->idestado;
                     $sot->idactivo = $equipo->idactivo;
                     $sot->motivo = Input::get('motivo');
                     $sot->justificacion = Input::get('justificacion');
                     $sot->id = $data["user"]->id;
                     $sot->save();
                     Session::flash('message', 'Se generó correctamente la solicitud.');
                     return Redirect::to('sot/list_sots');
                 } else {
                     Session::flash('error', 'No se encontró un activo con el código patrimonial ingresado.');
                     return Redirect::to('sot/create_sot');
                 }
             }
         } else {
             return View::make('error/error', $data);
         }
     } else {
         return View::make('error/error', $data);
     }
 }