<?php
    use Carbon\Carbon;
?>


<?php $__env->startSection('title', 'Payments'); ?>

<?php $__env->startPush('css'); ?>
    <!-- data tables -->
    <link href="<?php echo e(asset('admin/assets/plugins/datatables/plugins/bootstrap/dataTables.bootstrap4.min.css')); ?> " rel="stylesheet" type="text/css"/>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
    <div class="page-bar">
        <div class="page-title-breadcrumb">

        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
                <div class="btn-group">
                    <a href="<?php echo e(route('admin.payment.create')); ?>" id="addRow1" class="btn btn-primary" style="font-size:14px; padding: 6px 12px;" >
                        Make Payment <i style="color:white;" class="fa fa-plus"></i>
                    </a>

                </div>

            <div class="card card-topline-red">
                <div class="card-head" style="text-align: center;">
                    <header>PAYMENT</header> <span class="btn btn-primary ml-3"> <?php echo e($payments->count()); ?> </span>

                </div>
                <div class="card-body ">
                    <div class="row p-b-20">
                        <div class="col-md-6 col-sm-6 col-6">

                        </div>
                        <div class="col-md-6 col-sm-6 col-6">

                        </div>
                    </div>
                    <header class="panel-heading panel-heading-gray custom-tab ">
                        <ul class="nav nav-tabs">
                            <li class="nav-item">
                                <a href="#active" data-toggle="tab" class="active">Approved</a>
                            </li>
                            <li class="nav-item">
                                <a href="#pending" data-toggle="tab">Pending</a>
                            </li>

                        </ul>
                    </header>

                    <div class="tab-content">
                            
                            <div class="tab-pane active" id="active">
                                <div class="col-12">
                                    <div class="card">
                                        <div class="card-body">
                                            <div class="table-scrollable">
                                                <table class="table table-striped table-bordered table-hover table-checkable order-column" style="width: 100%" id="example4">
                                                    <thead>
                                                    <tr>
                                                        <th> Serial </th>
                                                        <th> Company / Farmer / Staff</th>
                                                        <th> Payment Amount </th>
                                                        <th> Payment Type </th>
                                                        <th> Payment Date </th>
                                                        <th> Action </th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    <?php $__currentLoopData = $payments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <tr class="odd gradeX">
                                                            <td> <?php echo e($key+1); ?> </td>
                                                            <td>
                                                                <?php if(is_null($payment->farmer_id) && is_null($payment->company_id) && is_null($payment->user_id)): ?>
                                                                    <?php echo e(ucwords($payment->payee_type)); ?>


                                                                <?php elseif(is_null($payment->farmer_id) && is_null($payment->user_id)): ?>
                                                                    <?php echo e(optional($payment->company)->name ?? ''); ?>


                                                                <?php elseif(is_null($payment->farmer_id) && is_null($payment->company_id)): ?>
                                                                    <?php echo e(optional($payment->user)->name ?? ''); ?>


                                                                <?php elseif(is_null($payment->company_id) && is_null($payment->user_id)): ?>
                                                                    <?php echo e(optional($payment->farmer)->name ?? ''); ?>

                                                                <?php endif; ?>


                                                            </td>
                                                            <td><?php echo e($payment->payment_amount); ?></td>
                                                            <td><?php echo e($payment->payment_type); ?></td>
                                                            <td><?php echo e(Carbon::parse($payment->payment_date)->toDayDateTimeString()); ?></td>
                                                            
                                                            <td>
                                                                <a  class="waves-effect btn btn-success" href="<?php echo e(route('admin.payment.show', $payment->id)); ?>"><i class="material-icons">visibility</i></a>
                                                                <?php if(auth()->check() && auth()->user()->hasRole('superadmin')): ?>
                                                                <a  class="waves-effect btn btn-primary" href="<?php echo e(route('admin.payment.edit', $payment->id)); ?>"><i class="material-icons">edit</i></a>

                                                                <button type="submit" class="waves-effect btn deepPink-bgcolor"
                                                                        onclick="deletePayment(<?php echo e($payment->id); ?>)">
                                                                    <i class="material-icons">delete</i>
                                                                </button>

                                                                <form id="delete-form-<?php echo e($payment->id); ?>" action="<?php echo e(route('admin.payment.destroy', $payment->id)); ?>" method="post" style="display:none;">
                                                                    <?php echo csrf_field(); ?>
                                                                    <?php echo method_field("DELETE"); ?>
                                                                </form>
                                                                <?php endif; ?>
                                                            </td>
                                                        </tr>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </tbody>
                                                    <tfoot>
                                                    <tr>
                                                        <th> Serial </th>
                                                        <th> Company / Farmer /Staff</th>
                                                        <th> Payment Amount </th>
                                                        <th> Payment Type </th>
                                                        <th> Payment Date </th>
                                                        <th> Action </th>
                                                    </tr>
                                                    </tfoot>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            
                            <div class="tab-pane" id="pending">
                                <div class="row">
                                    <div class="col-md-12 col-sm-12">
                                        <div class="card">

                                            <div class="card-body">
                                                <div class="table-scrollable">
                                                    
                                                    <table class="table table-striped table-bordered table-hover table-checkable order-column" style="width: 100%">
                                                        <thead >
                                                            <tr>
                                                                <th> Serial </th>
                                                                <th> Company / Farmer / Staff</th>
                                                                <th> Payment Amount </th>
                                                                <th> Payment Type </th>
                                                                <th> Payment Date </th>
                                                                <th> Action </th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                        <?php $__currentLoopData = $pending; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <tr class="odd gradeX">
                                                                <td> <?php echo e($key+1); ?> </td>
                                                                <td>
                                                                    <?php if(is_null($value->farmer_id) && is_null($value->company_id) && is_null($value->user_id)): ?>
                                                                        <?php echo e(ucwords($value->payee_type)); ?>


                                                                    <?php elseif(is_null($value->farmer_id) && is_null($value->user_id)): ?>
                                                                        <?php echo e(optional($value->company)->name ?? ''); ?>


                                                                    <?php elseif(is_null($value->farmer_id) && is_null($value->company_id)): ?>
                                                                        <?php echo e(optional($value->user)->name ?? ''); ?>


                                                                    <?php elseif(is_null($value->company_id) && is_null($value->user_id)): ?>
                                                                        <?php echo e(optional($value->farmer)->name ?? ''); ?>

                                                                    <?php endif; ?>


                                                                </td>
                                                                <td><?php echo e($value->payment_amount); ?></td>
                                                                <td><?php echo e($value->payment_type); ?></td>
                                                                <td><?php echo e(Carbon::parse($value->payment_date)->format('d-m-Y')); ?></td>

                                                                <td width="25%">
                                                                    <a  class="waves-effect btn btn-success" href="<?php echo e(route('admin.payment.show', $value->id)); ?>"><i class="material-icons">visibility</i></a>
                                                                    
                                                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('payment_edit')): ?>
                                                                    <a  class="waves-effect btn btn-primary" href="<?php echo e(route('admin.payment.edit', $value->id)); ?>"><i class="material-icons">edit</i></a>
                                                                    <?php endif; ?>

                                                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('payment_delete')): ?>
                                                                    <button type="submit" class="waves-effect btn deepPink-bgcolor"
                                                                            onclick="deletePayment(<?php echo e($value->id); ?>)">
                                                                        <i class="material-icons">delete</i>
                                                                    </button>

                                                                    <form id="delete-form-<?php echo e($value->id); ?>" action="<?php echo e(route('admin.payment.destroy', $value->id)); ?>" method="post" style="display:none;">
                                                                        <?php echo csrf_field(); ?>
                                                                        <?php echo method_field("DELETE"); ?>
                                                                    </form>
                                                                    <?php endif; ?>
                                                                    
                                                                </td>
                                                            </tr>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                        </tbody>

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


                        </div>


                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
    <!-- data tables -->
    <script src="<?php echo e(asset('admin/assets/plugins/datatables/jquery.dataTables.min.js')); ?>"></script>
    <script src="<?php echo e(asset('admin/assets/plugins/datatables/plugins/bootstrap/dataTables.bootstrap4.min.js')); ?>" ></script>
    <script src="<?php echo e(asset('admin/assets/js/pages/table/table_data.js')); ?>" ></script>

    <!-- sweet aleart -->
    <script src="<?php echo e(asset('admin/assets/js/sweetalert.min.js')); ?>"></script>

    <script type="text/javascript">

    function deletePayment(id) {

        const swalWithBootstrapButtons = Swal.mixin({
            customClass: {
                confirmButton: 'btn btn-success',
                cancelButton: 'btn btn-danger'
            },
            buttonsStyling: false,
            })

            swalWithBootstrapButtons.fire({
            title: 'Are you sure?',
            text: "You won't be able to revert this!",
            type: 'warning',
            showCancelButton: true,
            confirmButtonText: 'Yes, delete it!',
            cancelButtonText: 'No, cancel!',
            reverseButtons: true
            }).then((result) => {
            if (result.value) {
                event.preventDefault();
                document.getElementById("delete-form-"+id).submit();
            } else if (
                // Read more about handling dismissals
                result.dismiss === Swal.DismissReason.cancel
            ) {
                swalWithBootstrapButtons.fire(
                'Cancelled',
                'Your Payment name is safe :)',
                'error'
                )
            }
        })

    }

    </script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('template.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/forazitradersbd/public_html/resources/views/admin/payment/index.blade.php ENDPATH**/ ?>