<%@page import="project.ConnectionProvider"%>
<%@page import="java.sql.*"%>
<%@include file="employeeHeader.jsp" %>

<html>
    <head>
        <link rel="stylesheet" href="css/alerts.css"> 
        <link rel="stylesheet" href="css/home-style.css">
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Home</title>
        <style>

            .block {
                width: 100%;
                padding: 30px 30px;
                background-color: whitesmoke;
                border-radius: 5px;
            }
            [type=text],[type=email],[type=date],[type=password],[type=file], [type=number],select,option {
                display: block;
                margin: 0 auto;
                width: 100%;
                border: 0;
                border-bottom: 1px solid rgba(0,0,0,.2);
                height: 45px;
                line-height: 45px;  
                margin-bottom: 10px;
                font-size: 1em;
                color: black;
                background-color: whitesmoke;
            }

            [type=submit] {
                align-self: center;
                cursor: pointer;
                margin-top: 25px;
                width: 100%;
                border: 0;
                background-color: navy;
                border-radius: 5px;
                height: 50px;
                color: black;
                font-weight: 400;
                font-size: 1em;
            }

            [type='text']:focus {
                outline: none;
                border-color: #53CACE;
            }

            table {
                font-family: arial, sans-serif;
                border-collapse: collapse;
                width: 100%;
            }

            td, th {
                border: 1px solid #dddddd;
                text-align: left;
                padding: 8px;
            }

            th {
                background-color: #dddddd;
            }

            .edit{
                /*border: 1px solid #dddddd;*/
                border: none;
                text-align: center;
                padding: 0px;
                background-color: #dddddd;
                margin: 0px;
            }

            .edit:hover{
                border: none;
                text-align: center;
                background-color: gray;
                color: white;
            }
        </style>
    </head>
    <body>
        <div class="modal-content animate">
            <%
                String msg = request.getParameter("msg");
                if ("done".equals(msg)) {
            %>
            <div class="alert"> 
                <button class="closebtn"><i class="fa fa-close"></i></button>
                <h3 class="alert">Salary Slip Uploaded Successfully!</h3>
            </div>
            <%}%>
            <%
                if ("wrong".equals(msg)) {
            %> 
            <div class="alert"> 
                <button class="closebtn"><i class="fa fa-close"></i></button>
                <h3 class="alert">Some thing went wrong! Try again!</h3>
            </div>
            <%}%>
        </div>
        <script>
            var close = document.getElementsByClassName("closebtn");
            var i;

            for (i = 0; i < close.length; i++) {
                close[i].onclick = function () {
                    var div = this.parentElement;
                    div.style.opacity = "0";
                    setTimeout(function () {
                        div.style.display = "none";
                    }, 600);
                }
            }
        </script>
        <div class="block">
        
        <h3 style="text-align: center">My Salary Slips</h3>
        <table>
            <thead>
                <tr>
                    <th>Emp #</th>
                    <th>Date</th>
                    <th>Month</th>
                    <th>Year</th>
                    <th>File Name</th>
                    <th>View</th>
                </tr>
            </thead>
            <div class="row">
                <%
                    try {
                        Class.forName("com.mysql.jdbc.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/CLINIHR", "root", "Clinica123");
                        Statement st = con.createStatement();
                        ResultSet rs = st.executeQuery("select * from emp_payroll where email='" + email + "'");
                        while (rs.next()) {
                %>
                <form action="viewSalarySlipsEmp.jsp?payroll_id=<%=rs.getString(1)%>" method="post"> 
                    <tbody>
                        <tr style="background-color: white">
                            <td><%=rs.getString(2)%></td>
                            <td><%=rs.getString(4)%></td>
                            <td><%=rs.getString(5)%></td>
                            <td><%=rs.getString(6)%></td>
                            <td><%=rs.getString(7)%></td>
                            <td class="edit"><button class="edit" style="width: 100%; padding: 8px;" type="submit"> View </button></td>
                        </tr> 

                </form>  

                <%
                    }

                %>
            </div>
            <%    } catch (Exception e) {
                    System.out.println(e);
                }
            %>         
        </tbody>
    </table>
        </div>
    <br>
    <br>
    <br>
</body>
</html>