@extends('layouts.app') @section('title', 'Document Management') @section('content') @php $fq = array_filter(request()->only(['q','category','status','project_id','client_id','supplier_id','file_type','expiry','date_from','date_to','sort','direction','include_archived']), fn ($v) => $v !== null && $v !== ''); $secondaryCats = ['Invoice', 'Quotation', 'BOQ', 'Purchase Order', 'Supplier Bill', 'HR Document', 'Site Update', 'Compliance', 'Other']; @endphp
@if ($errors->any())
@foreach ($errors->all() as $err)

{{ $err }}

@endforeach
@endif

Document Management

Contracts, drawings, permits and reports

Excel PDF

Total documents

{{ $stats['total_documents'] }}

Approved

{{ $stats['approved_documents'] }}

Expiring soon

{{ $stats['expiring_soon'] }}

Storage used

{{ \Illuminate\Support\Number::fileSize($stats['storage_used'] ?? 0) }}

@foreach($folderCards as $card) @php $cat = $card['category']; $cnt = (int) ($byCategory[$cat] ?? 0); @endphp

{{ $card['label'] }}

{{ $cnt }} active files

Filter list by category

@endforeach
All @foreach($secondaryCats as $sc) {{ $sc }} @endforeach Compliance & expiry Archived
Clear
@if($documents->isEmpty())

No documents found

Upload your first project document or adjust filters.

@else @foreach($documents as $d) @php $exp = $d->expiryState(); $expClass = $exp==='expired'?'text-red-600':($exp==='expiring_soon'?'text-amber-600':'text-slate-500'); $stBadge = match($d->status) { 'Draft' => 's', 'Pending Review' => 'a', 'Approved' => 'g', 'Rejected' => 'r', 'Archived' => 's', 'Expired' => 'r', default => 's', }; $linkBits = collect([ $d->project ? ['Project', route('projects.show', $d->project), $d->project->name] : null, $d->client ? ['Client', route('clients.show', $d->client), $d->client->company_name] : null, $d->invoice ? ['Invoice', route('invoices.show', $d->invoice), $d->invoice->invoice_number] : null, $d->quotation ? ['Quotation', route('quotations.show', $d->quotation), $d->quotation->reference_number] : null, $d->purchaseOrder ? ['PO', route('procurement.orders.show', $d->purchaseOrder), $d->purchaseOrder->po_number] : null, $d->supplierBill ? ['Bill', route('procurement.bills.show', $d->supplierBill), $d->supplierBill->bill_number] : null, ])->filter(); @endphp @endforeach
Document Category Linked to Status Expiry Ver Uploaded Size Actions
{{ $d->title }}

{{ $d->displayFileName() }}

{{ $d->document_category }} @forelse($linkBits as $bit) {{ $bit[2] }} @empty General @endforelse {{ $d->status }} {{ $d->expiry_date?->format('M j, Y') ?? '—' }} v{{ $d->version_number }} {{ $d->uploader?->name ?? '—' }}
{{ $d->created_at?->format('M j, Y') }}
{{ \Illuminate\Support\Number::fileSize($d->file_size) }} View @if($d->file_path) Download @endif @if(!$d->isArchived()) Version @endif
{{ $documents->links() }}
@endif
@endsection