233 lines
12 KiB
PHP
233 lines
12 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 -->
|
|
<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>
|
|
</a>
|
|
</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>
|
|
@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();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
@endpush |