package ibase.webitm.ejb.fin;

import java.rmi.RemoteException;
import java.text.*;
import java.util.Date;
import java.sql.*;
import java.text.SimpleDateFormat;
import org.w3c.dom.*;
import javax.ejb.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.*;
import ibase.system.config.*;
import ibase.webitm.ejb.*;

@Stateless // added for ejb3
public class AssetRegisterIC extends ValidatorEJB implements AssetRegisterICRemote,AssetRegisterICLocal
{
	GenericUtility genericUtility = GenericUtility.getInstance(); 

	/* public void ejbCreate() throws RemoteException, CreateException 
	{
		System.out.println("AssetRegisterICEJB is in Process..........");
	}
	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
	{
		Document dom = null;
		Document dom1 = null;
		Document dom2 = null;
		String  errString = null;
		System.out.println("Validation Start..........");
		try
		{
			dom = parseString(xmlString);
			dom1 = parseString(xmlString1); 
			if (xmlString2.trim().length() > 0 )
			{
				dom2 = parseString(xmlString2);
			}
			errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
		}
		catch(Exception e)
		{
			System.out.println("Exception : AssetRegisterICEJB : 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
	{
		String errString = " ";
		NodeList parentNodeList = null;
		NodeList childNodeList = null;
		Node parentNode = null;
		Node childNode = null;
		String columnValue = null;
		String childNodeName = null;
		ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
		String errCode = null;
		String userId = null,loginSite = null;
		int cnt = 0;
		int ctr = 0;
		int currentFormNo = 0;
		int childNodeListLength;
		Connection conn = null;
		PreparedStatement pstmt=null;
		ResultSet rs = null;
		String sql = null;
		ConnDriver connDriver = new ConnDriver();
		String lineNoDet = null;
		String updateFlag = null;
    	try
		{
			System.out.println( "wfValData called" );
			conn = connDriver.getConnectDB("DriverITM");
			userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
			loginSite = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
			
			if(objContext != null && objContext.trim().length()>0)
			{
				currentFormNo = Integer.parseInt(objContext);
			}
			switch(currentFormNo)
			{
				case 1 :
					System.out.println("VALIDATION FOR DETAIL [ 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" ) )
						{
							if ( childNode.getFirstChild() == null )
							{
								errString =itmDBAccessEJB.getErrorString("SITE_CODE","VMINVSITE",userId);
								break ;
							}
							else
							{
								String siteCode = null;
								siteCode = genericUtility.getColumnValue( "site_code", dom, "1" );
								
								sql = " SELECT COUNT(*) FROM site WHERE site_code ='" + siteCode.trim() + "'";
								pstmt = conn.prepareStatement( sql );
								//pstmt.setString(1,siteCode.trim());
								rs = pstmt.executeQuery();
								if( rs.next() )
								{
									cnt = rs.getInt( 1 );
								} 
								if( cnt == 0 )
								{
									errCode = "VMINVSITE";
									errString = getErrorString( "SITE_CODE", errCode, userId );
									break ;
								}
								rs.close();
								rs = null;

								pstmt.close();
								pstmt = null;
							}
						}
						if ( childNodeName.equalsIgnoreCase( "item_grp" ) )
						{
							if ( childNode.getFirstChild() == null )
							{
								errString =itmDBAccessEJB.getErrorString("item_grp","INVITMGRP",userId);
								break ;
							}
							else
							{
								String itemGrp = genericUtility.getColumnValue( "item_grp", dom).trim();
								sql = "SELECT count(1) from gencodes"
            						 +"	where fld_name = 'GRP_CODE'"
									 +" AND trim(fld_value) = ? ";
								pstmt = conn.prepareStatement( sql );
								pstmt.setString(1,itemGrp);
								rs = pstmt.executeQuery();
								if( rs.next() )
								{
									cnt = rs.getInt( 1 );
								} 
								System.out.println(" COUNT =====> [" + cnt + "]");
								if( cnt == 0 )
								{
									errString = getErrorString( "item_grp","VMINVITMGP",userId );
									break ;
								}
								rs.close();
								rs = null;

								pstmt.close();
								pstmt = null;	 
							}
						}	
					} 
					//END OF CASE1
					break;
				case 2 :
					System.out.println("VALIDATION FOR DETAIL [ 2 ]..........");
					//String update_flag = null;
					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();
						
						if ( childNodeName.equalsIgnoreCase( "eff_from" ) )
						{
							if ( childNode.getFirstChild() == null )
							{
								errString =itmDBAccessEJB.getErrorString("eff_from","VEFDTNNUL",userId);
								break ;
							}
							else
							{
								String assetCode = genericUtility.getColumnValue( "asset_code", dom ) != null ?genericUtility.getColumnValue( "asset_code", dom ).trim() : null;
								String effdatestr = genericUtility.getColumnValue( "eff_from", dom );
								java.sql.Timestamp effDateDom = null;
								sql = "SELECT count(*) from asset_register"
								      +" where trim(asset_code) = ? ";
								pstmt = conn.prepareStatement( sql );
								pstmt.setString(1,assetCode);
								rs = pstmt.executeQuery();
								if( rs.next() )
								{
									cnt = rs.getInt( 1 );
								} 
								System.out.println(" COUNT =====> [" + cnt + "]");
								if( cnt == 0 )
								{
									errString =itmDBAccessEJB.getErrorString("eff_from","VTINVASET",userId);
									break ;
								}
								rs.close();
								rs = null;
								pstmt.close();
								pstmt = null;
								if(assetCode != null)
								{
									effDateDom = Timestamp.valueOf(genericUtility.getValidDateString(effdatestr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
									java.sql.Timestamp procdate = null;
									sql = "Select PROC_DATE_2 from ASSET_REGISTER"
									      +" where trim(ASSET_CODE) = ? ";
									pstmt = conn.prepareStatement( sql );
									pstmt.setString(1,assetCode);
									rs = pstmt.executeQuery();
									if( rs.next() )
									{
										procdate = rs.getTimestamp( 1 );
									} 
									if( effDateDom.compareTo ( procdate ) < 0 )
									{
										errString =itmDBAccessEJB.getErrorString("eff_from","VTPROCDT",userId);
										break ;
									}
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}		
							}
						}	
						if ( childNodeName.equalsIgnoreCase( "valid_upto" ) )
						{
							if ( childNode.getFirstChild() == null )
							{
								errString =itmDBAccessEJB.getErrorString("valid_upto","VDUPTONNUL",userId);
								break ;
							}
							else
							{
								String effdatestr = genericUtility.getColumnValue( "eff_from", dom ) != null ? genericUtility.getColumnValue( "eff_from", dom ) : null;
								String vuptodatestr = genericUtility.getColumnValue( "valid_upto", dom ) != null ? genericUtility.getColumnValue( "valid_upto", dom ): null;
								java.sql.Timestamp effDate = null;
								java.sql.Timestamp vuptodate = null;
								if( vuptodatestr != null && vuptodatestr.trim().length() > 0 && effdatestr != null && effdatestr.trim().length() > 0)
								{
									vuptodate = Timestamp.valueOf(genericUtility.getValidDateString(vuptodatestr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
									effDate = Timestamp.valueOf(genericUtility.getValidDateString(effdatestr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
									int effcDtMon = effDate.getMonth();
									int vldUtDtMon = vuptodate.getMonth();
									int effcDtYr = effDate.getYear();
									int vldUtDtYr = vuptodate.getYear();
									
									if( effDate.compareTo ( vuptodate ) > 0 )
									{
										errString = itmDBAccessEJB.getErrorString("valid_upto","VMVALIDDT",userId);
										break ;
									}
									if(!((effcDtMon == vldUtDtMon) && (effcDtYr == vldUtDtYr)))
									{
										errString = itmDBAccessEJB.getErrorString("valid_upto","VTLVEPRD1",userId);
										break ;
									}
								}
							}
						}
						if ( childNodeName.equalsIgnoreCase( "depr_type" ) )
						{
							if ( childNode.getFirstChild() == null )
							{
								errString =itmDBAccessEJB.getErrorString("depr_type","DPTYPNNUL",userId);
								break ;
							}
							else
							{
								String assetCode = genericUtility.getColumnValue( "asset_code", dom ) != null ? genericUtility.getColumnValue( "asset_code", dom ).trim() : null;
								String effdatestr = genericUtility.getColumnValue( "eff_from", dom ) != null ? genericUtility.getColumnValue( "eff_from", dom ) : null;
								String vuptodatestr = genericUtility.getColumnValue( "valid_upto", dom ) != null ? genericUtility.getColumnValue( "valid_upto", dom ) : null;
								String deprtype = genericUtility.getColumnValue( "depr_type", dom ) != null ? genericUtility.getColumnValue( "depr_type", dom ) : null;
								String itemgrp = genericUtility.getColumnValue( "item_grp", dom1 );
								String lineNo = genericUtility.getColumnValue( "line_no", dom );
								String assetDet = null;
								String effdateDet = null;
								String valuptoDet = null;
								String deprDet = null;
								
								java.sql.Timestamp efDtDomTimeStp = null;
								java.sql.Timestamp vuptodtDomTimeStp = null;
								java.sql.Timestamp efDtDetTimeStp = null;
								java.sql.Timestamp vuptodtDetTimeStp = null;
								if(assetCode != null && effdatestr != null && vuptodatestr != null && deprtype != null)
								{
									NodeList detail2List = dom2.getElementsByTagName("Detail2");
									
									int detail2ListLen = detail2List.getLength();
									for(int detail2Idx = 0; detail2Idx < detail2ListLen ; detail2Idx++ )
									{
										Node currDetail = detail2List.item( detail2Idx );
										NodeList currDetNodes = currDetail.getChildNodes();
										
										updateFlag = getNodeValue( currDetail, "updateFlag", true );
										assetDet = getNodeValue( currDetail, "asset_code", false );
										effdateDet = getNodeValue( currDetail, "eff_from", false );
										valuptoDet = getNodeValue( currDetail, "valid_upto", false );	
										deprDet = getNodeValue( currDetail, "depr_type", false );
										lineNoDet = getNodeValue( currDetail, "line_no", false );	
										
										if( (!lineNoDet.equals(lineNo)) && (!updateFlag.equals("D") ) )
										{
											if( (assetDet != null) && (assetDet.equals(assetCode)) && (effdateDet != null) && (valuptoDet != null) && (deprDet != null))
											{
												System.out.println("Inside first if condition.......");
												efDtDomTimeStp = Timestamp.valueOf(genericUtility.getValidDateString(effdatestr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
												vuptodtDomTimeStp = Timestamp.valueOf(genericUtility.getValidDateString(vuptodatestr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
												efDtDetTimeStp = Timestamp.valueOf(genericUtility.getValidDateString(effdateDet, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
												vuptodtDetTimeStp = Timestamp.valueOf(genericUtility.getValidDateString(valuptoDet, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
																								
												if( efDtDomTimeStp.compareTo ( efDtDetTimeStp ) >= 0 &&  efDtDomTimeStp.compareTo ( vuptodtDetTimeStp ) <= 0)
												{
													errString = itmDBAccessEJB.getErrorString("depr_type","VTDUPREC",userId);
													break ;
												}
												if( efDtDomTimeStp.compareTo ( efDtDetTimeStp ) <= 0 &&  vuptodtDomTimeStp.compareTo ( vuptodtDetTimeStp ) >= 0)
												{
													errString = itmDBAccessEJB.getErrorString("depr_type","VTDUPREC",userId);
													break ;
												}
												if( vuptodtDomTimeStp.compareTo ( efDtDetTimeStp ) >= 0 &&  vuptodtDomTimeStp.compareTo ( vuptodtDetTimeStp ) < 0)
												{
													errString = itmDBAccessEJB.getErrorString("depr_type","VTDUPREC",userId);
													break ;
												}
												if( efDtDomTimeStp.compareTo ( efDtDetTimeStp ) == 0 ||  vuptodtDomTimeStp.compareTo ( vuptodtDetTimeStp ) == 0)
												{
													errString = itmDBAccessEJB.getErrorString("depr_type","VTDUPREC",userId);
													break ;
												}
												/* if( deprDet.equals(deprtype) && assetCode.equalsIgnoreCase( assetDet ) )
												{
													errString = itmDBAccessEJB.getErrorString("depr_type","VTDEPRDUP",userId);
													break ;
												} */
											}
										}
									}
								}	
							}
						}
						if ( childNodeName.equalsIgnoreCase( "asset_code" ) )
						{
							if ( childNode.getFirstChild() == null )
							{
								errString =itmDBAccessEJB.getErrorString("asset_code","ASSETNNUL",userId);
								break ;
							}
							else
							{
								String assetCode = genericUtility.getColumnValue( "asset_code", dom );
								String deprType = genericUtility.getColumnValue( "depr_type", dom ) != null ? genericUtility.getColumnValue( "depr_type", dom ) : null;
								String effFromStr = genericUtility.getColumnValue( "eff_from", dom ) != null ? genericUtility.getColumnValue( "eff_from", dom ) : null;
								String validUptoStr = genericUtility.getColumnValue( "valid_upto", dom ) != null ? genericUtility.getColumnValue( "valid_upto", dom ) : null;
								String lineNo = genericUtility.getColumnValue( "line_no", dom );
								String tranId = genericUtility.getColumnValue( "tran_id", dom );
								String itemSer = genericUtility.getColumnValue( "item_grp", dom1 );
								String siteCode = genericUtility.getColumnValue( "site_code", dom1 );
								
								if((deprType != null) && (effFromStr != null) && (validUptoStr != null))
								{
									sql = "Select count(*) from asset_shiftdet"
									      +" where TRAN_ID <> ? "
 										  +" AND asset_code = ? "
										  +" AND (eff_from BETWEEN ? AND ?"
										  +" OR valid_upto BETWEEN ? AND ?)";
										  /* +" OR depr_type = ? )";   */
										  
									pstmt = conn.prepareStatement( sql );
									pstmt.setString(1,tranId);
									pstmt.setString(2,assetCode);
									pstmt.setTimestamp(3,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(effFromStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
									pstmt.setTimestamp(4,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(validUptoStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
									pstmt.setTimestamp(5,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(effFromStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
									pstmt.setTimestamp(6,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(validUptoStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
									/* pstmt.setString(7,deprType); */
									
									rs = pstmt.executeQuery();
									if( rs.next() )
									{
										cnt = rs.getInt( 1 );
									} 
									
									if( cnt > 0 )
									{
										errString =itmDBAccessEJB.getErrorString("asset_code","VTDUPREC",userId);
										break ;
									}
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
								if(assetCode != null && effFromStr != null)
								{
									String grpCode = null;
									
									sql = "SELECT grp_code from asset_register"
									      +" where asset_code = ? ";
										  
									pstmt = conn.prepareStatement( sql );
									pstmt.setString(1,assetCode);
									rs = pstmt.executeQuery();
									if( rs.next() )
									{
										grpCode = rs.getString( "grp_code" ) != null ? rs.getString( "grp_code" ) : null;
									}
									
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;		
									if(grpCode != null)
									{
										sql = "select count( 1 ) from"
										      +" (select prd_code__upto"
											  +" from asset_depr ad,"
											  +" ( select code	from acctprd"
											  +" where ? between"
											  +" fr_date and to_date ) acP"
											  +" where ad.asset_code = ? "
											  +" and ad.acct_prd = acp.code"
											  +" and ad.item_ser = ? "
											  +" and ad.grp_code = ? "
											  +" and ad.site_code = ? )"
											  +" a, ( select code from period"
											  +" where ? > = fr_date"
											  +" and ? <= to_date) b"
											  +" where a.prd_code__upto >= b.code";
											  
										pstmt = conn.prepareStatement( sql );
										pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(effFromStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));	  
										pstmt.setString(2,assetCode);
										pstmt.setString(3,itemSer);
										pstmt.setString(4,grpCode);
										pstmt.setString(5,siteCode);
										pstmt.setTimestamp(6,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(effFromStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));	  
										pstmt.setTimestamp(7,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(effFromStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));	  
										
										
										rs = pstmt.executeQuery();
										if( rs.next() )
										{
											cnt = rs.getInt( 1 );
										} 
										
										if( cnt > 0 )
										{
											errString =itmDBAccessEJB.getErrorString("asset_code","VTDEPALC",userId);
											break ;
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
										
										sql = "select count(1) from depr_itemgrp"
										      +" where Item_grp = ? "
											  +" and ? between eff_from and valid_upto"
											  +" and ? between eff_from and valid_upto"
											  +" and depr_type = ? " ;
											  
										pstmt = conn.prepareStatement( sql );
										pstmt.setString(1,grpCode);
										pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(effFromStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
										pstmt.setTimestamp(3,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(validUptoStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));	  
										pstmt.setString(4,deprType);
										
										rs = pstmt.executeQuery();
										if( rs.next() )
										{
											cnt = rs.getInt( 1 );
										} 
										
										if( cnt == 0 )
										{
											errString =itmDBAccessEJB.getErrorString("asset_code","VTDEPTYPE",userId);
											break ;
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}
									else
									{
										errString =itmDBAccessEJB.getErrorString("asset_code","VTGRPCDNUL",userId);
										break ;
									}
								}
									
							}
						}	
					}//END FOR OF CASE2
					break;
			}//END SWITCH
		}//END TRY
		catch(Exception e)
		{
			System.out.println("Exception ::" +e);
			e.printStackTrace();
			errCode = "VALEXCEP";
			errString = getErrorString( "", errCode, userId );									
		}
		finally
		{
			try
			{
				if(conn != null)
				{
					if( pstmt != null )
					{
						pstmt.close();
						pstmt = null;
					}
					
					if( rs != null )
					{
						rs.close();
						rs = null;
					}
					conn.close();
				}
				conn = null;
			}
			catch(Exception d)
				{
				  d.printStackTrace();
				}			
			System.out.println(" < AssetRegisterIcEJB > 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 = null;
		try
		{
			System.out.println("xmlString" + xmlString);
			dom = parseString(xmlString); 
			System.out.println("xmlString1" + xmlString1);
			dom1 = parseString(xmlString1); 

			if (xmlString2.trim().length() > 0 )
			{
				System.out.println("xmlString2" + xmlString2);
				dom2 = parseString("<Root>" + xmlString2 + "</Root>");
			}
			valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
		}
		catch(Exception e)
		{
			System.out.println("Exception : [AssetRegisterICEJB][itemChanged] :==>\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
	{
		Connection conn = null;
		ConnDriver connDriver = new ConnDriver();
		PreparedStatement pStmt = null;
		ResultSet rs = null;
		String sql = null;
		int currentFormNo = 0;
		StringBuffer valueXmlString = new StringBuffer();
		String columnValue = null;
		NodeList parentNodeList = null;
		Node parentNode = null; 
		Node childNode = null;
		NodeList childNodeList = null;
		String childNodeName = null;
		int childNodeListLength = 0;
		int ctr = 0;
		int cnt = 0;
		String  loginSite = null;
		String  chguserhdr = null;
		String  chgtermhdr = null;
		SimpleDateFormat sdf = null;
		ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
		
		try
		{
			sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
			conn = connDriver.getConnectDB("DriverITM");
			connDriver = null;
			if(objContext != null && objContext.trim().length()>0)
			{
				currentFormNo = Integer.parseInt(objContext);
			}
			
			loginSite = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
			chguserhdr = getValueFromXTRA_PARAMS(xtraParams, "loginCode");
			chgtermhdr = getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
			
			valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
			valueXmlString.append(editFlag).append("</editFlag></header>");
			
			System.out.println("Current Form No ["+currentFormNo+"]");							
			switch (currentFormNo)
			{
				case 1:
					valueXmlString.append("<Detail1>");	
					//SEARCHING THE DOM FOR THE INCOMING COLUMN VALUE START
					parentNodeList = dom.getElementsByTagName("Detail1");
					parentNode = parentNodeList.item(0);
					childNodeList = parentNode.getChildNodes();
					ctr = 0;
					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));
					System.out.println("[" + currentColumn + "] ==> '" + columnValue + "'");
					if (currentColumn.trim().equals( "itm_default" ))
					{
						String loginSiteCode = null;
						String siteDescr = null;
						loginSiteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
						if( loginSiteCode != null || loginSiteCode.trim().length()==0 )
						{
							sql = "select s.descr site_descr from site s "
									+" where s.site_code = ? ";

							pStmt = conn.prepareStatement( sql );
							pStmt.setString(1,loginSiteCode);
							rs = pStmt.executeQuery();
							if( rs.next() )
							{
								siteDescr = rs.getString( "site_descr" );
							}	
							rs.close();
							rs = null;
							pStmt.close();
							pStmt = null;

							valueXmlString.append("<tran_date>").append("<![CDATA[" + getCurrdateAppFormat() + "]]>").append("</tran_date>");
							valueXmlString.append("<site_code>").append("<![CDATA[" + ( loginSiteCode != null ? loginSiteCode.trim() : ""  )+ "]]>").append("</site_code>");
							valueXmlString.append("<site_descr>").append("<![CDATA[" + ( siteDescr != null ? siteDescr.trim() : ""  )+ "]]>").append("</site_descr>");	
							valueXmlString.append("<chg_user>").append("<![CDATA["+ chguserhdr + "]]>").append("</chg_user>");
							valueXmlString.append("<chg_term>").append("<![CDATA["+ chgtermhdr + "]]>").append("</chg_term>");
						}
					}
					if(currentColumn.trim().equalsIgnoreCase("itm_defaultedit"))
					{
						String siteCodeEdit = getColumnValue("site_code",dom);
						String itemGrpEdit = getColumnValue("item_grp",dom);
						String tranId = genericUtility.getColumnValue( "tran_id", dom );
						sql = "SELECT count(1) from ASSET_SHIFTDET"
						      +" where tran_id = ? ";
						pStmt = conn.prepareStatement( sql );
						pStmt.setString(1,tranId);
						rs = pStmt.executeQuery();
						if( rs.next() )
						{
							cnt = rs.getInt( 1 );
						} 
						rs.close();
						rs = null;
						pStmt.close();
						pStmt = null;
						
						String grpDescr = null;
						sql = "select fn_get_gen_descr('GRP_CODE','W_ITEM', ? ,'D') descr"
							  +" from dual";
						pStmt = conn.prepareStatement( sql );
						pStmt.setString(1, itemGrpEdit != null ? itemGrpEdit.trim() : "" );
						rs = pStmt.executeQuery();
						if( rs.next() )
						{
							grpDescr = rs.getString( 1 );
						}
						if( cnt == 0 )
						{
							valueXmlString.append("<site_code>").append("<![CDATA[" + ( siteCodeEdit != null ? siteCodeEdit.trim() : ""  )+ "]]>").append("</site_code>");
							valueXmlString.append("<item_grp>").append("<![CDATA[" + ( itemGrpEdit != null ? itemGrpEdit.trim() : ""  )+ "]]>").append("</item_grp>");
							valueXmlString.append("<grp_descr>").append("<![CDATA[" + ( grpDescr != null ? grpDescr.trim() : ""  )+ "]]>").append("</grp_descr>");
						}
						else
						{
							valueXmlString.append("<site_code protect=\"1\" >").append("<![CDATA["+siteCodeEdit+"]]>").append("</site_code>");
							valueXmlString.append("<item_grp protect=\"1\" >").append("<![CDATA["+itemGrpEdit+"]]>").append("</item_grp>");
							valueXmlString.append("<grp_descr>").append("<![CDATA[" + ( grpDescr != null ? grpDescr.trim() : ""  )+ "]]>").append("</grp_descr>");
						}
					}	
					if (currentColumn.trim().equals( "site_code" ))
					{
						String siteDescr = null;
						String sitecode = genericUtility.getColumnValue( "site_code", dom );
						sql = "select s.descr site_descr from site s "
								+" where s.site_code = ? ";
				
						pStmt = conn.prepareStatement( sql );
						pStmt.setString(1,sitecode);
						rs = pStmt.executeQuery();
						if( rs.next() )
						{
							siteDescr = rs.getString( "site_descr" );
						}	
						
						rs.close();
						rs = null;
						pStmt.close();
						pStmt = null;
						valueXmlString.append("<site_descr>").append("<![CDATA[" + ( siteDescr != null ? siteDescr.trim() : ""  )+ "]]>").append("</site_descr>");	
					}
					if (currentColumn.trim().equals( "item_grp" ))
					{
						
						String itemgrphdr = genericUtility.getColumnValue( "item_grp", dom ).trim();
						String itemgrp_descr = null;
						
						sql = "select fn_get_gen_descr('GRP_CODE','W_ITEM','"+itemgrphdr+"','D') descr"
						      +" from dual";
						
						pStmt = conn.prepareStatement( sql );
						rs = pStmt.executeQuery();
						if( rs.next() )
						{
							itemgrp_descr = rs.getString(1);
						}	
						
						rs.close();
						rs = null;
						pStmt.close();
						pStmt = null;
						valueXmlString.append("<grp_descr>").append("<![CDATA[" + ( itemgrp_descr != null ? itemgrp_descr.trim() : ""  )+ "]]>").append("</grp_descr>");		  
					}
					valueXmlString.append("</Detail1>");
					valueXmlString.append("</Root>");	
					break;
				///////////////
				case 2:
					valueXmlString.append("<Detail2>");	
					//SEARCHING THE DOM FOR THE INCOMING COLUMN VALUE START
					parentNodeList = dom.getElementsByTagName("Detail2");
					parentNode = parentNodeList.item(0);
					childNodeList = parentNode.getChildNodes();
					ctr = 0;
					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));
					System.out.println("[" + currentColumn + "] ==> '" + columnValue + "'");
					if (currentColumn.trim().equals("asset_code"))
					{
						String assetDescr = null;
						String assetcode = genericUtility.getColumnValue( "asset_code", dom ).trim();
						sql = "select DESCR from asset_register "
						       +"where trim(asset_code) = ? ";
						pStmt = conn.prepareStatement( sql );
						pStmt.setString(1,assetcode);
						rs = pStmt.executeQuery();
						if( rs.next() )
						{
							assetDescr = rs.getString( "DESCR" );
						}	
						
						rs.close();
						rs = null;
						pStmt.close();
						pStmt = null;
						valueXmlString.append("<descr>").append("<![CDATA[" + ( assetDescr != null ? assetDescr.trim() : ""  )+ "]]>").append("</descr>");	
					}
					valueXmlString.append("</Detail2>");					
					valueXmlString.append("</Root>");					
				////////////////
			}//END OF TRY
		}
		catch(Exception e)
		{
			System.out.println("Exception ::"+ e.getMessage());
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if ( rs != null )
				{
					rs.close();
					rs = null;
				}
				if ( pStmt != null )
				{
					pStmt.close();
					pStmt = null;					
				}
				if ( conn != null )
				{
					conn.close();
					conn = null;
				}
			}
			catch(Exception e)
			{
				System.out.println("Exception ::" + e);
				e.printStackTrace();
			}			
		}
		return valueXmlString.toString();
	}//END OF ITEMCHANGE	
	private String getCurrdateAppFormat()
	{
		String s = "";
		GenericUtility genericUtility = GenericUtility.getInstance();
		try
		{
			java.util.Date date = null;
			Timestamp timestamp = new Timestamp(System.currentTimeMillis());
			
			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 s;
	}
	private String getNodeValue( Node currDet, String fldName, boolean isAttribute )
	{
		String fldValue = null;
		boolean isFound = false;
		NodeList currNodes = currDet.getChildNodes();
		int currDetLen = currNodes.getLength();
		for(int detIdx = 0; detIdx < currDetLen && !isFound ; detIdx++ )
		{
			Node currNode = currNodes.item( detIdx );
			String nodeName = currNode.getNodeName();

			if( isAttribute == true )
			{
				if ( nodeName.equalsIgnoreCase( "attribute" ) )
				{
					fldValue = currNode.getAttributes().getNamedItem( fldName ).getNodeValue();
					isFound = true;
				}				
			}
			else if ( currNode.getNodeType() == Node.ELEMENT_NODE && nodeName.equalsIgnoreCase( fldName ) )
			{
				fldValue = currNode.getFirstChild() != null ? currNode.getFirstChild().getNodeValue().trim() : null;
				isFound = true;
			}
		}
		return fldValue;
	}
}
