<%--
    Document   : leaseRentCommodity
    Created on : Oct 16, 2017, 8:24:40 PM
    Author     : 594267
--%>
<%@page import="DataEntryBean.tradingPurchaseOrderBean"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.Date"%>
<%@page import="LoginDb.DbHandler"%>
<% try {
%>
<%@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>
        <title>Lease/Rent Commodity</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>
        <style>
            .hidden{
                display: none;
            }
            .fxd{
                display: none;
            }
        </style>
        <style>

            .dialog{
                border:5px solid #666;
                padding:10px;
                background:#FFFFFF;
                position:absolute;
                left: 300px;
                z-index:1;
                display:none;
            }
            .dialog label{
                display:inline-block;
                color:#151414;
            }
            div .dialog input[type=text]{
                border:1px solid #333;
                display:inline-block;
                margin:5px;
                width: 180px;

            }


        </style>
    </head>
    <body  onload="noBack()">
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }
            function ShowParent()
            {
                document.forms[0].action = "${pageContext.request.contextPath}/Trading_JSP/leaseRentCommodity.jsp";
                document.forms[0].submit();
            }
            function search_comm(width, height,commoditytype, tranType)
            {                
                //document.getElementById("trtranType").style.visibility = 'hidden';
                document.getElementById("tranType").disabled = true;
                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 = "leaseRentCommodity.jsp";
                var lovKey = "commDetails"
                popWin = open('/PacsApplication/CommonSearchInformationTradingLOV.jsp?commoditytype=' + commoditytype + '&tranType=' + tranType + '&screenName=' + screenName + '&lovKey=' + lovKey, 'commDetails', attr);
                popWin.focus();               

            }
            function search_cust(width, height, custID, tranType) {

                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 = "leaseRentCommodity.jsp";
                var lovKey = "custDetails"
                popWin = open('/PacsApplication/CommonSearchInformationTradingLOV.jsp?custID=' + custID + '&tranType=' + tranType + '&screenName=' + screenName + '&lovKey=' + lovKey, 'custDetails', attr);
                popWin.focus();

            }
            function numbersonly(e){
                    var unicode=e.charCode? e.charCode : e.keyCode
                    if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
                            if (unicode<48||unicode>57) //if not a number
                                    return false //disable key press
                    }
            }
            function showHidden(){
                $('.hidden').show();
                var tranType = document.getElementById('tranType').value;
                if(tranType == "R"){
                    $('#trmLenRow').hide();
                    $('#totPayDueRow').hide();
                    $('#secAmtRow').hide();
                }
                if(tranType == "RA"){
                    $('#trmLenRow').hide();
                    $('#totPayDueRow').hide();
                    $('#secAmtRow').hide();
                    $('#noOfUnitRow').hide();
                    
                }
                var v=document.getElementById('priceFreq').value.slice(0,-2);
                var a = "(In ";
                var b= "s)";
                if(v=="Dai")
                    v="Day";
                document.getElementById('trm').innerHTML = v.concat("s");
                document.getElementById('trm1').innerHTML = a + v + b;
                document.getElementById('trm2').innerHTML = a + v + b;
                document.getElementById('trm3').innerHTML = a + v + b;
            }
            function showFixed(){
                $('.fxd').show();
            }
            function calcAmt() {
                var noOfUnits = parseFloat($("#noOfUnits").val());
                var pricePerUnit = parseFloat($("#pricePerUnit").val());
                var trmLen = parseFloat($("#trmLen").val());
                var secAmt = parseFloat($("#secAmt").val());
                var net = parseFloat(0);
                if($("#noOfUnits").val()==""){
                    noOfUnits=1;
                }
                if($("#trmLen").val()==""){
                    trmLen=1;
                }
                if($("#secAmt").val()==""){
                    secAmt=0;
                }
                net = (noOfUnits * pricePerUnit * trmLen) + secAmt;
                document.getElementById("totPayDue").value = net;

            }
            function checkForm(){
                var noOfUnit = $("#noOfUnits").val();
                var trmLen  = parseFloat($("#trmLen").val());
                var secAmt  = $("#secAmt").val();
                var tranType = $("#tranType").val();
                var rentAmt = $("#rentAmt").val();
                var noOfUnits = parseFloat($("#noOfUnits").val());
                if($("#commType").val() == ""){
                    alert('Please provide Commodity Type.');
                    $("#commType").focus();
                    return false;
                }
                if($("#custID").val() == ""){
                    alert('Please enter the customer ID.');
                    $("#custID").focus();
                    return false;
                }
                if(noOfUnit == "" && (tranType=="L" || tranType=="R")){
                    alert('Please enter number of units.');
                    $("#noOfUnits").focus();
                    return false;
                }
                if(trmLen == "" && tranType=="L"){
                    alert('Please enter the term length.');
                    $("#trmLen").focus();
                    return false;
                }
                if((tranType == "L") &&(trmLen > parseFloat($("#maxTrm").val()) || trmLen < parseFloat($("#minTrm").val()))){
                    alert('Please enter term length within the range.');
                    $("#trmLen").focus();
                    return false;
                }
                if((tranType == "R") &&($("#oldNoOfUnits").val()=="")){
                    alert('Please search the customer before proceeding.');
                    $("#custID").focus();
                    return false;
                }
                if((tranType == "R") &&(noOfUnits != parseFloat($("#oldNoOfUnits").val()))){
                    alert('Number Of Units should be '+ $("#oldNoOfUnits").val());
                    $("#noOfUnits").focus();
                    return false;
                }
                if(secAmt == "" && tranType=="L"){
                    alert('Please enter the security amount.');
                    $("#secAmt").focus();
                    return false;
                }
                if((tranType == "R") &&(rentAmt != parseFloat($("#fxdPayDue").val()))){
                    alert('The rent amount should match the payment due amount.');
                    //$("#rentAmt").focus();
                    return false;
                }
                if((tranType == "RA") &&(rentAmt >= parseFloat($("#fxdPayDue").val()))){
                    alert('The rent amount cannot be same or greater than due amount.');
                    //$("#rentAmt").focus();
                    return false;
                }
                return true;
            }
            function submitForm(){
                if(checkForm()){
                    document.forms[0].action='/PacsApplication/LeaseCommodityServlet';
                    document.forms[0].submit();
                }
            }
            $(function(){
                $('#rentAmt').click(function(){
                    if($('#status').val() == "C"){
                        alert("Cash Drawer isn't opened yet!");
                    } else
                        $("#myform").show(500);
                })
            });
            
            // 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();
             }
        %>

        <jsp:include page="MenuHead_TRADING.jsp" flush="true" />
        <br>
        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>

        <%   String odeno2000 = "";
             String odeno500 = "";
             String odeno200 = "";
             String odeno100 = "";
             String odeno50 = "";
             String odeno20 = "";
             String odeno10 = "";
             String odeno5 = "";
             String odeno2 = "";
             String odeno1 = "";
             String odeno50P = "";
             String odeno1P = "";
             String status = "C";
             String pacsid = (String) session.getAttribute("pacsId");
             String makerId = session.getAttribute("user").toString();
             Connection connection = null;
             ResultSet rs = null;
             Statement statement = null;
             connection = DbHandler.getDBConnection();
             try {
                 statement = connection.createStatement();
                 rs = statement.executeQuery("select nvl(d.deno_2000,0),nvl(d.deno_500,0),nvl(d.deno_100,0),nvl(d.deno_50,0),nvl(d.deno_20,0),nvl(d.deno_10,0),nvl(d.deno_5,0),nvl(d.deno_2,0),nvl(d.deno_1,0),nvl(d.DENO_50P,0),nvl(d.DENO_1P,0),d.status,nvl(d.deno_200,0) from cash_drawer d where d.entry_date = (select system_date from system_date) and  d.teller_id ='" + makerId + "' and d.pacs_id ='" + pacsid + "' ");

                 while (rs.next()) {
                     odeno2000 = rs.getString(1);
                     odeno500 = rs.getString(2);
                     odeno100 = rs.getString(3);
                     odeno50 = rs.getString(4);
                     odeno20 = rs.getString(5);
                     odeno10 = rs.getString(6);
                     odeno5 = rs.getString(7);
                     odeno2 = rs.getString(8);
                     odeno1 = rs.getString(9);
                     odeno50P = rs.getString(10);
                     odeno1P = rs.getString(11);
                     status = rs.getString(12);
                     odeno200 = rs.getString(13);
                 }
                // statement.close();         
                // connection.close();
             } catch (Exception e) {
                System.out.println("Error occurred during processing.");
            } finally {
                try {
                    if(statement !=null)
                        statement.close();
                    if (connection != null)
                    connection.close();

            } catch (Exception e) {               
               System.out.println("Error Occurred during connection close.");
            }

            }
        %>
        <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">Lease/Rent Commodity</legend>
            <center>
                <form name="leaseCommodity" method="post" action="">

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

                    <div class="dialog" id="myform" >

                        <table border="2" width="auto" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px">
                            <thead class="CSSTableGenerator">
                                <tr>
                                    <td>Denominations</td>
                                    <td>Available</td>
                                    <td>IN</td>
                                    <td>OUT</td>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td align="left"><label>2000 Note</label></td>
                                    <td><input type="text" readonly name="twothouAvail" id="twothouAvail" class="available" value="<%=odeno2000%>"></td>
                                    <td><input type="text" name="twothouIN" id="twothouIN" class="inDeno"></td>
                                    <td><input type="text" name="twothouOUT" id="twothouOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td align="left"><label>500 Note</label></td>
                                    <td><input type="text" readonly name="fivehundredAvail" id="fivehundredAvail" class="available" value="<%=odeno500%>"></td>
                                    <td><input type="text" name="fivehundredIN" id="fivehundredIN" class="inDeno"></td>
                                    <td><input type="text" name="fivehundredOUT" id="fivehundredOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td align="left"><label>200 Note</label></td>
                                    <td><input type="text" readonly name="twohundredAvail" id="twohundredAvail" class="available" value="<%=odeno200%>"></td>
                                    <td><input type="text" name="twohundredIN" id="twohundredIN" class="inDeno"></td>
                                    <td><input type="text" name="twohundredOUT" id="twohundredOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td align="left"><label>100 Note</label></td>
                                    <td><input type="text" readonly name="hundredAvail" id="hundredAvail" class="available" value="<%=odeno100%>"></td>
                                    <td><input type="text" name="hundredIN" id="hundredIN" class="inDeno"></td>
                                    <td><input type="text" name="hundredOUT" id="hundredOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td align="left"><label>50 Note</label></td>
                                    <td><input type="text" readonly name="fiftyAvail" id="fiftyAvail" class="available" value="<%=odeno50%>"></td>
                                    <td><input type="text" name="fiftyIN" id="fiftyIN" class="inDeno"></td>
                                    <td><input type="text" name="fiftyOUT" id="fiftyOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td align="left"><label>20 Note</label></td>
                                    <td><input type="text" readonly name="twentyAvail" id="twentyAvail" class="available" value="<%=odeno20%>"></td>
                                    <td><input type="text" name="twentyIN" id="twentyIN" class="inDeno"></td>
                                    <td><input type="text" name="twentyOUT" id="twentyOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td align="left"><label>10 Note</label></td>
                                    <td><input type="text" readonly name="tenAvail" id="tenAvail" class="available" value="<%=odeno10%>"></td>
                                    <td><input type="text" name="tenIN" id="tenIN" class="inDeno"></td>
                                    <td><input type="text" name="tenOUT" id="tenOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td align="left"><label>5 Note</label></td>
                                    <td><input type="text" readonly name="fiveAvail" id="fiveAvail" class="available" value="<%=odeno5%>"></td>
                                    <td><input type="text" name="fiveIN" id="fiveIN" class="inDeno"></td>
                                    <td><input type="text" name="fiveOUT" id="fiveOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td align="left"><label>2 Note</label></td>
                                    <td><input type="text" readonly name="twoAvail" id="twoAvail" class="available" value="<%=odeno2%>"></td>
                                    <td><input type="text" name="twoIN" id="twoIN" class="inDeno"></td>
                                    <td><input type="text" name="twoOUT" id="twoOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td align="left"><label>1 Note</label></td>
                                    <td><input type="text" readonly name="oneAvail" id="oneAvail" class="available" value="<%=odeno1%>"></td>
                                    <td><input type="text" name="oneIN" id="oneIN" class="inDeno"></td>
                                    <td><input type="text" name="oneOUT" id="oneOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td align="left"><label>50 Paisa</label></td>
                                    <td><input type="text" readonly name="fiftyPaisaAvail" id="fiftyPaisaAvail" class="available" value="<%=odeno50P%>"></td>
                                    <td><input type="text" name="fiftyPaisaIN" id="fiftyPaisaIN" class="inDeno"></td>
                                    <td><input type="text" name="fiftyPaisaOUT" id="fiftyPaisaOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td align="left"><label>1 Paisa</label></td>
                                    <td><input type="text" readonly name="onePaisaAvail" id="onePaisaAvail" class="available" value="<%=odeno1P%>"></td>
                                    <td><input type="text" name="onePaisaIN" id="onePaisaIN" class="inDeno"></td>
                                    <td><input type="text" name="onePaisaOUT" id="onePaisaOUT" class="outDeno"></td>
                                </tr>
                                <tr>
                                    <td colspan="2" align="left"><label>Total IN/OUT</label></td>

                                    <td><input type="text" readonly name="totalIN" id="totalIN" ></td>
                                    <td><input type="text" readonly name="totalOUT" id="totalOUT" ></td>
                                </tr>
                                <tr>
                                    <td><label>Cash Drawer Present Balance</label></td>
                                    <td><input type="text" readonly name="cashDRWBal" id="cashDRWBal" ></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td><label>Resulted Txn Amount</label></td>
                                    <td><input type="text" readonly name="resTXNAmt" id="resTXNAmt"></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                            </tbody>
                        </table>
                        <br>
                        <div align="center">
                            <input type="button" value="Ok" id="btnOK"><input type="button" value="Reset" id="btnReset"><input type="button" value="Close" id="closePopup">
                        </div>

                    </div>

                    <center id="trtranType">
                        <lable style=" font-family: Berlin Sans FB; font-weight:  normal;">Operation Selection:</lable>
                        <select id="tranType" name="tranType">
                            <option value="" disabled selected>--Select--</option>
                            <option value="L">Lease/Rent Commodity</option>
                            <option value="RA">Receive Lease/Rent Amount</option>
                            <option value="R">Return from Lease/Rent</option>
                        </select>
                    </center>
                    <br>
                    <table style="font-weight: normal" id="mytable" name="mytable">

                        <tr>
                            <td></td>
                            <td>
                                Commodity Type:<font color="red" >*</font>
                            </td>
                            <td>
                                <input type="text" id="commType" name="commType" style="text-align:right;" onkeypress="return numbersonly(event);" /></td><td><input type="button" value="Search" onclick="javascript:search_comm(750, 400,document.getElementById('commType').value,document.getElementById('tranType').value)"/>
                            </td>
                        </tr>

                        <tr class="hidden">
                            <td></td>
                            <td>
                                Commodity Type Desc:
                            </td>
                            <td>
                                <input type="text" id="commTypeDesc" name="commTypeDesc" readonly />
                            </td>
                        </tr>
                        <tr class="hidden"><td colspan="5"><hr></td></tr>
                        <tr class="hidden">
                            <td>
                                Commodity Sub-Type:
                            </td>
                            <td>
                                <input type="text" id="commSubType" name="commSubType" readonly style="text-align:right;"/>
                            </td>
                            <td>
                                Sub-Type Desc:
                            </td>
                            <td>
                                <input type="text" id="commSubTypeDesc" name="commSubTypeDesc" readonly />
                            </td>
                        </tr>
                        <tr class="hidden">
                            <td>
                                Price Per Unit:
                            </td>
                            <td>
                                <input type="text" id="pricePerUnit" name="pricePerUnit" readonly style="text-align:right;"/>
                            </td>
                            <td>
                                Price Frequency:
                            </td>
                            <td>
                                <input type="text" id="priceFreq" name="priceFreq" readonly />
                            </td>
                        </tr>
                        <tr class="hidden">
                            <td>
                                Min Term <label id="trm1"></label>
                            </td>
                            <td>
                                <input type="text" id="minTrm" name="minTrm" readonly style="text-align:right;"/>
                            </td>
                            <td>
                                Max Term <label id="trm2"></label>
                            </td>
                            <td>
                                <input type="text" id="maxTrm" name="maxTrm" readonly style="text-align:right;" />
                            </td>
                        </tr>
                        <tr class="fxd"><td colspan="5"><hr></td></tr>
                        <tr class="fxd">
                            <td>
                                Number Of Units
                            </td>
                            <td>
                                <input type="text" id="fxdNounit" name="fxdNounit" readonly />
                            </td>
                            <td>
                                Term Length <label id="trm3"></label>
                            </td>
                            <td>
                                <input type="text" id="fxdTrmLen" name="fxdTrmLen" readonly />
                            </td>
                        </tr>
                        <tr class="fxd">
                            <td>
                                Security Amount
                            </td>
                            <td>
                                <input type="text" id="fxdSecAmt" name="fxdSecAmt" readonly />
                            </td>
                            <td>
                                Total Payment Due
                            </td>
                            <td>
                                <input type="text" id="fxdPayDue" name="fxdPayDue" readonly />
                            </td>
                        </tr>
                        <tr class="hidden"><td colspan="5"><hr></td></tr>
                        <tr class="hidden">
                            <td></td>
                            <td>
                                Customer ID<font color="red" >*</font>:
                            </td>
                            <td>
                                <input type="text" id="custID" name="custID" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' />
                            </td>
                            <td>
                                <input type="button" value="Search" onclick="javascript:search_cust(750, 400,document.getElementById('custID').value,document.getElementById('tranType').value)"/>
                            </td>
                        </tr>
                        <tr class="hidden" id="noOfUnitRow" name="noOfUnitRow">
                            <td></td>
                            <td>
                                Number of Units<font color="red" >*</font>:
                            </td>
                            <td>
                                <input type="text" id="noOfUnits" name="noOfUnits" style="text-align:right;" onkeypress="return numbersonly(event);" onkeyup="javascript:calcAmt();"  onchange="javascript:calcAmt();"/>
                            </td>
                            <td></td>
                        </tr>
                        <tr class="hidden" id="trmLenRow" name="trmLenRow">
                            <td></td>
                            <td>
                                Term Length:
                            </td>
                            <td>
                                <input type="text" id="trmLen" name="trmLen" style="text-align:right;" onkeypress="return numbersonly(event);" onkeyup="javascript:calcAmt();"  onchange="javascript:calcAmt();"/></td><td><label id="trm"></label>
                            </td>
                            <td></td>
                        </tr>
                        <tr class="hidden" id="secAmtRow" name="secAmtRow">
                            <td></td>
                            <td>
                                Security Amount<font color="red" >*</font>:
                            </td>
                            <td>
                                <input type="text" id="secAmt" name="secAmt" style="text-align:right;" onkeypress="return numbersonly(event);" onkeyup="javascript:calcAmt();" onchange="javascript:calcAmt();"/>
                            </td>
                            <td></td>
                        </tr>
                        <tr class="hidden" id="totPayDueRow" name="totPayDueRow">
                            <td></td>
                            <td>
                                Total payment Due:
                            </td>
                            <td>
                                <input type="text" id="totPayDue" name="totPayDue" style="text-align:right;" readonly onkeypress="return numbersonly(event);"/>
                            </td>
                            <td></td>
                        </tr>
                        <tr class="fxd">
                            <td></td>
                            <td>
                                Transaction Amount:
                            </td>
                            <td>
                                <input type="text" id="rentAmt" name="rentAmt" onkeypress="return numbersonly(event);"/>
                            </td>
                            <td class="DenoCanBAdded"></td>
                            <td></td>
                        </tr>

                    </table>
                    <br>
                    <input type="button" value="Submit" onclick="submitForm();"/>
                    <input type="button" value="Reset" onclick="ShowParent();" />

                    <input type="hidden" id="prod_id" name="prod_id" value=""/>
                    <input type="hidden" id="oldNoOfUnits" name="oldNoOfUnits" value=""/>
                    <input type="hidden" id="tdLeaseID" name="tdLeaseID" value=""/>
                    <input type="hidden" value="<%=status%>" name="status" id="status" />
                </form>
            </center>
        </fieldset>


    </body>
    <script>
        function check(v){
            if(isNaN(v) || v == '' || v.trim().length == 0){ return parseInt(0);}
            else { return v;}
        }

        var first = $('#twothouAvail').val();
        var second = $('#fivehundredAvail').val();
        var third = $('#hundredAvail').val();
        var fourth = $('#fiftyAvail').val();
        var fifth = $('#twentyAvail').val();
        var sixth = $('#tenAvail').val();
        var seventh = $('#fiveAvail').val();
        var eighth = $('#twoAvail').val();
        var ninth = $('#oneAvail').val();
        var eleventh = $('#fiftyPaisaAvail').val();
        var twelveth = $('#onePaisaAvail').val();
        var thirtinth = $('#twohundredAvail').val();


        $(document).ready(function() {
            $('#myform').find(':input.inDeno[type="text"],#totalIN,#totalOUT,#resTXNAmt').val('0');
            $('#myform').find(':input.outDeno[type="text"]').val('0');
            $('.inDeno,.outDeno').css({"background-color": "#FFFFC1"});
            $('#totalIN,#totalOUT').css({"background-color": "#ffff93"});
            $('#cashDRWBal,#resTXNAmt').css({"background-color": "#b2d0b2"});
        });

        var AvailsumOnLoad = 0;
        var DenoINsumOnLoad = 0;

        AvailsumOnLoad = (parseInt(check($('#twothouAvail').val()) * 2000) + parseInt(check($('#fivehundredAvail').val()) * 500) + parseInt(check($('#twohundredAvail').val()) * 200)+ parseInt(check($('#hundredAvail').val()) * 100)+ parseInt(check($('#fiftyAvail').val()) * 50)+ parseInt(check($('#twentyAvail').val()) * 20)+ parseInt(check($('#tenAvail').val()) * 10)+ parseInt(check($('#fiveAvail').val()) * 5)+ parseInt(check($('#twoAvail').val()) * 2)+ parseInt(check($('#oneAvail').val()) * 1) + parseFloat(parseInt(check($('#fiftyPaisaAvail').val())) * 0.50) + parseFloat(parseInt(check($('#onePaisaAvail').val())) * 0.01)).toFixed(2);
        $("#cashDRWBal").val(AvailsumOnLoad);
        var tenth = $('#cashDRWBal').val();//calculating present cash drawer value for first time

        $( "#btnReset" ).click(function() {
            $('#myform').find(':input.inDeno[type="text"],:input.outDeno[type="text"]').val('0');
            $("#totalIN").val('0');
            $("#totalOUT").val('0');
            $('#twothouAvail').val(first);
            $('#fivehundredAvail').val(second);
            $('#hundredAvail').val(third);
            $('#fiftyAvail').val(fourth);
            $('#twentyAvail').val(fifth);
            $('#tenAvail').val(sixth);
            $('#fiveAvail').val(seventh);
            $('#twoAvail').val(eighth);
            $('#oneAvail').val(ninth);
            $('#fiftyPaisaAvail').val(eleventh);
            $('#onePaisaAvail').val(twelveth);
            $("#cashDRWBal").val(tenth);
            $('#resTXNAmt').val('0');
            $('#twohundredAvail').val(thirtinth);

            if ($('.DenoCanBAdded').find('img').length > 0){
                $('.DenoAdded').remove();
            }
        });

        //make all inputs whole numbers only
        $('.dialog').on('keydown',':input[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 || event.keyCode == 46) {

            } else {
                event.preventDefault();
            }
        });

        //calculating IN & OUT Total,and Resultant final Amount
        $('#myform').on("keyup", ".inDeno,.outDeno", function() {
            var DenoINsumOnChange = 0;
            var DenoOUTsumOnChange = 0;
            DenoINsumOnChange = (parseInt(check($('#twothouIN').val())) * 2000 + parseInt(check($('#fivehundredIN').val())) * 500 + parseInt(check($('#twohundredIN').val())) * 200 + parseInt(check($('#hundredIN').val())) * 100 + parseInt(check($('#fiftyIN').val())) * 50 + parseInt(check($('#twentyIN').val())) * 20 + parseInt(check($('#tenIN').val())) * 10 + parseInt(check($('#fiveIN').val())) * 5 + parseInt(check($('#twoIN').val())) * 2 + parseInt(check($('#oneIN').val())) + parseFloat(check($('#fiftyPaisaIN').val()) * 0.50) + parseFloat(check($('#onePaisaIN').val()) * 0.01)).toFixed(2);
            $("#totalIN").val(DenoINsumOnChange);
            DenoOUTsumOnChange = (parseInt(check($('#twothouOUT').val())) * 2000 + parseInt(check($('#fivehundredOUT').val())) * 500 + parseInt(check($('#twohundredOUT').val())) * 200 + parseInt(check($('#hundredOUT').val())) * 100 + parseInt(check($('#fiftyOUT').val())) * 50 + parseInt(check($('#twentyOUT').val())) * 20 + parseInt(check($('#tenOUT').val())) * 10 + parseInt(check($('#fiveOUT').val())) * 5 + parseInt(check($('#twoOUT').val())) * 2 + parseInt(check($('#oneOUT').val())) + parseFloat(check($('#fiftyPaisaOUT').val()) * 0.50) + parseFloat(check($('#onePaisaOUT').val()) * 0.01)).toFixed(2);
            $("#totalOUT").val(DenoOUTsumOnChange);
            $('#resTXNAmt').val((parseInt(check($('#totalIN').val())) - parseInt(check($('#totalOUT').val()))).toFixed(2));
        });

        //for Rs 2000 starts
        $('#myform').on("keyup", "#twothouOUT", function() {
            if(parseInt($("#twothouAvail").val())<= 0)
            {
                alert("Insufficiernt Rs.2000 Notes");
                $('#btnReset').click();
            }
            else{
                $('#twothouAvail').val(parseInt(check(first)) + (parseInt(check($('#twothouIN').val())) - parseInt(check($('#twothouOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#twothouOUT", function() {
            if(parseInt(first)< parseInt(check($('#twothouOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#twothouIN", function() {

            $('#twothouAvail').val(parseInt(check(first)) + (parseInt(check($('#twothouIN').val())) - parseInt(check($('#twothouOUT').val()))));
            calculateDeno();

        });

        //for Rs 500 starts
        $('#myform').on("keyup", "#fivehundredOUT", function() {
            if(parseInt($("#fivehundredAvail").val())<= 0)
            {
                alert("Insufficiernt Rs.500 Notes");
                $('#btnReset').click();
            }
            else{
                $('#fivehundredAvail').val(parseInt(check(second)) + (parseInt(check($('#fivehundredIN').val())) - parseInt(check($('#fivehundredOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#fivehundredOUT", function() {
            if(parseInt(second)< parseInt(check($('#fivehundredOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#fivehundredIN", function() {

            $('#fivehundredAvail').val(parseInt(check(second)) + (parseInt(check($('#fivehundredIN').val())) - parseInt(check($('#fivehundredOUT').val()))));
            calculateDeno();
        });

        //for Rs 200 starts
        $('#myform').on("keyup", "#twohundredOUT", function() {
            if(parseInt($("#twohundredAvail").val())<= 0)
            {
                alert("Insufficiernt Rs.200 Notes");
                $('#btnReset').click();
            }
            else{
                $('#twohundredAvail').val(parseInt(check(thirtinth)) + (parseInt(check($('#twohundredIN').val())) - parseInt(check($('#twohundredOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#twohundredOUT", function() {
            if(parseInt(thirtinth)< parseInt(check($('#twohundredOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#twohundredIN", function() {

            $('#twohundredAvail').val(parseInt(check(thirtinth)) + (parseInt(check($('#twohundredIN').val())) - parseInt(check($('#twohundredOUT').val()))));
            calculateDeno();
        });

        //for Rs 100 starts
        $('#myform').on("keyup", "#hundredOUT", function() {
            if(parseInt($("#hundredAvail").val())<= 0)
            {
                alert("Insufficiernt Rs.100 Notes");
                $('#btnReset').click();
            }
            else{
                $('#hundredAvail').val(parseInt(check(third)) + (parseInt(check($('#hundredIN').val())) - parseInt(check($('#hundredOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#hundredOUT", function() {
            if(parseInt(third)< parseInt(check($('#hundredOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#hundredIN", function() {

            $('#hundredAvail').val(parseInt(check(third)) + (parseInt(check($('#hundredIN').val())) - parseInt(check($('#hundredOUT').val()))));
            calculateDeno();

        });


        //for Rs 50 starts
        $('#myform').on("keyup", "#fiftyOUT", function() {
            if(parseInt($("#fiftyAvail").val())<= 0)
            {
                alert("Insufficiernt Rs.50 Notes");
                $('#btnReset').click();
            }
            else{
                $('#fiftyAvail').val(parseInt(check(fourth)) + (parseInt(check($('#fiftyIN').val())) - parseInt(check($('#fiftyOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#fiftyOUT", function() {
            if(parseInt(fourth)< parseInt(check($('#fiftyOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#fiftyIN", function() {

            $('#fiftyAvail').val(parseInt(check(fourth)) + (parseInt(check($('#fiftyIN').val())) - parseInt(check($('#fiftyOUT').val()))));
            calculateDeno();

        });

        //for Rs 20 starts
        $('#myform').on("keyup", "#twentyOUT", function() {
            if(parseInt($("#twentyAvail").val())<= 0)
            {
                alert("Insufficiernt Rs.20 Notes");
                $('#btnReset').click();
            }
            else{
                $('#twentyAvail').val(parseInt(check(fifth)) + (parseInt(check($('#twentyIN').val())) - parseInt(check($('#twentyOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#twentyOUT", function() {
            if(parseInt(fifth)< parseInt(check($('#twentyOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#twentyIN", function() {

            $('#twentyAvail').val(parseInt(check(fifth)) + (parseInt(check($('#twentyIN').val())) - parseInt(check($('#twentyOUT').val()))));
            calculateDeno();

        });

        //for Rs 10 starts
        $('#myform').on("keyup", "#tenOUT", function() {
            if(parseInt($("#tenAvail").val())<= 0)
            {
                alert("Insufficiernt Rs.10 Notes");
                $('#btnReset').click();
            }
            else{
                $('#tenAvail').val(parseInt(check(sixth)) + (parseInt(check($('#tenIN').val())) - parseInt(check($('#tenOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#tenOUT", function() {
            if(parseInt(sixth)< parseInt(check($('#tenOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#tenIN", function() {

            $('#tenAvail').val(parseInt(check(sixth)) + (parseInt(check($('#tenIN').val())) - parseInt(check($('#tenOUT').val()))));
            calculateDeno();

        });


        //for Rs 5 starts
        $('#myform').on("keyup", "#fiveOUT", function() {
            if(parseInt($("#fiveAvail").val())<= 0)
            {
                alert("Insufficiernt Rs.5 Notes");
                $('#btnReset').click();
            }
            else{
                $('#fiveAvail').val(parseInt(check(seventh)) + (parseInt(check($('#fiveIN').val())) - parseInt(check($('#fiveOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#fiveOUT", function() {
            if(parseInt(seventh)< parseInt(check($('#fiveOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#fiveIN", function() {

            $('#fiveAvail').val(parseInt(check(seventh)) + (parseInt(check($('#fiveIN').val())) - parseInt(check($('#fiveOUT').val()))));
            calculateDeno();

        });


        //for Rs 2 starts
        $('#myform').on("keyup", "#twoOUT", function() {
            if(parseInt($("#twoAvail").val())<= 0)
            {
                alert("Insufficiernt Rs.2 Notes");
                $('#btnReset').click();
            }
            else{
                $('#twoAvail').val(parseInt(check(eighth)) + (parseInt(check($('#twoIN').val())) - parseInt(check($('#twoOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#twoOUT", function() {
            if(parseInt(eighth)< parseInt(check($('#twoOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#twoIN", function() {

            $('#twoAvail').val(parseInt(check(eighth)) + (parseInt(check($('#twoIN').val())) - parseInt(check($('#twoOUT').val()))));
            calculateDeno();

        });


        //for Rs 1 starts
        $('#myform').on("keyup", "#oneOUT", function() {
            if(parseInt($("#oneAvail").val())<= 0)
            {
                alert("Insufficiernt Rs.1 Notes");
                $('#btnReset').click();
            }
            else{
                $('#oneAvail').val(parseInt(check(ninth)) + (parseInt(check($('#oneIN').val())) - parseInt(check($('#oneOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#oneOUT", function() {
            if(parseInt(ninth)< parseInt(check($('#oneOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#oneIN", function() {

            $('#oneAvail').val(parseInt(check(ninth)) + (parseInt(check($('#oneIN').val())) - parseInt(check($('#oneOUT').val()))));
            calculateDeno();

        });

        //for 50 Paisa starts
        $('#myform').on("keyup", "#fiftyPaisaOUT", function() {
            if(parseInt($("#fiftyPaisaAvail").val())<= 0)
            {
                alert("Insufficiernt 50 Paisa");
                $('#btnReset').click();
            }
            else{
                $('#fiftyPaisaAvail').val(parseInt(check(eleventh)) + (parseInt(check($('#fiftyPaisaIN').val())) - parseInt(check($('#fiftyPaisaOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#fiftyPaisaOUT", function() {
            if(parseInt(eleventh)< parseInt(check($('#fiftyPaisaOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#fiftyPaisaIN", function() {

            $('#fiftyPaisaAvail').val(parseInt(check(eleventh)) + (parseInt(check($('#fiftyPaisaIN').val())) - parseInt(check($('#oneOUT').val()))));
            calculateDeno();

        });

        //for 1 Paisa starts
        $('#myform').on("keyup", "#onePaisaOUT", function() {
            if(parseInt($("#onePaisaAvail").val())<= 0)
            {
                alert("Insufficiernt 1 Paisa");
                $('#btnReset').click();
            }
            else{
                $('#onePaisaAvail').val(parseInt(check(twelveth)) + (parseInt(check($('#onePaisaIN').val())) - parseInt(check($('#onePaisaOUT').val()))));
                calculateDeno();
            }
        });
        $('#myform').on("change", "#onePaisaOUT", function() {
            if(parseInt(twelveth)< parseInt(check($('#onePaisaOUT').val()))){
                alert("Insufficient Denomination !!!");
                $('#btnReset').click();
            }
        });
        $('#myform').on("keyup", "#onePaisaIN", function() {

            $('#onePaisaAvail').val(parseInt(check(twelveth)) + (parseInt(check($('#onePaisaIN').val())) - parseInt(check($('#onePaisaOUT').val()))));
            calculateDeno();

        });


        //Reset transaction amout when OK button clicks
        $('#btnOK').click(function(){
            var amount = $('#resTXNAmt').val();
            //var InstAmt = $('#instAmt').val();
            //var matVal = $('#netAmt').val();
            var txnamt = $('#rentAmt').val();
            var flag = 0;
        
            if(Number(amount) <= 0){
                alert("Resultant amount cannot be lesser than or equal to zero!!! ");
                flag = 1;
            }

            if(parseInt(flag) == 0){
                $('#rentAmt').val(amount);
                $("#myform").hide(400);
                if ($('.DenoCanBAdded').find('img').length == 0)
                {
                    $('.DenoCanBAdded').append('<span class="DenoAdded" style="padding-right:3px; padding-top: 3px; padding-left: 5px; display:inline-block;"><img class="manImg" src="${pageContext.request.contextPath}/img/check.png" width="15" height="20"/>Denomination added</span>');

                }
            }
        });
        $('#closePopup').click(function(){
            $( "#btnReset" ).click();
            $("#myform").hide(400);
        });

        function calculateDeno()
        {
            $("#totalOUT").val((parseInt(check($('#twothouOUT').val())) * 2000 + parseInt(check($('#fivehundredOUT').val())) * 500 + parseInt(check($('#twohundredOUT').val())) * 200 + parseInt(check($('#hundredOUT').val())) * 100 + parseInt(check($('#fiftyOUT').val())) * 50 + parseInt(check($('#twentyOUT').val())) * 20 + parseInt(check($('#tenOUT').val())) * 10 + parseInt(check($('#fiveOUT').val())) * 5 + parseInt(check($('#twoOUT').val())) * 2 + parseInt(check($('#oneOUT').val())) + parseFloat(check($('#fiftyPaisaOUT').val()) * 0.50) + parseFloat(check($('#onePaisaOUT').val())* 0.01)).toFixed(2));
            $('#totalIN').val((parseInt(check($('#twothouIN').val())) * 2000 + parseInt(check($('#fivehundredIN').val())) * 500 + parseInt(check($('#twohundredIN').val())) * 200 + parseInt(check($('#hundredIN').val())) * 100 + parseInt(check($('#fiftyIN').val())) * 50 + parseInt(check($('#twentyIN').val())) * 20 + parseInt(check($('#tenIN').val())) * 10 + parseInt(check($('#fiveIN').val())) * 5 + parseInt(check($('#twoIN').val())) * 2 + parseInt(check($('#oneIN').val())) + parseFloat(check($('#fiftyPaisaIN').val()) * 0.50) + parseFloat(check($('#onePaisaIN').val()) * 0.01)).toFixed(2));
            $("#cashDRWBal").val((parseInt(check($('#twothouAvail').val()) * 2000) + parseInt(check($('#fivehundredAvail').val()) * 500) + parseInt(check($('#twohundredAvail').val()) * 200) + parseInt(check($('#hundredAvail').val()) * 100)+ parseInt(check($('#fiftyAvail').val()) * 50)+ parseInt(check($('#twentyAvail').val()) * 20)+ parseInt(check($('#tenAvail').val()) * 10)+ parseInt(check($('#fiveAvail').val()) * 5)+ parseInt(check($('#twoAvail').val()) * 2)+ parseInt(check($('#oneAvail').val()) * 1) + parseFloat(check($('#fiftyPaisaAvail').val()) * 0.50) + parseFloat(check($('#onePaisaAvail').val()) * 0.01)).toFixed(2));
            $('#resTXNAmt').val((Number(check($('#totalIN').val())) - Number(check($('#totalOUT').val()))).toFixed(2));
        }
    </script>
</html>
<% 	} catch (Exception e) {
               
            }
%>
