package ibase.webitm.ejb.fin;

import java.rmi.RemoteException;
import java.util.*;
import java.util.Date;
import java.text.*;
import java.sql.*;
import javax.ejb.*;
import org.w3c.dom.*;


import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.GenericUtility;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3

public class ReceivablesOpening extends ValidatorEJB implements ReceivablesOpeningLocal,ReceivablesOpeningRemote // SessionBean
{

	GenericUtility genericUtility = GenericUtility.getInstance();
	ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
	Connection conn = null;

	/*public void ejbCreate() throws RemoteException, CreateException 
	{
		System.out.println("Create Method Called...");
	}
	public void ejbRemove()
	{
	}
	public void ejbActivate() 
	{
	}
	public void ejbPassivate() 
	{
	}*/
	public String wfValData() throws RemoteException,ITMException
	{
		System.out.println("wfValData()....");
		return "";
	}

	public String itemChanged() throws RemoteException,ITMException
	{
		System.out.println("itemChanged Called...");
		return "";
	}
	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); //returns the DOM Object for the passed XML Stirng
			dom1 = parseString(xmlString1); //returns the DOM Object for the passed XML Stirng

			if (xmlString2.trim().length() > 0 )
			{
				dom2 = parseString("<Root>" + xmlString2+ "</Root>");
			}
			valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
		}
		catch(Exception e)
		{
			System.out.println("Exception : [ReceivablesOpeningEJB][itemChanged(String,String)] :==>\n"+e.getMessage());
			e.printStackTrace();
		}
        return valueXmlString; 
	}
	
	public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		Connection conn = null;
		Statement stmt = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		StringBuffer valueXmlString = new StringBuffer();
		String sql = "";
		String columnValue = "";
		String retValue1 = "";
		String retValue2 = "";
		String retValue3 = "";
		String format = "";

		String siteDescr = "";
		String currCode = "";
		String currDescr = "";
		String finEntity = "";
		String finentDescr = "";
		String tranId = "";
		String refDate = "";
		String crTerm = "";
		int crDays = 0;
			
		NodeList parentNodeList = null;
		Node parentNode = null;
		Node childNode = null;
		NodeList childNodeList = null;
		String childNodeName = "";
		int ctr,currentFormNo=0;

		NodeList detCtxNodeList = null;
		NodeList detCtxChildNodeList = null;
		Node detCtxChildNode = null;
		String detchildNodeName = "";
	//	System.out.println("XTRAPARAMSS : " + xtraParams);
		GenericUtility genericUtility = GenericUtility.getInstance();
		String empCode = getValueFromXTRA_PARAMS(xtraParams,"loginEmpCode");
		String userId = getValueFromXTRA_PARAMS(xtraParams,"userId");
		String loginSite = getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode");
		StringBuffer retString = new StringBuffer();
		java.text.SimpleDateFormat dtf= new SimpleDateFormat(format);

		try
		{
			format= getApplDateFormat();
		}
		catch(Exception e)
		{
			System.out.println("Exception :[ReceivablesOpeningEJB]While Getting Date Format"+e.getMessage());		
			e.printStackTrace();
			throw new ITMException(e);
		}
		
		try
		{
			conn = getConnection(); //This function is to connect with oracle....
			if(objContext != null && objContext.trim().length()>0)
			{
				currentFormNo = Integer.parseInt(objContext);
			}

			System.out.println("[ReceivablesOpeningEJB] [itemChanged] :currentFormNo ....." +currentFormNo);
			valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
			valueXmlString.append(editFlag).append("</editFlag></header>");
			valueXmlString.append("<Detail>");								
			switch (currentFormNo)
			{
				case 1:
					/* Searching the dom for the incoming column value start*/
					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().equals("itm_default"))
					{
						String errString = null;
						String keyStringQuery = null;
						String acctPrd = "";
						sql = "SELECT A.DESCR,A.FIN_ENTITY, B.DESCR, B.CURR_CODE, C.DESCR "
							+" FROM SITE A, FINENT B, CURRENCY C "
							+ "WHERE A.FIN_ENTITY = B.FIN_ENTITY "
							+ "AND B.CURR_CODE = C.CURR_CODE "
							+ "AND A.SITE_CODE = ?";							

						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1,loginSite.trim());
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							siteDescr = rs.getString(1);
							finEntity = rs.getString(2);
							finentDescr = rs.getString(3);
							currCode = rs.getString(4);
							currDescr = rs.getString(5);
						}
						pstmt.close();
						rs.close();

						sql = "SELECT ACCT_PRD FROM PARAMETER";
						stmt = conn.createStatement();
						rs = stmt.executeQuery(sql);
						if (rs.next())
						{
							acctPrd = rs.getString(1);
						}	
						stmt.close();
						rs.close();					
						System.out.println("AcctPrd :" + acctPrd + " SiteCode : " + loginSite + " FinEntity :" + finEntity + " CurrCode :" + currCode + " EmpCode :" + empCode );
						valueXmlString.append("<acct_prd>").append(acctPrd).append("</acct_prd>");						
						valueXmlString.append("<site_code>").append(loginSite).append("</site_code>");
						//valueXmlString.append("<site_descr>").append(siteDescr).append("</site_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<site_descr>").append("<![CDATA["+siteDescr+"]]>").append("</site_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<fin_entity>").append(finEntity).append("</fin_entity>");
						//valueXmlString.append("<finent_descr>").append(finentDescr).append("</finent_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<finent_descr>").append("<![CDATA["+finentDescr+"]]>").append("</finent_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<curr_code>").append(currCode).append("</curr_code>");
						//valueXmlString.append("<currency_descr>").append(currDescr).append("</currency_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<currency_descr>").append("<![CDATA["+currDescr+"]]>").append("</currency_descr>");// Gulzar - 30/12/06
						//valueXmlString.append("<emp_code__aprv>").append(empCode).append("</emp_code__aprv>");
						valueXmlString.append("<tot_amt>").append("0").append("</tot_amt>");
						valueXmlString.append("<tran_type protect = '1'>").append("OPN").append("</tran_type>"); //Gulzar 02-12-06
					}
					else if (currentColumn.trim().equals("site_code"))
					{
						if (columnValue != null)
						{
							try					 
							{
								sql = "SELECT A.DESCR,A.FIN_ENTITY, B.DESCR, B.CURR_CODE, C.DESCR "
									+" FROM SITE A, FINENT B, CURRENCY C "
									+ "WHERE A.FIN_ENTITY = B.FIN_ENTITY "
									+ "AND B.CURR_CODE = C.CURR_CODE "
									+ "AND A.SITE_CODE ='" +columnValue+ "'";								
								stmt = conn.createStatement();
								rs = stmt.executeQuery(sql);							
								if (rs.next())
								{
									siteDescr = rs.getString(1);
									finEntity = rs.getString(2);
									finentDescr = rs.getString(3);
									currCode = rs.getString(4);
									currDescr = rs.getString(5);
								}
								rs.close();
								stmt.close();
							}
							catch(Exception e)
							{
								System.out.println("Exception :[ReceivablesOpeningEJB][itemChanged::case 1::site_code] :==>\n"+e.getMessage());
								e.printStackTrace();
								throw new ITMException(e);
							}
						}
						//valueXmlString.append("<site_descr>").append(siteDescr).append("</site_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<site_descr>").append("<![CDATA["+siteDescr+"]]>").append("</site_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<fin_entity>").append(finEntity).append("</fin_entity>");
						//valueXmlString.append("<finent_descr>").append(finentDescr).append("</finent_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<finent_descr>").append("<![CDATA["+finentDescr+"]]>").append("</finent_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<curr_code>").append(currCode).append("</curr_code>");
						//valueXmlString.append("<currency_descr>").append(currDescr).append("</currency_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<currency_descr>").append("<![CDATA["+currDescr+"]]>").append("</currency_descr>");// Gulzar - 30/12/06
					}
					else if (currentColumn.trim().equals("curr_code"))
					{
						if (columnValue != null)
						{
							try					 
							{
								sql = "SELECT DESCR FROM CURRENCY WHERE CURR_CODE ='" +columnValue+ "'";
								stmt = conn.createStatement();
								rs = stmt.executeQuery(sql);							
								if (rs.next())
								{
									currDescr = rs.getString(1);
								}
								rs.close();
								stmt.close();
							}
							catch(Exception e)
							{
								System.out.println("Exception :[ReceivablesOpeningEJB][itemChanged::case 1::curr_code] :==>\n"+e.getMessage());
								e.printStackTrace();
								throw new ITMException(e);
							}
						}
						//valueXmlString.append("<currency_descr>").append(currDescr).append("</currency_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<currency_descr>").append("<![CDATA["+currDescr+"]]>").append("</currency_descr>");// Gulzar - 30/12/06
					}
					valueXmlString.append("</Detail>");
				break;

				case 2:
					
					/* Searching the dom for the incoming column value start*/
					parentNodeList = dom.getElementsByTagName("Detail2");
					parentNode = parentNodeList.item(0);
					childNodeList = parentNode.getChildNodes();
					String siteCode = getColumnValue("site_code",dom1);
					ctr = 0;
					int childListLength = childNodeList.getLength();
					do
					{
						childNode = childNodeList.item(ctr);
						childNodeName = childNode.getNodeName();
						if(childNodeName.equals(currentColumn))
						{
							if (childNode.getFirstChild() != null)
							{
								columnValue=childNode.getFirstChild().getNodeValue();
							}
						}
						ctr++;
					}while(ctr < childListLength && !childNodeName.equals(currentColumn));
					/* Searching the dom for the incoming column value end*/
					if (currentColumn.trim().equals("itm_default"))
					{
						System.out.println("itm_default...");
						String currCodeFin = "";
						finEntity = genericUtility.getColumnValue("fin_entity",dom1);
						currCode = genericUtility.getColumnValue("curr_code",dom1);
						currDescr = getColumnValue("currency_descr",dom1);
						tranId = getColumnValue("tran_id",dom1);
						valueXmlString.append("<curr_code>").append(currCode).append("</curr_code>");
						valueXmlString.append("<tran_id>").append(tranId).append("</tran_id>");
						//valueXmlString.append("<currency_descr>").append(currDescr).append("</currency_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<currency_descr>").append("<![CDATA["+currDescr+"]]>").append("</currency_descr>");// Gulzar - 30/12/06

						sql = "SELECT CURR_CODE FROM FINENT WHERE FIN_ENTITY = '" + finEntity + "'";
						stmt = conn.createStatement();
						rs = stmt.executeQuery(sql);							
						if (rs.next())
						{
							currCodeFin = rs.getString(1);
						}
						rs.close();
						stmt.close();
						System.out.println("CurrCode :[" + currCode.trim() + "]  CurrCodeFin : [" + currCodeFin.trim() + "]");
						if(currCode.trim().equalsIgnoreCase(currCodeFin.trim()))
						{
							valueXmlString.append("<exch_rate protect = '1'>").append("1").append("</exch_rate>");
						}
					}
					else if (currentColumn.trim().equals("cust_code"))
					{
						String custName = "";
						String acctCode = "";
						String cctrCode = "";
						if (columnValue != null)
						{
							try					 
							{
								sql = "SELECT CUST_NAME,ACCT_CODE__AR,CCTR_CODE__AR FROM CUSTOMER WHERE CUST_CODE= '"+columnValue+ "'";
								stmt = conn.createStatement();
								rs = stmt.executeQuery(sql);							
								if (rs.next())
								{
									custName = rs.getString(1);
									acctCode = rs.getString(2);
									cctrCode = rs.getString(3);
								}
								rs.close();
								stmt.close();	
							}
							catch(Exception e)
							{
								System.out.println("Exception :[ReceivablesOpeningEJB][itemChanged::case 2::cust_code] :==>\n"+e.getMessage());
								e.printStackTrace();
								throw new ITMException(e);
							}
						}
						//valueXmlString.append("<cust_name>").append(custName).append("</cust_name>");// Gulzar - 30/12/06
						valueXmlString.append("<cust_name>").append("<![CDATA["+custName+"]]>").append("</cust_name>");// Gulzar - 30/12/06
						valueXmlString.append("<acct_code>").append(acctCode).append("</acct_code>");
						valueXmlString.append("<cctr_code>").append(cctrCode).append("</cctr_code>");
					}
					else if (currentColumn.trim().equals("curr_code"))
					{
						String currDesc = "";
						String tranDate = "";
						double exchRate = 0.0;
						if (columnValue != null)
						{
							try					 
							{
								sql = "SELECT DESCR FROM CURRENCY WHERE CURR_CODE ='" +columnValue+ "'";
								stmt = conn.createStatement();
								rs = stmt.executeQuery(sql);							
								if (rs.next())
								{
									currDesc = rs.getString(1);
								}
								rs.close();
								stmt.close();								
							}
							catch(Exception e)
							{
								System.out.println("Exception :[ReceivablesOpeningEJB][itemChanged::case 2::curr_code] :==>\n"+e.getMessage());
								e.printStackTrace();
								throw new ITMException(e);
							}
							currCode = getColumnValue("curr_code",dom1);
							tranDate = getColumnValue("tran_date",dom1);
							System.out.println("CurrCode :"+ currCode + " ColumnValue :" + columnValue);
							if(columnValue.trim().equals(currCode.trim()))
							{
								valueXmlString.append("<exch_rate protect = '1'>").append("1").append("</exch_rate>");
							}
							else
							{
								FinCommon finCommon = new FinCommon();
								exchRate = finCommon.getDailyExchRateSellBuy(columnValue.trim(),"",loginSite.trim(),tranDate.trim(),"S",conn);
								System.out.println("Daily Exch Rate ::- "+ exchRate);
								valueXmlString.append("<exch_rate protect = '0'>").append(exchRate).append("</exch_rate>");
							}
						}
						//valueXmlString.append("<currency_descr>").append(currDesc).append("</currency_descr>");// Gulzar - 30/12/06
						valueXmlString.append("<currency_descr>").append("<![CDATA["+currDesc+"]]>").append("</currency_descr>");// Gulzar - 30/12/06
					}
				//	For Due Date as per RefDate and CrTerm
					else if (currentColumn.trim().equals("cr_term"))
					{
						System.out.println("cr_term... :" );
						refDate = genericUtility.getColumnValue("ref_date",dom);
						if (columnValue != null && refDate != null)
						{
							crTerm = genericUtility.getColumnValue("cr_term",dom); 
							System.out.println("crTerm : " + crTerm + "  refDate: " + refDate);
							sql = "SELECT CR_DAYS FROM CRTERM WHERE CR_TERM ='" +crTerm+ "'";
							stmt = conn.createStatement();
							rs = stmt.executeQuery(sql);							
							if (rs.next())
							{
								crDays = rs.getInt(1);
							}
							rs.close();
							stmt.close();
							SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
							Calendar  cal = Calendar.getInstance();
							
							java.util.Date currDate = simpleDateFormat.parse(refDate);
							cal.setTime(currDate);
							cal.add(cal.DATE,crDays);
							currDate = cal.getTime();
							String dueDate = simpleDateFormat.format(currDate);
							valueXmlString.append("<due_date>").append(dueDate).append("</due_date>");
						}
					}
					///////////////////// Ref No
					else if (currentColumn.trim().equals("ref_no"))
					{
						String tranSer = "";
						String refSql = "";
						String refType = "";
						String acctCode = "";
						String cctrCode = "";
						String custCode = "";
						String custName = "";
						String itemSer = "";
						String salesPers = "";
						String salesPers1 = "";
						String salesPers2 = "";
						String contactCode = "";
						String finScheme = "";
						String saleOrder = "";
						String reasCode = "";
						
						java.util.Date dueDate = null;
						java.util.Date refDate1 = null;
						java.util.Date dueDate1 = null;
						java.util.Date tranDate1 = null;
						double totAmount = 0.0;
						double adjAmount = 0.0;
						double exchRate = 0.0;
						columnValue = genericUtility.getColumnValue("ref_no",dom); 
						if (columnValue != null)
						{
							try					 
							{
								childNodeListLength = childNodeList.getLength();
								for(ctr = 0; ctr < childNodeListLength; ctr++)
								{
									childNode = childNodeList.item(ctr);
									childNodeName = childNode.getNodeName();
									if (childNodeName.equals("tran_ser"))
									{
										String spName = "";
										String spName1 = "";
										String spName2 = "";
										tranSer=getColumnValue("tran_ser",dom,"2");
										System.out.println("TranSer :" + tranSer + " RefNo :" + columnValue);
									
									    refSql = "SELECT REF_DATE, TRAN_DATE, CUST_CODE, ACCT_CODE, CCTR_CODE, CURR_CODE, EXCH_RATE, "
									    	   + "TOT_AMT, ADJ_AMT, CR_TERM, DUE_DATE, REAS_CODE, ITEM_SER, SALES_PERS, SALES_PERS__1, "
									    	   + "SALES_PERS__2, CONTACT_CODE, FIN_SCHEME, SALE_ORDER, DUE_DATE "
									    	   + "FROM RECEIVABLES "
									    	   + "WHERE TRAN_SER = '"+tranSer+"' AND  REF_NO = '"+columnValue+"' AND REF_TYPE ='OPN' "; //REF_TYPE ADDED GULZAR 02-12-06
									
										//System.out.println("REF SQL................."+refSql);
										stmt = conn.createStatement();
										rs = stmt.executeQuery(refSql);
										if (rs.next())
										{
											refDate1 = rs.getDate(1);
											tranDate1 = rs.getDate(2);
											custCode = rs.getString(3);
											acctCode = rs.getString(4);
											cctrCode = rs.getString(5);
											currCode = rs.getString(6);
											exchRate = rs.getDouble(7);
											totAmount = rs.getDouble(8);
											adjAmount = rs.getDouble(9);
											crTerm = rs.getString(10);
											dueDate = rs.getDate(11);
											reasCode = rs.getString(12);
											itemSer = rs.getString(13);											
											salesPers = rs.getString(14);
											salesPers1 = rs.getString(15);
											salesPers2 = rs.getString(16);
											contactCode = rs.getString(17);
											finScheme = rs.getString(18);
											saleOrder = rs.getString(19);
											dueDate1 = rs.getDate(20);
											
											rs.close();
											if(crTerm == null)
											{
												crTerm = "";
											}
											if(salesPers == null)
											{
												salesPers = "";
											}

											sql = "SELECT CUST_NAME FROM CUSTOMER WHERE CUST_CODE= '"+custCode+ "'";
											stmt = conn.createStatement();
											rs = stmt.executeQuery(sql);							
											if (rs.next())
											{
												custName = rs.getString(1);
											}
											rs.close();
											stmt.close();
											sql = "SELECT SP_NAME FROM SALES_PERS WHERE SALES_PERS= '"+salesPers+ "'";
											stmt = conn.createStatement();
											rs = stmt.executeQuery(sql);
											if (rs.next())
											{
												spName = rs.getString(1);
												
											}
											rs.close();
											stmt.close();	
											
											sql = "SELECT SP_NAME FROM SALES_PERS WHERE SALES_PERS= '"+salesPers1+ "'";
											stmt = conn.createStatement();
											rs = stmt.executeQuery(sql);							
											if (rs.next())
											{
												spName1 = rs.getString(1);
											}
											rs.close();
											stmt.close();	
											sql = "SELECT SP_NAME FROM SALES_PERS WHERE SALES_PERS= '"+salesPers2+ "'";
											stmt = conn.createStatement();
											rs = stmt.executeQuery(sql);							
											if (rs.next())
											{
												spName2 = rs.getString(1);
											}
											rs.close();
											stmt.close();	
											/*
											if(crTerm != null)
											{
												sql = "SELECT CR_DAYS FROM CRTERM WHERE CR_TERM ='" +crTerm+ "'";
												stmt = conn.createStatement();
												rs = stmt.executeQuery(sql);
												if (rs.next())
												{
													crDays = rs.getInt(1);
												}
												rs.close();
												stmt.close();
												SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
												Calendar cal = Calendar.getInstance();
												
												java.util.Date currDate = simpleDateFormat.parse(simpleDateFormat.format(new java.util.Date(refDate1.getTime())));
												cal.setTime(currDate);
												cal.add(cal.DATE,crDays);
												currDate = cal.getTime();
												String dueDateStr = simpleDateFormat.format(currDate);
												
												valueXmlString.append("<cr_term>").append(crTerm).append("</cr_term>");	
												valueXmlString.append("<due_date>").append(dueDateStr).append("</due_date>");																					
											}
											*/
											SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
											valueXmlString.append("<ref_date>").append(simpleDateFormat.format(new java.util.Date(refDate1.getTime()))).append("</ref_date>");
											valueXmlString.append("<tran_date>").append(simpleDateFormat.format(new java.util.Date(tranDate1.getTime()))).append("</tran_date>");
											valueXmlString.append("<cust_code protect = '1'>").append(custCode).append("</cust_code>");
											//valueXmlString.append("<cust_name>").append(custName).append("</cust_name>");// Gulzar - 30/12/06
											valueXmlString.append("<cust_name>").append("<![CDATA["+custName+"]]>").append("</cust_name>");// Gulzar - 30/12/06
											valueXmlString.append("<acct_code protect = '1'>").append(acctCode).append("</acct_code>");
											valueXmlString.append("<cctr_code protect = '1'>").append(cctrCode).append("</cctr_code>");
											valueXmlString.append("<curr_code>").append(currCode).append("</curr_code>");											
											valueXmlString.append("<exch_rate>").append(exchRate).append("</exch_rate>");	
											valueXmlString.append("<tot_amt__old>").append(totAmount).append("</tot_amt__old>");
											//valueXmlString.append("<tot_amt>").append(totAmount).append("</tot_amt>");
											valueXmlString.append("<adj_amt>").append(adjAmount).append("</adj_amt>");
											valueXmlString.append("<cr_term>").append(crTerm).append("</cr_term>");	
											valueXmlString.append("<due_date>").append(simpleDateFormat.format(new java.util.Date(dueDate1.getTime()))).append("</due_date>");																					
											valueXmlString.append("<reas_code>").append(reasCode).append("</reas_code>");
											valueXmlString.append("<item_ser>").append(itemSer).append("</item_ser>");
											valueXmlString.append("<sales_pers>").append(salesPers).append("</sales_pers>");
											//valueXmlString.append("<sp_name>").append(spName).append("</sp_name>");// Gulzar - 30/12/06
											valueXmlString.append("<sp_name>").append("<![CDATA["+spName+"]]>").append("</sp_name>");// Gulzar - 30/12/06
											valueXmlString.append("<sales_pers__1>").append(salesPers1).append("</sales_pers__1>");
											//valueXmlString.append("<sp_name1>").append(spName1).append("</sp_name1>");// Gulzar - 30/12/06
											valueXmlString.append("<sp_name1>").append("<![CDATA["+spName1+"]]>").append("</sp_name1>");// Gulzar - 30/12/06
											valueXmlString.append("<sales_pers__2>").append(salesPers2).append("</sales_pers__2>");
											//valueXmlString.append("<sp_name2>").append(spName2).append("</sp_name2>");// Gulzar - 30/12/06
											valueXmlString.append("<sp_name2>").append("<![CDATA["+siteDescr+"]]>").append("</sp_name2>");// Gulzar - 30/12/06
											valueXmlString.append("<contact_code>").append(contactCode).append("</contact_code>");
											valueXmlString.append("<fin_scheme>").append(finScheme).append("</fin_scheme>");
											valueXmlString.append("<sale_order>").append(saleOrder).append("</sale_order>");
										}//if
										else 
										{
											valueXmlString.append("<acct_code protect = '0'>").append("</acct_code>");
											valueXmlString.append("<cctr_code protect = '0'>").append("</cctr_code>");
										//	valueXmlString.append("<exch_rate>").append("</exch_rate>");	
											valueXmlString.append("<tot_amt__old protect = '1'>").append("0.000").append("</tot_amt__old>");
											valueXmlString.append("<cust_code protect = '0'>").append(custCode).append("</cust_code>");
										}
										rs.close();
										stmt.close();
									}
								}//for
							}//try
							catch(Exception e)
							{
								System.out.println("Exception :[ReceivablesOpeningEJB][itemChanged::case 2:] :==>\n"+e.getMessage());
								e.printStackTrace();
								throw new ITMException(e);
							}
						}//outer if
					}//else if
					else if(currentColumn.trim().equals("tot_amt"))
					{
						double totAmt = 0.0;
						double totAmtOld = 0.0;
						double diffAmt = 0.0;
						System.out.println("tot_amt__old :" + getColumnValue("tot_amt__old",dom,"2"));
						if (columnValue != null)
						{
							//totAmtOld = Double.parseDouble((getColumnValue("tot_amt__old",dom,"2")) == "0" ? "" : getColumnValue("tot_amt__old",dom,"2").trim()); //Gulzar 01-12-06
							//Added Gulzar 01-12-06
							String oldTotAmt = getColumnValue("tot_amt__old",dom,"2"); //
							if (oldTotAmt == null)
							{
								totAmtOld = 0;
							}
							else
							{
								totAmtOld = Double.parseDouble(oldTotAmt);
							}
							//End Addition Gulzar 01-12-06
							totAmt = Double.parseDouble(columnValue);
							diffAmt = (totAmt - totAmtOld);
							System.out.println("TotOldAmt :" + totAmtOld + " TotAmt:" + totAmt + " DiffAmt :" + diffAmt);
						}
						System.out.println("Diff Amt : " + decFormat(diffAmt));
						valueXmlString.append("<diff_amt>").append(decFormat(diffAmt)).append("</diff_amt>");
					}
					else if (currentColumn.trim().equals("sales_pers"))
					{
						String salesPers = "";
						if (columnValue != null)
						{
							try
							{
								sql = "SELECT SP_NAME FROM SALES_PERS WHERE SALES_PERS ='" +columnValue+ "'";
								stmt = conn.createStatement();
								rs = stmt.executeQuery(sql);							
								if (rs.next())
								{
									salesPers = rs.getString(1);
								}
								rs.close();
								stmt.close();
							}
							catch(Exception e)
							{
								System.out.println("Exception :[ReceivablesOpeningEJB][itemChanged::case 2::sales_pers] :==>\n"+e.getMessage());
								e.printStackTrace();
								throw new ITMException(e);
							}
						}
						//valueXmlString.append("<sp_name>").append(salesPers).append("</sp_name>");// Gulzar - 30/12/06
						valueXmlString.append("<sp_name>").append("<![CDATA["+salesPers+"]]>").append("</sp_name>");// Gulzar - 30/12/06
					}
					else if (currentColumn.trim().equals("sales_pers__1"))
					{
						String salesPers1 = "";
						if (columnValue != null)
						{
							try
							{
								sql = "SELECT SP_NAME FROM SALES_PERS WHERE SALES_PERS ='" +columnValue+ "'";
								stmt = conn.createStatement();
								rs = stmt.executeQuery(sql);							
								if (rs.next())
								{
									salesPers1 = rs.getString(1);
								}
								rs.close();
								stmt.close();								
							}
							catch(Exception e)
							{
								System.out.println("Exception :[ReceivablesOpeningEJB][itemChanged::case 2::sales_pers__1] :==>\n"+e.getMessage());
								e.printStackTrace();
								throw new ITMException(e);
							}
						}
						//valueXmlString.append("<sp_name1>").append(salesPers1).append("</sp_name1>");//30/12/06
						valueXmlString.append("<sp_name1>").append("<![CDATA["+salesPers1+"]]>").append("</sp_name1>");//30/12/06
					}
					else if (currentColumn.trim().equals("sales_pers__2"))
					{
						String salesPers2 = "";
						if (columnValue != null)
						{
							try					 
							{
								sql = "SELECT SP_NAME FROM SALES_PERS WHERE SALES_PERS ='" +columnValue+ "'";
								stmt = conn.createStatement();
								rs = stmt.executeQuery(sql);							
								if (rs.next())
								{
									salesPers2 = rs.getString(1);
								}
								rs.close();
								stmt.close();
							}
							catch(Exception e)
							{
								System.out.println("Exception :[ReceivablesOpeningEJB][itemChanged::case 2::sales_pers__2] :==>\n"+e.getMessage());
								e.printStackTrace();
								throw new ITMException(e);
							}
						}
						//valueXmlString.append("<sp_name2>").append(salesPers2).append("</sp_name2>");//30/12/06
						valueXmlString.append("<sp_name2>").append("<![CDATA["+salesPers2+"]]>").append("</sp_name2>");//30/12/06
					}
					valueXmlString.append("</Detail>\r\n");
					break;
			}
			valueXmlString.append("</Root>");
		}		
		catch(Exception e)
		{
			System.out.println("Exception ::"+e.getMessage());
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
				try
				{
					//conn.close();
					//conn = null;
				}catch(Exception s){}
		}
		return valueXmlString.toString();
	}
	
	public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		Document dom = null;
		Document dom1 = null;
		Document dom2 = null;
		String  errString = null;
		System.out.println("wfValData(String)...");
		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 : ReceivablesOpeningEJB : wfValData(String xmlString) : ==>\n"+e.getMessage());
			e.printStackTrace();
			throw new ITMException(e);
		}
		return errString;
	}

	public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException
	{
		String errString = "";
		String errCode = "";
		String sql = "";
		Statement stmt = null;
		ResultSet rs = null;
		String userId = "";
		String loginSite = "";
		String siteCode = "";
		String itemSer = "";
		String currCode = "";
		String tranSer = "", refNo = "", refType = "";
		
		NodeList parentNodeList = null;
		NodeList childNodeList = null;
		Node parentNode = null;
		Node childNode = null;
		String childNodeName = ""; 
		int ctr,currentFormNo=0;
		int childNodeListLength;
		
		//ITMDBAccessHome itmDBAccessHome = null;
		//ITMDBAccess itmDBAccess = null;
		//GenericUtility genericUtility = GenericUtility.getInstance(); //Gulzar 04-12-06
		try
		{
			conn = getConnection(); 
			stmt = conn.createStatement();
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
			userId = getValueFromXTRA_PARAMS(xtraParams,"userId");
			loginSite = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
			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();
						
							int cnt;
							//siteCode = getColumnValue("site_code",dom);
						System.out.println("childNodeName : " + childNodeName);
						if (childNodeName.equals("site_code"))
						{
							System.out.println("childNodeName 1. : " + childNodeName);
							siteCode=genericUtility.getColumnValue("site_code",dom);
							System.out.println("childNode.getFirstChild() 1. : " + childNode.getFirstChild());
							if (childNode.getFirstChild() == null)
							{
								errCode = "VMSITECD1";
								errString = getErrorString("site_code",errCode,userId);
								break;
							}
							errCode = itmDBAccessEJB.isSiteCode(siteCode, "", conn);
							if(errCode != "")
							{
								errString = getErrorString("site_code",errCode,userId);
								break;
							}
						}
						/*
						if (childNodeName.equals("tran_type"))
						{
							if (childNode.getFirstChild() == null)
							{
								errCode = "VMTYPE";
								System.out.println("errCode... : " + errCode);
								System.out.println("User Id... : " + userId);
								errString = getErrorString("tran_type",errCode,userId);
								break;
							}
						}*/
						
						if (childNodeName.equals("curr_code"))
						{
							currCode = genericUtility.getColumnValue("curr_code",dom);
							if (childNode.getFirstChild() == null)
							{
								errCode = "VMCURCD";
								errString = getErrorString("curr_code",errCode,userId);
								break;
							}
							currCode = childNode.getFirstChild().getNodeValue().trim();
							sql = "SELECT COUNT(1) AS COUNT FROM CURRENCY WHERE CURR_CODE = '"+currCode+"'";
							rs = stmt.executeQuery(sql);
							if (rs.next())
							{
								cnt = rs.getInt("COUNT");
								if (cnt == 0)
								{
									errCode = "VTCURRCD1";
									errString = getErrorString("curr_code",errCode,userId);
									break;
								}
							}
						}						
						if (childNodeName.equals("fin_entity"))
						{
							if (childNode.getFirstChild() == null)
							{
								errCode = "VEFENTY2";
								errString = getErrorString("fin_entity",errCode,userId);
								break;
							}
						}
					}
				break;
				case 2:
					System.out.println("In case 2 :");
					
					String adjAmt = null;
					String totAmt = null;
					String custCode = null;
					String acctCode = null;
					String cctrCode = null;
					int refTypeCnt = 0;
					parentNodeList = dom.getElementsByTagName("Detail2");
					parentNode = parentNodeList.item(0);
					childNodeList = parentNode.getChildNodes();
				
					childNodeListLength = childNodeList.getLength();
					for(ctr = 0; ctr < childNodeListLength; ctr++)
					{
						childNode = childNodeList.item(ctr);
						childNodeName = childNode.getNodeName();
						System.out.println("childNodeName case 2..." + childNodeName);
						if(childNodeName.equals("tran_ser"))
						{
							if(childNode.getFirstChild() == null)
							{
								errCode = "VETRN2";
								errString = getErrorString("tran_ser",errCode,userId);
								break;
							}
						}
						else if(childNodeName.equals("ref_no"))
						{
							System.out.println("childNode.getFirstChild() :: " + childNode.getFirstChild());
							if(childNode.getFirstChild() == null)
							{
								errCode = "VTREFLINE1";
								errString = getErrorString("ref_no",errCode,userId);
								break;
							}
							else // Added By Gulzar 02-12-06
							{
								tranSer = genericUtility.getColumnValue("tran_ser",dom); 
								refNo   = genericUtility.getColumnValue("ref_no",dom); 
								System.out.println("tranSer : " + tranSer);
								System.out.println("refNo : " + refNo);
								sql = "SELECT COUNT(*) AS COUNT FROM RECEIVABLES WHERE TRAN_SER = '"+tranSer+"' AND REF_NO = '"+refNo+"'"; 
								System.out.println("sql : " + sql);
								rs = stmt.executeQuery(sql);
								if (rs.next())
								{
									refTypeCnt = rs.getInt("COUNT");
								}
								rs.close();
								System.out.println("refTypeCnt : " + refTypeCnt);
								if (refTypeCnt > 0)
								{
									sql = "SELECT (CASE WHEN REF_TYPE IS NULL THEN ' ' ELSE REF_TYPE END) AS REF_TYPE FROM RECEIVABLES WHERE TRAN_SER = '"+tranSer+"' AND REF_NO = '"+refNo+"'"; 
									System.out.println("sql : " + sql);
									rs = stmt.executeQuery(sql);
									if (rs.next())
									{
										refType = rs.getString("REF_TYPE");
									}
									rs.close();
									System.out.println("refType : " + refType);
									if (!refType.equals("OPN"))
									{
										errCode = "VTOPNREF1";
										errString = getErrorString("ref_no",errCode,userId);
										break;
									}
								}
							}//End Added Gulzar 02-12-06
						}
						else if(childNodeName.equals("ref_date"))
						{
							if(childNode.getFirstChild() == null)
							{
								errCode = "VXPAYDATE";
								errString = getErrorString("ref_date",errCode,userId);
								break;
							}
						}
						else if(childNodeName.equals("tran_date"))
						{
							if(childNode.getFirstChild() == null)
							{
								errCode = "VTXFR2";
								errString = getErrorString("tran_date",errCode,userId);
								break;
							}
						}
						else if(childNodeName.equals("cust_code"))
						{
							if(childNode.getFirstChild() == null)
							{
								errCode = "VECUST2";
								errString = getErrorString("cust_code",errCode,userId);
								break;
							}						
							custCode = genericUtility.getColumnValue("cust_code",dom);
							errCode = itmDBAccessEJB.isCustomer(genericUtility.getColumnValue("site_code",dom1),custCode,"fin",conn);
							if(errCode != "")
							{
								errString = getErrorString("cust_code",errCode,userId);
								break;
							}						
						}
						
						else if (childNodeName.equals("acct_code"))
						{
							acctCode=getColumnValue("acct_code",dom,"2");
							if (childNode.getFirstChild() == null)
							{
								errCode = "VMSITECD1";
								errString = getErrorString("acct_code",errCode,userId);
								break;
							}
							FinCommon finCommon = new FinCommon();
							errCode = finCommon.isAcctCode(getColumnValue("site_code",dom1),acctCode,"fin",conn);
						
							if(errCode != "")
							{
								errString = getErrorString("acct_code",errCode,userId);
								break;
							}
						}//outer if
						else if (childNodeName.equals("cctr_code"))
						{
							cctrCode=getColumnValue("cctr_code",dom,"2");
							if (childNode.getFirstChild() == null)
							{
								errCode = "VMSITECD1";
								errString = getErrorString("cctr_code",errCode,userId);
								break;
							}
							errCode = itmDBAccessEJB.isCctrCode(getColumnValue("acct_code",dom,"2"),cctrCode,"fin",conn);
							if(errCode != "")
							{
								errString = getErrorString("cctr_code",errCode,userId);
								break;
							}
						}//outer if
						
						else if (childNodeName.equals("curr_code"))
						{
							currCode=genericUtility.getColumnValue("curr_code",dom);
							
							if (childNode.getFirstChild() == null)
							{
								errCode = "VMCURCD";
								errString = getErrorString("curr_code",errCode,userId);
								break;
							}
							currCode = childNode.getFirstChild().getNodeValue().trim();
							sql = "SELECT COUNT(1) AS COUNT FROM CURRENCY WHERE CURR_CODE = '"+currCode+"'";
							rs = stmt.executeQuery(sql);
							if (rs.next())
							{
								int cnt = rs.getInt("COUNT");
								if (cnt == 0)
								{
									errCode = "VTCURRCD1";
									errString = getErrorString("",errCode,userId);
									break;
								}
							}
							rs.close();
						}

						else if(childNodeName.equals("exch_rate"))
						{
							String exchRate = genericUtility.getColumnValue("exch_rate",dom);
							if(childNode.getFirstChild() == null || exchRate.trim().equals("0"))
							{
								errCode = "VTEXRAT1";
								errString = getErrorString("exch_rate",errCode,userId);
								break;
							}
							currCode = genericUtility.getColumnValue("curr_code",dom);
							String currCode1 = genericUtility.getColumnValue("curr_code",dom1);
							if(currCode.trim().equals(currCode1))
							{
								if(exchRate.trim().equals("1.0") || exchRate.trim().equals("1.000000")) exchRate = "1";
								if(!exchRate.trim().equals("1"))
								{
									errCode = "VTEXRAT3";
									errString = getErrorString("exch_rate",errCode,userId);
									break;
								}
							}
						}
						/*
						else if(childNodeName.equals("tot_amt"))
						{
							if(childNode.getFirstChild() == null)
							{
								errCode = "VTEXRAT1";
								errString = getErrorString("tot_amt",errCode,userId);
							}
						}
						else if(childNodeName.equals("adj_amt"))
						{
							if(childNode.getFirstChild() == null)
							{
								errCode = "VTEXRAT1";
								errString = getErrorString("adj_amt",errCode,userId);
							}
						}
						*/
						else if(childNodeName.equals("cr_term"))
						{
							if(childNode.getFirstChild() != null)
							{
								String crTerm = childNode.getFirstChild().getNodeValue();
								if(crTerm != null && crTerm.trim().length()>0)
								{
									System.out.println("crtermLen : " + crTerm.trim().length() + "CRTERM : " + crTerm);
									sql = "SELECT COUNT(1) AS COUNT FROM CRTERM WHERE CR_TERM = '"+crTerm+"'";
									rs = stmt.executeQuery(sql);
									if (rs.next())
									{
										int cnt = rs.getInt("COUNT");
										if (cnt == 0)
										{
											errCode = "VMCRTER1";
											errString = getErrorString("cr_term",errCode,userId);
											break;
										}
									}
									rs.close();
								}
							}
						}
						else if(childNodeName.equals("due_date"))
						{
							java.util.Date tranDate = new Date(simpleDateFormat.parse(genericUtility.getColumnValue("tran_date",dom)).getTime());
							String refDateStr = genericUtility.getColumnValue("ref_date",dom);
							System.out.println("TranDate : " + tranDate + " Ref Date : " + refDateStr);
							if(childNode.getFirstChild() == null)
							{
								errCode = "VDUDATE0";
								errString = getErrorString("due_date",errCode,userId);
								break;
							}
							else
							{
								java.util.Date dueDate = new Date(simpleDateFormat.parse(genericUtility.getColumnValue("due_date",dom)).getTime());								
								java.util.Date refDate = new Date(simpleDateFormat.parse(genericUtility.getColumnValue("ref_date",dom)).getTime());
								if(tranDate.after(dueDate) || refDate.after(dueDate))
								{
									errCode = "VTDATERT";								
									errString = getErrorString("due_date",errCode,userId);
									break;
								}
							}
						}

						else if (childNodeName.equals("item_ser"))
						{
							int cnt;
							if (childNode.getFirstChild() == null)
							{
								errCode = "VMITEMSER1";
								errString = getErrorString("item_ser",errCode,userId);
								break;
							}
							itemSer = childNode.getFirstChild().getNodeValue().trim();
							sql = "SELECT COUNT(1) AS COUNT FROM ITEMSER WHERE ITEM_SER = '"+itemSer+"'";
							rs = stmt.executeQuery(sql);
							if (rs.next())
							{
								cnt = rs.getInt("COUNT");
								if (cnt == 0)
								{
									errCode = "VTITEMSER1";
									errString = getErrorString("item_ser",errCode,userId);
									break;
								}
								else
								{
								  //Check in customer_series
								}
							}
						}
						
						else if(childNodeName.equals("sales_pers"))
						{
							if(childNode.getFirstChild() != null)
							{
								String salesPers = childNode.getFirstChild().getNodeValue();
								if(salesPers != null && salesPers.trim().length()>0)
								{
									sql = "SELECT COUNT(1) AS COUNT FROM SALES_PERS WHERE SALES_PERS = '"+salesPers+"'";
									rs = stmt.executeQuery(sql);
									if (rs.next())
									{
										int cnt = rs.getInt("COUNT");
										if (cnt == 0)
										{
											errCode = "VMSLPERS1 ";
											errString = getErrorString("sales_pers",errCode,userId);
											break;
										}
									}
									rs.close();
								}
							}
							else
							{
								errCode = "VMSLPERS1";
								errString = getErrorString("sales_pers",errCode,userId);	
								break;
							}
						}
						/*
						else if(childNodeName.equals("sales_pers__1"))
						{
							if(childNode.getFirstChild() != null)
							{
								String salesPers1 = childNode.getFirstChild().getNodeValue();
								if(salesPers1 != null && salesPers1.trim().length()>0)
								{
									sql = "SELECT COUNT(1) AS COUNT FROM SALES_PERS WHERE SALES_PERS = '"+salesPers1+"'";
									rs = stmt.executeQuery(sql);
									if (rs.next())
									{
										int cnt = rs.getInt("COUNT");
										if (cnt == 0)
										{
											errCode = "VMSLPERS1 ";
											errString = getErrorString("sales_pers__1",errCode,userId);
											break;
										}
									}
									rs.close();
								}
							}
							else
							{
								errCode = "VMSLPERS1";
								errString = getErrorString("sales_pers__1",errCode,userId);							
							}
						}

						else if(childNodeName.equals("sales_pers__2"))
						{
							if(childNode.getFirstChild() != null)
							{
								String salesPers2 = childNode.getFirstChild().getNodeValue();
								if(salesPers2 != null && salesPers2.trim().length()>0)
								{
									sql = "SELECT COUNT(1) AS COUNT FROM SALES_PERS WHERE SALES_PERS = '"+salesPers2+"'";
									rs = stmt.executeQuery(sql);
									if (rs.next())
									{
										int cnt = rs.getInt("COUNT");
										if (cnt == 0)
										{
											errCode = "VMSLPERS1";
											errString = getErrorString("sales_pers__2",errCode,userId);
											break;
										}
									}
									rs.close();
								}
							}
							else
							{
								errCode = "VMSLPERS1";
								errString = getErrorString("sales_pers__2",errCode,userId);							
							}
						}
						*/


						adjAmt = genericUtility.getColumnValue("adj_amt",dom);
						totAmt = genericUtility.getColumnValue("tot_amt",dom);
					//	System.out.println("AdjAmt :" + adjAmt + "  TotAmt : " + totAmt);
						if (totAmt != null && adjAmt != null)
						{
							if (Double.parseDouble(totAmt) < Double.parseDouble(adjAmt) && Double.parseDouble(adjAmt) != 0)
							{
									errCode = "VTHAILTSDA";
									errString = getErrorString("adj_amt",errCode,userId);	
									break;
							}
						}
					}
				break;
			}
		}
		catch(Exception e)
		{
			System.out.println("Exception ::"+e);
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				//System.out.println("Closing Connection.....");
				//conn.close();
				//conn = null;
			}catch(Exception se){}
		}
		System.out.println("ErrString ::"+errString);
		return errString;
	}
	

	private String decFormat(double num)
	{
		NumberFormat nf = new DecimalFormat("##############0.000");
		nf.setMaximumFractionDigits(3);
		return nf.format(num);
	}

/*	private addDays(String crTerm, String refDate)
	{
		String dateString = "";
		System.out.println("crTerm : " + crTerm + "  refDate: " + refDate);
		sql = "SELECT CR_DAYS FROM CRTERM WHERE CR_TERM ='" +crTerm+ "'";
		stmt = conn.createStatement();
		rs = stmt.executeQuery(sql);							
		if (rs.next())
		{
			crDays = rs.getInt(1);
		}
		rs.close();
		stmt.close();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
		Calendar  cal = Calendar.getInstance();
		
		java.util.Date currDate = simpleDateFormat.parse(refDate);
		cal.setTime(currDate);
		cal.add(cal.DATE,crDays);
		currDate = cal.getTime();
		String dueDate = simpleDateFormat.format(currDate);
		return dateString;
	}
*/
}