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

<%@page import="DataEntryBean.pdsSalesRegisterHeaderBean"%>
<%@page import="DataEntryBean.pdsSalesRegisterDetailsBean"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>

<%@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(pdsSalesRegister)

            {
               
                if (checkDate(pdsSalesRegister)){

                    document.forms[0].action = '/PacsApplication/pdsSalesRegisterServlet';

                    document.forms[0].submit();
                    
                    
                }
            }

            function checkDate(pdsSalesRegister)
            {

                var toDate = document.getElementById("toDate").value;

                var fromDate = document.getElementById("fromDate").value;
                if ((toDate == "" && !(fromDate == ""))|| (fromDate == "" && !(toDate == ""))){

                    alert("Either fill both date fields or none");
                    return false;
                }
                return true;

            }
            function populateHeader(o)
            {

            }
           
            function SearchProductSubType(width, height,productTypeSearch,productSubTypeSearch)
            {

                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 = "pdsSalesRegister.jsp";
                var  lovKey="PdsProductSearch"
                popWin = open('/PacsApplication/CommonSearchInformationPdsLOV.jsp?screenName=' + screenName+'&lovKey='+lovKey+'&productTypeSearch='+productTypeSearch+'&productSubTypeSearch='+productSubTypeSearch, 'PdsProductSearch', attr);
                popWin.focus();

            }
            function popup_CIF(width, height, cifNumber,cifName) {
                // cifNumber=cifNumber+'';
                //  cifName=cifName+'';
                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 = "pdsSalesRegister.jsp";
                var  lovKey="";

                lovKey="memberDetails";

                popWin = open('/PacsApplication/CommonSearchInformationPdsLOV.jsp?cifNumber=' + cifNumber + '&cifName=' + cifName +'&screenName=' + screenName+'&lovKey='+lovKey, 'memberDetails', attr);
                popWin.focus();

            }

        </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 alpdsSalesRegisterDetailsBeanApendObj = request.getAttribute("alpdsSalesRegisterDetailsBeanApend");
             ArrayList<pdsSalesRegisterDetailsBean> alpdsSalesRegisterDetailsBeanApend = new ArrayList<pdsSalesRegisterDetailsBean>();
             if (alpdsSalesRegisterDetailsBeanApendObj != null) {
                 alpdsSalesRegisterDetailsBeanApend = (ArrayList<pdsSalesRegisterDetailsBean>) request.getAttribute("alpdsSalesRegisterDetailsBeanApend");
             }

             Object opdsSalesRegisterHeaderBeanObj = request.getAttribute("opdsSalesRegisterHeaderBean");
             pdsSalesRegisterHeaderBean opdsSalesRegisterHeaderBean = new pdsSalesRegisterHeaderBean();
             if (opdsSalesRegisterHeaderBeanObj != null) {
                 opdsSalesRegisterHeaderBean = (pdsSalesRegisterHeaderBean) request.getAttribute("opdsSalesRegisterHeaderBean");
             }

        %>

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

        <jsp:include page="MenuHead_PDS.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="pdsSalesRegister" name="pdsSalesRegister" method="post" action="">

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

                                <tr>
                                    <td></td> <td style="text-align: right;"><label style=" font-family: Berlin Sans FB; ">Product Type:</label></td><td><input type="text" name="productTypeSearch" readonly="readonly" id="productTypeSearch" value="<%=blankNull(opdsSalesRegisterHeaderBean.getProductTypeSearch())%>" /></td>
                                    <td></td><td><label style=" font-family: Berlin Sans FB; ">Product Sub Type:</label></td><td><input type="text" readonly="readonly" name="productSubTypeSearch" id="productSubTypeSearch" value="<%=blankNull(opdsSalesRegisterHeaderBean.getProductSubTypeSearch())%>" /><input type="hidden" name="productIdSearch" id="productIdSearch" value="" /></td><td><input type="button" value="Search" id="search" name="search" onclick="SearchProductSubType(220,180,document.getElementById('productTypeSearch').value,document.getElementById('productSubTypeSearch').value)" /></td>

                                </tr>
                                <tr>
                                    <td></td><td style="text-align: right;"><label style=" font-family: Berlin Sans FB; ">Name:</label></td>
                                    <td> <input type="text" name="custNameSearch" readonly="readonly"  id="custNameSearch" value="<%=blankNull(opdsSalesRegisterHeaderBean.getCustNameSearch())%>"/></td>

                                    <td></td><td style="text-align: right;"><label style=" font-family: Berlin Sans FB; ">Card No:</label></td>
                                    <td><input type="text" name="cardNoSearch" readonly="readonly" id="cardNoSearch" value=""/><input type="hidden" name="cardNoPk" id="cardNoPk" value="<%=blankNull(opdsSalesRegisterHeaderBean.getCardNoSearch())%>" /></td>
                                    <td><input type="button"  value="Search" onclick="javascript:popup_CIF(220, 180, document.pdsSalesRegister.cardNoSearch.value, document.pdsSalesRegister.custNameSearch.value);" /></td>
                                </tr>



                                <tr>
                                    <td></td> <td style="text-align: right;"><label style=" font-family: Berlin Sans FB; ">From Date:</label></td><td><input type="text" name="fromDate" id="fromDate" readonly="readonly" value="<%=blankNull(opdsSalesRegisterHeaderBean.getFromDate())%>"/><a href="#" onclick="return getCalendar(getElementById('fromDate'));"><img src="${pageContext.request.contextPath}/img/calendar.gif" name="imgr" border="0" width="15" height="15" /></a></td>
                                    <td></td><td align="right" ><label style=" font-family: Berlin Sans FB; ">To Date:</label></td><td><input type="text" name="toDate" id="toDate" readonly="readonly" value="<%=blankNull(opdsSalesRegisterHeaderBean.getToDate())%>"/><a href="#" onclick="return getCalendar(getElementById('toDate'));"><img src="${pageContext.request.contextPath}/img/calendar.gif" name="imgr" border="0" width="15" height="15" /></a></td>

                                </tr>

                            </tbody>
                        </table>

                    </center>
                    <br>
                    <center>

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


                    </center>

                    <br>

                    <br>


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


                            <table id="order-listAmend"  border="2" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px; width: 100%;">
                                <thead  class="CSSTableGenerator" >
                                    <tr>

                                        <td style="text-align:center;"> <b>Name</b>  </td>
                                        <td style="text-align:center;"> <b>Card No</b>  </td>
                                        <td style="text-align:center;"> <b>Product Type</b>  </td>
                                        <td style="text-align:center;"> <b>Product Sub Type</b>  </td>
                                        <td style="text-align:center;" > <b>Quantity</b> </td>
                                        <td style="text-align:center;"> <b>Unit Sale Price</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>Total Amount</b>  </td>


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

                                        for (int i = 0; i < alpdsSalesRegisterDetailsBeanApend.size(); i++) {
                                            opdsSalesRegisterDetailsBeanApend = alpdsSalesRegisterDetailsBeanApend.get(i);
                                    %>


                                    <tr>

                                        <td style="text-align:center;"><input type="text" size="26" value="<%=blankNull(opdsSalesRegisterDetailsBeanApend.getName())%>" readonly="true"></td>
                                        <td style="text-align:center;"><input type="text" size="10" value="<%=blankNull(opdsSalesRegisterDetailsBeanApend.getCardNo())%>" readonly="true"></td>
                                        <td style="text-align:center;"><input type="text" size="25" value="<%=blankNull(opdsSalesRegisterDetailsBeanApend.getProductType())%>" readonly="true"></td>
                                        <td style="text-align:center;"><input type="text" size="25" value="<%=blankNull(opdsSalesRegisterDetailsBeanApend.getProductSubType())%>" readonly="true"></td>
                                        <td style="text-align:center;"><input type="text" size="10" value="<%=blankNull(opdsSalesRegisterDetailsBeanApend.getQuantity())%>" readonly="true"></td>
                                        <td style="text-align:center;"><input type="text" size="15" value="<%=blankNull(opdsSalesRegisterDetailsBeanApend.getUnitSalePrice())%>" readonly="true"></td>
                                        <td style="text-align:center;"><input type="text" value="<%=blankNull(opdsSalesRegisterDetailsBeanApend.getSaleDate())%>" readonly="true"></td>
                                        <td style="text-align:center;"><input type="text" value="<%=blankNull(opdsSalesRegisterDetailsBeanApend.getStockId())%>" readonly="true"></td>
                                        <td style="text-align:center;"><input type="text" size="12" value="<%=blankNull(opdsSalesRegisterDetailsBeanApend.getTotal())%>" readonly="true"></td>

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


                        </div>
                    </center>
                    <%}%>
                </div>
                <!-- <input type="hidden" name="handle_id" value="" />-->
            </form>
            <script>



             
                function ShowParent()
                {
                    document.forms[0].action = "/PacsApplication/Pds_JSP/pdsSalesRegister.jsp";
                    document.forms[0].submit();
                }


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