<%--
    Document   : TradingStockRegister
    Created on : May 5, 2016, 12:31:09 PM
    Author     : 590685
--%>

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

<html>

    <head>
        <title>Trading Stock Register</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="${pageContext.request.contextPath}/js/Calendar.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/TableCSSCode.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="shortcut icon" href="${pageContext.request.contextPath}/img/favicon.ico?pacs=<%=((new java.util.Date()).getTime())%>" type="image/x-icon" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/styles.css?pacs=<%=((new java.util.Date()).getTime())%>"/>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/ButtonAndText.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/info.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-ui-1.10.4.custom/development-bundle/jquery-1.10.2.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/chromejs/chrome.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/js/iFrame_killer.js"></script>

        <script>

            function noBack()
            {
                window.history.forward();
                callSell(trandingstockregister);
                callSell2(trandingstockregister);
            }
            function submitform(trandingstockregister)
            {
                if (checkDiv(trandingstockregister))
                {
                    document.forms[0].handle_id.value = "Enterstock";
                    document.forms[0].action = '/PacsApplication/TradingStockRegisterServlet';
                    document.forms[0].submit();
                }
            }
            function getDetails(trandingstockregister)
            {
                if( document.forms[0].commoditytypeSearch.value == ""  )
                {
                    alert("Please enter commodity type.");
                    document.forms[0].commoditytypeSearch.focus();
                    return false;
                }
                if( document.forms[0].commoditySubtypeSearch.value == ""  )
                {
                    alert("Please enter commodity sub-type.");
                    document.forms[0].commoditySubtypeSearch.focus();
                    return false;
                }
                callSell(trandingstockregister);
                document.forms[0].handle_id.value = "Viewstock";
                document.forms[0].action = '/PacsApplication/TradingStockRegisterServlet';
                document.forms[0].submit();

            }
            function PrintBarcode(ind){

                document.forms[0].handle_id.value = "PrintBarCode";
                document.forms[0].indicator.value = ind;
                document.forms[0].action = '/PacsApplication/TradingStockRegisterServlet';
                document.forms[0].submit();
            }

            function searchProduct(width, height, commoditytype,Subtype) {

                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 = "tradingstockregister.jsp";
                var lovKey = "stockDetails"
                popWin = open('/PacsApplication/CommonSearchInformationTradingLOV.jsp?commoditytype=' + commoditytype + '&Subtype='+Subtype+ '&screenName=' + screenName + '&lovKey=' + lovKey, 'prodDetails', attr);
                popWin.focus();

            }

            function searchGodown(width, height, i) {

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

            }

            function SearchPurchaseOrder(width, height,i)
            {
                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 = "tradingstockregister.jsp";
                var lovKey = "purchaseDetails"
                popWin = open('/PacsApplication/CommonSearchInformationTradingLOV.jsp?&screenName=' + screenName + '&lovKey=' + lovKey+  '&textIndex=' + i,  'purchaseDetails', attr);
                popWin.focus();
            }

            function search_vendor(width, height,name) {

                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 = "raisePurchaseOrder.jsp";
                var lovKey = "vendorDetails"
                popWin = open('/PacsApplication/CommonSearchInformationTradingLOV.jsp?vendorname=' + name + '&screenName=' + screenName + '&lovKey=' + lovKey, 'vendorDetails', attr);
                popWin.focus();
            }

            function checkDiv(trandingstockregister)
            {
                var counter = document.forms[0].rowCounter.value; 
                
                for (var i = 1; i <= counter; i++) {
                    try{
                        var purchase_id = document.getElementById("purchase_id" + i).value;
                        var price_unit = document.getElementById("price_unit" + i).value;
                        var quantity = document.getElementById("quantity" + i).value;
                        var pfm = document.getElementById("pfm" + i).value;
                        var pfnm = document.getElementById("pfnm" + i).value;
                        var selectperish = document.getElementById("selectperish" + i).value;
                        var stkexpiryDate = document.getElementById("stkexpiryDate" + i).value;
                        var stockdesc = document.getElementById("stockdesc" + i).value;
                        var godown_id = document.getElementById("godown_id" + i).value;                                                
                        
                        if (purchase_id == "" || price_unit == "" || quantity == "" || pfm == "" || pfnm == ""|| selectperish == "" || stockdesc == "" || godown_id == "" ) 
                        {
                            alert("Fill the required fields.");
                            return false;
                        }
                        if (selectperish=="Y" && stkexpiryDate=="")
                        {
                            alert("Please enter Stock Expiry Date.");
                            return false;
                        }                            
                    }
                    catch(e){}
                    document.getElementById("price_unit" + i).value = parseFloat(price_unit).toFixed(2);
                }                
                return true;
            }
            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 checkop()
            {
                if (document.getElementById("checkOption").value == "enterStock")
                {

                    document.getElementById('enterStock').style.display = 'block';
                    document.getElementById('checkStock').style.display = 'none';
                    document.getElementById('displayDiv').style.display = 'none';
                }
                if (document.getElementById("checkOption").value == "checkStock")
                {
                    document.getElementById('enterStock').style.display = 'none';
                    document.getElementById('checkStock').style.display = 'block';
                    document.getElementById('displayDiv').style.display = 'none';
                }
            }
            function Total(i) {

                var priceDetails = document.getElementById("price" + i).value;
                var quantityDetails = document.getElementById("quantity" + i).value;

                document.getElementById("total" + i).value = priceDetails * quantityDetails;
            }
            function callSell(trandingstockregister) 
            {
                var counter = document.forms[0].rowCounter.value;
                
                for (var i = 1; i <= counter; i++) {    
                    var ppu1 = document.getElementById("price_unit" + i).value;
                    var pfM1 = document.getElementById("pfm" + i).value;
                    var pfNm1 = document.getElementById("pfnm" + i).value;
                    
                    var ppu = parseFloat(ppu1);
                    var pfM = parseFloat(pfM1);
                    var pfNm = parseFloat(pfNm1);
                    
                    var sellM = (((pfM*ppu)/100)+ppu);
                    var sellNm = (((pfNm*ppu)/100)+ppu);

                    document.getElementById("sellPriceM" + i).value = sellM.toFixed(2);
                    document.getElementById("sellPriceNm" + i).value = sellNm.toFixed(2);                    
                }    
            }
            function callSell2(trandingstockregister) 
            {
                var counter = document.forms[0].rowCounter2.value;
                
                for (var i = 1; i <= counter; i++) {    
                    var ppu1 = document.getElementById("price_unit2" + i).value;
                    var pfM1 = document.getElementById("pfm2" + i).value;
                    var pfNm1 = document.getElementById("pfnm2" + i).value;

                    var ppu = parseFloat(ppu1);
                    var pfM = parseFloat(pfM1);
                    var pfNm = parseFloat(pfNm1);
                    
                    var sellM = (((pfM*ppu)/100)+ppu);
                    var sellNm = (((pfNm*ppu)/100)+ppu);

                    document.getElementById("sellPriceM2" + i).value = sellM.toFixed(2);
                    document.getElementById("sellPriceNm2" + i).value = sellNm.toFixed(2);                    
                }    
            }
            function checkDate(i) 
            {
                var flag = document.getElementById("selectperish" + i).value;
                if(flag=="N"){
                    document.getElementById("stkexpiryDate" + i).value = "";
                    document.getElementById("imgr").disabled = true;
                }
                if(flag=="Y"){
                    document.getElementById("imgr").disabled = false;
                }
            }
            
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });

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

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

        <%
                    Object oTrandinStockRegisterBeanObj = request.getAttribute("oTrandinStockRegisterBean");
                    Object alTrandinStockRegisterBeanAppendObj = request.getAttribute("arrTrandinStockRegisterBean");

                    TrandinStockRegisterBean oTrandinStockRegisterBeanApend = new TrandinStockRegisterBean();
                    if (oTrandinStockRegisterBeanObj != null) {
                        oTrandinStockRegisterBeanApend = (TrandinStockRegisterBean) request.getAttribute("oTrandinStockRegisterBean");
                    }

                    ArrayList<TrandinStockRegisterBean> alTrandinStockRegisterBeanAppend = new ArrayList<TrandinStockRegisterBean>();
                    if (alTrandinStockRegisterBeanAppendObj != null) {
                        alTrandinStockRegisterBeanAppend = (ArrayList<TrandinStockRegisterBean>) request.getAttribute("arrTrandinStockRegisterBean");
                    }
        %>

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

        <jsp:include page="MenuHead_TRADING.jsp" flush="true" />
        <br>
        <fieldset style="border-color: black;  background-image: url('/PacsApplication/img/download.jpg'); border-width: 3px">

            <legend style="padding: 8px; border-radius: 20px; background-color: #006600; color: white">
                Trading Stock Register
            </legend>

            <form id="trandingstockregister" name="trandingstockregister" method="post" action="TradingStockRegisterServlet">

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

                <center><label style=" font-family: Berlin Sans FB; font-weight:  normal;">Operation Selection:</label>
                    <select id="checkOption" onchange="checkop()" name="checkOption" >
                        <option value="" disabled selected style="display:none;" >--Select--</option>
                        <option value="enterStock" >Enter Stock</option>
                        <option value="checkStock" >View Stock</option>
                    </select>
                </center>
                <br>
                <div id="enterStock" style="display:none;" >
                    <center>
                        <div style="overflow:scroll; width: 1300px">
                        <table class="NumbersOnly" id="order-list" style="margin-left: 20px;"  border="2" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px; width: 100%;">
                            <thead  class="CSSTableGenerator" >
                                <tr>
                                    <td></td>
                                    <td colspan="2">Purchase Ref No</td>
                                    <td>Commodity type</td>
                                    <td>Commodity Subtype</td>
                                    <td>Price/Unit</td>
                                    <td>Quantity</td>
                                    <td>Profit Factor(Member)</td>
                                    <td>Sell Price(Member)</td>
                                    <td>Profit Factor(Non-Member)</td>
                                    <td>Sell Price(Non-Member)</td>
                                    <td>Perishable(Y/N)</td>
                                    <td width="10px">Stock Expiry Date</td>
                                    <td>Stock Description</td>
                                    <td colspan="2">Godown Name</td>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td><input type="checkbox" name="chckbox<%=count%>" id="chckbox<%=count%>" onclick="return checkboxTrue(<%=count%>)"/></td>
                                    <td><input size="8" type="text" readonly name="purchaserefno<%=count%>" id="purchaserefno<%=count%>"/></td>
                                    <td><input size="8" type="button" value="Search"  onclick="javascript:SearchPurchaseOrder(720, 380, <%=count%>)" /></td>
                                    <td><input size="11" type="text" readonly name="commoditytype<%=count%>" id="commoditytype<%=count%>" /></td>
                                    <td><input size="14" type="text" readonly name="commoditysubtype<%=count%>" id="commoditysubtype<%=count%>" /></td>
                                    <td><input size="8" type="text" readonly name="price_unit<%=count%>" id="price_unit<%=count%>" value="0" onmouseover="callSell(trandingstockregister)" onkeyup="callSell(trandingstockregister)"/></td>
                                    <td><input size="8" type="text" readonly name="quantity<%=count%>" id="quantity<%=count%>" /></td>
                                    <td><input size="12" type="text"  name="pfm<%=count%>" class="numberson" id="pfm<%=count%>" value="0" onmouseover="callSell(trandingstockregister)" onkeyup="callSell(trandingstockregister)" /></td>
                                    <td><input readonly size="11" type="text" name="sellPriceM<%=count%>" id="sellPriceM<%=count%>" /></td>
                                    <td><input size="8" type="text"  name="pfnm<%=count%>"  class="numberson" id="pfnm<%=count%>" value="0" onmouseover="callSell(trandingstockregister)" onkeyup="callSell(trandingstockregister)" /></td>
                                    <td><input readonly size="11" type="text" name="sellPriceNm<%=count%>" id="sellPriceNm<%=count%>" /></td>
                                    <td><select style="width:100%"  id="selectperish<%=count%>" name="selectperish<%=count%>" onchange="checkDate(<%=count%>)">
                                            <option value="N">No</option><option value="Y">Yes</option></select></td>

                                    <td><input size="10" readonly style="text-align:center;" disabled="true" id="stkexpiryDate<%=count%>" type="text" name="stkexpiryDate<%=count%>" /><a href="#" onclick="return ShowCalender(<%=count%>);"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" border="0" width="15" height="15" /></a></td>

                                    <td><input size="10" type="text" name="stockdesc<%=count%>" id="stockdesc<%=count%>" /></td>
                                    <td><input size="8" type="text" readonly name="godownname<%=count%>" id="godownname<%=count%>"/></td>
                                    <td><input size="8" type="button" value="Search"  onclick="javascript:searchGodown(220, 180, <%=count%>)" /></td>
                                    <td style="display:none"><input type="hidden" name="product_id<%=count%>" id="product_id<%=count%>"/></td>
                                    <td style="display:none"><input type="hidden" name="godown_id<%=count%>" id="godown_id<%=count%>"></td>
                                    <td style="display:none"><input type="hidden" name="purchase_id<%=count%>" id="purchase_id<%=count%>"></td>

                                </tr>
                            </tbody>
                        </table>
                        </div>            
                        <br/><br/>
                        <center>
                            <input type="button" id="addRow" value="Add Row"/>
                            <input type="button" id="deleteRow" value="Delete Row"/>
                            <input type="button" value="Submit" onclick="javascript:submitform(trandingstockregister)"/>
                            <input type="button" value="Reset" onclick="ShowParent();" />

                        </center>
                        <input type="hidden" name="rowCounter" id="rowCounter" value="<%=count%>">
                        <input type="hidden" name="chkboxCounter" id="chkboxCounter" value="0">
                    </center>
                </div>
                <br>
                <div id="checkStock" style="display: none;">

                    <center>
                        <table>
                            <tr>
                                <td>Enter commodity type:</td>
                                <td><input type="text" name="commoditytypeSearch" id="commoditytypeSearch" onkeypress="return numbersonly(event)" style="text-align:right;" /></td><td></td><td></td><td></td>
                                <td>Enter commodity sub-type:</td>
                                <td><input type="text" name="commoditySubtypeSearch" id="commoditySubtypeSearch" onkeypress="return numbersonly(event)" style="text-align:right;"/></td>
                                <td><input type="button"  value="Search" onclick="javascript:searchProduct(220, 180, document.trandingstockregister.commoditytypeSearch.value, document.trandingstockregister.commoditySubtypeSearch.value)" /></td>
                                <td><input type="button"  value="Submit" onclick="javascript:getDetails(trandingstockregister)" /></td>
                                <td><input type="button" value="Reset" onclick="ShowParent();" /></td>
                            </tr>
                        </table><br>
<!--                        <table>
                            <tr><td>OR</td></tr>
                        </table><br>

                        <table>  <tr>
                                <td>Enter Vendor Name:</td>
                                <td><input type="text" name="vendorname"  id="vendorname" /></td>
                                <td><input type="button"  value="Search" onclick="javascript:search_vendor(220, 180, document.trandingstockregister.vendorname.value)" /></td>
                                <td><input type="button"  value="Submit" onclick="javascript:getDetails(trandingstockregister)" /></td>
                            </tr>
                        </table>-->
                        <br>
                    </center>
                </div>
                
                <%if (displayFlag.equalsIgnoreCase("Y")) {%>
                <div id="displayDiv" >
                    <center>
                    <div style="overflow:scroll; width: 1300px">    
                    <table class="NumbersOnly "id="order-listAmend" style="overflow-y: scroll">
                        <thead  class="CSSTableGenerator" >
                            <tr>
                                <td style="text-align:center;">Commodity Type</td>
                                <td style="text-align:center;">Commodity Sub-Type</td>
                                <td style="text-align:center;">Vendor Name</td>
                                <td style="text-align:center;">Stock Entry Date</td>
                                <td style="text-align:center;">Perishable(Y/N)</td>
                                <td style="text-align:center;">Stock Expiry Date</td>
                                <td style="text-align:center;">Price/Unit</td>
                                <td style="text-align:center;">Quantity(Base)</td>
                                <td style="text-align:center;">Quantity(Availed)</td>
                                <td style="text-align:center;">Quantity(Available)</td>
                                <td style="text-align:center;">Profit Factor(Non-Member)</td>
                                <td style="text-align:center;">Sell Price(Non-Member)</td>
                                <td style="text-align:center;">Profit Factor(Member)</td>
                                <td style="text-align:center;">Sell Price(Member)</td>
                                <td style="text-align:center;">Action</td>
                            </tr>
                        </thead>
                        <tbody style="background-color: white; font-size: 15px">
                            <%
                                oTrandinStockRegisterBeanApend = null;
                                oTrandinStockRegisterBeanApend = new TrandinStockRegisterBean();
                                count= 0;

                                for (int i = 0; i < alTrandinStockRegisterBeanAppend.size(); i++) {
                                    oTrandinStockRegisterBeanApend = alTrandinStockRegisterBeanAppend.get(i);
                                    count++;
                            %>
                            <tr>

                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getCommoditytype())%></td>
                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getCommoditysubtype())%></td>
                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getName())%></td>
                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getEntDate())%></td>
                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getSelectperish())%></td>
                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getStkexpiryDate())%></td>
                                <td><input readonly size="11" type="text" name="price_unit2<%=count%>" id="price_unit2<%=count%>" value="<%=blankNull(oTrandinStockRegisterBeanApend.getPrice_unit())%>" onkeyup="callSell2(trandingstockregister)"/></td>
<!--                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getPrice_unit())%></td>-->
                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getQuantity())%></td>
                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getQuantity_availed())%></td>
                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getQuantity_available())%></td>
                                <td><input size="11" type="text" name="pfnm2<%=count%>" id="pfnm2<%=count%>" value="<%=blankNull(oTrandinStockRegisterBeanApend.getPfnm())%>" onkeyup="callSell2(trandingstockregister)"/></td>
<!--                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getPfnm())%></td>-->
                                <td><input readonly size="11" type="text" name="sellPriceNm2<%=count%>" id="sellPriceNm2<%=count%>" /></td>
                                <td><input size="11" type="text" name="pfm2<%=count%>" id="pfm2<%=count%>" value="<%=blankNull(oTrandinStockRegisterBeanApend.getPfm())%>" onkeyup="callSell2(trandingstockregister)"/></td>
<!--                                <td style="text-align:center;"><%=blankNull(oTrandinStockRegisterBeanApend.getPfm())%></td>-->
                                <td><input readonly size="11" type="text" name="sellPriceM2<%=count%>" id="sellPriceM2<%=count%>" /></td>
                                <td ><input type="button" name="printB<%=count%>" id="printB<%=count%>" value="Print Barcode" onclick="PrintBarcode(<%=i%>)"></td>
                                <td display: none><input type="hidden" name="stock_id<%=count%>" id="stock_id<%=count%>" value="<%=blankNull(oTrandinStockRegisterBeanApend.getStock_id())%>"></td>
                            </tr>

                            <%}%></tbody>
                    </table>                    
                </div>
                    </center>    
                    <br>
                        <center>
                            <input type="button" value="Reset" onclick="ShowParent();" />
                    </center>    
                            <input type="hidden" name="indicator" id="indicator" value="">
                            <input type="hidden" name="rowCounter2" id="rowCounter2" value="<%=count%>">
                </div>
                <%}%>
                <input type="hidden" name="handle_id" value="" />
                <input type="hidden" name="vendor_id" id="vendor_id"/>
            </form>
            <script>

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

                    var counter = $("#rowCounter").val();
                    ++counter;
                    $('#order-list tr:last').after('<tr> <td align="center"><input type="checkbox" name="chckbox' + counter + '" id="chckbox' + counter + '" onclick="return checkboxTrue('+counter+')"/></td>\n\
                        <td><input size="8" type="text" id="purchaserefno' + counter + '" name="purchaserefno' + counter + '"/></td>\n\
                        <td><input size="8" type="button" value="Search"  onclick="javascript:SearchPurchaseOrder(720, 380,'+ counter +')" /></td>\n\\n\
                        <td><input size="11" type="text" id="commoditytype' + counter + '" name="commoditytype' + counter + '"/></td>\n\\n\
                        <td><input size="14" type="text" id="commoditysubtype' + counter + '" name="commoditysubtype' + counter + '"/></td>\n\
                        <td><input size="8" type="text" name="price_unit' + counter + '" id="price_unit' + counter + '" value="0" onkeyup="callSell(trandingstockregister)" /></td>\n\
                        <td><input size="8" type="text" id="quantity' + counter + '" name="quantity' + counter + '"/></td>\n\
                        <td><input size="12" type="text" class="numberson" id="pfm' + counter + '" name="pfm' + counter + '" value="0" onkeyup="callSell(trandingstockregister)" /></td>\n\
                        <td><input readonly size="12" type="text" id="sellPriceM' + counter + '" name="sellPriceM' + counter + '"/></td>\n\\n\
                        <td><input size="8" type="text" class="numberson" id="pfnm' + counter + '" name="pfnm' + counter + '" value="0" onkeyup="callSell(trandingstockregister)" /></td>\n\
                        <td><input readonly size="12" type="text" id="sellPriceNm' + counter + '" name="sellPriceNm' + counter + '"/></td>\n\\n\
                        <td><select style="width:100%" id="selectperish' + counter + '" name="selectperish' + counter + '" onchange="checkDate('+ counter +')"><option value="N">No</option><option value="Y">Yes</option></select></td>\n\
                        <td><input size="8" type="text" disabled="true" id="stkexpiryDate' + counter + '" name="stkexpiryDate' + counter + '"/><a href="#" onclick="return ShowCalender('+counter+' );"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" border="0" width="15" height="15" /></a></td>\n\
                        <td><input size="10" type="text" id="stockdesc' + counter + '" name="stockdesc' + counter + '"/></td>\n\
                        <td><input size="8" type="text" id="godownname' + counter + '" name="godownname' + counter + '"/></td>\n\
                        <td><input size="8" type="button" value="Search"  onclick="javascript:searchGodown(220, 180,'+ counter +')" /></td>\n\
                        <td style="display: none"><input type="hidden" name="product_id' + counter + '" id="product_id' + counter + '"/></td>\n\\n\
                        <td style="display: none"><input type="hidden" name="purchase_id' + counter + '" id="purchase_id' + counter + '"/></td>\n\
                        <td style="display: none"><input type="hidden" name="godown_id' + counter + '" id="godown_id' + counter + '"/></td>\n\
                        </tr>');
                    $("#rowCounter").val(counter);

                });

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

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

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

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

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

                    }
                });

                function checkboxTrue(i){

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

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

                    else{

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

                function ShowCalender(i) {

                    getCalendar(document.getElementById("stkexpiryDate" + i));
                }

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

            </script>
        </fieldset>
    </body>
     <script>

                $('table.NumbersOnly').on('keydown','.numberson', 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 == 37 || event.keyCode == 39 || event.keyCode == 46 || event.keyCode == 190 || event.keyCode == 110) {

        } else {
            event.preventDefault();
        }
        if($(this).val().indexOf('.') !== -1 && (event.keyCode == 190 || event.keyCode == 110))
        { event.preventDefault();}
    });
            </script>
</html>
<% 	} catch (Exception e) {
               
            }
%>
