<!-- /**
 *  PURPOSE  : Scan loc_code and lon_no OR LOT_SL then Display Detail information of stock.
 *  AUTHOR   : Created By Dhanraj Thakare On 05/09/2014 W14FSUN004 
 *  
 */ -->

<%//Changed by Dhanraj on 05/09/14[W14FSUN004 || Set Encoding] %>

<%@page import="java.rmi.RemoteException"%>
<%@page import="ibase.webitm.utility.ITMException"%>
<%@page contentType="text/html"%>
<%@page	import="javax.xml.parsers.DocumentBuilderFactory,javax.xml.parsers.DocumentBuilder,org.w3c.dom.*"%>
<%@page import="ibase.utility.CommonConstants"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.Context"%>
<%@page import="org.w3c.dom.Node"%>
<%@page import="java.util.List"%>
<%@page import="org.w3c.dom.NodeList"%>
<%@page import="ibase.webitm.utility.GenericUtility"%>
<%@page import="ibase.utility.CommonConstants"%>
<jsp:useBean id = "stockinfo" scope = "application" class = "ibase.webitm.bean.wms.InventoryDispInfoBean" />
<%	
  ibase.utility.UserInfoBean userInfo = null;
//Changed by Nazia on 10-Sep-2008[Added try and catch block to avoid null exception when session expired]
try
{

	//Changed by Dayanand on 02/02/10[WI89SUN045 || Set Encoding]
	request.setCharacterEncoding(CommonConstants.ENCODING);
	System.out.println("<------- InventoryDeatilsInfo.jsp ---------->");
	System.out.println("Session Id :"+session.getId());	
	//Changed by Nazia on 10-Sep-2008[variable is defined before try ]Start
	//ibase.utility.UserInfoBean userInfo = ( ibase.utility.UserInfoBean )session.getAttribute( "USER_INFO" );
	userInfo = ( ibase.utility.UserInfoBean )session.getAttribute( "USER_INFO" );

	String loginID = userInfo.getLoginCode();
	String site = userInfo.getSiteCode();
	String password = "No Authentication";
	if (site == null || (site != null && site.equalsIgnoreCase("null")) || (site != null && site.trim().length() <=0))
	{
		site = "SP801";
	}
	String javascript = "enabled";
	System.out.println("loginID :"+loginID+", password : **** , Site :"+site);
	
	//Changed by Nazia on 09-Sep-2008[send empCode to DoctorEvents.jsp for show status BI89SUN008]Start	 
	String empCode = userInfo.getEmpCode().trim();	
	String callFromIbase = request.getParameter("callFromIbase");	
	System.out.println("  #########  callFromIbase ["+callFromIbase+"] ######### ");
	//Changed by Nazia on 09-Sep-2008[BI89SUN008]End

%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor="white">
     <%
     if((request.getParameter("location") != null  || request.getParameter("lotno") != null || request.getParameter("lotsl") != null) &&
    	(!"".equals(request.getParameter("location"))  || !"".equals(request.getParameter("lotno")) || !"".equals(request.getParameter("lotsl"))))// for all condition.
     {    //After submit 
    	   GenericUtility genericUtility = GenericUtility.getInstance();
    	   String lotNo="";
	       String location="";
	       String lotSl="";
	       location = request.getParameter("location").trim();
	       lotNo = request.getParameter("lotno").trim();
	       lotSl = request.getParameter("lotsl").trim();
	       /* out.println(lotNo);
	       out.println(location);
	       out.println(lotSl); */
	      
	     //Start To Read xml code.....................  
		   	String xmlString = "";
			String objName = "";
			Document dom = null;
			NodeList dtlList = null;
			Node parentNode = null;
			NodeList childNodeList = null;
			Node currDetail = null;
			String childNodeName = "";
			String locationCode="";
			String item="";
			int tdCount=5;
			boolean scanbyLotSl = true;//false;
			boolean locFlg=true;
			boolean lotFlg=true;
			boolean lpnFlg=true;
			String scanInfo = "";
			
			if("".equals(location) && "".equals(lotNo) && "".equals(lotSl))
			{
				/* xmlString=stpd.getStocklDataLpn(lotSl); 
				scanInfo=lotSl;
				 scanbyLotSl=true; */
				out.println("Please Scan Any one Location Code,LotNo OR Lot SL(lpn)");
			}else
			{
				/* //out.println("Call lot location");
				if("".equals(location) || "".equals(lotNo)){
					out.println("Please Scan Location Code and LotNo OR Lot SL(lpn)");
				}else{
					xmlString=stpd.getStocklDataLoc(location,lotNo);
					scanInfo = location+" "+lotNo;
					scanbyLotSl = false;
				} */
		    	// out.println("STR LEN "+stockDetialInfo.length()+"  ===========>"+stockDetialInfo.toString());
				
				if("".equals(location)){
					tdCount++;
				}else{
					locFlg=false;
					scanInfo=location;
				}
				if("".equals(lotNo)){
					tdCount++;
				}else{
				    lotFlg=false;
				    if("".equals(scanInfo)){
				       scanInfo= scanInfo+" "+lotNo;
				    }else{
				    	scanInfo= scanInfo+" : "+lotNo;
				    }
				}
				if("".equals(lotSl))
				{
					tdCount++;
				}else{
					lpnFlg=false;
					 if("".equals(scanInfo)){
						scanInfo=scanInfo+" "+lotSl;
					 }else{
						 scanInfo=scanInfo+" : "+lotSl;
					 }
				}
				System.out.println(" tdCount$$$$$4=== "+tdCount);
				xmlString=stockinfo.getStocklDataLoc(location,lotNo,lotSl,site);
			}
			String str123=""+tdCount;
		    System.out.println(" xmlString===================================>"+xmlString);
		
		%>
	        <table style="position: absolute; top: 10px;left:0px; height: auto; width:240pt;">
	    	   <TR align="center"  style=" text-align : center; color : #FFFFFF; background : darkblue;font : 5ptArial; cursor : hand;font-size:11pt;">
	    	       <TD  colspan="<%=tdCount%>"  >Inventory Information</TD>
	    	   </TR>
	    	   <TR align="center"  style=" text-align : center; color : #FFFFFF; background : darkblue;font : 5ptArial; cursor : hand;font-size:10pt;">
	    	       <TD  colspan="<%=tdCount%>"  ><%=scanInfo%></TD>
	    	   </TR>
	    	   <TR  style=" text-align : center; color : black; background : #c0c0c0; font : 3ptArial; cursor : hand;font-size:10pt;">
	    	     	<%if(scanbyLotSl)
	    	     	{ %>
		    	     	<TD Title="Item Code" >Item</TD>
		    	     	<%if(locFlg){ %>
		    	     		<TD Title="Location Code">Location</TD>
		    	     	<%}if(lotFlg){ %>
		    	     		<TD Title="Lot No">Lot</TD>
		    	     	<%}if(lpnFlg){ %>
		    	     		<TD Title="Lpn NO">Lpn</TD>
		    	     	<%}%>
		    	     	
		    	     	<TD Title="Quantity" >Qty</TD>
		    	     	<TD Title="Allocation Quantity" >Alloc Qty</TD>
		    	     	<TD Title="Available Quantity">Bal Qty</TD>
		    	     	<TD Title="Pallet Weight">Pallet Wt</TD>
		    	     </TR>
		    	     <%}%>
	    	     	<%-- <%}else{%>
		    	     	<TD Title="Location Code">location</TD>
		    	     	<TD Title="Lot No">lot</TD>
		    	     	<TD Title="Item Code" >item</TD>
		    	     	<TD Title="Quantity">qty</TD>
		    	     	<TD Title="Allocation Quantity">alloc qty</TD>
		    	     	<TD Title="Available Quantity">bal qty</TD>
		    	     	<TD Title="Pallet Weight">pallet wt</TD>
	    	     	<%}%> --%>
	    	  
	    	    <%  
	    	    if (xmlString != null && xmlString.trim().length() > 0) 
				{
	    	    	System.out.println(" Start work for read xml string");
	    	    	dom = genericUtility.parseString(xmlString);
					if (dom != null)
					{
						dtlList = dom.getElementsByTagName("Detail1");
						System.out.println("  dtlList .getLength()===>"+ dtlList.getLength());
						for (int cntr = 0; cntr < dtlList.getLength(); cntr++) 
						{
							parentNode = dtlList.item(cntr);
							childNodeList = parentNode.getChildNodes();
							String holdFlg="0";
							System.out.println("  childNodeList .getLength()===>"+ childNodeList .getLength());
                         %> <TR  style=" text-align : left; color : black; background : white; font : 3ptArial; cursor : hand;font-size:7pt;"> <% 
							for (int nodCtr = 0; nodCtr < childNodeList .getLength(); nodCtr++) 
							{
								Node subChildNode = childNodeList.item(nodCtr);
								String subchildNodeName = subChildNode.getNodeName();
								System.out.println(" subchildNodeName======>>> "+subchildNodeName);
							    if(scanbyLotSl)//location and lotno
							    {
							    	
							    	if (subchildNodeName.trim().equals("hold_flg")) // gross_wt
									{
										holdFlg = subChildNode.getFirstChild().getNodeValue();
										System.out.println(" From Xml holdFlgis===>"+holdFlg);
										if("1".equals(holdFlg))
								    	{
								    		System.out.println("Call 1");
								    	}   
									}
							    	
							    	else if (subchildNodeName.trim().equals("loc_code")) // loc_code
									{
							    		System.out.println("Call 1"+holdFlg);
							    		locationCode = subChildNode.getFirstChild().getNodeValue();
										System.out.println(" From Xml location code is===>"+locationCode);
										if(locFlg){
											if("1".equals(holdFlg)){
												holdFlg="0";	
											   %> <TD align="left"><img  src="../images/lock_red.jpg" width="10" height="10"><%=locationCode %> </TD><%
											}else{
												%> <TD align="left"><%=locationCode %> </TD><%
											}
										}
									}
							    
							    	else if (subchildNodeName.trim().equals("lot_no")) // lot no
									{
										String lotNoxml = subChildNode.getFirstChild().getNodeValue();
										System.out.println(" From Xml location code is===>"+lotNoxml);
										if(lotFlg){
											if("1".equals(holdFlg)){
												holdFlg="0";
												 %> <TD align="left"><img  src="../images/lock_red.jpg" width="10" height="10"><%=lotNoxml %> </TD><%
											}else{
										        %> <TD align="left"><%=lotNoxml %> </TD><%
											}
										}		 
									}
							    	else if (subchildNodeName.trim().equals("lot_sl")) // lotsl
									{
										lotSl = subChildNode.getFirstChild().getNodeValue();
										System.out.println(" From Xml lotsl is===>"+locationCode);
										if(lpnFlg){
											if("1".equals(holdFlg)){
												holdFlg="0";
												%> <TD align="left"><img  src="../images/lock_red.jpg" width="10" height="10"><%=lotSl%> </TD><%
											}else{
										 		%> <TD align="left"><%=lotSl%> </TD><%
											}
										}
									}
							    	else if (subchildNodeName.trim().equals("item")) //Item
									{
							    		System.out.println("Call 1"+holdFlg);
										item = subChildNode.getFirstChild().getNodeValue();
										System.out.println(" From Xml item code is===>"+item);
										if("1".equals(holdFlg)){
											holdFlg="0";
										%><TD align="left" nowrap="nowrap"><img  src="../images/lock_red.jpg" width="10" height="10"><%=item%> </TD><%
										}else{
											%><TD align="left" nowrap="nowrap"><%=item%> </TD><%
										}
									  
									}
							    	
							    	
									else if (subchildNodeName.trim().equals("quantity")) //qty
									{
										String quantity = subChildNode.getFirstChild().getNodeValue();
										System.out.println(" From Xml qty is===>"+quantity);
									    %> <TD align="right"><%=quantity %> </TD><% 
									}
									else if (subchildNodeName.trim().equals("alloc_qty")) // Replenishment Tasks
									{
										String allocQty = subChildNode.getFirstChild().getNodeValue();
										System.out.println(" From Xml alloc qty is===>"+allocQty);
										%> <TD  align="right"><%=allocQty%> </TD><% 
									}
									else if (subchildNodeName.trim().equals("avail_qty")) // Replenishment Tasks
									{
										String availQty = subChildNode.getFirstChild().getNodeValue();
										System.out.println(" From Xml Avai qty is===>"+availQty);
									     %> <TD  align="right"><%=availQty %> </TD><% 
									}
									else if (subchildNodeName.trim().equals("gross_wt")) // gross_wt
									{
										String grossWt = subChildNode.getFirstChild().getNodeValue();
										System.out.println(" From Xml gross wt is===>"+grossWt);
									     %> <TD  align="right"><%=Math.floor(Double.parseDouble(grossWt))%> </TD><% 
									}
									else if (subchildNodeName.trim().equals("item_descr")) // gross_wt
									{
										String itemDescr = subChildNode.getFirstChild().getNodeValue();
										System.out.println(" From Xml itemDescr is===>"+itemDescr);
									    
									}
									
							    }//My Codi close
							}//TD FOR Close
                         %></TR><%
						}// TR FOR 
						%>
						   <TR align="center"  style=" text-align : left;">
			    	        <TD  colspan="<%=tdCount%>"  ><INPUT Type="button" VALUE="Back" onClick="history.go(-1);return true;"></TD>
			    	   </TR><% 
					}//dom close
				}//All XML Detail close.
	    	    %>  
	    	   	   
	    	 </table>
			
		
		<%
		
	 }else{ //For First page
     %>
     <form id="myForm" action="InventoryDetailsInfo.jsp" method="GET">
    	<div align="Center" ><!--  style="width:100%; height: 100%; text-align: center; "> -->
    	   <table>
	    	   <TR align="right">
	    	     <TD>Location Code :</TD>
	    	     <TD><INPUT TYPE="TEXT" NAME='location' id='location' autofocus/></TD>
	    	   </TR>
	    	   <TR align="right">
	    	     	<TD>LOT :</TD>
	    	     	<TD><INPUT TYPE="TEXT" NAME='lotno' id='lotno' /></TD>
	    	   </TR >
	    	    <TR align="right">
	    	     	<TD>LPN :</TD>
	    	     	<TD><INPUT TYPE="TEXT" NAME='lotsl' id='lotsl'  /></TD>
	    	   </TR>	   
	    	   <TR>
	    	   		<TD colspan="2" align="center">
	    	   		<INPUT TYPE="submit" value="SUBMIT" NAME="subbutton" />
	    	   		<!-- <input type="button" onclick="myFunction()" value="Submit form"/> -->
                
                   </TD>
	    	   </TR>
	    	</table>
	    </div>
    </form> 
    <%}%> 
   <!--   <script>
		function myFunction() {
		    document.getElementById("myForm").submit();
		}
	</script>  -->
</body>
</html>
<%}//Changed by Nazia on 10-Sep-2008[Added try and catch block to avoid null exception when session expired]
	catch(Exception e)
	{
		if(userInfo==null)
		{
			out.println("Session Expired,Please relogin to continue.");
		}
	}
%>
