<?php
include "pin/header.php";
include "pin/sidenav.php";

$user_id = $_SESSION['user_id'];
$emp_id = $_SESSION['emp_id'];
$user_role = $_SESSION['user_role'];

if (isset($_GET['delete'])) {
    $q = mysqli_query($db, "DELETE FROM `fnf` WHERE `id`='$_GET[delete]' ");
    if($q){
        echo "<script>alert('Record deleted successfully');</script>";
    } else {
        echo "<script>alert('Error deleting record');</script>";
    }
    echo "<script>window.location='all_fnf';</script>";
    exit();
}

// $edit = mysqli_fetch_assoc(mysqli_query($db, "SELECT * FROM `employee_salary` WHERE `id`='$_GET[edit]' "));


?>


<!-- ============================================================== -->
<!-- Start Page Content here -->
<!-- ============================================================== -->

<div class="content-page">
    <div class="content">
        <div class="container-fluid">

            <div class="row page-title align-items-center">
                <div class="col-sm-4 col-xl-6">

                </div>
              
            </div>

            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-body p-4">
                            <div class="d-flex justify-content-between">
                                <h4 class="header-title mt-1 mb-4">All Employees FNF</h4>
                            </div>

                            <div class="row" id="yearlyData">
                                <div class="col-12">
                                    <table id="basic-datatable" class="table dt-responsive nowrap">
                                        <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>Employee Id</th>
                                                <th>Name</th>
                                                <th>FNF Details</th>
                                                <th>Net Payable</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>

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

                        </div> <!-- end card body-->
                    </div> <!-- end card -->
                </div><!-- end col-->
            </div>
            <!-- end row-->

        </div>
    </div> <!-- content -->

</div>

<!-- ============================================================== -->
<!-- End Page content -->
<!-- ============================================================== -->



<?php
include "pin/footer.php";
?>

<script>

    $(document).on('click', '.month_year', function() {
        $(this).next('ul').slideToggle();
        // also change the icon
        $(this).find('i').toggleClass('uil-angle-down uil-angle-up');
    });

    $(document).ready(function() {

        function show_hierarchy_data(table_id, file_name, columns, default_order) {

            $("#filter_options").html('');
            form_fields.each(function() {
                search_filter(this);
            });

            if (setArray.length > 0) {
                loadTable(`#${table_id}`, `get_from_server/${file_name}`, columns, default_order, setArray);
            } else {
                loadTable(`#${table_id}`, `get_from_server/${file_name}`, columns, default_order);
            }
            // console.log(setArray);
            setArray = [];
            // console.log(setArray);
        }

        let columns =[{data: 'id'}, {data: 'employee_id'}, {data: 'name'}, {data: 'fnf_details'}, {data: 'net_payable'}, {data: 'created_at'}];
        show_hierarchy_data('basic-datatable', 'all_fnf_get', columns, [1, "asc"]);
    });

</script>