cotizaweb/resources/views/auditoria/index.blade_funcional.php
jesusfb 161fcee049
Some checks are pending
Deploy to EC2 cotiza / deploy (push) Waiting to run
first commit
2026-04-24 12:53:27 -07:00

169 lines
3.5 KiB
PHP

@extends('layouts.app')
@section('content')
<div class="container-fluid">
<h3 class="mb-3">🔐 Bitácora de Auditoría</h3>
<div class="card">
<div class="card-header bg-dark text-white">
Registro de cambios del sistema
</div>
<div class="card-body">
<table class="table table-bordered table-striped align-middle">
<thead class="bg-light">
<tr>
<th>Fecha</th>
<th>Usuario</th>
<th>Evento</th>
<th>Modelo</th>
<th>ID</th>
<th>IP</th>
<th>Detalle</th>
</tr>
</thead>
<tbody>
@foreach($audits as $audit)
<tr>
<td>{{ $audit->created_at }}</td>
<td>{{ $audit->user->name ?? 'Sistema' }}</td>
<td>
<span class="badge
@if($audit->event=='created') bg-success
@elseif($audit->event=='updated') bg-warning text-dark
@elseif($audit->event=='deleted') bg-danger
@else bg-secondary
@endif">
{{ strtoupper($audit->event) }}
</span>
</td>
<td>{{ class_basename($audit->auditable_type) }}</td>
<td>{{ $audit->auditable_id }}</td>
<td>{{ $audit->ip_address }}</td>
<td>
<button class="btn btn-sm btn-secondary"
data-toggle="modal"
data-target="#audit{{ $audit->id }}">
Ver detalle
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
{{ $audits->links() }}
</div>
</div>
{{-- ================= MODALES FUERA DE LA TABLA (CORRECTO) ================= --}}
@foreach($audits as $audit)
<div class="modal fade" id="audit{{ $audit->id }}" tabindex="-1" role="dialog">
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content">
<div class="modal-header bg-dark text-white">
<h5 class="modal-title">
🔍 Auditoría #{{ $audit->id }} — {{ class_basename($audit->auditable_type) }}
</h5>
<button type="button" class="close text-white" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<p>
<strong>Evento:</strong>
<span class="badge
@if($audit->event=='created') bg-success
@elseif($audit->event=='updated') bg-warning text-dark
@elseif($audit->event=='deleted') bg-danger
@else bg-secondary
@endif">
{{ strtoupper($audit->event) }}
</span>
</p>
<p>
<strong>Usuario:</strong> {{ $audit->user->name ?? 'Sistema' }} |
<strong>Modelo:</strong> {{ class_basename($audit->auditable_type) }} |
<strong>ID:</strong> {{ $audit->auditable_id }}
</p>
<hr>
@php
$antes = $audit->old_values ?? [];
$despues = $audit->new_values ?? [];
/* Quitamos basura técnica para el usuario */
$ignorar = ['password','remember_token','created_at','updated_at'];
$campos = collect(array_keys(array_merge($antes, $despues)))
->reject(fn($c) => in_array($c, $ignorar))
->values();
@endphp
<h5 class="mb-3">📌 Cambios detectados</h5>
<table class="table table-bordered">
<thead>
<tr>
<th>Campo</th>
<th class="text-danger">ANTES</th>
<th class="text-success">DESPUÉS</th>
</tr>
</thead>
<tbody>
@foreach($campos as $campo)
<tr>
<td><strong>{{ ucfirst(str_replace('_',' ', $campo)) }}</strong></td>
<td class="bg-danger text-white">
@if(is_array($antes[$campo] ?? null))
<pre class="text-white mb-0">
{{ json_encode($antes[$campo], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) }}
</pre>
@else
{{ $antes[$campo] ?? '—' }}
@endif
</td>
<td class="bg-success text-white">
@if(is_array($despues[$campo] ?? null))
<pre class="text-white mb-0">
{{ json_encode($despues[$campo], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) }}
</pre>
@else
{{ $despues[$campo] ?? '—' }}
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
@endforeach
{{-- ================= FIN MODALES ================= --}}
</div>
@endsection