<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"> <?php print CommonLanguage::getMessage('employee_banks'); ?></div>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <?php
            if ($permissions->hasPermission('add_employee_banks')) {
                echo Forms::FloatingAddButton('4c0870', '#add_banks', CommonLanguage::getMessage('add'));
            }
            ?>
            <div class="row">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered hrm" id="tableWithSearch" >
                        <thead>
                            <tr>
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('Name'); ?></th>
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('branch'); ?></th>
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('Code'); ?></th>
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('Action'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade " id="add_banks" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm"  >
        <div class="modal-content">
            <div class="modal-header clearfix text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label bold"><?php echo CommonLanguage::getMessage('employee_banks');?></h5>
                <div id="assignbanksAlert"></div>
            </div>
            <div class="modal-body">
                <form id="assignbankForm">
                    <div class="row form-group">
                        <div class=" col-md-12" >
                            <label class="labelText"><?php print CommonLanguage::getMessage('Name'); ?>
                                <span class="red-star">*</span>
                            </label>
                            <input type="text" class="form-control" id="bank_name" name="bank_name" required/>
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class=" col-md-12" >
                            <label class="labelText"><?php print CommonLanguage::getMessage('branch'); ?>
                                <span class="red-star">*</span>
                            </label>
                            <input type="text" class="form-control" id="bank_branch" name="bank_branch" required/>
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class=" col-md-12" >
                            <label class="labelText"><?php print CommonLanguage::getMessage('Code'); ?>
                                <span class="red-star">*</span>
                            </label>
                            <input type="text" class="form-control" id="bank_code" name="bank_code" required/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close') ?></button>
                <button type="button" class="btn btn-success" id="assignBtn"><?php print CommonLanguage::getMessage('Save') ?></button>
            </div>
        </div>
    </div>
</div>
<script>
    var title = <?php echo json_encode(CommonLanguage::getMessage('salary_periods')); ?>,
        Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
                Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>;
                var IsEdit = false, IDToEdit = 0;
    $(function () {
        $(".floatingContainer").on("click", function () {
            IsEdit = false;
            IDToEdit = 0;
        })
        RebuildDataTable(title, [0], "HRMAjax/employee_banks_ajax")
        $("#assignBtn").on("click", function () {
            if(!$("#assignbankForm").valid()){
                return;
            }
            var DataArr = new FormData(document.getElementById("assignbankForm"));
            DataArr.append("bank_id", IDToEdit)
            DataArr.append("is_edit", (IsEdit ? 1 : 0))
            $("#assignbanksAlert").removeClass('hidden')
            $.ajax({
                url: "HRMAjax/add_edit_employee_banks",
                method: "POST",
                dataType: 'json',
                data: DataArr,
                processData: false,
                contentType: false,
                complete: function (v1, v2) {
                    if (v2 == "success" && v1.responseJSON == 'OK') {
                        $("#assignbanksAlert").attr("class", "alert alert-success").html(Submitted_Successfully)
                        RebuildDataTable(title, [0], "HRMAjax/employee_banks_ajax")
                        setTimeout(function () {
                            $("#assignbanksAlert").addClass('hidden')
                            $("#add_banks").modal("hide")
                        }, 5000)
                    } else {
                        $("#assignbanksAlert").attr("class", "alert alert-danger").html(v1.responseJSON)
                    }
                }
            })
        })
        $("#tableWithSearch tbody").on('click', '.Edit', function () {
            IsEdit = true;
            IDToEdit = $(this).attr('data-id');
            var tr = $(this).parents("tr");
            $("#bank_name").val(tr.find("td:eq(0)").html())
            $("#bank_branch").val(tr.find("td:eq(1)").html())
            $("#bank_code").val(tr.find("td:eq(2)").html())
            $("#add_banks").modal("show")
        })
    })
</script>
