
<%@page import="LoginDb.DbHandler"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="java.sql.Connection"%>
<%@page import="DataEntryBean.DepositRateSlabBean"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@page import="java.util.UUID" %>
<%String uuid = UUID.randomUUID().toString();%>
<% try {
%>

<html>
    <head>
        
        <title>SB Rate Slab</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();
                if($('#displayFlag').val() != "Y"){
	                    $('select#checkOption').change();
	                }
            }
            function selectproduct(width, height, pCode, iCat) {


                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 = "DepositRateSlab.jsp";
                var  lovKey="PickUPProduct";
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationDepositLOV.jsp?pCode=' + pCode + '&iCat=' + iCat + '&screenName=' + screenName+'&lovKey='+lovKey, 'PickUPProduct', attr);
                popWin.focus();
            }

            function selectproductAmend(width, height, pCode, iCat) {


                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 = "SBRateSlab.jsp";
                var  lovKey="PickUPProductAmend";
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationDepositLOV.jsp?pCode=' + pCode + '&iCat=' + iCat + '&screenName=' + screenName+'&lovKey='+lovKey, 'PickUPProduct', attr);
                popWin.focus();
            }
            function selectproductAmend2(width, height, pCode, iCat) {


                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 = "SBRateSlab.jsp";
                var  lovKey="PickUPProductAmend2";
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationDepositLOV.jsp?pCode=' + pCode + '&iCat=' + iCat + '&screenName=' + screenName+'&lovKey='+lovKey, 'PickUPProductAmend2', attr);
                popWin.focus();
            }

        // 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;
             int count3 = 1;
             String error_msg = "";
             Object error = request.getAttribute("message");
             if (error != null) {
                 error_msg = error.toString();
             }
        %>

        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>

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


        <%
             Object oDepositRateSlabBeanObj = request.getAttribute("oDepositRateSlabBean");
             DepositRateSlabBean oDepositRateSlabBeanHeader = new DepositRateSlabBean();
             if (oDepositRateSlabBeanObj != null) {
                 oDepositRateSlabBeanHeader = (DepositRateSlabBean) request.getAttribute("oDepositRateSlabBean");
             }

             Object alDepositRateSlabBeanObj = request.getAttribute("alDepositRateSlabBean");
             ArrayList<DepositRateSlabBean> alDepositRateSlabBean = new ArrayList<DepositRateSlabBean>();
             DepositRateSlabBean oDepositRateSlabBean = new DepositRateSlabBean();
             if (alDepositRateSlabBeanObj != null) {
                 alDepositRateSlabBean = (ArrayList<DepositRateSlabBean>) request.getAttribute("alDepositRateSlabBean");

             }
        %>

        <jsp:include page="MenuHead_Deposit.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">SB Rate Slab</legend>

            <form name="sbRateSlabForm" method="post" action="">

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

                <center style='display:none;'><h3><label style=" font-family: Berlin Sans FB; font-weight:  normal;">Operation Selection:</label>
                        <select id="checkOption" name="checkOption" >
                            <%--<option value="" disabled selected style="display:none;" > --Select-- </option>--%>
                            <%--<option value="create" >Create</option>--%>
                            <option value="amend" >Amend</option>

                        </select>
                    </h3></center>
                 
                <center>            
                <div id="amend">                        
                    <center>
                            <input type="button"  value="Fetch Product Parameters" onclick="javascript:submitformSearch()" />
                    </center>       
                        
                </div>
                </center> 
                <br><br>            
                <%if (displayFlag.equalsIgnoreCase("Y")) {%>
                <center>            
                
                <div id="amend2" style="width:930px;overflow: scroll;">                    

                    <center>
                        <table class="checkEvents" id="order-list" border="2" width="auto" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px">
                            <thead class="CSSTableGenerator" >
                                <tr>
                                    <td>Product Code</td>
                                    <td>Product Description</td>
                                    <td>Int Category</td>
                                    <td>Int Category Description</td>
                                    <td>Interest Rate(%)</td>
                                    <td>Int Cap Freq</td>                                    
                                    <td>Threshold Balance</td>
                                    <td>Threshold Intt Rate</td>
                                    <td>Minimum Bal</td>
                                    <td>Maximum Bal</td>
                                    <td>Minimum Withdrawal</td>
                                    <td>Maximum Withdrawal</td>
                                    <td>Debit Allow Flag</td>
                                    <td>Dormancy</td>
                                </tr>
                            </thead>
                           
                            <tbody>
                                <%
                                    oDepositRateSlabBean = new DepositRateSlabBean();
                                    count3 = 0;

                                    for (int i = 0; i < alDepositRateSlabBean.size(); i++) {
                                        oDepositRateSlabBean = alDepositRateSlabBean.get(i);

                                        count3++;
                                %>
                                <tr>                                    
                                    <td><input type="text"  style="border:none;" readonly name="prodCode<%=count3%>" id="prodCode<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getProdCode())%>"/></td>
                                    <td><input type="text"  style="border:none;" readonly name="prodDesc<%=count3%>" id="prodDesc<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getProdDesc())%>"/></td>
                                    <td><input type="text"  style="border:none;" readonly name="inttCat<%=count3%>" id="inttCat<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getInttCat())%>"/></td>
                                    <td><input type="text"  style="border:none;" readonly size="25" name="inttCatDesc<%=count3%>" id="inttCatDesc<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getInttCatDesc())%>"/></td>                                    
                                    <td><input type="text"  style="border:none;" class="numeric" name="inttRateAmend<%=count3%>" id="inttRateAmend<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getInttRate())%>"/></td>
                                    <td>
                                            <select style="width: 150px"  name="inttCapFreq<%=count3%>" id="inttCapFreq<%=count3%>" >
                                                <option <%if (oDepositRateSlabBean.getInttCapFreq().equalsIgnoreCase("Y")) {%>selected <%}%> value="Y">Yearly</option>
                                                <option <%if (oDepositRateSlabBean.getInttCapFreq().equalsIgnoreCase("H")) {%>selected <%}%> value="H">Half-Yearly</option>
                                                <option <%if (oDepositRateSlabBean.getInttCapFreq().equalsIgnoreCase("Q")) {%>selected <%}%> value="Q">Quarterly</option>
                                                <option <%if (oDepositRateSlabBean.getInttCapFreq().equalsIgnoreCase("M")) {%>selected <%}%> value="M">Monthly</option>
                                                <option <%if (oDepositRateSlabBean.getInttCapFreq().equalsIgnoreCase("O")) {%>selected <%}%> value="O">On-Closure</option>
                                            </select>
                                    </td>
                                    <td><input type="text"  style="border:none;" class="numeric" name="thresholdBal<%=count3%>" id="thresholdBal<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getThresholdBal())%>"/></td>
                                    <td><input type="text"  style="border:none;" class="numeric" name="thresholdInttRate<%=count3%>" id="thresholdInttRate<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getThresholdInttRate())%>"/></td>
                                    <td><input type="text"  style="border:none;" name="minBal<%=count3%>" id="minBal<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getMinBal())%>" onkeypress='return event.charCode >= 45 && event.charCode <= 57 && event.charCode != 47'/></td>
                                    <td><input type="text"  style="border:none;" class="numeric" name="maxBal<%=count3%>" id="maxBal<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getMaxBal())%>"/></td>
                                    <td><input type="text"  style="border:none;" class="numeric" name="minWithdraw<%=count3%>" id="minWithdraw<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getMinWithdraw())%>"/></td>
                                    <td><input type="text"  style="border:none;" class="numeric" name="maxWithdraw<%=count3%>" id="maxWithdraw<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getMaxWithdraw())%>"/></td>
                                    <td>
                                            <select style="width: 150px"  name="drTxnFlag<%=count3%>" id="drTxnFlag<%=count3%>" >
                                                <option <%if (oDepositRateSlabBean.getDrTxnFlag().equalsIgnoreCase("Y")) {%>selected <%}%> value="Y">Yes</option>
                                                <option <%if (oDepositRateSlabBean.getDrTxnFlag().equalsIgnoreCase("N")) {%>selected <%}%> value="N">No</option>
                                            </select>
                                    </td>
                                    <td><input type="text"  style="border:none;" class="numeric" name="dormancy<%=count3%>" id="dormancy<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getDormancy())%>"/></td>                                    
                                    <td><input type="hidden"  name="dep_product_id<%=count3%>" id="dep_product_id<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getDep_product_id())%>"/></td>
                                    <td style="display:none"><input type="hidden" name="slabTable_id<%=count3%>" id="slabTable_id<%=count3%>" value="<%=blankNull(oDepositRateSlabBean.getSlabTable_id())%>"/></td>
                                    <td style="display:none"><input type="hidden" name="rowStatus<%=count3%>" id="rowStatus<%=count3%>" value="A"/></td>
                                </tr>

                                <%}%>
                            </tbody>
                        </table>

                    </center>                    
                    </div>
                    </center> 
                    <%}%>        
                            <br>            
                            <br>
                <%if (displayFlag.equalsIgnoreCase("Y")) {%>
                <center>
                    <div>
                        <input type="button" value="Update" id="Update" onclick="javascript:submitformAmend(sbRateSlabForm)">
                        <input type="button" value="Reset" onclick="ShowParent();" />
                    </div>
                 </center>
                <%}%>           
                <input type="hidden" name="handle_id" value="" />
                <input type="hidden" id="displayFlag" name="displayFlag" value="<%=displayFlag%>"/>

                <input type="hidden" name="rowCounter" id="rowCounter" value="<%=count%>">
                <input type="hidden" name="rowCounterDelete" id="rowCounterDelete" value="<%=count%>">
                <input type="hidden" name="rowCounterAmend" id="rowCounterAmend" value="<%=count3%>">
                <input type="hidden" name="rowCounterDeleteAmend" id="rowCounterDeleteAmend" value="<%=count3%>">
                <input type="hidden" name="deletedRows" id="deletedRows" value=""/>
                <input type="hidden" name="chkboxCounter" id="chkboxCounter" value="0"/>
                <input type="hidden" name="chkboxCounterAmend" id="chkboxCounterAmend" value="0"/>
                <input type="hidden" name="add" id="add" value="0"/>

            </form>
            <script>

                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 checkboxTrueAmend(i){
                    if(document.getElementById("chckboxAmend"+i).checked==true){
                        var counter = $("#chkboxCounterAmend").val();
                        counter++;
                        $("#chkboxCounterAmend").val(counter);
                    }
                    else{
                        var counter = $("#chkboxCounterAmend").val();
                        counter--;
                        $("#chkboxCounterAmend").val(counter);
                    }
                }

                $("#addRow").click(function () {
                    //var counter = $("#rowCounter").val();
                    counter++;
                    $('#order-list tr:last').after('<tr> <td><input type="checkbox" name="chckbox' + counter + '" id="chckbox' + counter + '" onclick="checkboxTrue(' + counter + ');" /></td><td><input type="text" size="13" style="border:none;" name="inttRate' + counter + '" id="inttRate' + counter + '"/></td><td><input type="text" style="border:none;" name="termFrom' + counter + '" id="termFrom' + counter + '" class="noDot" /></td><td><input type="text" style="border:none;" name="termTo' + counter + '" id="termTo' + counter + '" class="noDot" /></td><td><input type="text" style="border:none;" class="numeric"  name="amountFrom' + counter + '" id="amountFrom' + counter + '"/></td><td><input type="text" style="border:none;" class="numeric" name="amountTo' + counter + '" id="amountTo' + counter + '"/></td> </tr>');
                    $("#rowCounter").val(counter);
                    $("#rowCounterDelete").val(counter);

                });
                $("#deleteRow").click(function () {
                    var len = ($("#order-list tr").length)-1;
                    var chkboxCounter=$("#chkboxCounter").val();
                    var rowcount = $("#rowCounterDelete").val();
                    var counterDelete = rowcount-chkboxCounter;
                    if (counterDelete == 0) {
                        alert("All rows can not be deleted");
                        return false;
                    }
                    else{
                        if (len ==chkboxCounter) {
                            alert("All rows can not be deleted");
                            return false;
                        }

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

                $("#addRowAmend").click(function () {
                   // var counter = $("#rowCounterAmend").val();
                    counter++;
                    $('#order-listAmend tr:last').after('<tr> <td><input type="checkbox" name="chckboxAmend' + counter + '" id="chckboxAmend' + counter + '" onclick="checkboxTrueAmend(' + counter + ');" /></td>\n\
                    <td><input type="text" size="13" style="border:none;" name="inttRateAmend' + counter + '" id="inttRateAmend' + counter + '" class="numeric"/></td>\n\
                    <td><input type="text" style="border:none;" name="termFromAmend' + counter + '" id="termFromAmend' + counter + '" class="noDot"/></td>\n\
                    <td><input type="text" style="border:none;" name="termToAmend' + counter + '" id="termToAmend' + counter + '" class="noDot" /></td>\n\
                    <td><input type="text" style="border:none;"  name="amountFromAmend' + counter + '" id="amountFromAmend' + counter + '" class="numeric"/></td>\n\
                    <td><input type="text" style="border:none;" name="amountToAmend' + counter + '" id="amountToAmend' + counter + '" class="numeric"/></td>\n\
                    <td style="display:none"><input type="text"  name="dep_product_idAmend' + counter + '" id="dep_product_idAmend' + counter + '" /></td>\n\
                    <td style="display:none"><input type="text" name="slabTable_id' + counter + '" id="slabTable_id' + counter + '"/></td>\n\
                    <td style="display:none"><input type="hidden" name="rowStatus' + counter + '" id="rowStatus' + counter + '" value="N"/></td>\n\
                    </tr>');
                    $("#rowCounterAmend").val(counter);
                    $("#rowCounterDeleteAmend").val(counter);
                });


                $("#deleteRowAmend").click(function () {
                    var len = ($("#order-listAmend tr").length)-1;
                    var chkboxCounter=$("#chkboxCounterAmend").val();
                    var rowcount = $("#rowCounterDeleteAmend").val();
                    var counterDelete = rowcount-chkboxCounter;
                    if (counterDelete == 0) {
                        alert("All rows can not be deleted");
                        return false;
                    }
                    else{
                        if (len ==chkboxCounter) {
                            alert("All rows can not be deleted");
                            return false;
                        }

                        var selchbox = [];
                        selchbox= getSelectedChbox(sbRateSlabForm);
                        $("#deletedRows").val(selchbox);
                        $('input:checkbox:checked').closest('tr').remove();
                        $("#rowCounterDeleteAmend").val( $("#rowCounterAmend").val());
                        chkboxCounter=0;
                        $("#chkboxCounterAmend").val(chkboxCounter);
                    }
                });


                function getSelectedChbox(sbRateSlabForm) {
                    var selchbox = [];
                    var inpfields = sbRateSlabForm.getElementsByTagName('input');
                    var nr_inpfields = inpfields.length;
                    for(var i=0; i<nr_inpfields; i++) {
                        if(inpfields[i].type == 'checkbox' && inpfields[i].checked == true){
                            if  (inpfields[i].value!=null || inpfields[i].value!="" ){
                                selchbox.push(inpfields[i].value);
                            }
                        }
                    }
                    return selchbox;
                }

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

                function submitformSearch(sbRateSlabForm)
                {    
                        document.forms[0].handle_id.value = "Search";
                        document.forms[0].action = '/PacsApplication/SBRateSlabServlet';
                        document.forms[0].submit();
                    
                }
                function submitformAmend(sbRateSlabForm)
                {   
                   if (checkDivAmend(sbRateSlabForm))
                   {
                        document.forms[0].handle_id.value = "Update";
                        document.forms[0].action = '/PacsApplication/SBRateSlabServlet';
                        sbRateSlabForm.submit(); 
                    }
                }          

                function checkDivAmend(sbRateSlabForm)
                {
                        var counter = document.forms[0].rowCounterAmend.value;
                        try{
                            for (var i = 1; i <= counter; i++) {
                                var inttRateAmend = document.getElementById("inttRateAmend" + i).value;
                                var thresholdBal = document.getElementById("thresholdBal" + i).value;
                                var thresholdInttRate = document.getElementById("thresholdInttRate" + i).value;
                                var minBal = document.getElementById("minBal" + i).value;
                                var maxBal = document.getElementById("maxBal" + i).value;
                                var minWithdraw = document.getElementById("minWithdraw" + i).value;
                                var maxWithdraw = document.getElementById("maxWithdraw" + i).value;
                                var dormancy = document.getElementById("dormancy" + i).value;

                                //alert("Rate"+inttRateAmend);

                            if ( inttRateAmend.indexOf('%') == -1 )
                            {
                                if (inttRateAmend == "" || thresholdBal == "" || thresholdInttRate == "" || minBal == "" || maxBal =="" || minWithdraw == "" || maxWithdraw == "" || dormancy =="") {
                                    alert("All Fields are mandatory.");
                                    return false;
                                }                                
                            }
                            else
                            {
                                  alert("Please do not enter % in Interest Rate.");
                                  document.getElementById("inttRateAmend").focus();
                                  return false;
                            }
                            }

                        }catch(e){

                        }                                        
                    return true;
                }                          

                $('.checkEvents').on('keydown',':input.numeric[type="text"]', function() {
                    if (event.shiftKey == true) {
                        event.preventDefault();
                    }

                    if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 46 || event.keyCode == 190) {

                    } else {
                        event.preventDefault();
                    }

                    if($(this).val().indexOf('.') !== -1 && event.keyCode == 190)
                    { event.preventDefault();}
                           
                });

                $('.checkEvents').on('keydown',':input.noDot[type="text"]', function(event) {
                    
                    if (event.shiftKey == true) {
                        event.preventDefault();
                    }

                    if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39  ) {

                    } else {
                        event.preventDefault();
                    }

                    if($(this).val().indexOf('.') !== -1 && event.keyCode == 190)
                    {event.preventDefault();}
                });                                

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

