<%--
    Document   : tradingProductCreation
    Created on : Apr 20, 2016, 3:16:34 PM
    Author     : 590685
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="DataEntryBean.PaymentAcknowledgementBean"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="LoginDb.DbHandler"%>
<% try {
%>
<html>
    <head>
        <title>Payment Acknowledgment </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>

            .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>
    <script>
        $(function() {
            $("#cnetAmt").click(function() {
                if($('#prodTotalDue').val() == "" || $('#prodTotalDue').val()==0){
                    alert("Due amount should be more than 0");
                    $('#prodTotalDue').focus();
                }else if($('#status').val() == "C" && $('#cpayMode').val() == "C" ){
                    alert("Cash Drawer isn't opened yet!");
                }/*else if($('#payMode').val() == null){
                    alert("Please select payment mode first");
                }*/
                else if($('#cpayMode').val() == "C"){
                        $("#myform").show(500);
                 }

            });

            $("#vnetAmt").click(function() {
                if($('#amountdue').val() == "" || $('#amountdue').val()==0){
                    alert("Due amount should be more than 0");
                    $('#amountdue').focus();
                }else if($('#status').val() == "C" && $('#vpayMode').val() == "C"){
                    alert("Cash Drawer isn't opened yet!");
                }/*else if($('#payMode').val() == null){
                    alert("Please select payment mode first");
                }*/
                else if($('#vpayMode').val() == "C"){
                        $("#myform").show(500);
                 }

            });

        });

        function ShowParent()
            {
                document.forms[0].action="${pageContext.request.contextPath}/Trading_JSP/PaymentAcknowldgement.jsp";
                document.forms[0].submit();
            }
            
        // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });    

    </script>
    <body onload="noBack()">
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }
            
            $(document).ready(function(){
                $('#vtobepaid').on("cut copy paste",function(e) {
                    e.preventDefault();
                });
               $('#ctobepaid').on("cut copy paste",function(e) {
                    e.preventDefault();
                });
            });

            function submitform(PaymentAcknowledgementForm)
            {
                if (checkCreateDiv(PaymentAcknowledgementForm))
                {
                    document.forms[0].handle_id.value = "V";
                    document.forms[0].action='/PacsApplication/PaymentAcknowledgementServlet';
                    PaymentAcknowledgementForm.submit();
                }

            }
            function checkCreateDiv(PaymentAcknowledgementForm)
            {
//                var cleanNum1 = parseFloat(Math.abs(PaymentAcknowledgementForm.disAmt.value)).toFixed(2);
//                document.getElementById('disAmt').value=cleanNum1;
         
                if (PaymentAcknowledgementForm.orderno.value == "")
                {
                    alert("Please search Purchase Order Number.");
                    PaymentAcknowledgementForm.orderno.focus();
                    return false;
                }
                if (PaymentAcknowledgementForm.vpayMode.value == "")
                {
                    alert("Please select Payment Mode.");
                    PaymentAcknowledgementForm.vpayMode.focus();
                    return false;
                }
                if (PaymentAcknowledgementForm.vtobepaid.value == "")
                {
                    alert("Please enter Amount To Be Paid.");
                    PaymentAcknowledgementForm.vtobepaid.focus();
                    return false;
                }
 
                    if (PaymentAcknowledgementForm.vsgst.value == "")
                    {
                    alert("Please enter SGST Amount.");
                    PaymentAcknowledgementForm.vsgst.focus();
                    return false;
                    }
                    if (PaymentAcknowledgementForm.vcgst.value == "")
                    {
                    alert("Please enter CGST Amount.");
                    PaymentAcknowledgementForm.vcgst.focus();
                    return false;
                    }
                    if (PaymentAcknowledgementForm.disAmt.value == "")
                    {
                    alert("Please enter Discount Amount.");
                    PaymentAcknowledgementForm.disAmt.focus();
                    return false;
                    }                
                       
                if (PaymentAcknowledgementForm.vtobepaid.value != "")

                {
                    if (PaymentAcknowledgementForm.vtobepaid.value == "0")
                    {
                    alert("Please enter valid amount.");
                    PaymentAcknowledgementForm.vtobepaid.focus();
                    return false;
                     }
//                    if (Number(PaymentAcknowledgementForm.vtobepaid.value) > Number(PaymentAcknowledgementForm.amountdue.value)){
//
//                        alert("Paid Amount Can not greater than Due Amount.");
//                        PaymentAcknowledgementForm.vtobepaid.focus();
//                        return false;
//
//                    }

                }

                if(PaymentAcknowledgementForm.vpayMode.value == "C" && $('#resTXNAmt').val()==""){
                    alert("Please enter the cash drawer denominations before proceeding.");
                    $("#vnetAmt").click();
                    return false;
                }
                if(PaymentAcknowledgementForm.vpayMode.value != "C" && $('#vtrfAcc').val()==""){
                    alert("Please search the transfer account number before proceeding.");
                    PaymentAcknowledgementForm.vtrfAcc.focus();
                    return false;
                }
                if (PaymentAcknowledgementForm.vpayMode.value == "C" && (Math.abs(parseFloat($('#resTXNAmt').val())) != parseFloat($('#vnetAmt').val())))
                {
                    alert("Please fill-in cash drawer deno before proceeding.");
                    $("#vnetAmt").click();
                    return false;
                }
                if ( PaymentAcknowledgementForm.checkOption.value == "S") {
                    if (PaymentAcknowledgementForm.csgst.value != PaymentAcknowledgementForm.ccgst.value )
                    {
                    alert("SGST and CGST should be same.");
                    PaymentAcknowledgementForm.csgst.focus();
                    return false;
                    }
                }
                if ( PaymentAcknowledgementForm.checkOption.value == "V") {
                    if (PaymentAcknowledgementForm.vsgst.value != PaymentAcknowledgementForm.vcgst.value )
                    {
                    alert("SGST and CGST should be same.");
                    PaymentAcknowledgementForm.vsgst.focus();
                    return false;
                    }
                }

                return true;
            }


            function updateform(PaymentAcknowledgementForm)
            {
                if (PaymentAcknowledgementForm.salesrefno.value == "")
                {
                    alert("Please search Sales Reference Number.");
                    PaymentAcknowledgementForm.salesrefno.focus();
                    return false;
                }
                if (PaymentAcknowledgementForm.cpayMode.value == "")
                {
                    alert("Please select Payment Mode.");
                    PaymentAcknowledgementForm.cpayMode.focus();
                    return false;
                }

                    if (PaymentAcknowledgementForm.csgst.value == "")
                    {
                    alert("Please enter SGST Amount.");
                    PaymentAcknowledgementForm.csgst.focus();
                    return false;
                    }
                    if (PaymentAcknowledgementForm.ccgst.value == "")
                    {
                    alert("Please enter CGST Amount.");
                    PaymentAcknowledgementForm.ccgst.focus();
                    return false;
                    }
                    
                if (checkUpdateDiv(PaymentAcknowledgementForm))
                {
                    document.forms[0].handle_id.value = "S";
                    document.forms[0].action='/PacsApplication/PaymentAcknowledgementServlet';
                    PaymentAcknowledgementForm.submit();
                }

            }
            function checkUpdateDiv(PaymentAcknowledgementForm)
            {
                if (PaymentAcknowledgementForm.ctobepaid.value == "")
                {
                    alert("Please enter Amount To Be Paid.");
                    PaymentAcknowledgementForm.ctobepaid.focus();
                    return false;
                }


                if (PaymentAcknowledgementForm.ctobepaid.value != "")

                {
                    if (PaymentAcknowledgementForm.ctobepaid.value == "0")
                    {
                    alert("Please enter valid amount.");
                    PaymentAcknowledgementForm.ctobepaid.focus();
                    return false;
                     }
//                    if (Number(PaymentAcknowledgementForm.ctobepaid.value) > Number(PaymentAcknowledgementForm.prodTotalDue.value)){
//
//                        alert("Paid Amount Can not greater than product Due Amount.");
//                        PaymentAcknowledgementForm.ctobepaid.focus();
//                        return false;
//
//                    }

                }
                if(PaymentAcknowledgementForm.cpayMode.value == "C" && $('#resTXNAmt').val()==""){
                    alert("Please enter the cash drawer denominations before proceeding.");
                    $("#cnetAmt").click();
                    return false;
                }
                if(PaymentAcknowledgementForm.cpayMode.value != "C" && $('#ctrfAcc').val()==""){
                    alert("Please enter the transfer account number before proceeding.");
                    PaymentAcknowledgementForm.ctrfAcc.focus();
                    return false;
                }

                if (PaymentAcknowledgementForm.cpayMode.value == "C" && (parseFloat($('#resTXNAmt').val()) != parseFloat($('#cnetAmt').val())))
                {
                    alert("Please fill-in cash drawer deno before proceeding.");
                    $("#cnetAmt").click();
                    return false;
                }

                if ( PaymentAcknowledgementForm.checkOption.value == "S") {
                    if (PaymentAcknowledgementForm.csgst.value != PaymentAcknowledgementForm.ccgst.value )
                    {
                    alert("SGST and CGST should be same.");
                    PaymentAcknowledgementForm.csgst.focus();
                    return false;
                    }
                }
                if ( PaymentAcknowledgementForm.checkOption.value == "V") {
                    if (PaymentAcknowledgementForm.vsgst.value != PaymentAcknowledgementForm.vcgst.value )
                    {
                    alert("SGST and CGST should be same.");
                    PaymentAcknowledgementForm.vsgst.focus();
                    return false;
                    }
                }

                return true;
            }
            
            function checkop()
            {
                if (document.getElementById("checkOption").value == "V")
                {
                    document.getElementById('ptv').style.display = 'block';
                    document.getElementById('pfc').style.display = 'none';

                }
                if (document.getElementById("checkOption").value == "S")
                {
                    document.getElementById('ptv').style.display = 'none';
                    document.getElementById('pfc').style.display = 'block';

                }

            }
            function searchPurchase(width, height,purchaseNo) {

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

            }

            function searchAccount(width, height, glAcc) {

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

            }

            function searchAccount2(width, height, glAcc, payMode, custId) {

                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 = "PaymentAcknowledgement.jsp";
                var lovKey = "searchAccount2"
                popWin = open('/PacsApplication/CommonSearchInformationTradingLOV.jsp?screenName=' + screenName + '&payMode=' + payMode + '&custId=' + custId + '&glAcc=' + glAcc + '&lovKey=' + lovKey, 'searchAccount', attr);
                popWin.focus();

            }

            function sumTax() {                         
                var amtToBPaid = parseFloat($("#vtobepaid").val());
                var cgst = parseFloat($("#vcgst").val());
                var sgst = parseFloat($("#vsgst").val());
                var disAmt = parseFloat($('#disAmt').val());

                if($("#vtobepaid").val()==""){
	                    amtToBPaid=parseFloat(0);
	                }
	        if($("#vcgst").val()==""){
	                    cgst=parseFloat(0);
	                }
	        if($("#vsgst").val()==""){
	                    sgst=parseFloat(0);
	                }
	        if($("#disAmt").val()==""){
	                    disAmt=parseFloat(0);
	                }

               if(document.getElementById("vpayMode").value == 'G' || document.getElementById("vpayMode").value == 'T')
                    document.getElementById("vnetAmt").value = parseFloat(parseFloat(amtToBPaid) + parseFloat(cgst) + parseFloat(sgst) - disAmt).toFixed(2);
                else
                    document.getElementById("vnetAmt").value = Math.round(parseFloat(amtToBPaid) + parseFloat(cgst) + parseFloat(sgst) - disAmt);
            }
            
            function sumTax2() {
                var amtToBPaid = parseFloat($("#ctobepaid").val());
                var cgst = parseFloat($("#ccgst").val());
                var sgst = parseFloat($("#csgst").val());

                if($("#ctobepaid").val()==""){
	                    amtToBPaid=parseFloat(0);
	                }
	        if($("#ccgst").val()==""){
	                    cgst=parseFloat(0);
	                }
	        if($("#csgst").val()==""){
	                    sgst=parseFloat(0);
	                }

                if (PaymentAcknowledgementForm.cpayMode.value == "C" )
                    {
                        document.getElementById("cnetAmt").value = Math.round(parseFloat(parseFloat(amtToBPaid) + parseFloat(cgst) + parseFloat(sgst)).toFixed(2));
                    }
                else{
                    document.getElementById("cnetAmt").value = parseFloat(parseFloat(amtToBPaid) + parseFloat(cgst) + parseFloat(sgst)).toFixed(2);
                }
            }

            function calcAmt() {       
                var amtToBPaid = parseFloat($("#vtobepaid").val());
                var cgstv = parseFloat($("#cgstv").val());
                var sgstv = parseFloat($("#sgstv").val());
                var disAmt = parseFloat($('#disAmt').val());
                var gst = 0;
                var cgst = 0;
                var sgst = 0;
                var net = parseFloat(0);
                if($("#vtobepaid").val()==""){
                    amtToBPaid=parseFloat(0);
                }
                if($("#cgstv").val()==""){
                    cgstv=parseFloat(0);
                }
                if($("#sgstv").val()==""){
                    sgstv=parseFloat(0);
                }
                if($("#disAmt").val()==""){
                    disAmt=parseFloat(0);
                }

                sgst = parseFloat(amtToBPaid * ((sgstv)/100)).toFixed(2);
                cgst = parseFloat(amtToBPaid * ((cgstv)/100)).toFixed(2);
                if(document.getElementById("vpayMode").value == 'G' || document.getElementById("vpayMode").value == 'T')
                    net = parseFloat(parseFloat(amtToBPaid) + parseFloat(cgst) + parseFloat(sgst) - disAmt).toFixed(2);
                else
                    net = Math.round(parseFloat(amtToBPaid) + parseFloat(cgst) + parseFloat(sgst) - disAmt);
                //net = amtToBPaid - Math.round((((amtToBPaid / (cgstv+100)) * cgstv) + ((amtToBPaid / (sgstv+100)) * sgstv))) ;
                document.getElementById("vsgst").value = sgst;
                document.getElementById("vcgst").value = cgst;
                document.getElementById("vnetAmt").value = net;

            }

            function calcAmt2() {
                var amtToBPaid = parseFloat($("#ctobepaid").val());
                var cgstc = parseFloat($("#cgstc").val());
                var sgstc = parseFloat($("#sgstc").val());
                var gst = 0;
                var sgst = 0;
                var cgst = 0;
                var net = parseFloat(0);
                if($("#ctobepaid").val()==""){
                    amtToBPaid=parseFloat(0);
                }
                if($("#cgstc").val()==""){
                    cgstc=parseFloat(0);
                }
                if($("#sgstc").val()==""){
                    sgstc=parseFloat(0);
                }
                sgst = parseFloat(amtToBPaid * ((sgstc)/100)).toFixed(2);
                cgst = parseFloat(amtToBPaid * ((cgstc)/100)).toFixed(2);                
               // sgst = parseFloat(((amtToBPaid / parseFloat((sgstc+100))) * parseFloat(sgstc))).toFixed(2);
               // cgst = parseFloat(((amtToBPaid / parseFloat((cgstc+100))) * parseFloat(cgstc))).toFixed(2);
                document.getElementById("ccgst").value = cgst;
                document.getElementById("csgst").value = sgst;
                if (PaymentAcknowledgementForm.cpayMode.value == "C" )
                    {
                        document.getElementById("cnetAmt").value = Math.round(parseFloat(parseFloat(amtToBPaid) + parseFloat(cgst) + parseFloat(sgst)).toFixed(2));
                    }
                else{
                    document.getElementById("cnetAmt").value = parseFloat(parseFloat(amtToBPaid) + parseFloat(cgst) + parseFloat(sgst)).toFixed(2);
                }
                $('#btnReset').click();
            }
            
            function calcAmtForDiscount() {                    
                var amtToBPaid = parseFloat($("#vtobepaid").val());
                var cgstv = parseFloat($("#vcgst").val());
                var sgstv = parseFloat($("#vsgst").val());
                var disAmt = parseFloat($('#disAmt').val());
                
                if(document.getElementById("vpayMode").value == 'G' || document.getElementById("vpayMode").value == 'T')
                    net = parseFloat(parseFloat(amtToBPaid) + parseFloat(cgstv) + parseFloat(sgstv) - disAmt).toFixed(2);
                else
                    net = Math.round(parseFloat(amtToBPaid) + parseFloat(cgstv) + parseFloat(sgstv) - disAmt);
                //net = amtToBPaid - Math.round((((amtToBPaid / (cgstv+100)) * cgstv) + ((amtToBPaid / (sgstv+100)) * sgstv))) ;
                // document.getElementById("vsgst").value = sgst;
                // document.getElementById("vcgst").value = cgst;
                document.getElementById("vnetAmt").value = net;

            }

            $(document).ready(function () {
                $('select#vpayMode').change(function () {
                    var shouldEnable = $(this).val();
                    $("#btnReset" ).click();
                    $('#vtrfAcc').val('');
                    calcAmt();
                    switch(shouldEnable)
                    {
                        case 'C':
                            $('#vtransferAccount').hide();
                            break;
                        case 'T':
                            $('#vtransferAccount').show(500);
                            break;
                        case 'G':
                            $('#vtransferAccount').show(500);
                            break;
                        default:
                            $('#vtransferAccount').hide();
                    }
                })
                $('select#cpayMode').change(function () {
                    var shouldEnable = $(this).val();
                    $("#btnReset" ).click();
                    $('#ctrfAcc').val('');
                    calcAmt2();
                    switch(shouldEnable)
                    {
                        case 'C':
                            $('#ctransferAccount').hide();
                            break;
                        case 'T':
                            $('#ctransferAccount').show(500);
                            $('#ctrfAcc').prop('readonly', true);
                            break;
                        case 'G':
                            $('#ctransferAccount').show(500);
                            $('#ctrfAcc').prop('readonly', false);
                            break;
                        default:
                            $('#ctransferAccount').hide();
                    }
                })
            });

            $(function() {
            
            $("#vnetAmt").keypress(function() {
                if($('select#vpayMode').val()!="C"){
                    //$("#myform").hide();
                 }else if($('#status').val() == "C" && $('#vpayMode').val() == "C"){
                        alert("Cash Drawer isn't opened yet!");
                        event.preventDefault();
                    }
                 else if($('#vpayMode').val() == "C"){
                        $("#myform").show(500);
                 }
            });
            /*$("#vnetAmt").click(function() {
                if($('select#vpayMode').val()!="C"){
                    //$("#myform").hide();
                 } else if($('#status').val() == "C" && $('#vpayMode').val() == "C"){
                        alert("Cash Drawer isn't opened yet!");
                    }
                 else if($('#vpayMode').val() == "C"){
                        $("#myform").show(500);
                 }
            });*/

            $("#cnetAmt").keypress(function() {
                if($('select#cpayMode').val()!="C"){
                    //$("#myform").hide();
                 }else if($('#status').val() == "C" && $('#cpayMode').val() == "C"){
                        alert("Cash Drawer isn't opened yet!");
                        event.preventDefault();
                    }
                 else if($('#cpayMode').val() == "C"){
                        $("#myform").show(500);
                 }
            });
            /*$("#cnetAmt").click(function() {
                if($('select#cpayMode').val()!="C"){
                    //$("#myform").hide();
                 }else if($('#status').val() == "C" && $('#cpayMode').val() == "C"){
                        alert("Cash Drawer isn't opened yet!");
                    }
                 else if($('#cpayMode').val() == "C"){
                        $("#myform").show(500);
                 }
            });*/
            });
            
            function searchSales(width, height,salesNo) {

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

            }


            $('body').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();}

            });
        </script>


        <%
             String displayFlag = "";
             Object display = request.getAttribute("displayFlag");
             if (display != null) {
                 displayFlag = display.toString();
             }
        %>
        <jsp:include page="MenuHead_TRADING.jsp" flush="true" />
        <br>
        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>
        <%          int count = 1;
             String error_msg = "";
             Object error = request.getAttribute("message");
             if (error != null) {
                 error_msg = error.toString();
             }
        %>


        <%   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">Payment Acknowledgement</legend>
            <form name="PaymentAcknowledgementForm" 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>

                <br>
                <center><lable style=" font-family: Berlin Sans FB; font-weight:  normal;">Operation Selection:</lable>
                    <select id="checkOption" onchange="checkop()" name="checkOption" >
                        <option value="" disabled selected style="display:none;" >--select--</option>
                        <option value="V" >Payment to Vendor</option>
                        <option value="S" >Payment from Customer</option>
                    </select>
                    <br>
                    <br>
                    <div id="ptv" style="display:none;">

                        <table>

                            <tr>
                                <td></td>
                                <td>Enter Purchase Reference Number<font color="red" >*</font>:</td>
                                <td><input type="text" name="orderno" id="orderno" value="" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/></td>
                                <td><input type="button" value="Search"  onclick="javascript:searchPurchase(520,280,document.PaymentAcknowledgementForm.orderno.value)"></td>
                                <td></td>
                            </tr>
                            <tr><td colspan="5"><hr></td></tr>
                            <tr>
                                <td>Due Date:</td>
                                <td><input type="text" name="vduedate" readonly id="vduedate" style="text-align:center;" /></td>
                                <td style="text-align:center">Total Amount:</td>
                                <td><input type="text" name="vtotal" readonly id="vtotal" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/></td>
                            </tr>
                            <tr>
                                <td>Amount Paid:</td>
                                <td><input type="text" name="amountpaid" readonly id="amountpaid" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                                <td style="text-align:center">Due Amount:</td>
                                <td><input type="text" name="amountdue" readonly id="amountdue" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                            </tr>
                            <tr>
                                <td>CGST Rate:</td>
                                <td><input type="text" name="cgstv" readonly id="cgstv" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                                <td style="text-align:center">SGST Rate:</td>
                                <td><input type="text" name="sgstv" readonly id="sgstv" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                            </tr> 
                            <tr><td colspan="5"><hr></td></tr>
                            <tr><td></td><td align="left">Payment Mode<font color="red" >*</font>:</td><td  colspan="2" align="left"><select id="vpayMode" name="vpayMode">
                                            <option value="" disabled selected style="display: none"> --Select-- </option>
                                            <option value="C">Cash/Cheque</option>
                                            <%--<option value="T">Transfer</option> --%>
                                            <option value="G">GL</option>
                                        </select></td></tr>
                            <tr id="vtransferAccount" style="display: none">
                                <td></td>
                                <td>Transfer Account Number<font color="red" >*</font>:</td>
                                <td><input type="text" name="vtrfAcc" id="vtrfAcc" value="0" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' />
                                <input type="button" value="Search" onclick="javascript:searchAccount(520,280,document.PaymentAcknowledgementForm.vtrfAcc.value)"/></td>

                            </tr>
                            <tr>
                                <td></td>
                                <td>Amount To Be Paid<font color="red" >*</font>:</td>
                                <td><input type="text" name="vtobepaid" id="vtobepaid" value="" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57' onkeyup="javascript:calcAmt();" /></td>

                            </tr>
                            <tr>
                                <td></td>
                                <td>SGST Amount<font color="red" >*</font>:</td>
                                <td><input type="text" name="vsgst" id="vsgst" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57' onkeyup="javascript:sumTax();" /></td>

                            </tr>
                            <tr>
                                <td></td>
                                <td>CGST Amount<font color="red" >*</font>:</td>
                                <td><input type="text" name="vcgst" id="vcgst" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57' onkeyup="javascript:sumTax();" /></td>

                            </tr>
                            <tr>
                                <td></td>
                                <td>Discount Amount<font color="red" >*</font>:</td>
                                <td><input type="text" name="disAmt" id="disAmt" value="0" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57' onkeyup="javascript:calcAmtForDiscount();"/></td>

                            </tr>

                            <tr>
                                <td></td>
                                <td>Net Amount:</td>
                                <td><input type="text" name="vnetAmt" id="vnetAmt" value="" readonly style="text-align:right;"/></td>
                                <td class="DenoCanBAdded"></td>
                            </tr>
                            <tr><br></tr>
                            <tr>
                                <td></td>
                                <td></td>
                                <td><br><input type="button" name="makepayment" id="makepayment" value="Make Payment" onclick="submitform(PaymentAcknowledgementForm)"/>
                                <input type="reset" value="Reset" name="reset" onclick="ShowParent();"/></td>
                            </tr>
                        </table>
                    </div>

                    <div id="pfc" style="display:none;">

                        <table>

                            <tr>
                                <td></td>
                                <td>Enter Sales Reference Number<font color="red" >*</font>: </td>
                                <td> <input type="text" name="salesrefno" id="salesrefno" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/></td>
                                <td><input type="button"  value="Search" onclick="javascript:searchSales(620, 280, document.PaymentAcknowledgementForm.salesrefno.value)" /></td>
                            </tr>
                            <tr><td colspan="5"><hr></td></tr>
                            <tr>
                                <td></td>
                                <td style="text-align:center">Customer Name: </td>
                                <td><input type="text" name="customerName" readonly id="customerName"  /></td>
<!--                                <td style="text-align:left">Product Name: </td>-->
                                <td><input type="hidden" readonly id="prod" name="prod" /></td>
                            </tr>
                            <tr>
                                <td>Total Due Amount: </td>
                                <td><input type="text" name="totalDue" readonly id="totalDue" style="text-align:right;" /></td>
                                <td style="text-align:left">Due Date: </td>
                                <td><input type="text" name="dueDt" readonly id="dueDt" style="text-align:center" /></td>
                            </tr>
                            <tr>
                                <td>Product Total Amount: </td>
                                <td><input type="text" name="prodTotalAmt" readonly id="prodTotalAmt" style="text-align:right;" /></td>
                                <td style="text-align:left">Product Total Due: </td>
                                <td><input type="text" name="prodTotalDue" readonly id="prodTotalDue" style="text-align:right;" /></td>
                            </tr>
                            <tr>
                                <td>CGST Rate: </td>
                                <td><input type="text" name="cgstc" readonly id="cgstc" style="text-align:right;" /></td>
                                <td style="text-align:left">SGST Rate: </td>
                                <td><input type="text" name="sgstc" readonly id="sgstc" style="text-align:right;" /></td>
                            </tr>
                            <tr><td colspan="5"><hr></td></tr>
                            <tr><td></td><td align="left">Payment Mode<font color="red" >*</font>:</td><td  colspan="2" align="left"><select id="cpayMode" name="cpayMode">
                                            <option value="" disabled selected style="display: none">--select---</option>
                                            <option value="C">Cash/Cheque</option>
                                            <%--<option value="T">Transfer</option> --%>
                                            <option value="G">GL</option>
                                        </select></td></tr>
                            <tr id="ctransferAccount" style="display: none">
                                <td></td>
                                <td>Transfer Account Number<font color="red" >*</font>:</td>
                                <td><input type="text" name="ctrfAcc" id="ctrfAcc" value="0" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' />
                                <input type="button" value="Search" onclick="javascript:searchAccount2(520,280,document.PaymentAcknowledgementForm.ctrfAcc.value,document.PaymentAcknowledgementForm.cpayMode.value,document.PaymentAcknowledgementForm.cust_id.value)"/></td>

                            </tr>
                            <tr>
                                <td></td>
                                <td>Amount To Be Paid: <font color="red" >*</font>:</td>
                                <td><input type="text" name="ctobepaid" id="ctobepaid" value="" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' onkeyup="javascript:calcAmt2();"/></td>

                            </tr>
                            <tr>
                                <td></td>
                                <td>SGST Amount<font color="red" >*</font>: </td>
                                <td><input type="text" name="csgst" id="csgst" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57' onkeyup="javascript:sumTax2();" /></td>

                            </tr>
                            <tr>
                                <td></td>
                                <td>CGST Amount<font color="red" >*</font>: </td>
                                <td><input type="text" name="ccgst" id="ccgst" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57' onkeyup="javascript:sumTax2();" /></td>

                            </tr>
                            <tr>
                                <td></td>
                                <td>Net Amount: </td>
                                <td><input type="text" name="cnetAmt" id="cnetAmt" readonly style="text-align:right;" /></td>
                                <td class="DenoCanBAdded"></td>
                            </tr>
                            <tr><br></tr>
                            <tr>
                                <td></td>
                                <td></td>
                                <td><br><input type="button" name="receivepayment" id="receivepayment" value="Make Payment" onclick="updateform(PaymentAcknowledgementForm)"/>
                                <input type="reset" value="Reset" name="reset" onclick="ShowParent();"/></td>
                            </tr>
                        </table><br><br>

                    </div>
                    <input type="hidden" name="handle_id" id="handle_id" value="" />
                    <input type="hidden" name="prod_id" id="prod_id" value="" />
                    <input type="hidden" name="cust_id" id="cust_id" value="" />
                    <input type="hidden" value="<%=status%>" name="status" id="status" />

                </center>
            </form>

        </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);
            $('#twohundredAvail').val(thirtinth);
            $('#resTXNAmt').val('0');

            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(second)< 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 sdueamt = $('#prodTotalDue').val();
            var cAmt = $('#cnetAmt').val();
            var vtobepaid = $('#vtobepaid').val();
            var vdueamt = $('#amountdue').val();
            var chkOp  = document.getElementById("checkOption").value;
            var flag = 0;
            if(chkOp == "S")//credit
            {
                if(Number(amount) <= 0){
                    alert("Resultant amount cannot be lesser than or equal to zero when payment is received from customer");
                    flag = 1;
                }
                else if(Math.abs(Number(amount)) != Math.abs(cAmt)){
                    alert("Please fill denominations for Rs. "+document.getElementById("ctobepaid").value);
                    flag = 1;
                }
                /*else if(Math.abs(Number(amount)) > Math.abs(sdueamt)){
                    alert("Total amount cannot be more than the product due amount");
                    flag = 1;
                }*/

            }
            else if(chkOp == "V")//debit
            {
                if(Number(amount) >= 0){
                    alert("Resultant amount can not be greater than or equal to zero when payment is given to vendor");
                    flag = 1;
                }
                else if(Math.abs(Number(vtobepaid)) > Math.abs(vdueamt)){
                    alert("Total amount cannot be more than the due amount");
                    flag = 1;
                }

                if(parseInt(flag) == 0){
                    document.getElementById("vnetAmt").value=Math.abs($('#resTXNAmt').val());
                }
            }

            if(parseInt(flag) == 0){

                $("#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) {
                
            }
%>
