<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">
                                Sales
                            </h4>
                            <hr>
                        </div>
                        <div class="col">
                            <form action="{{route('member_search_checkins')}}">
                                <div class="form-group">
                                    <div class="input-group"><input type="date" placeholder="Select Search date"
                                                                    class="form-control">
                                        <div class="btn btn-addon"><i class="fa fa-search"></i></div>
                                    </div>
                                </div>
                            </form>
                        </div>

                        <div class="col-auto">
                            <!-- Button -->
                            <a href="{{route('member_today_checkins')}}" 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">
                                    Customer
                                </a>
                            </th>
                            <th>
                                <a href="#" class="text-muted list-sort" data-sort="goal-status">
                                    Item
                                </a>
                            </th>
                            <th>
                                <a href="#" class="text-muted list-sort" data-sort="goal-status">
                                    Quantity
                                </a>
                            </th>
                            <th>
                                <a href="#" class="text-muted list-sort" data-sort="goal-status">
                                    Price
                                </a>
                            </th>
                            <th>
                                <a href="#" class="text-muted list-sort" data-sort="goal-progress">
                                    Amount
                                </a>
                            </th>
                            <th>
                                <a href="#" class="text-muted list-sort" data-sort="goal-date">
                                    Payment Method
                                </a>
                            </th>
                            <th>
                                <a href="#" class="text-muted list-sort" readonly="readonly" data-sort="goal-date">
                                    Status
                                </a>
                            </th>
                            <th>
                                <a href="#" class="text-muted list-sort" data-sort="goal-date">
                                    Review
                                </a>
                            </th>
                            <th></th>
                        </tr>
                        </thead>
                        <tbody class="list">
                        @forelse($sales as $sale)
                            <tr>
                                <td class="goal-project">
                                    {{$sale->customer == null ? "Unknown": $sale->customer}}
                                </td><?php $product = $products->where('id', $sale->product_id)->first(); ?>
                                <td class="goal-project">
                                    {{$product->name}}
                                </td>
                                <td class="goal-project">
                                  {{$sale->quantity}}
                                </td>
                                <td class="goal-project">
                                    {{$product->price}}
                                </td>
                                <td class="goal-project">
                                    {{$sale->amount}}
                                </td>
                                <td class="goal-project">
                                    {{ $sale->pay_channel}}
                                </td>
                                <td class="goal-project">
                                    {{ $sale->status }}
                                </td>
                                <td class="goal-project">
                                    NULL
                                </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">
                                            <form action="{{route('checkout', $sale->id)}}" method="post"
                                                  id="checkout-form-{{$sale->id}}">
                                                @csrf
                                                <a href="javascript:void(0)"
                                                   onclick="document.getElementById('checkout-form-{{$sale->id}}').submit();"
                                                   id="checkout-{{$sale->id}}" data-id="{{$sale->id}}"
                                                   class="dropdown-item checkout">
                                                    Checkout
                                                </a>
                                            </form>

                                            <a href="#!" class="dropdown-item">
                                                Change
                                            </a>
                                            <form action="{{route('remove_checkin', $sale->id)}}" method="post"
                                                  id="remove-form-{{$sale->id}}">
                                                @csrf
                                                <a href="javascript:void(0)"
                                                   onclick=" let conf  =confirm('are you sure you want to delete?'); if(conf){document.getElementById('remove-form-{{$sale->id}}').submit();}else{return;}"
                                                   id="remove-{{$sale->id}}" data-id="{{$sale->id}}"
                                                   class="dropdown-item checkin-remove">$sale</a>
                                            </form>
                                        </div>
                                    </div>
                                </td>

                            </tr>
                        @empty
                            <h3 class="p-2">No Sales Available</h3>
                        @endforelse
                        </tbody>
                    </table>
                </div>
                <div class="card-footer table-responsive mt-5">
                    <table class="table">
                        <tbody>
                        <tr>
                            <td><h4>POS:</h4></td>
                            <td>
                                <span class="pull-right"><strong>{{number_format($sales->where('pay_channel', 'POS')->sum('amount'), 2)}}</strong></span>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>
                                <h4 style="color: orange;">TOTAL CASH: </h4>

                            </td>
                            <td>
                                <span class="pull-right">
                                        <strong>{{number_format($sales->where('pay_channel', 'CASH')->sum('amount'), 2)}}</strong>
                                    </span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <h4 style="color: orange;">TOTAL TRANSFERS: </h4>

                            </td>
                            <td>
                                <span class="pull-right">
                                        <strong>{{number_format($sales->where('pay_channel', 'TRANSFER')->sum('amount'), 2)}}</strong>
                                    </span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <h4 style="color: RED;">TOTAL DEBT: </h4>

                            </td>
                            <td>
                                <span class="pull-right">
                                        <strong>{{number_format($sales->where('pay_channel', 'PENDING')->sum('amount'), 2)}}</strong>
                                    </span>
                            </td>
                        </tr>
                        </tbody>

                    </table>

                </div>
                <div class="card-footer" style="background: darkgreen!important;">

                    <h2>GRAND TOTAL:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
                                class="pull-right"><strong>{{number_format($sales->sum('amount'), 2)}}</strong></span>
                    </h2>

                </div>
            </div>

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