bug fixes, daily reports, holidays
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user