@extends ('layouts/template')

@section('content')
<div class="p-3 mcp-theme-1" id="patients-list">
    <div class="card">

        <div class="card-header px-2 py-1 d-flex align-items-center">
            <strong class="mr-4">
                <i class="fas fa-file-invoice-dollar"></i>
                Supply Orders
            </strong>
        </div>

        <div class="card-body p-0">
            <div class="p-3">
                @include('app.mcp.supply_orders_filters')
            </div>
            <table class="table table-sm table-striped border-top p-0 m-0">
                <thead class="bg-light">
                    <tr>
                        <th class="border-0">Date</th>
                        <th class="border-0">Patient</th>
                        <th class="border-0">Product</th>
                        <th class="border-0">Memo</th>
                        <th class="border-0">Is Cancelled</th>
                        <th class="border-0">Shipment</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($supplyOrders as $supplyOrder)
                    <tr>
                        <td>{{ friendlier_date_time($supplyOrder->created_at)}}</td>
                        <td>{{ $supplyOrder->client->displayName() }} -</td>
                        <td>{{ $supplyOrder->product->title }}</td>
                        <td style="width: 300px;">{{ $supplyOrder->reason }}</td>
                        <td>{{ $supplyOrder->is_cancelled ? 'Yes' : 'No' }}</td>
                        <td class="px-2">
                            @if($supplyOrder->shipment_id)
                            <i class="fa fa-building"></i>
                            {{$supplyOrder->shipment->status ? $supplyOrder->shipment->status : 'CREATED'}}
                            @elseif($supplyOrder->is_cleared_for_shipment)
                            <span class="text-info">
                                <i class="fa fa-user-nurse"></i>
                                Cleared for shipment
                            </span>
                            @else
                            <span class="text-warning-mellow">
                                <i class="fa fa-user-nurse"></i>
                                Not cleared for shipment
                            </span>
                            @endif
                        </td>
                    </tr>
                    @endforeach

                    @if(count($supplyOrders) === 0)
                    <tr>
                        <td colspan="6">No records found!</td>
                    </tr>
                    @endif
                </tbody>

            </table>

        </div>
    </div>
    <div class="mt-3">
        {{ $supplyOrders->appends(request()->input())->links() }}
    </div>
</div>
@endsection