Browse Source

perfiles: se agrego el nuevo modulo de perfiles

Israel
iht 1 year ago
parent
commit
ea8415bc2c
  1. 161
      app/Http/Controllers/Administracion/PerfilesController.php
  2. 24
      app/Models/Perfiles.php
  3. 28
      database/migrations/2023_07_27_044915_create_perfiles_table.php
  4. 1
      database/seeders/DatabaseSeeder.php
  5. 21
      database/seeders/PerfilesSeeder.php
  6. 365
      public/js/administracion/perfiles.js
  7. 2
      public/js/administracion/usuarios.js
  8. 52
      resources/views/administracion/forms/nuevo_usuarios.blade.php
  9. 62
      resources/views/administracion/perfiles.blade.php
  10. 6
      resources/views/layouts/lefsidebar.blade.php
  11. 10
      routes/api/AdministracionApi.php
  12. 4
      routes/web/AdminstracionRoute.php

161
app/Http/Controllers/Administracion/PerfilesController.php

@ -0,0 +1,161 @@
<?php
namespace App\Http\Controllers\Administracion;
use App\Http\Controllers\Controller;
use App\Models\ArchivosNominas;
use App\Models\Empleados;
use App\Models\ExpirarContrasena;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
class PerfilesController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('administracion/perfiles');
}
public function nuevoUsuario( Request $request ){
$datosUsuario = $request->usuario;
$datosEmpleado = $request->empleado;
$datosUsuario['password'] = bcrypt('123456');
$nuevoUsuario = User::create( $datosUsuario );
$datosEmpleado['fk_id_users'] = $nuevoUsuario->id;
Empleados::create( $datosEmpleado );
ExpirarContrasena::create([
'fk_id_users' => $nuevoUsuario->id,
'dias_expiracion' => 0,
'ultima_actualizacion' => Carbon::now()
]);
return 'Exito papuus';
}
public function editarUsuario( Request $request ){
$datosEmpleado = $request->empleado;
User::where('id',$request->usuario['id'])->update($request->usuario );
$datosEmpleado['fk_id_users'] = $request->usuario['id'];
Empleados::updateOrCreate( $datosEmpleado ) ;
return 'Exito papuus';
}
public function eliminarUsuario( Request $request ){
User::where('id',$request->id)->update([
'activo' => 0,
'eliminado' => 1
]);
return 'Exito';
}
public function cargarListasUsuarios(Request $request){
$fileContpaq = $this->convertirExcelArray($request->file('files'));
$this->generarUsuarios( $fileContpaq, $request) ;
return 'exito!!!';
}
public function convertirExcelArray($file){
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$reader->setReadDataOnly(true);
$excel = $reader->load($file);
$sheet = $excel->getSheet(0);
$sheetData = $sheet->toArray(null, false, true, true);
return $sheetData;
}
public function generarUsuarios($file, $request )
{
foreach ($file as $row => $val){
if( $row > 1 ){
if( !is_null($val['A']) && !is_null($val['B']) ){
$nuevoUsuario = User::create([
'name' => $val['B'],
'fk_id_roles' => 3,
'fk_id_grupos' => 0,
'email' => $val['B'],
'password' => bcrypt('123456'),
]);
Empleados::create([
'clave_contpaq' => $val['A'],
'nombre_completo' => $val['B'],
'fk_id_users' => $nuevoUsuario->id
]);
ExpirarContrasena::create([
'fk_id_users' => $nuevoUsuario->id,
'dias_expiracion' => 0,
'ultima_actualizacion' => Carbon::now()
]);
}
}
}
return 'Exito';
}
public function expirarContrasena( Request $request ){
ExpirarContrasena::where('fk_id_users',$request->id)->update(['dias_expiracion' => 0]);
User::where('id',$request->id)->update(['password' => bcrypt('123456')]);
}
}

24
app/Models/Perfiles.php

@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Perfiles extends Model
{
protected $connection = 'mysql';
protected $table = 'perfiles';
protected $primaryKey = 'id';
public $timestamps = false;
protected $fillable = [
'perfil',
'activo'
];
}

28
database/migrations/2023_07_27_044915_create_perfiles_table.php

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('perfiles', function (Blueprint $table) {
$table->id();
$table->string('perfil');
$table->boolean('activo')->default(1);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('perfiles');
}
};

1
database/seeders/DatabaseSeeder.php

@ -17,6 +17,7 @@ class DatabaseSeeder extends Seeder
UsersTableSeeder::class, UsersTableSeeder::class,
RolesTableSeeder::class, RolesTableSeeder::class,
EmpresasSeeder::class, EmpresasSeeder::class,
PerfilesSeeder::class
]); ]);
// \App\Models\User::factory(10)->create(); // \App\Models\User::factory(10)->create();

21
database/seeders/PerfilesSeeder.php

@ -0,0 +1,21 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use DB;
class PerfilesSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
DB::table('perfiles')->insert(['perfil'=>'Administrador']);
DB::table('perfiles')->insert(['perfil'=>'Gerencia']);
DB::table('perfiles')->insert(['perfil'=>'Supervisor']);
DB::table('perfiles')->insert(['perfil'=>'Empleado']);
}
}

365
public/js/administracion/perfiles.js

@ -0,0 +1,365 @@
$(function () {
$(document).ajaxStart(function(){
$.blockUI({
message: '<i class="fas fa-spin fa-sync text-white"></i>',
overlayCSS: {
backgroundColor: "#000",
opacity: 0.5,
cursor: "wait",
},
css: {
border: 0,
padding: 0,
color: "#333",
backgroundColor: "transparent",
}
});
});
$(document).ajaxStop($.unblockUI);
$("#formNuevoUsuario").on("submit", function(e){
e.preventDefault();
var check = document.getElementsByClassName('formNuevoUsuario')[0].reportValidity();
if (check) {
var formData = new FormData(this);
Swal.fire({
title: "¿Esta seguro que desea agregar un nuevo usuario?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
cancelButtonText: "Cancelar",
confirmButtonText: "Aceptar",
}).then((result) => {
if (result.value) {
$('#cerrarModalNuevoUsuario').trigger("click");
$.ajax({
type:'POST',
url:'nuevo_usuario',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data: formData,
processData:false,
contentType: false,
success:function(data){
cargarlistaEmpresas();
$(".formNuevoUsuario")[0].reset();
$('#formNuevoUsuario').removeClass('was-validated');
Swal.fire("¡Éxito!", "Se agrego un nuevo usuario.", "success");
},
error: function (e) {
mensajeError();
}
});
}
});
}else{
errorFaltanCampos();
}
});
$("#formEditarUsuario").on("submit", function(e){
e.preventDefault();
var check = document.getElementsByClassName('formEditarUsuario')[0].reportValidity();
if (check) {
var formData = new FormData(this);
Swal.fire({
title: "¿Esta seguro que desea editar los datos del usuario?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
cancelButtonText: "Cancelar",
confirmButtonText: "Aceptar",
}).then((result) => {
if (result.value) {
$('#cerrarModalEditarUsuario').trigger("click");
$.ajax({
type:'POST',
url:'editar_usuario',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data: formData,
processData:false,
contentType: false,
success:function(data){
cargarlistaEmpresas();
$("#formEditarUsuario")[0].reset();
$('#formEditarUsuario').removeClass('was-validated');
Swal.fire("¡Éxito!", "Se editaron los datos del usuario.", "success");
},
error: function (e) {
mensajeError();
}
});
}
});
}else{
errorFaltanCampos();
}
});
$("#formCargarUsuarios").on("submit", function(e){
e.preventDefault();
var formData = new FormData(this);
Swal.fire({
title: "¿Esta seguro que deseas cargar la lista de nuevos usuarios?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
cancelButtonText: "Cancelar",
confirmButtonText: "Aceptar",
}).then((result) => {
if (result.value) {
$('#cerrarModalNuevo').trigger("click");
$.ajax({
type:'POST',
url:'cargar_lista_usuarios',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data: formData,
processData:false,
contentType: false,
success:function(data){
cargarlistaEmpresas();
Swal.fire("¡Éxito!", "Se agrego la lista de nuevos usuarios.", "success");
},
error: function (e) {
mensajeError();
}
});
}
});
});
});
cargarListaPerfiles();
function cargarListaPerfiles(){
$('#listaPerfiles').empty().DataTable({
searchDelay: 400,
ajax: {
url: 'api/obtener_perfiles',
dataSrc: function(json){
return json;
}
},
// order: [[0, 'asc']],
// ordering:true,
columns:[
// { data: "id", defaultContent: "---", title: "#2" },
{data:function(row, type){
const id = row.id;
let botonAcciones = '<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton" style="">'+
'<li>'+
'<a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#modal_editar_form" onclick="cargarEditarForm('+id+')">Editar</a>'+
'</li>'+
'<li>'+
'<a class="dropdown-item" onclick="eliminarUsuario('+ id +')">Eliminar</a>'+
'</li>'+
'</ul>';
return '<div class="dropdown dropstart">'+
'<a href="table-basic.html#" class="link" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">'+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-more-horizontal feather-sm">'+
'<circle cx="12" cy="12" r="1"></circle>'+
'<circle cx="19" cy="12" r="1"></circle>'+
'<circle cx="5" cy="12" r="1"></circle>'+
'</svg>'+
'</a>'+
botonAcciones+
'</div>';
},
title: "Acciones"},
{ data: "id", defaultContent: "---", title: "#" },
{ data: "perfil", defaultContent: "---", title: "Perfiles" },
{data:function(row, type){
const activo = row.activo;
console.log(activo);
return (row.activo == 1) ? 'Activo' : 'Inactivo' ;
},
title: "Estado"}
],
aLengthMenu: [
[25, 50, 100, 200, -1],
[25, 50, 100, 200, 'All']
],
destroy: true,
paging:true,
info:true,
// responsive: true,
// dom: "Bfrtip",
// buttons: ["copy", "csv", "excel", "pdf", "print"],
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.19/i18n/Spanish.json"
}
});
}
cargarListaRoles();
function cargarListaRoles(){
$.get('api/lista_roles',function(data){
let opciones = '';
$('.roles').empty();
$.each(data,function(i,ele){
opciones += '<option value="'+ ele.id +'" >'+ ele.rol +'</option>';
});
$('.roles').append(opciones);
});
}
function cargarEditarForm(id){
$.get('api/detalle_usuario',{id:id},function(data){
$.each(data,function(i,ele){
$('#editar_'+i).val(ele).change;
if( i == 'datos_empleado' ){
$.each(ele,function(j,datos_empleado){
// if( j == 'id' ){
// $('#editar_empleado_'+j).val(datos_empleado);
// }
$('#editar_empleado_'+j).val(datos_empleado);
});
}
});
});
}
function eliminarUsuario(id){
Swal.fire({
title: "¿Esta seguro que desea eliminar el usuario?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
cancelButtonText: "Cancelar",
confirmButtonText: "Aceptar",
}).then((result) => {
if (result.value) {
$.get('eliminar_usuario',{id:id},function(data){
cargarlistaEmpresas();
Swal.fire("¡Éxito!", "Se editaron los datos del usuario.", "success");
});
}
});
}
function errorFaltanCampos(){
Swal.fire({
title: "Alerta!",
text: "Faltan campos por llenar.",
type: "warning",
timer: 3000,
showConfirmButton: false,
});
}
function mensajeError(){
Swal.fire({
type: "error",
title: "Oops...",
text: "¡Lo siento, ocurrió un error!",
});
}
(function () {
"use strict";
window.addEventListener(
"load",
function () {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName("needs-validation");
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(
forms,
function (form) {
form.addEventListener(
"submit",
function (event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add("was-validated");
},
false
);
}
);
},
false
);
})();

2
public/js/administracion/usuarios.js

@ -210,7 +210,7 @@ function cargarListaUsuarios(){
$('#listaUsuarios').DataTable({ $('#listaUsuarios').DataTable({
searchDelay: 400, searchDelay: 400,
ajax: { ajax: {
url: 'api/obtener_lista_tareas_usuarios', url: 'api/obtener_usuarios',
dataSrc: function(json){ dataSrc: function(json){
console.log(json); console.log(json);
return json; return json;

52
resources/views/administracion/forms/nuevo_usuarios.blade.php

@ -12,7 +12,7 @@
<!-- Nav tabs --> <!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist"> {{-- <ul class="nav nav-tabs" role="tablist">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" data-bs-toggle="tab" href="#home" role="tab"> <a class="nav-link active" data-bs-toggle="tab" href="#home" role="tab">
<span>Nuevo usuario</span> <span>Nuevo usuario</span>
@ -23,7 +23,7 @@
<span>Cargar por archivo</span> <span>Cargar por archivo</span>
</a> </a>
</li> </li>
</ul> </ul> --}}
<!-- Tab panes --> <!-- Tab panes -->
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane active" id="home" role="tabpanel"> <div class="tab-pane active" id="home" role="tabpanel">
@ -35,6 +35,7 @@
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="row">
<div class="col-md-8"> <div class="col-md-8">
<div class="mb-3"> <div class="mb-3">
<label class="control-label">Nombre del usuario</label> <label class="control-label">Nombre del usuario</label>
<div class="col-md-12"> <div class="col-md-12">
@ -47,7 +48,7 @@
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<div class="mb-3"> <div class="mb-3">
<label class="control-label">Rol</label> <label class="control-label">Perfiles</label>
<div class="col-md-12"> <div class="col-md-12">
<select id="fk_id_roles" name="usuario[fk_id_roles]" class="form-control form-select roles" required></select> <select id="fk_id_roles" name="usuario[fk_id_roles]" class="form-control form-select roles" required></select>
@ -64,18 +65,20 @@
</div> </div>
<!--/row--> <!--/row-->
<div class="row"> <div class="row">
<div class="col-md-4">
<div class="col-md-8">
<div class="mb-3"> <div class="mb-3">
<label class="control-label">Correo electronico</label> <label class="control-label">Empleado</label>
<div class="col-md-12"> <div class="col-md-12">
<input type="text" class="form-control " name="usuario[email]" placeholder="usuario@shadesdemexico.com" required> <select id="fk_id_roles" name="usuario[fk_id_roles]" class="form-control form-select roles" required></select>
{{-- <small class="form-control-feedback">
This field has error.
</small> --}} {{-- <small class="form-control-feedback">
This is inline help
</small> --}}
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<div class="mb-3"> <div class="mb-3">
<label class="control-label">Estado</label> <label class="control-label">Estado</label>
@ -93,29 +96,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-8">
<div class="mb-3">
<label class="control-label">Nombre completo</label>
<div class="col-md-12">
<input type="text" class="form-control " id="nombre_completo" name="empleado[nombre_completo]" placeholder="Sara Encinas Rivera" required>
</div>
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<label class="control-label">Clave contpaq</label>
<div class="col-md-12">
<input type="input" class="form-control " id="clave_contpaq" name="empleado[clave_contpaq]" placeholder="0159" required>
{{-- <small class="form-control-feedback">
This is inline help
</small> --}}
</div>
</div>
</div>
</div>
</div> </div>
</div> </div>
@ -128,11 +108,9 @@
</form> </form>
</div> </div>
</div> </div>
<div class="tab-pane p-3" id="profile" role="tabpanel"> {{-- <div class="tab-pane p-3" id="profile" role="tabpanel">
<form class="formCargarUsuarios needs-validation" id="formCargarUsuarios" name="formCargarUsuarios" method="POST" enctype="multipart/form-data" novalidate> <form class="formCargarUsuarios needs-validation" id="formCargarUsuarios" name="formCargarUsuarios" method="POST" enctype="multipart/form-data" novalidate>
{{ csrf_field() }} {{ csrf_field() }}
{{-- <input type="hidden" id="prospecto" name="cliente[prospecto]" value="0">
<input type="hidden" name="cliente[tipo_servicio]" value="1"> --}}
<div class="form-body"> <div class="form-body">
<h4 class="card-title">Cargar usuarios</h4> <h4 class="card-title">Cargar usuarios</h4>
<hr class="mt-0 mb-1"> <hr class="mt-0 mb-1">
@ -159,7 +137,7 @@
<button type="submit"class="btn btn-light-info text-info font-weight-medium"> Guardar </button> <button type="submit"class="btn btn-light-info text-info font-weight-medium"> Guardar </button>
</div> </div>
</form> </form>
</div> </div> --}}
</div> </div>

62
resources/views/administracion/perfiles.blade.php

@ -0,0 +1,62 @@
@extends('layouts.app')
@extends('layouts.head')
@extends('layouts.preloader')
@extends('layouts.scripts')
@extends('layouts.topbar')
@extends('layouts.lefsidebar')
@section('content')
@include('administracion.forms.nuevo_usuarios')
@include('administracion.forms.editar_usuarios')
<div id="main-wrapper">
<div class="page-wrapper">
<div class="page-breadcrumb border-bottom">
<div class="row">
<div class="col-lg-3 col-md-4 col-xs-12 justify-content-start d-flex align-items-center">
<h5 class="font-weight-medium text-uppercase mb-0">Perfiles</h5>
</div>
<div class="col-lg-9 col-md-8 col-xs-12 d-flex justify-content-start justify-content-md-end align-self-center" >
<nav aria-label="breadcrumb" class="mt-2">
<ol class="breadcrumb mb-0 p-0">
<li class="breadcrumb-item"><a >Adminstracion</a></li>
<li class="breadcrumb-item active" aria-current="page">Perfiles</li>
</ol>
</nav>
<div class="d-flex justify-content-end">
<button class="btn btn-success text-white ms-3 d-none d-md-block" data-bs-toggle="modal" data-bs-target="#info-header-modal" onclic="limpiarFormulario()"><i class="mdi mdi-plus"></i> Nuevo perfil </button>
</div>
</div>
</div>
</div>
<div class="page-content container-fluid">
<div class="card">
<div class="row no-gutters">
<div class="col-lg-12 col-md-12">
<div class="card-body">
<div class="row mb-4">
<div class="col-md-8">
<h3 class="font-weight-medium">Perfiles</h3>
</div>
<div class="d-flex justify-content-end"></div>
</div>
<div class="table-responsive">
<table id="listaPerfiles" class="table table-bordered no-wrap fs-3 w-100 display" ></table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('script')
<script src="js/administracion/perfiles.js"></script>
@endsection

6
resources/views/layouts/lefsidebar.blade.php

@ -28,6 +28,12 @@
<span class="hide-menu"> Grupos </span> <span class="hide-menu"> Grupos </span>
</a> </a>
</li> </li>
<li class="sidebar-item">
<a href="{{ route('perfiles') }}" class="sidebar-link">
<i class="mdi mdi-cards-variant"></i>
<span class="hide-menu"> Perfiles </span>
</a>
</li>
<li class="sidebar-item"> <li class="sidebar-item">
<a href="{{ route('usuarios') }}" class="sidebar-link"> <a href="{{ route('usuarios') }}" class="sidebar-link">
<i class="mdi mdi-adjust"></i> <i class="mdi mdi-adjust"></i>

10
routes/api/AdministracionApi.php

@ -4,6 +4,7 @@ use App\Models\Empresas;
use App\Models\Grupos; use App\Models\Grupos;
use App\Models\Roles; use App\Models\Roles;
use App\Models\User; use App\Models\User;
use App\Models\Perfiles;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -11,6 +12,15 @@ Route::get('/obtener_empresas', function (Request $request) {
return Empresas::where('activo',1)->get(); return Empresas::where('activo',1)->get();
}); });
Route::get('/obtener_perfiles', function (Request $request) {
return Perfiles::where('activo',1)->get();
});
Route::get('/obtener_usuarios', function (Request $request) {
return User::with('datosEmpleado','roles')->where('users.eliminado',0)->get();
});
// Route::get('/obtener_lista_tareas_usuarios', function (Request $request) { // Route::get('/obtener_lista_tareas_usuarios', function (Request $request) {
// return User::with('datosEmpleado','roles')->where('users.eliminado',0)->get(); // return User::with('datosEmpleado','roles')->where('users.eliminado',0)->get();

4
routes/web/AdminstracionRoute.php

@ -20,7 +20,6 @@ Route::group(['namespace' => 'Administracion', 'middleware' => 'auth' ,'middlewa
Route::post('cargar_lista_usuarios', 'UsuariosController@cargarListasUsuarios'); Route::post('cargar_lista_usuarios', 'UsuariosController@cargarListasUsuarios');
Route::get('grupos','GruposTrabajoController@index')->name('grupos'); Route::get('grupos','GruposTrabajoController@index')->name('grupos');
Route::post('nuevo_grupo','GruposTrabajoController@nuevo_grupo')->name('nuevo_grupo'); Route::post('nuevo_grupo','GruposTrabajoController@nuevo_grupo')->name('nuevo_grupo');
Route::post('agregar_users_grupo','GruposTrabajoController@agregar_users_grupo')->name('agregar_users_grupo'); Route::post('agregar_users_grupo','GruposTrabajoController@agregar_users_grupo')->name('agregar_users_grupo');
@ -28,4 +27,7 @@ Route::group(['namespace' => 'Administracion', 'middleware' => 'auth' ,'middlewa
Route::post('eliminar_grupo','GruposTrabajoController@eliminar_grupo')->name('eliminar_grupo'); Route::post('eliminar_grupo','GruposTrabajoController@eliminar_grupo')->name('eliminar_grupo');
Route::get('perfiles', 'PerfilesController@index')->name('perfiles');
}); });

Loading…
Cancel
Save