@php
if(Auth::user()->user_type == 'organization')
{
 $layout = 'bmviews.layouts.customer';
 $dashboard='customer-dashboard';
 $fdashboard='customer-dashboard';

}
else
{
 $layout = 'bmviews.layouts.admin';
 $dashboard='admin-dashboard';
}
@endphp
@extends($layout)
@section('content')
<style>
.dropdown-menu a:hover{ background:#f27200;color:#fff;}
</style>

<div class="main-panel">
    <div class="content">
            <div class="panel-header">
                <div class="page-inner py-5 text-white"  style="background:#313232">
                    <div class="d-flex align-items-left align-items-md-center flex-column flex-md-row">
                        <div><div class="page-header">
                            <h4 class="page-title text-white">Supervision</h4>
                            <ul class="breadcrumbs">
                                    <li class="nav-home">
                                        <a class="text-white" href="{{ route($dashboard)}}">
                                            <i class="flaticon-home"></i>
                                        </a>
                                    </li>
                                    <li class="separator">
                                        <i class="flaticon-right-arrow"></i>
                                    </li>
                                    <li class="nav-item">
                                        <a class="text-white" href="">Supervision</a>
                                    </li>
                                </ul>
                        </div></div>
                        <div class="ml-md-auto py-2 py-md-0">
                            <a href="{{route($fdashboard)}}" class="btn btn-white btn-border btn-round mr-2"><i class="fas fa-arrow-circle-left"></i> Back</a>
                        </div>
                    </div>
                </div>
            <div class="page-category">
                <div class="page-inner mt--5">
                    <div class="row mt--2">
                            <div class="col-md-12">
                                <div class="card full-height">
                                    <div class="card-body">
                                    @include ('bmviews.partials.filter-supervise')

                                    <div class="text-right mb-3 border-bottom pb-3">
                                    <div class="card-title pull-left">Supervision Details <small class="text-danger"> [Red rows have received payments more than 3 times today ]</small></div>
                                        <a class="btn btn-success btn-border btn-round btn-sm" data-toggle="collapse" data-target="#filter-panel">
                                            <i class="fas fa-filter"></i> Filter
                                        </a>
                                    </div>

                                    <div id="filter-msg" class="d-none">
                                        <div class="alert alert-info shadow-sm mb-0" role="alert">
                                            <p class="mb-0"><i class="fas fa-info-circle"></i> This is a filtered view. <span id="filters"></span></p>
                                        </div>
                                        <hr>
                                    </div>
                                    <div id="vue-admin-user">
                                        @if ($errors->any())
                                            <div class="alert alert-danger alert-dismissible" role="alert">
                                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                            <strong>Error! </strong>There were some errors with inputs.
                                            <ul>
                                                @foreach($errors->all() as $error)
                                                <li>{{ $error }}</li>
                                            @endforeach
                                            </ul>
                                            </div>

                                        @endif
                                        @include('layouts.messages')
                                        <form action="{{ route('supervise.store')}}" method="post">
                                        @csrf
                                        @foreach($payments as $payment)
                                        <input type="hidden" name="client_pay_batch_id[]" value="{{ $payment->client_pay_batch_id }}">
                                        <input type="hidden" name="amount[]" value="{{ $payment->transfer_amount }}">
                                        @endforeach
                                         <button type="submit" name="all" class="btn btn-success pull-left"><i class="fa fa-check"></i> Approve All</button>
                                         </form>
                                         <form action="{{ route('supervise.store')}}" method="post">
                                         @csrf
                                         <button type="submit" name="selected" class="btn btn-success pull-right"><i class="fa fa-check"></i> Approve Selected</button>
                                         <br><l>&nbsp;</l>
                                        <div class="table-responsive">
                                        <!-- show for admin -->
                                            <table id="table" class="display table table-striped table-hover" cellspacing="0" width="100%">
                                            <thead class="thead-default">
                                                <tr>
                                                    <th>#</th>
                                                    <th>Batch Count</th>
                                                    <th>Amount[Kes.]</th>
                                                    <th>Paid on</th>
                                                    <th>Batch</th>
                                                    <th>Action</th>
                                                </tr>
                                            </thead>
                                            <tfoot>
                                                <tr>
                                                <th>#</th>
                                                <th>Batch Count</th>
                                                <th>Amount[Kes.]</th>
                                                <th>Paid on</th>
                                                <th>Batch</th>
                                                <th>Action</th>
                                                </tr>
                                            </tfoot>
                                            <tbody>
                                            @foreach($payments as $payment)
                                            @php
                                                $pay_count = App\Models\bmmodels\CustomerClientPayment::where('client_pay_status',1)->where('created_at','LIKE',"%date('Y-m-d')")->where('customer_client_cust_client_id', $payment->customer_client_cust_client_id)->count('client_pay_id');
                                            @endphp
                                            @if($pay_count > 3)
                                            <tr class="table-danger">
                                            @else
                                            <tr>
                                            @endif
                                                <td>{{ ++$i }}</td>
                                                <td>
                                                @php
                                                    $batch_count = App\Models\bmmodels\CustomerClientPayment::where('client_pay_batch_id', $payment->client_pay_batch_id)->count('client_pay_id');
                                                @endphp
                                                {{ $batch_count }}
                                                </td>
                                                <td>
                                                @php
                                                    $batch_totals = App\Models\bmmodels\CustomerClientPayment::where('client_pay_batch_id', $payment->client_pay_batch_id)->sum('client_pay_amount');
                                                @endphp
                                                {{ $batch_totals }}
                                                        </td>
                                                <td>{{ $payment->created_at }}</td>
                                                <td><button type="button" class="btn btn-info" data-toggle="modal" data-target="#view-{{ $payment->client_pay_batch_id }}">{{ $payment->client_pay_batch_id }}</button></td>
                                                <td><input type='checkbox' name="client_pay_batch_id[]" value="{{ $payment->client_pay_batch_id}}"></td>
                                                
                                                <td>
                                                    <button type="button" @click="rejectItem('payreject',{{$payment->client_pay_id}})" id="{{$payment->client_pay_id}}" data-toggle="tooltip"  data-original-title="Reject" name="Reject" class="tester btn btn-warning btn-sm" title="Reject"><i class="fas fa-ban"></i></button>
                                                 {{--<div class="form-button-action" role="group" aria-label="Actions">
                                                    @if(Auth::guard('customer')->check())
                                                        <button  @click="rejectItem('payreject',{{$payment->client_pay_id}})" data-toggle="tooltip"  data-original-title="Reject" name="Reject" class="btn btn-warning btn-sm" title="Reject">
                                                                <i class="fas fa-ban"></i> 
                                                        </button>
                                                    @endif
                                                </div>--}}
                                                </td>
                                            </tr>
                                            <!--view batch -->
                                         <div class="modal fade" id="view-{{ $payment->client_pay_batch_id }}" tabindex="-1" role="dialog" aria-hidden="true">
                                            <div class="modal-dialog modal-lg" role="document">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                    <h4>Batch contacts for [{{ $payment->client_pay_batch_id }}]</h4>
                                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                            <span aria-hidden="true">&times;</span>
                                                        </button>
                                                    </div>
                                                    
                                                        <div class="modal-body bg-light">
                                                        <div id="name-list" class="name-list" data-toggle="lists" data-lists-values='["name"]'>
                                                        <input class="search mb-2" type="search" placeholder="Search">
                                                        <ul class="list-group list-group-bordered list">
                                                            <li class="list-group-item row">
                                                                <span class="name col-sm-6 col-md-3 border-right">Name</span>
                                                                <span class="col-sm-6 col-md-3 border-right">Contact No</span>
                                                                <span class="col-sm-6 col-md-3 border-right">Amount[Kes.]</span>
                                                                <span class="col-sm-6 col-md-3 border-right">Ref.</span>
                                                                <!--<span class="col-sm-6 col-md-3 border-right">Status</span>-->
                                                            </li>
                                                       
                                                        @php
                                                        $batch_dets = App\Models\bmmodels\CustomerClientPayment::where('client_pay_batch_id', $payment->client_pay_batch_id)->get();
                                                        @endphp
                                                        @foreach($batch_dets as $detail)
                                                        <li class="list-group-item row">
                                                            <span class="name col-sm-6 col-md-3 border-right">@if($detail->customer_client_cust_client_id)
                                                                {{ $detail->ClientPaymentClient->cust_client_fullname }}
                                                                @elseif($detail->customer_client_batch_id)
                                                                {{ $detail->ClientPaymentBatch->client_name }}
                                                                @elseif($detail->client_b2b_number)
                                                                {{ $detail->client_pay_account_name}}
                                                                @endif
                                                            </span>
                                                            <span class="name col-sm-6 col-md-3 border-right">@if($detail->customer_client_cust_client_id)
                                                                254{{ $detail->ClientPaymentClient->cust_client_phone }}
                                                                @elseif($detail->customer_client_batch_id)
                                                                254{{ $detail->ClientPaymentBatch->client_phone }}<span class="text-success" title="Batch contact">[B2CBatch]</span>
                                                                @elseif($detail->client_b2b_number)
                                                                {{ $detail->client_b2b_number}}<span class="text-success" title="Batch contact">[B2B]</span>
                                                                @endif
                                                            </span>
                                                            <span class="col-sm-6 col-md-3 border-right">{{ $detail->client_pay_amount }}</span>
                                                            <span class="col-sm-6 col-md-3 border-right">{{ $detail->client_pay_ref }}</span>
                                                            <span class="col-sm-6 col-md-3 border-right">
                                                            {{--{{@if($detail->client_pay_status == 1)
                                                            <span class="badge badge-success">Paid</span>
                                                            @elseif($detail->client_pay_status == 2)
                                                            <span class="badge badge-danger">Failed</span>
                                                            @elseif($detail->client_pay_status == 0)
                                                            <span class="badge badge-warning">Pending</span>
                                                            @endif--}}
                                                            </span>
                                                        @endforeach
                                                        
                                                        </li>
                                                        </ul>
                                                        </div>
                                                        </div>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- /view batch -->
                                            @endforeach
                                            </tbody>
                                            </table>
                                            </div>
                                            </form>
                                         
                                        </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            </div>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
    <script src='https://unpkg.com/popper.js@1.11.1'></script>
    <script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js'></script>
   
    
@endsection
