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...");
		
		
		
		
		

		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("@@@@@@@@@ node name[" + detail2Node.getNodeName()+"]"); 
										{

											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;
									}

									if( !(( deleteBomList.contains(bomCodeParent) )  && deleteSaleOrderList.contains(saleOrder+"@"+lineNo)))
									{
										
										ArrayList tempdetail4OuterList = new ArrayList();
										ArrayList tempdetail4List = new ArrayList();
										
										//System.out.println("@@@@ inside first if....");
										if( bomCodeRef != null && ! (bomCodeParent.equalsIgnoreCase(bomCodeRef))   && bomCodeRef.trim().length() >0  &&  itemCodeDetailMapStr.contains(bomCodeParent)) 
										{
											//System.out.println("@@@@ inside second if....");
											// for creating existing row
											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");


											//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("@@@@@@@@@ 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("<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("00").append("</item_code__from>\r\n");
											argData.append("<item_code__to>").append("ZZ").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("</Detail>");
											argData.append("</Root>");

											System.out.println("argData=="+argData);
											argDom = genericUtility.parseString(argData.toString());


											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);
											pstmt.setString(2, siteCode);
											rs = pstmt.executeQuery();
											while (rs.next())
											{
												replaceBomItemList.add(rs.getString(1));

												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,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+"]");

													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;
																orderList1 = refrenceNode2.getChildNodes();
																sourceSupply = "";

																for (int nodCtr1 = 0; nodCtr1 < orderList1.getLength(); nodCtr1++) 
																{
																	Node detail4Node=orderList1.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");


															}

															//from detail2

															if( refrenceNode2.getFirstChild() != null)
															{	
																if("site_code".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	siteCode =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("item_code".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	itemCode =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("supp_sour".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	suppSour =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("demand".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	demand =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("supply".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	supply =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("due_date".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	dueDate =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("plan_supply".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	planSupply =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("running_demand".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	runningDemand =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("running_supply".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	runningSupplyStr =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("running_plan_supply".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	runningPlanSupply =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("independent_demand".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	independentDemand =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("bom_code".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	bomCode =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("order_opt".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	orderOpt =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("batch_qty_type".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	batchQtyType =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("unit".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	unit =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("min_order_qty".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	minOrderQty =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("integral_qty".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	integralQty =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("max_qty".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	maxQty =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("min_qty".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	minQty =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("reorder_qty".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	reorderQty =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("yield_perc".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	yieldPerc =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("min_plan_perc".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	minPlanPerc =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("batch_qty".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	batchQty =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("pur_lead_time".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	purLeadTime =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("qc_lead_time".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	qcLeadTime =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("mfg_lead_time".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	mfgLeadTime =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("description".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	description =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("stock_qty".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	stockQty =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("oth_supply".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	othSupply =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("pending_po".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	pendingPo =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("pending_do".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	pendingDo =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("pending_indent".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	pendingIndent =  refrenceNode2.getFirstChild().getNodeValue();
																}
																if("pending_dr".equalsIgnoreCase(refrenceNode2.getNodeName()))
																{
																	pendingDr =  refrenceNode2.getFirstChild().getNodeValue();
																}
															}
														}

													}

													//for detail2 tag
													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("<supp_sour protect = '1'>").append("<![CDATA[" + suppSour  + "]]>").append("</supp_sour>\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("<due_date protect = '1'>").append("<![CDATA[" + dueDate  + "]]>").append("</due_date>\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("<bom_code protect = '1'>").append("<![CDATA[" + bomCode  + "]]>").append("</bom_code>\r\n");
													valueXmlString.append("<order_opt protect = '1'>").append("<![CDATA[" + orderOpt  + "]]>").append("</order_opt>\r\n");
													valueXmlString.append("<batch_qty_type protect = '1'>").append("<![CDATA[" + batchQtyType  + "]]>").append("</batch_qty_type>\r\n");
													valueXmlString.append("<unit protect = '1'>").append("<![CDATA[" + unit  + "]]>").append("</unit>\r\n");
													valueXmlString.append("<min_order_qty protect = '1'>").append("<![CDATA[" + minOrderQty  + "]]>").append("</min_order_qty>\r\n");
													valueXmlString.append("<integral_qty protect = '1'>").append("<![CDATA[" + integralQty  + "]]>").append("</integral_qty>\r\n");
													valueXmlString.append("<max_qty protect = '1'>").append("<![CDATA[" + maxQty  + "]]>").append("</max_qty>\r\n");
													valueXmlString.append("<min_qty protect = '1'>").append("<![CDATA[" + minQty  + "]]>").append("</min_qty>\r\n");
													valueXmlString.append("<reorder_qty protect = '1'>").append("<![CDATA[" + reorderQty  + "]]>").append("</reorder_qty>\r\n");
													valueXmlString.append("<yield_perc protect = '1'>").append("<![CDATA[" + yieldPerc  + "]]>").append("</yield_perc>\r\n");
													valueXmlString.append("<min_plan_perc protect = '1'>").append("<![CDATA[" + minPlanPerc  + "]]>").append("</min_plan_perc>\r\n");
													valueXmlString.append("<batch_qty protect = '1'>").append("<![CDATA[" + batchQty  + "]]>").append("</batch_qty>\r\n");
													valueXmlString.append("<pur_lead_time protect = '1'>").append("<![CDATA[" + purLeadTime  + "]]>").append("</pur_lead_time>\r\n");
													valueXmlString.append("<qc_lead_time protect = '1'>").append("<![CDATA[" + qcLeadTime  + "]]>").append("</qc_lead_time>\r\n");
													valueXmlString.append("<mfg_lead_time protect = '1'>").append("<![CDATA[" + mfgLeadTime  + "]]>").append("</mfg_lead_time>\r\n");
													valueXmlString.append("<description protect = '1'>").append("<![CDATA[" + description  + "]]>").append("</description>\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");


													// for reference tag
													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[" + bomCodeRef  + "]]>").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");

													System.out.println("detail2 close : dtlCtr2["+dtlCtr2+"]");
													valueXmlString.append("</Detail2>\r\n");
												}

											}

											/*			
											if (mrpGetData.contains("<Detail2>"))
											{
												String replaceStr="";
												i++;

												String[] mrpGetDataParts = mrpGetData.split("<Detail2>");
												System.out.println("mrpGetDataParts length["+mrpGetDataParts.length+"]");
												for( i=0 ; i < mrpGetDataParts.length ; i++ )
												{
													String tempMrpGetDataParts = mrpGetDataParts[i];

													if( tempMrpGetDataParts != null && tempMrpGetDataParts.trim().length()  > 0 )
													{	
														tempMrpGetDataParts = "<Detail2>" + tempMrpGetDataParts;
														mrpGetDataParts[i] = tempMrpGetDataParts;

														System.out.println("tempMrpGetDataParts"+i+"]::["+tempMrpGetDataParts+"]");

														int itemCodeIndexFrom=0,itemCodeIndexTo=0;
														itemCode="";
														itemCodeDescr = "";
														if( tempMrpGetDataParts.indexOf("<item_code") != -1 )
														{
															itemCodeIndexFrom = tempMrpGetDataParts.indexOf("<item_code");
															System.out.println("itemCodeIndexFrom["+itemCodeIndexFrom+"]");
															itemCodeIndexTo = tempMrpGetDataParts.indexOf("</item_code");
															System.out.println("itemCodeIndexTo["+itemCodeIndexTo+"]");

															itemCode = tempMrpGetDataParts.substring(itemCodeIndexFrom+34, itemCodeIndexTo-3);
															itemCodeDescr = setDescription("descr", "item", "item_code", itemCode , conn);

															int suppSourIndexFrom = tempMrpGetDataParts.indexOf("<supp_sour");
															System.out.println("suppSourIndexFrom["+suppSourIndexFrom+"]");
															int suppSourIndexTo = tempMrpGetDataParts.indexOf("</supp_sour");
															System.out.println("suppSourIndexTo["+suppSourIndexTo+"]");
															suppSour = tempMrpGetDataParts.substring(suppSourIndexFrom+34, suppSourIndexTo-3);

															if( "P".equalsIgnoreCase(suppSour))
															{
																bomCodeParent = bomCodeRef;
																bomCodeRef = "";
															}

															System.out.println("itemCode["+itemCode+"]suppSour["+suppSour+"]");

															replaceStr = "<reference><order>" +
																	"<sale_order>"+saleOrder+"</sale_order>" +
																	"<line_no>"+lineNo+"1</line_no>" +
																	"<qty_reqd>"+qtyReqdStr+"</qty_reqd>" +
																	"<site_code>"+siteCode+"</site_code>" +
																	"<item_code>"+itemCode+"</item_code>" +
																	"<item_code_descr>"+itemCodeDescr+"</item_code_descr>" +
																	"<supp_sour>"+suppSour+"</supp_sour>" +
																	"<running_supply>"+runningSupply+"</running_supply>" +
																	"<unit>"+unit+"</unit>" +
																	"<originalOrAltitem>"+originalOrAltitem+"</originalOrAltitem>" +
																	"<bom_code_parent>"+bomCodeParent+"</bom_code_parent>" +
																	"<bom_code_org>"+bomCodeRef+"</bom_code_org>" +
																	"<bom_code_ref>"+bomCodeRef+"</bom_code_ref>" +
																	"<source_supply>"+suppSour+"</source_supply>" +
																	"</order>" +
																	"</reference>";

															System.out.println("@@@@mrpGetData replaceStr::["+replaceStr+"]");
															mrpGetDataParts[i] = tempMrpGetDataParts.replace("<Detail2>", replaceStr);
															System.out.println("@@@@mrpGetDataParts[i]::["+i+"]mrpGetDataParts[i]"+mrpGetDataParts[i]+"]");
														}
													}
												}

												//System.out.println("@@@@mrpGetData after merging return string in bean::["+mrpGetData+"]");
												//<?xml version = "1.0"?>
												String tempXmldata="";
												for( i=0 ; i < mrpGetDataParts.length  ; i++ )
												{
													tempXmldata = tempXmldata + mrpGetDataParts[i] ;	
												}

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

										}
										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; 
	}







}