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


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


@endphp

<div class="col-lg-7">
    <div class="page-header-title">
        <div class="d-inline">
            <div class="card-header">
                <h5>Approved Deposit History </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 class="feather 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-block">
            <div class="table-responsive dt-responsive">
                <table id="dom-jqry"
                    class="table table-striped table-bordered nowrap">
                    <thead>
                        <tr>
                            <th>Date</th>
                            <th>Method</th>
                            <th>Transaction #</th>
                            <th>Username</th>
                            <th>Amount</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        @if ($deposits->count() > 0)

                        @foreach ($deposits as $d)
                        <tr>
                            <td>{{ \Carbon\Carbon::parse($d->created_at)->diffForHumans() }}
                            </td>
                            <td>{{ $d->method }}</td>
                            <td>{{ $d->transaction }}</td>
                            <td style="text-transform: lowercase">
                                @php
                                    
                                $thisguy = DB::table('users')->where('username', $d->username)->first();
                                $iduser = $thisguy->id ?? 1;

                                @endphp
                                <a href="{{ route('viewuser', $iduser) }}">
                                    <u>
                                        {{  $thisguy->username ?? $d->username }}
                                    </u>
                                </a> 
                            </td>
                            <td>KSH {{ $d->amount }}</td>
                            <td>
                                <span
                                    class="label label-success">{{ $d->status }}</span>
                            </td>
                        </tr>
                        @endforeach
                        @else

                        <tr>
                            <td>
                                <center> No Data Found</center>
                            </td>
                        </tr>
 
                        @endif
                    </tbody>
                </table>
            </div>
               <div class="card-footer py-4">
                        {!! $deposits->withQueryString()->links('pagination::bootstrap-5') !!}
                </div>
        </div>
    </div>
</div>
@endsection