259 lines
12 KiB
PHP
259 lines
12 KiB
PHP
@extends('layouts.masterbeta')
|
|
|
|
@section('title', 'Click ERP - Document Vault')
|
|
|
|
@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;">Document Vault</span>
|
|
@endsection
|
|
|
|
@section('content')
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<div>
|
|
<h4 class="fw-bold mb-1">Document Vault</h4>
|
|
<p class="text-secondary mb-0" style="font-size: 0.9rem;">Store, manage, and share company or staff documents securely.</p>
|
|
</div>
|
|
<button class="btn text-white fw-bold d-flex align-items-center" style="background-color: #5c4df0; border-radius: 8px;" id="btnOpenUploadModal">
|
|
<i class="bi bi-upload me-2"></i> Upload Document
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Filters & Search -->
|
|
<div class="content-card mb-4 p-3 shadow-sm">
|
|
<form action="{{ route('documents.index') }}" method="GET">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<div class="input-group">
|
|
<span class="input-group-text bg-white border-end-0 text-secondary"><i class="bi bi-search"></i></span>
|
|
<input type="text" name="search" value="{{ request('search') }}" class="form-control bg-white border-start-0 ps-0" placeholder="Search by document name or description...">
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<select name="category" class="form-select bg-white" onchange="this.form.submit()">
|
|
<option value="">Category: All</option>
|
|
@foreach($categories as $cat)
|
|
<option value="{{ $cat }}" {{ request('category') == $cat ? 'selected' : '' }}>{{ $cat }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<button type="submit" class="btn text-white w-100" style="background-color: #5c4df0;">
|
|
<i class="bi bi-funnel me-1"></i> Filter
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Documents Grid / Table -->
|
|
<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>Category</th>
|
|
<th>Description</th>
|
|
<th>Format</th>
|
|
<th>Uploaded</th>
|
|
<th class="text-end">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@forelse($documents as $doc)
|
|
<tr>
|
|
<td>
|
|
<div class="fw-bold text-dark d-flex align-items-center">
|
|
<i class="bi bi-file-earmark-text text-primary me-2 fs-5"></i>
|
|
{{ $doc->name }}
|
|
</div>
|
|
</td>
|
|
<td>
|
|
@if($doc->category)
|
|
<span class="badge bg-secondary bg-opacity-10 text-dark border">{{ $doc->category }}</span>
|
|
@else
|
|
<span class="text-secondary small">Uncategorized</span>
|
|
@endif
|
|
</td>
|
|
<td>
|
|
<span class="text-secondary small text-truncate d-inline-block" style="max-width: 250px;" title="{{ $doc->description }}">
|
|
{{ $doc->description ?? 'No description provided.' }}
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<span class="text-uppercase fw-bold text-secondary" style="font-size: 0.75rem;">{{ $doc->file_extension }}</span>
|
|
</td>
|
|
<td class="text-secondary small">
|
|
<div>{{ $doc->created_at ? $doc->created_at->format('M d, Y') : 'N/A' }}</div>
|
|
</td>
|
|
<td class="text-end">
|
|
<a href="{{ asset('public/storage/' . $doc->filename) }}" target="_blank" class="btn btn-sm btn-light text-primary me-1" title="View / Download">
|
|
<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="6" class="text-center py-4 text-secondary">No documents found in the Vault.</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="p-3 border-top">
|
|
{{ $documents->links('pagination::bootstrap-5') }}
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('modals')
|
|
<!-- UPLOAD DOCUMENT MODAL -->
|
|
<div class="modal fade" id="uploadDocModal" 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">Upload Document</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
|
|
<form id="uploadDocForm" enctype="multipart/form-data">
|
|
@csrf
|
|
<div class="modal-body p-4">
|
|
<div id="uploadModalAlert"></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. Employee Handbook 2026">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label text-secondary fw-semibold small">Category</label>
|
|
<!-- <input type="text" class="form-control" name="category" placeholder="e.g. Policy, Contract, Template"> -->
|
|
<select name="client_id" id="modal_client_id" class="form-select select2-field">
|
|
<option value="">Category</option>
|
|
@foreach($document_types as $type)
|
|
<option value="{{ $type }}">{{ $type }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label text-secondary fw-semibold small">Description</label>
|
|
<textarea class="form-control" name="description" rows="2" placeholder="Brief details about this file..."></textarea>
|
|
</div>
|
|
|
|
<div class="mb-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,.xls,.xlsx">
|
|
</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="btnSubmitDoc" class="btn text-white btn-sm fw-bold px-4" style="background-color: #5c4df0;">Upload File</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endpush
|
|
|
|
@push('scripts')
|
|
<script>
|
|
$(document).ready(function() {
|
|
const uploadModal = new bootstrap.Modal(document.getElementById('uploadDocModal'));
|
|
const $form = $('#uploadDocForm');
|
|
|
|
$('#btnOpenUploadModal').on('click', function() {
|
|
$form[0].reset();
|
|
$('#uploadModalAlert').html('');
|
|
uploadModal.show();
|
|
});
|
|
|
|
// Handle AJAX Upload
|
|
$form.on('submit', function(e) {
|
|
e.preventDefault();
|
|
const $btn = $('#btnSubmitDoc');
|
|
const originalText = $btn.html();
|
|
|
|
$btn.html('<span class="spinner-border spinner-border-sm me-2"></span> Uploading...');
|
|
$btn.prop('disabled', true);
|
|
|
|
let formData = new FormData(this);
|
|
|
|
$.ajax({
|
|
url: "{{ route('documents.store') }}",
|
|
type: 'POST',
|
|
data: formData,
|
|
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. Check file size/type.';
|
|
$('#uploadModalAlert').html(`
|
|
<div class="alert alert-danger py-2 px-3 small" role="alert">
|
|
<i class="bi bi-exclamation-triangle-fill me-2"></i> ${msg}
|
|
</div>
|
|
`);
|
|
},
|
|
complete: function() {
|
|
$btn.html(originalText).prop('disabled', false);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Handle Delete Document
|
|
$('.btn-delete-doc').on('click', function() {
|
|
const docId = $(this).data('id');
|
|
|
|
Swal.fire({
|
|
title: 'Delete Document?',
|
|
text: "This file will be permanently removed from storage.",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#ef4444',
|
|
cancelButtonColor: '#6c757d',
|
|
confirmButtonText: 'Yes, delete it!'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
url: "{{ url('documents') }}/" + docId,
|
|
type: 'POST',
|
|
data: {
|
|
_token: '{{ csrf_token() }}',
|
|
_method: 'DELETE'
|
|
},
|
|
success: function(response) {
|
|
if (response.success) {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Deleted!',
|
|
text: response.message,
|
|
confirmButtonColor: '#5c4df0'
|
|
}).then(() => location.reload());
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
@endpush |