<?php $__env->startSection('content'); ?>
    <?php Fun::lang()?>
    <div class="modal fade bs-modal-lg" id="upload-file-modal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-dm modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h3 class="modal-title">Upload File</h3>
                </div>
                <div id="_div_paymentPopup" style="display:none;" class="alert alert-block alert-danger fade in">
                    <h4 class="alert-heading">Warning!</h4>
                    <p id="_msg_paymentPopup"></p>
                </div>

                <div style="display:none;" class="alert-message alert-success" role="alert" id="done">
                    <h4 class="alert-heading">Successfully!</h4>
                    <hr>
                    <p class="mb-0">Data has been saved successfully!</p>
                </div>
                <br />
                <form class="form-horizontal" role="form" action="<?php echo e(route('save_upload_image')); ?>" method="post" enctype="multipart/form-data" id="form-save-image">
                    <?php echo csrf_field(); ?>
                    <div class="row">
                        <div class="col-sm-12" style="text-align: center;padding: 20px;margin-left: 100px;">
                            <input type="hidden" id="loan-id-input" name="loan_id">
                            <input type="file" id="file-upload-input" name="file_name[]" multiple>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="button_danger" data-dismiss="modal">Close</button>
                        <button type="submit" class="button_success">Submit</button>
                    </div>
                </form>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <?php echo $__env->make('administrator.client_loan_with_bank.edit', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <?php echo $__env->make('administrator.client_loan_with_bank.show-file-download', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <div class="title-add">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li> <a class="ng-binding" href="#"><i class="fa fa-dashboard"></i> Dashboard</a> </li>
                <li><a href="#">Client Loan with bank</a></li>
            </ul>
        </div>
    </div>
    <div class="page">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                    <div class="title-add">
                        <div class="pull-left">
                            <h3>Client Loan with bank list</h3>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body table-responsive">
            <table id="client_loan_bank" class="table table-striped table-bordered table-hover nowrap">
                <thead>
                <tr>
                    <th>No</th>
                    <th>Full Name</th>
                    <th>Gender</th>
                    <th>DOB</th>
                    <th>Phone</th>
                    <th>Amount With Bank</th>
                    <th>Item Name</th>
                    <th>Project Name</th>
                    <th>Category</th>
                    <th>Sub Category</th>
                    <th>Action</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
    <script type="text/javascript">
        function show_document(loan_id) {
            var route = "<?php echo e(route('show_upload_image',':id')); ?>";
            route = route.replace(":id",loan_id);
            $("#main-spinner").show();
            $.ajax({
                url:route,
                type:"GET",
                dataType:"JSON",
                success:function (data) {
                    $("#main-spinner").hide();
                    $("#show-download-file").modal('show');
                    $("#tb-file-download").find("tbody").empty();
                    $.each(data,function (index,val) {
                        var local= "/assets/document/"+val.file_name;
                        $("#tb-file-download").find("tbody").append(`
                            <tr>
                                <td>${index+1}</td>
                                <td>${val.file_name}</td>
                                <td>
                                     <a style="color:white;margin-left:0;" href="${local}" download class="button_info btn-circle" title="Download">
                                        <i class="glyphicon glyphicon-save"></i>
                                     </a>
                                </td>
                            </tr>
                        `);
                    })
                },
                error:function () {

                }
            })
        }
        function show_upload(loan_id) {
            $("#upload-file-modal").modal("show");
            $("#loan-id-input").val(loan_id);
        }
        function status_note(obj) {
           var status = $(obj).prop("checked");
           var type = "";
           if(status==false){
               type = "uncheck";
           }else{
               type = "checked";
           }
           $(obj).closest('tr').find("td:eq(2)").find('input').val(type);
        }
        function edit_follow_up(loan_id){
            $("#main-spinner").show();
            $.ajax({
                url:"<?php echo e(route('get_follow_up')); ?>",
                type:"POST",
                dataType:"JSON",
                data:{
                  "_token":"<?php echo e(csrf_token()); ?>",
                    loan_id:loan_id
                },
                success:function (data) {
                    $("#main-spinner").hide();
                    $("#show-follow-up").modal("show");
                    $("#btn-save-follow-up").show();
                    $("#follow-up-loan-id").val(loan_id);
                    var tr=``;
                    $.each(data,function (index,value) {
                        var status = ``;var con="";
                        if(value.status==1){
                            con = `<input type="hidden" name="type[]" value="checked" class="type-check form-control">`;
                            status=`<input type="checkbox" name="follow_up_status[]" checked onchange="status_note(this)">`;
                        }

                        else {
                            con=`<input type="hidden" name="type[]" value="uncheck" class="type-check form-control">`;
                            status=`<input type="checkbox" name="follow_up_status[]" onchange="status_note(this)">`;
                        }
                        tr+=`<tr>
                                <td>${index+1}</td>
                                <td>${value.bank_loan_procedures_name}</td>
                                <td>${value.bank_loan_procedures_description==null?"":value.bank_loan_procedures_description} ${con}</td>
                                <td>
                                    <label style="width: 100%;font-size: 14px" class="checkbox-list">
                                        ${status}
                                        <span class="checkmark"></span>
                                    </label>
                                     <input type="hidden" name="follow_id_data[]" value="${value.id}">
                                </td>
                            </tr>`;
                    });
                    $("#follow-up-tbody").find("tbody").empty();
                    $("#follow-up-tbody tbody").append(tr);
                },
                error:function () {

                }
            });
        }
        function show_follow_up(loan_id){
            $("#main-spinner").show();
            $.ajax({
                url:"<?php echo e(route('get_follow_up')); ?>",
                type:"POST",
                dataType:"JSON",
                data:{
                    "_token":"<?php echo e(csrf_token()); ?>",
                    loan_id:loan_id
                },
                success:function (data) {
                    $("#main-spinner").hide();
                    $("#show-follow-up").modal("show");
                    $("#btn-save-follow-up").hide();
                    $("#follow-up-loan-id").val(loan_id);
                    var tr=``;
                    $.each(data,function (index,value) {
                        var status = ``;var con="";
                        if(value.status==1){
                            con = `<input type="hidden" name="type[]" value="checked" class="type-check form-control">`;
                            status=`<input type="checkbox" name="follow_up_status[]" disabled checked onchange="status_note(this)">`;
                        }

                        else {
                            con=`<input type="hidden" name="type[]" value="uncheck" class="type-check form-control">`;
                            status=`<input type="checkbox" name="follow_up_status[]" disabled onchange="status_note(this)">`;
                        }
                        tr+=`<tr>
                                <td>${index+1}</td>
                                <td>${value.bank_loan_procedures_name}</td>
                                <td>${value.bank_loan_procedures_description==null?"":value.bank_loan_procedures_description} ${con}</td>
                                <td>
                                    <label style="width: 100%;font-size: 14px" class="checkbox-list">
                                        ${status}
                                        <span class="checkmark"></span>
                                    </label>
                                     <input type="hidden" name="follow_id_data[]" value="${value.id}">
                                </td>
                            </tr>`;
                    });
                    $("#follow-up-tbody").find("tbody").empty();
                    $("#follow-up-tbody tbody").append(tr);
                },
                error:function () {

                }
            });
        }
        $(document).ready(function(){
            $('#main-spinner').show();
            $('#client_loan_bank').DataTable({
                ordering: false,
                serverSide: true,
                ajax: "<?php echo e(route('get_data_client_loan_bank')); ?>",
                columns: [

                    {data: 'DT_RowIndex'},
                    {data: "client_name"},
                    {data: "client_gender"},
                    {data: "client_dob"},
                    {data: "client_phone"},
                    {data: "amount_bank"},
                    {data: "item_names"},
                    {data: "project_name"},
                    {data: "category_name"},
                    {data: "sub_category_name"},
                    {data: "action"},

                ],
                "initComplete": function(settings, json) {
                    $('#main-spinner').hide();
                }
            });

            $.fn.dataTable.ext.errMode = 'throw';
        });

    </script>

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


<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>