package ibase.webitm.ejb.mfg;


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


import org.w3c.dom.*;

import java.text.SimpleDateFormat;

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 MRPWizardXmlDataBean 
{

	boolean isBomReplace = false;

	public String getXmlData(String xmlString1 )throws ITMException
	{
		Document dom = null;
		String xmldata="";
		System.out.println("@@@@@@@@@---------MRPWizardXmlDataBean EJB called...");
		try
		{
			System.out.println("@@@@@@@ getXmlData === xmlString1::::::["+xmlString1+"]@@@@@@@");
			if (xmlString1 != null && xmlString1.trim().length() > 0)
			{
				dom = GenericUtility.getInstance().parseString(xmlString1);
				xmldata = getXmlData(dom);
			}			
		}
		catch(Exception e)
		{
			System.out.println("Exception :MRPWizardXmlDataBean ::" + e.getMessage() + ":");
			e.printStackTrace();
			throw new ITMException(e);
		}

		System.out.println("@@@@@@@@@return xmldata[["+xmldata+"]]");

		return xmldata;
	}


	private String getXmlData(Document dom )throws ITMException
	{
		PreparedStatement pstmt = null;
		String sql = "", itemCode = "", effDate = "", itemSer = "";
		int updCnt = 0;
		//java.util.Date effDate1 = null, preDate = null;
		GenericUtility genericUtility = GenericUtility.getInstance();
		NodeList hdrDom = null;
		//Node currDetail = null;

		String saleOrder="",lineNo="", siteCode="", lotNo="", locCode="", lotSl="", tranSer="", runningSupplyStr="", qtyReqdStr="",allocQtyStr="";
		double runningSupply=0,qtyReqd=0;
		String tranId="",refId="",refLineNo="",unit="",errString="",bomCodeParent="",sourceSupplyRef="";
		int cnt=0;
		Connection conn = null;
		ConnDriver connDriver = new ConnDriver(); 

		String xmldata="",bomCodeOrg="",itemCodeDescr="",bomCodeRef="";

		ArrayList replaceBomItemList = new ArrayList();
		ArrayList deleteBomList = new ArrayList();
		ArrayList deleteSaleOrderList = new ArrayList();


		NodeList orderList=null; 
		NodeList orderList1=null;
		//Node mrpGetDataNode =null, referenceChildNode=null, Detail4ChildNode=null,mrpGetDataNode2=null;
		RunMRPPrc runMRPObj = new RunMRPPrc();

		int i=0,domCnt=0;
		String suppSour="",originalOrAltitem="",sourceSupply="";

		String itemCodeDetailMapStr="";
		HashMap itemCodeDetailMap = new HashMap();


		String siteCodeSupp="",itemCodeSupp="",parentItem="",demand="",supply="",planSupply="",runningDemand="",runningPlanSupply="";
		String independentDemand="",stockQty="",othSupply="",pendingPo="",pendingDo="",pendingIndent="",pendingDr="",itemCodeParent="";
		String bomCode="",dueDate="",orderOpt="",minOrderQty="",batchQtyType="",integralQty="",purLeadTime="";
		String reorderQty="",minPlanPerc="",maxQty="",minQty="",batchQty="",yieldPerc="",mfgLeadTime="",description="",qcLeadTime="";
		int domCnt2=0;
		Document mrpGetDataDom = null;

		String Deatail4SiteCode="",Deatail4LotNo="",Deatail4LocCode="",Deatail4LotSl="",Deatail4AllocQty="",Deatail4TranId="";
		String Deatail4ItemCode="",Deatail4Unit="",Deatail4TranSer="",Deatail4RefLineNo="",Deatail4Supply="",Deatail4ParentItem="";
		String Deatail4SourceSupply="",Deatail4PlannedQuantity="",Deatail4ItemCodeDescr="",Deatail4ItemCodeParent="";
		String allocQty="",plannedQuantity="";

		HashMap detail4ListMap = new HashMap();
		//System.out.println("@@@ initiaalize detail4ListMap...");

		String locGroup="",mfgType="",other="",grossWeight="",netReq="",orderType="",currentSorder="",itemDetailsInfo="";

		String sodemand="";
		int nextDomId = 0,soItemListCnt=0;

		String altItemPerc="",soItemList="",itemCodeSuppDescr="",locGroupList="";
		try
		{
			conn = connDriver.getConnectDB("DriverITM");

			NodeList hdrDommList = dom.getElementsByTagName("Detail2");
			System.out.println("len===["+hdrDommList.getLength()+"]");

			nextDomId = hdrDommList.getLength();
			System.out.println("@@@@ nextDomId["+nextDomId+"]");
			//// for test

			for (int dtlCtr = 0; dtlCtr < hdrDommList.getLength(); dtlCtr++)
			{
				Node detailListNode = hdrDommList.item(dtlCtr);

				/*
				if("Detail2".equalsIgnoreCase(detailListNode.getNodeName()))
				{
					detail2Flag = true;
					detail2keyList = new ArrayList();

					for (int cntr = 0; cntr < refrenceList.getLength(); cntr++) 
					{
						Node	refrenceNode = refrenceList.item(cntr); 
						orderList = refrenceNode.getChildNodes(); 
						//System.out.println("@@@@@@@@@refrenceNode node name[" + refrenceNode.getNodeName()+"]"); 

						if("sale_order".equalsIgnoreCase(refrenceNode.getNodeName())) 
						{
							saleOrder =  refrenceList.item(cntr).getFirstChild().getNodeValue();
							System.out.println("saleOrder["+saleOrder+"]");
						}
				 */
				if("Detail2".equalsIgnoreCase(detailListNode.getNodeName()))
				{
					ArrayList detail4OuterList = new ArrayList();
					NodeList refrenceList= detailListNode.getChildNodes();
					for (int cntr1 = 0; cntr1 < refrenceList.getLength(); cntr1++) 
					{
						Node	refrenceNode = refrenceList.item(cntr1); 
						orderList = refrenceNode.getChildNodes(); 
						System.out.println("@@@@@@@@ detail2 node :::  refrenceNode.getNodeName()["+ refrenceNode.getNodeName()+"]");
						if("sale_order".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							saleOrder =  refrenceNode.getTextContent();
						}
						if("line_no".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							lineNo  =  refrenceNode.getTextContent();
							System.out.println("@@@@@@@@ lineNo["+lineNo+"] found....");
						}
						if("item_code".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							itemCode  =  refrenceNode.getTextContent();
						}
						if("bom_code_org".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							bomCodeOrg =  refrenceNode.getTextContent();
						}
						if("bom_code_ref".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							bomCodeRef  =  refrenceNode.getTextContent();
						}
						if("loc_group".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							locGroup  =  refrenceNode.getTextContent();
							System.out.println("@@@@@@@@ locGroup["+locGroup+"] found....");
						}



						String LineNo =  "",QtyReqd =  "",ItemCodeDescr =  "",AvailableSupply =  "",OriginalOrAltitem =  "";
						String QuantityFlag =  "",PrevItemWorder =  "",PreviousItem =  "",NewPlannedSupply =  "",DueDate =  "",AllocPref =  "";
						altItemPerc="";
						if("Detail4".equalsIgnoreCase(refrenceNode.getNodeName()))
						{
							System.out.println("@@@@@@ inside Detail4 :::itemCode["+itemCode+"]");
							//orderList1 = refrenceNode.getChildNodes();
							for (int nodCtr1 = 0; nodCtr1 < orderList.getLength(); nodCtr1++) 
							{
								Node detail4Node2=orderList.item(nodCtr1); 
								//System.out.println("node in detail4 ["+detail4Node2.getNodeName()+"]");
								{
									if( detail4Node2.getFirstChild() != null)
									{
										if("site_code".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											siteCodeSupp =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("item_code".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											itemCodeSupp =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("item_code_descr".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											itemCodeDescr =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("lot_no".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											lotNo =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("lot_sl".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											lotSl =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("loc_code".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											locCode =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("tran_ser".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											tranSer =  detail4Node2.getFirstChild().getNodeValue();
										}   
										if("tran_id".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											tranId =  detail4Node2.getFirstChild().getNodeValue();
										} 
										if("supply".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											supply =  detail4Node2.getFirstChild().getNodeValue();
										} 
										if("alloc_qty".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											allocQty =  detail4Node2.getFirstChild().getNodeValue();
										} 
										if("unit".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											unit =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("ref_line_no".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											refLineNo =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("planned_quantity".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											plannedQuantity =  detail4Node2.getFirstChild().getNodeValue();
										} 
										if("parent_item".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											parentItem =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("source_supply".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											sourceSupply =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("item_code_parent".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											itemCodeParent =  detail4Node2.getFirstChild().getNodeValue();
										}



										if("sale_order".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											saleOrder =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("line_no".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											LineNo =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("qty_reqd".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											QtyReqd =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("item_code_descr".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											ItemCodeDescr =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("available_supply".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											AvailableSupply =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("originalOrAltitem".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											OriginalOrAltitem =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("quantityFlag".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											QuantityFlag =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("prev_item_worder".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											PrevItemWorder =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("previous_item".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											PreviousItem =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("new_planned_supply".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											NewPlannedSupply =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("due_date".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											DueDate =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("alloc_pref".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											AllocPref =  detail4Node2.getFirstChild().getNodeValue(); 
										}

										if("alt_item_perc".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											altItemPerc =  detail4Node2.getFirstChild().getNodeValue(); 
										}

									}								
								}
							}

							System.out.println("@@@@ for list ctr["+dtlCtr+"]itemCodeSupp["+itemCodeSupp+"]sourceSupply["+sourceSupply+"]siteCodeSupp["+siteCodeSupp+"]-itemCodeSupp["+itemCodeSupp+"]-lotNo["+lotNo+"]-lotSl["+lotSl+"]-locCode["+locCode+"]-tranSer["+tranSer+"]originalOrAltitem["+originalOrAltitem+"]@@@");

							//detail4List.clear();
							ArrayList detail4List = new ArrayList();

							detail4List.add(siteCodeSupp);  
							detail4List.add(itemCodeSupp );
							detail4List.add(itemCodeDescr );
							detail4List.add(lotNo  );
							detail4List.add(lotSl  );
							detail4List.add(locCode  );
							detail4List.add(tranSer );
							detail4List.add(tranId );
							detail4List.add(supply );
							detail4List.add(allocQty );
							detail4List.add(unit  );
							detail4List.add(refLineNo);  
							detail4List.add(plannedQuantity); 
							detail4List.add(parentItem  );
							detail4List.add(sourceSupply  );
							detail4List.add(itemCodeParent );

							detail4List.add(saleOrder);
							detail4List.add(LineNo);
							detail4List.add(QtyReqd );
							detail4List.add(ItemCodeDescr ); 
							detail4List.add(AvailableSupply );
							detail4List.add(OriginalOrAltitem );
							detail4List.add(QuantityFlag ); 
							detail4List.add(PrevItemWorder ); 
							detail4List.add(PreviousItem ); 
							detail4List.add(NewPlannedSupply );
							detail4List.add(DueDate ); 
							detail4List.add(AllocPref);

							detail4List.add(altItemPerc);

							System.out.println("detail4List["+detail4List+"]");
							detail4OuterList.add(detail4List);
							//System.out.println("detail4List added");
						}
					}

					System.out.println("for delete compare ::: bomCodeOrg["+bomCodeOrg+"]bomCodeRef["+bomCodeRef+"]");

					if( bomCodeOrg != null && bomCodeRef != null &&  bomCodeOrg.trim().length() > 0 && bomCodeRef.trim().length() > 0  )
					{
						if( !(bomCodeOrg.equalsIgnoreCase(bomCodeRef)))
						{
							System.out.println("@@@@@@@@ bomCodeOrg ["+bomCodeOrg+"] added in deleteBomList ");
							if(! (deleteBomList.contains(bomCodeOrg) ))
							{
								deleteBomList.add(bomCodeOrg);
							}
							if( !(deleteSaleOrderList.contains(saleOrder+"@"+lineNo)))
							{
								deleteSaleOrderList.add(saleOrder+"@"+lineNo);
							}
							// String returnBom = runMRPObj.bomExplode(siteCode, bomCodeRef);
						}
					}

//					start 24/03/15 in urse by cpatil

					System.out.println("soItemListCnt["+soItemListCnt+"]saleOrder["+saleOrder+"]itemCode["+itemCode+"]soItemList["+soItemList+"]locGroup["+locGroup+"]");
					if( saleOrder != null && saleOrder.trim().length() > 0 && itemCode != null && itemCode.trim().length() > 0)
					{
						if(!( soItemList.contains(saleOrder+"@"+itemCode) ))
						{
							if(soItemListCnt > 0)
							{
								soItemList = soItemList + ","+saleOrder+"@"+itemCode+"" ;
								soItemListCnt++;
							}
							else
							{
								soItemList = saleOrder+"@"+itemCode ;
								soItemListCnt++;
							}
						}
					}
					System.out.println("@@@@@@ final :::soItemList in recalculate::["+soItemList+"]");

					if( saleOrder != null && saleOrder.trim().length() > 0 && locGroup != null && locGroup.trim().length() > 0)
					{
						if( locGroupList != null && locGroupList.trim().length() > 0)
						{	//locGroupList = locGroupList + ",'"+saleOrder+itemCode+"@"+locGroup+"'" ;
							locGroupList = locGroupList + ","+checkNull(saleOrder).trim()+"@"+checkNull(locGroup).trim()+"" ;
						}
						else
						{
							//locGroupList =  "'"+saleOrder+itemCode+"@"+locGroup+"'" ;
							locGroupList =  ""+checkNull(saleOrder).trim()+"@"+checkNull(locGroup).trim()+"" ;
						}
					}
					System.out.println("@@@@@@ final :::locGroupList in recalculate::["+locGroupList+"]");
					// end

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

					if( detail4OuterList != null && detail4OuterList.size() > 0 )
					{
						//System.out.println("before addedd.."+saleOrder+lineNo+itemCode+".detail4ListMap["+detail4ListMap+"]");
						detail4ListMap.put(saleOrder+lineNo+itemCode, detail4OuterList);
						System.out.println("after addedd.."+saleOrder+lineNo+itemCode+".detail4ListMap["+detail4ListMap+"]");
						// detail4OuterList.clear();
					}
				}
			}	

			// end	
			System.out.println("@@@@@@@@ deleteBomList["+deleteBomList+"]deleteSaleOrderList["+deleteSaleOrderList+"]detail4ListMap["+detail4ListMap+"]");
			//// start new test

			StringBuffer valueXmlString = new StringBuffer();
			valueXmlString = new StringBuffer("<?xml version = \"1.0\"?><Root>\r\n");

			for (int dtlCtr = 0; dtlCtr < hdrDommList.getLength(); dtlCtr++)
			{
				Node detailListNode = hdrDommList.item(dtlCtr);
				NodeList refrenceList= detailListNode.getChildNodes();
				if("Detail2".equalsIgnoreCase(detailListNode.getNodeName()))
				{

					for (int cntr1 = 0; cntr1 < refrenceList.getLength(); cntr1++) 
					{
						Node	refrenceNode = refrenceList.item(cntr1); 
						orderList = refrenceNode.getChildNodes(); 
						System.out.println("344@@@@@@@@  refrenceNode.getNodeName()[ "+ refrenceNode.getNodeName()+"]");
						if("supp_sour".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							suppSour =  refrenceNode.getTextContent();
						}
						if("sale_order".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							saleOrder =  refrenceNode.getTextContent();
							System.out.println("352@@@@@@@@ saleOrder["+saleOrder+"]");
						}
						if("line_no".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							lineNo =   refrenceNode.getTextContent();
						}
						if("site_code".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							siteCode =  refrenceNode.getTextContent(); 
						}
						if("bom_code_parent".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							bomCodeParent =  refrenceNode.getTextContent();
						}
						if("bom_code_org".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							bomCodeOrg =  refrenceNode.getTextContent();
						}
						if("bom_code_ref".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							bomCodeRef  =  refrenceNode.getTextContent();
						}
						if("item_code".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							itemCode =  refrenceNode.getTextContent();
						}
						if("item_code_descr".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							itemCodeDescr =  refrenceNode.getTextContent();
						}
						if("qty_reqd".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							qtyReqdStr =  refrenceNode.getTextContent();
						}
						if("unit".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							unit =  refrenceNode.getTextContent();
						}
						if("source_supply".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							sourceSupply =  refrenceNode.getTextContent();
						}
						if("source_supply_ref".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							sourceSupplyRef =  refrenceNode.getTextContent();
						}

						if("itemCodeDetailMap".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							itemCodeDetailMapStr =  refrenceNode.getTextContent();
							System.out.println("@@@@@@ itemCodeDetailMapStr["+itemCodeDetailMapStr+"]");
						}

						// 230115


						//new tag
						if("mfg_type".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							mfgType =  refrenceNode.getTextContent();
						}
						if("demand".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							demand =  refrenceNode.getTextContent();
						}						
						if("other".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							other =  refrenceNode.getTextContent();
						}
						if("gross_weight".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							grossWeight =  refrenceNode.getTextContent();
						}

						if("supply".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							supply =  refrenceNode.getTextContent();
						}
						if("net_req".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							netReq =  refrenceNode.getTextContent();
						}
						if("order_type".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							orderType =  refrenceNode.getTextContent();
						}

						if("current_sorder".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							currentSorder =  refrenceNode.getTextContent();
						}
						if("item_code_descr".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							itemCodeDescr =  refrenceNode.getTextContent();
						}
						if("due_date".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							dueDate =  refrenceNode.getTextContent();
						}
						if("loc_group".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							locGroup =  refrenceNode.getTextContent();
						}
						if("itemDetailsInfo".equalsIgnoreCase( refrenceNode.getNodeName()))
						{
							itemDetailsInfo =  refrenceNode.getTextContent();
						}
						// end new tag






						//230115

					}

					//	}
					System.out.println("@@@@ saleOrder["+saleOrder+"]-lineNo["+lineNo+"]-qtyReqd["+qtyReqdStr+"]sourceSupply["+sourceSupply+"]locGroup["+locGroup+"]@@@");
					System.out.println("@@@@ siteCode["+siteCode+"]-itemCode["+itemCode+"]-bomCodeOrg["+bomCodeOrg+"]-bomCodeRef["+bomCodeRef+"]bomCodeParent["+bomCodeParent+"]");
					System.out.println("@@@@@ itemCodeDetailMap in bean itemCodeDetailMapStr["+itemCodeDetailMapStr+"]bomCodeRef["+bomCodeRef+"]");
					System.out.println("@@@@@ itemCodeDetailMap in bean deleteBomList["+deleteBomList+"]deleteSaleOrderList["+deleteSaleOrderList+"]");

					if( itemCodeDetailMapStr != null && ( ! bomCodeOrg.equalsIgnoreCase(bomCodeRef)) )
					{
						itemCodeDetailMapStr = bomCodeParent;
					}
					System.out.println("@@@@@ itemCodeDetailMap in bean itemCode["+itemCode+"]bomCodeParent["+bomCodeParent+"]deleteBomList["+deleteBomList+"]deleteSaleOrderList["+deleteSaleOrderList+"]saleOrder@lineNo["+saleOrder+"@"+lineNo+"]bomCodeRef["+bomCodeRef+"]bomCodeOrg["+bomCodeOrg+"]");

					//if( !( ( deleteBomList.contains(bomCodeParent.trim())  )  && deleteSaleOrderList.contains(saleOrder+"@"+lineNo))  )
					if( !(  deleteBomList.contains(bomCodeParent.trim())  )  )
					{   // ||
						System.out.println("@@@@@ itemCodeDetailMapitemCode["+itemCode+"]deleteBomList["+deleteBomList+"]bomCodeOrg["+bomCodeOrg+"]");
						//if( !(deleteBomList.contains(bomCodeOrg)) ) 
						//{
						System.out.println("14/06/14 supreme  1 inside itemCode ["+itemCode+"]bomCodeRef["+bomCodeRef+"] suppSour [" + suppSour+"]itemCodeDetailMapStr["+itemCodeDetailMapStr+"]bomCodeParent["+bomCodeParent+"]bomCodeOrg["+bomCodeOrg+"]");
						ArrayList tempdetail4OuterList = new ArrayList();
						ArrayList tempdetail4List = new ArrayList();

						//System.out.println("@@@@ inside first if....");
						if( ( (bomCodeRef != null  && bomCodeRef.trim().length() > 0 ) ) 
								&& ( (itemCodeDetailMapStr.contains(bomCodeParent)) 
										&& ( !bomCodeOrg.equalsIgnoreCase(bomCodeRef)) ) )  
						{

							System.out.println("@@@@@@@@ before recalculate valueXmlString ["+valueXmlString.toString()+"]soItemList["+soItemList+"]locGroupList["+locGroupList+"]");

							System.out.println("14/06/14 supreme  2 inside itemCode ["+itemCode+"]bomCodeRef["+bomCodeRef+"] suppSour [" + suppSour+"]bomCodeOrg["+bomCodeOrg+"]");
							System.out.println("14/06/14 Before recalculate itemCode {" + itemCode +"] bomCodeRef [" + bomCodeRef + "] bomCodeParent [" + bomCodeParent+ "]dueDate["+dueDate+"]" );

							Document argDom = null;
							NodeList parentNodeList = null;
							Node parentNode = null;
							String winName="",editFlag="",xtraParams="",mrpGetData="" ;
							Document dom2 = null;
							ResultSet rs = null;

							//Timestamp dateFr = java.sql.Timestamp.valueOf(genericUtility.getValidDateString(dueDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00");


							System.out.println("456 @@@@@@@@@ exsting order deleted next...duedate["+dueDate+"]..finish..errString["+errString+"]");

							SimpleDateFormat simpleDateFormat = null;
							simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());

							StringBuffer argData = new StringBuffer();
							argData = new StringBuffer("<?xml version=\"1.0\"?><Root><Header><editFlag>");
							argData.append(editFlag).append("</editFlag></Header>");
							argData.append("<Detail\r\n>");
							argData.append("<site_code>").append(siteCode).append("</site_code>\r\n");
							argData.append("<process_cycle>").append("3").append("</process_cycle>\r\n");
							//argData.append("<run_date>").append(simpleDateFormat.format(new Date())).append("</run_date>\r\n"); // 01-10-2007
							//argData.append("<run_date>").append(simpleDateFormat.format(new Date())).append("</run_date>\r\n"); // 01-10-2007
							argData.append("<run_date>").append(dueDate).append("</run_date>\r\n"); // 01-10-2007
							argData.append("<dis_plan>").append("Y").append("</dis_plan>\r\n");  //N
							argData.append("<mfg_plan>").append("Y").append("</mfg_plan>\r\n");
							argData.append("<mat_plan>").append("Y").append("</mat_plan>\r\n");   // change from N
							argData.append("<made_to_stock>").append("1").append("</made_to_stock>\r\n");  //0
							argData.append("<made_to_order>").append("0").append("</made_to_order>\r\n");
							argData.append("<balance_intersite>").append("N").append("</balance_intersite>\r\n");
							argData.append("<gen_ind>").append("Y").append("</gen_ind>\r\n");   //N
							argData.append("<wizard>").append("2").append("</wizard>\r\n");    //3
							argData.append("<verifier>").append("N").append("</verifier>\r\n");
							argData.append("<isBomReplace>").append("Y").append("</isBomReplace>\r\n");   // added by cpatil on 17/05/14 for BomReplace
							argData.append("<bom_code>").append(bomCodeRef).append("</bom_code>\r\n");   // added by cpatil on 17/05/14 for BomReplace
							argData.append("<bomReplaceDemand>").append(qtyReqdStr).append("</bomReplaceDemand>\r\n");   // added by cpatil on 17/05/14 for BomReplace

							//argData.append("<date_from>").append(simpleDateFormat.format(new Date())).append("</date_from>\r\n"); //  01-10-2007
							//argData.append("<date_to>").append(simpleDateFormat.format(new Date())).append("</date_to>\r\n"); // 01-10-2007

							argData.append("<date_from>").append(dueDate).append("</date_from>\r\n"); // 01-10-2007
							argData.append("<date_to>").append(dueDate).append("</date_to>\r\n"); // 01-10-2007

							argData.append("<saleOrderReplaceBom>").append(saleOrder).append("</saleOrderReplaceBom>\r\n");   // added by cpatil on 17/05/14 for BomReplace
							argData.append("<lineNoReplaceBom>").append(lineNo).append("</lineNoReplaceBom>\r\n");   // added by cpatil on 17/05/14 for BomReplace
							argData.append("<bom_code_parent>").append(bomCodeParent).append("</bom_code_parent>\r\n");   // added by cpatil on 17/05/14 for BomReplace


							argData.append("<site_code__from>").append(siteCode).append("</site_code__from>\r\n");
							argData.append("<site_code__to>").append(siteCode).append("</site_code__to>\r\n");
							argData.append("<item_code__from>").append(itemCode).append("</item_code__from>\r\n");
							argData.append("<item_code__to>").append(itemCode).append("</item_code__to>\r\n");
							argData.append("<item_ser__from>").append("0").append("</item_ser__from>\r\n");
							argData.append("<item_ser__to>").append("ZZ").append("</item_ser__to>\r\n");

							argData.append("<item_code_list>").append("").append("</item_code_list>\r\n");
							argData.append("<soItemList>").append("<![CDATA[").append(soItemList).append("]]>").append("</soItemList>\r\n");
							argData.append("<locGroupList>").append("<![CDATA[").append(locGroupList).append("]]>").append("</locGroupList>\r\n");


							argData.append("</Detail>");
							argData.append("</Root>");

							System.out.println("argData=="+argData);
							argDom = genericUtility.parseString(argData.toString());
							// 13/06/14 manoharan delete line for which bom_code changed
							errString =  runMRPObj.validateFilterParams( argDom );
							if (errString != null && errString.trim().length() > 0)
							{
								System.out.println("Error validating filter parameters:..." + errString);
								return errString;
							}
							errString = runMRPObj.deleteOldPlan (siteCode,itemCode);
							if (errString != null && errString.trim().length() > 0)
							{
								System.out.println("Error validating filter parameters:..." + errString);
								return errString;
							}

							// end 13/06/14 manoharan

							sql = "select bomdet.item_code  from bomdet bomdet, bom bom " +
							"  where bom.bom_code = bomdet.bom_code " +
							"  and bom.bom_code = ? " +
							"  and bom.site_code = ? ";
							pstmt = conn.prepareStatement(sql);
							//pstmt.setString(1, bomCodeRef); // 13/06/14 manoharan
							pstmt.setString(1, bomCodeOrg);
							pstmt.setString(2, siteCode);
							rs = pstmt.executeQuery();
							while (rs.next())
							{
								replaceBomItemList.add(rs.getString(1));


								errString = runMRPObj.deleteOldPlan (siteCode,rs.getString(1));
								if (errString != null && errString.trim().length() > 0)
								{
									System.out.println("Error validating filter parameters:..." + errString);
									return errString;
								}
								//errString = runMRPObj.deleteOldPlan (siteCode,rs.getString(1));
							}
							rs.close(); rs=null;
							pstmt.close(); pstmt=null;
							System.out.println("@@@@@ replaceBomItemList["+replaceBomItemList+"]");



							winName = "w_mrp_run_wiz";
							mrpGetData = runMRPObj.getData(argDom, argDom, winName, xtraParams);
							//	mrpGetData = runMRPObj.getData(argDom, dom2, winName, xtraParams);

							System.out.println("@@@@mrpGetData return string in bean:: after recalculate::["+mrpGetData+"]");

							mrpGetDataDom = genericUtility.parseString(mrpGetData.toString());

							NodeList hdrDommList2 = mrpGetDataDom.getElementsByTagName("Detail2");
							System.out.println("len1===["+hdrDommList2.getLength()+"]");
							for (int dtlCtr2 = 0; dtlCtr2 < hdrDommList2.getLength(); dtlCtr2++)
							{
								Node detailListNode2 = hdrDommList2.item(dtlCtr2);

								if( detailListNode2.hasChildNodes() == true )
								{
									System.out.println("@@@@@@@@for_test detailListNode2.hasChildNodes()["+detailListNode2.hasChildNodes()+"]dtlCtr2["+dtlCtr2+"]");
									qtyReqdStr = "0";
									sourceSupply =  "";
									siteCodeSupp =  "";
									itemCodeSupp =  "";
									itemCodeSuppDescr="";
									itemCodeDescr =  "";
									lotNo =  "";
									lotSl =  "";
									locCode =  "";
									unit =  "";
									parentItem =  ""; 
									tranSer =  "";
									demand =  "";
									supply =  "";
									planSupply =  "0";
									runningDemand =  "0";
									runningSupplyStr =  "0";
									runningPlanSupply =  "0";
									independentDemand =  "0";
									stockQty =  "0"; 
									othSupply =  "0";
									pendingPo =  "0";
									pendingDo =  "0";
									pendingIndent =  "0";
									pendingDr =  "0";
									itemCodeParent =  "";
									originalOrAltitem =  "";
									nextDomId++;
									valueXmlString.append("<Detail2  domID='" + nextDomId + "' >\r\n");
									//domCnt++;
									//300115 valueXmlString.append("<Detail2  domID='" + domCnt + "' >\r\n");

									System.out.println("@@@@@ node name1 ["+detailListNode2.getNodeName()+"]");
									NodeList refrenceList2= detailListNode2.getChildNodes();
									if( refrenceList2 != null )
									{
										System.out.println("refrenceList2.getLength()["+refrenceList2.getLength()+"]");
										for (int cntr2 = 0; cntr2 < refrenceList2.getLength(); cntr2++) 
										{
											System.out.println("@@@@@@@@ inside detail2["+cntr2+"]");
											Node	refrenceNode2 = refrenceList2.item(cntr2); 
											orderList1 = refrenceNode2.getChildNodes(); 
											System.out.println("@@@@@ node name2 ["+refrenceNode2.getNodeName()+"]");

											// for detail4 start
											if("Detail4".equalsIgnoreCase(refrenceNode2.getNodeName()))
											{
												//detail4Flag = true;
												NodeList orderList2 = refrenceNode2.getChildNodes();
												sourceSupply =  "";
												siteCodeSupp =  "";
												itemCodeSupp =  "";
												itemCodeSuppDescr =  "";
												lotNo =  "";
												lotSl =  "";
												locCode =  "";
												unit =  "";
												parentItem =  ""; 
												tranSer =  "";
												//demand =  "";
												supply =  "";
												planSupply =  "0";
												runningDemand =  "0";
												runningSupplyStr =  "0";
												runningPlanSupply =  "0";
												independentDemand =  "0";
												stockQty =  "0"; 
												othSupply =  "0";
												pendingPo =  "0";
												pendingDo =  "0";
												pendingIndent =  "0";
												pendingDr =  "0";
												itemCodeParent =  "";
												originalOrAltitem =  "";
												altItemPerc = "";

												for (int nodCtr1 = 0; nodCtr1 < orderList2.getLength(); nodCtr1++) 
												{

													Node detail4Node=orderList2.item(nodCtr1); 
													//NodeList suppDetailList=detail4Node.getChildNodes();
													//System.out.println("@@@@@@@@@orderNode node name[" + detail4Node.getNodeName()+"]"); 
													//if("supp_detail".equalsIgnoreCase(detail4Node.getNodeName())) 
													//	for (int cn = 0; cn < suppDetailList .getLength(); cn++) 
													{
														//String nodeName=suppDetailList.item(cn).getNodeName();


														if("source_supply".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															if( detail4Node.getFirstChild() != null)
															{
																sourceSupply =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																sourceSupply="";
															}
															//sourceSupply =  detail4Node.getFirstChild().getNodeValue(); 
														}
														if("site_code".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															if( detail4Node.getFirstChild() != null)
															{
																siteCodeSupp =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																siteCodeSupp="";
															}
															//siteCodeSupp =  detail4Node.getFirstChild().getNodeValue(); 
														}
														if("item_code".equalsIgnoreCase(detail4Node.getNodeName())) 
														{
															if( detail4Node.getFirstChild() != null)
															{
																itemCodeSupp =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																itemCodeSupp="";
															}
															//itemCodeSupp =  detail4Node.getFirstChild().getNodeValue();
														}
														if("item_code_descr".equalsIgnoreCase(detail4Node.getNodeName())) 
														{
															if( detail4Node.getFirstChild() != null)
															{
																itemCodeSuppDescr =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																itemCodeSuppDescr="";
															}
															//itemCodeDescr =  detail4Node.getFirstChild().getNodeValue();
														}

														if("lot_no".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															if( detail4Node.getFirstChild() != null)
															{
																lotNo =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																lotNo="";
															}
															//lotNo =  detail4Node.getFirstChild().getNodeValue(); 
														}
														if("lot_sl".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															if( detail4Node.getFirstChild() != null)
															{
																lotSl =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																lotSl="";
															}
															//lotSl =  detail4Node.getFirstChild().getNodeValue(); 
														}
														if("loc_code".equalsIgnoreCase(detail4Node.getNodeName())) 
														{
															if( detail4Node.getFirstChild() != null)
															{
																locCode =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																locCode="";
															}
														}
														if("unit".equalsIgnoreCase(detail4Node.getNodeName())) 
														{
															if( detail4Node.getFirstChild() != null)
															{
																unit =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																unit="";
															}
															//unit =  detail4Node.getFirstChild().getNodeValue(); 
														}
														if("parent_item".equalsIgnoreCase(detail4Node.getNodeName())) 
														{
															if( detail4Node.getFirstChild() != null)
															{
																parentItem =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																parentItem="";
															}
															//parentItem =  detail4Node.getFirstChild().getNodeValue(); 
														}
														if("tran_ser".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															if( detail4Node.getFirstChild() != null)
															{
																tranSer =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																tranSer="";
															}
															//tranSer =  detail4Node.getFirstChild().getNodeValue();
														}   
														/*if("demand".equalsIgnoreCase(detail4Node.getNodeName()))
															{
																demand =  detail4Node.getFirstChild().getNodeValue();
															}*/  
														if("supply".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															supply =  detail4Node.getFirstChild().getNodeValue();
														} 
														if("plan_supply".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															planSupply =  detail4Node.getFirstChild().getNodeValue();
														} 
														if("running_demand".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															runningDemand =  detail4Node.getFirstChild().getNodeValue();
														} 
														if("running_supply".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															runningSupplyStr =  detail4Node.getFirstChild().getNodeValue();
														} 
														if("running_plan_supply".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															runningPlanSupply =  detail4Node.getFirstChild().getNodeValue();
														} 
														if("independent_demand".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															independentDemand =  detail4Node.getFirstChild().getNodeValue();
														} 
														if("stock_qty".equalsIgnoreCase(detail4Node.getNodeName())) 
														{
															stockQty =  detail4Node.getFirstChild().getNodeValue(); 
														}
														if("oth_supply".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															othSupply =  detail4Node.getFirstChild().getNodeValue();
														}
														if("pending_po".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															pendingPo =  detail4Node.getFirstChild().getNodeValue();
														}
														if("pending_do".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															pendingDo =  detail4Node.getFirstChild().getNodeValue();
														}
														if("pending_indent".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															pendingIndent =  detail4Node.getFirstChild().getNodeValue();
														}
														if("pending_dr".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															pendingDr =  detail4Node.getFirstChild().getNodeValue();
														}
														if("item_code_parent".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															if( detail4Node.getFirstChild() != null)
															{
																itemCodeParent =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																itemCodeParent="";
															}
															//itemCodeParent =  detail4Node.getFirstChild().getNodeValue();
														}
														if("originalOrAltitem".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															if( detail4Node.getFirstChild() != null)
															{
																originalOrAltitem =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																originalOrAltitem="";
															}
															//originalOrAltitem =  detail4Node.getFirstChild().getNodeValue();
														}


														if("alt_item_perc".equalsIgnoreCase(detail4Node.getNodeName()))
														{
															if( detail4Node.getFirstChild() != null)
															{
																altItemPerc =  detail4Node.getFirstChild().getNodeValue();
															}
															else
															{
																altItemPerc="";
															}
														}


													}
												}


												System.out.println("@@@@ for test ctr["+dtlCtr+"]itemCodeSupp["+itemCodeSupp+"]sourceSupply["+sourceSupply+"]siteCodeSupp["+siteCodeSupp+"]-itemCodeSupp["+itemCodeSupp+"]-lotNo["+lotNo+"]-lotSl["+lotSl+"]-locCode["+locCode+"]-tranSer["+tranSer+"]@@@");

												if( "Stock".equalsIgnoreCase(tranSer))
												{
													sourceSupply = sourceSupply+"S";	
												}


												domCnt2++;

												valueXmlString.append("<Detail4 domID='" + domCnt2 + "' >\r\n");

												/*
													selectedSampleItem = selectedSampleItem + "<CommonDetail >" +	
		"<sale_order>" + saleOrderDet2 + "</sale_order><line_no>" + lineNoDet2 + "</line_no>" +
		"<site_code>"+siteCodeDet2 + "</site_code><item_code>"+ itemCodeDet2 + "</item_code>" +
		"<item_code_descr>" + itemCodeDescr1 + "</item_code_descr>" +
		"<qty_reqd>" + qtyReqd2 + "</qty_reqd>" + 
		"<order_type>" + orderType + "</order_type>" +
		"<detail2dbID>"+detail2dbID+"</detail2dbID>" + 
		"</CommonDetail>";
												 */
												valueXmlString.append("<source_supply protect = '1'>").append("<![CDATA[" + sourceSupply  + "]]>").append("</source_supply>\r\n");
												valueXmlString.append("<site_code protect = '1'>").append("<![CDATA[" + siteCode  + "]]>").append("</site_code>\r\n");
												valueXmlString.append("<item_code protect = '1'>").append("<![CDATA[" + itemCodeSupp  + "]]>").append("</item_code>\r\n");
												valueXmlString.append("<item_code_descr protect = '1'>").append("<![CDATA[" + itemCodeSuppDescr  + "]]>").append("</item_code_descr>\r\n");
												valueXmlString.append("<lot_no protect = '1'>").append("<![CDATA[" + lotNo  + "]]>").append("</lot_no>\r\n");
												valueXmlString.append("<lot_sl protect = '1'>").append("<![CDATA[" + lotSl  + "]]>").append("</lot_sl>\r\n");
												valueXmlString.append("<loc_code protect = '1'>").append("<![CDATA[" + locCode  + "]]>").append("</loc_code>\r\n");
												valueXmlString.append("<unit protect = '1'>").append("<![CDATA[" + unit  + "]]>").append("</unit>\r\n");
												valueXmlString.append("<parent_item protect = '1'>").append("<![CDATA[" + parentItem  + "]]>").append("</parent_item>\r\n");
												valueXmlString.append("<tran_ser protect = '1'>").append("<![CDATA[" + tranSer  + "]]>").append("</tran_ser>\r\n");
												//valueXmlString.append("<demand protect = '1'>").append("<![CDATA[" + demand  + "]]>").append("</demand>\r\n");
												valueXmlString.append("<supply protect = '1'>").append("<![CDATA[" + supply  + "]]>").append("</supply>\r\n");
												valueXmlString.append("<plan_supply protect = '1'>").append("<![CDATA[" + planSupply  + "]]>").append("</plan_supply>\r\n");
												valueXmlString.append("<running_demand protect = '1'>").append("<![CDATA[" + runningDemand  + "]]>").append("</running_demand>\r\n");
												valueXmlString.append("<running_supply protect = '1'>").append("<![CDATA[" + runningSupply  + "]]>").append("</running_supply>\r\n");
												valueXmlString.append("<running_plan_supply protect = '1'>").append("<![CDATA[" + runningPlanSupply  + "]]>").append("</running_plan_supply>\r\n");
												valueXmlString.append("<independent_demand protect = '1'>").append("<![CDATA[" + independentDemand  + "]]>").append("</independent_demand>\r\n");
												valueXmlString.append("<stock_qty protect = '1'>").append("<![CDATA[" + stockQty  + "]]>").append("</stock_qty>\r\n");
												valueXmlString.append("<oth_supply protect = '1'>").append("<![CDATA[" + othSupply  + "]]>").append("</oth_supply>\r\n");
												valueXmlString.append("<pending_po protect = '1'>").append("<![CDATA[" + pendingPo  + "]]>").append("</pending_po>\r\n");
												valueXmlString.append("<pending_do protect = '1'>").append("<![CDATA[" + pendingDo  + "]]>").append("</pending_do>\r\n");
												valueXmlString.append("<pending_indent protect = '1'>").append("<![CDATA[" + pendingIndent  + "]]>").append("</pending_indent>\r\n");
												valueXmlString.append("<pending_dr protect = '1'>").append("<![CDATA[" + pendingDr  + "]]>").append("</pending_dr>\r\n");
												valueXmlString.append("<item_code_parent protect = '1'>").append("<![CDATA[" + itemCodeParent  + "]]>").append("</item_code_parent>\r\n");
												valueXmlString.append("<originalOrAltitem protect = '1'>").append("<![CDATA[" + originalOrAltitem  + "]]>").append("</originalOrAltitem>\r\n");

												valueXmlString.append("<alt_item_perc protect = '1'>").append("<![CDATA[" + altItemPerc  + "]]>").append("</alt_item_perc>\r\n");

												valueXmlString.append("</Detail4>\r\n");

											}

											//////////////////////////////////////////////////////////
											//if("reference".equalsIgnoreCase(refrenceNode2.getNodeName())) 
											//{
											//orderList =  refrenceNode2.getChildNodes();
											//for (int nodCtr1 = 0; nodCtr1 < orderList .getLength(); nodCtr1++) 
											//{
											//orderNode=orderList.item(nodCtr1);
											//orderDtlList=orderNode.getChildNodes();
											//if("order".equalsIgnoreCase(orderNode.getNodeName()))
											//{

											/*			saleOrder = "";
															lineNo = "";
															bomCodeParent= "";
															bomCodeOrg = "";
															bomCodeRef = "";
															itemCode= "";
															itemCodeDescr = "";
															qtyReqdStr = "0";
															unit = "";
															sourceSupply = "";
															sourceSupplyRef = "";
															suppSour = "";
											 */
											//for (int cntr = 0; cntr < refrenceList2.getLength(); cntr++)  //orderDtlList
											//{
											//Node	detail2Node = refrenceList2.item(cntr);  //orderDtlList

											if("sale_order".equalsIgnoreCase( refrenceNode2.getNodeName()))  // detail2Node replace below detail2Node
											{
												saleOrder =  refrenceNode2.getTextContent();
											}
											if("line_no".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												lineNo =   refrenceNode2.getTextContent();
											}
											if("site_code".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												siteCode =  refrenceNode2.getTextContent(); 
											}
											if("bom_code_parent".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												bomCodeParent =  refrenceNode2.getTextContent();
											}
											if("bom_code_org".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												bomCodeOrg =  refrenceNode2.getTextContent();
											}
											if("bom_code_ref".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												bomCodeRef  =  refrenceNode2.getTextContent();
											}
											if("item_code".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												itemCode =  refrenceNode2.getTextContent();
											}
											if("item_code_descr".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												itemCodeDescr =  refrenceNode2.getTextContent();
											}
											if("qty_reqd".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												qtyReqdStr =  refrenceNode2.getTextContent();
												System.out.println("@@@@@@ in detail2 qtyReqdStr["+qtyReqdStr+"]");
											}
											if("unit".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												unit =  refrenceNode2.getTextContent();
											}
											if("source_supply".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												sourceSupply =  refrenceNode2.getTextContent();
											}
											if("source_supply_ref".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												sourceSupplyRef =  refrenceNode2.getTextContent();
											}
											if("supp_sour".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												suppSour =  refrenceNode2.getTextContent();
											}

											if("itemCodeDetailMap".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												itemCodeDetailMapStr =  refrenceNode2.getTextContent();
												System.out.println("@@@@@@ itemCodeDetailMapStr["+itemCodeDetailMapStr+"]");
											}


											//new tag
											if("mfg_type".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												mfgType =  refrenceNode2.getTextContent();
											}
											if("demand".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												demand =  refrenceNode2.getTextContent();
											}						
											if("other".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												other =  refrenceNode2.getTextContent();
											}
											if("gross_weight".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												grossWeight =  refrenceNode2.getTextContent();
											}

											if("supply".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												supply =  refrenceNode2.getTextContent();
											}
											if("net_req".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												netReq =  refrenceNode2.getTextContent();
											}
											if("order_type".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												orderType =  refrenceNode2.getTextContent();
											}

											if("current_sorder".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												currentSorder =  refrenceNode2.getTextContent();
											}
											if("item_code_descr".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												itemCodeDescr =  refrenceNode2.getTextContent();
											}
											if("due_date".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												dueDate =  refrenceNode2.getTextContent();
											}
											if("loc_group".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												locGroup =  refrenceNode2.getTextContent();
											}
											if("itemDetailsInfo".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												itemDetailsInfo =  refrenceNode2.getTextContent();
											}
											if("sodemand".equalsIgnoreCase( refrenceNode2.getNodeName()))
											{
												sodemand =  refrenceNode2.getTextContent();
											}
											// end new tag

											//}

											//}
											//}
											//test

											//test
											//}
											///////////////////////////////////////////////////////////
										}	
									}
									System.out.println("14/06/14 After recalculate itemCode {" + itemCode +"] bomCodeRef [" + bomCodeRef + "] bomCodeParent [" + bomCodeParent+ "]itemCodeDetailMapStr["+itemCodeDetailMapStr+"]" );

									System.out.println("13/06/14  reference qtyReqdStr before["+qtyReqdStr+"]demand["+demand+"]sodemand["+sodemand+"]");
									if (sodemand == null || "null".equals(sodemand) || sodemand.trim().length() == 0 )
									{
										sodemand = "0";
									}
									//qtyReqd = Double.parseDouble(qtyReqdStr);
									System.out.println("13/06/14  outside qtyReqd before["+qtyReqd+"]sodemand["+sodemand+"]itemCode["+itemCode+"]");
									if( Double.parseDouble( sodemand )  > 0)
									{
										System.out.println("13/06/14  inside qtyReqd before["+qtyReqd+"]itemCode["+itemCode+"]");
										//valueXmlString.append("<reference protect = '1'>\r\n");
										//valueXmlString.append("<order protect = '1' domID='" + domCnt + "'>\r\n");
										valueXmlString.append("<sale_order protect = '1'>").append("<![CDATA[" + saleOrder  + "]]>").append("</sale_order>\r\n");
										valueXmlString.append("<line_no protect = '1'>").append("<![CDATA[" + lineNo  + "]]>").append("</line_no>\r\n");
										valueXmlString.append("<site_code protect = '1'>").append("<![CDATA[" + siteCode  + "]]>").append("</site_code>\r\n");
										valueXmlString.append("<qty_reqd protect = '1'>").append("<![CDATA[" + sodemand  + "]]>").append("</qty_reqd>\r\n");
										valueXmlString.append("<item_code protect = '1'>").append("<![CDATA[" + itemCode  + "]]>").append("</item_code>\r\n");
										valueXmlString.append("<item_code_descr protect = '1'>").append("<![CDATA[" + itemCodeDescr  + "]]>").append("</item_code_descr>\r\n");
										valueXmlString.append("<supp_sour protect = '1'>").append("<![CDATA[" + suppSour  + "]]>").append("</supp_sour>\r\n");
										valueXmlString.append("<running_supply protect = '1'>").append("<![CDATA[" + runningSupplyStr  + "]]>").append("</running_supply>\r\n");
										valueXmlString.append("<unit protect = '1'>").append("<![CDATA[" + unit  + "]]>").append("</unit>\r\n");
										valueXmlString.append("<originalOrAltitem protect = '1'>").append("<![CDATA[" + originalOrAltitem  + "]]>").append("</originalOrAltitem>\r\n");
										valueXmlString.append("<bom_code_parent protect = '1'>").append("<![CDATA[" + bomCodeParent  + "]]>").append("</bom_code_parent>\r\n");  //bomCodeParent
										valueXmlString.append("<bom_code_org protect = '1'>").append("<![CDATA[" + bomCodeRef  + "]]>").append("</bom_code_org>\r\n");
										if( "P".equalsIgnoreCase(suppSour))
										{
											valueXmlString.append("<bom_code_ref protect = '1'>").append(" ").append("</bom_code_ref>\r\n");
										}
										else
										{
											valueXmlString.append("<bom_code_ref protect = '1'>").append("<![CDATA[" + bomCodeRef  + "]]>").append("</bom_code_ref>\r\n");
										}
										valueXmlString.append("<source_supply protect = '1'>").append("<![CDATA[" + sourceSupply  + "]]>").append("</source_supply>\r\n");
										valueXmlString.append("<source_supply_ref protect = '1'>").append("<![CDATA[" + sourceSupplyRef  + "]]>").append("</source_supply_ref>\r\n");

										//new tag
										valueXmlString.append("<itemDetailsInfo protect = '1'>").append("<![CDATA[" + itemCode  + "]]>").append("</itemDetailsInfo>\r\n");
										valueXmlString.append("<mfg_type protect = '1'>").append("<![CDATA[" + mfgType  + "]]>").append("</mfg_type>\r\n");
										valueXmlString.append("<demand protect = '1'>").append("<![CDATA[" + demand  + "]]>").append("</demand>\r\n");
										valueXmlString.append("<sodemand protect = '1'>").append("<![CDATA[" + sodemand  + "]]>").append("</sodemand>\r\n");
										valueXmlString.append("<other protect = '1'>").append("<![CDATA[" + other  + "]]>").append("</other>\r\n");
										valueXmlString.append("<gross_weight protect = '1'>").append("<![CDATA[" + grossWeight  + "]]>").append("</gross_weight>\r\n");
										valueXmlString.append("<supply protect = '1'>").append("<![CDATA[" + supply  + "]]>").append("</supply>\r\n");
										valueXmlString.append("<net_req protect = '1'>").append("<![CDATA[" + netReq  + "]]>").append("</net_req>\r\n");
										valueXmlString.append("<order_type protect = '1'>").append("<![CDATA[" + orderType  + "]]>").append("</order_type>\r\n");
										valueXmlString.append("<current_sorder protect = '1'>").append("<![CDATA[" + currentSorder  + "]]>").append("</current_sorder>\r\n");
										valueXmlString.append("<due_date protect = '1'>").append("<![CDATA[" + dueDate  + "]]>").append("</due_date>\r\n");
										valueXmlString.append("<loc_group protect = '1'>").append("<![CDATA[" + locGroup  + "]]>").append("</loc_group>\r\n");
										//valueXmlString.append("<itemDetailsInfo protect = '1'>").append("<![CDATA[" + itemDetailsInfo  + "]]>").append("</itemDetailsInfo>\r\n");

										//valueXmlString.append("<refDetails protect = '1'>").append("<![CDATA[" + itemCode  + "]]>").append("</refDetails>\r\n");
										//valueXmlString.append("<bom_code protect = '1'>").append("<![CDATA[" + ""  + "]]>").append("</bom_code>\r\n");
										//valueXmlString.append("<stock_qty protect = '1'>").append("<![CDATA[" + itemDetailsInfo  + "]]>").append("</stock_qty>\r\n");
										//valueXmlString.append("<itemType protect = '1'>").append("<![CDATA[" + getItemType(suppSour)  + "]]>").append("</itemType>\r\n");
										//valueXmlString.append("<itemCodeDetailMap protect = '1'>").append("<![CDATA[" + itemDetailsInfo  + "]]>").append("</itemCodeDetailMap>\r\n");


										// end new tag
										//valueXmlString.append("</order>\r\n");
										//valueXmlString.append("</reference>\r\n");
									}
									////////////////////////////////////////////////////////

									/*
										valueXmlString.append("<CommonDetail protect = '1'>\r\n>");
										valueXmlString.append("<sale_order protect = '1'>").append("<![CDATA[" + saleOrder  + "]]>").append("</sale_order>\r\n");
										valueXmlString.append("<line_no protect = '1'>").append("<![CDATA[" + lineNo  + "]]>").append("</line_no>\r\n");
										valueXmlString.append("<site_code protect = '1'>").append("<![CDATA[" + siteCode  + "]]>").append("</site_code>\r\n");
										valueXmlString.append("<item_code protect = '1'>").append("<![CDATA[" + itemCode  + "]]>").append("</item_code>\r\n");
										valueXmlString.append("<item_code_descr protect = '1'>").append("<![CDATA[" + itemCodeDescr  + "]]>").append("</item_code_descr>\r\n");
										valueXmlString.append("<qty_reqd protect = '1'>").append("<![CDATA[" + sodemand  + "]]>").append("</qty_reqd>\r\n");
										valueXmlString.append("<order_type protect = '1'>").append("<![CDATA[" + orderType  + "]]>").append("</order_type>\r\n");
										valueXmlString.append("</CommonDetail>\r\n");
									 */


									valueXmlString.append("</Detail2>\r\n");
								}
							}

							System.out.println("@@@@@@@@ before recalcilate valueXmlString after added ["+valueXmlString.toString()+"]");

						}
						else
						{
							System.out.println("@@@@@@@@ for old xml itemDetailsInfo["+itemDetailsInfo+"]itemCode["+itemCode+"]mfgType["+mfgType+"]demand["+demand+"]qtyReqdStr["+qtyReqdStr+"]supply["+supply+"]currentSorder["+currentSorder+"]suppSour["+suppSour+"]");

							domCnt++;
							valueXmlString.append("<Detail2  domID='" + domCnt + "' >\r\n");
							//valueXmlString.append("<reference protect = '1'>");
							//valueXmlString.append("<order protect = '1' domID='" + domCnt + "'>\r\n");
							valueXmlString.append("<sale_order protect = '1'>").append("<![CDATA[" + saleOrder  + "]]>").append("</sale_order>\r\n");
							valueXmlString.append("<line_no protect = '1'>").append("<![CDATA[" + lineNo  + "]]>").append("</line_no>\r\n");
							valueXmlString.append("<site_code protect = '1'>").append("<![CDATA[" + siteCode  + "]]>").append("</site_code>\r\n");
							valueXmlString.append("<qty_reqd protect = '1'>").append("<![CDATA[" + qtyReqdStr  + "]]>").append("</qty_reqd>\r\n");
							valueXmlString.append("<item_code protect = '1'>").append("<![CDATA[" + itemCode  + "]]>").append("</item_code>\r\n");
							valueXmlString.append("<item_code_descr protect = '1'>").append("<![CDATA[" + itemCodeDescr  + "]]>").append("</item_code_descr>\r\n");
							valueXmlString.append("<supp_sour protect = '1'>").append("<![CDATA[" + suppSour  + "]]>").append("</supp_sour>\r\n");
							valueXmlString.append("<running_supply protect = '1'>").append("<![CDATA[" + runningSupplyStr  + "]]>").append("</running_supply>\r\n");
							valueXmlString.append("<unit protect = '1'>").append("<![CDATA[" + unit  + "]]>").append("</unit>\r\n");
							valueXmlString.append("<originalOrAltitem protect = '1'>").append("<![CDATA[" + originalOrAltitem  + "]]>").append("</originalOrAltitem>\r\n");
							valueXmlString.append("<bom_code_parent protect = '1'>").append("<![CDATA[" + bomCodeParent  + "]]>").append("</bom_code_parent>\r\n");
							valueXmlString.append("<bom_code_org protect = '1'>").append("<![CDATA[" + bomCodeOrg  + "]]>").append("</bom_code_org>\r\n");
							valueXmlString.append("<bom_code_ref protect = '1'>").append("<![CDATA[" + bomCodeRef  + "]]>").append("</bom_code_ref>\r\n");
							valueXmlString.append("<source_supply protect = '1'>").append("<![CDATA[" + sourceSupply  + "]]>").append("</source_supply>\r\n");
							valueXmlString.append("<source_supply_ref protect = '1'>").append("<![CDATA[" + sourceSupplyRef  + "]]>").append("</source_supply_ref>\r\n");
							//valueXmlString.append("</order>\r\n");
							//valueXmlString.append("</reference>\r\n");

							//new tag
							valueXmlString.append("<mfg_type protect = '1'>").append("<![CDATA[" + mfgType  + "]]>").append("</mfg_type>\r\n");
							valueXmlString.append("<demand protect = '1'>").append("<![CDATA[" + demand  + "]]>").append("</demand>\r\n");
							valueXmlString.append("<sodemand protect = '1'>").append("<![CDATA[" + demand  + "]]>").append("</sodemand>\r\n");
							valueXmlString.append("<other protect = '1'>").append("<![CDATA[" + other  + "]]>").append("</other>\r\n");
							valueXmlString.append("<gross_weight protect = '1'>").append("<![CDATA[" + grossWeight  + "]]>").append("</gross_weight>\r\n");
							valueXmlString.append("<supply protect = '1'>").append("<![CDATA[" + supply  + "]]>").append("</supply>\r\n");
							valueXmlString.append("<net_req protect = '1'>").append("<![CDATA[" + netReq  + "]]>").append("</net_req>\r\n");
							valueXmlString.append("<order_type protect = '1'>").append("<![CDATA[" + orderType  + "]]>").append("</order_type>\r\n");
							valueXmlString.append("<current_sorder protect = '1'>").append("<![CDATA[" + currentSorder  + "]]>").append("</current_sorder>\r\n");
							valueXmlString.append("<due_date protect = '1'>").append("<![CDATA[" + dueDate  + "]]>").append("</due_date>\r\n");
							valueXmlString.append("<loc_group protect = '1'>").append("<![CDATA[" + locGroup  + "]]>").append("</loc_group>\r\n");
							valueXmlString.append("<itemDetailsInfo protect = '1'>").append("<![CDATA[" + itemDetailsInfo  + "]]>").append("</itemDetailsInfo>\r\n");

							// end new tag



							//tempdetail4OuterList.clear();
							tempdetail4OuterList = (ArrayList) detail4ListMap.get(saleOrder+lineNo+itemCode);

							System.out.println("@@@@@@1073["+detail4ListMap.size()+"]:["+saleOrder+lineNo+itemCode+"]detail4ListMap["+detail4ListMap+"]");
							if( tempdetail4OuterList != null && tempdetail4OuterList.size() > 0 )
							{
								System.out.println("@@@@@@1074[:tempdetail4OuterList.size["+tempdetail4OuterList.size()+"]");

								for( int listCtr=0; listCtr < tempdetail4OuterList.size() ; listCtr++)
								{	 
									//tempdetail4List.clear();
									tempdetail4List = ( ArrayList ) tempdetail4OuterList.get(listCtr);

									System.out.println("@@@@@@ tempdetail4List listCtr["+listCtr+"]["+tempdetail4List+"]");

									domCnt2++;
									int k=0;
									valueXmlString.append("<Detail4 domID='" + domCnt2 + "' >\r\n");
									valueXmlString.append("<site_code protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) +  "]]>").append("</site_code>\r\n");
									valueXmlString.append("<item_code protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) +  "]]>").append("</item_code>\r\n");
									valueXmlString.append("<item_code_descr protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</item_code_descr>\r\n");
									valueXmlString.append("<lot_no protect = '1' >" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</lot_no>\r\n");
									valueXmlString.append("<lot_sl protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</lot_sl>\r\n");
									valueXmlString.append("<loc_code protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</loc_code>\r\n");
									valueXmlString.append("<tran_ser protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</tran_ser>\r\n");
									valueXmlString.append("<tran_id protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</tran_id>\r\n");
									valueXmlString.append("<supply protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</supply>\r\n");
									valueXmlString.append("<alloc_qty protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</alloc_qty>\r\n");
									valueXmlString.append("<unit protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</unit>\r\n");
									valueXmlString.append("<ref_line_no protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</ref_line_no>\r\n");
									valueXmlString.append("<planned_quantity protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</planned_quantity>\r\n");
									valueXmlString.append("<parent_item protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</parent_item>\r\n");
									valueXmlString.append("<source_supply protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</source_supply>\r\n");
									valueXmlString.append("<item_code_parent protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</item_code_parent>\r\n");


									valueXmlString.append("<sale_order protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</sale_order>\r\n");										
									valueXmlString.append("<line_no protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</line_no>\r\n");
									valueXmlString.append("<qty_reqd protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</qty_reqd>\r\n");
									valueXmlString.append("<item_code_descr protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</item_code_descr>\r\n");
									valueXmlString.append("<available_supply protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</available_supply>\r\n");
									valueXmlString.append("<originalOrAltitem protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</originalOrAltitem>\r\n");
									valueXmlString.append("<quantityFlag protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</quantityFlag>\r\n");
									valueXmlString.append("<prev_item_worder protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</prev_item_worder>\r\n");
									valueXmlString.append("<previous_item protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</previous_item>\r\n");
									valueXmlString.append("<new_planned_supply protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</new_planned_supply>\r\n");
									valueXmlString.append("<due_date protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</due_date>\r\n");
									valueXmlString.append("<alloc_pref protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</alloc_pref>\r\n");

									valueXmlString.append("<alt_item_perc protect = '1'>").append("<![CDATA[" + tempdetail4List.get(k++)  + "]]>").append("</alt_item_perc>\r\n");

									valueXmlString.append("</Detail4>\r\n");


								}
							}
							valueXmlString.append("</Detail2>\r\n");

						}
						//System.out.println("@@@@@@@@@ 328 xmldata============[["+xmldata+"]]");
						//}

					}
					else
					{
						System.out.println("@@@@@@this item code deletedc from display --> itemCode["+itemCode+"]qtyReqdStr["+qtyReqdStr+"]deleteBomList["+deleteBomList+"]bomCodeParent["+bomCodeParent+"]");
					}
					//}
					//}
					//}
					//}
				}
			}	

			// end	

			valueXmlString.append("</Root>");
			xmldata =  valueXmlString.toString();
			System.out.println("@@@@@@@@@final bean xmldata============[["+xmldata+"]]");

		}//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 Exception occurs in MrpWizPrsSaveBean  : "+e);			
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally 
		{
			try
			{

				if (errString == null || errString.trim().length() == 0)
				{
					System.out.println("@@@@@@ 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 Exception occurs in MrpWizPrsSaveBean  :"+e);			
				e.printStackTrace();
				throw new ITMException(e);
			}
		}



		return xmldata;
	}


	private String getXmlDataBackup(Document dom )throws ITMException
	{
		PreparedStatement pstmt = null;
		String sql = "", itemCode = "", effDate = "", itemSer = "";
		int updCnt = 0;
		//java.util.Date effDate1 = null, preDate = null;
		GenericUtility genericUtility = GenericUtility.getInstance();
		NodeList hdrDom = null;
		//Node currDetail = null;

		String saleOrder="",lineNo="", siteCode="", lotNo="", locCode="", lotSl="", tranSer="", runningSupplyStr="", qtyReqdStr="",allocQtyStr="";
		double runningSupply=0,qtyReqd=0;
		String tranId="",refId="",refLineNo="",unit="",errString="",bomCodeParent="",sourceSupplyRef="";
		int cnt=0;
		Connection conn = null;
		ConnDriver connDriver = new ConnDriver(); 

		String xmldata="",bomCodeOrg="",itemCodeDescr="",bomCodeRef="";

		ArrayList replaceBomItemList = new ArrayList();
		ArrayList deleteBomList = new ArrayList();
		ArrayList deleteSaleOrderList = new ArrayList();


		NodeList orderList=null; 
		NodeList orderList1=null;
		//Node mrpGetDataNode =null, referenceChildNode=null, Detail4ChildNode=null,mrpGetDataNode2=null;
		RunMRPPrc runMRPObj = new RunMRPPrc();

		int i=0,domCnt=0;
		String suppSour="",originalOrAltitem="",sourceSupply="";

		String itemCodeDetailMapStr="";
		HashMap itemCodeDetailMap = new HashMap();


		String siteCodeSupp="",itemCodeSupp="",parentItem="",demand="",supply="",planSupply="",runningDemand="",runningPlanSupply="";
		String independentDemand="",stockQty="",othSupply="",pendingPo="",pendingDo="",pendingIndent="",pendingDr="",itemCodeParent="";
		String bomCode="",dueDate="",orderOpt="",minOrderQty="",batchQtyType="",integralQty="",purLeadTime="";
		String reorderQty="",minPlanPerc="",maxQty="",minQty="",batchQty="",yieldPerc="",mfgLeadTime="",description="",qcLeadTime="";
		int domCnt2=0;
		Document mrpGetDataDom = null;

		String Deatail4SiteCode="",Deatail4LotNo="",Deatail4LocCode="",Deatail4LotSl="",Deatail4AllocQty="",Deatail4TranId="";
		String Deatail4ItemCode="",Deatail4Unit="",Deatail4TranSer="",Deatail4RefLineNo="",Deatail4Supply="",Deatail4ParentItem="";
		String Deatail4SourceSupply="",Deatail4PlannedQuantity="",Deatail4ItemCodeDescr="",Deatail4ItemCodeParent="";
		String allocQty="",plannedQuantity="";

		HashMap detail4ListMap = new HashMap();
		//System.out.println("@@@ initiaalize detail4ListMap...");






		try
		{
			conn = connDriver.getConnectDB("DriverITM");

			NodeList hdrDommList = dom.getElementsByTagName("Detail2");
			System.out.println("len===["+hdrDommList.getLength()+"]");


			//// for test

			for (int dtlCtr = 0; dtlCtr < hdrDommList.getLength(); dtlCtr++)
			{
				Node detailListNode = hdrDommList.item(dtlCtr);
				if("Detail2".equalsIgnoreCase(detailListNode.getNodeName()))
				{
					ArrayList detail4OuterList = new ArrayList();

					NodeList refrenceList= detailListNode.getChildNodes();
					for (int cntr1 = 0; cntr1 < refrenceList.getLength(); cntr1++) 
					{
						Node	refrenceNode = refrenceList.item(cntr1); 
						orderList = refrenceNode.getChildNodes(); 
						if("reference".equalsIgnoreCase(refrenceNode.getNodeName())) 
						{
							for (int nodCtr = 0; nodCtr < orderList .getLength(); nodCtr++) 
							{
								Node orderNode=orderList.item(nodCtr);
								NodeList orderDtlList=orderNode.getChildNodes();
								if("order".equalsIgnoreCase(orderNode.getNodeName()))
								{
									for (int cntr = 0; cntr < orderDtlList.getLength(); cntr++) 
									{
										Node	detail2Node = orderDtlList.item(cntr); 
										//System.out.println("@@@@@@@@@ 127 node name[" + detail2Node.getNodeName()+"]"); 
										{
											if("sale_order".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												saleOrder =  detail2Node.getTextContent();
											}
											if("line_no".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												lineNo  =  detail2Node.getTextContent();
											}
											if("item_code".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												itemCode  =  detail2Node.getTextContent();
											}
											if("bom_code_org".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												bomCodeOrg =  detail2Node.getTextContent();
											}
											if("bom_code_ref".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												bomCodeRef  =  detail2Node.getTextContent();
											}
											///	itemCodeDetailMap
										}

									}
									System.out.println("bomCodeOrg["+bomCodeOrg+"]bomCodeRef["+bomCodeRef+"]");
									if( !(bomCodeOrg.equalsIgnoreCase(bomCodeRef)))
									{
										deleteBomList.add(bomCodeOrg);
										deleteSaleOrderList.add(saleOrder+"@"+lineNo);
										// String returnBom = runMRPObj.bomExplode(siteCode, bomCodeRef);
									}
								}
							}
						}
						/// for detail 4 start
						if("Detail4".equalsIgnoreCase(refrenceNode.getNodeName()))
						{
							orderList1 = refrenceNode.getChildNodes();
							for (int nodCtr1 = 0; nodCtr1 < orderList1.getLength(); nodCtr1++) 
							{
								Node detail4Node2=orderList1.item(nodCtr1); 
								//System.out.println("node in detail4 ["+detail4Node2.getNodeName()+"]");
								{
									if( detail4Node2.getFirstChild() != null)
									{
										if("site_code".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											siteCodeSupp =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("item_code".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											itemCodeSupp =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("item_code_descr".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											itemCodeDescr =  detail4Node2.getFirstChild().getNodeValue();
										}
										if("lot_no".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											lotNo =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("lot_sl".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											lotSl =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("loc_code".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											locCode =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("tran_ser".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											tranSer =  detail4Node2.getFirstChild().getNodeValue();
										}   
										if("tran_id".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											tranId =  detail4Node2.getFirstChild().getNodeValue();
										} 
										if("supply".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											supply =  detail4Node2.getFirstChild().getNodeValue();
										} 
										if("alloc_qty".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											allocQty =  detail4Node2.getFirstChild().getNodeValue();
										} 
										if("unit".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											unit =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("ref_line_no".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											refLineNo =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("planned_quantity".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											plannedQuantity =  detail4Node2.getFirstChild().getNodeValue();
										} 
										if("parent_item".equalsIgnoreCase(detail4Node2.getNodeName())) 
										{
											parentItem =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("source_supply".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											sourceSupply =  detail4Node2.getFirstChild().getNodeValue(); 
										}
										if("item_code_parent".equalsIgnoreCase(detail4Node2.getNodeName()))
										{
											itemCodeParent =  detail4Node2.getFirstChild().getNodeValue();
										}
									}								
								}
							}

							System.out.println("@@@@ for list ctr["+dtlCtr+"]itemCodeSupp["+itemCodeSupp+"]sourceSupply["+sourceSupply+"]siteCodeSupp["+siteCodeSupp+"]-itemCodeSupp["+itemCodeSupp+"]-lotNo["+lotNo+"]-lotSl["+lotSl+"]-locCode["+locCode+"]-tranSer["+tranSer+"]@@@");

							//detail4List.clear();
							ArrayList detail4List = new ArrayList();

							detail4List.add(siteCodeSupp);  
							detail4List.add(itemCodeSupp );
							detail4List.add(itemCodeDescr );
							detail4List.add(lotNo  );
							detail4List.add(lotSl  );
							detail4List.add(locCode  );
							detail4List.add(tranSer );
							detail4List.add(tranId );
							detail4List.add(supply );
							detail4List.add(allocQty );
							detail4List.add(unit  );
							detail4List.add(refLineNo);  
							detail4List.add(plannedQuantity); 
							detail4List.add(parentItem  );
							detail4List.add(sourceSupply  );
							detail4List.add(itemCodeParent );

							System.out.println("detail4List["+detail4List+"]");
							detail4OuterList.add(detail4List);
							//System.out.println("detail4List added");
						}
					}
					System.out.println("detail4OuterList["+detail4OuterList+"]");

					if( detail4OuterList != null && detail4OuterList.size() > 0 )
					{
						//System.out.println("before addedd.."+saleOrder+lineNo+itemCode+".detail4ListMap["+detail4ListMap+"]");
						detail4ListMap.put(saleOrder+lineNo+itemCode, detail4OuterList);
						System.out.println("after addedd.."+saleOrder+lineNo+itemCode+".detail4ListMap["+detail4ListMap+"]");
						// detail4OuterList.clear();
					}
				}
			}	

			// end	
			System.out.println("@@@@@@@@ deleteBomList["+deleteBomList+"]deleteSaleOrderList["+deleteSaleOrderList+"]");
			//// start new test

			StringBuffer valueXmlString = new StringBuffer();
			valueXmlString = new StringBuffer("<?xml version = \"1.0\"?><Root>\r\n");

			for (int dtlCtr = 0; dtlCtr < hdrDommList.getLength(); dtlCtr++)
			{
				Node detailListNode = hdrDommList.item(dtlCtr);
				if("Detail2".equalsIgnoreCase(detailListNode.getNodeName()))
				{
					NodeList refrenceList= detailListNode.getChildNodes();
					for (int cntr1 = 0; cntr1 < refrenceList.getLength(); cntr1++) 
					{
						Node	refrenceNode = refrenceList.item(cntr1); 
						orderList = refrenceNode.getChildNodes(); 
						if("reference".equalsIgnoreCase(refrenceNode.getNodeName())) 
						{
							for (int nodCtr = 0; nodCtr < orderList .getLength(); nodCtr++) 
							{
								Node orderNode=orderList.item(nodCtr);
								NodeList orderDtlList=orderNode.getChildNodes();
								if("order".equalsIgnoreCase(orderNode.getNodeName()))
								{
									for (int cntr = 0; cntr < orderDtlList.getLength(); cntr++) 
									{
										Node	detail2Node = orderDtlList.item(cntr); 
										//System.out.println("13/06/14 supreme node name[" + detail2Node.getNodeName()+"] detail2Node.getTextContent() [" + detail2Node.getTextContent() + "]"); 
										{

											if("supp_sour".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												suppSour =  detail2Node.getTextContent();
											}
											if("sale_order".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												saleOrder =  detail2Node.getTextContent();
											}
											if("line_no".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												lineNo =   detail2Node.getTextContent();
											}
											if("site_code".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												siteCode =  detail2Node.getTextContent(); 
											}
											if("bom_code_parent".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												bomCodeParent =  detail2Node.getTextContent();
											}
											if("bom_code_org".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												bomCodeOrg =  detail2Node.getTextContent();
											}
											if("bom_code_ref".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												bomCodeRef  =  detail2Node.getTextContent();
											}
											if("item_code".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												itemCode =  detail2Node.getTextContent();
											}
											if("item_code_descr".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												itemCodeDescr =  detail2Node.getTextContent();
											}
											if("qty_reqd".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												qtyReqdStr =  detail2Node.getTextContent();
											}
											if("unit".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												unit =  detail2Node.getTextContent();
											}
											if("source_supply".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												sourceSupply =  detail2Node.getTextContent();
											}
											if("source_supply_ref".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												sourceSupplyRef =  detail2Node.getTextContent();
											}

											if("itemCodeDetailMap".equalsIgnoreCase( detail2Node.getNodeName()))
											{
												itemCodeDetailMapStr =  detail2Node.getTextContent();
												System.out.println("@@@@@@ itemCodeDetailMapStr["+itemCodeDetailMapStr+"]");
											}


										}

									}
									System.out.println("@@@@ saleOrder["+saleOrder+"]-lineNo["+lineNo+"]-qtyReqd["+qtyReqdStr+"]sourceSupply["+sourceSupply+"]@@@");
									System.out.println("@@@@ siteCode["+siteCode+"]-itemCode["+itemCode+"]-bomCodeOrg["+bomCodeOrg+"]-bomCodeRef["+bomCodeRef+"]bomCodeParent["+bomCodeParent+"]");
									System.out.println("@@@@@ itemCodeDetailMap in bean itemCodeDetailMapStr["+itemCodeDetailMapStr+"]bomCodeRef["+bomCodeRef+"]");
									System.out.println("@@@@@ itemCodeDetailMap in bean deleteBomList["+deleteBomList+"]deleteSaleOrderList["+deleteSaleOrderList+"]");

									if( itemCodeDetailMapStr != null && ( ! bomCodeOrg.equalsIgnoreCase(bomCodeRef)) )
									{
										itemCodeDetailMapStr = bomCodeParent;
									}
									System.out.println("@@@@@ itemCodeDetailMap in bean deleteBomList["+deleteBomList+"]deleteSaleOrderList["+deleteSaleOrderList+"]");
									if( !(deleteBomList.contains(bomCodeParent)   && deleteSaleOrderList.contains(saleOrder+"@"+lineNo)))
									{
										System.out.println("14/06/14 supreme  1 inside itemCode ["+itemCode+"]bomCodeRef["+bomCodeRef+"] suppSour [" + suppSour);
										ArrayList tempdetail4OuterList = new ArrayList();
										ArrayList tempdetail4List = new ArrayList();

										//System.out.println("@@@@ inside first if....");
										if (( (bomCodeRef != null  && bomCodeRef.trim().length() > 0 ) ) && ( (itemCodeDetailMapStr.contains(bomCodeParent)) && ( !bomCodeOrg.equalsIgnoreCase(bomCodeRef)) ))
										{
											System.out.println("14/06/14 supreme  2 inside itemCode ["+itemCode+"]bomCodeRef["+bomCodeRef+"] suppSour [" + suppSour);
											System.out.println("14/06/14 Before recalculate itemCode {" + itemCode +"] bomCodeRef [" + bomCodeRef + "] bomCodeParent [" + bomCodeParent+ "]" );
											//System.out.println("@@@@ inside second if....");
											// for creating existing row
											/* 13/06/14 manoharan domCnt++;
											// valueXmlString =
											valueXmlString.append("<Detail2  domID='" + domCnt + "' >\r\n");
											valueXmlString.append("<reference protect = '1'>");
											valueXmlString.append("<order protect = '1' domID='" + domCnt + "'>\r\n");
											valueXmlString.append("<sale_order protect = '1'>").append("<![CDATA[" + saleOrder  + "]]>").append("</sale_order>\r\n");
											valueXmlString.append("<line_no protect = '1'>").append("<![CDATA[" + lineNo  + "]]>").append("</line_no>\r\n");
											valueXmlString.append("<site_code protect = '1'>").append("<![CDATA[" + siteCode  + "]]>").append("</site_code>\r\n");
											valueXmlString.append("<qty_reqd protect = '1'>").append("<![CDATA[" + qtyReqdStr  + "]]>").append("</qty_reqd>\r\n");
											valueXmlString.append("<item_code protect = '1'>").append("<![CDATA[" + itemCode  + "]]>").append("</item_code>\r\n");
											valueXmlString.append("<item_code_descr protect = '1'>").append("<![CDATA[" + itemCodeDescr  + "]]>").append("</item_code_descr>\r\n");
											valueXmlString.append("<supp_sour protect = '1'>").append("<![CDATA[" + suppSour  + "]]>").append("</supp_sour>\r\n");
											valueXmlString.append("<running_supply protect = '1'>").append("<![CDATA[" + runningSupplyStr  + "]]>").append("</running_supply>\r\n");
											valueXmlString.append("<unit protect = '1'>").append("<![CDATA[" + unit  + "]]>").append("</unit>\r\n");
											valueXmlString.append("<originalOrAltitem protect = '1'>").append("<![CDATA[" + originalOrAltitem  + "]]>").append("</originalOrAltitem>\r\n");
											valueXmlString.append("<bom_code_parent protect = '1'>").append("<![CDATA[" + bomCodeParent  + "]]>").append("</bom_code_parent>\r\n");
											valueXmlString.append("<bom_code_org protect = '1'>").append("<![CDATA[" + bomCodeRef  + "]]>").append("</bom_code_org>\r\n");
											valueXmlString.append("<bom_code_ref protect = '1'>").append("<![CDATA[" + bomCodeRef  + "]]>").append("</bom_code_ref>\r\n");
											valueXmlString.append("<source_supply protect = '1'>").append("<![CDATA[" + sourceSupply  + "]]>").append("</source_supply>\r\n");
											valueXmlString.append("<source_supply_ref protect = '1'>").append("<![CDATA[" + sourceSupplyRef  + "]]>").append("</source_supply_ref>\r\n");
											valueXmlString.append("</order>\r\n");
											valueXmlString.append("</reference>\r\n");

											//for detail4

											//tempdetail4OuterList.clear();
											System.out.println("@@@@@@492["+detail4ListMap.size()+"]:["+saleOrder+lineNo+itemCode+"]detail4ListMap["+detail4ListMap+"]");
											tempdetail4OuterList = (ArrayList) detail4ListMap.get(saleOrder+lineNo+itemCode);

											if( tempdetail4OuterList != null && tempdetail4OuterList.size() > 0 )
											{

											System.out.println("@@@@@@492:tempdetail4OuterList.size["+tempdetail4OuterList.size()+"]");

											for( int listCtr=0; listCtr < tempdetail4OuterList.size() ; listCtr++)
											{	 

												//tempdetail4List.clear();
												tempdetail4List = ( ArrayList ) tempdetail4OuterList.get(listCtr);

												System.out.println("@@@@@@ tempdetail4List listCtr["+listCtr+"]["+tempdetail4List+"]");

												domCnt2++;
												int k=0;
												valueXmlString.append("<Detail4 domID='" + domCnt2 + "' >\r\n");
												valueXmlString.append("<site_code protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) +  "]]>").append("</site_code>\r\n");
												valueXmlString.append("<item_code protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) +  "]]>").append("</item_code>\r\n");
												valueXmlString.append("<item_code_descr protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</item_code_descr>\r\n");
												valueXmlString.append("<lot_no protect = '1' >" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</lot_no>\r\n");
												valueXmlString.append("<lot_sl protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</lot_sl>\r\n");
												valueXmlString.append("<loc_code protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</loc_code>\r\n");
												valueXmlString.append("<tran_ser protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</tran_ser>\r\n");
												valueXmlString.append("<tran_id protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</tran_id>\r\n");
												valueXmlString.append("<supply protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</supply>\r\n");
												valueXmlString.append("<alloc_qty protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</alloc_qty>\r\n");
												valueXmlString.append("<unit protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</unit>\r\n");
												valueXmlString.append("<ref_line_no protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</ref_line_no>\r\n");
												valueXmlString.append("<planned_quantity protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</planned_quantity>\r\n");
												valueXmlString.append("<parent_item protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</parent_item>\r\n");
												valueXmlString.append("<source_supply protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</source_supply>\r\n");
												valueXmlString.append("<item_code_parent protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</item_code_parent>\r\n");
												valueXmlString.append("</Detail4>\r\n");

												}
											}
											//end detail4
											valueXmlString.append("</Detail2>\r\n"); *//// 13/06/14 manoharan


											//System.out.println("@@@@@@@@@ 326 xmldata============[["+xmldata+"]]");
											// end

											Document argDom = null;
											NodeList parentNodeList = null;
											Node parentNode = null;
											String winName="",editFlag="",xtraParams="",mrpGetData="" ;
											Document dom2 = null;
											ResultSet rs = null;

											System.out.println("1500 @@@@@@@@@ exsting order deleted next.....finish..errString["+errString+"]");

											SimpleDateFormat simpleDateFormat = null;
											simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());

											StringBuffer argData = new StringBuffer();
											argData = new StringBuffer("<?xml version=\"1.0\"?><Root><Header><editFlag>");
											argData.append(editFlag).append("</editFlag></Header>");
											argData.append("<Detail\r\n>");
											argData.append("<site_code>").append(siteCode).append("</site_code>\r\n");
											argData.append("<process_cycle>").append("3").append("</process_cycle>\r\n");
											argData.append("<run_date>").append(simpleDateFormat.format(new Date())).append("</run_date>\r\n"); // 01-10-2007
											argData.append("<dis_plan>").append("Y").append("</dis_plan>\r\n");  //N
											argData.append("<mfg_plan>").append("Y").append("</mfg_plan>\r\n");
											argData.append("<mat_plan>").append("Y").append("</mat_plan>\r\n");   // change from N
											argData.append("<made_to_stock>").append("1").append("</made_to_stock>\r\n");  //0
											argData.append("<made_to_order>").append("0").append("</made_to_order>\r\n");
											argData.append("<balance_intersite>").append("N").append("</balance_intersite>\r\n");
											argData.append("<gen_ind>").append("Y").append("</gen_ind>\r\n");   //N
											argData.append("<wizard>").append("2").append("</wizard>\r\n");    //3
											argData.append("<verifier>").append("N").append("</verifier>\r\n");
											argData.append("<isBomReplace>").append("Y").append("</isBomReplace>\r\n");   // added by cpatil on 17/05/14 for BomReplace
											argData.append("<bom_code>").append(bomCodeRef).append("</bom_code>\r\n");   // added by cpatil on 17/05/14 for BomReplace
											argData.append("<bomReplaceDemand>").append(qtyReqdStr).append("</bomReplaceDemand>\r\n");   // added by cpatil on 17/05/14 for BomReplace
											argData.append("<date_from>").append(simpleDateFormat.format(new Date())).append("</date_from>\r\n"); // 01-10-2007
											argData.append("<date_to>").append(simpleDateFormat.format(new Date())).append("</date_to>\r\n"); // 01-10-2007

											argData.append("<saleOrderReplaceBom>").append(saleOrder).append("</saleOrderReplaceBom>\r\n");   // added by cpatil on 17/05/14 for BomReplace
											argData.append("<lineNoReplaceBom>").append(lineNo).append("</lineNoReplaceBom>\r\n");   // added by cpatil on 17/05/14 for BomReplace
											argData.append("<bom_code_parent>").append(bomCodeParent).append("</bom_code_parent>\r\n");   // added by cpatil on 17/05/14 for BomReplace


											argData.append("<site_code__from>").append(siteCode).append("</site_code__from>\r\n");
											argData.append("<site_code__to>").append(siteCode).append("</site_code__to>\r\n");
											argData.append("<item_code__from>").append(itemCode).append("</item_code__from>\r\n");
											argData.append("<item_code__to>").append(itemCode).append("</item_code__to>\r\n");
											argData.append("<item_ser__from>").append("0").append("</item_ser__from>\r\n");
											argData.append("<item_ser__to>").append("ZZ").append("</item_ser__to>\r\n");


											argData.append("<item_code_list>").append("").append("</item_code_list>\r\n");

											argData.append("</Detail>");
											argData.append("</Root>");

											System.out.println("argData=="+argData);
											argDom = genericUtility.parseString(argData.toString());
											// 13/06/14 manoharan delete line for which bom_code changed
											errString =  runMRPObj.validateFilterParams( argDom );
											if (errString != null && errString.trim().length() > 0)
											{
												System.out.println("Error validating filter parameters:..." + errString);
												return errString;
											}
											errString = runMRPObj.deleteOldPlan (siteCode,itemCode);
											if (errString != null && errString.trim().length() > 0)
											{
												System.out.println("Error validating filter parameters:..." + errString);
												return errString;
											}

											// end 13/06/14 manoharan

											sql = "select bomdet.item_code from bomdet bomdet, bom bom " +
											"  where bom.bom_code = bomdet.bom_code " +
											"  and bom.bom_code = ? " +
											"  and bom.site_code = ? ";
											pstmt = conn.prepareStatement(sql);
											//pstmt.setString(1, bomCodeRef); // 13/06/14 manoharan
											pstmt.setString(1, bomCodeOrg);
											pstmt.setString(2, siteCode);
											rs = pstmt.executeQuery();
											while (rs.next())
											{
												replaceBomItemList.add(rs.getString(1));


												errString = runMRPObj.deleteOldPlan (siteCode,rs.getString(1));
												if (errString != null && errString.trim().length() > 0)
												{
													System.out.println("Error validating filter parameters:..." + errString);
													return errString;
												}
												//errString = runMRPObj.deleteOldPlan (siteCode,rs.getString(1));
											}
											rs.close(); rs=null;
											pstmt.close(); pstmt=null;
											System.out.println("@@@@@ replaceBomItemList["+replaceBomItemList+"]");



											winName = "w_mrp_run_wiz";
											mrpGetData = runMRPObj.getData(argDom, argDom, winName, xtraParams);
											//	mrpGetData = runMRPObj.getData(argDom, dom2, winName, xtraParams);

											System.out.println("@@@@mrpGetData return string in bean::["+mrpGetData+"]");

											mrpGetDataDom = genericUtility.parseString(mrpGetData.toString());

											NodeList hdrDommList2 = mrpGetDataDom.getElementsByTagName("Detail2");
											System.out.println("len1===["+hdrDommList2.getLength()+"]");
											for (int dtlCtr2 = 0; dtlCtr2 < hdrDommList2.getLength(); dtlCtr2++)
											{
												Node detailListNode2 = hdrDommList2.item(dtlCtr2);

												if( detailListNode2.hasChildNodes() == true )
												{
													System.out.println("@@@@@@@@for_test detailListNode2.hasChildNodes()["+detailListNode2.hasChildNodes()+"]dtlCtr2["+dtlCtr2+"]");
													qtyReqdStr = "0";
													sourceSupply =  "";
													siteCodeSupp =  "";
													itemCodeSupp =  "";
													itemCodeDescr =  "";
													lotNo =  "";
													lotSl =  "";
													locCode =  "";
													unit =  "";
													parentItem =  ""; 
													tranSer =  "";
													demand =  "";
													supply =  "";
													planSupply =  "0";
													runningDemand =  "0";
													runningSupplyStr =  "0";
													runningPlanSupply =  "0";
													independentDemand =  "0";
													stockQty =  "0"; 
													othSupply =  "0";
													pendingPo =  "0";
													pendingDo =  "0";
													pendingIndent =  "0";
													pendingDr =  "0";
													itemCodeParent =  "";
													originalOrAltitem =  "";
													domCnt++;
													valueXmlString.append("<Detail2  domID='" + domCnt + "' >\r\n");

													System.out.println("@@@@@ node name1 ["+detailListNode2.getNodeName()+"]");
													NodeList refrenceList2= detailListNode2.getChildNodes();
													if( refrenceList2 != null )
													{
														System.out.println("refrenceList2.getLength()["+refrenceList2.getLength()+"]");
														for (int cntr2 = 0; cntr2 < refrenceList2.getLength(); cntr2++) 
														{
															System.out.println("@@@@@@@@ inside detail2["+cntr2+"]");
															Node	refrenceNode2 = refrenceList2.item(cntr2); 
															orderList1 = refrenceNode2.getChildNodes(); 
															System.out.println("@@@@@ node name2 ["+refrenceNode2.getNodeName()+"]");

															// for detail4 start
															if("Detail4".equalsIgnoreCase(refrenceNode2.getNodeName()))
															{
																//detail4Flag = true;
																NodeList orderList2 = refrenceNode2.getChildNodes();
																sourceSupply =  "";
																siteCodeSupp =  "";
																itemCodeSupp =  "";
																itemCodeDescr =  "";
																lotNo =  "";
																lotSl =  "";
																locCode =  "";
																unit =  "";
																parentItem =  ""; 
																tranSer =  "";
																demand =  "";
																supply =  "";
																planSupply =  "0";
																runningDemand =  "0";
																runningSupplyStr =  "0";
																runningPlanSupply =  "0";
																independentDemand =  "0";
																stockQty =  "0"; 
																othSupply =  "0";
																pendingPo =  "0";
																pendingDo =  "0";
																pendingIndent =  "0";
																pendingDr =  "0";
																itemCodeParent =  "";
																originalOrAltitem =  "";

																for (int nodCtr1 = 0; nodCtr1 < orderList2.getLength(); nodCtr1++) 
																{

																	Node detail4Node=orderList2.item(nodCtr1); 
																	//NodeList suppDetailList=detail4Node.getChildNodes();
																	//System.out.println("@@@@@@@@@orderNode node name[" + detail4Node.getNodeName()+"]"); 
																	//if("supp_detail".equalsIgnoreCase(detail4Node.getNodeName())) 
																	//	for (int cn = 0; cn < suppDetailList .getLength(); cn++) 
																	{
																		//String nodeName=suppDetailList.item(cn).getNodeName();


																		if("source_supply".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			sourceSupply =  detail4Node.getFirstChild().getNodeValue(); 
																		}
																		if("site_code".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			siteCodeSupp =  detail4Node.getFirstChild().getNodeValue(); 
																		}
																		if("item_code".equalsIgnoreCase(detail4Node.getNodeName())) 
																		{
																			itemCodeSupp =  detail4Node.getFirstChild().getNodeValue();
																		}
																		if("item_code_descr".equalsIgnoreCase(detail4Node.getNodeName())) 
																		{
																			itemCodeDescr =  detail4Node.getFirstChild().getNodeValue();
																		}

																		if("lot_no".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			lotNo =  detail4Node.getFirstChild().getNodeValue(); 
																		}
																		if("lot_sl".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			lotSl =  detail4Node.getFirstChild().getNodeValue(); 
																		}
																		if("loc_code".equalsIgnoreCase(detail4Node.getNodeName())) 
																		{
																			locCode =  detail4Node.getFirstChild().getNodeValue(); 
																		}
																		if("unit".equalsIgnoreCase(detail4Node.getNodeName())) 
																		{
																			unit =  detail4Node.getFirstChild().getNodeValue(); 
																		}
																		if("parent_item".equalsIgnoreCase(detail4Node.getNodeName())) 
																		{
																			parentItem =  detail4Node.getFirstChild().getNodeValue(); 
																		}
																		if("tran_ser".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			tranSer =  detail4Node.getFirstChild().getNodeValue();
																		}   
																		if("demand".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			demand =  detail4Node.getFirstChild().getNodeValue();
																		}  
																		if("supply".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			supply =  detail4Node.getFirstChild().getNodeValue();
																		} 
																		if("plan_supply".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			planSupply =  detail4Node.getFirstChild().getNodeValue();
																		} 
																		if("running_demand".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			runningDemand =  detail4Node.getFirstChild().getNodeValue();
																		} 
																		if("running_supply".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			runningSupplyStr =  detail4Node.getFirstChild().getNodeValue();
																		} 
																		if("running_plan_supply".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			runningPlanSupply =  detail4Node.getFirstChild().getNodeValue();
																		} 
																		if("independent_demand".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			independentDemand =  detail4Node.getFirstChild().getNodeValue();
																		} 
																		if("stock_qty".equalsIgnoreCase(detail4Node.getNodeName())) 
																		{
																			stockQty =  detail4Node.getFirstChild().getNodeValue(); 
																		}
																		if("oth_supply".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			othSupply =  detail4Node.getFirstChild().getNodeValue();
																		}
																		if("pending_po".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			pendingPo =  detail4Node.getFirstChild().getNodeValue();
																		}
																		if("pending_do".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			pendingDo =  detail4Node.getFirstChild().getNodeValue();
																		}
																		if("pending_indent".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			pendingIndent =  detail4Node.getFirstChild().getNodeValue();
																		}
																		if("pending_dr".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			pendingDr =  detail4Node.getFirstChild().getNodeValue();
																		}
																		if("item_code_parent".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			itemCodeParent =  detail4Node.getFirstChild().getNodeValue();
																		}
																		if("originalOrAltitem".equalsIgnoreCase(detail4Node.getNodeName()))
																		{
																			originalOrAltitem =  detail4Node.getFirstChild().getNodeValue();
																		}

																	}
																}


																System.out.println("@@@@ for test ctr["+dtlCtr+"]itemCodeSupp["+itemCodeSupp+"]sourceSupply["+sourceSupply+"]siteCodeSupp["+siteCodeSupp+"]-itemCodeSupp["+itemCodeSupp+"]-lotNo["+lotNo+"]-lotSl["+lotSl+"]-locCode["+locCode+"]-tranSer["+tranSer+"]@@@");

																if( "Stock".equalsIgnoreCase(tranSer))
																{
																	sourceSupply = sourceSupply+"S";	
																}


																domCnt2++;
																valueXmlString.append("<Detail4 domID='" + domCnt2 + "' >\r\n");

																valueXmlString.append("<source_supply protect = '1'>").append("<![CDATA[" + sourceSupply  + "]]>").append("</source_supply>\r\n");
																valueXmlString.append("<site_code protect = '1'>").append("<![CDATA[" + siteCode  + "]]>").append("</site_code>\r\n");
																valueXmlString.append("<item_code protect = '1'>").append("<![CDATA[" + itemCodeSupp  + "]]>").append("</item_code>\r\n");
																valueXmlString.append("<item_code_descr protect = '1'>").append("<![CDATA[" + itemCodeDescr  + "]]>").append("</item_code_descr>\r\n");
																valueXmlString.append("<lot_no protect = '1'>").append("<![CDATA[" + lotNo  + "]]>").append("</lot_no>\r\n");
																valueXmlString.append("<lot_sl protect = '1'>").append("<![CDATA[" + lotSl  + "]]>").append("</lot_sl>\r\n");
																valueXmlString.append("<loc_code protect = '1'>").append("<![CDATA[" + locCode  + "]]>").append("</loc_code>\r\n");
																valueXmlString.append("<unit protect = '1'>").append("<![CDATA[" + unit  + "]]>").append("</unit>\r\n");
																valueXmlString.append("<parent_item protect = '1'>").append("<![CDATA[" + parentItem  + "]]>").append("</parent_item>\r\n");
																valueXmlString.append("<tran_ser protect = '1'>").append("<![CDATA[" + tranSer  + "]]>").append("</tran_ser>\r\n");
																valueXmlString.append("<demand protect = '1'>").append("<![CDATA[" + demand  + "]]>").append("</demand>\r\n");
																valueXmlString.append("<supply protect = '1'>").append("<![CDATA[" + supply  + "]]>").append("</supply>\r\n");
																valueXmlString.append("<plan_supply protect = '1'>").append("<![CDATA[" + planSupply  + "]]>").append("</plan_supply>\r\n");
																valueXmlString.append("<running_demand protect = '1'>").append("<![CDATA[" + runningDemand  + "]]>").append("</running_demand>\r\n");
																valueXmlString.append("<running_supply protect = '1'>").append("<![CDATA[" + runningSupply  + "]]>").append("</running_supply>\r\n");
																valueXmlString.append("<running_plan_supply protect = '1'>").append("<![CDATA[" + runningPlanSupply  + "]]>").append("</running_plan_supply>\r\n");
																valueXmlString.append("<independent_demand protect = '1'>").append("<![CDATA[" + independentDemand  + "]]>").append("</independent_demand>\r\n");
																valueXmlString.append("<stock_qty protect = '1'>").append("<![CDATA[" + stockQty  + "]]>").append("</stock_qty>\r\n");
																valueXmlString.append("<oth_supply protect = '1'>").append("<![CDATA[" + othSupply  + "]]>").append("</oth_supply>\r\n");
																valueXmlString.append("<pending_po protect = '1'>").append("<![CDATA[" + pendingPo  + "]]>").append("</pending_po>\r\n");
																valueXmlString.append("<pending_do protect = '1'>").append("<![CDATA[" + pendingDo  + "]]>").append("</pending_do>\r\n");
																valueXmlString.append("<pending_indent protect = '1'>").append("<![CDATA[" + pendingIndent  + "]]>").append("</pending_indent>\r\n");
																valueXmlString.append("<pending_dr protect = '1'>").append("<![CDATA[" + pendingDr  + "]]>").append("</pending_dr>\r\n");
																valueXmlString.append("<item_code_parent protect = '1'>").append("<![CDATA[" + itemCodeParent  + "]]>").append("</item_code_parent>\r\n");
																valueXmlString.append("<originalOrAltitem protect = '1'>").append("<![CDATA[" + originalOrAltitem  + "]]>").append("</originalOrAltitem>\r\n");
																valueXmlString.append("</Detail4>\r\n");

															}

															//////////////////////////////////////////////////////////
															if("reference".equalsIgnoreCase(refrenceNode2.getNodeName())) 
															{
																orderList =  refrenceNode2.getChildNodes();
																for (int nodCtr1 = 0; nodCtr1 < orderList .getLength(); nodCtr1++) 
																{
																	orderNode=orderList.item(nodCtr1);
																	orderDtlList=orderNode.getChildNodes();
																	if("order".equalsIgnoreCase(orderNode.getNodeName()))
																	{
																		saleOrder = "";
																		lineNo = "";
																		bomCodeParent= "";
																		bomCodeOrg = "";
																		bomCodeRef = "";
																		itemCode= "";
																		itemCodeDescr = "";
																		qtyReqdStr = "0";
																		unit = "";
																		sourceSupply = "";
																		sourceSupplyRef = "";
																		suppSour = "";
																		for (int cntr = 0; cntr < orderDtlList.getLength(); cntr++) 
																		{
																			Node	detail2Node = orderDtlList.item(cntr); 

																			if("sale_order".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				saleOrder =  detail2Node.getTextContent();
																			}
																			if("line_no".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				lineNo =   detail2Node.getTextContent();
																			}
																			if("site_code".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				siteCode =  detail2Node.getTextContent(); 
																			}
																			if("bom_code_parent".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				bomCodeParent =  detail2Node.getTextContent();
																			}
																			if("bom_code_org".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				bomCodeOrg =  detail2Node.getTextContent();
																			}
																			if("bom_code_ref".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				bomCodeRef  =  detail2Node.getTextContent();
																			}
																			if("item_code".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				itemCode =  detail2Node.getTextContent();
																			}
																			if("item_code_descr".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				itemCodeDescr =  detail2Node.getTextContent();
																			}
																			if("qty_reqd".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				qtyReqdStr =  detail2Node.getTextContent();
																			}
																			if("unit".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				unit =  detail2Node.getTextContent();
																			}
																			if("source_supply".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				sourceSupply =  detail2Node.getTextContent();
																			}
																			if("source_supply_ref".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				sourceSupplyRef =  detail2Node.getTextContent();
																			}
																			if("supp_sour".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				suppSour =  detail2Node.getTextContent();
																			}

																			if("itemCodeDetailMap".equalsIgnoreCase( detail2Node.getNodeName()))
																			{
																				itemCodeDetailMapStr =  detail2Node.getTextContent();
																				System.out.println("@@@@@@ itemCodeDetailMapStr["+itemCodeDetailMapStr+"]");
																			}

																		}
																		System.out.println("14/06/14 After recalculate itemCode {" + itemCode +"] bomCodeRef [" + bomCodeRef + "] bomCodeParent [" + bomCodeParent+ "]" );
																	}
																}
																////////////////////////////////////////////////////////
																System.out.println("13/06/14  reference qtyReqdStr before["+qtyReqdStr+"]");
																if (qtyReqdStr == null || "null".equals(qtyReqdStr) )
																{
																	qtyReqdStr = "0";
																}
																qtyReqd = Double.parseDouble(qtyReqdStr);
																System.out.println("13/06/14  qtyReqd before["+qtyReqd+"]itemCode["+itemCode+"]");
																if(qtyReqd > 0)
																{
																	System.out.println("13/06/14  inside qtyReqd before["+qtyReqd+"]");
																	//valueXmlString.append("<reference protect = '1'>\r\n");
																	//valueXmlString.append("<order protect = '1' domID='" + domCnt + "'>\r\n");
																	valueXmlString.append("<sale_order protect = '1'>").append("<![CDATA[" + saleOrder  + "]]>").append("</sale_order>\r\n");
																	valueXmlString.append("<line_no protect = '1'>").append("<![CDATA[" + lineNo  + "]]>").append("</line_no>\r\n");
																	valueXmlString.append("<site_code protect = '1'>").append("<![CDATA[" + siteCode  + "]]>").append("</site_code>\r\n");
																	valueXmlString.append("<qty_reqd protect = '1'>").append("<![CDATA[" + qtyReqdStr  + "]]>").append("</qty_reqd>\r\n");
																	valueXmlString.append("<item_code protect = '1'>").append("<![CDATA[" + itemCode  + "]]>").append("</item_code>\r\n");
																	valueXmlString.append("<item_code_descr protect = '1'>").append("<![CDATA[" + itemCodeDescr  + "]]>").append("</item_code_descr>\r\n");
																	valueXmlString.append("<supp_sour protect = '1'>").append("<![CDATA[" + suppSour  + "]]>").append("</supp_sour>\r\n");
																	valueXmlString.append("<running_supply protect = '1'>").append("<![CDATA[" + runningSupplyStr  + "]]>").append("</running_supply>\r\n");
																	valueXmlString.append("<unit protect = '1'>").append("<![CDATA[" + unit  + "]]>").append("</unit>\r\n");
																	valueXmlString.append("<originalOrAltitem protect = '1'>").append("<![CDATA[" + originalOrAltitem  + "]]>").append("</originalOrAltitem>\r\n");
																	valueXmlString.append("<bom_code_parent protect = '1'>").append("<![CDATA[" + bomCodeParent  + "]]>").append("</bom_code_parent>\r\n");  //bomCodeParent
																	valueXmlString.append("<bom_code_org protect = '1'>").append("<![CDATA[" + bomCodeRef  + "]]>").append("</bom_code_org>\r\n");
																	if( "P".equalsIgnoreCase(suppSour))
																	{
																		valueXmlString.append("<bom_code_ref protect = '1'>").append(" ").append("</bom_code_ref>\r\n");
																	}
																	else
																	{
																		valueXmlString.append("<bom_code_ref protect = '1'>").append("<![CDATA[" + bomCodeRef  + "]]>").append("</bom_code_ref>\r\n");
																	}
																	valueXmlString.append("<source_supply protect = '1'>").append("<![CDATA[" + sourceSupply  + "]]>").append("</source_supply>\r\n");
																	valueXmlString.append("<source_supply_ref protect = '1'>").append("<![CDATA[" + sourceSupplyRef  + "]]>").append("</source_supply_ref>\r\n");
																	//valueXmlString.append("</order>\r\n");
																	//valueXmlString.append("</reference>\r\n");
																}
																////////////////////////////////////////////////////////
															}
															///////////////////////////////////////////////////////////
														}	

													}
													valueXmlString.append("</Detail2>\r\n");
												}
											}

										}
										else
										{

											domCnt++;
											valueXmlString.append("<Detail2  domID='" + domCnt + "' >\r\n");
											valueXmlString.append("<reference protect = '1'>");
											valueXmlString.append("<order protect = '1' domID='" + domCnt + "'>\r\n");
											valueXmlString.append("<sale_order protect = '1'>").append("<![CDATA[" + saleOrder  + "]]>").append("</sale_order>\r\n");
											valueXmlString.append("<line_no protect = '1'>").append("<![CDATA[" + lineNo  + "]]>").append("</line_no>\r\n");
											valueXmlString.append("<site_code protect = '1'>").append("<![CDATA[" + siteCode  + "]]>").append("</site_code>\r\n");
											valueXmlString.append("<qty_reqd protect = '1'>").append("<![CDATA[" + qtyReqdStr  + "]]>").append("</qty_reqd>\r\n");
											valueXmlString.append("<item_code protect = '1'>").append("<![CDATA[" + itemCode  + "]]>").append("</item_code>\r\n");
											valueXmlString.append("<item_code_descr protect = '1'>").append("<![CDATA[" + itemCodeDescr  + "]]>").append("</item_code_descr>\r\n");
											valueXmlString.append("<supp_sour protect = '1'>").append("<![CDATA[" + suppSour  + "]]>").append("</supp_sour>\r\n");
											valueXmlString.append("<running_supply protect = '1'>").append("<![CDATA[" + runningSupplyStr  + "]]>").append("</running_supply>\r\n");
											valueXmlString.append("<unit protect = '1'>").append("<![CDATA[" + unit  + "]]>").append("</unit>\r\n");
											valueXmlString.append("<originalOrAltitem protect = '1'>").append("<![CDATA[" + originalOrAltitem  + "]]>").append("</originalOrAltitem>\r\n");
											valueXmlString.append("<bom_code_parent protect = '1'>").append("<![CDATA[" + bomCodeParent  + "]]>").append("</bom_code_parent>\r\n");
											valueXmlString.append("<bom_code_org protect = '1'>").append("<![CDATA[" + bomCodeOrg  + "]]>").append("</bom_code_org>\r\n");
											valueXmlString.append("<bom_code_ref protect = '1'>").append("<![CDATA[" + bomCodeRef  + "]]>").append("</bom_code_ref>\r\n");
											valueXmlString.append("<source_supply protect = '1'>").append("<![CDATA[" + sourceSupply  + "]]>").append("</source_supply>\r\n");
											valueXmlString.append("<source_supply_ref protect = '1'>").append("<![CDATA[" + sourceSupplyRef  + "]]>").append("</source_supply_ref>\r\n");
											valueXmlString.append("</order>\r\n");
											valueXmlString.append("</reference>\r\n");



											//tempdetail4OuterList.clear();
											tempdetail4OuterList = (ArrayList) detail4ListMap.get(saleOrder+lineNo+itemCode);

											System.out.println("@@@@@@1073["+detail4ListMap.size()+"]:["+saleOrder+lineNo+itemCode+"]detail4ListMap["+detail4ListMap+"]");
											if( tempdetail4OuterList != null && tempdetail4OuterList.size() > 0 )
											{
												System.out.println("@@@@@@1074[:tempdetail4OuterList.size["+tempdetail4OuterList.size()+"]");

												for( int listCtr=0; listCtr < tempdetail4OuterList.size() ; listCtr++)
												{	 
													//tempdetail4List.clear();
													tempdetail4List = ( ArrayList ) tempdetail4OuterList.get(listCtr);

													System.out.println("@@@@@@ tempdetail4List listCtr["+listCtr+"]["+tempdetail4List+"]");

													domCnt2++;
													int k=0;
													valueXmlString.append("<Detail4 domID='" + domCnt2 + "' >\r\n");
													valueXmlString.append("<site_code protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) +  "]]>").append("</site_code>\r\n");
													valueXmlString.append("<item_code protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) +  "]]>").append("</item_code>\r\n");
													valueXmlString.append("<item_code_descr protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</item_code_descr>\r\n");
													valueXmlString.append("<lot_no protect = '1' >" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</lot_no>\r\n");
													valueXmlString.append("<lot_sl protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</lot_sl>\r\n");
													valueXmlString.append("<loc_code protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</loc_code>\r\n");
													valueXmlString.append("<tran_ser protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</tran_ser>\r\n");
													valueXmlString.append("<tran_id protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</tran_id>\r\n");
													valueXmlString.append("<supply protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</supply>\r\n");
													valueXmlString.append("<alloc_qty protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</alloc_qty>\r\n");
													valueXmlString.append("<unit protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</unit>\r\n");
													valueXmlString.append("<ref_line_no protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</ref_line_no>\r\n");
													valueXmlString.append("<planned_quantity protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</planned_quantity>\r\n");
													valueXmlString.append("<parent_item protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</parent_item>\r\n");
													valueXmlString.append("<source_supply protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</source_supply>\r\n");
													valueXmlString.append("<item_code_parent protect = '1'>" ).append("<![CDATA[" + tempdetail4List.get(k++) + "]]>").append("</item_code_parent>\r\n");
													valueXmlString.append("</Detail4>\r\n");


												}
											}
											valueXmlString.append("</Detail2>\r\n");

										}
										//System.out.println("@@@@@@@@@ 328 xmldata============[["+xmldata+"]]");
									}
								}
							}
						}
					}
				}
			}	

			// end	

			valueXmlString.append("</Root>");
			xmldata =  valueXmlString.toString();
			System.out.println("@@@@@@@@@final bean xmldata============[["+xmldata+"]]");

		}//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 Exception occurs in MrpWizPrsSaveBean  :"+e);			
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally 
		{
			try
			{

				if (errString == null || errString.trim().length() == 0)
				{
					System.out.println("@@@@@@ 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 Exception occurs in MrpWizPrsSaveBean  :"+e);			
				e.printStackTrace();
				throw new ITMException(e);
			}
		}



		return xmldata;
	}

	/*
	private String setDescription(String field, String table,
			String field2, String value,Connection conn) throws SQLException 
			{
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String descr="",sql="";

		sql = "select "+ field +" from "+ table +" where "+ field2 +" = ? ";
		pstmt = conn.prepareStatement(sql);
		pstmt.setString( 1, value );
		rs = pstmt.executeQuery();
		if (rs.next())
		{
			descr = rs.getString(1);
		}
		rs.close();rs = null;
		pstmt.close();pstmt = null;  

		System.out.println("@@@@@@@@cpatil-Descr["+descr+"]");

		return descr;
			}
	 */

	private String getWinName(Node node) throws Exception 
	{
		String objName = "";
		NamedNodeMap attrMap = node.getAttributes(); 
		objName = attrMap.getNamedItem("objName").getNodeValue(); 
		System.out.println(" Object Name is==>" + objName); 
		return "w_" + objName; 
	}

	private String checkNull(String value)
	{
		if (value == null)
		{
			value = "";
		}
		return value;
	}
	private String getItemType(String suppSour) throws SQLException 
	{

		String value="";

		suppSour = checkNull(suppSour);
		//System.out.println("@@@@@@@@@ inside getItemType suppSour["+suppSour+"]");
		//		if( flag == true )
		//		{
		//			value="0";
		//		}
		//		else 
		if("M".equalsIgnoreCase(suppSour.trim()) )  // M
		{
			value="1";
			//System.out.println("@@@@@@@@@ inside M suppSour["+suppSour+"]value["+value+"]");
		}
		else if("P".equalsIgnoreCase(suppSour) )
		{
			value="2";
			//System.out.println("@@@@@@@@@ inside P suppSour["+suppSour+"]value["+value+"]");
		}
		else
		{
			value="0";
			//System.out.println("@@@@@@@@@ inside else suppSour["+suppSour+"]value["+value+"]");
		}
		//System.out.println("return --- > suppSour["+suppSour+"]value["+value+"]");
		return value;
	}





}