<?php
if ((!$is_actual && $permissions->hasPermission('addEmployeeDeductionNote')) || ($is_actual && $permissions->hasPermission('addActEmployeeDeductionNote'))) {
    include('Views/HRM/AddEmployeeDeductionNote.php');
}
?>
<style>
    .table thead tr >th{
        background-color:#4c0870;
        color:#fff;
        width: 17% !important;
    }
    .table thead tr th[class*='sorting_'] {
        color: #fff;
    }
    .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:#4c0870!important;
        color:#fff;
        border: none;
    }
    #Employee_Role{
        border: 2px solid #ddd;
        background: #eee;
        width: 100%;
        margin-left: 16px;
    }
</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('viewemployeedeductionnote') ?></div>
            <?php
            if ((!$is_actual && $permissions->hasPermission('addEmployeeDeductionNote')) || ($is_actual && $permissions->hasPermission('addActEmployeeDeductionNote'))) {


                echo Forms::FloatingAddButton('4c0870', '#add_employee_deduction_note', CommonLanguage::getMessage('add_employee_deduction_note'));
            }
            ?>  <div id="ValidationAlert"> </div>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <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('Date') ?></th>
                        <th class="text-center"><?php print CommonLanguage::getMessage('type') ?></th>
                        <th class="text-center"><?php print CommonLanguage::getMessage('note') ?></th>
                        <th class="text-center"><?php print CommonLanguage::getMessage('status') ?></th>
                        <th class="text-center"><?php print CommonLanguage::getMessage('Action') ?></th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>


<script>
    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            title = <?php echo json_encode(CommonLanguage::getMessage('viewemployeedeductionnote')) ?>,
            is_actual = <?php echo json_encode($is_actual); ?>;
    $(function () {


        RebuildDataTable(title, [0, 1, 2, 3, 4], 'HRMAjax/viewEmployeeDeductionNote', {is_actual: is_actual});



        $("#tableWithSearch").on("click", ".Reject", function () {
            $.ajax({
                url: "HRMAjax/rejectEmployeeDeductionNote",
                method: "POST",
                data: {id: $(this).attr('data-id'), status: $(this).attr('data-status')},
                complete: function (v1, v2) {
                    if (v2 == 'success' && v1.responseText == 'OK') {
                        RebuildDataTable(title, [0, 1, 2, 3, 4], 'HRMAjax/viewEmployeeDeductionNote', {is_actual: is_actual});
                        $("#ValidationAlert").attr("class", "alert alert-success").empty().html(Submitted_Successfully);
                    } else {
                        $("#ValidationAlert").attr("class", "alert alert-success").empty().html(Submitted_Successfully);
                    }
                }
            })
        })



        $("#tableWithSearch").on("click", ".Delete", function () {
            $.ajax({
                url: "HRMAjax/deleteEmployeeDeductionNote",
                method: "POST",
                data: {id: $(this).attr('data-id')},
                complete: function (v1, v2) {
                    if (v2 == 'success' && v1.responseText == 'OK') {
                        RebuildDataTable(title, [0, 1, 2, 3, 4], 'HRMAjax/viewEmployeeDeductionNote', {is_actual: is_actual});
                        $("#ValidationAlert").attr("class", "alert alert-success").empty().html(Submitted_Successfully);
                    } else {
                        $("#ValidationAlert").attr("class", "alert alert-success").empty().html(Submitted_Successfully);
                    }
                }
            })
        })









    })






</script>
