<%--
    Document   : Payroll Report
    Created on : May 18, 2022, 4:50:51 PM
    Author     : 1242938
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList" %>
<% try {
%>
<html>
    <head>
        <title>Payroll Report</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="${pageContext.request.contextPath}/js/Calendar.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/TableCSSCode.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="shortcut icon" href="${pageContext.request.contextPath}/img/favicon.ico?pacs=<%=((new java.util.Date()).getTime())%>" type="image/x-icon" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/styles.css?pacs=<%=((new java.util.Date()).getTime())%>"/>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/ButtonAndText.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/info.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-ui-1.10.4.custom/development-bundle/jquery-1.10.2.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/chromejs/chrome.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/js/iFrame_killer.js"></script>

        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }
            function downloadFiles() {

                var e = document.getElementById("reportSelection");

                if (e.options[e.selectedIndex].value == "")
                {
                    alert("Report Name cannot be empty.");
                    document.forms[0].reportSelection.focus();
                    return false;
                }
                if (document.forms[0].yyyymm.value == "")
                {
                    alert("Date cannot be empty.");
                    document.forms[0].yyyymm.focus();
                    return false;
                }
                if(document.forms[0].reportSelection.value == '1')
                {    
                    if (document.forms[0].empId.value == "")
                    {
                    alert("Select employee.");
                    document.forms[0].empId.focus();
                    return false;
                    }
                }    
                                
                var dt = document.getElementById("yyyymm").value;
                var format = dt.slice(0,4) + "-" + dt.slice(4,6)+"-01";                
                var dtMonth = dt.slice(4,6);
                
                if (dt.length < 6) 
                {  alert("Please enter valid year and month.");
                    return false;
                }
                if (dtMonth < 1 || dtMonth > 12) 
                {  alert("Please enter valid year and month.");
                    return false;
                }    
                                   
                switch (e.options[e.selectedIndex].value) {

                    case "1" :

                        document.forms[0].reportPath.value = "/Reports/payroll_payslip";
                        document.forms[0].reportName.value = "PAYSLIP REPORT";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;
                    case "2" :

                        document.forms[0].reportPath.value = "/Reports/payroll_details";
                        document.forms[0].reportName.value = "PAYROLL DETAILS REPORT";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    default :

                        null;

                }

                document.forms[0].action = '/PacsApplication/ExcelReportServlet';
                document.forms[0].submit();

            }
            function ShowParent()
            {

                document.forms[0].action = "${pageContext.request.contextPath}/Payroll/payroll_reports.jsp";
                document.forms[0].submit();
            }
            function SearchEMP(width, height)
            {
                if (window.innerWidth) {
                    LeftPosition = (window.innerWidth - width) / 2;
                    TopPosition = ((window.innerHeight - height) / 2) - 20;
                }
                else {
                    LeftPosition = (parseInt(window.screen.width) - width) / 2;
                    TopPosition = ((parseInt(window.screen.height) - height) / 2) - 20;
                }

                attr = 'resizable=yes,scrollbars=yes,width=' + width + ',height=' +
                    height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
                    TopPosition + '';
                var screenName = "payroll_reports.jsp";
                var lovKey = "EMPID";

                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationShgLOV.jsp?screenName=' + screenName+'&lovKey='+lovKey, 'AccountSearch', attr);
                popWin.focus();
            }
            $(document).ready(function () {                
               $('select#reportSelection').change(function () {
                    var shouldEnable = $(this).val();
                    switch(shouldEnable)
                    {
                        case '1':
                            $('#empDiv').show(500);
                            break;
                        case '2':
                            $('#empDiv').hide();
                            break;
                        default:
                            $('#empDiv').hide();
                            break;
                    }
                });
            });
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });

        </script>

        <link rel="shortcut icon" href="${pageContext.request.contextPath}/img/favicon.ico" type="image/x-icon" />
    </head>
    <body  onload="noBack();">

        <jsp:include page="MenuHead_Payroll.jsp" flush="true" />
        <br>
        <div style="top:500px">
            <fieldset style="border-color: black; background-image: url('/PacsApplication/img/download.jpg'); border-width: 3px">
                <legend style="padding: 8px; border-radius: 20px; background-color: #006600; color: white">Payroll Report</legend>

                <form name="formPayroll" method="post" action="/PacsApplication/DownloadPacsReport">
                    <br>

                    <table>
                        <%if (request.getAttribute("error") != null) {%>
                        <tr><td colspan="2" align="center"><%=request.getAttribute("error").toString()%></td></tr>
                        <%}%>

                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                        <tr>
                            <td style=" font-family: Berlin Sans FB; font-weight:normal; ">Report Name <font color="red" >*</font>: </td>
                            <td><select id="reportSelection" name="reportSelection" >
                                    <option value="" disabled selected style="display:none;" >--Select--</option>
                                    <option value="1">Payslip Report</option>
                                    <option value="2">Payroll Details Report</option>
                                </select></td>
                        </tr><br><tr></tr>
                        <tr>
                            <td style=" font-family: Berlin Sans FB; font-weight:  normal;">Date <font color="red" >*</font>: </td>
                                <td><input type="text" placeholder="yyyymm" style="text-align:center;" id="yyyymm" name="yyyymm" maxlength="6" onkeypress='return event.charCode >= 48 && event.charCode <= 57'ondrop="return false;" onpaste="return false;" /> (Enter year and month only)</td>
                        </tr>
                        <tr id="empDiv">
                            <td style=" font-family: Berlin Sans FB; font-weight:  normal;">Employee ID <font color="red" >*</font>: </td>
                            <td><input readonly="" type="text" id="empId" name="empId" maxlength="15" />
                                <input type="button" name="empSearch" id="empSearch" value="Search" onclick="javascript:SearchEMP(550,240);" /></td>                                
                        </tr>
                    </table>
                        <br><br><br><br>
                    <center>
                        <input type="button" value="Fetch Report" onclick="javascript:downloadFiles();">
                        <input type="button" value="Reset" id="Reset" onclick="ShowParent();"
                    </center>

                    <input type="hidden" name="reportPath" value=""/>
                    <input type="hidden" name="reportName" value=""/>
                    <input type="hidden" name="DOWNLOAD" value=""/>


                </form>
            </fieldset>
        </div>
    </body>
</html>
<% 	} catch (Exception e) {
                
            }
%>