<?php
    use Carbon\Carbon;
?>


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

<?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.collection.create')); ?>" id="addRow1" class="btn btn-primary" style="font-size:14px; padding: 6px 12px;">
                        Make Collection <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>COLLECTION</header> <span class="btn btn-primary ml-3"> <?php echo e($collections->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> Farmer / Purpose </th>
                                                    <th> Collection Amount </th>
                                                    <th> Collection Type </th>
                                                    <th> Given By </th>
                                                    <th> Collection Date</th>
                                                    <th> Action </th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <?php $__currentLoopData = $collections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$collection): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <tr class="odd gradeX">
                                                        <td> <?php echo e($key+1); ?> </td>
                                                        <td>
                                                            <?php if($collection->collect_type == 'farmer'): ?>
                                                                <?php echo e($collection->farmer->name); ?>

                                                            <?php endif; ?>

                                                            <?php if(is_null($collection->farmer_id)): ?>
                                                                <?php echo e(ucwords($collection->collect_type)); ?>

                                                            <?php endif; ?>
                                                        </td>
                                                        <td><?php echo e($collection->collection_amount); ?></td>
                                                        <td><?php echo e($collection->collection_type); ?></td>
                                                        <td><?php echo e($collection->given_by); ?></td>
                                                        <td><?php echo e(Carbon::parse($collection->collectin_date)->toDayDateTimeString()); ?></td>
                                                        
                                                        <td>
                                                            <a  class="waves-effect btn btn-success" href="<?php echo e(route('admin.collection.show', $collection->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.collection.edit', $collection->id)); ?>"><i class="material-icons">edit</i></a>

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

                                                            <form id="delete-form-<?php echo e($collection->id); ?>" action="<?php echo e(route('admin.collection.destroy', $collection->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 </th>
                                                    <th> Collection Amount </th>
                                                    <th> Collection Type </th>
                                                    <th> Given By </th>
                                                    <th> Collection 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> Farmer / Purpose </th>
                                                        <th> Collection Amount </th>
                                                        <th> Collection Type </th>
                                                        <th> Given By </th>
                                                        <th> Collection 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($value->collect_type == 'farmer'): ?>
                                                                    <?php echo e($value->farmer->name); ?>

                                                                <?php endif; ?>

                                                                <?php if(is_null($value->farmer_id)): ?>
                                                                    <?php echo e(ucwords($value->collect_type)); ?>

                                                                <?php endif; ?>
                                                            </td>
                                                            <td><?php echo e($value->collection_amount); ?></td>
                                                            <td><?php echo e($value->collection_type); ?></td>
                                                            <td><?php echo e($value->given_by); ?></td>
                                                            <td><?php echo e(Carbon::parse($value->collectin_date)->toDayDateTimeString()); ?></td>
                                                            
                                                            <td>
                                                                <a  class="waves-effect btn btn-success" href="<?php echo e(route('admin.collection.show', $value->id)); ?>"><i class="material-icons">visibility</i></a>
                                                                
                                                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('collection_edit')): ?>
                                                                <a  class="waves-effect btn btn-primary" href="<?php echo e(route('admin.collection.edit', $value->id)); ?>"><i class="material-icons">edit</i></a>
                                                                <?php endif; ?>

                                                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("collection_delete")): ?>
                                                                <button type="submit" class="waves-effect btn deepPink-bgcolor"
                                                                        onclick="deleteCollection(<?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.collection.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 deleteCollection(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 Collection 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 E:\farm\resources\views/admin/collection/index.blade.php ENDPATH**/ ?>