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

<%@page import="DataEntryBean.TradingSaleRegisterBean"%>
<%@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.pdsStockRegisterBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="LoginDb.DbHandler"%>
<% try {
%>

<html>

    <head>
        <title>Sales 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();
            }

            function submitform(tradingsaleregister)

            {
                if (checkDiv(tradingsaleregister))
                {
                    document.forms[0].handle_id.value = "display";
                    document.forms[0].action = '/PacsApplication/TradingSaleRegisterServlet';
                    document.forms[0].submit();
                }
            }

            function checkDiv(tradingsaleregister)
            {
                var commoditytype = document.getElementById("commoditytype").value;
                var commoditysubtype = document.getElementById("commoditysubtype").value;
                if (commoditytype == "" )
                {
                    alert("Please enter Commodity Type.");
                    document.forms[0].commoditytype.focus();
                    return false;
                }
                if (commoditysubtype == "" )
                {
                    alert("Please enter Commodity Sub-Type.");
                    document.forms[0].commoditysubtype.focus();
                    return false;
                }

                var startDate = $('#fromdate').val();
	                var endDate = $('#todate').val();
	                if(startDate != "" && endDate != "") {
	                    var adata = startDate.split('/');
	                    var dd = parseInt(adata[0],10);
	                    var mm = parseInt(adata[1],10);
	                    var yyyy = parseInt(adata[2],10);
	                    var from_date = new Date(yyyy,mm-1,dd);

	                    adata = endDate.split('/');
	                    var dd = parseInt(adata[0],10);
	                    var mm = parseInt(adata[1],10);
	                    var yyyy = parseInt(adata[2],10);
	                    var to_date = new Date(yyyy,mm-1,dd);

	                    if(Date.parse(from_date) > Date.parse(to_date)){
	                        alert("From Date cannot be greater than To Date");
	                        return false;
	                    }
                        }

                <%--if ( document.getElementById("fromdate").value =="" )
                {
                    alert("Please enter From Date.");
                    document.forms[0].fromdate.focus();
                    return false;
                }
                if ( document.forms[0].todate.value =="" )
                {
                    alert("Please enter To Date.");
                    document.forms[0].todate.focus();
                    return false;
                }--%>
                if ( document.forms[0].customername.value =="" )
                {
                    alert("Please enter Customer Name.");
                    document.forms[0].customername.focus();
                    return false;
                }
                return true;
            }

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

            }

            function searchCustomer(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 = "saleregister.jsp";
                var lovKey = "CustomerDetails";

                popWin = open('/PacsApplication/CommonSearchInformationTradingLOV.jsp?customername=' + name + '&screenName=' + screenName + '&lovKey=' + lovKey, 'CustomerDetails', attr);
                popWin.focus();

            }

            function Total(i) {

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

                document.getElementById("total" + i).value = priceDetails * quantityDetails;

            }
            
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });
            
        </script>
    </head>
    <body>

        <%          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 alTradingSaleRegisterBeanApendObj = request.getAttribute("alTradingSaleRegisterBeanApend");
             ArrayList<TradingSaleRegisterBean> alTradingSaleRegisterBeanApend = new ArrayList<TradingSaleRegisterBean>();
             if (alTradingSaleRegisterBeanApendObj != null) {
                 alTradingSaleRegisterBeanApend = (ArrayList<TradingSaleRegisterBean>) request.getAttribute("alTradingSaleRegisterBeanApend");
             }
        %>

        <%
             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">
                Sales Register
            </legend>

            <form id="tradingsaleregister" name="tradingsaleregister" method="post" action="">

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

                                <td>Commodity Type<font color="red" >*</font>:</td>
                                <td> <input type="text" id="commoditytype" name="commoditytype" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' ></td>
                                <td>Commodity Sub-Type<font color="red" >*</font>:</td>
                                <td> <input type="text" id="commoditysubtype" name="commoditysubtype" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' ></td>
                                <td><input type="button" name="productSearch" id="productSearch" value="Search" onclick="javascript:searchProduct(220, 180, document.tradingsaleregister.commoditytype.value, document.tradingsaleregister.commoditysubtype.value)"/></td>

                            </tr>
                        </tbody>
                    </table>
                    <br>
                    <center><table>
                            <tr>
                                <td style="text-align:right">From Date<font color="red" >*</font>:</td>
                                <td> <input id="fromdate" type="text" name="fromdate" readonly="true" style="text-align:center;"/>&nbsp;<a href="#" onclick="return getCalendar(getElementById('fromdate'));"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" border="0" width="25" height="20" /></a></td>
                            </tr> 
                            <tr>
                                <td style="text-align:right">To Date<font color="red" >*</font>:</td>
                                <td><input id="todate" type="text" name="todate" readonly="true" style="text-align:center;" />&nbsp;<a href="#" onclick="return getCalendar(getElementById('todate'));"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" border="0" width="25" height="20" /></a></td>
                            </tr>
                            <tr>
                                <td>Customer Name<font color="red" >*</font>: </td>
                                <td> <input type="text" id="customername" name="customername"></td>
                                <td><input type="button" name="customerSearch" id="customerSearch" value="Search" onclick="javascript:searchCustomer(220, 180, document.tradingsaleregister.customername.value)"/></td>
                            </tr></table>
                    </center>
                </center>
                <br>
                <center>

                    <input type="button" value="Submit" onclick="javascript:submitform(tradingsaleregister);"/>
                    <input type="button" value="Reset" onclick="ShowParent();" />
                </center>
                <br>

                <br>
                <%if (displayFlag.equalsIgnoreCase("Y")) {%>
                <center>
                    <div id="amend" style="overflow:scroll; width: 900px;">

                        <table id="order-listAmend"  border="1" width="auto" cellspacing="1" cellpadding="1" style="text-align: center ; font-size: 10px;">
                            <thead  class="CSSTableGenerator" >
                                <tr>

                                    <td style="text-align:center; "> <b>Sales Reference ID</b>  </td>
                                    <td style="text-align:center;"> <b>Customer Name</b>  </td>
                                    <td style="text-align:center;"> <b>Commodity type</b>  </td>
                                    <td style="text-align:center;"> <b>Commodity sub-type</b>  </td>
                                    <td style="text-align:center;"> <b>Sale Date</b>  </td>
                                    <td style="text-align:center;"> <b>Stock ID</b>  </td>
                                    <td style="text-align:center;"> <b>Quantity</b>  </td>
                                    <td style="text-align:center;"> <b>Price</b>  </td>
                                    <td style="text-align:center;"> <b>Total</b>  </td>

                                </tr>
                            </thead>
                            <tbody style="background-color: white; font-size: 15px">
                                <%
                                    TradingSaleRegisterBean oTradingSaleRegisterBeanApend = new TradingSaleRegisterBean();

                                    for (int i = 0; i < alTradingSaleRegisterBeanApend.size(); i++) {
                                        oTradingSaleRegisterBeanApend = alTradingSaleRegisterBeanApend.get(i);
                                %>
                                <tr>

                                    <td style="text-align:center; "><input  style="text-align:center; " type="text" value="<%=oTradingSaleRegisterBeanApend.getSalesref_id()%>" readonly="true"></td>
                                    <td style="text-align:center; width: 15px"><input  style="text-align:center; " type="text" value="<%=oTradingSaleRegisterBeanApend.getMemberName()%>" readonly="true"></td>
                                    <td style="text-align:center; width: 15px"><input  style="text-align:center; " type="text" value="<%=oTradingSaleRegisterBeanApend.getCommoditytype()%>" readonly="true"></td>
                                    <td style="text-align:center; width: 15px"><input  style="text-align:center; " type="text" value="<%=oTradingSaleRegisterBeanApend.getCommoditysubtype()%>" readonly="true"></td>
                                    <td style="text-align:center; width: 15px"><input  style="text-align:center; " type="text" value="<%=oTradingSaleRegisterBeanApend.getSaleDate()%>" readonly="true"></td>
                                    <td style="text-align:center; width: 15px"><input  style="text-align:center; " type="text" value="<%=oTradingSaleRegisterBeanApend.getStock_id()%>" readonly="true"></td>
                                    <td style="text-align:center; width: 15px"><input  style="text-align:center; " size="14" type="text" value="<%=oTradingSaleRegisterBeanApend.getQuantity()%>" readonly="true"></td>
                                    <td style="text-align:center; width: 15px"><input  style="text-align:center; " size="14" type="text" value="<%=oTradingSaleRegisterBeanApend.getPrice()%>" readonly="true"></td>
                                    <td style="text-align:center; width: 15px"><input  style="text-align:center; " size="14" type="text" value="<%=oTradingSaleRegisterBeanApend.getTotal()%>" readonly="true"></td>

                                </tr>
                                <%}%>
                            </tbody>
                        </table>
                </div>
                             </center>
                <%}%>

                <input type="hidden" name="handle_id" value="" />
                <input type="hidden" id="product_id" name="product_id" value="">
                <input type="hidden" id="customer_id" name="customer_id" value="">

            </form>
            <script>

                function ShowCalender(i) {

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

                function popup_product(width, height, itemCode, itemName)
                {

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

                }

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

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