<?php $__env->startSection('content'); ?>

<div class="card">
    <div class="card-header">
        <div class="row align-items-center">
            <div class="col">
                <h5 class="mb-0">Loans</h5>
            </div>
            <div class="col-auto">
                <a href="<?php echo e(route('payroll.loans.create')); ?>" class="btn btn-primary btn-sm">
                    Add Loan
                </a>
            </div>
        </div>       
    </div>
    <div class="card-body">
        <table class="table table-bordered table-striped w-100" id="loantbl">
            <thead>
                <tr>
                    <th>#</th><th>Code</th><th>Name</th><th>Interest</th><th>Status</th><th width="120">Action</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
let table = $('#loantbl').DataTable({
    ajax: "<?php echo e(route('payroll.loans.index')); ?>",
        dom:
        "<'row mb-3 align-items-center'<'col-md-6'l><'col-md-6 d-flex justify-content-end'f>>" +
        "<'table-responsive'tr>" +
        "<'row mt-3 align-items-center'<'col-md-6'i><'col-md-6 d-flex justify-content-end'p>>",

        language: {
        search: "",
        searchPlaceholder: "Search loans...",
        lengthMenu: "Show _MENU_ entries",
        info: "Showing _START_–_END_ of _TOTAL_ loans"
        },
    columns: [
        {data:'DT_RowIndex'},
        {data:'code'},
        {data:'name'},
        {data:'interest_type'},
        {data:'status', orderable:false, searchable:false},
        {data:'action', orderable:false, searchable:false},
    ]
});


    $(document).on('click', '.btn-delete', function () {
        let id = $(this).data('id');

        Swal.fire({
            title: 'Are you sure?',
            text: 'This record will be deleted!',
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#d33',
            confirmButtonText: 'Yes, delete it'
        }).then((result) => {
            if (result.isConfirmed) {
                $.ajax({
                    url: "<?php echo e(url('payroll/loans')); ?>/" + id,
                    type: 'DELETE',
                    data: { _token: "<?php echo e(csrf_token()); ?>" },
                    success: function (res) {
                        Swal.fire('Deleted!', res.message, 'success');
                        table.ajax.reload();
                    }
                });
            }
        });
    });
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /media/madu/E8460E1D460DECDE/projects/laraoffice/app/Modules/HR/Payroll/Providers/../Views/loans/index.blade.php ENDPATH**/ ?>