<?php Fun::lang() ?>
<?php $__env->startSection('content'); ?>
<?php echo $__env->make('administrator.report-approve-payment.form-audit', 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>Approved Payment</h3>
                </div>
            </div>
        </div>
    </div>
    <div class="box-body">
        <form action="<?php echo e(route('print-approve-client-payment')); ?>" method="POST">
            <?php echo csrf_field(); ?>
            <?php echo method_field('POST'); ?>
            <div class="col-sm-12">
                <div class="form-group col-sm-6">
                    <label for="" class="col-sm-4 text-right">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 text-right">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-6">
                    <label for="" class="col-sm-4 text-right">Cashier</label>
                    <div class="col-sm-8">
                        <?php echo Form::select('cashier',$cashier,null,['class'=>'form-control select2','id'=>'cashier']); ?>

                    </div>
                </div>
                <div class="form-group col-sm-6">
                    <label for="" class="col-sm-4 text-right">Payment Method</label>
                    <div class="col-sm-8">
                        <?php echo Form::select('method',$method,null,['class'=>'form-control select2','id'=>'method']); ?>

                    </div>
                </div>
                <div class="form-group col-sm-6">
                    <label for="" class="col-sm-4 text-right">Receipt No</label>
                    <div class="col-sm-8">
                        <?php echo Form::text('receipt_no',null,['class'=>'form-control','id'=>'receipt-no',"placeholder"=>"Receipt No"]); ?>

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

                    </div>
                </div>
                <div class="form-group col-sm-12">
                    <div class="col-sm-12">
                        <button type="submit" class="btn btn-warning pull-right" style="margin-left: 2px;"><span class="fa fa-print"></span> Print</button>
                        <button type="button" class="btn btn-info pull-right" onclick="search()"><span class="fa fa-search "></span> Search</button>
                    </div>
                </div>
            </div>
            <hr>
            <div class="form-group col-sm-12">
                <div class="pull-right">
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Payment-Report-Run-Audit')): ?>
                    <a class="btn btn-warning-sb btn-sm" id="run_audit"><i class="fa fa-history"></i> RUN AUDIT</a>
                    <?php endif; ?>
                </div>
            </div>
        </form>
        <div class="col-sm-12">
            <div class="table-responsive">
                <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>User Approve</th>
                            <th>Cashier</th>
                            <th>Receipt No</th>
                            <th>Payment Method</th>
                            <th>Reference</th>
                            <th>Amount</th>
                            <th>Penalty</th>
                            <th>Option</th>
                            <th>
                                <label class="checkbox-list">
                                    <input type="checkbox" id="check_all">
                                    <span class="checkmark"></span>
                                </label>
                            </th>
                        </tr>
                    </thead>
                    <tbody id="tbody">

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

    </div>
</div>
<div class="overlay">
    <div id="loading-img"></div>
</div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('js'); ?>
<script type="text/javascript">
    $(document).ready(function() {
        $('#datatable_payment_pending').DataTable({
            ordering: false,
            serverSide: false,
            searching: true,
            paging: true,
            ajax: "<?php echo e(route('approve-client-payments-list')); ?>",
            "lengthMenu": [
                [25, 50, 100, -1],
                [25, 50, 100, "All"]
            ],
            dom: 'Blfrtip',
            buttons: [
                'copyHtml5',
                'excelHtml5',
                'csvHtml5',
                'pdfHtml5'
            ],
            columns: [{
                    data: 'DT_RowIndex'
                },
                {
                    data: 'date'
                },
                {
                    data: 'des'
                },
                {
                    data: 'user_approve'
                },
                {
                    data: 'user'
                },
                {
                    data: 'invoice'
                },
                {
                    data: 'bank'
                },
                {
                    data: 'reference'
                },
                {
                    data: 'payment',
                    'className': 'text-right'
                },
                {
                    data: 'penalty',
                    'className': 'text-right'
                },
                {
                    data: 'penalty_status'
                },
                {
                    data: 'check_id',
                    'width': '3px'
                }
            ]
        });
    });
    $(document).on('click', '#run_audit', function() {
        var Ids = [];
        $('.checkbox').each(function() {
            if ($(this).is(':checked')) {
                Ids.push($(this).data('id'));
            }
        });
        if (Ids.length == 0) {
            $.alert({
                title: 'Warning!',
                content: 'No Payment Selected!',
            });
        } else {
            $.confirm({
                title: 'Are Your Sure to Approve?',
                content: '<p>' + Ids.length + ' Payment(s) will be Audited</p>',
                buttons: {
                    formSubmit: {
                        text: 'Submit',
                        btnClass: 'btn-blue',
                        action: function() {
                            var name = this.$content.find('.name').val();
                            if (Ids.length <= 0) {
                                $.alert('Please Select Any Payment');
                                return false;
                            } else {
                                $('#main-spinner').show();
                                $.ajax({
                                    url: "<?php echo e(route('run-audit.payment')); ?>",
                                    type: "POST",
                                    dataType: 'json',
                                    data: {
                                        "_token": "<?php echo e(csrf_token()); ?>",
                                        Ids: Ids
                                    },
                                    success: function(data) {
                                        $('#done').show();
                                        $('#datatable_payment_pending').DataTable().ajax.reload();
                                        $('#main-spinner').hide();
                                    },
                                    error: function(err) {
                                        console.log(err);
                                    }
                                });
                            }
                        }
                    },
                    cancel: function() {},
                },
                onContentReady: function() {
                    var jc = this;
                    this.$content.find('form').on('submit', function(e) {
                        e.preventDefault();
                        jc.$$formSubmit.trigger('click');
                    });
                }
            });
        }
        $('#paymentIDs').val(Ids);
    });
    $(document).on('change', '#check_all', function() {
        if ($(this).is(':checked')) {
            $('.checkbox').prop('checked', true);
        } else {
            $('.checkbox').prop('checked', false);
        }
    });

    function search() {
        var start_date = $('#start_date').val();
        var end_date = $('#end_date').val();
        var cashier = $('#cashier').find(':selected').val();
        var method = $('#method').find(':selected').val();
        $('#datatable_payment_pending').DataTable().destroy();
        $('#datatable_payment_pending').DataTable({
            ordering: false,
            serverSide: false,
            searching: true,
            paging: true,
            ajax: {
                url: "<?php echo e(route('approve-client-payments-list')); ?>",
                type: "POST",
                data: {
                    _token: "<?php echo e(csrf_token()); ?>",
                    start: start_date,
                    end: end_date,
                    cashier: cashier,
                    method: method,
                    receipt_no: $("#receipt-no").val(),
                    reference: $("#reference").val()
                }
            },
            "lengthMenu": [
                [25, 50, 100, -1],
                [25, 50, 100, "All"]
            ],
            dom: 'Blfrtip',
            buttons: [
                'copyHtml5',
                'excelHtml5',
                'csvHtml5',
                'pdfHtml5'
            ],
            columns: [{
                    data: 'DT_RowIndex'
                },
                {
                    data: 'date'
                },
                {
                    data: 'des'
                },
                {
                    data: 'user_approve'
                },
                {
                    data: 'user'
                },
                {
                    data: 'invoice'
                },
                {
                    data: 'bank'
                },
                {
                    data: 'reference'
                },
                {
                    data: 'payment',
                    'className': 'text-right'
                },
                {
                    data: 'penalty',
                    'className': 'text-right'
                },
                {
                    data: 'penalty_status'
                },
                {
                    data: 'check_id',
                    'width': '3px'
                }
            ]
        });
    }
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>