@extends('layouts.app')
@section('title', __('Purchases'))
@section('content')
<div class="card">
    <div class="card-body">
        <div class="d-flex flex-wrap gap-2 justify-content-between mb-3">
            <form class="d-flex gap-2"><input name="search" class="form-control" value="{{ request('search') }}" placeholder="{{ __('Purchase number or supplier') }}"><button class="btn btn-light"><i class="fa-solid fa-magnifying-glass"></i></button></form>
            <a class="btn btn-success" href="{{ route('purchases.create') }}"><i class="fa-solid fa-cart-plus me-1"></i>{{ __('New Purchase') }}</a>
        </div>
        <div class="table-responsive">
            <table class="table align-middle">
                <thead><tr><th>{{ __('Purchase') }}</th><th>{{ __('Supplier') }}</th><th>{{ __('Total') }}</th><th>{{ __('Paid / Due') }}</th><th>{{ __('Status') }}</th></tr></thead>
                <tbody>@forelse($purchases as $purchase)<tr><td><a class="fw-bold" href="{{ route('purchases.show', $purchase) }}">{{ $purchase->purchase_number }}</a><small class="d-block text-muted">{{ \App\Support\DualDate::format($purchase->purchase_date, 'd M Y') }}</small></td><td>{{ $purchase->supplier?->name ?? '-' }}</td><td class="money">{{ number_format($purchase->subtotal, 2) }} {{ $purchase->currency_code }}</td><td><span class="text-success money">{{ number_format($purchase->paid_amount, 2) }}</span> / <span class="text-danger money">{{ number_format($purchase->due_amount, 2) }}</span></td><td><span class="badge badge-soft rounded-pill">{{ __(ucfirst($purchase->status)) }}</span></td></tr>@empty<tr><td colspan="5" class="text-center text-muted py-5">{{ __('No purchases yet.') }}</td></tr>@endforelse</tbody>
            </table>
        </div>
        {{ $purchases->links('pagination::bootstrap-5') }}
    </div>
</div>
@endsection
