<div class="wrapper">
    <div class="panel ">
        <div class="panel-heading">
            <div class="panel-title"><?php print CommonLanguage::getMessage($is_actual == 1 ? 'employee_advance_payment_act' :'employee_advance_payment'); ?></div>
            <div id="alertdiv"></div>
        </div>
        <div class="panel-body">
            <div class="row form-group">
                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('departments') ?></label>
                    <input type="hidden" id="department_id" class="full-width department_id" name="department_id" />
                </div>
                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('employee_name') ?></label>
                    <input type="hidden" id="employee_select_id" autocomplete="off" name="employee_select_id" class='full-width employee_select_id' />
                </div>
                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('bank_name') ?></label>
                    <input type="hidden"  placeholder="<?php print CommonLanguage::getMessage('bank_name'); ?>" id="bank_id" name="bank_id" class="full-width " >
                </div>
                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('nssf') . ' ?' ?></label>
                    <select id="is_nssf" class="full-width" data-init-plugin="select2" name="is_nssf" >
                        <option value=""><?php echo CommonLanguage::getMessage('All') ?></option>
                        <option value="1"><?php echo CommonLanguage::getMessage('yes') ?></option>
                        <option value="0"><?php echo CommonLanguage::getMessage('no') ?></option>
                    </select>
                </div>
            </div>
            <div class="row form-group">
                <div class="col-md-3 ">
                    <label><?php echo CommonLanguage::getMessage('Date') ?></label>
                    <input type="text" id="current_date" autocomplete="off" class="form-control current_date" name="current_date" />
                </div>
                <div class='col-md-2 m-t-25 pull-right'>
                    <button class='btn btn-success pull-right' id='search_advance_payment'><?php echo CommonLanguage::getMessage('search') ?></button>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered hrm" id="tableWithSearch">
                        <thead>
                            <tr>
                                <th class="text-center"><?php echo CommonLanguage::getMessage('employee_name') ?></th>
                                <th class="text-center"><?php echo CommonLanguage::getMessage('bank_name') ?></th>
                                <th class="text-center"><?php echo CommonLanguage::getMessage('branch') ?></th>
                                <th class="text-center"><?php echo CommonLanguage::getMessage('bank_account') ?></th>
                                <th class="text-center"><?php echo CommonLanguage::getMessage('amount') ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var startDate =<?php echo json_encode($today); ?>, endDate =<?php echo json_encode($today); ?>,is_actual= <?php echo json_encode($is_actual);?>;
    $(function () {
        buildCurrentTable();
        build_select2($('.department_id'), 'HRMAjax/searchDepartment');
        build_select2($('.employee_select_id'), 'xhr/employeeSearch?is_actual='+is_actual, 1);
        build_select2($("#bank_id"), "HRMAjax/searchBanks?add_no_bank=1");
        $('#current_date').daterangepicker({locale: {
            format: 'YYYY-MM-DD'
        }, ranges: {
            'Today': [moment(), moment()],
            'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
            'Last 7 Days': [moment().subtract(6, 'days'), moment()],
            'Last 30 Days': [moment().subtract(29, 'days'), moment()],
            'This Month': [moment().startOf('month'), moment().endOf('month')],
            'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        }}, function (start, end, label) {
            window.startDate = start.format("YYYY-MM-DD");
            window.endDate = end.format("YYYY-MM-DD");
        })
        $('#search_advance_payment').on('click',function(){
            buildCurrentTable()
        });
    });
    function buildCurrentTable(){
        var data = {
            from_date: (window.startDate ? window.startDate : today),
            to_date: (window.endDate ? window.endDate : today),
            dep_id: $('#department_id').val(),
            emp_id: $('#employee_select_id').val(),
            bank_id: $('#bank_id').val(),
            is_nssf: $("#is_nssf").val(),
            is_actual:is_actual
        };
        RebuildDataTable($('.panel-heading .panel-title').html(), [0, 1, 2, 3], 'HRMAjax/AdvancePaymentList',data);

    }
</script>