Updated ERP with new modules and features

This commit is contained in:
Kwesi Banson
2026-09-22 08:06:31 +00:00
parent 71bc103fee
commit 5174e82e51
53 changed files with 3706 additions and 203 deletions

View File

@@ -0,0 +1,203 @@
@extends('layouts.masterbeta')
@section('title', 'Click ERP - System Activity Logs')
@section('breadcrumbs')
<a href="{{ url('/') }}" class="text-secondary text-decoration-none"><i class="bi bi-house me-2"></i></a>
<i class="bi bi-chevron-right text-secondary me-2" style="font-size: 0.8rem;"></i>
<span class="fw-bold" style="font-size: 0.95rem;">Activity Logs</span>
@endsection
@section('content')
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<h4 class="fw-bold mb-1">System Audit Trail</h4>
<p class="text-secondary mb-0" style="font-size: 0.9rem;">Monitor user actions, data modifications, and security events.</p>
</div>
</div>
<div class="content-card shadow-sm bg-white rounded-3 overflow-hidden">
<!-- Filters Section -->
<div class="p-3 border-bottom bg-light bg-opacity-50">
<form method="GET" action="{{ route('activity-logs.index') }}" class="row g-2 align-items-center">
<div class="col-md-4">
<div class="input-group input-group-sm">
<span class="input-group-text bg-white border-end-0 text-secondary"><i class="bi bi-search"></i></span>
<input type="text" class="form-control bg-white border-start-0 ps-0" name="search" value="{{ request('search') }}" placeholder="Search user or entity (e.g. VpnConfig)...">
</div>
</div>
<div class="col-md-2">
<select class="form-select form-select-sm" name="action_type">
<option value="">All Actions</option>
<option value="created" {{ request('action_type') == 'created' ? 'selected' : '' }}>Created</option>
<option value="updated" {{ request('action_type') == 'updated' ? 'selected' : '' }}>Updated</option>
<option value="deleted" {{ request('action_type') == 'deleted' ? 'selected' : '' }}>Deleted</option>
</select>
</div>
<div class="col-md-2">
<input type="date" class="form-control form-control-sm" name="date_from" value="{{ request('date_from') }}" placeholder="From">
</div>
<div class="col-md-2">
<input type="date" class="form-control form-control-sm" name="date_to" value="{{ request('date_to') }}" placeholder="To">
</div>
<div class="col-md-2 d-flex gap-1">
<button type="submit" class="btn btn-sm btn-dark w-100 fw-bold">Filter</button>
<a href="{{ route('activity-logs.index') }}" class="btn btn-sm btn-outline-secondary" title="Clear Filters"><i class="bi bi-x-lg"></i></a>
</div>
</form>
</div>
<!-- Data Table -->
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="table-light text-secondary" style="font-size: 0.85rem;">
<tr>
<th class="ps-4">Timestamp</th>
<th>User</th>
<th>Action</th>
<th>Entity Context</th>
<th class="text-end pe-4">Details</th>
</tr>
</thead>
<tbody>
@forelse($logs as $log)
<tr>
<td class="ps-4">
<div class="fw-bold text-dark" style="font-size: 0.9rem;">{{ $log->created_at->format('d M Y') }}</div>
<div class="text-secondary small">{{ $log->created_at->format('h:i:s A') }}</div>
</td>
<td>
<div class="fw-bold text-dark">{{ $log->user->name ?? 'System/Guest' }}</div>
<div class="text-secondary font-monospace" style="font-size: 0.75rem;">{{ $log->ip_address }}</div>
</td>
<td>
@php
$badgeColor = match($log->action) {
'created' => 'success',
'updated' => 'primary',
'deleted' => 'danger',
default => 'secondary'
};
@endphp
<span class="badge bg-{{ $badgeColor }} bg-opacity-10 text-{{ $badgeColor }} text-uppercase">
{{ $log->action }}
</span>
</td>
<td>
<div class="text-dark fw-medium" style="font-size: 0.85rem;">
{{ class_basename($log->loggable_type) }} <span class="text-secondary">#{{ $log->loggable_id }}</span>
</div>
</td>
<td class="text-end pe-4">
@if(!empty($log->old_data) || !empty($log->new_data))
<button class="btn btn-sm btn-light text-primary border fw-bold btn-view-changes"
data-action="{{ $log->action }}"
data-old="{{ json_encode($log->old_data) }}"
data-new="{{ json_encode($log->new_data) }}"
data-entity="{{ class_basename($log->loggable_type) }} #{{ $log->loggable_id }}">
<i class="bi bi-eye me-1"></i> View Data
</button>
@else
<span class="text-muted small">No Context</span>
@endif
</td>
</tr>
@empty
<tr>
<td colspan="5" class="text-center py-5 text-secondary">
<i class="bi bi-journal-x fs-1 text-muted mb-2 d-block"></i>
No activity records found.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<!-- Pagination -->
@if($logs->hasPages())
<div class="card-footer bg-white border-top p-3 d-flex justify-content-center">
{{ $logs->links('pagination::bootstrap-5') }}
</div>
@endif
</div>
@endsection
@push('modals')
<!-- VIEW CHANGES MODAL -->
<div class="modal fade" id="viewChangesModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content">
<div class="modal-header bg-light border-bottom-0">
<h5 class="modal-title fw-bold" id="modalEntityTitle">Data Context</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body p-4 bg-light">
<div class="row g-3">
<div class="col-md-6" id="oldDataCol">
<h6 class="fw-bold text-danger mb-2"><i class="bi bi-dash-circle me-1"></i> Previous State</h6>
<div class="card border-danger border-opacity-25 shadow-sm">
<div class="card-body p-0">
<pre class="m-0 p-3 text-danger" style="font-size: 0.8rem; overflow-x: auto;" id="oldDataContainer"></pre>
</div>
</div>
</div>
<div class="col-md-6" id="newDataCol">
<h6 class="fw-bold text-success mb-2"><i class="bi bi-plus-circle me-1"></i> New State</h6>
<div class="card border-success border-opacity-25 shadow-sm">
<div class="card-body p-0">
<pre class="m-0 p-3 text-success" style="font-size: 0.8rem; overflow-x: auto;" id="newDataContainer"></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endpush
@push('scripts')
<script>
$(document).ready(function() {
$('.btn-view-changes').on('click', function() {
let action = $(this).data('action');
let entity = $(this).data('entity');
// Parse the JSON data passed from the Blade attributes
let oldData = $(this).data('old');
let newData = $(this).data('new');
$('#modalEntityTitle').text('Context: ' + entity);
let $oldCol = $('#oldDataCol');
let $newCol = $('#newDataCol');
let $oldContainer = $('#oldDataContainer');
let $newContainer = $('#newDataContainer');
// Reset layout
$oldCol.show().removeClass('col-md-12').addClass('col-md-6');
$newCol.show().removeClass('col-md-12').addClass('col-md-6');
// Format JSON cleanly, checking if null
let formattedOld = oldData && oldData !== "null" ? JSON.stringify(oldData, null, 4) : 'No previous data (or field was empty).';
let formattedNew = newData && newData !== "null" ? JSON.stringify(newData, null, 4) : 'No new data recorded.';
$oldContainer.text(formattedOld);
$newContainer.text(formattedNew);
// Adjust layout based on action type to maximize reading space
if (action === 'created') {
$oldCol.hide();
$newCol.removeClass('col-md-6').addClass('col-md-12');
} else if (action === 'deleted') {
$newCol.hide();
$oldCol.removeClass('col-md-6').addClass('col-md-12');
}
$('#viewChangesModal').modal('show');
});
});
</script>
@endpush