@extends('layouts.app')
@section('title', __('nav.sales_history'))
@section('content')
<div class="d-flex justify-content-between mb-3">
    <h1 class="h4 mb-0">{{ __('nav.sales_history') }}</h1>
    @can('sales.create')<a class="btn btn-success" href="{{ route('sales.create') }}">{{ __('nav.new_sale') }}</a>@endcan
</div>
<form class="row g-2 mb-3">
    <div class="col-md-4"><input class="form-control" name="q" value="{{ request('q') }}" placeholder="{{ __('messages.search') }}"></div>
    <div class="col-md-2"><button class="btn btn-outline-secondary">{{ __('messages.filter') }}</button></div>
</form>
<div class="card">
    <div class="table-responsive">
        <table class="table compact-table mb-0">
            <thead><tr>
                <th>#</th><th>{{ __('messages.customer') }}</th><th>{{ __('messages.line') }}</th>
                <th>{{ __('messages.plan') }}</th><th>{{ __('messages.total') }}</th><th>{{ __('messages.date') }}</th>
            </tr></thead>
            <tbody>
            @forelse($sales as $s)
                <tr>
                    <td><a href="{{ route('sales.show',$s) }}">{{ $s->sale_number }}</a></td>
                    <td>{{ $s->customer?->name }}</td>
                    <td>{{ $s->line?->phone_number }}</td>
                    <td>{{ $s->plan?->name ?? __('messages.no_plan') }}</td>
                    <td>{{ money($s->total) }}</td>
                    <td>{{ format_datetime($s->created_at) }}</td>
                </tr>
            @empty
                <tr><td colspan="6">{{ __('messages.no_results') }}</td></tr>
            @endforelse
            </tbody>
        </table>
    </div>
    @include('partials.pagination', ['paginator' => $sales])
</div>
@endsection
