<?php Fun::lang() ?>
<?php $__env->startSection('content'); ?>
<?php echo $__env->make('administrator.client-payment.payment.form-approve-payment', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<div class="page">
    <div class="alert-message alert-success" id="done" style="display: none">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <i class="fa fa-check"></i>
        <h3>Success</h3>
        <p>Approved success</p>
    </div>
    <div class="top-content">
        <div class="row">
            <div class="col-sm-12 col-xs-12">
                <div class="pull-left">
                    <h3>Payment Rejected</h3>
                </div>
            </div>
            
        </div>

    </div>

    <div class="box-body table-responsive">
        <div class="col-sm-12">
            <!-- <div class="form-group col-sm-6">
                <label for="" class="col-sm-4">Start Date</label>
                <div class="col-sm-8">
                    <?php echo Form::text('start_date',null,['class'=>'form-control date_picker','id'=>'start_date']); ?>

                </div>
            </div>
            <div class="form-group col-sm-6">
                <label for="" class="col-sm-4">End Date</label>
                <div class="col-sm-8">
                    <?php echo Form::text('end_date',null,['class'=>'form-control date_picker','id'=>'end_date']); ?>

                </div>
            </div> -->
            <div class="form-group col-sm-12">
                <div class="col-sm-12">
                    <a href="<?php echo e(route('print-rejected-client-payment')); ?>" class="btn btn-md btn-warning-sb fa fa-print pull-right"> Print</a>
                    <!-- <button type="button" class="btn btn-info fa fa-search pull-right" onclick="search()"> Search</button> -->
                </div>
            </div>
        </div>
        <br/><br/>
        <table id="datatable_payment_pending" class="table table-striped table-bordered table-hover nowrap">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Date</th>
                    <th>Description</th>
                    <th>Cashier</th>
                    <th>Receipt No</th>
                    <th>Payment Method</th>
                    <th>Reference</th>
                    <th>Amount</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('js'); ?>
<script type="text/javascript">
    function search(){
        
    }
    $(document).ready(function() {
        $('#datatable_payment_pending').DataTable({
            ordering: false,
            serverSide: false,
            searching: true,
            paging: true,
            ajax: "<?php echo e(route('report_reject_payment')); ?>",
            columns: [
                {
                    data: 'DT_RowIndex'
                },
                {
                    data: 'created_at'
                },
                {
                    data: 'description'
                },
                {
                    data: 'cashier'
                },
                {
                    data: 'receipt_no'
                },
                {
                    data: 'bank'
                },
                {
                    data: 'reference'
                },
                {
                    data: 'payment'
                }
            ]
        });
        $('#check_all').on('click', function(e) {
            if ($(this).is(':checked', true)) {
                $(".checkbox").prop('checked', true);
            } else {
                $(".checkbox").prop('checked', false);
            }
        });
        $(document).on('click', '#reject_payment', function() {
            var idsArr = [];
            $(".checkbox:checked").each(function() {
                idsArr.push($(this).attr('data-id'));
            });
            if (idsArr.length <= 0) {
                alert("No Payment Selected!");
            } else {
                if (confirm('Are You Sure To Reject')) {
                    $.ajax({
                        url: "<?php echo e(route('reject_client_payment')); ?>",
                        type: "POST",
                        dataType: 'json',
                        data: {
                            "_token": "<?php echo e(csrf_token()); ?>",
                            paid_id: idsArr
                        },
                        success: function(data) {
                            $('#datatable_payment_pending').DataTable().ajax.reload();
                            $('#done').show();
                        },
                        error: function(err) {
                            console.log(err);
                        }
                    });
                }
            }
        });
        $('.checkbox').on('click', function() {
            if ($('.checkbox:checked').length == $('.checkbox').length) {
                $('#check_all').prop('checked', true);
            } else {
                $('#check_all').prop('checked', false);
            }
        });
        $('#approve_payment').on('click', function() {
            var idsArr = [];
            $(".checkbox:checked").each(function() {
                idsArr.push($(this).attr('data-id'));
            });
            if (idsArr.length <= 0) {
                $('#approve-client-payment').modal('show');
            } else {
                if (confirm('Are You Sure To Approve')) {
                    $.ajax({
                        url: "<?php echo e(route('approve_client_payment')); ?>",
                        type: "POST",
                        dataType: 'json',
                        data: {
                            "_token": "<?php echo e(csrf_token()); ?>",
                            paid_id: idsArr
                        },
                        success: function(data) {
                            $('#datatable_payment_pending').DataTable().ajax.reload();
                            $('#done').show();
                        },
                        error: function(err) {
                            console.log(err);
                        }
                    });
                }
            }
        });
    }); 
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>