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

            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <?php
            echo Forms::FloatingAddButton('4c0870', '#add_group_accounts', 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" data-backdrop="static" id="add_group_accounts" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width:50%">
        <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('group_accounts') ?></h4>
                <div id="assignGroupAlert"></div>
            </div>
            <div class="modal-body">
                <form id="AssignGroupForm">
                    <div class="row">

                        <div class=" col-md-12 m-t-10 " >
                            <div class="col-md-6 p-r-5 p-l-5">
                                <label class="labelText"><?php print CommonLanguage::getMessage('Name'); ?></label>
                                <span class="red-star">*</span>
                                <input type="text" class="form-control" id="group_name" name="group_name" required/>
                            </div>


                            <div class="col-md-6">
                                <label class="labelText"><?php print CommonLanguage::getMessage('purchase_account'); ?></label>
                                <span class="fa fa-plus-circle m-l-5 openFrame" data-src="ACC/viewlibrary/1?is_pop=1" style="color:#4c0870;cursor:pointer"></span>

                                <input class=" full-width" id="pur_acc_id" name="pur_acc_id" type="hidden"  />

                            </div>


                        </div>
                        <div class=" col-md-12 m-t-10 " >
                            <div class="col-md-6">
                                <label class="labelText"><?php print CommonLanguage::getMessage('purchase_tax_account'); ?></label>
                                <span class="fa fa-plus-circle m-l-5 openFrame" data-src="ACC/viewlibrary/1?is_pop=1" style="color:#4c0870;cursor:pointer"></span>

                                <input class=" full-width" id="pur_tax_acc_id" name="pur_tax_acc_id" type="hidden"  />
                            </div>


                            <div class="col-md-6">
                                <label class="labelText"><?php print CommonLanguage::getMessage('purchase_return_account'); ?></label>
                                <span class="fa fa-plus-circle m-l-5 openFrame" data-src="ACC/viewlibrary/1?is_pop=1" style="color:#4c0870;cursor:pointer"></span>

                                <input class=" full-width" id="pur_return_acc_id" name="pur_return_acc_id" type="hidden"  />

                            </div>


                        </div>

                        <div class=" col-md-12 m-t-10 " >
                            <div class="col-md-6">
                                <label class="labelText"><?php print CommonLanguage::getMessage('purchase_return_tax_account'); ?></label>
                                <span class="fa fa-plus-circle m-l-5 openFrame" data-src="ACC/viewlibrary/1?is_pop=1" style="color:#4c0870;cursor:pointer"></span>
                                <input class=" full-width" id="pur_return_tax_acc_id" name="pur_return_tax_acc_id" type="hidden"  />
                            </div>
                            <div class="col-md-6">
                                <label class="labelText"><?php print CommonLanguage::getMessage('sales_account'); ?></label>
                                <span class="fa fa-plus-circle m-l-5 openFrame" data-src="ACC/viewlibrary/1?is_pop=1" style="color:#4c0870;cursor:pointer"></span>
                                <input class=" full-width" id="sales_acc_id" name="sales_acc_id" type="hidden"  />
                            </div>
                        </div>
                        <div class=" col-md-12 m-t-10 " >
                            <div class="col-md-6">
                                <label class="labelText"><?php print CommonLanguage::getMessage('sales_tax_account'); ?></label>
                                <span class="fa fa-plus-circle m-l-5 openFrame" data-src="ACC/viewlibrary/1?is_pop=1" style="color:#4c0870;cursor:pointer"></span>
                                <input class=" full-width" id="sales_tax_acc_id" name="sales_tax_acc_id" type="hidden"  />
                            </div>
                            <div class="col-md-6">
                                <label class="labelText"><?php print CommonLanguage::getMessage('sales_return_account'); ?></label>
                                <span class="fa fa-plus-circle m-l-5 openFrame" data-src="ACC/viewlibrary/1?is_pop=1" style="color:#4c0870;cursor:pointer"></span>
                                <input class=" full-width" id="sales_return_acc_id" name="sales_return_acc_id" type="hidden"  />
                            </div>
                        </div>
                        <div class=" col-md-12 m-t-10 " >
                            <div class="col-md-6">
                                <label class="labelText"><?php print CommonLanguage::getMessage('sales_return_tax_account'); ?></label>
                                <span class="fa fa-plus-circle m-l-5 openFrame" data-src="ACC/viewlibrary/1?is_pop=1" style="color:#4c0870;cursor:pointer"></span>
                                <input class=" full-width" id="sales_return_tax_id" name="sales_return_tax_id" type="hidden"  />
                            </div>
                        </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('user_accounts')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            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($("#pur_acc_id"), ("xhr/accIDSearch?type=purchase"))
        build_select2($("#pur_tax_acc_id"), ("xhr/accIDSearch?type=purchase"))
        build_select2($("#pur_return_acc_id"), ("xhr/accIDSearch?type=purchase"))
        build_select2($("#pur_return_tax_acc_id"), ("xhr/accIDSearch?type=purchase"))

        build_select2($("#sales_acc_id"), ("xhr/accIDSearch?type=sales"))
        build_select2($("#sales_tax_acc_id"), ("xhr/accIDSearch?type=sales"))
        build_select2($("#sales_return_acc_id"), ("xhr/accIDSearch?type=sales"))
        build_select2($("#sales_return_tax_id"), ("xhr/accIDSearch?type=sales"))

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

        $("#assignBtn").on("click", function () {
            $("#assignGroupAlert").removeClass('hidden')
            if($('#group_name').val() == ''){
                $("#assignGroupAlert").attr("class", "alert alert-danger").html('<?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>')

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

        $("#tableWithSearch tbody").on('click', '.Edit', function () {
            IsEdit = true;
            IDToEdit = $(this).attr('data-id');
//            IsEdit = true;
            $.ajax({
                url: "ACCAjax/get_group_accounts",
                method: "GET",
                dataType: "JSON",
                data: {id: $(this).attr('data-id')},
                complete: function (v1, v2) {
                    var Data = v1.responseJSON;

                    $("#pur_acc_id").val(Data['pur_acc_id']).attr("data-select-name", Data['pur_acc_name'])
                    $("#pur_tax_acc_id").val(Data['pur_tax_acc_id']).attr("data-select-name", Data['pur_tax_acc_name'])
                    $("#pur_return_acc_id").val(Data['pur_return_acc_id']).attr("data-select-name", Data['pur_return_acc_name'])
                    $("#pur_return_tax_acc_id").val(Data['pur_return_tax_acc_id']).attr("data-select-name", Data['pur_return_tax_acc_name'])
                    $("#sales_acc_id").val(Data['sales_acc_id']).attr("data-select-name", Data['sales_acc_name'])
                    $("#sales_tax_acc_id").val(Data['sales_tax_acc_id']).attr("data-select-name", Data['sales_tax_acc_name'])
                    $("#sales_return_acc_id").val(Data['sales_return_acc_id']).attr("data-select-name", Data['sales_return_acc_name'])
                    $("#sales_return_tax_id").val(Data['sales_return_tax_id']).attr("data-select-name", Data['sales_return_tax_name'])

                    $("#group_name").val(Data['group_name'])
                    build_select2($("#pur_acc_id"), ("xhr/accIDSearch?type=purchase"))
                    build_select2($("#pur_tax_acc_id"), ("xhr/accIDSearch?type=purchase"))
                    build_select2($("#pur_return_acc_id"), ("xhr/accIDSearch?type=purchase"))
                    build_select2($("#pur_return_tax_acc_id"), ("xhr/accIDSearch?type=purchase"))

                    build_select2($("#sales_acc_id"), ("xhr/accIDSearch?type=sales"))
                    build_select2($("#sales_tax_acc_id"), ("xhr/accIDSearch?type=sales"))
                    build_select2($("#sales_return_acc_id"), ("xhr/accIDSearch?type=sales"))
                    build_select2($("#sales_return_tax_id"), ("xhr/accIDSearch?type=sales"))
                    $("#add_group_accounts").modal("show")
                }
            })

        })
    })





</script>
