public function submit_program_ot_retiro_servicio() { 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 == 3 || $data["user"]->idrol == 4) { // Validate the info, create rules for the inputs $attributes = array('fecha_programacion' => 'Fecha de Programación', 'solicitante' => 'Solicitante'); $messages = array(); $rules = array('fecha_programacion' => 'required', 'solicitante' => 'required'); // 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 $reporte_info_id = Input::get('reporte_info_id'); if ($validator->fails()) { $url = "retiro_servicio/programacion/" . $reporte_info_id; return Redirect::to($url)->withErrors($validator)->withInput(Input::all()); } else { $idactivo = Input::get('idactivo'); $activo = Activo::find($idactivo); // Algoritmo para añadir numeros correlativos $string = $this->getOtCorrelativeReportNumber(); $ot = new OtRetiro(); $ot->ot_tipo_abreviatura = "OT"; $ot->ot_correlativo = $string; $ot->ot_activo_abreviatura = "RS"; $ot->fecha_programacion = date('Y-m-d H:i:s', strtotime(Input::get('fecha_programacion'))); $ot->idreporte_retiro = $reporte_info_id; $ot->idactivo = $idactivo; $ot->idservicio = $activo->idservicio; $ot->idestado_ot = 9; // A mejorar este hardcode :/ $ot->id_usuarioelaborador = $data["user"]->id; $ot->id_usuariosolicitante = Input::get('solicitante'); $ot->idestado_inicial = $activo->idestado; $ot->idubicacion_fisica = $activo->idubicacion_fisica; $ot->costo_total_personal = 0.0; $ot->save(); /* Aca se le cambia el estado al reporte de donde proviene... $reporte_retiro = SolicitudOrdenTrabajo::find($reporte_info_id); $reporte_retiro->idestado = 15; $reporte_retiro->save(); */ $url = "retiro_servicio/list_retiro_servicio"; Session::flash('message', 'Se programó correctamente la OT.'); return Redirect::to($url); } } else { return View::make('error/error', $data); } } else { return View::make('error/error', $data); } }