<?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';
}
?>

<?php $__env->startSection('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="<?php echo e(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="<?php echo e(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">
                                    <?php echo $__env->make('bmviews.partials.filter-supervise', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

                                    <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">
                                        <?php 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>
                                                <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <li><?php echo e($error); ?></li>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </ul>
                                            </div>

                                        <?php endif; ?>
                                        <?php echo $__env->make('layouts.messages', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                        <form action="<?php echo e(route('supervise.store')); ?>" method="post">
                                        <?php echo csrf_field(); ?>
                                        <?php $__currentLoopData = $payments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <input type="hidden" name="client_pay_batch_id[]" value="<?php echo e($payment->client_pay_batch_id); ?>">
                                        <input type="hidden" name="amount[]" value="<?php echo e($payment->transfer_amount); ?>">
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                         <button type="submit" name="all" class="btn btn-success pull-left"><i class="fa fa-check"></i> Approve All</button>
                                         </form>
                                         <form action="<?php echo e(route('supervise.store')); ?>" method="post">
                                         <?php echo csrf_field(); ?>
                                         <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>
                                            <?php $__currentLoopData = $payments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <?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');
                                            ?>
                                            <?php if($pay_count > 3): ?>
                                            <tr class="table-danger">
                                            <?php else: ?>
                                            <tr>
                                            <?php endif; ?>
                                                <td><?php echo e(++$i); ?></td>
                                                <td>
                                                <?php
                                                    $batch_count = App\Models\bmmodels\CustomerClientPayment::where('client_pay_batch_id', $payment->client_pay_batch_id)->count('client_pay_id');
                                                ?>
                                                <?php echo e($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');
                                                ?>
                                                <?php echo e($batch_totals); ?>

                                                        </td>
                                                <td><?php echo e($payment->created_at); ?></td>
                                                <td><button type="button" class="btn btn-info" data-toggle="modal" data-target="#view-<?php echo e($payment->client_pay_batch_id); ?>"><?php echo e($payment->client_pay_batch_id); ?></button></td>
                                                <td><input type='checkbox' name="client_pay_batch_id[]" value="<?php echo e($payment->client_pay_batch_id); ?>"></td>
                                                
                                                <td>
                                                    <button type="button" @click="rejectItem('payreject',<?php echo e($payment->client_pay_id); ?>)" id="<?php echo e($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>
                                                 
                                                </td>
                                            </tr>
                                            <!--view batch -->
                                         <div class="modal fade" id="view-<?php echo e($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 [<?php echo e($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();
                                                        ?>
                                                        <?php $__currentLoopData = $batch_dets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $detail): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <li class="list-group-item row">
                                                            <span class="name col-sm-6 col-md-3 border-right"><?php if($detail->customer_client_cust_client_id): ?>
                                                                <?php echo e($detail->ClientPaymentClient->cust_client_fullname); ?>

                                                                <?php elseif($detail->customer_client_batch_id): ?>
                                                                <?php echo e($detail->ClientPaymentBatch->client_name); ?>

                                                                <?php elseif($detail->client_b2b_number): ?>
                                                                <?php echo e($detail->client_pay_account_name); ?>

                                                                <?php endif; ?>
                                                            </span>
                                                            <span class="name col-sm-6 col-md-3 border-right"><?php if($detail->customer_client_cust_client_id): ?>
                                                                254<?php echo e($detail->ClientPaymentClient->cust_client_phone); ?>

                                                                <?php elseif($detail->customer_client_batch_id): ?>
                                                                254<?php echo e($detail->ClientPaymentBatch->client_phone); ?><span class="text-success" title="Batch contact">[B2CBatch]</span>
                                                                <?php elseif($detail->client_b2b_number): ?>
                                                                <?php echo e($detail->client_b2b_number); ?><span class="text-success" title="Batch contact">[B2B]</span>
                                                                <?php endif; ?>
                                                            </span>
                                                            <span class="col-sm-6 col-md-3 border-right"><?php echo e($detail->client_pay_amount); ?></span>
                                                            <span class="col-sm-6 col-md-3 border-right"><?php echo e($detail->client_pay_ref); ?></span>
                                                            <span class="col-sm-6 col-md-3 border-right">
                                                            
                                                            </span>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                        
                                                        </li>
                                                        </ul>
                                                        </div>
                                                        </div>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- /view batch -->
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </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>
   
    
<?php $__env->stopSection(); ?>

<?php echo $__env->make($layout, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/dashmobisky/public_html/Accounts/resources/views/bmviews/supervise/index.blade.php ENDPATH**/ ?>