<%--
    Document   : LeaveMaster
    Created on : May 6, 2022, 6:00:00 PM
    Author     : 1242938
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="DataEntryBean.PayrollBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="LoginDb.DbHandler"%>
<% try {
%>

<html>

    <head>
        <title>Leave Master</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>

            function noBack()
            {
                window.history.forward(); 
                calDaAmt2(formPayroll);
            }
            
            function submitform(formPayroll)
            {
              if (checkDiv(formPayroll))
                {
                    document.forms[0].handle_id.value = "Create";
                    document.forms[0].action = '/PacsApplication/LeaveMasterServlet';
                    document.forms[0].submit();
                }
            }
            function amendform(formPayroll)
            { 
                if (checkDivAmend(formPayroll))
                {
                document.forms[0].handle_id.value = "Amend";
                document.forms[0].action = '/PacsApplication/LeaveMasterServlet';
                document.forms[0].submit();
                }
            }
            function getDetails(formPayroll)
            {
                document.forms[0].handle_id.value = "getDetails";
                document.forms[0].action = '/PacsApplication/LeaveMasterServlet';
                document.forms[0].submit();
            }

            function checkDiv(formPayroll)
            {
                var counter = document.forms[0].rowCounter.value; 
                
                var el = 0;
                var ml = 0;
                var cl = 0;
                var ol = 0;
                for (var i = 1; i <= counter; i++) {
                    var leavT = parseInt(document.getElementById("leaveType" + i).value);
                    if (leavT == '1') {
                        el = el+1;
                    }
                    if (leavT == '2') {
                        ml = ml+1;
                    }
                    if (leavT == '3') {
                        cl = cl+1;
                    }
                    if (leavT == '4') {
                        ol = ol+1;
                    }
                }
                if (el>1 || ml>1 || cl>1 || ol>1) {
                    alert("Each leave type can only be entered once.");
                    return false;
                }
                
                for (var i = 1; i <= counter; i++) {
                    try{
                        var leave = document.getElementById("leave" + i).value;
                        var yearlyCredit = parseInt(document.getElementById("yearlyCredit" + i).value);
                        var encashLimit = parseInt(document.getElementById("encashLimit" + i).value);
                        var minReserve = parseInt(document.getElementById("minReserve" + i).value);
                        var maxReserve = parseInt(document.getElementById("maxReserve" + i).value);
                        var minAllow = parseInt(document.getElementById("minAllow" + i).value);
                        var maxAllow = parseInt(document.getElementById("maxAllow" + i).value);
                        
                        if (leave == "" || yearlyCredit == "" || encashLimit == "" || minReserve == "" || maxReserve == "" || minAllow == "" || maxAllow == "" ) 
                        {
                            alert("Please enter all fields.");
                            return false;
                        }
                        if(yearlyCredit > maxReserve) 
                        {
                            alert("Yearly Credit Limit Cannot be grater than Maximum Reserve Limit");
                            return false;
                        }
                        if(minReserve > maxReserve) 
                        {
                            alert("Minimum Reserve Limit Cannot be grater than Maximum Reserve Limit");
                            return false;
                        }                        
                        if(encashLimit > maxReserve) 
                        {
                            alert("Maximum Encashment Limit Cannot be grater than Maximum Reserve Limit");
                            return false;
                        }  
                        if(minAllow > maxAllow) 
                        {
                            alert("Minimum Allowed Limit Cannot be grater than Maximum Allowed Limit");
                            return false;
                        }                        
                        if(encashLimit > yearlyCredit) 
                        {
                            alert("Maximum Encashment Limit Cannot be grater than Yearly Credit Limit");
                            return false;
                        }
                        if(minAllow > maxReserve) 
                        {
                            alert("Maximum Allowed Limit Cannot be grater than Maximum Reserve Limit");
                            return false;
                        }                        
                        if(minAllow > minReserve) 
                        {
                            alert("Minimum Allowed Limit Cannot be grater than Minimum Reserve Limit");
                            return false;
                        }
                    }
                    catch(e){}
                }                
                return true;
            } 
            function checkDivAmend(formPayroll)
            {
                var counter2 = document.forms[0].rowCounter2.value; 
                var el = 0;
                var ml = 0;
                var cl = 0;
                var ol = 0;
                for (var i = 2; i <= counter2; i++) {
                    var leavT = parseInt(document.getElementById("leaveType" + i).value);
                    if (leavT == '1') {
                        el = el+1;
                    }
                    if (leavT == '2') {
                        ml = ml+1;
                    }
                    if (leavT == '3') {
                        cl = cl+1;
                    }
                    if (leavT == '4') {
                        ol = ol+1;
                    }
                }
                if (el>1 || ml>1 || cl>1 || ol>1) {
                    alert("Each leave type can only be entered once.");
                    return false;
                }
                
                for (var i = 2; i < counter2; i++) {
                    try{
                        var leave = document.getElementById("leave" + i).value;
                        var yearlyCredit = parseInt(document.getElementById("yearlyCredit" + i).value);
                        var encashLimit = parseInt(document.getElementById("encashLimit" + i).value);
                        var minReserve = parseInt(document.getElementById("minReserve" + i).value);
                        var maxReserve = parseInt(document.getElementById("maxReserve" + i).value);
                        var minAllow = parseInt(document.getElementById("minAllow" + i).value);
                        var maxAllow = parseInt(document.getElementById("maxAllow" + i).value);
                        
                        if (leave == "" || yearlyCredit == "" || encashLimit == "" || minReserve == "" || maxReserve == "" || minAllow == "" || maxAllow == "" ) 
                        {
                            alert("Please enter all fields.");
                            return false;
                        }
                        if(yearlyCredit > maxReserve) 
                        {
                            alert("Yearly Credit Limit Cannot be grater than Maximum Reserve Limit");
                            return false;
                        }
                        if(minReserve > maxReserve) 
                        {
                            alert("Minimum Reserve Limit Cannot be grater than Maximum Reserve Limit");
                            return false;
                        }                        
                        if(encashLimit > maxReserve) 
                        {
                            alert("Maximum Encashment Limit Cannot be grater than Maximum Reserve Limit");
                            return false;
                        }  
                        if(minAllow > maxAllow) 
                        {
                            alert("Minimum Allowed Limit Cannot be grater than Maximum Allowed Limit");
                            return false;
                        }                        
                        if(encashLimit > yearlyCredit) 
                        {
                            alert("Maximum Encashment Limit Cannot be grater than Yearly Credit Limit");
                            return false;
                        }
                        if(minAllow > maxReserve) 
                        {
                            alert("Maximum Allowed Limit Cannot be grater than Maximum Reserve Limit");
                            return false;
                        }                        
                        if(minAllow > minReserve) 
                        {
                            alert("Minimum Allowed Limit Cannot be grater than Minimum Reserve Limit");
                            return false;
                        }
                    }
                    catch(e){}
                }                
                return true;
            }

            function checkop()
            {                
                if (document.getElementById("checkOption").value == "create")
                {

                    document.getElementById('create').style.display = 'block';
                    document.getElementById('forAmend').style.display = 'none';
                    document.getElementById('amend').style.display = 'none';
                }
                if (document.getElementById("checkOption").value == "amend")
                {
                    document.getElementById('create').style.display = 'none';
                    document.getElementById('forAmend').style.display = 'block';
                }
            } 
            function calDecimal(formPayroll) 
            {
                var counter = document.forms[0].rowCounter.value;
                
                for (var i = 1; i <= counter; i++) {    
                    var var1 = String(document.getElementById("yearlyCredit" + i).value);
                    var var2 = String(document.getElementById("encashLimit" + i).value);
                    var var3 = String(document.getElementById("minReserve" + i).value);
                    var var4 = String(document.getElementById("maxReserve" + i).value);
                    var var5 = String(document.getElementById("minAllow" + i).value);
                    var var6 = String(document.getElementById("maxAllow" + i).value);
                    
                    if(var1.includes('.')){
                        var len1 =  var1.split('.')[1].length;                                            
                        if (len1>2) {
                            document.getElementById("yearlyCredit" + i).value = (parseFloat(var1)).toFixed(2);
                            return false;
                        }
                    }
                    if(var2.includes('.')){
                        var len2 =  var2.split('.')[1].length;                                            
                        if (len2>2) {
                            document.getElementById("encashLimit" + i).value = (parseFloat(var2)).toFixed(2);
                            return false;
                        }
                    }
                    if(var3.includes('.')){
                        var len3 =  var3.split('.')[1].length;                                            
                        if (len3>2) {
                            document.getElementById("minReserve" + i).value = (parseFloat(var3)).toFixed(2);
                            return false;
                        }
                    }
                    if(var4.includes('.')){
                        var len4 =  var4.split('.')[1].length;                                            
                        if (len4>2) {
                            document.getElementById("maxReserve" + i).value = (parseFloat(var4)).toFixed(2);
                            return false;
                        }
                    }
                    if(var5.includes('.')){
                        var len5 =  var5.split('.')[1].length;                                            
                        if (len5>2) {
                            document.getElementById("minAllow" + i).value = (parseFloat(var5)).toFixed(2);
                            return false;
                        }
                    }
                    if(var6.includes('.')){
                        var len6 =  var6.split('.')[1].length;                                            
                        if (len6>2) {
                            document.getElementById("maxAllow" + i).value = (parseFloat(var6)).toFixed(2);
                            return false;
                        }
                    }                    
                }
            }
            function calDecimal2(formPayroll) 
            {
                var counter2 = document.forms[0].rowCounter2.value;
                
                for (var i = 1; i <= counter2; i++) {    
                    var var1 = String(document.getElementById("yearlyCredit" + i).value);
                    var var2 = String(document.getElementById("encashLimit" + i).value);
                    var var3 = String(document.getElementById("minReserve" + i).value);
                    var var4 = String(document.getElementById("maxReserve" + i).value);
                    var var5 = String(document.getElementById("minAllow" + i).value);
                    var var6 = String(document.getElementById("maxAllow" + i).value);
                    
                    if(var1.includes('.')){
                        var len1 =  var1.split('.')[1].length;                                            
                        if (len1>2) {
                            document.getElementById("yearlyCredit" + i).value = (parseFloat(var1)).toFixed(2);
                            return false;
                        }
                    }
                    if(var2.includes('.')){
                        var len2 =  var2.split('.')[1].length;                                            
                        if (len2>2) {
                            document.getElementById("encashLimit" + i).value = (parseFloat(var2)).toFixed(2);
                            return false;
                        }
                    }
                    if(var3.includes('.')){
                        var len3 =  var3.split('.')[1].length;                                            
                        if (len3>2) {
                            document.getElementById("minReserve" + i).value = (parseFloat(var3)).toFixed(2);
                            return false;
                        }
                    }
                    if(var4.includes('.')){
                        var len4 =  var4.split('.')[1].length;                                            
                        if (len4>2) {
                            document.getElementById("maxReserve" + i).value = (parseFloat(var4)).toFixed(2);
                            return false;
                        }
                    }
                    if(var5.includes('.')){
                        var len5 =  var5.split('.')[1].length;                                            
                        if (len5>2) {
                            document.getElementById("minAllow" + i).value = (parseFloat(var5)).toFixed(2);
                            return false;
                        }
                    }
                    if(var6.includes('.')){
                        var len6 =  var6.split('.')[1].length;                                            
                        if (len6>2) {
                            document.getElementById("maxAllow" + i).value = (parseFloat(var6)).toFixed(2);
                            return false;
                        }
                    }                    
                }
            }
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });

        </script>        

    </head>
    <body onload="noBack()">

        <%          int count = 1;
                    String error_msg = "";
                    Object error = request.getAttribute("message");
                    if (error != null) {
                        error_msg = error.toString();
                    }
        %>
        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>

        <%
                    Object oPayrollBeanObj = request.getAttribute("oPayrollBean");
                    Object alPayrollBeanObj = request.getAttribute("arrPayrollBean");

                    PayrollBean oPayrollBean = new PayrollBean();
                    if (oPayrollBeanObj != null) {
                        oPayrollBean = (PayrollBean) request.getAttribute("oPayrollBean");
                    }

                    ArrayList<PayrollBean> alPayrollBean = new ArrayList<PayrollBean>();
                    if (alPayrollBeanObj != null) {
                        alPayrollBean = (ArrayList<PayrollBean>) request.getAttribute("arrPayrollBean");
                    }
        %>

        <%
                    String displayFlag = "";
                    Object display = request.getAttribute("displayFlag");
                    if (display != null) {
                        displayFlag = display.toString();
                    }
                    
                    String userRole = (String) session.getAttribute("userRole");
                    
                    String checkOption = "";
                error = request.getAttribute("checkOption");
                if (error != null) {
                 checkOption = error.toString();
                }
        %>

        <jsp:include page="MenuHead_Payroll.jsp" flush="true" />
        <br>                    
        <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">Leave Master</legend>

            <form id="formPayroll" name="formPayroll" method="post" action="EmployeeMasterServlet">

                <%if (!error_msg.equalsIgnoreCase("")) {%>
                <center><div class="info" id="errorMessage"><center><%= error_msg%></center></div></center>
                <% }%>
                <br>

                <center><label style=" font-family: Berlin Sans FB; font-weight:  normal;">Operation Selection:</label>
                    <select id="checkOption" onchange="checkop()" name="checkOption" >
                        <option value="" style="display:none;" >--Select--</option>                            
                            <option value="create" >Create</option>
                            <option value="amend" >Amend</option>
                    </select>                    
                </center>
                <br>
            <div id ="create" style="display:none;" >
            <center>     
                <div style="overflow:scroll; width: 1300px">
                <center>
                        <br><br>
                        <table id="order-list" style="margin-left: 20px;"  border="2" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px; width: 100%;">
                            <thead  class="CSSTableGenerator" >
                                <tr>
                                    <td></td>
                                    <td>Leave Name</td>  
                                    <td>Leave Type</td>
                                    <td>Yearly Credit Limit</td>
                                    <td>Encash Flag</td>
                                    <td>Carry Forward Flag</td>
                                    <td>Encash Limit</td>
                                    <td>Min Reserve Limit</td>
                                    <td>Max Reserve Limit</td>
                                    <td>Min Allowed Limit</td>
                                    <td>Max Allowed Limit</td>                                    
                                    <td>Status</td>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td><input type="checkbox" name="chckbox<%=count%>" id="chckbox<%=count%>" onclick="return checkboxTrue(<%=count%>)"/></td>                                    
                                    <td><input size="15" type="text" name="leave<%=count%>" id="leave<%=count%>" ondrop="return false;" onpaste="return false;" /></td>                                      
                                    <td><select style="width: 150px" id="leaveType<%=count%>" name="leaveType<%=count%>" >
                                            <option value="1">Earned Leave</option><option value="2">Medical Leave</option><option value="3">Casual Leave</option><option value="4">Others Leave</option></select></td>
                                    <td><input size="17" type="text" name="yearlyCredit<%=count%>" id="yearlyCredit<%=count%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' onkeyup="calDecimal(formPayroll)"/></td>
                                    <td><select style="width: 150px" id="encashFlag<%=count%>" name="encashFlag<%=count%>" >
                                            <option value="N">No</option><option value="Y">Yes</option></select></td>
                                    <td><select style="width: 150px" id="carryfFlag<%=count%>" name="carryfFlag<%=count%>" >
                                            <option value="N">No</option><option value="Y">Yes</option></select></td>        
                                    <td><input size="15" type="text" name="encashLimit<%=count%>" id="encashLimit<%=count%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' onkeyup="calDecimal(formPayroll)"/></td>
                                    <td><input size="15" type="text" name="minReserve<%=count%>" id="minReserve<%=count%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' onkeyup="calDecimal(formPayroll)"/></td>
                                    <td><input size="15" type="text" name="maxReserve<%=count%>" id="maxReserve<%=count%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' onkeyup="calDecimal(formPayroll)"/></td>
                                    <td><input size="15" type="text" name="minAllow<%=count%>" id="minAllow<%=count%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' onkeyup="calDecimal(formPayroll)"/></td>
                                    <td><input size="15" type="text" name="maxAllow<%=count%>" id="maxAllow<%=count%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' onkeyup="calDecimal(formPayroll)"/></td>
                                    <td><select style="width: 150px" id="status<%=count%>" name="status<%=count%>" >
                                            <option value="N">No</option><option value="Y">Yes</option></select></td>                                    
                                    <td style="display:none"><input type="hidden" name="id<%=count%>" id="id<%=count%>"></td>
                                </tr>
                            </tbody>
                        </table>
                    <br>            
                </center>
                </div>                    
                        <br/><br/>
                        <center>
                            <input type="button" id="addRow" value="Add Row"/>
                            <input type="button" id="deleteRow" value="Delete Row"/>
                            <input type="button" value="Submit" onclick="javascript:submitform(formPayroll)"/>
                            <input type="button" value="Reset" onclick="ShowParent();" />

                        </center>
                        <input type="hidden" name="rowCounter" id="rowCounter" value="<%=count%>">
                        <input type="hidden" name="chkboxCounter" id="chkboxCounter" value="0">
               </center>
            </div>            
                        <br>        
                <center>        
                <div id="forAmend" style="display:none;" >    
                    
                        <input type="button"  value="Fetch Employee Details" onclick="javascript:getDetails()" />
                                             
                </div>        
                <br>
                </center>
                <%if (displayFlag.equalsIgnoreCase("Y")) {%>
                <div id="amend" >
                <div style="overflow:scroll; width: 1300px">
                    <center>                       
                    <table id="order-listAmend" style="margin-left: 20px;"  border="2" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px; width: 100%;">
                        <thead  class="CSSTableGenerator" >
                            <tr>                                
                                    <td>Leave Name</td>  
                                    <td>Leave Type</td>
                                    <td>Yearly Credit Limit</td>
                                    <td>Encash Flag</td>
                                    <td>Carry Forward Flag</td>
                                    <td>Encash Limit</td>
                                    <td>Min Reserve Limit</td>
                                    <td>Max Reserve Limit</td>
                                    <td>Min Allowed Limit</td>
                                    <td>Max Allowed Limit</td>                                    
                                    <td>Status</td>
                            </tr>
                        </thead>
                        <tbody style="background-color: white; font-size: 15px">
                            <%
                                oPayrollBean = null;
                                oPayrollBean = new PayrollBean();
                                int count2= 1;

                                for (int i = 0; i < alPayrollBean.size(); i++) {
                                    oPayrollBean = alPayrollBean.get(i);
                                    count2++;
                            %>
                            <tr>                                    
                                    <td><input maxlength="15" type="text" name="leave<%=count2%>" id="leave<%=count2%>" ondrop="return false;" onpaste="return false;" value="<%=blankNull(oPayrollBean.getLeave())%>" /></td>                                      
                                    <td><select style="width: 150px" id="leaveType<%=count2%>" name="leaveType<%=count2%>" >
                                            <option <%if (oPayrollBean.getLeaveType().equalsIgnoreCase("1")) {%>selected <%}%> value="1">Earned Leave</option>
                                            <option <%if (oPayrollBean.getLeaveType().equalsIgnoreCase("2")) {%>selected <%}%> value="2">Medical Leave</option>
                                            <option <%if (oPayrollBean.getLeaveType().equalsIgnoreCase("3")) {%>selected <%}%> value="3">Casual Leave</option>
                                            <option <%if (oPayrollBean.getLeaveType().equalsIgnoreCase("4")) {%>selected <%}%> value="4">Others Leave</option>
                                        </select></td>
                                    <td><input size="17" type="text" name="yearlyCredit<%=count2%>" id="yearlyCredit<%=count2%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' value="<%=blankNull(oPayrollBean.getYearlyCredit())%>" onkeyup="calDecimal2(formPayroll)"/></td>
                                    <td><select style="width: 150px" id="encashFlag<%=count2%>" name="encashFlag<%=count2%>" >
                                            <option <%if (oPayrollBean.getEncashFlag().equalsIgnoreCase("Y")) {%>selected <%}%> value="Y">Yes</option>
                                            <option <%if (oPayrollBean.getEncashFlag().equalsIgnoreCase("N")) {%>selected <%}%> value="N">No</option></select></td>
                                    <td><select style="width: 150px" id="carryfFlag<%=count2%>" name="carryfFlag<%=count2%>" >
                                            <option <%if (oPayrollBean.getCarryfFlag().equalsIgnoreCase("Y")) {%>selected <%}%> value="Y">Yes</option>
                                            <option <%if (oPayrollBean.getCarryfFlag().equalsIgnoreCase("N")) {%>selected <%}%> value="N">No</option></select></td>        
                                    <td><input size="15" type="text" name="encashLimit<%=count2%>" id="encashLimit<%=count2%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' value="<%=blankNull(oPayrollBean.getEncashLimit())%>" onkeyup="calDecimal2(formPayroll)"/></td>
                                    <td><input size="15" type="text" name="minReserve<%=count2%>" id="minReserve<%=count2%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' value="<%=blankNull(oPayrollBean.getMinReserve())%>" onkeyup="calDecimal2(formPayroll)"/></td>
                                    <td><input size="15" type="text" name="maxReserve<%=count2%>" id="maxReserve<%=count2%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' value="<%=blankNull(oPayrollBean.getMaxReserve())%>" onkeyup="calDecimal2(formPayroll)"/></td>
                                    <td><input size="15" type="text" name="minAllow<%=count2%>" id="minAllow<%=count2%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' value="<%=blankNull(oPayrollBean.getMinAllow())%>" onkeyup="calDecimal2(formPayroll)"/></td>
                                    <td><input size="15" type="text" name="maxAllow<%=count2%>" id="maxAllow<%=count2%>" onkeypress='return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47' value="<%=blankNull(oPayrollBean.getMaxAllow())%>" onkeyup="calDecimal2(formPayroll)"/></td>
                                    <td><select style="width: 150px" id="status<%=count2%>" name="status<%=count2%>" >
                                            <option <%if (oPayrollBean.getStatus().equalsIgnoreCase("Y")) {%>selected <%}%> value="Y">Yes</option>
                                            <option <%if (oPayrollBean.getStatus().equalsIgnoreCase("N")) {%>selected <%}%> value="N">No</option></select></td>                                                                       
                                    <td display: none><input type="hidden" name="id<%=count2%>" id="id<%=count2%>" value="<%=blankNull(oPayrollBean.getId())%>"></td>
                            </tr>

                            <%}%></tbody>
                    </table>                    
                
                    </center>
                </div>    
                    <br><br>
                        <center>
                            <input type="button" value="Submit" onclick="javascript:amendform(formPayroll)"/>
                            <input type="button" value="Reset" onclick="ShowParent();" />
                        </center>
                            <input type="hidden" name="indicator" id="indicator" value="">
                            <input type="hidden" name="rowCounter2" id="rowCounter2" value="<%=count2%>">
                            <input type="hidden" name="chkboxCounter" id="chkboxCounter" value="0">
                </div> 
            <%}%>                
                <input type="hidden" name="handle_id" value="" />
                <input type="hidden" name="actionApl" value="" />
                <input type="hidden" name="vendor_id" id="vendor_id"/>
                <input type="hidden" id="displayFlag" name="displayFlag" value="<%=displayFlag%>"/>
            </form>
            <script>

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

                    //var counter = $("#rowCounter").val();
                    ++counter;
                    $('#order-list tr:last').after('<tr> <td align="center"><input type="checkbox" name="chckbox' + counter + '" id="chckbox' + counter + '" onclick="return checkboxTrue('+counter+')"/></td>\n\
                                    <td><input size="15" type="text" id="leave' + counter + '" name="leave' + counter + '" ondrop="return false;" onpaste="return false;" /></td>\n\
                                    <td><select style="width:100%"  id="leaveType' + counter + '" name="leaveType' + counter + '" ><option value="1">Earned Leave</option><option value="2">Medical Leave</option><option value="3">Casual Leave</option><option value="4">Others Leave</option></select></td>\n\
                                    <td><input size="17" type="text" name="yearlyCredit' + counter + '" id="yearlyCredit' + counter + '" onkeypress="return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47" onkeyup="calDecimal(formPayroll)"/></td>\n\
                                    <td><select style="width: 150px" id="encashFlag' + counter + '" name="encashFlag' + counter + '" ><option value="N">No</option><option value="Y">Yes</option></select></td>\n\
                                    <td><select style="width: 150px" id="carryfFlag' + counter + '" name="carryfFlag' + counter + '" ><option value="N">No</option><option value="Y">Yes</option></select></td>\n\
                                    <td><input size="15" type="text" name="encashLimit' + counter + '" id="encashLimit' + counter + '" onkeypress="return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47" onkeyup="calDecimal(formPayroll)"/></td>\n\
                                    <td><input size="15" type="text" name="minReserve' + counter + '" id="minReserve' + counter + '" onkeypress="return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47" onkeyup="calDecimal(formPayroll)"/></td>\n\
                                    <td><input size="15" type="text" name="maxReserve' + counter + '" id="maxReserve' + counter + '" onkeypress="return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47" onkeyup="calDecimal(formPayroll)"/></td>\n\
                                    <td><input size="15" type="text" name="minAllow' + counter + '" id="minAllow' + counter + '" onkeypress="return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47" onkeyup="calDecimal(formPayroll)"/></td>\n\
                                    <td><input size="15" type="text" name="maxAllow' + counter + '" id="maxAllow' + counter + '" onkeypress="return event.charCode >= 46 && event.charCode <= 57 && event.charCode != 47" onkeyup="calDecimal(formPayroll)"/></td>\n\
                                    <td><select style="width: 150px" id="status' + counter + '" name="status' + counter + '" ><option value="N">No</option><option value="Y">Yes</option></select></td>\n\
                                    <td style="display: none"><input type="hidden" name="id' + counter + '" id="id' + counter + '"/></td>\n\
                        </tr>');
                    $("#rowCounter").val(counter);

                });

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

                    var len = ($("#order-list tr").length)-1;
                    var counter = $("#rowCounter").val();
                    var chkboxCounter=$("#chkboxCounter").val();
                    //alert(chkboxCounter);
                    counter=counter-chkboxCounter;
                    // alert(counter);
                    if (counter==0){

                        alert("All rows cannot be deleted");
                    }
                    else{

                        if (len ==chkboxCounter) {
                            alert("All rows can not be deleted");
                            return false;
                        }

                        $('input:checkbox:checked').closest('tr').remove();
                        chkboxCounter=0;
                        $("#chkboxCounter").val(chkboxCounter);

                    }
                });

                function checkboxTrue(i){

                    if(document.getElementById("chckbox"+i).checked==true){

                        var counter = $("#chkboxCounter").val();
                        counter++;
                        $("#chkboxCounter").val(counter);
                    }

                    else{

                        var counter = $("#chkboxCounter").val();
                        counter--;
                        $("#chkboxCounter").val(counter);
                    }
                }

                function ShowParent()
                { 
                    document.forms[0].action = "${pageContext.request.contextPath}/Payroll/LeaveMaster.jsp";
                    document.forms[0].submit();
                }

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