<%-- 
    Document   : swapCashDeno
    Created on : Apr 5, 2018, 3:05:21 PM
    Author     : 594267
--%>

<%@page import="DataEntryBean.CashDenoBean"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Swap Cash Deno</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>
    </head>
    <style>
        table tbody.NoBorder tr td input[type=text]{
            border:none;
        }
    </style>
    <body onload="noBack();calcAvailBal();">
        <script type="text/javascript">
            function noBack()
            {
               window.history.forward();
               document.getElementById("body").style.visibility = 'hidden';
               document.getElementById("submitBttn").style.visibility = 'hidden';
			   document.getElementById("resetBttn").style.visibility = 'hidden';
            }
            function calcAvailBal(){
                var AvailsumOnLoad = parseInt($('#aDeno_2000').val() * 2000) + parseInt($('#aDeno_500').val() * 500) + parseInt($('#aDeno_200').val() * 200) + parseInt($('#aDeno_100').val() * 100) + parseInt($('#aDeno_50').val() * 50) + parseInt($('#aDeno_20').val() * 20)+ parseInt($('#aDeno_10').val() * 10)+ parseInt($('#aDeno_5').val() * 5)+ parseInt($('#aDeno_2').val() * 2)+ parseInt($('#aDeno_1').val() * 1 )+ parseFloat(parseInt($('#aDeno_50p').val()) * 0.50)+ parseFloat(parseInt($('#aDeno_1p').val()) * 0.01);
                document.getElementById("availBal").value = AvailsumOnLoad;
            }
            function calcNewBal(){
                var deno = ["2000","500","200","100","50","20","10","5","2","1","50p","1p"];
                var valu = ["2000","500","200","100","50","20","10","5","2","1","0.5","0.01"];
                var zerovalu = "0";
                var AvailsumOnLoad = 0;
                for(var i=0;i<deno.length;i++){
                    if($('#deno_'+deno[i]).val()==''||$('#deno_'+deno[i]).val()==null)
                        zerovalu="0";
                    else {
                        zerovalu=$('#deno_'+deno[i]).val();
                    }
                    AvailsumOnLoad = AvailsumOnLoad + parseFloat(parseInt(zerovalu) * valu[i]);
                }
                if(isNaN(AvailsumOnLoad))
                    AvailsumOnLoad = 0;
                document.getElementById("newBal").value = AvailsumOnLoad;

            }
            function updateZero(){
                var deno = ["2000","500","200","100","50","20","10","5","2","1","50p","1p"];
                for(var i=0;i<deno.length;i++){
                    if($('#deno_'+deno[i]).val()==''||$('#deno_'+deno[i]).val()==null)
                        $('#deno_'+deno[i]).val("0");
                    $('#deno_'+deno[i]).val(parseInt($('#deno_'+deno[i]).val()));
                }
                /*var AvailsumOnLoad = parseInt($('#deno_2000').val() * 2000) + parseInt($('#deno_500').val() * 500) + parseInt($('#deno_200').val() * 200) + parseInt($('#deno_100').val() * 100)+ parseInt($('#deno_50').val() * 50)+ parseInt($('#deno_20').val() * 20)+ parseInt($('#deno_10').val() * 10)+ parseInt($('#deno_5').val() * 5)+ parseInt($('#deno_2').val() * 2)+ parseInt($('#deno_1').val() * 1 )+ parseFloat(parseInt($('#deno_50p').val()) * 0.50)+ parseFloat(parseInt($('#deno_1p').val()) * 0.01);
                if(isNaN(AvailsumOnLoad))
                    AvailsumOnLoad = 0;
                document.getElementById("newBal").value = AvailsumOnLoad;*/
            }
            function validateBal(){
                updateZero();
                if($('#operationType').val()=="SWAP") {
                    if($('#availBal').val()!=$('#newBal').val()){
                        alert('Available Bal and New Balance should match!');
                        return false;
                    }
                    return true;
                }
                return true;
            }
            function updateCashDeno(){
                if (validateBal()) {
                    document.getElementById("operationType").disabled= false;
                    document.forms[0].handle_id.value = "update";
                    document.forms[0].action = '/PacsApplication/SwapCashDenoServlet';
                    document.forms[0].submit();
                }
            }
            function checkNegative(e){
                var charCode = (e.which) ? e.which : e.keyCode;
                if(!((charCode > 95 && charCode < 106)
                    || (charCode > 47 && charCode < 58) || (charCode == 189)
                    || charCode == 8)) {
                    return false;

                }
            }
            function ShowParent()
            {
                document.forms[0].action = '/PacsApplication/SwapCashDenoServlet';
                document.forms[0].submit();
            }
            $(document).ready(function () {
                $('select#operationType').change(function () {
                    document.getElementById("operationType").disabled= true;
                    document.getElementById("body").style.visibility = 'visible';
                    document.getElementById("submitBttn").style.visibility = 'visible';
					document.getElementById("resetBttn").style.visibility = 'visible';
                })
                
            });        
            
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            }); 
            
        </script>

        <%
                    String error_msg = "";
                    Object error = request.getAttribute("message");
                    if (error != null) {
                        error_msg = error.toString();
                    }
                    String ModuleName = new String();
                    ModuleName = (String) session.getAttribute("moduleName");
        %>
        <% if (ModuleName.equalsIgnoreCase("KCC")) {%>
        <jsp:include page="/MenuHead.jsp" flush="true" />
        <%} else if (ModuleName.equalsIgnoreCase("Deposit")) {%>
        <jsp:include page="/Deposit/MenuHead_Deposit.jsp" flush="true" />
        <%} else if (ModuleName.equalsIgnoreCase("Loan")) {%>
        <jsp:include page="/Loan/MenuHead_Loan.jsp" flush="true" />
        <%}%>
        <br>
        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>

        <%
                    CashDenoBean oCashDenoBean = new CashDenoBean();
                    Object oCashDenoBeanObj = request.getAttribute("oCashDenoBean");
                    if (oCashDenoBeanObj != null) {
                        oCashDenoBean = (CashDenoBean) request.getAttribute("oCashDenoBean");
                    }

                    //float totalAmt = ((Float.parseFloat(oCashDenoBean.getDeno_2000()) * Float.parseFloat("2000")) + (Float.parseFloat(oCashDenoBean.getDeno_500()) * Float.parseFloat("500")) + (Float.parseFloat(oCashDenoBean.getDeno_100()) * Float.parseFloat("100")) + (Float.parseFloat(oCashDenoBean.getDeno_50()) * Float.parseFloat("50")) + (Float.parseFloat(oCashDenoBean.getDeno_20()) * Float.parseFloat("20")) + (Float.parseFloat(oCashDenoBean.getDeno_10()) * Float.parseFloat("10")) + (Float.parseFloat(oCashDenoBean.getDeno_5()) * Float.parseFloat("5")) + (Float.parseFloat(oCashDenoBean.getDeno_2()) * Float.parseFloat("2")) + (Float.parseFloat(oCashDenoBean.getDeno_1()) * Float.parseFloat("1")) + (Float.parseFloat(oCashDenoBean.getDeno_50p()) * Float.parseFloat("0.5")) + (Float.parseFloat(oCashDenoBean.getDeno_1p()) * Float.parseFloat("0.01")));
        %>


        <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">Swap Cash Denomination</legend>
            <form name="transactionForm" id="transactionForm" method="post" action="">


                <%if (!error_msg.equalsIgnoreCase("")) {%>
                <center><div class="info" id="errorMessage"><center><%= error_msg%></center></div></center>
                <% }%>
                <br>
                <%--<center>--%>
                <center><h3><label style=" font-family: Berlin Sans FB; font-weight:  normal;">Operation Selection :</label></h3>
                    <select id="operationType" name="operationType" >
                            <option value="" disabled selected style="display:none;" > --Select-- </option>
                            <option value="SWAP" >Swap Cash Deno</option>
                            <option value="UPDATE" >Edit/Update Deno</option>
                            
                        </select>
                    <br>
                    <br>
                    <br>
                    <div id="body">
                    <table border="2" width="auto" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px">
                        <thead  class="CSSTableGenerator">
                            <tr>
                                <td><b>Denominations</b></td>
                                <td><b>Available Deno</b></td>
                                <td><b>New Denomination</b></td>
                            </tr>
                        </thead>
                        <tbody  style="background-color: white">
                            <tr>
                                <td style="text-align: left" >Rs. 2000</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_2000()%>" readonly id="aDeno_2000" /> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_2000" name="deno_2000" value="0"  onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                            <tr>
                                <td style="text-align: left" >Rs. 500</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_500()%>" readonly id="aDeno_500"/> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_500" name="deno_500" value="0" onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                            <tr>
                                <td style="text-align: left" >Rs. 200</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_200()%>" readonly id="aDeno_200"/> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_200" name="deno_200" value="0" onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                            <tr>
                                <td style="text-align: left" >Rs. 100</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_100()%>" readonly id="aDeno_100"/> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_100" name="deno_100" value="0" onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                            <tr>
                                <td style="text-align: left" >Rs. 50</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_50()%>" readonly id="aDeno_50"/> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_50" name="deno_50" value="0" onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                            <tr>
                                <td style="text-align: left" >Rs. 20</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_20()%>" readonly id="aDeno_20"/> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_20" name="deno_20" value="0" onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                            <tr>
                                <td style="text-align: left" >Rs. 10</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_10()%>" readonly id="aDeno_10"/> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_10" name="deno_10"  value="0" onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                            <tr>
                                <td style="text-align: left" >Rs. 5</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_5()%>" readonly id="aDeno_5"/> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_5" name="deno_5"  value="0" onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                            <tr>
                                <td style="text-align: left" >Rs. 2</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_2()%>" readonly id="aDeno_2"/> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_2" name="deno_2" value="0" onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                            <tr>
                                <td style="text-align: left" >Rs. 1</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_1()%>" readonly id="aDeno_1"/> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_1" name="deno_1" value="0" onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                            <tr>
                                <td style="text-align: left" >50 Paisa</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_50p()%>" readonly id="aDeno_50p"/> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_50p" name="deno_50p" value="0" onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                            <tr>
                                <td style="text-align: left" >1 Paisa</td>
                                <td><input type="text" style="text-align: right" value="<%=oCashDenoBean.getDeno_1p()%>" readonly id="aDeno_1p"/> </td>
                                <td><input type="text" min="0" style="text-align: right" id="deno_1p" name="deno_1p" value="0" onkeypress="return checkNegative(event)" onchange="javascript:calcNewBal()" onkeyup="javascript:calcNewBal()"/> </td>
                            </tr>
                        </tbody>
                    </table>
                                <p>Available Balance(INR):  <input type="text" id="availBal" name="availBal" readonly style="text-align: right;" /> &nbsp;&nbsp;&nbsp;
                                    New Balance(INR): <input type="text" id="newBal" name="newBal" readonly  value="0" style="text-align: right"/>

                    </p>
                    </div>
                    <p><input type="button" id="submitBttn" value="Update" onclick="javascript:updateCashDeno()" />
                        <input type="button" id="resetBttn" value="Reset" onclick="ShowParent();" /> </p>
                        <input type="hidden" name="handle_id" id="handle_id" value=""/>
                </center>

            </form>
        </fieldset>
    </body>
</html>
