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

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

if (isset($_GET['delete'])) {
    $q = mysqli_query($db, "DELETE FROM `employee_details` WHERE `id`='$_GET[delete]' ");

    if ($q) {
        echo "<script>alert('Details Deleted Successfully !');</script>";
        echo "<script>location.href='employeeDetails';</script>";
    }
}

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


?>


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

<div class="content-page">
    <div class="content">
        <div class="container-fluid">
            <div class="mt-5"></div>

            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body p-4">
                            <h4 class="header-title mt-1 mb-4">
                                <span class="text-primary" style="font-size:1.5rem;"><?php echo $user_name; ?></span>, Please Fill Your Details
                            </h4>

                            <?php print_r($edit); ?>

                            <form action="fun/function" method="post" enctype="multipart/form-data" id="employeeDetailForm" class="parsley-examples">
                                <div class="row">

                                    <!-- ############################## -->
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="employeeId">Employee Id</label>
                                            <input type="text" name="employeeIdDetails" placeholder="Enter Employee Id" class="form-control" id="employeeId" value="<?php echo $emp_id; ?>" disabled>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="dob">Date of Birth (DOB)</label>
                                            <input type="date" name="dob" class="form-control" id="dob" value="<?php echo $edit['dob']; ?>">
                                        </div>
                                    </div>
                                    <!-- ############################## -->


                                    <!-- ############################## -->
                                    <div class="col-12">
                                        <h5>Previous Employment Details</h5>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="prevCompanyName">Company Name</label>
                                            <input type="text" name="prevCompanyName" placeholder="Enter Previous Company Name" class="form-control" id="prevCompanyName" value="<?php echo $edit['prev_comp_name']; ?>">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="fySalary">Salary Received in Financial Year (FY)</label>
                                            <input type="text" name="fySalary" placeholder="Enter FY Salary" class="form-control" id="fySalary" value="<?php echo $edit['fy_salary']; ?>">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="prevTDS">TDS Deducted by Previous Employer</label>
                                            <input type="text" name="prevTDS" placeholder="Enter Previous TDS" class="form-control" id="prevTDS" value="<?php echo $edit['prev_tds']; ?>">
                                        </div>
                                    </div>





                                    <!-- ############################## -->
                                    <div class="col-12">
                                        <h5>Is staying at Rental House</h5>
                                    </div>
                                    <div class="col-12">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="" class="d-block">Staying at Rental House</label>
                                                    <div class="form-check d-inline-block">
                                                        <input class="form-check-input" type="radio" name="rentalHouseStatus" value="Yes" id="rentalHouseYes" <?php echo (!empty($edit['rental_house'])) ? 'checked' : ''; ?>>
                                                        <label class="form-check-label" for="rentalHouseYes">Yes</label>
                                                    </div>
                                                    <div class="form-check d-inline-block ml-3">
                                                        <input class="form-check-input" type="radio" name="rentalHouseStatus" value="No" id="rentalHouseNo" <?php echo (isset($edit['rental_house'])) ? ((empty($edit['rental_house'])) ? 'checked' : '') : 'checked'; ?>>
                                                        <label class="form-check-label" for="rentalHouseNo">No</label>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-6" id="rentalPayHide" style="display:<?php echo (!empty($edit['rental_house'])) ? 'block' : 'none'; ?>;">
                                                <div class="form-group">
                                                    <label for="rentalPay">Rental Amount Per Year</label>
                                                    <input type="text" name="rentalPay" placeholder="Enter Rental Amount" class="form-control" id="rentalPay" value="<?php echo $edit['rental_house']; ?>">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- ############################## -->


                                    <!-- ############################## -->
                                    <div class="col-12">
                                        <h5>Investment Details (If you have not any Investment Fill 0 (Zero))</h5>
                                    </div>
                                    <div class="col-12">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="lic">LIC</label>
                                                    <input type="text" name="lic" placeholder="Enter LIC Amount" class="form-control" id="lic" value="<?php echo $edit['lic']; ?>">
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="licAttachment">LIC Attachment</label>
                                                    <input type="file" name="licAttachment" class="form-control" id="licAttachment">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-12">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="mutualFund">Mutual Fund (MF)</label>
                                                    <input type="text" name="mutualFund" placeholder="Enter Mutual Fund Amount" class="form-control" id="mutualFund" value="<?php echo $edit['mf']; ?>">
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="mutualFundAttachment">MF Attachment</label>
                                                    <input type="file" name="mutualFundAttachment" class="form-control" id="mutualFundAttachment">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-12">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="fixedDeposit">Fixed Deposit (FD)</label>
                                                    <input type="text" name="fixedDeposit" placeholder="Enter Fixed Deposit Amount" class="form-control" id="fixedDeposit" value="<?php echo $edit['fd']; ?>">
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="fixedDepositAttachment">FD Attachment</label>
                                                    <input type="file" name="fixedDepositAttachment" class="form-control" id="fixedDepositAttachment">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-12">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="medicalInsurance">Medical Insurance</label>
                                                    <input type="text" name="medicalInsurance" placeholder="Enter Medical Insurance Amount" class="form-control" id="medicalInsurance" value="<?php echo $edit['med_ins']; ?>">
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="medicalInsuranceAttachment">Medical Insurance Attachment</label>
                                                    <input type="file" name="medicalInsuranceAttachment" class="form-control" id="medicalInsuranceAttachment">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-12">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="booksPer">Books & Periodicals</label>
                                                    <input type="text" name="booksPer" placeholder="Enter Books & Periodicals Amount" class="form-control" id="booksPer" value="<?php echo $edit['books_per']; ?>">
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="booksPerAttachment">Books & Periodicals Attachment</label>
                                                    <input type="file" name="booksPerAttachment" class="form-control" id="booksPerAttachment">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-12">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="otherInvestment">Other Investment</label>
                                                    <input type="text" name="otherInvestment" placeholder="Enter Other Investment Amount" class="form-control" id="otherInvestment" value="<?php echo $edit['other_inv']; ?>">
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="otherInvestmentAttachment">Other Investment Attachment</label>
                                                    <input type="file" name="otherInvestmentAttachment" class="form-control" id="otherInvestmentAttachment">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- ############################## -->


                                    <!-- ############################## -->
                                    <div class="col-12">
                                        <h5>Other Income Source</h5>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="interestSaving">Interest From Bank on Saving Account</label>
                                            <input type="text" name="interestSaving" placeholder="Enter Interest" class="form-control" id="interestSaving" value="<?php echo $edit['saving_account_interest']; ?>">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="interestFD">Interest From Fixed Deposit (FD)</label>
                                            <input type="text" name="interestFD" placeholder="Enter Interest" class="form-control" id="interestFD" value="<?php echo $edit['fd_interest']; ?>">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="dividendIncome">Dividend Income</label>
                                            <input type="text" name="dividendIncome" placeholder="Enter dividend Income" class="form-control" id="dividendIncome" value="<?php echo $edit['dividend_income']; ?>">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="otherIncome">Other Income</label>
                                            <input type="text" name="otherIncome" placeholder="Enter other Income" class="form-control" id="otherIncome" value="<?php echo $edit['other_income']; ?>">
                                        </div>
                                    </div>
                                    <!-- ############################## -->


                                    <!-- ############################## -->
                                    <div class="col-12">
                                        <h5>House Property Income</h5>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="rentalIncome">Rental Income</label>
                                            <input type="text" name="rentalIncome" placeholder="Enter Rental Income" class="form-control" id="rentalIncome" value="<?php echo $edit['rental_income']; ?>">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="homeLoanInterest">Interest paid in Home Loan</label>
                                            <input type="text" name="homeLoanInterest" placeholder="Enter Home Load Interest" class="form-control" id="homeLoanInterest" value="<?php echo $edit['home_loan_interest']; ?>">
                                        </div>
                                    </div>
                                    <!-- ############################## -->

                                </div>

                                <div class="form-group text-right mb-0 mt-4">
                                    <?php if (isset($edit['id'])) { ?>
                                        <input type="hidden" name="edit_id" value="<?php echo $edit['id']; ?>">
                                        <button class="btn btn-primary mr-1" name="updateDetails" type="button">Update Details</button>
                                    <?php } else { ?>
                                        <button class="btn btn-primary mr-1" name="addDetails" id="detailFormSubmitButton" type="button">Add Details</button>
                                    <?php } ?>
                                    <button type="reset" class="btn btn-secondary">Cancel</button>
                                </div>

                            </form>
                        </div>
                    </div> <!-- end card -->
                </div>
                <!-- end col -->

            </div>
            <!-- end row -->


            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-body p-4">
                            <h4 class="header-title mt-0 mb-1 mb-4">
                                <span class="text-primary"><?php echo $user_name; ?></span> Details
                            </h4>

                            <table id="basic-datatable" class="table dt-responsive nowrap custom-responsive-datatable">
                                <thead>
                                    <tr>
                                        <th>#</th>

                                        <th></th>

                                        <th>Previous Company Details</th>

                                        <th></th>

                                        <th>Investment Details</th>

                                        <th>Other Income Source</th>

                                        <th>House Property Income</th>
                                    </tr>
                                </thead>


                                <tbody>
                                    <?php
                                    $i = 1;
                                    $empDetails = mysqli_query($db, "select * from employee_details where employee_id='$emp_id' ");
                                    while ($row = mysqli_fetch_assoc($empDetails)) {
                                    ?>
                                        <tr>
                                            <td><?php echo $i++; ?></td>

                                            <td>
                                                <strong class="text-dark">Employee Id: </strong><?php echo $row['employee_id']; ?><br>
                                                <strong class="text-dark">Date Of Birth: </strong><?php echo (!empty($row['dob'])) ? date('d M Y', strtotime($row['dob'])) : ''; ?>
                                            </td>

                                            <td>
                                                <strong class="text-dark">Company Name: </strong><?php echo $row['prev_comp_name']; ?><br>
                                                <strong class="text-dark">Financial year Salary: </strong><?php echo $row['fy_salary']; ?><br>
                                                <strong class="text-dark">Previous TDS: </strong><?php echo $row['prev_tds']; ?><br>
                                                <strong class="text-dark">ESI No.: </strong><?php echo $row['esi_no']; ?><br>
                                                <strong class="text-dark">EPF No.: </strong><?php echo $row['uan_no']; ?><br>
                                                <strong class="text-dark">EPF Applicable: </strong><?php echo $row['epf_applicable_status']; ?>
                                            </td>

                                            <td>
                                                <strong class="text-dark">Rental House: </strong><?php echo $row['rental_house']; ?>
                                            </td>

                                            <td>
                                                <strong class="text-dark">LIC: </strong><a href="attachment_files/<?php echo $row['lic_attach']; ?>" target="_blank" title="See the Attachment"><?php echo $row['lic']; ?></a><br>
                                                <!-- <strong class="text-dark">LIC Attachment: </strong><br> -->
                                                <strong class="text-dark">Mutual Fund: </strong><a href="attachment_files/<?php echo $row['mf_attach']; ?>" target="_blank" title="See the Attachment"><?php echo $row['mf']; ?></a><br>
                                                <!-- <strong class="text-dark">Mutual Fund Attachment: </strong><br> -->
                                                <strong class="text-dark">Fixed Deposit: </strong><a href="attachment_files/<?php echo $row['fd_attach']; ?>" target="_blank" title="See the Attachment"><?php echo $row['fd']; ?></a><br>
                                                <!-- <strong class="text-dark">Fixed Deposit Attachment: </strong><br> -->
                                                <strong class="text-dark">Medical Insurance: </strong><a href="attachment_files/<?php echo $row['med_ins_attach']; ?>" target="_blank" title="See the Attachment"><?php echo $row['med_ins']; ?></a><br>
                                                <!-- <strong class="text-dark">Medical Insurance Attachment: </strong><br> -->
                                                <strong class="text-dark">Books & Periodicals: </strong><a href="attachment_files/<?php echo $row['books_per_attach']; ?>" target="_blank" title="See the Attachment"><?php echo $row['books_per']; ?></a><br>
                                                <!-- <strong class="text-dark">Books & Periodicals Attachment: </strong><br> -->
                                                <strong class="text-dark">Other Investment: </strong><a href="attachment_files/<?php echo $row['other_inv_attach']; ?>" target="_blank" title="See the Attachment"><?php echo $row['other_inv']; ?></a>
                                                <!-- <strong class="text-dark">Other Investment Attachment: </strong> -->
                                            </td>

                                            <td>
                                                <strong class="text-dark">Saving Account Interest: </strong><?php echo $row['saving_account_interest']; ?><br>
                                                <strong class="text-dark">Fixed Deposit Interest: </strong><?php echo $row['fd_interest']; ?><br>
                                                <strong class="text-dark">Dividend Income: </strong><?php echo $row['dividend_income']; ?><br>
                                                <strong class="text-dark">Other Income: </strong><?php echo $row['other_income']; ?>
                                            </td>

                                            <td>
                                                <strong class="text-dark">Rental Income: </strong><?php echo $row['rental_income']; ?><br>
                                                <strong class="text-dark">Home Loan Interest: </strong><?php echo $row['home_loan_interest']; ?>
                                            </td>

                                            <td><a href="?edit=<?php echo $row['id']; ?>">Edit</a></td>
                                            <td><a href="?delete=<?php echo $row['id']; ?>">Delete</a></td>
                                        </tr>
                                    <?php } ?>
                                </tbody>

                            </table>
                            <!-- </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>
    $(".custom-select-picker").select2();

    setTimeout(() => {
        $(".custom-responsive-datatable").parent().parent().css("overflow", "auto");
    }, 1000);



    $("input[name=rentalHouseStatus]").change(function() {
        if ($("input[name=rentalHouseStatus]:checked").val() == 'Yes') {
            $("#rentalPayHide").slideDown();
            $("#rentalPayHide input").val('');
            $("#rentalPayHide input").prop('required', true);
        } else {
            $("#rentalPayHide").slideUp();
            $("#rentalPayHide input").val('');
            $("#rentalPayHide input").prop('required', false);
        }
    });

    $("#detailFormSubmitButton").click(function() {

        $("input[name=employeeIdDetails]").prop("disabled", false);
        // $("input[name=PFApplicabilityStatus]").prop("disabled", false);

        $("#employeeDetailForm").submit();

    });
</script>