<% System.out.println(" *****BOMStockButton.jsp***** "); %>
<%@page import = "java.util.*"%>
<%@page import ="ibase.webitm.utility.*"%>
<%@page import = "ibase.webitm.ejb.mfg.adv.*"%>
<%@page import = "java.sql.*"%>
<%@page import = "java.text.DecimalFormat"%>
<%@page import = "ibase.webitm.utility.GenericUtility"%>
<%@page import = "ibase.utility.CommonConstants"%>
<%@page import ="java.net.URLDecoder"%>
<%@page import="ibase.utility.UserInfoBean"%>

<jsp:useBean id="BOMStkBean" scope="session" class="ibase.webitm.ejb.mfg.adv.BOMStockBean"/>
<html>
<head>
	<title>Bom Stock</title>
	<script type="text/javascript">
	
		function callValidate() 
		{
			var bomCd = document.form1.bom_code.value;		
			var batchQty = document.form1.batch_qty.value;
			if( bomCd == "" )
			{
				alert("Please enter Bom Code.");
				document.form1.bom_code.focus();
				return false;
			}
			if( batchQty == "" )
			{
				alert("Please enter batchQtyD.");
				document.form1.batch_qty.focus();
				return false;
			}
		}
		function CloseWindow()
		{
			var win=window.open("about:blank","_self");
			win.close();
		}
    </script>
</head>

<body>

<a style="position:absolute;top:10;left:0;height:50;width:1200;background:url(/ibase/webitm/images/title_bar_bg_blue.jpg);font-family:Verdana"></a>
<%
	GenericUtility genericUtility = GenericUtility.getInstance(); 
	DecimalFormat df = new DecimalFormat( "##.000" );
	if((request.getParameter("form") == null ) || ( !request.getParameter("form").equals("2")))
	{
		%>

		<Form name = "form1" action = "BOMStockButton.jsp?form=2" method = "post">

		<%
		  String param = null;
		  String paramvalue = null;
		  
		 Enumeration enum1 = request.getParameterNames();
		  while( enum1.hasMoreElements() )
		  {
			  param = (String)enum1.nextElement();
			  paramvalue = request.getParameter(param);
			  //System.out.println("param ["+param+"] paramvalue ["+paramvalue+"]");    
		  } 
		
	    
		String paramList[];
		String bomCode = "";
		String batchQtyD = "";
		if ( paramvalue.indexOf("~") != -1 )
		{
		  paramList = paramvalue.split("~");
		  bomCode = paramList[0];
		  batchQtyD = paramList[1];
		}

		String itemDescr = "";

		System.out.println("bomCode [" + bomCode + "]");
		System.out.println("batchQtyD [" + batchQtyD + "]");

		%>
		<br/><br/><br/><br/>
		<table align = "center">
			<tr>
				<td> Bom Code:</td>
				<td> <input type = "text" name = "bom_code" size = "10" value = "<%= bomCode %>" onChange = "javascript: this.value = this.value.toUpperCase();"/></td>
				<td> &nbsp;&nbsp;Batch Quantity:</td>
				<td> <input type = "text" name = "batch_qty" size = "10" value = "<%= batchQtyD %>" onChange = "javascript: this.value = this.value.toUpperCase();"/></td>
			</tr>
			
			<tr>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tr>
			
			<tr>
				<td></td>
				<td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type = "submit" VALUE = "Retrieve"  onClick = "return callValidate();" /></td>
				</td>
				<td></td>
			</tr>
		</table>	  	
		</FORM>
		<%
	}
	if((request.getParameter("form") != null ) &&(request.getParameter("form").equals("2")))
	{
		%>

		<Form name = "form2" action = "BOMStockButton.jsp" method = "POST">
		<%
			//added by Dadaso pawar 10/01/14 [start]
			 UserInfoBean userInfo = (UserInfoBean)session.getAttribute("USER_INFO");
			System.out.println("User Info bom----->>>>$%$%$ [["+userInfo+"]]");			
			BOMStkBean.setUserInfo(userInfo);			
			//added by Dadaso pawar 10/01/14 [End]
		    String bomCode = (String) request.getParameter("bom_code") == null ? "" : request.getParameter("bom_code");
		    String batchQtyD = (String) request.getParameter("batch_qty") == null ? "" : request.getParameter("batch_qty");

		    System.out.println("bomCode of bean 2 ==>"+bomCode+" batchQtyD of bean ==>"+batchQtyD);
			BOMStkBean.setBomCode( bomCode.toUpperCase() );
			if(batchQtyD != null && batchQtyD.trim().length() > 0)
			{
				BOMStkBean.setBatchQtyD( batchQtyD.toUpperCase() );
			}
		
			ArrayList BOMStockHelpList = BOMStkBean.getDetails();
			if( BOMStockHelpList.size() > 0 )
			{
				%>
		
				<br/>

				<DIV ID="TableBorder" class="tableborderDiv">
					<TABLE name="main" border = "3" id="main" CLASS="sort-table" STYLE="class:header_css;POSITION:relative;TOP:20;left:10;width:790" >
					<tr><input type = "button" VALUE = "Back"  onClick = "history.back();" /></tr>
					<thead>	
						<th colspan="11">&nbsp;</th>
						<th colspan="3">Login Site [<%=userInfo.getSiteCode() %>]</th>				
				</thead>	
					<thead>	
						
						<!--TH WIDTH=39><P>Stock</P></TH-->
						<TH WIDTH=66><P>Bom Code</P></TH>
						<TH WIDTH=59><P>Item Code</P></TH>
						<TH WIDTH=128><P>Item Description</P></TH>
						<TH WIDTH=71><P>Required Type</P></TH>
						<TH WIDTH=72><P>Minimum Quantity</P></TH>
						<TH WIDTH=61><P>Quantity Per</P></TH>
						<TH WIDTH=62><P>Batch Quantity</P></TH>
						<TH WIDTH=97><P>Stock Usable Quantity</P></TH>
						<TH WIDTH=126><P>Stock NonUsable Quantity</P></TH>
						<TH WIDTH=75><P>Required Quantity</P></TH>
						<TH WIDTH=66><P>Allocated Quantity</P></TH>
						<!--TH WIDTH=56><P>Quantity</P></TH-->
						<!-- added by Dadaso pawar 10/01/14 -->
						<TH WIDTH=97><P>Stock Usable Quantity</P></TH>
						<TH WIDTH=126><P>Stock NonUsable Quantity</P></TH>
						<TH WIDTH=66><P>Allocated Quantity</P></TH>
						
						
					</thead>
				
					<%
						for(int i=0;i<BOMStockHelpList.size();i++)
						{
							BOMStkBean = ( ibase.webitm.ejb.mfg.adv.BOMStockBean)(BOMStockHelpList.get(i));
							%>
			
							<tr BGCOLOR="#FFFFFF">	
								
								<td align = "left"><font size="-1"><%=(BOMStkBean.bomCode != null && BOMStkBean.bomCode.equals("")) ? "-" : BOMStkBean.bomCode%></font></td>
								<td align = "left"><font size="-1"><%=(BOMStkBean.itemCode != null && BOMStkBean.itemCode.equals("")) ? "-" : BOMStkBean.itemCode%></font></td>
								<td align = "left"><font size="-1"><%=(BOMStkBean.descr != null && BOMStkBean.descr.equals("")) ? "-" : BOMStkBean.descr%></font></td>
								<td align = "left"><font size="-1"><%=(BOMStkBean.reqType != null && BOMStkBean.reqType.equals("")) ? "-" : BOMStkBean.reqType%></font></td>
								<td align = "right"><font size="-1"><%=((BOMStkBean.minQty == 0) ? "0.000" : df.format(BOMStkBean.minQty))%></font></td>
								<td align = "right"><font size="-1"><%=((BOMStkBean.qtyPar == 0) ? "0.000" :df.format(BOMStkBean.qtyPar))%></font></td>
								<td align = "right"><font size="-1"><%= batchQtyD %></font></td>
								<td align = "right"><font size="-1"><%=((BOMStkBean.stkQty == 0) ? "0.000" :df.format(BOMStkBean.stkQty))%></font></td>
								<td align = "right"><font size="-1"><%=((BOMStkBean.nonStkQty == 0) ? "0.000" :df.format(BOMStkBean.nonStkQty))%></font></td>
								<td align = "right"><font size="-1"><%=((BOMStkBean.reqQty == 0) ? "0.000" :df.format(BOMStkBean.reqQty))%></font></td>
								<td align = "right"><font size="-1"><%=((BOMStkBean.allockQty == 0) ? "0.000" :df.format(BOMStkBean.allockQty))%></font></td>
								
								<!-- added by Dadaso pawar 10/01/14 -->
								<td align = "right"><font size="-1"><%=((BOMStkBean.stkQty == 0) ? "0.000" :df.format(BOMStkBean.stkQtyL))%></font></td>
								<td align = "right"><font size="-1"><%=((BOMStkBean.nonStkQty == 0) ? "0.000" :df.format(BOMStkBean.nonStkQtyL))%></font></td>
								<td align = "right"><font size="-1"><%=((BOMStkBean.allockQty == 0) ? "0.000" :df.format(BOMStkBean.allockQtyL))%></font></td>
								
							</tr>
							<%
						}
						%>
					</TABLE>
				</DIV>
				<%
			}
			else
			{
				System.out.println("Inside else");
				%>			
				<BR/><BR/><BR/><BR/>
				<p><b><center><h2>
				No any stock detail found for entered data.
				</h2></center></b></p>
				<%	
			}
			%>
		
			<BR/><BR/>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<!-- <input type = "button" VALUE = "Back" onClick = "history.back()"/> -->
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<!--input type = "button" value = "Close" onclick="return CloseWindow();"/-->
			
			<!--<a href="javascript:window.opener='x';window.close();">Close me</a>-->
			<!-- Running code in mozilla 1.5 -->
			<!-- <a href="javascript:window.open('','_parent','');window.close();">
			<input type="button" value="Close Window"/></a> -->
		</FORM>
		<%
	}
	%>

</body>
</html>
