bug fixes, daily reports, holidays

This commit is contained in:
Kwesi Banson Jnr
2026-09-08 08:01:08 +00:00
parent 26f23c825a
commit c96e49ccdf
23 changed files with 1148 additions and 160 deletions

View File

@@ -38,9 +38,11 @@
</div>
</div>
<div>
@if(Auth::User()->id == $showclient->auth_user_id)
<button type="button" class="btn btn-sm btn-outline-primary edit-client-btn" data-client-id="{{ $showclient->id }}" data-bs-toggle="modal" data-bs-target="#editClientModal">
<i class="bi bi-pencil me-1"></i> Edit Client
</button>
@endif
</div>
</div>

View File

@@ -0,0 +1,104 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Daily Report Submitted</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: #333333;
background-color: #f4f7f6;
margin: 0;
padding: 20px;
}
.email-wrapper {
max-width: 600px;
margin: 0 auto;
background-color: #ffffff;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.email-header {
background-color: #5c4df0;
color: #ffffff;
padding: 20px;
text-align: center;
}
.email-header h2 {
margin: 0;
font-size: 20px;
font-weight: 600;
}
.email-body {
padding: 30px;
}
.info-row {
margin-bottom: 15px;
border-bottom: 1px solid #eeeeee;
padding-bottom: 10px;
}
.label {
font-weight: 600;
color: #666666;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.value {
font-size: 16px;
color: #111111;
margin-top: 4px;
}
.report-content {
background-color: #f8f9fc;
border-left: 4px solid #5c4df0;
padding: 15px;
margin-top: 15px;
white-space: pre-wrap;
font-size: 15px;
color: #444444;
}
.email-footer {
background-color: #fcfcfc;
padding: 15px;
text-align: center;
font-size: 12px;
color: #999999;
border-top: 1px solid #eeeeee;
}
</style>
</head>
<body>
<div class="email-wrapper">
<div class="email-header">
<h2>New Daily Report Submitted</h2>
</div>
<div class="email-body">
<p>Hello Management,</p>
<p>A new daily activity report has been submitted and is ready for review.</p>
<div class="info-row">
<div class="label">Staff Member</div>
<div class="value">{{ $user->name }}</div>
</div>
<div class="info-row">
<div class="label">Report Date</div>
<div class="value">{{ \Carbon\Carbon::parse($report->report_date)->format('l, d F Y') }}</div>
</div>
<div class="info-row" style="border-bottom: none;">
<div class="label">Activities & Progress</div>
<div class="report-content">{{ $report->content }}</div>
</div>
</div>
<div class="email-footer">
This is an automated notification from the Click ERP System. Please do not reply directly to this email.
</div>
</div>
</body>
</html>

View File

@@ -43,6 +43,7 @@
@stack('styles')
<script>
var base_url = "{!! url('/') !!}";
const currentUserId = {{ auth()->id() ?? 'null' }};
</script>
</head>
<body>
@@ -60,8 +61,10 @@
@stack('modals')
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<!-- <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> -->
<script src="{{ asset('public/assets/libs/jquery-3.7.1.min.js') }}"></script>
<script src="{{ asset('public/assets/libs/bootstrap/js/bootstrap5.3.2.js') }}"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> -->
<!-- SweetAlert2 CDN -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Select2 JS (Place right after jQuery) -->

View File

@@ -39,6 +39,9 @@
<div class="sidebar-heading mt-2">Others</div>
<a href="{{ url('/reports') }}" class="sidebar-nav-item {{ request()->is('reports*') ? 'active' : '' }}">
<i class="bi bi-buildings me-2"></i> Reports
</a>
<a href="{{ url('/offices') }}" class="sidebar-nav-item {{ request()->is('offices*') ? 'active' : '' }}">
<i class="bi bi-buildings me-2"></i> Office Locations
</a>

View File

@@ -58,11 +58,16 @@
</div>
<!-- Action Button to navigate to Documents -->
<div class="mt-4">
<a href="{{ route('offices.documents', $office->id) }}" class="btn btn-light border w-100 fw-medium d-flex justify-content-between align-items-center">
<span><i class="bi bi-folder-check me-2 text-primary"></i> Documents</span>
<span class="badge bg-primary rounded-pill">{{ $office->documents->count() }}</span>
<!-- Action Buttons -->
<div class="mt-4 d-flex gap-2">
<a href="{{ route('offices.documents', $office->id) }}" class="btn btn-light border w-50 fw-medium d-flex justify-content-between align-items-center" style="font-size: 0.85rem;">
<span><i class="bi bi-folder-check me-1 text-primary"></i> Docs</span>
<span class="badge bg-primary rounded-pill">{{ $office->documents->count() ?? 0 }}</span>
</a>
<button type="button" class="btn btn-light border w-50 fw-medium d-flex justify-content-between align-items-center btn-manage-holidays" data-id="{{ $office->id }}" data-location="{{ $office->city }}, {{ $office->country }}" data-country-code="{{ $office->country_code ?? 'GH' }}" style="font-size: 0.85rem;">
<span><i class="bi bi-calendar-event me-1 text-warning"></i> Holidays</span>
<span class="badge bg-warning text-dark rounded-pill" id="holiday-count-{{ $office->id }}">{{ $office->holidays->count() ?? 0 }}</span>
</button>
</div>
</div>
</div>
@@ -142,6 +147,60 @@
</div>
</div>
</div>
<!-- MANAGE HOLIDAYS OFFCANVAS -->
<div class="offcanvas offcanvas-end shadow" tabindex="-1" id="holidaysOffcanvas" style="width: 500px;">
<div class="offcanvas-header bg-light border-bottom">
<div>
<h5 class="offcanvas-title fw-bold" id="holidaysOffcanvasTitle">Public Holidays</h5>
<div class="text-secondary small" id="holidaysLocationName">Loading...</div>
</div>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body p-4">
<!-- API Auto-Fetch Alert Box -->
<!-- <div class="alert alert-info d-flex justify-content-between align-items-center p-3 mb-4">
<div>
<strong class="d-block" style="font-size: 0.85rem;">Auto-populate Holidays for the year {{ now()->year }} </strong>
<small>Fetch standard holidays via Nager.Date API.</small>
</div>
<button class="btn btn-sm btn-info text-white fw-bold" id="btnFetchApiHolidays">
<i class="bi bi-cloud-arrow-down me-1"></i> Fetch
</button>
</div> -->
<!-- Add Custom Holiday Form -->
<form id="addHolidayForm" class="mb-4 border p-3 rounded bg-light">
<h6 class="fw-bold mb-3" style="font-size: 0.85rem;">Add Custom / Local Holiday</h6>
<input type="hidden" id="holiday_location_id" name="office_location_id">
<div class="row g-2">
<div class="col-md-7">
<input type="text" class="form-control form-control-sm" name="name" placeholder="Holiday Name" required>
</div>
<div class="col-md-5">
<input type="date" class="form-control form-control-sm" name="holiday_date" required>
</div>
<div class="col-12 mt-2 d-flex justify-content-between align-items-center">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="is_recurring" value="1" id="holidayRecurring">
<label class="form-check-label small text-secondary" for="holidayRecurring">Recurs annually</label>
</div>
<button type="submit" class="btn btn-sm btn-primary fw-bold px-3">Add</button>
</div>
</div>
</form>
<!-- Holidays List -->
<h6 class="fw-bold border-bottom pb-2 mb-3 text-secondary" style="font-size: 0.85rem;">Current Holidays</h6>
<div class="table-responsive">
<table class="table table-hover table-sm align-middle">
<tbody id="holidaysListBody">
<!-- Loaded via AJAX -->
</tbody>
</table>
</div>
</div>
</div>
@endpush
@push('scripts')
@@ -228,6 +287,112 @@
}
});
});
// -- HOLIDAYS OFFCANVAS LOGIC --
const holidaysOffcanvas = new bootstrap.Offcanvas(document.getElementById('holidaysOffcanvas'));
let currentHolidayLocationId = null;
let currentCountryCode = null;
// 1. Open Offcanvas & Load Data
$('.btn-manage-holidays').on('click', function(e) {
e.preventDefault();
currentHolidayLocationId = $(this).data('id');
currentCountryCode = $(this).data('country-code');
console.log(currentHolidayLocationId);
$('#holidaysLocationName').text($(this).data('location'));
$('#holiday_location_id').val(currentHolidayLocationId);
loadHolidays();
holidaysOffcanvas.show();
});
// 2. Fetch Data via AJAX
function loadHolidays() {
$('#holidaysListBody').html('<tr><td colspan="3" class="text-center py-4"><span class="spinner-border spinner-border-sm text-primary"></span></td></tr>');
// Ensure you have a route set up in web.php like: Route::get('/offices/{id}/holidays', [OfficeController::class, 'getHolidays']);
$.get("{{ url('offices') }}/" + currentHolidayLocationId + "/holidays", function(holidays) {
let html = '';
if (holidays.length === 0) {
html = '<tr><td colspan="3" class="text-center text-secondary py-3 small">No holidays added yet.</td></tr>';
} else {
holidays.forEach(h => {
let dateObj = new Date(h.holiday_date);
let formattedDate = dateObj.toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' });
let recurringBadge = h.is_recurring ? '<span class="badge bg-info bg-opacity-10 text-info" style="font-size: 0.65rem;">Recurring</span>' : '';
html += `
<tr>
<td class="fw-medium text-dark" style="font-size: 0.85rem;">${formattedDate}</td>
<td style="font-size: 0.85rem;">${h.name} ${recurringBadge}</td>
<td class="text-end">
<button class="btn btn-sm text-danger btn-delete-holiday p-1" data-id="${h.id}"><i class="bi bi-x-circle"></i></button>
</td>
</tr>
`;
});
}
$('#holidaysListBody').html(html);
});
}
// 3. Add Custom Holiday
$('#addHolidayForm').on('submit', function(e) {
e.preventDefault();
let $btn = $(this).find('button[type="submit"]');
$btn.prop('disabled', true).html('<i class="spinner-border spinner-border-sm"></i>');
$.ajax({
url: "{{ url('holidays') }}", // Adjust to your store route
type: 'POST',
data: $(this).serialize() + '&_token={{ csrf_token() }}',
success: function() {
$('#addHolidayForm')[0].reset();
loadHolidays();
},
complete: function() { $btn.prop('disabled', false).text('Add'); }
});
});
// 4. Delete Holiday
$(document).on('click', '.btn-delete-holiday', function() {
let id = $(this).data('id');
if(confirm('Remove this holiday?')) {
$.ajax({
url: "{{ url('holidays') }}/" + id,
type: 'DELETE',
data: { _token: '{{ csrf_token() }}' },
success: function() { loadHolidays(); }
});
}
});
// 5. Auto-Fetch API Holidays
$('#btnFetchApiHolidays').on('click', function() {
let $btn = $(this);
let originalText = $btn.html();
$btn.prop('disabled', true).html('<i class="spinner-border spinner-border-sm"></i>');
$.ajax({
url: "{{ url('offices') }}/" + currentHolidayLocationId + "/holidays/import",
type: 'POST',
data: { _token: '{{ csrf_token() }}', year: new Date().getFullYear(), country_code: currentCountryCode },
success: function(res) {
Swal.fire({ icon: 'success', title: 'Imported!', text: res.message, timer: 2000, showConfirmButton: false });
loadHolidays();
},
error: function() {
Swal.fire('Error', 'Ensure the location has a valid ISO Country Code (e.g., GH).', 'error');
},
complete: function() { $btn.prop('disabled', false).html(originalText); }
});
});
});
</script>
@endpush
@endpush

View File

@@ -0,0 +1,216 @@
@extends('layouts.masterbeta')
@section('title', 'Click ERP - My Daily Reports')
@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;">Daily Reports</span>
@endsection
@section('content')
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<h4 class="fw-bold mb-1">My Daily Reports</h4>
<p class="text-secondary mb-0" style="font-size: 0.9rem;">Submit and track your daily activity and progress.</p>
</div>
<button class="btn text-white fw-bold d-flex align-items-center" style="background-color: #5c4df0; border-radius: 8px;" data-bs-toggle="modal" data-bs-target="#submitReportModal">
<i class="bi bi-plus-lg me-2"></i> Submit Report
</button>
</div>
<div class="content-card shadow-sm bg-white rounded-3 overflow-hidden">
<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">Report Date</th>
<th>Content Preview</th>
<th>Submitted At</th>
<th class="text-end pe-4">Action</th>
</tr>
</thead>
<tbody>
@forelse($reports as $report)
<tr>
<td class="ps-4 fw-medium text-dark">
<i class="bi bi-calendar-check text-primary me-2"></i>
{{ \Carbon\Carbon::parse($report->report_date)->format('D, d M Y') }}
</td>
<td class="text-secondary" style="max-width: 400px; font-size: 0.9rem;">
{{ Str::limit(strip_tags($report->content), 80) }}
</td>
<td class="text-secondary" style="font-size: 0.85rem;">
<i class="bi bi-clock me-1"></i> {{ $report->created_at->format('d M Y, H:i') }}
</td>
<td class="text-end pe-4">
<button class="btn btn-sm btn-light text-primary btn-view-report"
data-date="{{ \Carbon\Carbon::parse($report->report_date)->format('D, d M Y') }}"
data-content="{{ htmlspecialchars($report->content) }}">
<i class="bi bi-eye"></i> View
</button>
</td>
</tr>
@empty
<tr>
<td colspan="4" class="text-center py-5 text-secondary">
<i class="bi bi-journal-x fs-1 text-muted mb-2 d-block"></i>
No reports submitted yet.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
@if($reports->hasPages())
<div class="card-footer bg-white border-top p-3 d-flex justify-content-center">
{{ $reports->links('pagination::bootstrap-5') }}
</div>
@endif
</div>
@endsection
@push('modals')
<!-- SUBMIT REPORT MODAL -->
<div class="modal fade" id="submitReportModal" 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">Submit Daily Report</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form id="submitReportForm">
@csrf
<div class="modal-body p-4">
<!-- <div id="reportModalAlert"></div> -->
<div class="mb-3">
<label class="form-label text-secondary fw-semibold small">Report Date *</label>
<input type="date" class="form-control" name="report_date" id="report_date" required max="{{ now()->format('Y-m-d') }}" value="{{ now()->format('Y-m-d') }}">
<div class="form-text text-muted" style="font-size: 0.75rem;">Standard submission window is 48 hours from the report date.</div>
</div>
<div class="mb-3">
<label class="form-label text-secondary fw-semibold small">Activities & Progress *</label>
<textarea class="form-control" name="content" id="report_content" rows="8" required placeholder="Detail your tasks, achievements, and blockers for the day..."></textarea>
</div>
</div>
<div class="modal-footer bg-light border-top-0">
<button type="button" class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal">Cancel</button>
<button type="submit" id="btnSaveReport" class="btn text-white btn-sm fw-bold px-4" style="background-color: #5c4df0;">
Submit Report
</button>
</div>
</form>
</div>
</div>
</div>
<!-- VIEW REPORT MODAL -->
<div class="modal fade" id="viewReportModal" 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">Report Details: <span id="viewReportDate" class="text-primary"></span></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body p-4">
<div class="bg-light p-3 rounded border" style="white-space: pre-wrap;" id="viewReportContent"></div>
</div>
<div class="modal-footer border-top-0">
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@endpush
@push('scripts')
<script>
$(document).ready(function() {
$('#submitReportForm').on('submit', function(e) {
e.preventDefault();
let $form = $(this);
let $submitBtn = $('#btnSaveReport');
let originalText = $submitBtn.html();
$submitBtn.html('<span class="spinner-border spinner-border-sm me-2"></span>Sending...').prop('disabled', true);
// Clear previous validation errors
$form.find('.is-invalid').removeClass('is-invalid');
$form.find('.invalid-feedback').remove();
$.ajax({
url: "{{ url('reports') }}",
type: 'POST',
data: $form.serialize(),
success: function(response) {
if(response.success) {
$('#submitReportModal').modal('hide');
Swal.fire({
icon: 'success',
title: 'Report Submitted!',
text: response.message,
showConfirmButton: false,
timer: 1500
}).then(() => location.reload());
}
},
error: function(xhr) {
if (xhr.status === 422) {
let errors = xhr.responseJSON.errors;
// If the 48-hour validation fails, trigger a SweetAlert warning
if (errors.report_date && errors.report_date[0].includes('48-hour')) {
$('#submitReportModal').modal('hide');
Swal.fire({
icon: 'warning',
title: 'Submission Locked',
text: errors.report_date[0],
confirmButtonColor: '#5c4df0'
}).then(() => $('#submitReportModal').modal('show')); // reopen if they dismiss
} else {
// For standard field validation, show inline text errors
$.each(errors, function(key, value) {
let $input = $form.find('[name="' + key + '"]');
if ($input.length) {
$input.addClass('is-invalid');
$input.parent().append('<div class="invalid-feedback d-block fw-medium">' + value[0] + '</div>');
}
});
}
} else {
// Generic server errors
Swal.fire({
icon: 'error',
title: 'Server Error',
text: 'An unexpected error occurred. Please try again.',
confirmButtonColor: '#5c4df0'
});
}
},
complete: function() {
$submitBtn.html(originalText).prop('disabled', false);
}
});
});
// View Report Modal Population
$('.btn-view-report').on('click', function() {
$('#viewReportDate').text($(this).data('date'));
$('#viewReportContent').text($(this).data('content'));
new bootstrap.Modal(document.getElementById('viewReportModal')).show();
});
// Reset modal on close
$('#submitReportModal').on('hidden.bs.modal', function () {
$('#submitReportForm')[0].reset();
$('#report_date').val("{{ now()->format('Y-m-d') }}");
$('#submitReportForm').find('.is-invalid').removeClass('is-invalid');
$('#submitReportForm').find('.invalid-feedback').remove();
});
});
</script>
@endpush

View File

@@ -33,9 +33,16 @@
<p class="text-secondary mb-0" style="font-size: 0.9rem;">Manage employee profiles, department roles, and system access.</p>
</div>
<div class="d-flex gap-2">
@if(strtolower(Auth::user()->department->name) == 'directors')
<button class="btn btn-warning btn-sm fw-bold" data-bs-toggle="modal" data-bs-target="#overrideModal">
<i class="bi bi-unlock-fill me-1"></i> Grant Report Override
</button>
@endif
@if(in_array(strtolower(Auth::user()->department->name) , ['directors', 'human resource']))
<button class="btn text-white fw-bold d-flex align-items-center" style="background-color: #5c4df0; border-radius: 8px;" id="btnOpenStaffModal">
<i class="bi bi-person-plus me-2"></i> Add Employee
</button>
@endif
</div>
</div>
@@ -264,82 +271,141 @@
</div>
</div>
<!-- VIEW STAFF PROFILE MODAL -->
<div class="modal fade" id="viewStaffModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-light">
<h5 class="modal-title fw-bold" id="viewStaffTitle">Staff Profile Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body p-4">
<!-- Basic Info Header -->
<div class="d-flex align-items-center mb-4 pb-3 border-bottom">
<div id="viewStaffAvatarContainer" class="me-3">
<!-- Dynamic Avatar inserted via JS -->
</div>
<div>
<h4 class="fw-bold mb-1 text-dark" id="viewStaffName">---</h4>
<p class="text-secondary mb-1 small" id="viewStaffDesignation">---</p>
<span id="viewStaffStatusBadge" class="badge">---</span>
</div>
<div class="modal fade" id="viewStaffModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-light">
<h5 class="modal-title fw-bold" id="viewStaffTitle">Staff Profile Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body p-4">
<!-- Basic Info Header -->
<div class="d-flex align-items-center mb-4 pb-3 border-bottom">
<div id="viewStaffAvatarContainer" class="me-3">
<!-- Dynamic Avatar inserted via JS -->
</div>
<div>
<h4 class="fw-bold mb-1 text-dark" id="viewStaffName">---</h4>
<p class="text-secondary mb-1 small" id="viewStaffDesignation">---</p>
<span id="viewStaffStatusBadge" class="badge">---</span>
</div>
</div>
<!-- Info Grid -->
<div class="row g-3 mb-4">
<div class="col-md-4">
<div class="text-secondary small fw-semibold">WORK EMAIL</div>
<div class="fw-medium text-dark small" id="viewStaffEmail">---</div>
<!-- Info Grid -->
<div class="row g-3 mb-4">
<div class="col-md-4">
<div class="text-secondary small fw-semibold">WORK EMAIL</div>
<div class="fw-medium text-dark small" id="viewStaffEmail">---</div>
</div>
<div class="col-md-4">
<div class="text-secondary small fw-semibold">PHONE NUMBER</div>
<div class="fw-medium text-dark small" id="viewStaffPhone">---</div>
</div>
<div class="col-md-4">
<div class="text-secondary small fw-semibold">STAFF ID</div>
<div class="fw-medium text-dark small" id="viewStaffCode">---</div>
</div>
<div class="col-md-4">
<div class="text-secondary small fw-semibold">PERSONAL EMAIL</div>
<div class="fw-medium text-dark small" id="viewStaffPersonalEmail">---</div>
</div>
<div class="col-md-4">
<div class="text-secondary small fw-semibold">LOCATION / COUNTRY</div>
<div class="fw-medium text-dark small" id="viewStaffLocation">---</div>
</div>
<div class="col-md-4">
<div class="text-secondary small fw-semibold">ANNUAL LEAVE BALANCE</div>
<div class="fw-medium text-dark small"><span id="viewStaffLeaveBalance">0</span> Days</div>
</div>
</div>
<div class="col-md-4">
<div class="text-secondary small fw-semibold">PHONE NUMBER</div>
<div class="fw-medium text-dark small" id="viewStaffPhone">---</div>
</div>
<div class="col-md-4">
<div class="text-secondary small fw-semibold">STAFF ID</div>
<div class="fw-medium text-dark small" id="viewStaffCode">---</div>
</div>
<div class="col-md-4">
<div class="text-secondary small fw-semibold">PERSONAL EMAIL</div>
<div class="fw-medium text-dark small" id="viewStaffPersonalEmail">---</div>
</div>
<div class="col-md-4">
<div class="text-secondary small fw-semibold">LOCATION / COUNTRY</div>
<div class="fw-medium text-dark small" id="viewStaffLocation">---</div>
</div>
<div class="col-md-4">
<div class="text-secondary small fw-semibold">ANNUAL LEAVE BALANCE</div>
<div class="fw-medium text-dark small"><span id="viewStaffLeaveBalance">0</span> Days</div>
</div>
</div>
<!-- Emergency Contacts Table Section -->
<h6 class="fw-bold text-dark mb-3"><i class="bi bi-shield-exclamation me-2 text-danger"></i>Emergency Contacts & Dependents</h6>
<div class="table-responsive">
<table class="table table-bordered table-sm align-middle mb-0">
<thead class="table-light">
<tr>
<th>Full Name</th>
<th>Relationship</th>
<th>Phone</th>
<th>Medical Details</th>
</tr>
</thead>
<tbody id="viewStaffDependentsList">
<tr>
<td colspan="4" class="text-center text-secondary py-3">Loading emergency contacts...</td>
</tr>
</tbody>
</table>
<!-- Emergency Contacts Table Section -->
<h6 class="fw-bold text-dark mb-3"><i class="bi bi-shield-exclamation me-2 text-danger"></i>Emergency Contacts & Dependents</h6>
<div class="table-responsive">
<table class="table table-bordered table-sm align-middle mb-0">
<thead class="table-light">
<tr>
<th>Full Name</th>
<th>Relationship</th>
<th>Phone</th>
<th>Medical Details</th>
</tr>
</thead>
<tbody id="viewStaffDependentsList">
<tr>
<td colspan="4" class="text-center text-secondary py-3">Loading emergency contacts...</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal">Close</button>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@push('modals')
<!-- OVERRIDE MODAL) -->
<div class="modal fade" id="overrideModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-light border-bottom-0">
<h5 class="modal-title fw-bold">Grant Report Override</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form id="overrideForm">
@csrf
<div class="modal-body p-4">
<div class="alert alert-warning d-flex align-items-center p-3 mb-4" style="font-size: 0.85rem;">
<i class="bi bi-exclamation-triangle-fill me-2 fs-5 text-warning"></i>
<div>Temporarily unlock the submission window for a staff member to file a past daily report.</div>
</div>
<div id="overrideModalAlert"></div>
<div class="mb-3">
<label class="form-label text-secondary fw-semibold small">Staff Member *</label>
<select class="form-select select2-staff" id="override_user_id" name="user_id" required style="width: 100%;">
<option value=""></option>
<!-- Assuming you pass $staffMembers from the controller -->
@foreach($allstaffMembers as $staff)
<option value="{{ $staff->id }}">{{ $staff->name }}</option>
@endforeach
</select>
</div>
<div class="row g-3">
<div class="col-md-6">
<label class="form-label text-secondary fw-semibold small">Locked Report Date *</label>
<input type="date" class="form-control" name="report_date" required max="{{ now()->format('Y-m-d') }}">
</div>
<div class="col-md-6">
<label class="form-label text-secondary fw-semibold small">Validity Window</label>
<div class="input-group">
<input type="number" class="form-control" name="hours_valid" value="24" min="1" max="72">
<span class="input-group-text bg-light text-secondary">Hours</span>
</div>
<div class="form-text text-muted" style="font-size: 0.75rem;">Time given to submit before locking again.</div>
</div>
</div>
</div>
<div class="modal-footer bg-light border-top-0">
<button type="button" class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal">Cancel</button>
<button type="submit" id="btnSubmitOverride" class="btn text-white btn-sm fw-bold px-4" style="background-color: #5c4df0;">
Grant Access
</button>
</div>
</form>
</div>
</div>
</div>
@endpush
@endpush
@push('scripts')
@@ -477,78 +543,157 @@
});
});
$(document).ready(function() {
const viewModal = new bootstrap.Modal(document.getElementById('viewStaffModal'));
$(document).ready(function() {
const viewModal = new bootstrap.Modal(document.getElementById('viewStaffModal'));
$('.btn-view-staff').on('click', function() {
const staffId = $(this).data('id');
$('.btn-view-staff').on('click', function() {
const staffId = $(this).data('id');
// Reset fields to loading state
$('#viewStaffName').text('Loading...');
$('#viewStaffDesignation').text('');
$('#viewStaffEmail').text('');
$('#viewStaffPhone').text('');
$('#viewStaffCode').text('');
$('#viewStaffPersonalEmail').text('');
$('#viewStaffLocation').text('');
$('#viewStaffLeaveBalance').text('');
$('#viewStaffDependentsList').html('<tr><td colspan="4" class="text-center text-secondary py-3">Loading...</td></tr>');
// Reset fields to loading state
$('#viewStaffName').text('Loading...');
$('#viewStaffDesignation').text('');
$('#viewStaffEmail').text('');
$('#viewStaffPhone').text('');
$('#viewStaffCode').text('');
$('#viewStaffPersonalEmail').text('');
$('#viewStaffLocation').text('');
$('#viewStaffLeaveBalance').text('');
$('#viewStaffDependentsList').html('<tr><td colspan="4" class="text-center text-secondary py-3">Loading...</td></tr>');
viewModal.show();
// Fetch staff details via AJAX
$.ajax({
url: "{{ url('staff') }}/" + staffId + "/details", // Match your route endpoint
type: 'GET',
success: function(response) {
if (response.success) {
let staff = response.staff;
$('#viewStaffName').text(staff.name);
$('#viewStaffDesignation').text(staff.designation || 'Staff Member');
$('#viewStaffEmail').text(staff.email || 'N/A');
$('#viewStaffPhone').text(staff.phone || 'N/A');
$('#viewStaffCode').text(staff.staff_id || 'N/A');
$('#viewStaffPersonalEmail').text(staff.personal_email || 'N/A');
$('#viewStaffLocation').text(staff.location_country || 'N/A');
$('#viewStaffLeaveBalance').text(staff.annual_leave_balance ?? 0);
// Status Badge
let badgeClass = staff.status === 'ACTIVE' ? 'bg-success bg-opacity-10 text-success' : 'bg-warning bg-opacity-10 text-warning';
$('#viewStaffStatusBadge').attr('class', `badge ${badgeClass} px-3 py-1`).text(staff.status);
// Avatar setup
if (staff.profile_pic) {
$('#viewStaffAvatarContainer').html(`<img src="{{ asset('public/storage') }}/${staff.profile_pic}" class="rounded-circle border" style="width: 70px; height: 70px; object-fit: cover;">`);
} else {
let initials = staff.name.split(' ').map(n => n[0]).join('').substring(0, 2).toUpperCase();
$('#viewStaffAvatarContainer').html(`<div class="rounded-circle bg-light text-primary fw-bold d-flex align-items-center justify-content-center border" style="width: 70px; height: 70px; font-size: 1.5rem;">${initials}</div>`);
}
// Dependents Table population
let dependentsHtml = '';
if (response.dependents && response.dependents.length > 0) {
response.dependents.forEach(dep => {
dependentsHtml += `
<tr>
<td class="fw-bold">${dep.fullname}</td>
<td><span class="badge bg-secondary bg-opacity-10 text-dark border">${dep.relationship}</span></td>
<td>${dep.phone || 'N/A'}</td>
<td class="text-secondary">${dep.medical_details || 'None'}</td>
</tr>
`;
});
} else {
dependentsHtml = `<tr><td colspan="4" class="text-center text-secondary py-3">No emergency contacts found.</td></tr>`;
}
$('#viewStaffDependentsList').html(dependentsHtml);
}
},
error: function() {
$('#viewStaffName').text('Error loading profile details.');
}
});
});
viewModal.show();
// Fetch staff details via AJAX
$.ajax({
url: "{{ url('staff') }}/" + staffId + "/details", // Match your route endpoint
type: 'GET',
success: function(response) {
if (response.success) {
let staff = response.staff;
$('#viewStaffName').text(staff.name);
$('#viewStaffDesignation').text(staff.designation || 'Staff Member');
$('#viewStaffEmail').text(staff.email || 'N/A');
$('#viewStaffPhone').text(staff.phone || 'N/A');
$('#viewStaffCode').text(staff.staff_id || 'N/A');
$('#viewStaffPersonalEmail').text(staff.personal_email || 'N/A');
$('#viewStaffLocation').text(staff.location_country || 'N/A');
$('#viewStaffLeaveBalance').text(staff.annual_leave_balance ?? 0);
// Status Badge
let badgeClass = staff.status === 'ACTIVE' ? 'bg-success bg-opacity-10 text-success' : 'bg-warning bg-opacity-10 text-warning';
$('#viewStaffStatusBadge').attr('class', `badge ${badgeClass} px-3 py-1`).text(staff.status);
// Avatar setup
if (staff.profile_pic) {
$('#viewStaffAvatarContainer').html(`<img src="{{ asset('public/storage') }}/${staff.profile_pic}" class="rounded-circle border" style="width: 70px; height: 70px; object-fit: cover;">`);
} else {
let initials = staff.name.split(' ').map(n => n[0]).join('').substring(0, 2).toUpperCase();
$('#viewStaffAvatarContainer').html(`<div class="rounded-circle bg-light text-primary fw-bold d-flex align-items-center justify-content-center border" style="width: 70px; height: 70px; font-size: 1.5rem;">${initials}</div>`);
}
// Dependents Table population
let dependentsHtml = '';
if (response.dependents && response.dependents.length > 0) {
response.dependents.forEach(dep => {
dependentsHtml += `
<tr>
<td class="fw-bold">${dep.fullname}</td>
<td><span class="badge bg-secondary bg-opacity-10 text-dark border">${dep.relationship}</span></td>
<td>${dep.phone || 'N/A'}</td>
<td class="text-secondary">${dep.medical_details || 'None'}</td>
</tr>
`;
});
} else {
dependentsHtml = `<tr><td colspan="4" class="text-center text-secondary py-3">No emergency contacts found.</td></tr>`;
}
$('#viewStaffDependentsList').html(dependentsHtml);
}
},
error: function() {
$('#viewStaffName').text('Error loading profile details.');
}
});
});
});
// OVERRIDE
$(document).ready(function() {
// Initialize Select2 for the staff dropdown
$('.select2-staff').select2({
theme: 'bootstrap-5',
dropdownParent: $('#overrideModal'),
placeholder: 'Search staff member...',
allowClear: true
});
$('#overrideForm').on('submit', function(e) {
e.preventDefault();
let $form = $(this);
let $submitBtn = $('#btnSubmitOverride');
let originalText = $submitBtn.html();
let $alertBox = $('#overrideModalAlert');
$submitBtn.html('<span class="spinner-border spinner-border-sm me-2"></span>Processing...').prop('disabled', true);
$alertBox.html('');
$form.find('.is-invalid').removeClass('is-invalid');
$form.find('.invalid-feedback').remove();
$.ajax({
url: base_url + '/overrides', // Ensure you mapped this route in web.php to ReportOverrideController@store
type: 'POST',
data: $form.serialize(),
success: function(response) {
if(response.success) {
$alertBox.html(`
<div class="alert alert-success d-flex align-items-center p-3" role="alert">
<i class="bi bi-check-circle-fill me-2 fs-5 text-success"></i>
<div style="font-size: 0.85rem;">${response.message}</div>
</div>
`);
setTimeout(() => {
$('#overrideModal').modal('hide');
}, 1500);
}
},
error: function(xhr) {
if (xhr.status === 422) {
let errors = xhr.responseJSON.errors;
$.each(errors, function(key, value) {
let $input = $form.find('[name="' + key + '"]');
if ($input.length) {
$input.addClass('is-invalid');
$input.parent().append('<div class="invalid-feedback d-block fw-medium" style="font-size: 0.75rem;">' + value[0] + '</div>');
}
});
} else {
$alertBox.html(`
<div class="alert alert-danger d-flex align-items-center p-3" role="alert">
<i class="bi bi-x-circle-fill me-2 fs-5 text-danger"></i>
<div style="font-size: 0.85rem;">Server error. Please try again.</div>
</div>
`);
}
},
complete: function() {
$submitBtn.html(originalText).prop('disabled', false);
}
});
});
// Clean up modal on close
$('#overrideModal').on('hidden.bs.modal', function () {
$('#overrideForm')[0].reset();
$('#override_user_id').val(null).trigger('change');
$('#overrideModalAlert').html('');
$('#overrideForm').find('.is-invalid').removeClass('is-invalid');
$('#overrideForm').find('.invalid-feedback').remove();
});
});
</script>
@endpush