
<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('paid_accrued_leave'); ?></div>
            <div class="clearfix"></div>

        </div>
        <div id="AssignLeaveValidationAlert"></div>
        <div class="panel-body">
            <div class="row m-b-10">
                <div class="col-md-12">

                    <div class="col-md-3  ">
                        <label><?php echo CommonLanguage::getMessage('Date') ?></label>
                        <input type="text" id="EmployeeDate" class="form-control EmployeeDate" name="EmployeeDate" />
                    </div>

                    <div class="col-md-3">
                        <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>
            <div class="row">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered hrm" id="tableWithSearch">
                        <thead>
                        <th  class="text-center"><?php print CommonLanguage::getMessage('employee_name'); ?></th>
                        <th  class="text-center"><?php print CommonLanguage::getMessage('Date'); ?></th>
                        <th  class="text-center"><?php print CommonLanguage::getMessage('day_number'); ?></th>
                        <th  class="text-center"><?php print CommonLanguage::getMessage('amount'); ?></th>
                        <th  class="text-center"><?php print CommonLanguage::getMessage('Action'); ?></th>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>

        </div>
    </div>
</div>

<script>
    var title = <?php echo json_encode(CommonLanguage::getMessage('paid_accrued_leave')) ?>,
            is_actual = <?php echo json_encode($is_actual); ?>,
            startDate =<?php echo json_encode($today); ?>, endDate =<?php echo json_encode($today); ?>,
            id_to_edit = 0, is_edit = false;

    $(function () {
        build_select2($('.employee_select_id'), 'xhr/employeeSearch?is_actual=' + is_actual + '&with_id=1');


        $('#EmployeeDate').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");
            build_table()
        })
        //        $("#pend-status").val(is_approved).select2()
        build_table()
        $('.employee_select_id').on("click", function () {
            build_table()

        })
//        $(".actionButton").on("click", function () {
//            id_to_edit = 0;
//            is_edit = false;
//        })
//        $("#tableWithSearch").on("click", ".edit_leave", function () {
//            id_to_edit = $(this).parents('.Action').attr('data-id');
//            is_edit = true;
//            $.ajax({
//                url: "HRMAjax/view_leave_by_id",
//                data: {id: $(this).parents('.Action').attr('data-id')},
//                dataType: 'json',
//                complete: function (v1, v2) {
//                    if (v2 == 'success') {
//                        var data = v1.responseJSON;
//                        $("#Employee_AssignAcruedLeave").val(data['Employee_ID']).select2()
//                        $("#is_half_day").prop("checked", data['is_half_day'] ? true : false)
//                        $("#trs_dys").prop("checked", data['trs_dys'] ? true : false)
//                        //                        build_select2($('.Employee_ID'), 'xhr/employeeSearch?is_actual=' + is_actual);
//                        $("#From_To_Date").val(data['Date_From'] + ' - ' + data['Date_To'])
//                        $("#AssignAcruedLeave").modal("show")
//                        //                        build_table()
//                    }
//                }
//            })
//        })






    })
    function build_table() {
        var data = {is_actual: is_actual,
            start_date: window.startDate ? window.startDate : startDate,
            employee_id: $("input.employee_select_id").val(),
            end_date: window.endDate ? window.endDate : endDate};
        var optns = {
            cb_ft: function (dt_optns) {
                // stop sorting for column since on click on header checkbox the sorting is triggered
                dt_optns.columnDefs.push({targets: [0], "orderable": false});
            },
        };
        RebuildDataTable(title, '', 'HRMAjax/paid_accrued_list_ajax', data, '', '', optns);
    }
</script>