
<style>
    .table thead tr >th{
        background-color: #4c0870;
        color:#fff;
    }
    .table thead tr th[class*='sorting_'] {
        color: #FFFFFF;
    }
    .bg-master-lighter {
        border:none;
        background-color:#fff;
        border-top:1px solid #ddd; 

    }
    .btn-default{
        border: none;
        background-color: #eee;
    }
    .btn-default:hover{
        background-color:#ed9421 !important;
        color:#fff;
        border: none;
    }

</style>
<div id="Barcode" style="display:none"></div>


<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('family_accounts'); ?></div>

            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <?php
            if ($permissions->hasPermission('add_family_account')) {
                echo Forms::FloatingAddButton('4c0870', '#add_family', CommonLanguage::getMessage('add'));
            }
            ?>
            <table class="table table-bordered table-hover demo-table-search" 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('Action'); ?></th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>



    </div>
</div>
<div class="modal fade bs-example-modal-md " data-backdrop="static" id="add_family" 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-label="Close"><span aria-hidden="true"><i class="pg-close fa-22"></i></span></button>
                <h4 class="modal-title"><?php print CommonLanguage::getMessage('family_accounts') ?></h4>
                <div id="assignFamilyAlert"></div>
            </div>
            <div class="modal-body">
                <form id="AssignFamilyForm">
                    <div class="row">
                        <div class=" col-md-12 m-t-10 " >
                            <label class="labelText"><?php print CommonLanguage::getMessage('Name'); ?><span class="red-star">*</span></label>
                            <input type="text" class="form-control" id="family_name" name="family_name" required/>
                        </div>
                        <div class=" col-md-12 m-t-10 " >
                            <label class="labelText"><?php print CommonLanguage::getMessage('accounts'); ?><span class="red-star">*</span></label>
                            <input type="hidden" class="full-width" id="family_accounts" name="family_accounts" 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 bg-complete white" id="assignBtn" style="width:auto"><?php print CommonLanguage::getMessage('Save') ?></button>
            </div>
        </div>
    </div>
</div>

<script>
    var title = <?php echo json_encode(CommonLanguage::getMessage('jobs')); ?>,
            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;
        })
        build_select2($("#family_accounts"), ("xhr/accIDSearch?type=Payment"), 1)

        RebuildDataTable(title, [0], "ACCAjax/family_accounts_list")

        $("#assignBtn").on("click", function () {
            $("#assignFamilyAlert").removeClass('hidden')
            if ($("#family_name").val() == '' ||$("#family_accounts").val() == '' ) {
                $("#assignFamilyAlert").attr("class", "alert alert-danger").html(Required_Fields)
                return false;

            }
            var DataArr = new FormData(document.getElementById("AssignFamilyForm"));
            DataArr.append("family_id", IDToEdit)
            DataArr.append("is_edit", (IsEdit ? 1 : 0))
            $.ajax({
                url: "ACCAjax/add_edit_family_accounts",
                method: "POST",
                dataType: 'json',
                data: DataArr,
                processData: false,
                contentType: false,
                complete: function (v1, v2) {
                    if (v2 == "success" && v1.responseJSON == 'OK') {
                        $("#assignFamilyAlert").attr("class", "alert alert-success").html(Submitted_Successfully)
                        RebuildDataTable(title, [0], "ACCAjax/family_accounts_list")
                        setTimeout(function () {
                            $("#assignFamilyAlert").addClass('hidden')
                            $("#add_family").modal("hide")
                        }, 5000)
                    } else {
                        $("#assignFamilyAlert").attr("class", "alert alert-danger").html(v1.responseJSON)
                    }
                }
            })
        })

        $("#tableWithSearch tbody").on('click', '.Edit', function () {
            IsEdit = true;
            IDToEdit = $(this).attr('data-id');
            $.ajax({
                url: "ACCAjax/get_family_accounts",
                method: "GET",
                dataType: "JSON",
                data: {id: IDToEdit},
                complete: function (v1, v2) {
                    var Data = v1.responseJSON;
                    $("#family_name").val(Data['main']['family_name'])
                    $("#family_accounts").data().select2.updateSelection(Data['accounts'])
                    $("#add_family").modal("show")
                }
            })


        })
    })





</script>
