<% System.out.println(" *****stockButton.jsp***** "); %>
<%@page import = "java.util.*"%>
<%@page import ="ibase.webitm.utility.*"%>
<%@page import = "ibase.webitm.ejb.dis.*"%>
<%@page import = "java.sql.*"%>
<%@page import = "java.text.DecimalFormat"%>
<%@page import = "ibase.webitm.utility.GenericUtility"%>

<jsp:useBean id="stkHlpBn" scope="session" class="ibase.webitm.ejb.dis.StockHelpBean"/>

<HTML>
<HEAD>
	<TITLE>Stock Help</TITLE>
	<script type="text/javascript">
		function callValidate() 
		{
			var siteCd = document.form1.site_code.value;		
			var itemCd = document.form1.item_code.value;
			if( siteCd == "" )
			{
				alert("Please enter Site Code.");
				document.form1.site_code.focus();
				return false;
			}
			if( itemCd == "" )
			{
				alert("Please enter Item Code.");
				document.form1.item_code.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 = "stockButton.jsp?form=2" method = "Post">

<%
   String saleOrder = request.getParameter("PK_VALUES");
   System.out.println("dsfsfsf"+saleOrder);
   String siteCode = request.getParameter("site_code") == null ? "" : request.getParameter("site_code");
   String itemCode = request.getParameter("item_code") == null ? "" : request.getParameter("item_code");
   
%>
  <br/><br/><br/><br/>
  <table align = "center">
	<tr>
		<td>Site Code:</td>
		<td><input type = "text" name = "site_code" size = "10" value = "<%= siteCode %>" onChange = "javascript: this.value = this.value.toUpperCase();"/></td>
		<td>&nbsp;&nbsp;Item Code:</td>
		<td><input type = "text" name = "item_code" size = "10" value = "<%= itemCode %>" 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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type = "button" value = "  Close " onClick = "return CloseWindow();"/>
		</td>
		<td></td>
	</tr>
  </table>	  	
</FORM>
<%
	}
	if((request.getParameter("form") != null ) &&(request.getParameter("form").equals("2")))
	{
%>
<Form name = "form2" action = "stockButton.jsp" method = "POST">

<%
	String siteCode = request.getParameter("site_code");
	String itemCode = request.getParameter("item_code");
	System.out.println("siteCode of bean ==>"+siteCode+" itemCode of bean ==>"+itemCode);
	stkHlpBn.setSiteCode( siteCode.toUpperCase() );
	stkHlpBn.setItemCode( itemCode.toUpperCase() );
%>

	<%
		ArrayList stockHelpList = stkHlpBn.getDetails();
		if( stockHelpList.size() > 0 )
		{
	%>
			<br/>
			<DIV ID="TableBorder" class="tableborderDiv">
			<TABLE name="main" border = "1" id="main" CLASS="sort-table" STYLE="class:header_css;POSITION:relative;TOP:20;left:10;width:790" >
			<thead>	
				<th  class="thClass" nowrap>Item Code</th>
				<th  class="thClass" nowrap>Loc Code</th>
				<th  class="thClass" nowrap>Lot No</th>
				<th  class="thClass" nowrap>Loc Sl</th>
				<th  class="thClass" nowrap>Mfg Date</th>
				<th  class="thClass" nowrap>Exp Date</th>
				<th  class="thClass" nowrap>Quantity</th>
				<th  class="thClass" nowrap>Alloc Qty</th>
				<th  class="thClass" nowrap>Hold Qty</th>
				<th  class="thClass" nowrap>Net Avail</th>
				<th  class="thClass" nowrap>No Art</th>
				<th  class="thClass" nowrap> Rate </th>
				<th  class="thClass" nowrap>Available</th>
				<th  class="thClass" nowrap>Pack Code</th>
				<th  class="thClass" nowrap>Unit</th>
				<th  class="thClass" nowrap>Retest Date</th>
				<th  class="thClass" nowrap>Potency</th>
				<th  class="thClass" nowrap>Supp Code Mfg</th>
				<th  class="thClass" nowrap>Batch No</th>
				<th  class="thClass" nowrap>Dimention</th>
				<th  class="thClass" nowrap>Quant Per Art</th>
				<th  class="thClass" nowrap>Batch Size</th>				
				<th  class="thClass" nowrap>Pack Ref</th> <!-- added by swati bade on 09-May-2013-->
			</thead>
		<%
			
			String mapKey = "", keyIndex = "", prevKeyIndex = "";
			double totQuant = 0, totAllocQuant = 0, totHoldQuant = 0;
			double prevTotQuant = 0, prevTotAllocQuant = 0, prevTotHoldQuant = 0;
			double totNetQuant = 0, grndTotQty = 0, grndTotAllocQuant = 0;
			double grndTotHoldQuant = 0, grndTotAvailQuant = 0;
			java.sql.Timestamp retestDateTs = null, expDateTs = null;
			
			for(int i=0;i<stockHelpList.size();i++)
			{
				stkHlpBn = ( ibase.webitm.ejb.dis.StockHelpBean)(stockHelpList.get(i));
				System.out.println("stkHlpBn.batchNo==["+stkHlpBn.batchNo+"]");
				
				for(Iterator it = (stkHlpBn.beanLotQuantMap).keySet().iterator(); it.hasNext(); )
				{
					mapKey = (String)it.next();
					System.out.println("mapKey is ==>"+mapKey);
					keyIndex = mapKey.substring(3, mapKey.length());
					System.out.println("keyIndex is ==>"+keyIndex);
					if(mapKey.equals("LWQ"+keyIndex))
						totQuant = ((Double)(stkHlpBn.beanLotQuantMap).get(mapKey)).doubleValue();
					else if(mapKey.equals("LAQ"+keyIndex))
						totAllocQuant = ((Double)(stkHlpBn.beanLotQuantMap).get(mapKey)).doubleValue();
					else
						totHoldQuant = ((Double)(stkHlpBn.beanLotQuantMap).get(mapKey)).doubleValue();
				}
				
				if( (!keyIndex.equals(prevKeyIndex)) && ( i != 0 ) )
				{
					%>					
					<tr BGCOLOR="#FFFFFF">
						<!-- <td></td><td></td><td></td><td></td><td></td> -->
						<td colspan = "6" align = "right"><b>Lotwise Total : </b></td>
						<td align = "right"><font size="-1"><%= df.format(prevTotQuant) %></font></td>
						<td align = "right"><font size="-1"><%= df.format(prevTotAllocQuant) %></font></td>
						<td align = "right"><font size="-1"><%= df.format(prevTotHoldQuant) %></font></td>
						<td align = "right"><font size="-1"><%= df.format(totNetQuant) %></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>
					</tr>
					<%
						totNetQuant = 0;
				}
		%>
				<tr BGCOLOR="#FFFFFF">	
					<td align = "center"><font size="-1"><%= (stkHlpBn.itemCodeStk != null && stkHlpBn.itemCodeStk.equals("")) ? "-" : stkHlpBn.itemCodeStk %></font></td>
					<td align = "center"><font size="-1"><%= (stkHlpBn.locCode != null && stkHlpBn.locCode.equals("")) ? "-" : stkHlpBn.locCode %></font></td>
					<td align = "center"><font size="-1"><%= ((stkHlpBn.lotNo != null && stkHlpBn.lotNo.equals("")) || (stkHlpBn.lotNo == null)) ? "-" : stkHlpBn.lotNo %></font></td>
					<td align = "center"><font size="-1"><%= (stkHlpBn.locSl != null && stkHlpBn.locSl.equals("")) ? "-" : stkHlpBn.locSl %></font></td>
					<td align = "center"><font size="-1"><%= (stkHlpBn.mfgDate != null && stkHlpBn.mfgDate.equals("")) ? "-" : stkHlpBn.mfgDate %></font></td>
			<%
				if( stkHlpBn.expDate != null && stkHlpBn.expDate.trim().length() > 0 )
				{
					expDateTs = Timestamp.valueOf(genericUtility.getValidDateString(stkHlpBn.expDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
					if( expDateTs.compareTo(stkHlpBn.currDateTs) < 0 )
					{
					%>
					<td align = "center"><font size="-1" color = "red"><%= stkHlpBn.expDate %></font></td>
					<%
					}
					else
					{
					%>
						<td align = "center"><font size="-1"><%= stkHlpBn.expDate %></font></td>
					<%
					}
				}
				else
				{
				%>
					<td align = "center"><font size="-1"><%= "-" %></font></td>
				<%
				}
				
			%>	
					<td align = "right"><font size="-1"><%= (stkHlpBn.quantity != null && stkHlpBn.quantity.equals("")) ? "0.000" : df.format(Double.parseDouble(stkHlpBn.quantity))  %></font></td>
					<td align = "right"><font size="-1"><%= (stkHlpBn.allocQty != null && stkHlpBn.allocQty.equals("")) ? "0.000" : df.format(Double.parseDouble(stkHlpBn.allocQty)) %></font></td>
					<td align = "right"><font size="-1"><%= (stkHlpBn.holdQuant != null && stkHlpBn.holdQuant.equals("")) ? "0.000" : df.format(Double.parseDouble(stkHlpBn.holdQuant)) %></font></td>
					<td align = "right"><font size="-1"><%= (stkHlpBn.netAvailable != null && stkHlpBn.netAvailable.equals("")) ? "0.000" : df.format(Double.parseDouble(stkHlpBn.netAvailable)) %></font></td>					
					<td align = "center"><font size="-1"><%= (stkHlpBn.noArt != null && stkHlpBn.noArt.equals("")) ? "-" : stkHlpBn.noArt %></font></td>
					<td align = "center"><font size="-1"><%= ((stkHlpBn.rate != null && stkHlpBn.rate.equals("")) || (stkHlpBn.rate == null)) ? "0.000" : df.format(Double.parseDouble(stkHlpBn.rate)) %></font></td>
					<%
				if( stkHlpBn.available != null && stkHlpBn.available.trim().equals("Y"))
				{
			%>
					<td align = "center"><font size="-1" color = "blue"><b><%= "Yes" %></b></font></td>
			<%
				}
				else if( stkHlpBn.available != null && stkHlpBn.available.trim().equals("N"))
				{
			%>
					<td align = "center"><font size="-1" color = "red"><b><%= "No" %></b></font></td>
			<%
				}
				else
				{
			%>	
					<td align = "center"><font size="-1"><%= "-"  %></font></td>
			<%
				}
			%>
					<td align = "center"><font size="-1"><%= (stkHlpBn.packCode != null && stkHlpBn.packCode.equals("")) ? "-" : stkHlpBn.packCode %></font></td>
					<td align = "center"><font size="-1"><%= (stkHlpBn.unit != null && stkHlpBn.unit.equals("")) ? "-" : stkHlpBn.unit %></font></td>
			<%
				if( stkHlpBn.retestDate != null && stkHlpBn.retestDate.trim().length() > 0 )
				{
					retestDateTs = Timestamp.valueOf(genericUtility.getValidDateString(stkHlpBn.retestDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
					if( retestDateTs.compareTo(stkHlpBn.currDateTs) < 0 )
					{
					%>
						<td align = "center"><font size="-1" color = "red"><%= stkHlpBn.retestDate %></font></td>
					<%
					}
					else
					{
					%>
						<td align = "center"><font size="-1"><%= stkHlpBn.retestDate %></font></td>
					<%
					}
				}
				else
				{
				%>
					<td align = "center"><font size="-1"><%= "-" %></font></td>
				<%
				}
			%>		
					
					<td align = "center"><font size="-1"><%= (stkHlpBn.potency != null && stkHlpBn.potency.equals("")) ? "-" : stkHlpBn.potency %></font></td>	
					<td align = "center"><font size="-1"><%= ((stkHlpBn.suppCodeMfg != null && stkHlpBn.suppCodeMfg.equals("")) || (stkHlpBn.suppCodeMfg == null )) ? "-" : stkHlpBn.suppCodeMfg %></font></td>
					<td align = "center"><font size="-1"><%= ((stkHlpBn.batchNo != null && stkHlpBn.batchNo.trim().equals("")) || (stkHlpBn.batchNo == null)) ? "-" : stkHlpBn.batchNo %></font></td>
					<td align = "center"><font size="-1"><%= ((stkHlpBn.dimention != null && stkHlpBn.dimention.equals("")) || (stkHlpBn.dimention == null)) ? "-" : stkHlpBn.potency %></font></td>	
					<td align = "right"><font size="-1"><%= ((stkHlpBn.qtyPerArt != null && stkHlpBn.qtyPerArt.trim().equals("")) || (stkHlpBn.qtyPerArt == null)) ? "0.000" : df.format(Double.parseDouble(stkHlpBn.qtyPerArt)) %></font></td>
					<td align = "center"><font size="-1"><%= ((stkHlpBn.batchSize != null && stkHlpBn.batchSize.equals("")) || (stkHlpBn.batchSize == null)) ? "-" : stkHlpBn.batchSize %></font></td>	
					<!-- start of code added by swati bade on 09-May-2013 for pack_ref input-->
					<td align = "center"><font size="-1"><%= ((stkHlpBn.packRef != null && stkHlpBn.packRef.equals("")) || (stkHlpBn.packRef == null)) ? "-" : stkHlpBn.packRef %></font></td>
					<!--  end of code added by swati bade on 09-May-2013-->	
				</tr>
		<%
				prevTotQuant = totQuant;
				prevTotAllocQuant = totAllocQuant;
				prevTotHoldQuant = totHoldQuant;
				prevKeyIndex = keyIndex;
				totNetQuant = totNetQuant + Double.parseDouble(stkHlpBn.netAvailable);
				grndTotQty = grndTotQty + Double.parseDouble(stkHlpBn.quantity);
				grndTotAllocQuant = grndTotAllocQuant + Double.parseDouble(stkHlpBn.allocQty);
				grndTotHoldQuant = grndTotHoldQuant + Double.parseDouble(stkHlpBn.holdQuant);
				grndTotAvailQuant = grndTotAvailQuant + Double.parseDouble(stkHlpBn.netAvailable);
			}
	%>
			<tr BGCOLOR="#FFFFFF">
				<td colspan = "6" align = "right"><b>Grand Total : </b></td>
				<td align = "right"><font size="-1"><%= df.format(grndTotQty) %></font></td>
				<td align = "right"><font size="-1"><%= df.format(grndTotAllocQuant) %></font></td>
				<td align = "right"><font size="-1"><%= df.format(grndTotHoldQuant) %></font></td>
				<td align = "right"><font size="-1"><%= df.format(grndTotAvailQuant) %></font></td>
				<td></td><td></td><td colspan = "2" align = "right"><b>Indent :</b></td>
				<td align = "right"><font size="-1" color = "blue"><%= df.format(Double.parseDouble(stkHlpBn.pindQty)) %></font></td>
				<td align = "right"><b>PO :</b></td>
				<td align = "right"><font size="-1" color = "blue"><%= df.format(Double.parseDouble(stkHlpBn.ppoQty)) %></font></td>
				<td></td>
				<td></td><td></td><td></td><td></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>
		

