@extends("layouts.members")
@section('page_title')
    Purchase
@endsection
@section('page_category')
    All Purchase
@endsection
<!-- HEADER -->
@section('page_action')
    <!-- Button -->
    <a href="{{ route('member_all_purchases') }}" class="btn btn-primary lift">
        All Purchases
    </a>
    @endsectionion

@section('content')
    <div class="container-fluid">
        {{--<div class="row">--}}
        <div class="row">
            <div class="col-12">
                <!-- Goals -->
                <div class="card">
                    <div class="card-header">
                        <div class="row align-items-center">
                            <div class="col">
                                <!-- Title -->
                                <h4 class="card-header-title">
                                    Purchases
                                </h4>

                            </div>
                            <div class="col-auto">
                                <!-- Button -->
                                <a href="#!" class="btn btn-sm btn-white">
                                    Today
                                </a>
                                <!-- Button -->
                                <a href="#!" class="btn btn-sm btn-white">
                                    Last 7 Days
                                </a>
                                <!-- Button -->
                                <a href="#!" class="btn btn-sm btn-white">
                                    All
                                </a>
                                <!-- Button -->
                                <a href="#!" class="btn btn-sm btn-white">
                                    Export
                                </a>
                            </div>
                        </div> <!-- / .row -->
                    </div>
                    <div class="table-responsive mb-0"
                         data-list="{&quot;valueNames&quot;: [&quot;goal-project&quot;, &quot;goal-status&quot;, &quot;goal-progress&quot;, &quot;goal-date&quot;]}">
                        <table class="table table-sm table-nowrap card-table">
                            <thead>
                            <tr>
                                <th>
                                    <a href="#" class="text-muted list-sort" data-sort="goal-project">
                                        SN
                                    </a>
                                </th>
                                <th>
                                    <a href="#" class="text-muted list-sort" data-sort="goal-project">
                                        Products
                                    </a>
                                </th>
                                <th>
                                    <a href="#" class="text-muted list-sort" data-sort="goal-project">
                                        Quantity
                                    </a>
                                </th>
                                <th>
                                    <a href="#" class="text-muted list-sort" data-sort="goal-status">
                                        Unit
                                    </a>
                                </th>
                                <th>
                                    <a href="#" class="text-muted list-sort" data-sort="goal-status">
                                        Cost
                                    </a>
                                </th>
                                <th>
                                    <a href="#" class="text-muted list-sort" data-sort="goal-status">
                                        Amount
                                    </a>
                                </th>
                                <th>
                                    <a href="#" class="text-muted list-sort" data-sort="goal-progress">
                                        Date
                                    </a>
                                </th>
                                <th></th>
                            </tr>
                            </thead>
                            <tbody class="list">
                            <?php $n=1; ?>
                            @forelse($purchases as $purchase)
                                <tr>
                                    <td class="goal-project">
                                        {{$n++}}
                                    </td>
                                    <?php $product  = \App\Models\Product::where('id', $purchase->product_id)->first(); ?>
                                    <td class="goal-project">
                                        {{!$product ? $purchase->product_id : $product->name}}
                                    </td>
                                    <td class="goal-project">
                                        {{$purchase->quantity}}
                                    </td>
                                    <td class="goal-project">
                                        {{$purchase->unit}}
                                    </td>
                                    <td class="goal-project">
                                        {{$purchase->cost_price}}
                                    </td>
                                    <td class="goal-project">
                                        {{$purchase->amount}}
                                    </td>
                                    <td class="goal-project">
                                        {{$purchase->created_at}}
                                    </td>

                                    <td class="text-right">
                                        <div class="dropdown">
                                            <a href="#" class="dropdown-ellipses dropdown-toggle" role="button"
                                               data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                <i class="fe fe-more-vertical"></i>
                                            </a>
                                            <div class="dropdown-menu dropdown-menu-right">
                                                <a href="#!" class="dropdown-item">
                                                    Details
                                                </a>
                                                <a href="#!" class="dropdown-item">
                                                    Edit
                                                </a>
                                                <a href="{{route('member_remove_purchase', $purchase->id)}}" onclick="let conf = confirm('are you sure you want to delete this item? this action is non-reversable');
 if (!conf){return false;}" class="dropdown-item">
                                                    Delete
                                                </a>
                                            </div>
                                        </div>
                                    </td>

                                </tr>
                            @empty
                                <h6>No Purchase Record Availanle</h6>
                            @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>

            </div>
        </div> <!-- / .row -->
    </div>

@endsection