Loading app/Exports/ContactosExport.php +32 −10 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\WithHeadings; use App\Models\Contacto; use App\Models\Grupos; class ContactosExport implements FromCollection, WithHeadings { Loading Loading @@ -54,29 +55,51 @@ public function headings(): array private function applyFilters($query) { if (!empty($this->filters['listas'])) { /* if (!empty($this->filters['listas'])) { $query->orWhereHas('listas', function ($q) { $q->whereIn('listas.id', $this->filters['listas']); }); } } */ if (!empty($this->filters['caracteristicas'])) { /* if (!empty($this->filters['caracteristicas'])) { $query->orWhereHas('caracteristicas', function ($q) { $q->whereIn('caracteristicas.id', $this->filters['caracteristicas']); }); } */ if(!empty($this->filters['subgrupos'])){ $query->orWhereHas('subgrupos', function ($q) { $q->whereIn('subgrupos.id', $this->filters['subgrupos']); }); } if(!empty($this->filters['grupos'])){ $query->orWhereHas('grupos', function ($q) { $q->whereIn('grupos.id', $this->filters['grupos']); $grupoId = $this->filters['grupos']; $subgruposIds = Grupos::find($grupoId)->subgrupos->pluck('id')->toArray(); $query->where(function($query) use ($grupoId, $subgruposIds) { $query->whereHas('grupos', function ($q) use ($grupoId) { $q->where('grupos.id', $grupoId); })->orWhereHas('subgrupos', function ($q) use ($subgruposIds) { $q->whereIn('subgrupos.id', $subgruposIds); }); }); } if (!empty($this->filters['cargos'])) { if (!empty($this->filters['fechaInicio']) && !empty($this->filters['fechaFin'])) { // Filtrar por rango de fechas (mes/día) $fechaInicio = $this->filters['fechaInicio']; $fechaFin = $this->filters['fechaFin']; $query->where(function ($query) use ($fechaInicio, $fechaFin) { $query->whereRaw("CONCAT(LPAD(mes_cump, 2, '0'), '-', LPAD(dia_cump, 2, '0')) >= ?", [$fechaInicio]) ->whereRaw("CONCAT(LPAD(mes_cump, 2, '0'), '-', LPAD(dia_cump, 2, '0')) <= ?", [$fechaFin]); }); } /* if (!empty($this->filters['cargos'])) { $query->orWhereHas('cargo', function ($q) { $q->whereIn('cargos.id', $this->filters['cargos']); }); } } */ } private function formatContactoData($contacto) Loading Loading @@ -113,7 +136,6 @@ private function formatContactoData($contacto) 'Tipo' => $contacto->telefonos->pluck('tipo')->join(', ') ?? 'N/A', 'Estatus' => $contacto->telefonos->pluck('estatus')->join(', ') ?? 'N/A', 'Extensión' => $contacto->telefonos->pluck('ext')->join(', ') ?? 'N/A', 'ID Radio' => $contacto->telefonos->pluck('id_radio')->join(', ') ?? 'N/A', 'Observaciones' => $contacto->telefonos->pluck('observaciones')->join(', ') ?? 'N/A', ]); break; Loading Loading @@ -146,7 +168,7 @@ private function getExtraHeadings() $headings[] = 'Cumpleaños'; break; case 'telefonos': $headings = array_merge($headings, ['Número de teléfono', 'Tipo', 'Estatus', 'Extensión', 'ID Radio', 'Observaciones']); $headings = array_merge($headings, ['Número de teléfono', 'Tipo', 'Estatus', 'Extensión', 'Observaciones']); break; case 'conyuge': $headings[] = 'Cónyuge'; Loading app/Http/Controllers/ReporteController.php +10 −3 Original line number Diff line number Diff line Loading @@ -93,12 +93,19 @@ public function export(Request $request) $extraFields = $request->input('exportar', []); $filters = [ 'listas' => $request->input('listas', []), 'caracteristicas' => $request->input('caracteristicas', []), 'grupos' => $request->input('grupos', []), 'cargos' => $request->input('cargos', []), 'subgrupos' => $request->input('subgrupos', []), 'grupos' => $request->input('grupo'), 'fechaInicio' => $request->input('fechaInicio'), 'fechaFin' => $request->input('fechaFin'), ]; // TODO: Crear archivos de exportacion: PDF, Excel return Excel::download(new ContactosExport($contactIds, $extraFields, $filters), 'contactos.xlsx'); //dd($request->all()); } public function getSubgrupos(Int $id) { $grupo = Grupos::find($id); return response()->json($grupo->subgrupos); } } app/Models/Grupos.php +5 −0 Original line number Diff line number Diff line Loading @@ -32,5 +32,10 @@ public function contactos(): BelongsToMany return $this->belongsToMany(Contacto::class, 'contactos_grupos', 'contacto_id', 'grupo_id'); } public function subgrupos(): HasMany { return $this->hasMany(Subgrupo::class, 'grupo_id'); } public $timestamps = false; } resources/views/adminGen/contactos/export.blade.php +62 −23 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ <div class="p-6 bg-gray-100 rounded-lg shadow-md"> <form method="GET" action="" class="space-y-4" onsubmit="event.preventDefault(); logData();"> <!-- Listas --> <div class="flex flex-col space-y-2"> <!-- <div class="flex flex-col space-y-2"> <label for="listas" class="text-gray-700 font-semibold">Listas:</label> <div class="flex space-x-2"> <select id="listas" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> Loading @@ -29,9 +29,9 @@ <button type="button" onclick="agregarEtiqueta('listas', 'listasAgregadas')" class="bg-blue-500 text-white px-3 py-2 rounded-md">Agregar</button> </div> <div id="listasAgregadas" class="flex flex-wrap space-x-2 mt-2"></div> </div> </div> --> <!-- Características --> <div class="flex flex-col space-y-2"> <!-- <div class="flex flex-col space-y-2"> <label for="caracteristicas" class="text-gray-700 font-semibold">Características:</label> <div class="flex space-x-2"> <select id="caracteristicas" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> Loading @@ -43,25 +43,55 @@ <button type="button" onclick="agregarEtiqueta('caracteristicas', 'caracteristicasAgregadas')" class="bg-blue-500 text-white px-3 py-2 rounded-md">Agregar</button> </div> <div id="caracteristicasAgregadas" class="flex flex-wrap space-x-2 mt-2"></div> </div> --> <!-- Contacto --> <div class="flex items-center space-x-2"> <label for="contacto" class="text-gray-700 font-semibold">Agregar Contacto:</label> <input type="text" id="contacto" placeholder="Buscar contacto..." class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md" oninput="buscarContactos(this.value)"> <ul id="sugerenciasContactos" class="border border-gray-300 bg-white rounded-md shadow-md mt-1 hidden"></ul> </div> <!-- Lista de Contactos Agregados --> <div id="contactosAgregados" class="flex flex-wrap space-x-2 mt-4"></div> <!-- Grupos --> <div class="flex flex-col space-y-2"> <label for="grupos" class="text-gray-700 font-semibold">Grupos:</label> <div class="flex space-x-2"> <select id="grupos" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> <select id="grupos" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md" onchange="cargarSubgrupos(this.value)"> <option value="" disabled selected>Selecciona un grupo</option> @foreach($grupos as $grupo) <option value="{{ $grupo->id }}">{{ $grupo->nombre }}</option> @endforeach </select> <button type="button" onclick="agregarEtiqueta('grupos', 'gruposAgregados')" class="bg-blue-500 text-white px-3 py-2 rounded-md">Agregar</button> </div> <div id="gruposAgregados" class="flex flex-wrap space-x-2 mt-2"></div> </div> <!-- Subgrupos --> <div class="flex flex-col space-y-2"> <label for="subgrupos" class="text-gray-700 font-semibold">Subgrupos:</label> <div class="flex space-x-2"> <select id="subgrupos" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> <option value="" disabled selected>Selecciona un subgrupo</option> </select> <button type="button" onclick="agregarEtiqueta('subgrupos', 'subgruposAgregados')" class="bg-blue-500 text-white px-3 py-2 rounded-md">Agregar</button> </div> <div id="subgruposAgregados" class="flex flex-wrap space-x-2 mt-2"></div> </div> <!-- Cargos --> <!-- Rango de fechas --> <div class="flex flex-col space-y-2"> <label for="fechaInicio" class="text-gray-700 font-semibold">Rango de Fechas:</label> <div class="flex space-x-2"> <input type="date" id="fechaInicio" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> <input type="date" id="fechaFin" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> </div> </div> <!-- Cargos --> <!-- <div class="flex flex-col space-y-2"> <label for="cargos" class="text-gray-700 font-semibold">Cargos:</label> <div class="flex space-x-2"> <select id="cargos" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> Loading @@ -73,19 +103,7 @@ <button type="button" onclick="agregarEtiqueta('cargos', 'cargosAgregados')" class="bg-blue-500 text-white px-3 py-2 rounded-md">Agregar</button> </div> <div id="cargosAgregados" class="flex flex-wrap space-x-2 mt-2"></div> </div> <!-- Contacto --> <div class="flex items-center space-x-2"> <label for="contacto" class="text-gray-700 font-semibold">Agregar Contacto:</label> <input type="text" id="contacto" placeholder="Buscar contacto..." class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md" oninput="buscarContactos(this.value)"> <ul id="sugerenciasContactos" class="border border-gray-300 bg-white rounded-md shadow-md mt-1 hidden"></ul> </div> <!-- Lista de Contactos Agregados --> <div id="contactosAgregados" class="flex flex-wrap space-x-2 mt-4"></div> </div> --> <!-- Campos a exportar --> <div class="flex flex-col space-y-2"> Loading Loading @@ -147,7 +165,7 @@ class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md" let contactosSeleccionados = []; let listasSeleccion = []; let caracteristicasSeleccion = []; let gruposSeleccion = []; let subgruposSeleccion = []; let cargosSeleccion = []; let exportarSeleccion = []; Loading Loading @@ -219,14 +237,20 @@ function logData() { const select = document.getElementById('archivo'); const selectedOption = select.options[select.selectedIndex]; const fechaInicio = document.getElementById('fechaInicio').value; const fechaFin = document.getElementById('fechaFin').value; const data = { contactos: contactosSeleccionados, listas: listasSeleccion, caracteristicas: caracteristicasSeleccion, grupos: gruposSeleccion, subgrupos: subgruposSeleccion, cargos: cargosSeleccion, exportar: exportarSeleccion, archivo: selectedOption.value, grupo: document.getElementById('grupos').value, fechaInicio: fechaInicio ? new Date(fechaInicio).toISOString().slice(5, 10) : null, fechaFin: fechaFin ? new Date(fechaFin).toISOString().slice(5, 10) : null, }; fetch('/reportes/contactos/exportar', { Loading Loading @@ -259,6 +283,21 @@ function logData() { showToast(err.message || 'Error al descargar el archivo', 'Error', 'error'); }); } async function cargarSubgrupos(grupoId) { const response = await fetch(`/reportes/subgrupos/${grupoId}`); const subgrupos = await response.json(); const subgruposSelect = document.getElementById('subgrupos'); subgruposSelect.innerHTML = '<option value="" disabled selected>Selecciona un subgrupo</option>'; // Limpiar los subgrupos previos subgrupos.forEach(subgrupo => { const option = document.createElement('option'); option.value = subgrupo.id; option.textContent = subgrupo.nombre; subgruposSelect.appendChild(option); }); } </script> <script> Loading @@ -283,8 +322,8 @@ function agregarEtiqueta(selectId, containerId) { case 'cargos': cargosSeleccion.push(selectedOption.value); break; case 'grupos': gruposSeleccion.push(selectedOption.value); case 'subgrupos': subgruposSeleccion.push(selectedOption.value); break; case 'exportar': exportarSeleccion.push(selectedOption.value); Loading routes/web.php +1 −0 Original line number Diff line number Diff line Loading @@ -156,4 +156,5 @@ Route::get('/reportes/contactos', [ReporteController::class, 'index'])->name('get')->middleware(CheckRoles::class . ':admingen,admin,capturista,lector'); Route::get('/reportes/contactos/buscar', [ReporteController::class, 'find'])->name('find')->middleware(CheckRoles::class . ':admingen,admin,capturista,lector'); Route::post('/reportes/contactos/exportar', [ReporteController::class, 'export'])->name('export')->middleware(CheckRoles::class . ':admingen,admin,capturista,lector'); Route::get('/reportes/subgrupos/{id}', [ReporteController::class, 'getSubgrupos'])->name('subgrupos')->middleware(CheckRoles::class . ':admingen,admin,capturista,lector'); }); No newline at end of file Loading
app/Exports/ContactosExport.php +32 −10 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\WithHeadings; use App\Models\Contacto; use App\Models\Grupos; class ContactosExport implements FromCollection, WithHeadings { Loading Loading @@ -54,29 +55,51 @@ public function headings(): array private function applyFilters($query) { if (!empty($this->filters['listas'])) { /* if (!empty($this->filters['listas'])) { $query->orWhereHas('listas', function ($q) { $q->whereIn('listas.id', $this->filters['listas']); }); } } */ if (!empty($this->filters['caracteristicas'])) { /* if (!empty($this->filters['caracteristicas'])) { $query->orWhereHas('caracteristicas', function ($q) { $q->whereIn('caracteristicas.id', $this->filters['caracteristicas']); }); } */ if(!empty($this->filters['subgrupos'])){ $query->orWhereHas('subgrupos', function ($q) { $q->whereIn('subgrupos.id', $this->filters['subgrupos']); }); } if(!empty($this->filters['grupos'])){ $query->orWhereHas('grupos', function ($q) { $q->whereIn('grupos.id', $this->filters['grupos']); $grupoId = $this->filters['grupos']; $subgruposIds = Grupos::find($grupoId)->subgrupos->pluck('id')->toArray(); $query->where(function($query) use ($grupoId, $subgruposIds) { $query->whereHas('grupos', function ($q) use ($grupoId) { $q->where('grupos.id', $grupoId); })->orWhereHas('subgrupos', function ($q) use ($subgruposIds) { $q->whereIn('subgrupos.id', $subgruposIds); }); }); } if (!empty($this->filters['cargos'])) { if (!empty($this->filters['fechaInicio']) && !empty($this->filters['fechaFin'])) { // Filtrar por rango de fechas (mes/día) $fechaInicio = $this->filters['fechaInicio']; $fechaFin = $this->filters['fechaFin']; $query->where(function ($query) use ($fechaInicio, $fechaFin) { $query->whereRaw("CONCAT(LPAD(mes_cump, 2, '0'), '-', LPAD(dia_cump, 2, '0')) >= ?", [$fechaInicio]) ->whereRaw("CONCAT(LPAD(mes_cump, 2, '0'), '-', LPAD(dia_cump, 2, '0')) <= ?", [$fechaFin]); }); } /* if (!empty($this->filters['cargos'])) { $query->orWhereHas('cargo', function ($q) { $q->whereIn('cargos.id', $this->filters['cargos']); }); } } */ } private function formatContactoData($contacto) Loading Loading @@ -113,7 +136,6 @@ private function formatContactoData($contacto) 'Tipo' => $contacto->telefonos->pluck('tipo')->join(', ') ?? 'N/A', 'Estatus' => $contacto->telefonos->pluck('estatus')->join(', ') ?? 'N/A', 'Extensión' => $contacto->telefonos->pluck('ext')->join(', ') ?? 'N/A', 'ID Radio' => $contacto->telefonos->pluck('id_radio')->join(', ') ?? 'N/A', 'Observaciones' => $contacto->telefonos->pluck('observaciones')->join(', ') ?? 'N/A', ]); break; Loading Loading @@ -146,7 +168,7 @@ private function getExtraHeadings() $headings[] = 'Cumpleaños'; break; case 'telefonos': $headings = array_merge($headings, ['Número de teléfono', 'Tipo', 'Estatus', 'Extensión', 'ID Radio', 'Observaciones']); $headings = array_merge($headings, ['Número de teléfono', 'Tipo', 'Estatus', 'Extensión', 'Observaciones']); break; case 'conyuge': $headings[] = 'Cónyuge'; Loading
app/Http/Controllers/ReporteController.php +10 −3 Original line number Diff line number Diff line Loading @@ -93,12 +93,19 @@ public function export(Request $request) $extraFields = $request->input('exportar', []); $filters = [ 'listas' => $request->input('listas', []), 'caracteristicas' => $request->input('caracteristicas', []), 'grupos' => $request->input('grupos', []), 'cargos' => $request->input('cargos', []), 'subgrupos' => $request->input('subgrupos', []), 'grupos' => $request->input('grupo'), 'fechaInicio' => $request->input('fechaInicio'), 'fechaFin' => $request->input('fechaFin'), ]; // TODO: Crear archivos de exportacion: PDF, Excel return Excel::download(new ContactosExport($contactIds, $extraFields, $filters), 'contactos.xlsx'); //dd($request->all()); } public function getSubgrupos(Int $id) { $grupo = Grupos::find($id); return response()->json($grupo->subgrupos); } }
app/Models/Grupos.php +5 −0 Original line number Diff line number Diff line Loading @@ -32,5 +32,10 @@ public function contactos(): BelongsToMany return $this->belongsToMany(Contacto::class, 'contactos_grupos', 'contacto_id', 'grupo_id'); } public function subgrupos(): HasMany { return $this->hasMany(Subgrupo::class, 'grupo_id'); } public $timestamps = false; }
resources/views/adminGen/contactos/export.blade.php +62 −23 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ <div class="p-6 bg-gray-100 rounded-lg shadow-md"> <form method="GET" action="" class="space-y-4" onsubmit="event.preventDefault(); logData();"> <!-- Listas --> <div class="flex flex-col space-y-2"> <!-- <div class="flex flex-col space-y-2"> <label for="listas" class="text-gray-700 font-semibold">Listas:</label> <div class="flex space-x-2"> <select id="listas" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> Loading @@ -29,9 +29,9 @@ <button type="button" onclick="agregarEtiqueta('listas', 'listasAgregadas')" class="bg-blue-500 text-white px-3 py-2 rounded-md">Agregar</button> </div> <div id="listasAgregadas" class="flex flex-wrap space-x-2 mt-2"></div> </div> </div> --> <!-- Características --> <div class="flex flex-col space-y-2"> <!-- <div class="flex flex-col space-y-2"> <label for="caracteristicas" class="text-gray-700 font-semibold">Características:</label> <div class="flex space-x-2"> <select id="caracteristicas" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> Loading @@ -43,25 +43,55 @@ <button type="button" onclick="agregarEtiqueta('caracteristicas', 'caracteristicasAgregadas')" class="bg-blue-500 text-white px-3 py-2 rounded-md">Agregar</button> </div> <div id="caracteristicasAgregadas" class="flex flex-wrap space-x-2 mt-2"></div> </div> --> <!-- Contacto --> <div class="flex items-center space-x-2"> <label for="contacto" class="text-gray-700 font-semibold">Agregar Contacto:</label> <input type="text" id="contacto" placeholder="Buscar contacto..." class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md" oninput="buscarContactos(this.value)"> <ul id="sugerenciasContactos" class="border border-gray-300 bg-white rounded-md shadow-md mt-1 hidden"></ul> </div> <!-- Lista de Contactos Agregados --> <div id="contactosAgregados" class="flex flex-wrap space-x-2 mt-4"></div> <!-- Grupos --> <div class="flex flex-col space-y-2"> <label for="grupos" class="text-gray-700 font-semibold">Grupos:</label> <div class="flex space-x-2"> <select id="grupos" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> <select id="grupos" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md" onchange="cargarSubgrupos(this.value)"> <option value="" disabled selected>Selecciona un grupo</option> @foreach($grupos as $grupo) <option value="{{ $grupo->id }}">{{ $grupo->nombre }}</option> @endforeach </select> <button type="button" onclick="agregarEtiqueta('grupos', 'gruposAgregados')" class="bg-blue-500 text-white px-3 py-2 rounded-md">Agregar</button> </div> <div id="gruposAgregados" class="flex flex-wrap space-x-2 mt-2"></div> </div> <!-- Subgrupos --> <div class="flex flex-col space-y-2"> <label for="subgrupos" class="text-gray-700 font-semibold">Subgrupos:</label> <div class="flex space-x-2"> <select id="subgrupos" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> <option value="" disabled selected>Selecciona un subgrupo</option> </select> <button type="button" onclick="agregarEtiqueta('subgrupos', 'subgruposAgregados')" class="bg-blue-500 text-white px-3 py-2 rounded-md">Agregar</button> </div> <div id="subgruposAgregados" class="flex flex-wrap space-x-2 mt-2"></div> </div> <!-- Cargos --> <!-- Rango de fechas --> <div class="flex flex-col space-y-2"> <label for="fechaInicio" class="text-gray-700 font-semibold">Rango de Fechas:</label> <div class="flex space-x-2"> <input type="date" id="fechaInicio" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> <input type="date" id="fechaFin" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> </div> </div> <!-- Cargos --> <!-- <div class="flex flex-col space-y-2"> <label for="cargos" class="text-gray-700 font-semibold">Cargos:</label> <div class="flex space-x-2"> <select id="cargos" class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md"> Loading @@ -73,19 +103,7 @@ <button type="button" onclick="agregarEtiqueta('cargos', 'cargosAgregados')" class="bg-blue-500 text-white px-3 py-2 rounded-md">Agregar</button> </div> <div id="cargosAgregados" class="flex flex-wrap space-x-2 mt-2"></div> </div> <!-- Contacto --> <div class="flex items-center space-x-2"> <label for="contacto" class="text-gray-700 font-semibold">Agregar Contacto:</label> <input type="text" id="contacto" placeholder="Buscar contacto..." class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md" oninput="buscarContactos(this.value)"> <ul id="sugerenciasContactos" class="border border-gray-300 bg-white rounded-md shadow-md mt-1 hidden"></ul> </div> <!-- Lista de Contactos Agregados --> <div id="contactosAgregados" class="flex flex-wrap space-x-2 mt-4"></div> </div> --> <!-- Campos a exportar --> <div class="flex flex-col space-y-2"> Loading Loading @@ -147,7 +165,7 @@ class="w-full px-3 py-2 bg-white border border-gray-300 rounded-md" let contactosSeleccionados = []; let listasSeleccion = []; let caracteristicasSeleccion = []; let gruposSeleccion = []; let subgruposSeleccion = []; let cargosSeleccion = []; let exportarSeleccion = []; Loading Loading @@ -219,14 +237,20 @@ function logData() { const select = document.getElementById('archivo'); const selectedOption = select.options[select.selectedIndex]; const fechaInicio = document.getElementById('fechaInicio').value; const fechaFin = document.getElementById('fechaFin').value; const data = { contactos: contactosSeleccionados, listas: listasSeleccion, caracteristicas: caracteristicasSeleccion, grupos: gruposSeleccion, subgrupos: subgruposSeleccion, cargos: cargosSeleccion, exportar: exportarSeleccion, archivo: selectedOption.value, grupo: document.getElementById('grupos').value, fechaInicio: fechaInicio ? new Date(fechaInicio).toISOString().slice(5, 10) : null, fechaFin: fechaFin ? new Date(fechaFin).toISOString().slice(5, 10) : null, }; fetch('/reportes/contactos/exportar', { Loading Loading @@ -259,6 +283,21 @@ function logData() { showToast(err.message || 'Error al descargar el archivo', 'Error', 'error'); }); } async function cargarSubgrupos(grupoId) { const response = await fetch(`/reportes/subgrupos/${grupoId}`); const subgrupos = await response.json(); const subgruposSelect = document.getElementById('subgrupos'); subgruposSelect.innerHTML = '<option value="" disabled selected>Selecciona un subgrupo</option>'; // Limpiar los subgrupos previos subgrupos.forEach(subgrupo => { const option = document.createElement('option'); option.value = subgrupo.id; option.textContent = subgrupo.nombre; subgruposSelect.appendChild(option); }); } </script> <script> Loading @@ -283,8 +322,8 @@ function agregarEtiqueta(selectId, containerId) { case 'cargos': cargosSeleccion.push(selectedOption.value); break; case 'grupos': gruposSeleccion.push(selectedOption.value); case 'subgrupos': subgruposSeleccion.push(selectedOption.value); break; case 'exportar': exportarSeleccion.push(selectedOption.value); Loading
routes/web.php +1 −0 Original line number Diff line number Diff line Loading @@ -156,4 +156,5 @@ Route::get('/reportes/contactos', [ReporteController::class, 'index'])->name('get')->middleware(CheckRoles::class . ':admingen,admin,capturista,lector'); Route::get('/reportes/contactos/buscar', [ReporteController::class, 'find'])->name('find')->middleware(CheckRoles::class . ':admingen,admin,capturista,lector'); Route::post('/reportes/contactos/exportar', [ReporteController::class, 'export'])->name('export')->middleware(CheckRoles::class . ':admingen,admin,capturista,lector'); Route::get('/reportes/subgrupos/{id}', [ReporteController::class, 'getSubgrupos'])->name('subgrupos')->middleware(CheckRoles::class . ':admingen,admin,capturista,lector'); }); No newline at end of file