<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 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('cash_drawer_accounts'); ?></div>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <?php
            echo Forms::FloatingAddButton('4c0870', '#add-edit-cash-drawer-modal', CommonLanguage::getMessage('add'),'add_cash_drawer');
            ?>
            <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('cash_account'); ?></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-edit-cash-drawer-modal">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label h-labels text-left semi-bold hidden"><?php echo CommonLanguage::getMessage('add_cash_drawer');?></h5>
                <h5 class="edit-label h-labels text-left semi-bold hidden"><?php echo CommonLanguage::getMessage('edit_cash_drawer');?></h5>
            </div>
            <div class="modal-body">
                <form id="cash_drawer_form" method="POST" onsubmit="return false">
                    <input type='hidden' name='cash_drawer_id' id='cash_drawer_id'/>
                    <div class="row">
                        <?php echo Forms::AlertDiv('cash_drawer_alert'); ?>
                        <div class="col-md-12 form-group m-t-10">
                            <label><?php print CommonLanguage::getMessage('title'); ?></label><span class="red-star">*</span>
                            <input type="text"  placeholder="<?php print CommonLanguage::getMessage('title'); ?>" id="cash_drawer_title" name="cash_drawer_title" class="form-control " required>
                        </div>
                        <div class="col-md-12 form-group">
                            <label class="labelText"><?php print CommonLanguage::getMessage('cash_account'); ?></label>
                            <span class="red-star">*</span>
                            <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="cash_account" name="cash_account" type="hidden"  required/>
                        </div>
                        <div class="col-md-12 form-group">
                            <label class="labelText"><?php print CommonLanguage::getMessage('branch'); ?></label>
                            <span class="red-star">*</span>
                            <span class="fa fa-plus-circle m-l-5 openFrame" data-src="ACC/org_branches?is_pop=1" style="color:#4c0870;cursor:pointer"></span>
                            <input class=" full-width" id="default_branch" name="default_branch" type="hidden" required />
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button class="btn bg-complete white" id="submit_cash_drawer"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('cashDrawerLoader'); ?>
        </div>
    </div>
</div>
<script>
    $(function () {
        RebuildDataTable($('.panel-heading .panel-title').html(), [0,1], 'ACCAjax/CashDrawerAccounts');
        build_select2($("#cash_account"), ("xhr/accIDSearch?type=cash"));
        build_select2($("#default_branch"), "xhr/CommonSearch?col_id=branch_id&col_name=branch_name&table=tbl_organization_branches");
        $(".add_cash_drawer").on("click", function () {
            $("#cash_drawer_id").val(0);
            $("#add-edit-cash-drawer-modal .add-label").removeClass('hidden');
        });
        $("#tableWithSearch").on("click", ".edit_cash_drawer", function () {
            var cash_drawer_id = $(this).attr('data-id');
            $("#cash_drawer_id").val(cash_drawer_id);
            $("#add-edit-cash-drawer-modal .edit-label").removeClass('hidden');
            CommonViewById('',{table:'view_cash_drawer_accounts',entry_id:'cash_drawer_id',entry_value:cash_drawer_id},
                           '#cashDrawerLoader',function(response){
                $('#cash_drawer_title').val(response[0].cash_drawer_title)
                $('#cash_account').val(response[0].cash_account_id);
                $('#cash_account').attr('data-select-name',response[0].account_name);
                 build_select2($("#cash_account"), ("xhr/accIDSearch?type=cash"));
                $('#default_branch').val(response[0].branch_id);
                $('#default_branch').attr('data-select-name',response[0].branch_name);
                build_select2($("#default_branch"), "xhr/CommonSearch?col_id=branch_id&col_name=branch_name&table=tbl_organization_branches");
            });
        });
        $("#submit_cash_drawer").on("click", function () {
            if (!$("#cash_drawer_form").valid())
                return;
            var Data = new FormData(document.getElementById("cash_drawer_form"));
            $("#cashDrawerLoader").removeClass('hidden');
            $.ajax({
                url: "ACCAjax/submitCashDrawerAccount",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            RebuildDataTable($('.panel-heading .panel-title').html(), [0,1], 'ACCAjax/CashDrawerAccounts');
                            hideModalAlert('add-edit-cash-drawer-modal', 'cash_drawer_alert');
                        }
                        AddAlert("#cash_drawer_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#cashDrawerLoader").addClass('hidden');
                }
            });
        });
        //        $("#tableWithSearch tbody").on('click', '.Edit', function () {
        ////            IsEdit = true;
        //            $.ajax({
        //                url: "ACCAjax/getUserAccounts",
        //                method: "GET",
        //                dataType: "JSON",
        //                data: {id: $(this).attr('data-id')},
        //                complete: function (v1, v2) {
        //                    var Data = v1.responseJSON;
        //                    $("#users").val(Data['User_ID']).select2()
        //                    $("#cash_account").val(Data['cash_account_id']).attr("data-select-name", Data['c_name'])
        //                    $("#cheque_account").val(Data['cheque_account_id']).attr("data-select-name", Data['cheque_name'])
        //                    $("#purchase_account").val(Data['purchase_account_id']).attr("data-select-name", Data['p_name'])
        //                    $("#sales_account").val(Data['sales_account_id']).attr("data-select-name", Data['s_name'])
        //                    $("#purchase_shipping").val(Data['pur_ship_account_id']).attr("data-select-name", Data['ps_name'])
        //                    $("#sales_shipping").val(Data['sales_ship_account_id']).attr("data-select-name", Data['ss_name'])
        //                    $("#deposit_accounts").val(Data['deposit_account_id']).select2()
        //                    $("#Other_Account").val(Data['other_account_id']).select2()
        //                    $("#withdrawal_accounts").val(Data['withdrawal_account_id']).select2()
        //                    $("#default_class").val(Data['class_id']).attr("data-select-name", Data['Class_Name'])
        //                    $("#default_depot").val(Data['depot_id']).attr("data-select-name", Data['Depot_Name'])
        //                    $("#default_branch").val(Data['branch_id']).attr("data-select-name", Data['branch_name'])
        //                    $("#user_prefix").val(Data['serial_prefix'])
        //                    $("#max_discount").val(Data['max_discount'])
        //                    $("#edit_price").prop("checked",Data['edit_price'] ==1 ? true : false)
        //                    build_select2($("#cash_account"), ("xhr/accIDSearch?type=cash"))
        //                    build_select2($("#cheque_account"), ("xhr/accIDSearch?type=check"))
        //                    build_select2($("#purchase_account"), ("xhr/accIDSearch?type=purchase"))
        //                    build_select2($("#purchase_shipping"), ("xhr/accIDSearch?type=purchase"))
        //                    build_select2($("#sales_account"), ("xhr/accIDSearch?type=sales"))
        //                    build_select2($("#sales_shipping"), ("xhr/accIDSearch?type=sales"))
        //                    build_select2($("#default_class"), "xhr/PricingClassSearch")
        //                    build_select2($("#default_depot"), "xhr/depotSearch")
        //                    build_select2($("#default_branch"), "xhr/CommonSearch?col_id=branch_id&col_name=branch_name&table=tbl_organization_branches")
        //                    $("#assignUserAccount").modal("show")
        //                }
        //            })
        //
        //        })
    });
</script>
