public function aprobar_prepadrino_ajax() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["permisos"] = Session::get('permisos'); if (in_array('side_aprobar_padrinos', $data["permisos"])) { $selected_ids = Input::get('selected_id'); foreach ($selected_ids as $selected_id) { $prepadrino = Prepadrino::find($selected_id); if ($prepadrino) { //Primero creo ala persona $persona = new Persona(); $persona->nombres = $prepadrino->nombres; $persona->apellido_pat = $prepadrino->apellido_pat; $persona->apellido_mat = $prepadrino->apellido_mat; $persona->fecha_nacimiento = $prepadrino->fecha_nacimiento; $persona->direccion = $prepadrino->direccion; $persona->telefono = $prepadrino->telefono; $persona->celular = $prepadrino->celular; $persona->save(); // Creo al usuario y le asigno su información de persona $password = Str::random(8); $user = new User(); $user->num_documento = $prepadrino->dni; $user->password = Hash::make($password); $user->idtipo_identificacion = 1; $user->email = $prepadrino->email; $user->idpersona = $persona->idpersonas; $user->auth_token = Str::random(32); $user->save(); //Registro perfil padrino $user_perfil = new UsersPerfil(); $user_perfil->idperfiles = 4; $user_perfil->idusers = $user->id; $user_perfil->save(); //Regisro al padrino $padrino = new Padrino(); $padrino->como_se_entero = $prepadrino->como_se_entero; $padrino->idusers = $user->id; $padrino->idperiodo_pagos = $prepadrino->idperiodo_pagos; $padrino->idresponsable = $data["user"]->id; $padrino->save(); $descripcion_log = "Se aprobó al padrino con id {{$padrino->idpadrinos}}"; Helpers::registrarLog(3, $descripcion_log); //Generacion de Calendario de Pagos $periodo_pago = PeriodoPago::find($padrino->idperiodo_pagos); if ($periodo_pago) { $numero_pagos = $periodo_pago->numero_pagos; $fecha_vencimiento = date('Y-m-d', strtotime($padrino->created_at)); $fecha_vencimiento = date('Y-m-t', strtotime($fecha_vencimiento . '+ 1 days')); for ($indice = 1; $indice <= $numero_pagos; $indice++) { $calendario_pago = new CalendarioPago(); $calendario_pago->vencimiento = $fecha_vencimiento; $calendario_pago->num_cuota = $indice; //$calendario_pago->aprobacion = 0; $calendario_pago->idpadrinos = $padrino->idpadrinos; $calendario_pago->monto = 360 / $numero_pagos; $calendario_pago->save(); for ($offset_mes = 1; $offset_mes <= 12 / $numero_pagos; $offset_mes++) { $fecha_vencimiento = date('Y-m-t', strtotime($fecha_vencimiento . '+ 1 days')); } } $descripcion_log = "Se creó el calendario de pagos para el padrino con id {{$padrino->idpadrinos}}"; Helpers::registrarLog(3, $descripcion_log); } //Borrado logico del prepadrino $prepadrino->delete(); Mail::send('emails.userRegistration', array('user' => $user, 'persona' => $persona, 'password' => $password), function ($message) use($user, $persona) { $message->to($user->email, $persona->nombres)->subject('Registro de nuevo padrino'); }); } } return Response::json(array('success' => true, 'prepadrino_data' => $prepadrino), 200); } else { return Response::json(array('success' => false), 200); } } else { return Response::json(array('success' => false), 200); } }
public function submit_edit_user() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["permisos"] = Session::get('permisos'); if (in_array('side_nuevo_usuario', $data["permisos"])) { // Validate the info, create rules for the inputs $attributes = array('idtipo_identificacion' => 'Tipo de identificación', 'num_documento' => 'Número de Documento', 'email' => 'E-mail', 'nombres' => 'Nombres', 'apellido_pat' => 'Apellido Paterno', 'apellido_mat' => 'Apellido Materno', 'direccion' => 'Dirección', 'telefono' => 'Teléfono', 'celular' => 'Celular', 'perfiles' => 'Perfiles'); $messages = array(); $rules = array('idtipo_identificacion' => 'required', 'num_documento' => 'numeric|digits_between:8,16|unique:users', 'email' => 'email|max:100|unique:users', 'nombres' => 'required|alpha_spaces|min:2|max:100', 'apellido_pat' => 'required|alpha_spaces|min:2|max:100', 'apellido_mat' => 'required|alpha_spaces|min:2|max:100', 'direccion' => 'required|max:150', 'telefono' => 'numeric|digits_between:7,20', 'celular' => 'numeric|digits_between:7,20', 'perfiles' => '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 $user_id = Input::get('user_id'); if ($validator->fails()) { return Redirect::to("user/edit_user/" . $user_id)->withErrors($validator)->withInput(Input::all()); } else { $password = Input::get('password'); $user = User::find($user_id); if (!empty(Input::get('email'))) { $user->email = Input::get('email'); } if (!empty($password)) { $user->password = Hash::make($password); } if (!empty(Input::get('num_documento'))) { $user->num_documento = Input::get('num_documento'); } $user->idtipo_identificacion = Input::get('idtipo_identificacion'); $user->save(); $persona = Persona::find($user->idpersona); $persona->nombres = Input::get('nombres'); $persona->apellido_pat = Input::get('apellido_pat'); $persona->apellido_mat = Input::get('apellido_mat'); if (!empty(Input::get('fecha_nacimiento'))) { $persona->fecha_nacimiento = date('Y-m-d H:i:s', strtotime(Input::get('fecha_nacimiento'))); } $persona->direccion = Input::get('direccion'); $persona->telefono = Input::get('telefono'); $persona->celular = Input::get('celular'); $persona->latitud = Input::get('latitud'); $persona->longitud = Input::get('longitud'); $persona->save(); // Elimino los perfiles anteriores $perfiles_usuario = User::getPerfilesPorUsuario2($user->id)->get(); foreach ($perfiles_usuario as $perfil_usuario) { $p = UsersPerfil::find($perfil_usuario->idusers_perfiles); $p->delete(); } // Registro los perfiles seleccionados $perfiles = Input::get('perfiles'); foreach ($perfiles as $perfil) { $users_perfil = new UsersPerfil(); $users_perfil->idusers = $user->id; $users_perfil->idperfiles = $perfil; $users_perfil->save(); } // Llamo a la función para registrar el log de auditoria $descripcion_log = "Se editó el usuario con id {{$user->id}}"; Helpers::registrarLog(4, $descripcion_log); Session::flash('message', 'Se editó correctamente la información.'); return Redirect::to("user/edit_user/" . $user_id); } } else { // Llamo a la función para registrar el log de auditoria $descripcion_log = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'"; Helpers::registrarLog(10, $descripcion_log); Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.'); return Redirect::to('/dashboard'); } } else { return View::make('error/error'); } }
public function search_voluntarios() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["permisos"] = Session::get('permisos'); if (in_array('side_listar_voluntarios', $data["permisos"])) { $data["convocatoria_info"] = Periodo::searchPeriodoById(Input::get('idperiodos'))->get()[0]; $data["search"] = Input::get('search'); $data["voluntarios_data"] = UsersPerfil::searchVoluntariosInfoByIdPeriodo(Input::get('idperiodos'), $data["search"]); return View::make('convocatorias/listVoluntariosConvocatoria', $data); } else { return View::make('error/error'); } } else { return View::make('error/error'); } }
public function submit_disable_perfil() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["permisos"] = Session::get('permisos'); if (in_array('side_nuevo_usuario', $data["permisos"])) { $idperfiles = Input::get('idperfiles'); $url = "sistema/edit_perfil/" . $idperfiles; $users_perfil = UsersPerfil::getUsersPorPerfil($idperfiles)->get(); if ($users_perfil->isEmpty()) { $perfil = Perfil::find($idperfiles); $perfil->delete(); Session::flash('message', 'Se eliminó correctamente el perfil.'); } else { Session::flash('error', 'No se pudo eliminar el perfil debido a que por lo menos un usuario pertenece a dicho perfil.'); } // Llamo a la función para registrar el log de auditoria $descripcion_log = "Se eliminó el perfil con id {{$perfil->idperfiles}}"; Helpers::registrarLog(5, $descripcion_log); Session::flash('message', 'Se eliminó correctamente el perfil.'); return Redirect::to($url); } else { // Llamo a la función para registrar el log de auditoria $descripcion_log = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'"; Helpers::registrarLog(10, $descripcion_log); Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.'); return Redirect::to('/dashboard'); } } else { return View::make('error/error'); } }
public function submit_asistencia_excel() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["permisos"] = Session::get('permisos'); if (in_array('side_reporte_asistencia', $data["permisos"])) { $data["search_periodo"] = Input::get('search_periodo_excel'); $data["search_usuario"] = Input::get('search_usuario_excel'); $data["periodos"] = Periodo::lists('nombre', 'idperiodos'); $periodo = Periodo::find($data["search_periodo"]); $eventos_asistencia = Asistencia::getEventosAsistencia()->get(); $voluntarios_data = UsersPerfil::searchVoluntariosReporteInfo($data["search_periodo"], $data["search_usuario"]); $str_table = "<table><tr><td></td><td></td><td></td><td><strong>Reporte de Asistencia</strong></td></tr></table>"; if ($periodo == null) { $str_table .= "<table><tr><td><strong>Periodo</strong></td><td>Todos</td></tr><tr></tr></table>"; } else { $str_table .= "<table><tr><td><strong>Periodo:</strong></td><td>" . $periodo->nombre . "</td></tr><tr></tr></table>"; } $str_table .= "<table border=1><tr><th>Periodo</th><th>Doc. de Identidad</th><th>Nombre</th><th>Eventos Programados</th><th>Eventos que Asistio</th><th>% Asistencia</th><th>Promedio Calificacion</th></tr>"; if ($voluntarios_data != null) { foreach ($voluntarios_data as $voluntario_data) { $eventos_total = 0; $eventos_asistidos = 0; $str_table .= "<tr><td>" . htmlentities($voluntario_data->nombre_periodo) . "</td><td>" . htmlentities($voluntario_data->num_documento) . "</td><td>" . htmlentities($voluntario_data->apellido_pat . ' ' . $voluntario_data->apellido_mat . ', ' . $voluntario_data->nombre_persona) . "</td><td>"; foreach ($eventos_asistencia as $asistencia) { if ($asistencia->idusers == $voluntario_data->id) { $str_table .= "-" . htmlentities($asistencia->nombre) . "<br>"; $eventos_total++; } } $str_table .= "</td><td>"; foreach ($eventos_asistencia as $asistencia) { if ($asistencia->idusers == $voluntario_data->id) { if ($asistencia->asistio == 1) { $str_table .= "-" . htmlentities($asistencia->nombre) . "<br>"; $eventos_asistidos++; } } } $str_table .= "</td><td>" . htmlentities(round($eventos_asistidos / $eventos_total * 100, 2)) . "%</td><td>" . htmlentities(round($voluntario_data->prom_calificaciones), 2) . "</td></tr>"; } } $str_table .= "</table>"; $filename = "reporte_asistencia" . date('Y-m-d') . ".xls"; // Show the download dialog header("Content-type: application/vnd.ms-excel; charset=utf-8"); // Let's indicate to the browser we are giving it the file header("Content-Disposition: attachment; filename=\"{$filename}\""); // Avoid the browser to save the file into it's cache header("Pragma: no-cache"); header("Expires: 0"); // Render the table echo $str_table; } else { return View::make('error/error'); } } else { return View::make('error/error'); } }