<%--
    Document   : gl
    Created on : Aug 3, 2015, 2:23:35 PM
    Author     : Administrator
--%>
<%@page import="DataEntryBean.tradingPurchaseOrderBean"%>
<% try {
%>
<html>
    <head>
        <title>Raise Purchase Order</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>
    </head>
    <body  onload="noBack()">
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }
            function ShowParent()
            {
                document.forms[0].action = "${pageContext.request.contextPath}/Trading_JSP/RaisePurchaseOrder.jsp";
                document.forms[0].submit();
            }
            
            function submitform(tradingPurchaseOrder)
            {
                if (checkCreateDiv(tradingPurchaseOrder))
                {
                    document.forms[0].handle_id.value = "Update";
                    document.forms[0].action = "/PacsApplication/tradingPurchaseOrderServlet";
                    document.forms[0].submit();
                }
            }
            
            function checkCreateDiv(tradingPurchaseOrder)
            {
                //alert("entering");
                if (tradingPurchaseOrder.commoditytype.value == "")
                {
                    alert("Commodity Type must be filled.");
                    tradingPurchaseOrder.commoditytype.focus();
                    return false;
                }
                if (tradingPurchaseOrder.typedesc.value == "")
                {
                    alert("Type Description must be filled.");
                    tradingPurchaseOrder.typedesc.focus();
                    return false;
                }

                if (tradingPurchaseOrder.commoditysubtype.value == "")
                {
                    alert("Commodity Sub-Type must be filled.");
                    tradingPurchaseOrder.commoditysubtype.focus();
                    return false;
                }
                if (tradingPurchaseOrder.subtypedesc.value == "")
                {
                    alert("Sub-Type Description must be filled.");
                    tradingPurchaseOrder.subtypedesc.focus();
                    return false;
                }
                re = /^\d+$/; //this checks whether field contains digits
                if (tradingPurchaseOrder.unit.value == "")
                {
                    alert("Number of Units must be filled.");
                    tradingPurchaseOrder.unit.focus();
                    return false;
                }
                if (tradingPurchaseOrder.vendorname.value == "")
                {
                    alert("Vendor Name must be filled.");
                    tradingPurchaseOrder.vendorname.focus();
                    return false;
                }
                if (tradingPurchaseOrder.purchaseref.value == "")
                {
                    alert("Purchase Reference number must be filled.");
                    tradingPurchaseOrder.purchaseref.focus();
                    return false;
                }
                if (tradingPurchaseOrder.checkOption.value == "")
                {
                    alert("Please select Mode of Payment.");
                    tradingPurchaseOrder.checkOption.focus();
                    return false;
                }

                re = /^(?=.*\d)\d*(?:\.\d*)?$/; //this checks whether field contains digits
                if (tradingPurchaseOrder.unit_price.value == "")
                {
                    alert("Per/Units Price must be filled.");
                    tradingPurchaseOrder.unit_price.focus();
                    return false;
                }
                if (!re.test(tradingPurchaseOrder.total.value))
                {
                    alert("total must be filled.");
                    tradingPurchaseOrder.total.focus();
                    return false;
                }                               
                if (tradingPurchaseOrder.purchasedesc.value == "")
                {
                    alert("Purchase Description field must be filled.");
                    tradingPurchaseOrder.purchasedesc.focus();
                    return false;
                }
                if (tradingPurchaseOrder.checkOption.value == "2")
                {
                    if (tradingPurchaseOrder.credisp.value == "")
                    {
                        alert("Due Date field must be filled.");
                        tradingPurchaseOrder.credisp.focus();
                        return false;
                    }
                }
                return true;
            }

            function checkop1()
            {
                if (document.getElementById("checkOption").value == "2")
                {
                    document.getElementById('duedate').style.display = 'block';

                }
                if (document.getElementById("checkOption").value == "1")
                {
                    document.getElementById('duedate').style.display = 'none';

                }
            }

            function Total(){

                var priceDetails = document.getElementById("unit_price").value;
                var quantityDetails = document.getElementById("unit").value;

                document.getElementById("total").value=parseFloat(priceDetails*quantityDetails).toFixed(2);

            }

            function search_product(width, height,commoditytype) {

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

            }

            function search_vendor(width, height,name,product_id) {

                if(tradingPurchaseOrder.product_id.value == ""){
                    alert("Please select Product first !!!");
                }else{
                    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 + '&product_id=' + product_id + '&screenName=' + screenName + '&lovKey=' + lovKey, 'vendorDetails', attr);
                    popWin.focus();
                }                
            }
            
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });
           
        </script>
        <%          int count = 1;
                    String error_msg = "";
                    Object error = request.getAttribute("message");
                    if (error != null) {
                        error_msg = error.toString();
                    }
        %>


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

        <%
                    Object tradingPurchaseOrderBeanObj = request.getAttribute("tradingPurchaseOrderBeanObj");
                    tradingPurchaseOrderBean otradingPurchaseOrderBean = new tradingPurchaseOrderBean();
                    if (tradingPurchaseOrderBeanObj != null) {
                        otradingPurchaseOrderBean = (tradingPurchaseOrderBean) request.getAttribute("tradingPurchaseOrderBeanObj");

                    }
        %>


        <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">Raise Purchase Order</legend>

            <form name="tradingPurchaseOrder" method="post" action="">

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


                <br>

                <div id="create" >
                    <table class="NumbersOnly">
                        <tbody>

                            <tr>
                                <td>Commodity Type<font color="red" >*</font>: </td>
                                <td> <input type="text" name="commoditytype" id="commoditytype" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                                <td> <input type="button" value="Search" onclick="javascript:search_product(620, 280,document.tradingPurchaseOrder.commoditytype.value)"/></td>
                            </tr>
                            <tr>
                                <td>Type Description<font color="red" >*</font>:</td>
                                <td> <input type="text" readonly name="typedesc" id="typedesc" /></td>

                            </tr>
                            <tr>
                                <td>Commodity Sub-Type<font color="red" >*</font>:</td>
                                <td><input  name="commoditysubtype" readonly id="commoditysubtype" readonly value="" style="text-align:right;" /></td>
                            </tr>
                            <tr>
                                <td>Sub-Type Description<font color="red" >*</font>:</td>
                                <td><input   name="subtypedesc" readonly id="subtypedesc" readonly value="<%=blankNull(otradingPurchaseOrderBean.getSubtypedesc())%>"/></td>
                            </tr>
                            <tr>

                                <td>Number of Units<font color="red" >*</font>:</td>
                                <td><input type="text" name="unit" id="unit"value="" onchange="Total();" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/></td>
                            </tr>
                            <tr>
                                <td>Price Per/Units<font color="red" >*</font>:</td>
                                <td><input type="text" name="unit_price" id="unit_price" value="" onchange="Total();" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57' /></td>
                            </tr>
                            <tr>
                                <td>Total:</td>
                                <td><input type="text" readonly name="total" id="total" value="" style="text-align:right;" /></td>
                            </tr>
                            <tr>
                                <td>Vendor Name<font color="red" >*</font>:</td>
                                <td><input type="text"  name="vendorname" id="vendorname" /></td>
                                <td><input type="button"  value="Search" onclick="javascript:search_vendor(620, 280,document.tradingPurchaseOrder.vendorname.value,document.tradingPurchaseOrder.product_id.value)" /></td>

                            </tr>
                            <tr>
                                <td>Purchase Reference Number<font color="red" >*</font>:</td>
                                <td><input type="text" name="purchaseref" id="purchaseref"value="" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                            </tr>
                            <tr>
                                <td>Purchase Description<font color="red" >*</font>:</td>
                                <td><textarea name="purchasedesc" id="purchasedesc"></textarea></td>
                            </tr>





                        </tbody>
                    </table>
                    <table>
                        <tr>
                            <td>Mode of Payment<font color="red" >*</font>: </td>
                            <td></td><td></td><td></td><td></td><td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td>
                                <select id="checkOption" onchange="checkop1()" name="checkOption" >
                                    <option value="" disabled selected style="display:none;" > --Select-- </option>
                                    <option value="1" >Cash</option>
                                    <option value="2" >Credit</option>
                                </select>
                            </td>
                        </tr>
                    </table>

                    <div id="duedate" style="display:none" >
                        <table>
                            <td>Due Date<font color="red" >*</font>:</td>
                            <td></td><td></td><td></td><td></td>
                            <td></td><td></td><td></td>
                            <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
                            <td> <input id="credisp" type="text" name="credisp" readonly="readonly"/>&nbsp;<a href="#" onclick="return getCalendar(getElementById('credisp'));"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" border="0" width="25" height="20" /></a></td>
                        </table>

                    </div>
                    <tr><td><br></td></tr>
                    <tr><td><br></td></tr>
                    <tr><td><label style="font-weight:  normal;"><font color="red" >*</font>All fields are mandatory</label></td></tr>

                    <center>
                        <input type="button" value="Generate Purchase Order" onclick="javascript:submitform(tradingPurchaseOrder)">
                        <input type="button" value="Reset" name="reset" onclick="ShowParent();" />
                    </center>
                </div>

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

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

                $('table.NumbersOnly').on('keydown','#unit,#unit_price', 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) {
               
            }
%>

