<style>
    .table thead tr >th{
        background-color:#4c0870;
        color:#fff;
        /*width: 16% !important;*/
    }
    .success {background:#4c0870 !important}
</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('employee_due_payments'); ?></div>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-3 form-group">
                    <label><?php echo CommonLanguage::getMessage('Date');?></label>
                    <div class="input-group  ">
                        <span class="input-group-addon success ">
                            <i class="fa fa-calendar"></i>
                        </span>
                        <input id="range_date" type="text" class="form-control" readonly="" name="range_date">
                    </div>
                </div>
                <div class="col-md-3 form-group <?php echo $permissions->hasPermission('see_all_employee_payment') ? '' : 'hidden' ?>">
                    <label><?php echo CommonLanguage::getMessage('employee_name') ?></label><span class="red-star">*</span>
                    <input type="hidden" id="employee_select_id" name="employee_select_id" class='full-width employee_select_id' />
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover demo-table-search" id="tableWithSearch">
                            <thead>
                                <tr>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('employee'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('real_work'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('basic_salary'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('total'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var startDate = '<?php echo date('Y-m-d');?>', 
        endDate = '<?php echo date('Y-m-d');?>',
        show_all_emp_payments_dudates = <?php echo json_encode($permissions->hasPermission('see_all_employee_payment'));?>,
        is_actual=<?php echo json_encode($is_actual);?>;
        $(function(){
            build_select2($('#employee_select_id'), 'xhr/employeeSearch?is_actual='+is_actual);
            if(!show_all_emp_payments_dudates){
                $('#employee_select_id').val('<?php echo smc_session()['user_details']['Employee_ID'];?>');
                $('#employee_select_id').attr('data-select-name','<?php echo smc_session()['user_details']['Employee_FirstName'].' '.smc_session()['user_details']['Employee_LastName'];?>');
                build_select2($('#employee_select_id'), 'xhr/employeeSearch?is_actual='+is_actual);
            }
            AjaxCall();
            $("input[name=range_date]").daterangepicker({
                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");
                AjaxCall()
            });
            $('#employee_select_id').on('change',function(){
                AjaxCall();
            });
        });
    function AjaxCall(){
        var data = {
            employee_id:$('#employee_select_id').val(),
            start_date: startDate,
            end_date:endDate,
            is_actual: is_actual
        }
        $('#tableWithSearch').DataTable().destroy();
        $("#tableWithSearch tbody").empty();
        $.ajax({
            url: 'HRMAjax/getEmployeeDuePayments',
            method: 'GET',
            data: data,
            complete: function (data, vv) {
                if(vv == 'success'){
                    $('#tableWithSearch tbody').html(data.responseText);
                    RebuildDataTable();
                }
            }
        });
    }
</script>