399 lines
21 KiB
PHP
399 lines
21 KiB
PHP
@extends('layouts.masterbeta')
|
|
|
|
@section('title', 'Click ERP - Office Locations')
|
|
@push('styles')
|
|
<!-- Select2 CSS -->
|
|
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
|
<link href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" rel="stylesheet" />
|
|
@endpush
|
|
|
|
@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;">Office Locations</span>
|
|
@endsection
|
|
|
|
@section('content')
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<div>
|
|
<h4 class="fw-bold mb-1">Global Offices</h4>
|
|
<p class="text-secondary mb-0" style="font-size: 0.9rem;">Manage regional branches and compliance documents.</p>
|
|
</div>
|
|
<button class="btn text-white fw-bold d-flex align-items-center" style="background-color: #5c4df0; border-radius: 8px;" id="btnOpenLocationModal">
|
|
<i class="bi bi-plus-lg me-2"></i> Add Office
|
|
</button>
|
|
</div>
|
|
|
|
<div class="row g-4">
|
|
@forelse($locations as $office)
|
|
<div class="col-md-4">
|
|
<div class="content-card shadow-sm h-100 position-relative">
|
|
<div class="p-4">
|
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
|
<h5 class="fw-bold mb-0 text-dark">
|
|
<i class="bi bi-geo-alt-fill text-danger me-2"></i>{{ $office->city ?? 'N/A' }}, {{ $office->country }}
|
|
</h5>
|
|
<div class="dropdown">
|
|
<button class="btn btn-sm btn-light border-0" type="button" data-bs-toggle="dropdown">
|
|
<i class="bi bi-three-dots-vertical"></i>
|
|
</button>
|
|
<ul class="dropdown-menu dropdown-menu-end shadow-sm">
|
|
<li><a class="dropdown-item btn-edit-location" href="#" data-location="{{ json_encode($office) }}"><i class="bi bi-pencil me-2"></i>Edit Details</a></li>
|
|
<li><a class="dropdown-item text-danger btn-delete-location" href="#" data-id="{{ $office->id }}"><i class="bi bi-trash me-2"></i>Remove</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3 text-secondary small">
|
|
<div><i class="bi bi-building me-2"></i>{{ $office->physical_address ?? 'Address not set' }}</div>
|
|
<div class="mt-1"><i class="bi bi-telephone me-2"></i>{{ $office->office_phone ?? 'Phone not set' }}</div>
|
|
</div>
|
|
|
|
<div class="border-top pt-3 mt-auto">
|
|
<div class="text-secondary fw-bold" style="font-size: 0.7rem; letter-spacing: 0.5px;">COUNTRY MANAGER</div>
|
|
<div class="d-flex align-items-center mt-1">
|
|
<i class="bi bi-person-circle fs-4 text-primary me-2"></i>
|
|
<span class="fw-medium text-dark">{{ $office->manager->name ?? 'Not Assigned' }}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Action Button to navigate to Documents -->
|
|
<!-- 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>
|
|
</div>
|
|
@empty
|
|
<div class="col-12 text-center py-5">
|
|
<div class="text-secondary">No office locations configured yet.</div>
|
|
</div>
|
|
@endforelse
|
|
</div>
|
|
<div class="d-flex justify-content-center mt-4">
|
|
{{ $locations->links('pagination::bootstrap-5') }}
|
|
</div>
|
|
@endsection
|
|
|
|
@push('modals')
|
|
<!-- ADD/EDIT LOCATION MODAL -->
|
|
<div class="modal fade" id="locationModal" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content">
|
|
<div class="modal-header bg-light">
|
|
<h5 class="modal-title fw-bold" id="locationModalTitle">Add Office Location</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
|
|
<form id="locationForm">
|
|
@csrf
|
|
<input type="hidden" id="locationId" name="id">
|
|
<div class="modal-body p-4">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<label class="form-label text-secondary fw-semibold small">Country *</label>
|
|
<!-- Added width: 100% and select2 class -->
|
|
<select class="form-select select2-country" id="loc_country" name="country" required style="width: 100%;">
|
|
<option value=""></option> <!-- Empty option required for Select2 placeholder -->
|
|
@foreach($countries as $country)
|
|
<option value="{{ $country->en_short_name }}">{{ $country->en_short_name }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label text-secondary fw-semibold small">City *</label>
|
|
<input type="text" class="form-control" id="loc_city" name="city" required placeholder="e.g. Accra">
|
|
</div>
|
|
|
|
<div class="col-md-12">
|
|
<label class="form-label text-secondary fw-semibold small">Physical Address</label>
|
|
<input type="text" class="form-control" id="loc_physical_address" name="physical_address">
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label text-secondary fw-semibold small">Office Phone</label>
|
|
<input type="text" class="form-control" id="loc_office_phone" name="office_phone">
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label text-secondary fw-semibold small">ZIP / Postal Code</label>
|
|
<input type="text" class="form-control" id="loc_zip_code" name="zip_code">
|
|
</div>
|
|
|
|
<div class="col-md-12 border-top pt-3 mt-3">
|
|
<label class="form-label text-secondary fw-semibold small">Country Manager</label>
|
|
<select class="form-select" id="loc_country_manager_id" name="country_manager_id">
|
|
<option value="">Select a Manager</option>
|
|
@foreach($staffMembers as $staff)
|
|
<option value="{{ $staff->id }}">{{ $staff->name }} ({{ $staff->designation ?? 'Staff' }})</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer bg-light">
|
|
<button type="button" class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="submit" id="btnSubmitLocation" class="btn text-white btn-sm fw-bold px-4" style="background-color: #5c4df0;">Save Location</button>
|
|
</div>
|
|
</form>
|
|
</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')
|
|
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
|
<script>
|
|
$(document).ready(function() {
|
|
const locationModal = new bootstrap.Modal(document.getElementById('locationModal'));
|
|
const $form = $('#locationForm');
|
|
|
|
$('.select2-country').select2({
|
|
theme: 'bootstrap-5',
|
|
dropdownParent: $('#locationModal'), // Fixes unclickable search box in Bootstrap modals
|
|
placeholder: 'Search for a country...',
|
|
allowClear: true
|
|
});
|
|
|
|
$('#btnOpenLocationModal').on('click', function() {
|
|
$form[0].reset();
|
|
$('#locationId').val('');
|
|
|
|
$('#loc_country').val(null).trigger('change');
|
|
|
|
$('#locationModalTitle').text('Add Office Location');
|
|
$('#btnSubmitLocation').text('Save Location');
|
|
locationModal.show();
|
|
});
|
|
|
|
$('.btn-edit-location').on('click', function(e) {
|
|
e.preventDefault();
|
|
const data = $(this).data('location');
|
|
|
|
$form[0].reset();
|
|
$('#locationId').val(data.id);
|
|
|
|
|
|
$('#loc_country').val(data.country).trigger('change');
|
|
|
|
$('#loc_city').val(data.city);
|
|
$('#loc_physical_address').val(data.physical_address);
|
|
$('#loc_office_phone').val(data.office_phone);
|
|
$('#loc_zip_code').val(data.zip_code);
|
|
$('#loc_country_manager_id').val(data.country_manager_id);
|
|
|
|
$('#locationModalTitle').text('Edit Office Location');
|
|
$('#btnSubmitLocation').text('Update Location');
|
|
locationModal.show();
|
|
});
|
|
|
|
$form.on('submit', function(e) {
|
|
e.preventDefault();
|
|
const recordId = $('#locationId').val();
|
|
const url = recordId ? "{{ url('offices') }}/" + recordId : "{{ route('offices.store') }}";
|
|
let formData = $form.serialize();
|
|
if (recordId) formData += '&_method=PUT';
|
|
|
|
$.ajax({
|
|
url: url,
|
|
type: 'POST',
|
|
data: formData,
|
|
success: function(response) {
|
|
if (response.success) {
|
|
locationModal.hide();
|
|
Swal.fire({
|
|
icon: 'success', title: 'Success!', text: response.message, confirmButtonColor: '#5c4df0'
|
|
}).then(() => location.reload());
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
$('.btn-delete-location').on('click', function(e) {
|
|
e.preventDefault();
|
|
const id = $(this).data('id');
|
|
Swal.fire({
|
|
title: 'Remove Office?', icon: 'warning', showCancelButton: true, confirmButtonColor: '#ef4444', confirmButtonText: 'Yes, remove!'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
url: "{{ url('offices') }}/" + id, type: 'POST', data: { _token: '{{ csrf_token() }}', _method: 'DELETE' },
|
|
success: function(response) {
|
|
if(response.success) location.reload();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
// -- 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
|
|
|
|
|
|
|
|
|
|
|
|
|