209 lines
11 KiB
PHP
209 lines
11 KiB
PHP
@extends('layouts.masterbeta')
|
|
|
|
@section('title', 'Click ERP - Office Documents')
|
|
|
|
@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>
|
|
<a href="{{ route('offices.index') }}" class="text-secondary text-decoration-none">Offices</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;">{{ $location->city }} Documents</span>
|
|
@endsection
|
|
|
|
@section('content')
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<div>
|
|
<h4 class="fw-bold mb-1"><i class="bi bi-folder-check text-primary me-2"></i>{{ $location->city }}, {{ $location->country }}</h4>
|
|
<p class="text-secondary mb-0" style="font-size: 0.9rem;">Manage compliance files, leases, and local registrations.</p>
|
|
</div>
|
|
<button class="btn text-white fw-bold d-flex align-items-center" style="background-color: #5c4df0; border-radius: 8px;" id="btnOpenDocModal">
|
|
<i class="bi bi-upload me-2"></i> Upload Document
|
|
</button>
|
|
</div>
|
|
|
|
<div class="content-card shadow-sm">
|
|
<div class="table-responsive">
|
|
<table class="table table-custom table-hover mb-0 align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th>Document Name</th>
|
|
<th>Format</th>
|
|
<th>Validity Period</th>
|
|
<th>Next Renewal</th>
|
|
<th class="text-end">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@forelse($location->documents as $doc)
|
|
<tr>
|
|
<td class="fw-bold text-dark">{{ $doc->name }}</td>
|
|
<td class="text-uppercase small fw-bold text-secondary">{{ $doc->file_extension }}</td>
|
|
<td>
|
|
<span class="badge bg-secondary bg-opacity-10 text-dark border">{{ $doc->validity_period }}</span>
|
|
</td>
|
|
<td>
|
|
@if($doc->validity_period === 'On Demand')
|
|
<span class="text-secondary small">N/A</span>
|
|
@else
|
|
@php
|
|
// Highlight if renewal is approaching within 30 days or past due
|
|
$isUrgent = $doc->next_renewal_date && \Carbon\Carbon::parse($doc->next_renewal_date)->isPast() || \Carbon\Carbon::parse($doc->next_renewal_date)->diffInDays(now()) <= 30;
|
|
@endphp
|
|
<span class="small fw-medium {{ $isUrgent ? 'text-danger' : 'text-dark' }}">
|
|
@if($isUrgent) <i class="bi bi-exclamation-circle-fill me-1"></i> @endif
|
|
{{ $doc->next_renewal_date ? \Carbon\Carbon::parse($doc->next_renewal_date)->format('M d, Y') : 'Not Set' }}
|
|
</span>
|
|
@endif
|
|
</td>
|
|
<td class="text-end">
|
|
<a href="{{ asset('public/storage/' . $doc->file_path) }}" target="_blank" class="btn btn-sm btn-light text-primary me-1" title="View File">
|
|
<i class="bi bi-download"></i>
|
|
</a>
|
|
<button class="btn btn-sm btn-light text-danger btn-delete-doc" data-id="{{ $doc->id }}" title="Delete">
|
|
<i class="bi bi-trash"></i>
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="5" class="text-center py-4 text-secondary">No regional documents uploaded yet.</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('modals')
|
|
<!-- UPLOAD DOCUMENT MODAL -->
|
|
<div class="modal fade" id="uploadOfficeDocModal" 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">Archive Regional Document</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
|
|
<form id="officeDocForm" enctype="multipart/form-data">
|
|
@csrf
|
|
<div class="modal-body p-4">
|
|
<div id="officeDocAlert"></div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label text-secondary fw-semibold small">Document Name *</label>
|
|
<input type="text" class="form-control" name="name" required placeholder="e.g. Business Operating License">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label text-secondary fw-semibold small">Validity Period *</label>
|
|
<select class="form-select" id="validityPeriodSelect" name="validity_period" required>
|
|
<option value="On Demand">On Demand (No Expiration)</option>
|
|
<option value="Monthly">Monthly</option>
|
|
<option value="Quarterly">Quarterly</option>
|
|
<option value="Biannually">Biannually</option>
|
|
<option value="Yearly">Yearly</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- This wrapper is hidden by default in JS if 'On Demand' is selected -->
|
|
<div class="mb-3" id="renewalDateWrapper" style="display: none;">
|
|
<label class="form-label text-secondary fw-semibold small">Next Renewal Date *</label>
|
|
<input type="date" class="form-control" id="nextRenewalDateInput" name="next_renewal_date">
|
|
</div>
|
|
|
|
<div class="mb-3 border-top pt-3 mt-3">
|
|
<label class="form-label text-secondary fw-semibold small">Select File * (Max: 10MB)</label>
|
|
<input type="file" class="form-control" name="file" required accept=".pdf,.jpg,.jpeg,.png,.doc,.docx">
|
|
</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="btnSubmitOfficeDoc" class="btn text-white btn-sm fw-bold px-4" style="background-color: #5c4df0;">Upload Document</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endpush
|
|
|
|
@push('scripts')
|
|
<script>
|
|
$(document).ready(function() {
|
|
const uploadModal = new bootstrap.Modal(document.getElementById('uploadOfficeDocModal'));
|
|
const $form = $('#officeDocForm');
|
|
|
|
$('#btnOpenDocModal').on('click', function() {
|
|
$form[0].reset();
|
|
$('#officeDocAlert').html('');
|
|
$('#renewalDateWrapper').hide(); // Reset to hidden
|
|
$('#nextRenewalDateInput').prop('required', false);
|
|
uploadModal.show();
|
|
});
|
|
|
|
// Dynamic logic for Validity Period selection
|
|
$('#validityPeriodSelect').on('change', function() {
|
|
if ($(this).val() === 'On Demand') {
|
|
$('#renewalDateWrapper').slideUp();
|
|
$('#nextRenewalDateInput').prop('required', false).val('');
|
|
} else {
|
|
$('#renewalDateWrapper').slideDown();
|
|
$('#nextRenewalDateInput').prop('required', true);
|
|
}
|
|
});
|
|
|
|
// Submit logic
|
|
$form.on('submit', function(e) {
|
|
e.preventDefault();
|
|
const $btn = $('#btnSubmitOfficeDoc');
|
|
const originalText = $btn.html();
|
|
|
|
$btn.html('<span class="spinner-border spinner-border-sm me-2"></span> Uploading...');
|
|
$btn.prop('disabled', true);
|
|
|
|
$.ajax({
|
|
url: "{{ route('offices.documents.store', $location->id) }}",
|
|
type: 'POST',
|
|
data: new FormData(this),
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(response) {
|
|
if (response.success) {
|
|
uploadModal.hide();
|
|
Swal.fire({
|
|
icon: 'success', title: 'Uploaded!', text: response.message, confirmButtonColor: '#5c4df0'
|
|
}).then(() => location.reload());
|
|
}
|
|
},
|
|
error: function(xhr) {
|
|
let msg = xhr.responseJSON?.message || 'Failed to upload document.';
|
|
$('#officeDocAlert').html(`<div class="alert alert-danger py-2 px-3 small"><i class="bi bi-exclamation-triangle-fill me-2"></i> ${msg}</div>`);
|
|
},
|
|
complete: function() {
|
|
$btn.html(originalText).prop('disabled', false);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Delete logic
|
|
$('.btn-delete-doc').on('click', function() {
|
|
const docId = $(this).data('id');
|
|
Swal.fire({
|
|
title: 'Delete Document?', icon: 'warning', showCancelButton: true, confirmButtonColor: '#ef4444', confirmButtonText: 'Yes, delete it!'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
url: "{{ url('offices/documents/delete') }}/" + docId,
|
|
type: 'POST',
|
|
data: { _token: '{{ csrf_token() }}', _method: 'DELETE' },
|
|
success: function(response) {
|
|
if (response.success) location.reload();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
@endpush |