
/********************************************************
	Title : WorkOrderAmdEJB
	Date  : 21/01/09
	Author: pankaj singh

********************************************************/

package ibase.webitm.ejb.mfg;

import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;

import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Date;
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import java.text.SimpleDateFormat;
import java.sql.Timestamp;
import ibase.webitm.ejb.sys.UtilMethods;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.ejb.Stateless; // added for ejb3

@Stateless // added for ejb3

public class WorkOrderAmd extends ValidatorEJB implements  WorkOrderAmdLocal,  WorkOrderAmdRemote //SessionBean
{
	/*public void ejbCreate() throws RemoteException, CreateException
	{
		System.out.println("<======= WorkOrderAmdEJB DISPLAY IS IN PROCESS ! \n Welcome!========>");
	}
	public void ejbRemove()
	{
	}
	public void ejbActivate()
	{
	}
	public void ejbPassivate()
	{
	}*/
	public String wfValData() throws RemoteException,ITMException
	{
		return "";
	}

	public String itemChanged() throws RemoteException,ITMException
	{
		return "";
	}

	public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		String errString = null;
		Document dom = null;
		Document dom1 = null;
		Document dom2 = null;
		try
		{
			dom = parseString(xmlString);
			dom1 = parseString(xmlString1);
			if (xmlString2.trim().length() > 0 )
			{
				dom2 = parseString("<Root>" + xmlString2+ "</Root>");
			}
			errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
		}
		catch(Exception e)
		{
			System.out.println("Exception : WorkOrderAmdEJB : wfValData(String xmlString) : ==>\n"+e.getMessage());
		}
		return (errString);
	}
	public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		NodeList parentNodeList = null;
		NodeList childNodeList = null;
		Node parentNode = null;
		Node childNode = null;
		int ctr=0;
		String childNodeName = null;
		String errString = "";
		String errCode = "",errcode = "";
		Connection conn = null;
		PreparedStatement pstmt = null ;
		ResultSet rs = null , rs1 = null;
		String sql = "" ,sql1 = "";
		String userId = "";
		String effFromStr = null;
		String validUptoStr = null;
		String divHead="",tranIdRef = "";
		double minAmount = 0;
		double maxAmount = 0;
		int cnt = 0,cnt1 = 0;
		int currentFormNo=0;
		int childNodeListLength;
		String mfgDateStart = "",expDate = "",planDueDate = "";
		Timestamp mfgDateStartTs = null,mfgDateStartOldTs  = null;
		Timestamp expDateTs = null,expDateOldTs  = null;
		String expDateOld = "";
		String mfgDateStartOld = "";
        ConnDriver connDriver = new ConnDriver();
		String siteCode = "",empCodeAmd = "",startTime = "",confirmed = "",status = "",projCode = "";
		Timestamp planDueDateTs = null,planDueDateOldTs  = null;
		String planDueDateOld = "";
		try
		{
			conn = connDriver.getConnectDB("DriverITM");
			connDriver = null;
			userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
			GenericUtility genericUtility = GenericUtility.getInstance();
			if(objContext != null && objContext.trim().length()>0)
			{
				currentFormNo = Integer.parseInt(objContext);
			}
			switch(currentFormNo)
			{
				case 1 :

					parentNodeList = dom.getElementsByTagName("Detail1");
					parentNode = parentNodeList.item(0);
					childNodeList = parentNode.getChildNodes();
					childNodeListLength = childNodeList.getLength();
					for(ctr = 0; ctr < childNodeListLength; ctr++)
					{
						childNode = childNodeList.item(ctr);
						childNodeName = childNode.getNodeName();
					if (childNodeName.equalsIgnoreCase("site_code"))
						{
							siteCode = getColumnValue("site_code",dom);
							siteCode = siteCode == null ? "" : siteCode;
							sql = "Select count(*) from site where site_code = ?";
							pstmt= conn.prepareStatement(sql);
							pstmt.setString(1,siteCode);
							rs = pstmt.executeQuery(); 
							if(rs.next())
							 {
							   cnt = rs.getInt(1);
							 }
							pstmt.close();
							rs.close();
							pstmt = null;
							rs = null;
							if(cnt == 0)
							{
								errCode = "VMSITE1";
								errString = getErrorString("site_code",errCode,userId);
								break;
							}
						}// End Of site_code
						else if (childNodeName.equalsIgnoreCase("work_order__ref"))
						{
							tranIdRef = getColumnValue("work_order__ref",dom);
							sql = "Select status from workorder where work_order = ?";
							pstmt= conn.prepareStatement(sql);
							pstmt.setString(1,tranIdRef);
							rs = pstmt.executeQuery(); 
							if(rs.next())
							 {
							   status = rs.getString(1) == null ? "" : rs.getString(1);
							 }
							pstmt.close();
							rs.close();
							pstmt = null;
							rs = null;
							System.out.println("status>>>>>>>>>>>>>> " + status);
							if( status.equalsIgnoreCase("R") ||  status.equalsIgnoreCase("U"))
							{
								System.out.println("U R permited>>>>>>>>>>>>>> " + status);
							}	
							else
							{
								errCode = "VTWOSA";
								errString = getErrorString("tran_id__ref",errCode,userId);
								break;
							}
						}// End Of tran_id__ref
						
						else if (childNodeName.equalsIgnoreCase("mfg_date__start"))
						{
							
							mfgDateStart = getColumnValue("mfg_date__start",dom);
							mfgDateStartOld = getColumnValue("mfg_date__start__o",dom);
							expDate = getColumnValue("exp_date",dom);
							planDueDate = getColumnValue("plan__due_date",dom);
							if( (mfgDateStart == null || mfgDateStart.trim().length() == 0) && (expDate == null || expDate.trim().length() == 0)&&(planDueDate == null || planDueDate.trim().length() == 0))
							{
								errCode = "VTWOVLNL";
								errString = getErrorString("mfg_date__start",errCode,userId);
								break;
							}// end if any value is null
							else
							{
								mfgDateStart  = genericUtility.getValidDateString(mfgDateStart,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
								mfgDateStartTs = Timestamp.valueOf(mfgDateStart + " 00:00:00.0");
								System.out.println("mfgDateStart in Timestamp:- " + mfgDateStart);
								if(mfgDateStartOld != null && mfgDateStartOld.trim().length() > 0)
								{
									mfgDateStartOld  = genericUtility.getValidDateString(mfgDateStartOld,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
									mfgDateStartOldTs = Timestamp.valueOf(mfgDateStartOld + " 00:00:00.0");
									System.out.println("mfgDateStartOldTs in Timestamp:- " + mfgDateStartOldTs);
									if(mfgDateStartTs.compareTo(mfgDateStartOldTs) == 0)
									{
										errCode = "VTWOMFNL";
										errString = getErrorString("mfg_date__start",errCode,userId);
										break;
									}
									if(mfgDateStartTs.before(mfgDateStartOldTs))
									{
										errCode = "VTWOMFIN";
										errString = getErrorString("mfg_date__start",errCode,userId);
										break;
									}
								}
								/*if(mfgDateStartTs.before(getCurrdateAppFormat()))
								{
									System.out.println("Previous day mfg date:");
									errCode = "VTWOMFMFT";
									errString = getErrorString("start_time",errCode,userId);
									break;
								}*/
							}
						}//end mfg_date
						else if (childNodeName.equalsIgnoreCase("exp_date"))
						{
							
							mfgDateStart = getColumnValue("mfg_date__start",dom);
							expDateOld = getColumnValue("exp_date__o",dom);
							expDate = getColumnValue("exp_date",dom);
							planDueDate = getColumnValue("plan__due_date",dom);
							
							if(  expDate == null || expDate.trim().length() == 0)
							{
								
							}// end if expDate is null
							else
							{
								expDate  = genericUtility.getValidDateString(expDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
								System.out.println("expDate in dbdate format:- " + expDate);
								System.out.println("expDate + 00:00:00.0 in dbdate format:- " + (expDate + " 00:00:00.0"));
								expDateTs = Timestamp.valueOf(expDate + " 00:00:00.0");
								if(mfgDateStart != null && mfgDateStart.trim().length() > 0)
								{
									mfgDateStart  = genericUtility.getValidDateString(mfgDateStart,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
									System.out.println("mfgDateStart in dbdate format:- " + mfgDateStart);
									System.out.println("mfgDateStart + 00:00:00.0 in dbdate format:- " + (mfgDateStart + " 00:00:00.0"));
									mfgDateStartTs = Timestamp.valueOf(mfgDateStart + " 00:00:00.0");
									System.out.println("mfgDateStart in Timestamp:- " + mfgDateStart);	
								}
								if(expDateOld != null && expDateOld.trim().length() > 0)
								{
									expDateOld  = genericUtility.getValidDateString(expDateOld,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
									System.out.println("expDateOld in dbdate format:- " + expDateOld);
									System.out.println("expDateOld + 00:00:00.0 in dbdate format:- " + (expDateOld + " 00:00:00.0"));
									expDateOldTs = Timestamp.valueOf(expDateOld + " 00:00:00.0");
									System.out.println("mfgDateStartOldTs in Timestamp:- " + expDateOldTs);
									System.out.println("expDateTs.compareTo(mfgDateStartTs)>>>>>>>>> " + expDateTs.compareTo(mfgDateStartTs));
									if(expDateTs.compareTo(mfgDateStartTs) <= 0)
									{

										errCode = "VTWOEXMF";
										errString = getErrorString("mfg_date__start",errCode,userId);
										break;
									}
									if(expDateTs.before(expDateOldTs))
									{
										System.out.println("Changed expiry date less the old exp date:");
										errCode = "VTWOEXIN";
										errString = getErrorString("mfg_date__start",errCode,userId);
										break;
									}
								}
//								if(expDateTs.compareTo(expDateOldTs) == 0)
//								{
//									errCode = "VTWOVLNL";
//									errString = getErrorString("mfg_date__start",errCode,userId);
//									break;
//								}
								
								if(expDateTs.before(getCurrdateAppFormat()))
								{
									System.out.println("Previous day expdate:");
									errCode = "VTWOMFMFT";
									errString = getErrorString("start_time",errCode,userId);
									break;
								}
							}
						}// end exp date
						else if (childNodeName.equalsIgnoreCase("plan__due_date"))
						{
						
							mfgDateStart = getColumnValue("mfg_date__start",dom);
							planDueDateOld = getColumnValue("plan_due_date_o",dom);
							expDate = getColumnValue("exp_date",dom);
							planDueDate = getColumnValue("plan__due_date",dom);
							if(  planDueDate == null || planDueDate.trim().length() == 0)
							{
								
							}// end if planDueDate is null
							else
							{
								planDueDate  = genericUtility.getValidDateString(planDueDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
								System.out.println("planDueDate in dbdate format:- " + planDueDate);
								System.out.println("planDueDate + 00:00:00.0 in dbdate format:- " + (planDueDate + " 00:00:00.0"));
								planDueDateTs = Timestamp.valueOf(planDueDate + " 00:00:00.0");
								System.out.println("planDueDateTs in Timestamp:- " + planDueDateTs);
								System.out.println("planDueDateOld:- " + planDueDateOld);
								if(planDueDateOld != null && planDueDateOld.trim().length() > 0)
								{
									planDueDateOld  = genericUtility.getValidDateString(planDueDateOld,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
									System.out.println("planDueDateOld in dbdate format:- " + planDueDateOld);
									System.out.println("planDueDateOld + 00:00:00.0 in dbdate format:- " + (planDueDateOld + " 00:00:00.0"));
									planDueDateOldTs = Timestamp.valueOf(planDueDateOld + " 00:00:00.0");
									System.out.println("planDueDateOldTs in Timestamp:- " + planDueDateOldTs);
									if(planDueDateTs.compareTo(planDueDateOldTs) == 0)
									{
										errCode = "VTWOPLNL";
										errString = getErrorString("mfg_date__start",errCode,userId);
										break;
									}
									if(planDueDateTs.before(planDueDateOldTs))
									{
										errCode = "VTWOPLIN";
										errString = getErrorString("mfg_date__start",errCode,userId);
										break;
									}
								}
								/*if(planDueDateTs.before(getCurrdateAppFormat()))
								{
									System.out.println("Previous day plan date:");
									errCode = "VTWOMFPLT";
									errString = getErrorString("start_time",errCode,userId);
									break;
								}*/
							}//plan__due_date not null
						}// end plan__due_date
						// end proj_time
					}//end for	
			} //END switch
		}//END TRY
		catch(Exception e)
		{
			System.out.println("Exception ::"+e);
			e.printStackTrace();
			errString=e.getMessage();
		}
		finally
		{
			try
			{
				if(conn!=null)
				{
					if(pstmt != null )pstmt.close();
					if(rs != null )rs.close();
					if(rs1 != null )rs.close();
					rs = null;
					rs1 = null;
					pstmt =null;
					conn.close();
				}
				conn = null;
			}catch(Exception d)
				{
				  d.printStackTrace();
				}
			System.out.println("[WorkOrderAmdEJB] Connection is Closed");
		}
		System.out.println("ErrString ::"+errString);
		return errString;
	}//END OF VALIDATION

	public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		Document dom = null;
		Document dom1 = null;
		Document dom2 = null;
		String valueXmlString = "";
		try
		{
			dom = parseString(xmlString);
			System.out.println("xmlString" + xmlString);
			dom1 = parseString(xmlString1);
			if (xmlString2.trim().length() > 0 )
			{
				dom2 = parseString(xmlString2);
			}
			valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
		}
		catch(Exception e)
		{
			System.out.println("Exception : [WorkOrderAmdEJB][itemChanged(String,String)] :==>\n"+e.getMessage());
		}
        return valueXmlString;
	}
	public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		StringBuffer valueXmlString = new StringBuffer();
		NodeList parentNodeList = null;
		NodeList childNodeList = null;
		Node parentNode = null;
		Node childNode = null;
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null ;
		int ctr=0;
		String childNodeName = null;
		String columnValue = null;
		String Col_name = "";
		int currentFormNo = 0 ,cnt = 0;
		int  ShortId = 0;
		String salesPers = "" ,itemSer = "",descr = "", empCodeAprv = "",empCodeAmd = "",tranIdRef = "";
		String fName = "",lName = "",mName = "";
		String sql = "",sql1 = "",startTime = "",noOfHour = "",endTime = "";
		double noOfHourD = 0.0;
		int noOfHr =0,noOfMin = 0;
		String trackShelfLife = "",mfgDateStartStr = "",expDateStr = "",planDueDateStr = "";
		int shelfLife = 0;
		Timestamp mfgDateStart = null,expDate = null,planDueDate = null;
		String noOfHourStr = "",startTimeStr = "",endTimeStr = "";
		Timestamp startTs = null,endTs = null;
		String loginSite = "", siteCode = "",status= "",siteDescr = "";
		Calendar calender = Calendar.getInstance();
		ConnDriver connDriver = new ConnDriver();
		Timestamp startTimeTs = null,endTimeTs = null,statusDateTs = null;
		GenericUtility genericUtility = GenericUtility.getInstance();
		String statusDate = "",projCode="",workCntr = "",workCntrDescr = "";
		try
		{
			conn = connDriver.getConnectDB("DriverITM");
			connDriver=null;
			if(objContext != null && objContext.trim().length()>0)
			{
				currentFormNo = Integer.parseInt(objContext);
			}
			System.out.println("Itemchange called for WorderAmd>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			System.out.println("FORM NO:::"+currentFormNo);
			System.out.println("\n Extra param........"+xtraParams);
			valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
			valueXmlString.append(editFlag).append("</editFlag></header>");
			valueXmlString.append("<Detail>");

			switch(currentFormNo)
			{
				case 1 :
					parentNodeList = dom.getElementsByTagName("Detail1");
					parentNode = parentNodeList.item(0);
					childNodeList = parentNode.getChildNodes();
					ctr = 0;
					int childNodeListLength = childNodeList.getLength();
					do
					{
						childNode = childNodeList.item(ctr);
						childNodeName = childNode.getNodeName();
						if(childNodeName.equals(currentColumn))
						{
							if (childNode.getFirstChild() != null)
							{
								columnValue = childNode.getFirstChild().getNodeValue().trim();
							}
						}
						ctr++;
					}while(ctr < childNodeListLength  && !childNodeName.equals(currentColumn));	
					
					 if(currentColumn.trim().equalsIgnoreCase("itm_default"))
					{
						loginSite = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
						empCodeAmd = getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode");
						sql = "select descr from site where site_code = '"+loginSite+"'";
						pstmt= conn.prepareStatement(sql);
						rs = pstmt.executeQuery();
						if(rs.next())
						 {
						   descr = rs.getString(1) == null ? "" : rs.getString(1);
						 }
						pstmt.close();
						rs.close();
						pstmt = null;
						rs = null;
						String s = (new SimpleDateFormat(genericUtility.getApplDateFormat())).format(getCurrdateAppFormat()).toString();
						valueXmlString.append("<site_code>").append("<![CDATA["+loginSite.trim()+"]]>").append("</site_code>");
						valueXmlString.append("<tran_date>").append("<![CDATA["+s+"]]>").append("</tran_date>");
						valueXmlString.append("<site_descr>").append("<![CDATA["+descr.trim()+"]]>").append("</site_descr>");
						sql = "select emp_fname,emp_mname,emp_lname from employee where emp_code = '" + empCodeAmd.toUpperCase() + "'";
						pstmt= conn.prepareStatement(sql);
						rs = pstmt.executeQuery();
						if(rs.next())
						 {
						   fName = rs.getString("emp_fname") == null ? "" : rs.getString("emp_fname");
						   mName = rs.getString("emp_mname") == null ? "" : rs.getString("emp_mname");
						   lName = rs.getString("emp_lname") == null ? "" : rs.getString("emp_lname");
						 }
						pstmt.close();
						rs.close();
						pstmt = null;
						rs = null;
						valueXmlString.append("<emp_code__amd protect =\"1\">").append("<![CDATA["+empCodeAmd.toUpperCase().trim()+"]]>").append("</emp_code__amd>");
						valueXmlString.append("<emp_fname_1>").append("<![CDATA["+fName.trim()+"]]>").append("</emp_fname_1>");
						valueXmlString.append("<emp_mname_1>").append("<![CDATA["+mName.trim()+"]]>").append("</emp_mname_1>");
						valueXmlString.append("<emp_lname_1>").append("<![CDATA["+lName.trim()+"]]>").append("</emp_lname_1>");
					}
					else if(currentColumn.trim().equalsIgnoreCase("itm_defaultedit"))
					{
						tranIdRef = getColumnValue("work_order__ref",dom);
						expDateStr = getColumnValue("exp_date",dom);
						sql =" select track_shelf_life,shelf_life "
									+ " from item "
									+ " where item_code = "
									+ " (Select item_code from "
									+ " workorder where tran_id = '"+tranIdRef +"')" ;
						System.out.println("exp date qry>>>>>> " +sql);
						pstmt= conn.prepareStatement(sql);
						rs = pstmt.executeQuery();
						if(rs.next()) 
						 {
						   trackShelfLife = rs.getString(1);
						   shelfLife = rs.getInt(2);
						 }
						pstmt.close();
						rs.close();
						pstmt = null;
						rs = null;
						System.out.println("trackShelfLife>>>>> " +trackShelfLife + " shelfLife>>>>>>>> " + shelfLife);
						if(trackShelfLife.equalsIgnoreCase("Y"))
						{
							valueXmlString.append("<exp_date protect =\"1\">").append("<![CDATA["+expDateStr.trim()+"]]>").append("</exp_date>");
						}
						else
						{
							valueXmlString.append("<exp_date protect =\"0\">").append("<![CDATA["+expDateStr.trim()+"]]>").append("</exp_date>");
						}
					}
					else if(currentColumn.trim().equalsIgnoreCase("site_code"))
					{
						siteCode = getColumnValue("site_code",dom);
						sql = "select descr from site where site_code = '"+siteCode.toUpperCase()+"'";
						pstmt= conn.prepareStatement(sql);
						rs = pstmt.executeQuery();
						if(rs.next())
						 {
						   descr = rs.getString(1) == null ? "" : rs.getString(1);
						 }
						pstmt.close();
						rs.close();
						pstmt = null;
						rs = null;
						valueXmlString.append("<site_descr>").append("<![CDATA["+descr.trim()+"]]>").append("</site_descr>");
						valueXmlString.append("<site_code>").append("<![CDATA["+siteCode.toUpperCase().trim()+"]]>").append("</site_code>");
					}
					else if(currentColumn.trim().equalsIgnoreCase("work_order__ref"))
					{
						
						tranIdRef = getColumnValue("work_order__ref",dom);
						sql = " select mfg_date__start,exp_date,plan_due_date " 
								+ " from workorder where  tran_id = '"+tranIdRef +"'";
						System.out.println("values from workorder qry>>>>>> " +sql);
						pstmt= conn.prepareStatement(sql);
						rs = pstmt.executeQuery();
						if(rs.next()) 
						 {
							mfgDateStart = rs.getTimestamp(1);
							expDate = rs.getTimestamp(2);
							planDueDate = rs.getTimestamp(3);
						 }
						pstmt.close();
						rs.close();
						pstmt = null;
						rs = null;
						if(mfgDateStart != null )
						{
							mfgDateStartStr  = genericUtility.getValidDateString(mfgDateStart.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
						}
						if(expDate != null )
						{
							expDateStr  = genericUtility.getValidDateString(expDate.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
						}
						if(planDueDate != null)
						{
							planDueDateStr  = genericUtility.getValidDateString(planDueDate.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
						}
						valueXmlString.append("<mfg_date__start__o>").append("<![CDATA["+mfgDateStartStr.trim()+"]]>").append("</mfg_date__start__o>");
						valueXmlString.append("<exp_date__o>").append("<![CDATA["+expDateStr.trim()+"]]>").append("</exp_date__o>");
						valueXmlString.append("<plan_due_date_o>").append("<![CDATA["+planDueDateStr.trim()+"]]>").append("</plan_due_date_o>");
//						sql =" select track_shelf_life,shelf_life "
//									+ " from item "
//									+ " where item_code = "
//									+ " (Select item_code from "
//									+ " workorder where tran_id = '"+tranIdRef +"')" ;
//						System.out.println("exp date qry>>>>>> " +sql);
//						pstmt= conn.prepareStatement(sql);
//						rs = pstmt.executeQuery();
//						if(rs.next()) 
//						 {
//						   trackShelfLife = rs.getString(1);
//						   shelfLife = rs.getInt(2);
//						 }
//						pstmt.close();
//						rs.close();
//						pstmt = null;
//						rs = null;
//						System.out.println("trackShelfLife>>>>> " +trackShelfLife + " shelfLife>>>>>>>> " + shelfLife);
//						if(trackShelfLife.equalsIgnoreCase("Y"))
//						{
//							calender.setTimeInMillis(mfgDateStart.getTime());
//							calender.add(Calendar.MONTH,shelfLife);
//							System.out.println("exp date old>>>>>> " + expDateStr );
//							System.out.println("exp date calculated>>>>>> " + calender.getTime() );
//							sql = "select last_day(?)  from dual";
//							pstmt= conn.prepareStatement(sql);
//							pstmt.setTimestamp(1,new Timestamp(calender.getTime().getTime()));
//							rs = pstmt.executeQuery();
//							if(rs.next()) 
//							 {
//							   expDate = rs.getTimestamp(1);
//							 }
//							System.out.println("last exp date calculated>>>>>> " + expDate + " expDateStr>> " +expDateStr );
//							pstmt.close();
//							rs.close();
//							pstmt = null;
//							rs = null;
//							expDateStr  = genericUtility.getValidDateString(expDate.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
//							valueXmlString.append("<exp_date>").append("<![CDATA["+expDateStr.trim()+"]]>").append("</exp_date>");
//						}
//						else
//						{
//							valueXmlString.append("<exp_date>").append("").append("</exp_date>");
//						}
					}
					else if(currentColumn.trim().equalsIgnoreCase("emp_code__aprv"))
					{
						empCodeAprv = getColumnValue("mfg_date__start",dom);
						System.out.println("empCodeAprv:- " + empCodeAprv);
						sql = "select emp_fname,emp_mname,emp_lname from employee where emp_code = '" + empCodeAprv.toUpperCase() + "'";
						pstmt= conn.prepareStatement(sql);
						rs = pstmt.executeQuery();
						if(rs.next())
						 {
						   fName = rs.getString("emp_fname") == null ? "" : rs.getString("emp_fname");
						   mName = rs.getString("emp_mname") == null ? "" : rs.getString("emp_mname");
						   lName = rs.getString("emp_lname") == null ? "" : rs.getString("emp_lname");
						 }
						pstmt.close();
						rs.close();
						pstmt = null;
						rs = null;
						valueXmlString.append("<emp_fname>").append("<![CDATA["+fName.trim()+"]]>").append("</emp_fname>");
						valueXmlString.append("<emp_fname>").append("<![CDATA["+mName.trim()+"]]>").append("</emp_fname>");
						valueXmlString.append("<emp_fname>").append("<![CDATA["+lName.trim()+"]]>").append("</emp_fname>");
						System.out.println("valueXmlString for emp_code aprv:- " + valueXmlString);
					}
					else if(currentColumn.trim().equalsIgnoreCase("mfg_date__start"))
					{
						mfgDateStartStr = getColumnValue("mfg_date__start",dom);
						System.out.println("mfgDateStartStr:- " + mfgDateStartStr);
						if(mfgDateStartStr == null || mfgDateStartStr.trim().length() == 0)
						{
							tranIdRef = getColumnValue("work_order__ref",dom);
							sql =" select track_shelf_life,shelf_life "
										+ " from item "
										+ " where item_code = "
										+ " (Select item_code from "
										+ " workorder where tran_id = '"+tranIdRef +"')" ;
							System.out.println("exp date qry>>>>>> " +sql);
							pstmt= conn.prepareStatement(sql);
							rs = pstmt.executeQuery();
							if(rs.next()) 
							 {
							   trackShelfLife = rs.getString(1);
							   shelfLife = rs.getInt(2);
							 }
							pstmt.close();
							rs.close();
							pstmt = null;
							rs = null;
							System.out.println("trackShelfLife>>>>> " +trackShelfLife + " shelfLife>>>>>>>> " + shelfLife);
							if(trackShelfLife.equalsIgnoreCase("Y"))
							{
								valueXmlString.append("<exp_date protect =\"1\">").append("<![CDATA[]]>").append("</exp_date>");
							}
							else
							{
								valueXmlString.append("<exp_date protect =\"0\">").append("<![CDATA[]]>").append("</exp_date>");
							}
							}
						else
						{
							mfgDateStartStr  = genericUtility.getValidDateString(mfgDateStartStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
							System.out.println("mfgDateStartStr in dbdate format:- " + mfgDateStartStr);
							System.out.println("mfgDateStartStr + 00:00:00.0 in dbdate format:- " + (mfgDateStartStr + " 00:00:00.0"));
							mfgDateStart = Timestamp.valueOf(mfgDateStartStr + " 00:00:00.0");
							System.out.println("mfgDateStart in Timestamp:- " + mfgDateStart);
							tranIdRef = getColumnValue("work_order__ref",dom);
							sql =" select track_shelf_life,shelf_life "
										+ " from item "
										+ " where item_code = "
										+ " (Select item_code from "
										+ " workorder where tran_id = '"+tranIdRef +"')" ;
							System.out.println("exp date qry>>>>>> " +sql);
							pstmt= conn.prepareStatement(sql);
							rs = pstmt.executeQuery();
							if(rs.next()) 
							 {
							   trackShelfLife = rs.getString(1);
							   shelfLife = rs.getInt(2);
							 }
							pstmt.close();
							rs.close();
							pstmt = null;
							rs = null;
							System.out.println("trackShelfLife>>>>> " +trackShelfLife + " shelfLife>>>>>>>> " + shelfLife);
							if(trackShelfLife.equalsIgnoreCase("Y"))
							{
								calender.setTimeInMillis(mfgDateStart.getTime());
								calender.add(Calendar.MONTH,shelfLife);
								System.out.println("exp date old>>>>>> " + expDateStr );
								System.out.println("exp date calculated>>>>>> " + calender.getTime() );
								sql = "select last_day(?)  from dual";
								pstmt= conn.prepareStatement(sql);
								pstmt.setTimestamp(1,new Timestamp(calender.getTime().getTime()));
								rs = pstmt.executeQuery();
								if(rs.next()) 
								 {
								   expDate = rs.getTimestamp(1);
								 }
								System.out.println("last exp date calculated>>>>>> " + expDate + " expDateStr>> " +expDateStr );
								pstmt.close();
								rs.close();
								pstmt = null;
								rs = null;
								expDateStr  = genericUtility.getValidDateString(expDate.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
								valueXmlString.append("<exp_date protect =\"1\">").append("<![CDATA["+expDateStr.trim()+"]]>").append("</exp_date>");
							}
							else
							{
								valueXmlString.append("<exp_date protect =\"0\">").append("").append("</exp_date>");
							}
						}
					}
					valueXmlString.append("</Detail>");
				break;
		   	}//end of switch
			valueXmlString.append("</Root>");
		}//END OF TRY
		catch(Exception e)
		{
			e.printStackTrace();
			System.out.println("Exception ::"+e.getMessage());
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				if(conn!=null)
				{
					if(pstmt != null)pstmt.close();
					if(rs != null)rs.close();
					rs = null;
					pstmt = null;
					conn.close();
				}
				conn = null;
			}catch(Exception d)
			{
			  d.printStackTrace();
			}
			System.out.println("[WorkOrderAmdEJB] CONNECTION is CLOSED");
		}
		System.out.println("valueXmlString:::::"+valueXmlString.toString());
		return valueXmlString.toString();
	 }//END OF ITEMCHANGE
	  private Timestamp getCurrdateAppFormat()
    {
        String s = "";	
		 Timestamp timestamp = null;	
        GenericUtility genericUtility = GenericUtility.getInstance();
        try
        {
            java.util.Date date = null;
             timestamp = new Timestamp(System.currentTimeMillis());
            System.out.println(genericUtility.getDBDateFormat());
            SimpleDateFormat simpledateformat = new SimpleDateFormat(genericUtility.getDBDateFormat());
            date = simpledateformat.parse(timestamp.toString());
            timestamp = Timestamp.valueOf(simpledateformat.format(date).toString() + " 00:00:00.0");
           // s = (new SimpleDateFormat(genericUtility.getApplDateFormat())).format(timestamp).toString();
        }
        catch(Exception exception)
        {
            System.out.println("Exception in getCurrdateAppFormat " + exception.getMessage());
        }
        return timestamp;
    }
 }// END OF MAIN CLASS