@extends('layouts.main')
@section('content')


@php
//fetch users with pagination
if (!empty($_GET['search'])) {
   $neenoe = request()->query('search');
   //where('title','like','%'.$search.'%')
   $cashouts = DB::table('cashouts')->where('phone','like','%'.$neenoe.'%')->orWhere('amount','like','%'.$neenoe.'%')->orWhere('phone','like','%'.$neenoe.'%')->paginate(10);
}else {
    $cashouts = DB::table('cashouts')->paginate(10);
}


@endphp

    <div class="col-lg-7">
        <div class="page-header-title">
            <div class="d-inline">
                <div class="card-header">
                    <h5>All withdrawal</h5>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-5">
        <div class="page-header-breadcrumb">
            <div class="col-sm-12">
                <form
                    method="GET">
                    @csrf
                    <div class="input-group input-group-success">
                        <input type="text" name="search" class="form-control"
                            placeholder="Enter username/Trans ID">
                        <button class="input-group-addon">
                            <i data-feather="search" class="menuicons icon-search f-15"></i>
                        </button>
                    </div>
                </form>

            </div>
        </div>
    </div>

<div class="col-xl-12 col-md-12">
    <!-- DOM/Jquery table start -->
    <div class="card">
        <div class="card-header">
            <h5>All withdrawal History </h5>
        </div>
        <div class="card-block">
            <div class="table-responsive dt-responsive">
                <table id="dom-jqry"
                    class="table table-striped table-bordered nowrap">
                    <thead>
                        <tr>
                            <th>Date</th>
                            <th>Code</th>
                            <th>Username</th>
                            <th>Phone</th>
                            <th>Charge</th>
                            <th>Amount</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        @if ($cashouts->count() > 0)

                        @foreach ($cashouts as $c)
                            

                        <tr>
                            <td>{{ \Carbon\Carbon::parse($c->created_at)->diffForHumans() }}
                            </td>
                            <td>{{ $c->code }}</td>
                            <td style="text-transform: lowercase">
                                @php
                                    
                                    $thisguy = DB::table('users')->where('phone', $c->phone)->first();
                                    $iduser = $thisguy->id ?? 1;
                                @endphp
                                <a href="{{ route('viewuser', $iduser) }}">
                                    <u>
                                        {{  $thisguy->username ?? "nouser" }}
                                    </u>
                                </a>                                              
                            </td>
                            <td>
                                {{ $c->phone }}</td>
                            <td>KSH {{ $c->Charge }}</td>
                            <td>KSH {{ $c->amount }}</td>
                            <td>
                                {{ $c->status }}
                            </td>
                        </tr>


                        @endforeach
                        @else
                        <tr>
                            <td class="text-center" colspan="100%">
                                No search results found
                            </td>
                        </tr>

                        @endif
                    </tbody>
                </table>
            </div>
            <div class="card-footer py-4">
                <nav aria-label="...">

                </nav>
            </div>
        </div>
    </div>
</div>
@endsection