package ibase.webitm.ejb.mfg;


import java.util.*;
import java.io.File;
import java.sql.*;
import java.sql.Date;


import org.w3c.dom.*;

import java.text.SimpleDateFormat;

import javax.naming.InitialContext;
import javax.servlet.http.HttpSession;

import ibase.system.config.AppConnectParm;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;

import ibase.webitm.ejb.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.GenericUtility;

import ibase.webitm.utility.TransIDGenerator;

public class MRPWizardAllocateQtyBean 
{
	// startt

	private ibase.utility.UserInfoBean userInfo = null;
	private HttpSession sessionCtx = null;
	ITMWizardStatefulRemote itmWizardRemote = null;
	private String objName = "";
	private String user_lang ="en"; 
	private String user_country = "US";

	public String getItemCodeList( String itemCode,String search , String dbID, String siteCode ) throws ITMException
	{
		String itemCodeData = "";
		RequirementICRemote requirementICRemote = null;
		try
		{
			InitialContext ctx = new InitialContext( new AppConnectParm().getProperty() );
			requirementICRemote = (ibase.webitm.ejb.mfg.RequirementICRemote)ctx.lookup("ibase/RequirementIC/remote");
			itemCodeData = requirementICRemote.getItemCodeList( itemCode ,search,dbID,siteCode);
			requirementICRemote = null;
			System.out.println("itemCodeData=="+itemCodeData);

			String xslFileName = getXSLFileName( "requirement_item_code_set_wiz_" + this.user_lang + "_" + this.user_country + ".xsl" );
			//String xslFileName = getXSLFileName( "requirement_item_code_wiz_en_US.xsl" );
			itemCodeData = ( new ibase.webitm.utility.GenericUtility() ).transformToString( xslFileName, itemCodeData, CommonConstants.APPLICATION_CONTEXT + File.separator + "temp", "Output", ".html" );

			System.out.println("itemCodeData===>"+itemCodeData);
		}
		catch ( Exception e  )
		{
			throw new ITMException(e);
		}
		finally
		{
			if ( requirementICRemote != null )
			{
				requirementICRemote = null;
			}						
		}
		return itemCodeData;
	}
	private String getXSLFileName( String xslFileName )throws ITMException
	{   
		String retFileName = null;
		try
		{
			String defaultPath = null;
			if( CommonConstants.APPLICATION_CONTEXT != null )
			{
				defaultPath = CommonConstants.APPLICATION_CONTEXT + CommonConstants.ITM_CONTEXT + File.separator;
			}
			else
			{
				defaultPath = ".." + File.separator + "webapps" + File.separator + "ibase" + File.separator + CommonConstants.ITM_CONTEXT + File.separator;
			}
			File xslPath = new File( defaultPath + File.separator  + "xsl" + File.separator + CommonConstants.THEME + File.separator + "WIZARD");
			if ( !xslPath.exists() )
			{
				xslPath.mkdir();
			}
			System.out.println( " xslPath [" + xslPath +"] xslFileName ["+xslFileName +"]");
			File xslFile = new File(xslPath , xslFileName);
			if( xslFile.exists() )
			{
				retFileName = xslFile.getAbsolutePath();
			}
			else
			{
				throw new ITMException( new Exception( retFileName + " Wizard XSL file Not Found") );	
			}
		}
		catch (Exception e)
		{
			throw new ITMException(e);
		}
		return retFileName;
	}



	// end

	public String mrpwizardAllocateQty(String xmlString1 , String locGroup , String QuantityReq, String dueDate , String currentSorder, String currentItemCode )throws ITMException
	{
		Document dom = null;
		System.out.println("@@@@@@@@@---------mrpwizardAllocateQty EJB called...");
		String returnXml="";

		try
		{
			System.out.println("@@@@@@@xmlString1["+xmlString1+"]@@@@@@@");

			System.out.println("@@@@@@ in bean locGroup["+locGroup+"]QuantityReq["+QuantityReq+"]dueDate["+dueDate+"]currentSorder["+currentSorder+"]currentItemCode["+currentItemCode+"]");

			if (xmlString1 != null && xmlString1.trim().length() > 0)
			{
				dom = GenericUtility.getInstance().parseString(xmlString1);
				returnXml = mrpwizardAllocateQty(dom, locGroup, QuantityReq, dueDate , currentSorder, currentItemCode);
			}	


		}
		catch(Exception e)
		{
			System.out.println("Exception :mrpwizardAllocateQty ::" + e.getMessage() + ":");
			e.printStackTrace();
			throw new ITMException(e);
		}
		System.out.println("@@@@@@@@@ returnXml["+returnXml+"]");
		return returnXml;
	}

	private String mrpwizardAllocateQty(Document dom , String locGroup , String QuantityReq , String dueDate , String currentSorder, String currentItemCode)throws ITMException
	{
		PreparedStatement pstmt = null, pstmt1 = null, pstmt2 = null;
		String sql = "", itemCode = "", effDate = "", itemSer = "", sql1="", sql2="";
		int updCnt = 0;
		GenericUtility genericUtility = GenericUtility.getInstance();
		NodeList hdrDom = null;
		//Node currDetail = null;
		ResultSet rs1 = null, rs2 = null;
		String saleOrder="",lineNo="", siteCode="", lotNo="", locCode="", lotSl="", tranSer="", runningSupplyStr="", qtyReqdStr="",allocQtyStr="";
		double runningSupply=0,qtyReqd=0;
		String tranId="",refId="",refLineNo="",unit="",errString="";
		double quantity=0,qtyAllocated=0,totAllocQty=0,allocQty=0,supply=0,availableSupply=0;
		int cnt=0;
		Connection conn = null;
		ConnDriver connDriver = new ConnDriver(); 
		String supplyStr="",availableSupplyStr="" ,suppSour="",remarks=" ";

		ArrayList retValue = new ArrayList();

		java.util.Date currentDate = new java.util.Date();
		//	SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
		//	Timestamp newsysDate = java.sql.Timestamp.valueOf( sdf.format(currentDate)+" 00:00:00.0");
		//	System.out.println("Now the date is :=>  ["+newsysDate+"]");
		java.sql.Date date = new java.sql.Date(currentDate.getTime());
		String parentItem="",prevItemWorder="",previousItem="";


		ArrayList itemValueList = new ArrayList();
		String selectedItemHtml="";
		ArrayList<String> locCodeGrpList= new ArrayList<String>();

		TreeMap<String, ArrayList<String>> allocationMap = new TreeMap<String, ArrayList<String>>();
		String allocPref="",key="";
		try
		{
			conn = connDriver.getConnectDB("DriverITM");

			NodeList hdrDommList = dom.getElementsByTagName("Detail4");
			System.out.println("len===["+hdrDommList.getLength()+"]locGroup["+locGroup+"]QuantityReq["+QuantityReq+"]dueDate["+dueDate+"]");

			double QuantityRequired =  Double.parseDouble(QuantityReq==null?"0":QuantityReq);

			sql1=" select  distinct loc_code from location where loc_group = ? ";   
			pstmt1=conn.prepareStatement(sql1);
			pstmt1.setString(1,locGroup);
			rs1 = pstmt1.executeQuery();
			while(rs1.next())
			{
				locCodeGrpList.add(rs1.getString("loc_code"));
			}
			rs1.close();
			rs1=null;
			pstmt1.close();
			pstmt1=null;

			System.out.println("locCodeGrpList["+locCodeGrpList+"]");

			int lineCounter=0;
			for (int dtlCtr = 0; dtlCtr < hdrDommList.getLength(); dtlCtr++)
			{
				lineCounter++;
				Node detailListNode = hdrDommList.item(dtlCtr);
				NodeList detail4List= detailListNode.getChildNodes(); 
				System.out.println("@@@@@@@@@node name[" + detailListNode.getNodeName()+"]");

				if("Detail4".equalsIgnoreCase(detailListNode.getNodeName()))
				{
					System.out.println("@@@@inside detail4----------------");
					for (int cntr = 0; cntr < detail4List.getLength(); cntr++) 
					{
						Node	detail4Node = detail4List.item(cntr); 
						//NodeList detail4NodeList = detail4Node.getChildNodes(); 
						System.out.println("@@@@@@@@@node name[" + detail4Node.getNodeName()+"]"); 

						// if(  detail4Node != null  &&  detail4Node.getNodeValue() != null )
						{
							if("sale_order".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									saleOrder =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									saleOrder= "";
								}
							}
							if("line_no".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									lineNo =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									lineNo= "";
								}
							}
							if("site_code".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									siteCode =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									siteCode= "";
								}
							}
							if("item_code".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									itemCode =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									itemCode= "";
								}
							}
							if("lot_no".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									lotNo =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									lotNo= "";
								}
							}
							if("lot_sl".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									lotSl =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									lotSl= "";
								}
							}
							if("loc_code".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									locCode =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									locCode= "";
								}
							}
							if("tran_ser".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									tranSer =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									tranSer= "";
								}
							}
							if("running_supply".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									runningSupplyStr =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									runningSupplyStr= "0";
								}
							}
							if("qty_reqd".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									qtyReqdStr =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									qtyReqdStr= "0";
								}
							}
							if("alloc_qty".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									allocQtyStr =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									allocQtyStr= "0";
								}
							}
							if("supply".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									supplyStr =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									supplyStr= "";
								}
							}
							if("available_supply".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									availableSupplyStr =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									availableSupplyStr= "";
								}
							}
							if("supp_sour".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									suppSour =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									suppSour= "";
								}
							}
							if("parent_item".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if( detail4List.item(cntr).getFirstChild() != null)
								{
									parentItem =  detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									parentItem= "";
								}
							}

							if("prev_item_worder".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if(detail4List.item(cntr).getFirstChild()!=null)
								{
									prevItemWorder = detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									prevItemWorder="";
								}
							}
							if("previous_item".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if(detail4List.item(cntr).getFirstChild()!=null)
								{
									previousItem = detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									previousItem = "";
								}
							}
							if("alloc_pref".equalsIgnoreCase( detail4Node.getNodeName()))
							{
								if(detail4List.item(cntr).getFirstChild()!=null)
								{
									allocPref = detail4List.item(cntr).getFirstChild().getNodeValue();
								}
								else
								{
									allocPref = "";
								}
							}
						}
					}
					System.out.println("@@@@@@@@itemCode["+itemCode+"]currentItemCode["+currentItemCode+"] ");
					if(  itemCode.trim().equalsIgnoreCase(currentItemCode.trim()) )
					{
						saleOrder = saleOrder==null?"":saleOrder.trim();
						lineNo = lineNo==null?"":lineNo.trim();

						System.out.println("cpatil@@@@lineCounter["+lineCounter+"]ctr["+dtlCtr+"]saleOrder["+saleOrder+"]-lineNo["+lineNo+"]-" +
						"qtyReqd["+qtyReqdStr+"]prevItemWorder["+prevItemWorder+"]previousItem["+previousItem+"]@@@");
						System.out.println("@@@@ctr["+dtlCtr+"]siteCode["+siteCode+"]-itemCode["+itemCode+"]" +
								"-lotNo["+lotNo+"]-lotSl["+lotSl+"]-locCode["+locCode+"]-tranSer["+tranSer+"]" +
								"allocQtyStr["+allocQtyStr+"]allocPref["+allocPref+"]" +
								"availableSupplyStr["+availableSupplyStr+"]supplyStr["+supplyStr+"]@@@");

						String stockInfo="";


						if( locCodeGrpList.contains(locCode))
						{
							key = "A1";
						}
						else
						{
							key = "B"+allocPref;
						}
						//System.out.println("key["+key+"]");
						stockInfo = siteCode+"@"+itemCode+"@"+lotNo+"@"+lotSl+"@"+locCode+"@" +
								""+tranSer+"@"+runningSupplyStr+"@"+qtyReqdStr+"@"+allocQtyStr+"@"+supplyStr+"@" +
								""+suppSour+"@"+parentItem+"@" +prevItemWorder+"@"+previousItem+"@"+lineCounter;
						System.out.println("key["+key+"]stockInfo["+stockInfo+"]");
						ArrayList<String> tempAllocationList = new ArrayList<String>(); 
						if(allocationMap.containsKey(key))
						{
							tempAllocationList = allocationMap.get(key);
							tempAllocationList.add(stockInfo);
						}
						else
						{
							tempAllocationList.add(stockInfo);
						}
						
						allocationMap.put(key, tempAllocationList);
					}
				}
			}
			// prepare xml from treemap
			ArrayList<String> tempList = new ArrayList<String>();
			String dtlCtr="";
			double QuantityReqAllocate=0;

			System.out.println("@@@@@final---allocationMap["+allocationMap+"]QuantityReqAllocate["+QuantityReqAllocate+"]");

			Set s1=allocationMap.entrySet(); 
			Iterator itr=s1.iterator();

			while(itr.hasNext())
			{ 
				//System.out.println("@@@@@final---keyMap["+keyMap+"]@@@@@@@");
				Map.Entry m=(Map.Entry)itr.next(); 
				{ 
					//System.out.println("@@@@@@@@@@@m["+m+"]@@@@@@@@@");
					tempList = new ArrayList();	
					String keyListStr =  m.getKey().toString(); 
					System.out.println("@@@@@keyListStr["+keyListStr+"]");
					tempList =   (ArrayList) allocationMap.get(keyListStr);

					for( int i=0; i < tempList.size(); i++)
					{
						String[] keyStr = tempList.get(i).split("@"); 
						System.out.println("@@@@@ i["+i+"] keyStr["+keyStr+"]");
						siteCode =  keyStr[0];  
						itemCode =  keyStr[1]; 
						lotNo =  keyStr[2];  
						lotSl =  keyStr[3];   
						locCode =  keyStr[4];  
						tranSer = keyStr[5];
						runningSupplyStr =  keyStr[6];  
						qtyReqdStr =  keyStr[7];   
						allocQtyStr =  keyStr[8];  
						availableSupplyStr =  keyStr[9];  
						suppSour =  keyStr[10];  
						parentItem = keyStr[11];
						prevItemWorder =  keyStr[12]; 
						previousItem =  keyStr[13]; 
						lineCounter =  Integer.parseInt(keyStr[14]); 

						if( runningSupplyStr.trim().length() > 0)
						{
							runningSupply = runningSupplyStr==null?0:Double.parseDouble(runningSupplyStr);
						}
						if( qtyReqdStr.trim().length() > 0)
						{
							qtyReqd = qtyReqdStr==null?0:Double.parseDouble(qtyReqdStr);
						}
						if( allocQtyStr.trim().length() > 0)
						{
							allocQty = allocQtyStr==null?0:Double.parseDouble(allocQtyStr);
						}

						if( supplyStr.trim().length() > 0)
						{
							supply = supplyStr==null?0:Double.parseDouble(supplyStr);
						}
						if( availableSupplyStr.trim().length() > 0)
						{
							availableSupply = availableSupplyStr==null?0:Double.parseDouble(availableSupplyStr);
						}
						System.out.println("@@@@@513::supply["+supply+"]:availableSupply["+availableSupply+"]QuantityRequired["+QuantityRequired+"]");
						if( availableSupply > 0  && QuantityRequired > 0 )
						{
							if( availableSupply >= QuantityRequired )
							{
								QuantityReqAllocate = QuantityRequired;
								QuantityRequired=0;
							}
							else
							{
								QuantityReqAllocate = availableSupply;
								QuantityRequired= QuantityRequired-QuantityReqAllocate;
							}
						}
						else
						{
							QuantityReqAllocate = 0;
						}

						if( saleOrder == null || saleOrder.trim().length() == 0 )
						{
							saleOrder = currentSorder ;
						}
						System.out.println("@@@@@531:::QuantityReqAllocate["+QuantityReqAllocate+"]dueDate["+dueDate+"]dtlCtr["+dtlCtr+"]");
						//dtlCtr++;
						selectedItemHtml = selectedItemHtml +                        //Detail4.PORF0006..3.11/03/13.item_code
								//"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dtlCtr+"."+dueDate+".sale_order' id='Detail4." +saleOrder+"."+lineNo+"."+dtlCtr+"."+dueDate+".sale_order' value='" + saleOrder + "'></INPUT>"+
								//"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dtlCtr+"."+dueDate+".line_no' id='Detail4." +saleOrder+"."+lineNo+"."+dtlCtr+"."+dueDate+".line_no' value='" + lineNo + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".item_code' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".item_code' value='" + itemCode + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".qty_reqd' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".qty_reqd' value='" + qtyReqd + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".site_code' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".site_code' value='" + siteCode + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".lot_no' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".lot_no' value='" + lotNo + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".lot_sl' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".lot_sl' value='" + lotSl + "'></INPUT>" +
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".loc_code' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".loc_code' value='" + locCode + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".tran_ser' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".tran_ser' value='" + tranSer + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".tran_id' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".tran_id' value='" + tranId + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".ref_line_no' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".ref_line_no' value='" + refLineNo + "'></INPUT>"+
								//"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".supply' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".supply' value='" + ( availableSupply - QuantityReqAllocate ) + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".supply' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".supply' value='" +  availableSupply  + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".available_supply' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".available_supply' value='" + availableSupply + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".parent_item' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".parent_item' value='" + parentItem + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".prev_item_worder' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".prev_item_worder' value='" + prevItemWorder + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".previous_item' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".previous_item' value='" + previousItem + "'></INPUT>"+
								"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".alloc_qty' id='Detail4." +saleOrder+"."+lineNo+"."+lineCounter+"."+dueDate+".alloc_qty' value='" + QuantityReqAllocate + "'></INPUT>";
						System.out.println("@@@@@@@@ lineCounter["+lineCounter+"]QuantityReqAllocate["+QuantityReqAllocate+"] for itemCode["+itemCode+"]locCode["+locCode+"]lotNo["+lotNo+"]lotSl["+lotSl+"]saleOrder["+saleOrder+"]lineNo["+lineNo+"]");
					}
				}
			}

			System.out.println("@@@@@@@@@@@@@@ in jsp selectedItemHtml["+selectedItemHtml+"]");



		}//try end
		catch (SQLException sqx)
		{
			System.out.println("The SQLException occurs in MrpWizPrsSaveBean :"+sqx);
			sqx.printStackTrace();
			throw new ITMException(sqx);
		}
		catch(Exception e)
		{
			System.out.println("The SQLException occurs in MrpWizPrsSaveBean  :"+e);			
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally 
		{
			try
			{

				if (errString == null || errString.trim().length() == 0)
				{
					System.out.println("@@@@@@commit errString :::"+ errString );
					conn.commit();
					//return errString;
				}

				if (pstmt!= null)
				{
					pstmt = null;
				}
				if( conn != null )
				{
					conn.close();
					conn=null;
				}
			}
			catch(Exception e)
			{
				System.out.println("The SQLException occurs in MrpWizPrsSaveBean  :"+e);			
				e.printStackTrace();
				throw new ITMException(e);
			}
		}
		return selectedItemHtml;
	}








}