package ibase.webitm.ejb.fin;

import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;

import javax.ejb.Stateless;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import ibase.system.config.ConnDriver;
import ibase.utility.BaseLogger;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.dis.DistCommon;
//import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;


@Stateless
public class FixedAssetTransf extends ValidatorEJB implements FixedAssetTransfLocal,FixedAssetTransfRemote{
	FinCommon finCommon        = new FinCommon();
	DistCommon distCommon = new DistCommon();

	E12GenericUtility genericUtility = new E12GenericUtility();



	public String wfValData(String xmlString, String xmlString1, String xmlString2,String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		BaseLogger.log("3", getUserInfo(), null, "------------ wfvalData method called-----------------");
		BaseLogger.log("3", getUserInfo(), null, "xtraParams --->>>  [["+xtraParams+"  ]]");
		BaseLogger.log("3", getUserInfo(), null, "xmlString1 --->>>  [["+xmlString1+"  ]]");
		BaseLogger.log("3", getUserInfo(), null, "xmlString2 --->>>  [["+xmlString2+"  ]]");
		BaseLogger.log("3", getUserInfo(), null, "editFlag --->>>  [["+editFlag+"  ]]");

		String errString = null;
		Document dom = null;
		Document dom1 = null;
		Document dom2 = null;
		try
		{
			dom2 = parseString(xmlString);
			dom1 = parseString(xmlString1);
			dom = parseString(xmlString2);
			errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);

		}
		catch(Exception e)
		{
			BaseLogger.log("3", getUserInfo(), null, "Exception : FixedAssetTransf.java : wfValData(String xmlString) : ==>\n"+e.getMessage());
			throw new ITMException(e);
		}

		return errString;
	} //end of wfValData 


	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;
		ITMDBAccessEJB itmDBAccess = new ITMDBAccessEJB();
		String childNodeName = null;
		String errString = "",errorType="",loginSite="",status="",invoiceID="",sreturnTranID="",sql1="",userId="",taxClass = "", taxChap = "",
				taxEnv = "",sql="",tranDateStr="",loginCode="", errorCode = "",currCode="",isExistFlag="";
		Timestamp tranDateTm= null,orderDate=null;
		String errCode="";
		Connection conn = null;
		PreparedStatement pstmt;		
		ResultSet rs=null;
		int count=0,cnt=0;
		int currentFormNo=0,childNodeListLength;

		ConnDriver connDriver = new ConnDriver();
		//ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
		ArrayList <String> errList = new ArrayList<String>();
		ArrayList <String>errFields = new ArrayList <String> ();
		//		GenericUtility genericUtility = GenericUtility.getInstance();
		E12GenericUtility genericUtility = new E12GenericUtility();
		StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>"); 
		ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
		try
		{					
			//Changes and Commented By Bhushan on 06-06-2016 :START
			//conn = connDriver.getConnectDB("DriverITM");
			conn = getConnection();
			//Changes and Commented By Bhushan on 06-06-2016 :END
			loginCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode"); 
			userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
			BaseLogger.log("3", getUserInfo(), null, "user ID form XtraParam : "+userId +"Edit Flag -->>: "+editFlag);

			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();
					BaseLogger.log("3", getUserInfo(), null, "Child name --->> "+childNodeName); 				

					if (childNodeName.equalsIgnoreCase("site_code__to"))
					{
						String siteCodeTo="";	
						siteCodeTo = genericUtility.getColumnValue("site_code__to",dom);
						siteCodeTo=siteCodeTo == null ? "" :siteCodeTo.trim(); 
						BaseLogger.log("3", getUserInfo(), null, "siteCodeTo---->>["+siteCodeTo+"]");
						if(siteCodeTo.length() == 0){
							errCode = "VTSITETNN";//empty site code
							errList.add( errCode );
							errFields.add( childNodeName.toLowerCase() );
						}else{
							count=getDBRowCount(conn, "site", "site_code", siteCodeTo);						
							if(count ==0){
								errCode = "VTSITETND"; //Site code does not exist in master
								errList.add( errCode );
								errFields.add( childNodeName.toLowerCase() );
							}							
						}
					}
					if (childNodeName.equalsIgnoreCase("site_code__from"))
					{
						String siteCodeFrom="";	
						siteCodeFrom = genericUtility.getColumnValue("site_code__from",dom);
						siteCodeFrom=siteCodeFrom == null ? "" :siteCodeFrom.trim(); 
						BaseLogger.log("3", getUserInfo(), null, "siteCodeFrom---->>["+siteCodeFrom+"]");
						if(siteCodeFrom.length() == 0){
							errCode = "VTSITEFNN";//empty site code
							errList.add( errCode );
							errFields.add( childNodeName.toLowerCase() );
						}else{
							count=getDBRowCount(conn, "site", "site_code", siteCodeFrom);						
							if(count ==0){
								errCode = "VTSITEFND"; //Site code does not exist in master
								errList.add( errCode );
								errFields.add( childNodeName.toLowerCase() );
							}
							//Added by sarita to check for finentity for site_code__to and site_code__from should not be different if site codes are different. on 16 JULY 18 [START]
							else
							{
								String siteCodeTo = "";
								HashSet<String> siteData = new HashSet<String>();
								siteCodeTo = checkNull(genericUtility.getColumnValue("site_code__to",dom));
								BaseLogger.log("3", getUserInfo(), null, "siteCodeFrom ["+siteCodeFrom+"] \t siteCodeTo ["+siteCodeTo+"]");

								if((siteCodeTo != null && siteCodeTo.trim().length() > 0) && ((siteCodeFrom.trim()).equalsIgnoreCase(siteCodeTo.trim()) == false))
								{
									sql = "select fin_entity from site where site_code in (? , ?)";
									pstmt=conn.prepareStatement(sql);
									pstmt.setString(1, siteCodeTo);
									pstmt.setString(2, siteCodeFrom);
									rs=pstmt.executeQuery();
									while(rs.next())
									{
										siteData.add(checkNull(rs.getString("fin_entity")));
									}
									if(rs != null)
									{
										rs.close();
										rs = null;
									}
									if(pstmt != null)
									{
										pstmt.close();
										pstmt = null;
									}
									BaseLogger.log("3", getUserInfo(), null, "Value of HashSet<siteData> : ["+siteData+"]");
									if((siteData != null) && (siteData.size() > 1))
									{
										errCode = "INVFINENT"; //Fin entity should be same for different site_code__from and site_code__to.
										errList.add( errCode );
										errFields.add( childNodeName.toLowerCase() );
									}
								}
							}
							//Added by sarita to check for finentity for site_code__to and site_code__from should not be different if site codes are different. on 16 JULY 18 [END]
							//						sql ="select "
						}
					}
					if(childNodeName.equalsIgnoreCase("link_type")){
						String linkType="";
						linkType = genericUtility.getColumnValue("link_type",dom);
						linkType=linkType==null ? "" :linkType.trim();
						BaseLogger.log("3", getUserInfo(), null, "linkType-->>["+linkType+"]");
						if(linkType.length() == 0){
							errCode = "VTLINKTN"; //Site code does not exist in master
							errList.add( errCode );
							errFields.add( childNodeName.toLowerCase() );	
						}
					}
					//Added By Ganpat Yeram[04/Jun/2024]
					if(childNodeName.equalsIgnoreCase("curr_code"))
					{ 
						currCode = checkNull(genericUtility.getColumnValue("curr_code", dom));
						if( currCode != null && currCode.trim().length() > 0 )  
						{
							isExistFlag = isExistCurrCode("currency", "curr_code", currCode, conn);
							if ("FALSE".equalsIgnoreCase(isExistFlag) )	
							{
								errCode = "VMCURR1";
								errList.add(errCode);
								errFields.add(childNodeName.toLowerCase());
							}	 
						}
					}
					//END By Ganpat Yeram[04/JUN/2024]
				} //end for loop 
				break;
			case 2 :
				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("asset_code__from"))
					{
						String assetCodeFrom="",xFrType="",siteCodeFrom="",SiteCode="",acctPrd="",prd="",
								tranDate="";
						assetCodeFrom=genericUtility.getColumnValue("asset_code__from", dom);
						siteCodeFrom=genericUtility.getColumnValue("site_code__from", dom);
						tranDate=genericUtility.getColumnValue("tran_date", dom);
						xFrType=genericUtility.getColumnValue("xfr_type", dom);
						assetCodeFrom=assetCodeFrom== null ? "" :assetCodeFrom.trim();
						siteCodeFrom=siteCodeFrom== null ? "" :siteCodeFrom.trim();
						tranDate=tranDate== null ? "" :tranDate.trim();
						xFrType=xFrType== null ? "" :xFrType.trim();
						BaseLogger.log("3", getUserInfo(), null, "assetCodeFrom-->>["+assetCodeFrom+"] tranDate-->["+tranDate+"]");
						BaseLogger.log("3", getUserInfo(), null, "xFrType-->>["+xFrType+"] siteCodeFrom--["+siteCodeFrom+"]");
						if(assetCodeFrom.length() == 0){
							errCode = "VTASSETCE"; //Old Asset Code can not be blank.
							errList.add( errCode );
							errFields.add( childNodeName.toLowerCase() );
						} else if (!("T".equalsIgnoreCase(xFrType)) && !("R".equalsIgnoreCase(xFrType))){
							count=getDBRowCount(conn,"asset_register","asset_code",assetCodeFrom);
							BaseLogger.log("3", getUserInfo(), null, "asset_code count--->>["+count+"]");
							if(count== 0){
								errCode = "VTASSETCD"; // Entered Old Asset Code is not defined in asset register master.
								errList.add( errCode );
								errFields.add( childNodeName.toLowerCase() );
							}else{
								status=getNameOrDescrForCode(conn,"asset_register","status","asset_code",assetCodeFrom);
								SiteCode=getNameOrDescrForCode(conn,"asset_register","site_code","asset_code",assetCodeFrom);
								BaseLogger.log("3", getUserInfo(), null, "Status---->>["+status+"]");
								BaseLogger.log("3", getUserInfo(), null, "SiteCode---->>["+SiteCode+"]");
								/*if(!(SiteCode.equalsIgnoreCase(siteCodeFrom))){
									errCode = "VTASSTSITE"; 
									errList.add( errCode );
									errFields.add( childNodeName.toLowerCase() );	
								}*/
								if(!("A".equalsIgnoreCase(status))){									
									errCode = "VTASETSTAT"; //VTASETSTAT
									errList.add( errCode );
									errFields.add( childNodeName.toLowerCase() );
								}/*else{
									//Cannot transfer the asset if Asset Depreciation is not calculated
									sql="select code from acctprd where ? between fr_date and to_date";
									pstmt=conn.prepareStatement(sql);
									pstmt.setString(1, tranDate);
									rs=pstmt.executeQuery();
									if(rs.next()){
										acctPrd=rs.getString(1);
									}
									if(rs!=null){
										rs.close();
										rs=null;
									}
									if(pstmt!=null){
										pstmt.close();
										pstmt=null;
									}
									BaseLogger.log("3", getUserInfo(), null, "acctPrd--->["+acctPrd+"]");
									sql="select code from period where ? between fr_date and to_date";
									pstmt=conn.prepareStatement(sql);
									pstmt.setString(1, tranDate);
									rs=pstmt.executeQuery();
									if(rs.next()){
										prd=rs.getString(1);
									}
									if(rs!=null){
										rs.close();
										rs=null;
									}
									if(pstmt!=null){
										pstmt.close();
										pstmt=null;
									}
									BaseLogger.log("3", getUserInfo(), null, "prd--->["+prd+"]");
									sql="select count(1) from asset_depr where asset_code = ? and acct_prd= ? and "
											+ "case when prd_code__upto is not null then prd_code__upto else ? end >= ?";
									pstmt=conn.prepareStatement(sql);
									pstmt.setString(1, assetCodeFrom);
									pstmt.setString(2, acctPrd);
									pstmt.setString(3, prd);
									pstmt.setString(4, prd);
									rs=pstmt.executeQuery();
									if(rs.next()){
										count=rs.getInt(1);
									}
									if(rs!=null){
										rs.close();
										rs=null;
									}
									if(pstmt!=null){
										pstmt.close();
										pstmt=null;
									}
									BaseLogger.log("3", getUserInfo(), null, "count--->["+count+"]");
									if(count == 0){
										errCode = "VTDEPRPROC"; //Asset Depreciation is not calculated for entered asset
										errList.add( errCode );
										errFields.add( childNodeName.toLowerCase() );		
									}
								}*/
							}

						}

					}	
					if(childNodeName.equalsIgnoreCase("asset_code__to"))
					{
						String assetCodeTo="";
						assetCodeTo=genericUtility.getColumnValue("asset_code__to", dom);
						assetCodeTo=assetCodeTo== null ? "" :assetCodeTo.trim();
						BaseLogger.log("3", getUserInfo(), null, "assetCodeFrom----->>["+assetCodeTo+"]");
						/*	if(assetCodeTo.length() == 0){
							errCode = "VTASETNND"; //
							errList.add( errCode );
							errFields.add( childNodeName.toLowerCase() );
						}*/
						if(assetCodeTo.length() > 0){
							count=getDBRowCount(conn,"asset_register","asset_code",assetCodeTo);
							BaseLogger.log("3", getUserInfo(), null, "asset_code count--->>["+count+"]");
							if(count== 0){
								errCode = "VTASETNND"; //Asset Code is not present in Asset Register
								errList.add( errCode );
								errFields.add( childNodeName.toLowerCase() );
							}else{
								status=getNameOrDescrForCode(conn,"asset_register","status","asset_code",assetCodeTo);
								BaseLogger.log("3", getUserInfo(), null, "Status---->>["+status+"]");
								if(!("A".equalsIgnoreCase(status))){									
									errCode = "VTASETSTAT"; 
									errList.add( errCode );
									errFields.add( childNodeName.toLowerCase() ); 
								}
							}

						}
					}	

					if(childNodeName.equalsIgnoreCase("item_ser__to"))
					{
						count=0;
						String itemSerTo="";
						itemSerTo=genericUtility.getColumnValue("item_ser__to", dom);
						itemSerTo=itemSerTo== null ? "" :itemSerTo.trim();
						BaseLogger.log("3", getUserInfo(), null, "itemSerTo---->>["+itemSerTo+"]");
						if(itemSerTo.length() > 0){
							count=getDBRowCount(conn,"itemser","item_ser",itemSerTo);
							BaseLogger.log("3", getUserInfo(), null, "itemser count---->>["+count+"]");
							if(count==0){
								errCode = "VTITEMSER1"; //item series not present in master.
								errList.add( errCode );
								errFields.add( childNodeName.toLowerCase() ); 
							}						
						}					
					}
					if(childNodeName.equalsIgnoreCase("grp_code__to"))
					{
						count=0;
						String grpCodeTo="";
						grpCodeTo=genericUtility.getColumnValue("grp_code__to", dom);
						grpCodeTo=grpCodeTo== null ? "" :grpCodeTo.trim();
						BaseLogger.log("3", getUserInfo(), null, "grpCodeTo---->>["+grpCodeTo+"]");
						if(grpCodeTo.length() > 0){
							count=getDBRowCount(conn,"gencodes","fld_value",grpCodeTo);
							BaseLogger.log("3", getUserInfo(), null, "groupcode count---->>["+count+"]");
							if(count==0){
								errCode = "VTPGRPCD1"; //grp_code not present in master.
								errList.add( errCode );
								errFields.add( childNodeName.toLowerCase() ); 
							}
						}						
					}
					if(childNodeName.equalsIgnoreCase("aloc_code__to"))
					{
						count=0;
						String alocCodeTo="",siteCodeTo="";
						alocCodeTo=genericUtility.getColumnValue("aloc_code__to", dom);
						siteCodeTo=genericUtility.getColumnValue("site_code__to", dom);
						alocCodeTo=alocCodeTo== null ? "" :alocCodeTo.trim();
						siteCodeTo=siteCodeTo== null ? "" :siteCodeTo.trim();
						BaseLogger.log("3", getUserInfo(), null, "grpCodeTo---->>["+alocCodeTo+"]");
						BaseLogger.log("3", getUserInfo(), null, "siteCodeTo---->>["+siteCodeTo+"]");
						if(alocCodeTo.length() > 0){
							sql="select count(*) from asset_location where aloc_code = ? and site_code = ?";
							pstmt=conn.prepareStatement(sql);
							pstmt.setString(1, alocCodeTo);
							pstmt.setString(2, siteCodeTo);

							rs=pstmt.executeQuery();
							if(rs.next()){
								count=rs.getInt(1);								
							}
							if(rs!=null){
								rs.close();
								rs=null;
							}
							if(pstmt!=null){
								pstmt.close();
								pstmt=null;
							}							
							BaseLogger.log("3", getUserInfo(), null, "itemser count---->>["+count+"]");
							if(count == 0){
								errCode = "VTALOC"; //The asset location is not valid..
								errList.add( errCode );
								errFields.add( childNodeName.toLowerCase() ); 
							}
						}
					}
					if(childNodeName.equalsIgnoreCase("depr_type__to"))
					{
						String deprTypeTo="";
						deprTypeTo=genericUtility.getColumnValue("depr_type__to", dom);
						deprTypeTo=deprTypeTo== null ? "" :deprTypeTo.trim();
						BaseLogger.log("3", getUserInfo(), null, "cctrCodeTo---->>["+deprTypeTo+"]");
						if(deprTypeTo.length() == 0){
							errCode = "VTDEPRTP"; //Select Depr Type 
							errList.add( errCode );
							errFields.add( childNodeName.toLowerCase() );	
						}						
					}
					if(childNodeName.equalsIgnoreCase("cctr_code__to"))
					{
						count=0;
						String cctrCodeTo="";
						cctrCodeTo=genericUtility.getColumnValue("cctr_code__to", dom);
						cctrCodeTo=cctrCodeTo== null ? "" :cctrCodeTo.trim();
						BaseLogger.log("3", getUserInfo(), null, "cctrCodeTo---->>["+cctrCodeTo+"]");
						if(cctrCodeTo.length() > 0){							
							count=getDBRowCount(conn,"costctr","cctr_code",cctrCodeTo);
							BaseLogger.log("3", getUserInfo(), null, "cctrCodeTo count---->>["+count+"]");
							if(count==0){
								errCode = "VTCCTRCDPL"; //cctr code not present in master.
								errList.add( errCode );
								errFields.add( childNodeName.toLowerCase() ); 
							}
						}
					}	
					if(childNodeName.equalsIgnoreCase("asset_code__par_to"))
					{
						String assetCodeParTo="";
						assetCodeParTo=genericUtility.getColumnValue("asset_code__par_to", dom);
						assetCodeParTo=assetCodeParTo== null ? "" :assetCodeParTo.trim();
						BaseLogger.log("3", getUserInfo(), null, "assetCodeParTo---->>["+assetCodeParTo+"]");
						if(assetCodeParTo.length() > 0){
							count=getDBRowCount(conn,"asset_register","asset_code",assetCodeParTo);
							BaseLogger.log("3", getUserInfo(), null, "itemser count---->>["+count+"]");
							if(count==0){
								errCode = "VTASETPND"; //
								errList.add( errCode );
								errFields.add( childNodeName.toLowerCase() ); 
							}	
						}
					}
					
					String isTaxNA = checkNull(finCommon.getFinparams("999999", "TAX_NA", conn));
					isTaxNA = isTaxNA.trim();
					System.out.println("isTaxNA =======>>> wfValData"+isTaxNA);
					
					
					//					ADDED BY VIJAY[ VALIDATION FOR TAX_CLASS,TAX_CHAP,TAX_ENV].START
					
					//Added condition by Ajit, if entry finds in the finparm table for TAX_NA var_name then skip the validation for tax fields on 22-JAN-26
					if(!isTaxNA.equalsIgnoreCase("N/A")) {
						if (childNodeName.equalsIgnoreCase("tax_class"))
						{
							taxClass = checkNull(genericUtility.getColumnValue("tax_class", dom));
							System.out.println("inside tax_class==>"+taxClass);
							BaseLogger.log("3", getUserInfo(), null,  "taxClass: " + taxClass);
							if (taxClass != null && (taxClass.trim().length() >= 0))
							{
								System.out.println("taaax_chap==>"+taxChap);
								if (!(isExist(conn, "taxclass", "tax_class", taxClass))) {
									errCode = "VTTCLASS1";
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
									BaseLogger.log("3", getUserInfo(), null,  "Tax class not define in tax class master.");
								}
							}
						}
						// tax_chap
						if (childNodeName.equalsIgnoreCase("tax_chap")) 
						{
							taxChap = checkNull(genericUtility.getColumnValue("tax_chap", dom));
							System.out.println("inside taxChap==>"+taxChap);
							BaseLogger.log("3", getUserInfo(), null,  "taxChap: " + taxChap);
							if (taxChap != null && (taxChap.trim().length() >= 0))
							{
								if (!(isExist(conn, "taxchap", "tax_chap", taxChap))) {
									errCode = "VTTCHAP1";
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
									BaseLogger.log("3", getUserInfo(), null,  "Tax chapter not define in tax chapter master");
								}
							}
						}
						// tax_env
						if (childNodeName.equalsIgnoreCase("tax_env"))
						{
							taxEnv = checkNull(genericUtility.getColumnValue("tax_env", dom));
							System.out.println("inside taxEnv==>"+taxEnv);
							//						orderDate = Timestamp.valueOf(
							//								genericUtility.getValidDateString(genericUtility.getColumnValue("order_date", dom),
							//										genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat())
							//								+ " 00:00:00.0");
							//						 orderDate=Timestamp.valueOf(genericUtility.getColumnValue("order_date", dom));
							//						 System.out.println("inside orderDate==>"+orderDate);

							if (taxEnv != null  && (taxEnv.trim().length() >= 0))
							{
								if (!(isExist(conn, "taxenv", "tax_env", taxEnv))) {
									errCode = "VTTENV1";
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
									BaseLogger.log("3", getUserInfo(), null,  "TAX ENVIRONMENT NOT DEFINED");
								} else {
									//Pavan R 17sept19 start[to validate tax environment]
									//errCode = gfCheckTaxenvStatus(taxEnv, orderDate, conn);															
									//errCode = gfCheckTaxenvStatus(taxEnv, orderDate, "S", conn);
									errCode = distCommon.getCheckTaxEnvStatus(taxEnv, orderDate, "D", conn);
									System.out.println("errCode==VJ==>"+errCode);
									//Pavan R 17sept19 end[to validate tax environment]
									if (errCode != null && errCode.trim().length() > 0) {
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
										BaseLogger.log("3", getUserInfo(), null,  "TAX ENVIRONMENT NOT DEFINED");
									}
								}
							}
						}
						//						ADDED BY VIJAY[ VALIDATION FOR TAX_CLASS,TAX_CHAP,TAX_ENV].END

					}
					
				}
				break;

			} //end switch


			int errListSize = errList.size();
			cnt =0;
			String errFldName = null;
			if ( errList != null && errListSize > 0 )
			{
				for (cnt = 0; cnt < errListSize; cnt++ )
				{
					errCode = errList.get(cnt);
					errFldName = errFields.get(cnt);
					BaseLogger.log("3", getUserInfo(), null, "errCode .........."+errCode);
					errString = getErrorString( errFldName, errCode, userId );
					errorType =  errorType( conn, errCode );
					if ( errString.length() > 0)
					{
						String bifurErrString = errString.substring( errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>"));
						bifurErrString =bifurErrString+errString.substring( errString.indexOf("</trace>") + 8,errString.indexOf("</Errors>"));
						errStringXml.append(bifurErrString);
						BaseLogger.log("3", getUserInfo(), null, "errStringXml .........."+errStringXml);
						errString = "";
					}
					if ( errorType.equalsIgnoreCase("E"))
					{
						break;
					}
				}
				errList.clear();
				errList = null;
				errFields.clear();
				errFields = null;

				errStringXml.append("</Errors></Root>\r\n");
			}
			else
			{
				errStringXml = new StringBuffer( "" );
			}	

		} //end try
		catch (SQLException se) {
			BaseLogger.log("3", getUserInfo(), null, "SQLException ::"+se);
			se.printStackTrace();
			throw new ITMException(se);
		}
		catch(Exception e)
		{
			BaseLogger.log("3", getUserInfo(), null, "Exception ::"+e);
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				if(conn!=null)
				{
					conn.close();
					conn = null;
				}
				if(connDriver!=null){
					connDriver = null;
				}	
				if(rs !=null)
				{
					rs.close();
					rs=null;
				}


			}
			catch(Exception d)
			{
				d.printStackTrace();
			}
		}

		BaseLogger.log("3", getUserInfo(), null, "ErrString ::[ "+errStringXml.toString()+" ]");
		return errStringXml.toString();


	}

	public String itemChanged(String xmlString,String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		BaseLogger.log("3", getUserInfo(), null, "------------------ itemChanged calleddddd------------------1"+xmlString);
		BaseLogger.log("3", getUserInfo(), null, "------------------ itemChanged calleddddd------------------2"+xmlString1);
		BaseLogger.log("3", getUserInfo(), null, "------------------ itemChanged calleddddd------------------3"+xmlString2);

		Document dom = null;
		Document dom1 = null;
		Document dom2 = null;
		String valueXmlString = "";
		try
		{   
			dom = parseString(xmlString);
			dom1 = parseString(xmlString1);
			dom2 = parseString(xmlString2);
			valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
		}
		catch(Exception e)
		{
			BaseLogger.log("3", getUserInfo(), null, "Exception : [FixedAssetTransf ][itemChanged(String,String)] :==>\n"+e.getMessage());
			e.printStackTrace();
		}
		return valueXmlString;
	}

	@SuppressWarnings("resource")
	public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
	{	
		BaseLogger.log("3", getUserInfo(), null, "@@@@@@@ itemChanged called");
		StringBuffer valueXmlString = new StringBuffer();
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		//		GenericUtility genericUtility = GenericUtility.getInstance();
		E12GenericUtility genericUtility = new E12GenericUtility();
		ConnDriver connDriver = new ConnDriver();
		DistCommon disCommon = new DistCommon();
		int currentFormNo =0;
		finCommon = new FinCommon();
		String columnValue = null;
		NodeList parentNodeList = null;
		NodeList childNodeList = null;
		Node parentNode = null;
		Node childNode = null;
		int ctr = 0;
		String assetCodeFrom="",custName1="",sql="",assetCodeFromAssetTrans="",assetCode = "";		
		String itemSer="", grpCode="",itemCode="",siteCode="",alocCode="",assetType="",tranIdCreate="",
				tranSerCreate="", billNo="", suppCode="",currCode="",tranIdRem="",tranSerRem="",
				deprType="",deprMethod1="",deprMethod2="",empCodeVerify="", remarks="",assetCodeLink="", 
				empCode="",suppName="",suppNameNew="",acctPrdProc="",cctrCode="",assetCodePar="",itemDescr="";
		String rcpDateS="",instDateS="",remDateS="",useDateS="",verifiedOnS="",procDate1S="",procDate2S="",revalueDateS="";
		String taxClass="",taxChap="",taxEnv="",siteCodeForm="",siteCodeTo="",stationfrom="",stationto="",taxClassAcct="",
				taxEnvAcct="",tranType="",siteCodeFrm="",currCodeDescr="";
		double exchRate=0, orginalValue=0, otherChgs=0, taxAmt=0,taxRecoAmt=0,diffAmtExch=0,
				revalueAmt=0,totalValue=0,deprPerc1=0,deprAmt1=0,deprAmt2=0,wdvAmt1=0, deprPerc2=0,
				wdvAmt2=0,remValue=0,exciseAmt=0, commChgs=0, installChgs=0, insurChgs=0,
				profitLoss=0,totValueBc=0,deprAmtRevl2=0,wdvAmtRevl2=0,octroiChgs=0;
		Timestamp rcpDate=null,instDate=null,remDate=null,useDate=null,verifiedOn=null,procDate1=null,procDate2=null,revalueDate=null;

		try
		{			
			//Changes and Commented By Bhushan on 06-06-2016 :START
			//conn = connDriver.getConnectDB("DriverITM");
			conn = getConnection();
			//Changes and Commented By Bhushan on 06-06-2016 :END
			conn.setAutoCommit(false);
			connDriver=null;
			if(objContext != null && objContext.trim().length()>0)
			{
				currentFormNo = Integer.parseInt(objContext.trim());
			}
			SimpleDateFormat simpleDateFormatObj = new SimpleDateFormat(genericUtility.getApplDateFormat());
			valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
			valueXmlString.append(editFlag).append("</editFlag></header>");
			BaseLogger.log("3", getUserInfo(), null, "-------- currentFormNo : "+currentFormNo);
			BaseLogger.log("3", getUserInfo(), null,  "DOM CASE 1>>>> Elements>>["+genericUtility.serializeDom(dom).toString()+"]");

			switch(currentFormNo)
			{	
			case 1 :
				BaseLogger.log("3", getUserInfo(), null,  "DOM CASE 1>>>> Elements>>["+genericUtility.serializeDom(dom).toString()+"]");
				BaseLogger.log("3", getUserInfo(), null,  "DOM 1 CASE 1>>>> Elements>>["+genericUtility.serializeDom(dom1).toString()+"]");
				BaseLogger.log("3", getUserInfo(), null,  "DOM 2 CASE 1>>>> Elements>>["+genericUtility.serializeDom(dom2).toString()+"]");
				valueXmlString.append("<Detail1>");				
				BaseLogger.log("3", getUserInfo(), null, "[" + currentColumn + "] ==> '" + columnValue + "'");
				BaseLogger.log("3", getUserInfo(), null, "editFlag =>" +editFlag);

				if( currentColumn.trim().equalsIgnoreCase( "itm_default" ) )
				{
					assetCodeFromAssetTrans = genericUtility.getColumnValue("asset_code",dom);
					BaseLogger.log("3", getUserInfo(), null, "------------in itm_default--------->--AJIT--"+assetCodeFromAssetTrans);
					String confirm="N",loginSite="",loginSiteDescr="",xfrType1="T";
					Calendar currentDate = Calendar.getInstance();					 
					String tranDate = simpleDateFormatObj.format(currentDate.getTime());						 
					valueXmlString.append("<tran_date>").append("<![CDATA[" + tranDate + "]]>").append("</tran_date>");
					valueXmlString.append("<confirmed>").append("<![CDATA[" + confirm + "]]>").append("</confirmed>");
					valueXmlString.append("<xfr_type>").append("<![CDATA[" + xfrType1 + "]]>").append("</xfr_type>");
					valueXmlString.append("<assigned_to>").append("<![CDATA[" + "" + "]]>").append("</assigned_to>");

					loginSite = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");					
					loginSite=loginSite==null ? "" :loginSite.trim(); 
					BaseLogger.log("3", getUserInfo(), null, "loginSite ----->>["+loginSite+"]");	
					loginSiteDescr=getNameOrDescrForCode(conn, "site", "descr", "site_code", loginSite);
					valueXmlString.append("<site_code__from>").append("<![CDATA[" + loginSite + "]]>").append("</site_code__from>");
					valueXmlString.append("<site_descr>").append("<![CDATA[" + loginSiteDescr + "]]>").append("</site_descr>");
					//Added By Ganpat Yeram[05/JUN/2024]
					siteCodeFrm = genericUtility.getColumnValue("site_code__from",dom);
					BaseLogger.log("3", getUserInfo(), null, "<------SITE_CODE__FROM["+siteCodeFrm);
					if(loginSite !=null && loginSite.trim().length()>0)
					{
						sql = "SELECT FI.CURR_CODE FROM FINENT FI WHERE FI.FIN_ENTITY = (SELECT FIN_ENTITY FROM SITE WHERE SITE_CODE = ? )";
						pstmt =  conn.prepareStatement(sql);
						pstmt.setString(1, loginSite);
						rs = pstmt.executeQuery();
						if(rs.next())
						{
							currCode =rs.getString("CURR_CODE");
						}
						rs.close();
						rs = null;
						pstmt.close();
						pstmt = null;
						if(currCode !=null && currCode.trim().length()>0)
						{
							sql = "SELECT DESCR FROM CURRENCY WHERE CURR_CODE = ?";
							pstmt =  conn.prepareStatement(sql);
							pstmt.setString(1, currCode);
							rs = pstmt.executeQuery();
							if(rs.next())
							{
								currCodeDescr =rs.getString("DESCR");
							}
							rs.close();
							rs = null;
							pstmt.close();
							pstmt = null;
							valueXmlString.append("<curr_code>").append("<![CDATA["+currCode+"]]>").append("</curr_code>");
							valueXmlString.append("<currency_descr>").append("<![CDATA["+currCodeDescr+"]]>").append("</currency_descr>");
						}
						
					}//END BY GANPAT YERAm[05/JUN/2024]

				}else if (currentColumn.trim().equals("site_code__to")){
					String siteDescrTo="";
					siteCodeTo = genericUtility.getColumnValue("site_code__to",dom);
					BaseLogger.log("3", getUserInfo(), null, "");
					siteCodeTo=siteCodeTo==null ? "" :siteCodeTo.trim(); 
					BaseLogger.log("3", getUserInfo(), null, "siteCodeTo----->>["+siteCodeTo+"]");	
					siteDescrTo=getNameOrDescrForCode(conn, "site", "descr", "site_code", siteCodeTo);
					if(siteCodeTo.length() > 0)
						valueXmlString.append("<descr_1>").append("<![CDATA["+siteDescrTo+"]]>").append("</descr_1>");
					else
						valueXmlString.append("<descr_1>").append("<![CDATA[]]>").append("</descr_1>");
				}else if (currentColumn.trim().equals("site_code__from")){
					String siteCodeFrom="",siteDescrFrom="";
					siteCodeFrom = genericUtility.getColumnValue("site_code__from",dom);					
					siteCodeFrom=siteCodeFrom==null ? "" :siteCodeFrom.trim(); 
					BaseLogger.log("3", getUserInfo(), null, "siteCodeFrom----->>["+siteCodeFrom+"]");	
					siteDescrFrom=getNameOrDescrForCode(conn, "site", "descr", "site_code", siteCodeFrom);
					if(siteCodeFrom.length() > 0)
						valueXmlString.append("<site_descr>").append("<![CDATA["+siteDescrFrom+"]]>").append("</site_descr>");
					else
						valueXmlString.append("<site_descr>").append("<![CDATA[]]>").append("</site_descr>");
					//Added By Ganpat yeram[05/JUN/2024]
					if(siteCodeFrom !=null && siteCodeFrom.trim().length()>0)
					{
						sql = "SELECT FI.CURR_CODE FROM FINENT FI WHERE FI.FIN_ENTITY = (SELECT FIN_ENTITY FROM SITE WHERE SITE_CODE = ? )";
						pstmt =  conn.prepareStatement(sql);
						pstmt.setString(1, siteCodeFrom);
						rs = pstmt.executeQuery();
						if(rs.next())
						{
							currCode =rs.getString("CURR_CODE");
						}
						rs.close();
						rs = null;
						pstmt.close();
						pstmt = null;
						BaseLogger.log("3", getUserInfo(), null, "<----CURRENCY_CODE["+currCode+"]");	
						
						if(currCode !=null && currCode.trim().length()>0)
						{
							sql = "SELECT DESCR FROM CURRENCY WHERE CURR_CODE = ?";
							pstmt =  conn.prepareStatement(sql);
							pstmt.setString(1, currCode);
							rs = pstmt.executeQuery();
							if(rs.next())
							{
								currCodeDescr =rs.getString("DESCR");
							}
							rs.close();
							rs = null;
							pstmt.close();
							pstmt = null;
							valueXmlString.append("<curr_code>").append("<![CDATA["+currCode+"]]>").append("</curr_code>");
							valueXmlString.append("<currency_descr>").append("<![CDATA["+currCodeDescr+"]]>").append("</currency_descr>");
						}
						if(currCode==null || currCode.trim().length()==0)
						{
							valueXmlString.append("<curr_code>").append("<![CDATA[]]>").append("</curr_code>");
							valueXmlString.append("<currency_descr>").append("<![CDATA[]]>").append("</currency_descr>");
						}
						//END BY Ganpat Yeram[05/JUN/2024]
					}
				}
				//Added By Ganpat Yeram[04/JUN/2024]
				else if(currentColumn.trim().equals("curr_code"))
				{
					currCode = genericUtility.getColumnValue("curr_code",dom);
					if(currCode!=null && currCode.trim().length()>0)
					{
					sql = "SELECT DESCR FROM CURRENCY WHERE CURR_CODE = ?";
					pstmt =  conn.prepareStatement(sql);
					pstmt.setString(1, currCode);
					rs = pstmt.executeQuery();
					if(rs.next())
					{
						currCodeDescr =rs.getString("DESCR");
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
					}
					valueXmlString.append("<currency_descr>").append("<![CDATA["+currCodeDescr+"]]>").append("</currency_descr>");
					if(currCode ==null || currCode.trim().length()==0)
					{
						valueXmlString.append("<currency_descr>").append("<![CDATA[]]>").append("</currency_descr>");
					}
				}
				//END
                valueXmlString.append("</Detail1>");
				break;
				
				
				
			case 2:
				BaseLogger.log("3", getUserInfo(), null,  "DOM CASE 2>>>> Elements>>["+genericUtility.serializeDom(dom).toString()+"]");
				BaseLogger.log("3", getUserInfo(), null,  "DOM 1 CASE 2>>>> Elements>>["+genericUtility.serializeDom(dom1).toString()+"]");
				BaseLogger.log("3", getUserInfo(), null,  "DOM 2 CASE 2>>>> Elements>>["+genericUtility.serializeDom(dom2).toString()+"]");
				parentNodeList = dom.getElementsByTagName("Detail2");
				parentNode = parentNodeList.item(0);
				childNodeList = parentNode.getChildNodes();
				valueXmlString.append("<Detail2>");
				int childListLength = childNodeList.getLength();	
				String tempStr="";
				int pos;
				BaseLogger.log("3", getUserInfo(), null, "Detail 2item default called111::["+assetCodeFrom+"]");
				//Added itm_default condition for Detail2 to call the itemChange condition for asset_code__from field -- Ajit[12-SEP-2025]
				if (currentColumn.trim().equals("itm_default"))
				{	
					assetCode = genericUtility.getColumnValue("asset_code",dom2);
					valueXmlString.append("<asset_code__from>").append("<![CDATA[" + assetCode + "]]>").append("</asset_code__from>");
					BaseLogger.log("3", getUserInfo(), null, "Detail 2item default called::["+assetCode+"]");
					tempStr = itemChanged(dom2, dom2, dom2, objContext, "asset_code__from", editFlag, xtraParams);
                    System.out.println("8887776"+tempStr);
                    pos = tempStr.indexOf("<Detail2>");
                    tempStr = tempStr.substring(pos + 9);
                    pos = tempStr.indexOf("</Detail2>");
                    tempStr = tempStr.substring(0, pos);
                    valueXmlString.append(tempStr);
				}
				
				else if (currentColumn.trim().equals("asset_code__from"))
				{						
					assetCodeFrom = genericUtility.getColumnValue("asset_code__from",dom);
					assetCodeFrom=assetCodeFrom==null ? "" :assetCodeFrom.trim();
					BaseLogger.log("3", getUserInfo(), null, "assetCodeFrom ----->>["+assetCodeFrom+"]");

					sql="select	 item_ser, grp_code, item_code,site_code, aloc_code, asset_type," 
							+ "tran_id__create, tran_ser__create,rcp_date, bill_no, inst_date, supp_code,"
							+ "curr_code,exch_rate, orginal_value, other_chgs, tax_amt,tax_reco_amt,"
							+ "diff_amt__exch, revalue_amt, revalue_date,total_value, tran_id__rem, "
							+ "tran_ser__rem, rem_date,depr_type, depr_perc_1, depr_method_1, depr_amt_1,"
							+ "wdv_amt_1, depr_perc_2, depr_method_2, depr_amt_2,wdv_amt_2, verified_on, "
							+ "emp_code__verify, remarks,asset_code__link, emp_code, rem_value, use_date,"
							+ "excise_amt, comm_chgs, install_chgs, insur_chgs,profit_loss, supp_name,"
							+ "tot_value__bc, acct_prd__proc,cctr_code, asset_code__par, "
							+ "depr_amt_revl_2,wdv_amt_revl_2,octroi_chgs,proc_date_1,proc_date_2"
							+ " from asset_register where asset_code = ?";

					pstmt=conn.prepareStatement(sql);
					pstmt.setString(1, assetCodeFrom);
					rs=pstmt.executeQuery();
					if(rs.next()){		
						//item_ser, grp_code, item_code,site_code, aloc_code, asset_type, 6
						itemSer=rs.getString("item_ser") == null ? "" : rs.getString("item_ser").trim();
						grpCode=rs.getString("grp_code") == null ? "" : rs.getString("grp_code").trim();
						itemCode=rs.getString("item_code") == null ? "" : rs.getString("item_code").trim();
						siteCode=rs.getString("site_code") == null ? "" : rs.getString("site_code").trim();
						alocCode=rs.getString("aloc_code") == null ? "" : rs.getString("aloc_code").trim();
						assetType=rs.getString("asset_type") == null ? "" : rs.getString("asset_type").trim();						

						//tran_id__create, tran_ser__create,rcp_date, bill_no, inst_date, supp_code  6
						tranIdCreate=rs.getString("tran_id__create") == null ? "" : rs.getString("tran_id__create").trim();
						tranSerCreate=rs.getString("tran_ser__create") == null ? "" : rs.getString("tran_ser__create").trim();
						rcpDate=rs.getTimestamp("rcp_date");
						billNo=rs.getString("bill_no") == null ? "" : rs.getString("bill_no").trim();
						instDate=rs.getTimestamp("inst_date");
						suppCode=rs.getString("supp_code") == null ? "" : rs.getString("supp_code").trim();

						//curr_code,exch_rate, orginal_value, other_chgs, tax_amt,tax_reco_amt 6
						currCode=rs.getString("curr_code") == null ? "" : rs.getString("curr_code").trim();
						exchRate=rs.getDouble("exch_rate");
						orginalValue=rs.getDouble("orginal_value");
						otherChgs=rs.getDouble("other_chgs");
						taxAmt=rs.getDouble("tax_amt");
						taxRecoAmt=rs.getDouble("tax_reco_amt");

						//diff_amt__exch, revalue_amt, revalue_date,total_value, tran_id__rem 5							
						diffAmtExch=rs.getDouble("diff_amt__exch");
						revalueAmt=rs.getDouble("revalue_amt");
						revalueDate=rs.getTimestamp("revalue_date");
						totalValue=rs.getDouble("total_value");
						tranIdRem=rs.getString("tran_id__rem") == null ? "" : rs.getString("tran_id__rem").trim();

						//tran_ser__rem, rem_date,depr_type, depr_perc_1, depr_method_1, depr_amt_1  6
						tranSerRem=rs.getString("tran_ser__rem") == null ? "" : rs.getString("tran_ser__rem").trim();
						remDate=rs.getTimestamp("rem_date");
						deprType=rs.getString("depr_type") == null ? "" : rs.getString("depr_type").trim();
						deprPerc1=rs.getDouble("depr_perc_1");
						deprMethod1=rs.getString("depr_method_1") == null ? "" : rs.getString("depr_method_1").trim();
						deprAmt1=rs.getDouble("depr_amt_1");

						//wdv_amt_1, depr_perc_2, depr_method_2, depr_amt_2,wdv_amt_2, verified_on  6							
						wdvAmt1=rs.getDouble("wdv_amt_1");
						deprPerc2=rs.getDouble("depr_perc_2");
						deprMethod2=rs.getString("depr_method_2") == null ? "" : rs.getString("depr_method_2").trim();
						deprAmt2=rs.getDouble("depr_amt_2");
						wdvAmt2=rs.getDouble("wdv_amt_2");
						verifiedOn=rs.getTimestamp("verified_on");

						//emp_code__verify, remarks,asset_code__link, emp_code, rem_value, use_date 6
						empCodeVerify=rs.getString("emp_code__verify") == null ? "" : rs.getString("emp_code__verify").trim();
						remarks=rs.getString("remarks") == null ? "" : rs.getString("remarks");
						assetCodeLink=rs.getString("asset_code__link") == null ? "" : rs.getString("asset_code__link").trim();
						empCode=rs.getString("emp_code") == null ? "" : rs.getString("emp_code").trim();
						remValue=rs.getDouble("rem_value");
						useDate=rs.getTimestamp("use_date");							

						//excise_amt, comm_chgs, install_chgs, insur_chgs,profit_loss, supp_name  6
						exciseAmt=rs.getDouble("excise_amt");
						commChgs=rs.getDouble("comm_chgs");
						installChgs=rs.getDouble("install_chgs");
						insurChgs=rs.getDouble("insur_chgs");
						profitLoss=rs.getDouble("profit_loss");
						suppName=rs.getString("supp_name") == null ? "" : rs.getString("supp_name").trim();

						//tot_value__bc, acct_prd__proc,cctr_code, asset_code__par 4
						totValueBc=rs.getDouble("tot_value__bc");
						acctPrdProc=rs.getString("acct_prd__proc") == null ? "" : rs.getString("acct_prd__proc").trim();
						cctrCode=rs.getString("cctr_code") == null ? "" : rs.getString("cctr_code").trim();
						assetCodePar=rs.getString("asset_code__par") == null ? "" : rs.getString("asset_code__par").trim();
						//depr_amt_revl_2,wdv_amt_revl_2,octroi_chgs,proc_date_1,proc_date_2  5
						deprAmtRevl2=rs.getDouble("depr_amt_revl_2");
						wdvAmtRevl2=rs.getDouble("wdv_amt_revl_2"); 
						octroiChgs=rs.getDouble("octroi_chgs");
						procDate1=rs.getTimestamp("proc_date_1");	
						procDate2=rs.getTimestamp("proc_date_2");				


						//Formatting Dates
						useDateS=useDate==null ? "" : simpleDateFormatObj.format(useDate);
						rcpDateS=rcpDate==null ? "" : simpleDateFormatObj.format(rcpDate);
						instDateS=instDate==null ? "" : simpleDateFormatObj.format(instDate);							
						revalueDateS=revalueDate==null ? "" : simpleDateFormatObj.format(revalueDate);
						remDateS=remDate==null ? "" : simpleDateFormatObj.format(remDate);
						verifiedOnS=verifiedOn==null ? "" : simpleDateFormatObj.format(verifiedOn);
						procDate1S=procDate1==null ? "" : simpleDateFormatObj.format(procDate1);
						procDate2S=procDate2==null ? "" : simpleDateFormatObj.format(procDate2);						

					}
					valueXmlString.append("<depr_type__to protect = \"0\">").append("<![CDATA[]]>").append("</depr_type__to>");
					//Basic
					valueXmlString.append("<asset_type>").append("<![CDATA[" + assetType + "]]>").append("</asset_type>");
					//Added code by varsha v on 24-05-18 to set item_ser__to,grp_code__to,aloc_code__to,asset_code__par_to,depr_type__to,cctr_code__to
					valueXmlString.append("<asset_code__to>").append("<![CDATA[" + assetCodeFrom + "]]>").append("</asset_code__to>");
					valueXmlString.append("<item_ser__from>").append("<![CDATA[" + itemSer + "]]>").append("</item_ser__from>");
					valueXmlString.append("<item_ser__to>").append("<![CDATA[" + itemSer + "]]>").append("</item_ser__to>");
					valueXmlString.append("<grp_code__from>").append("<![CDATA[" + grpCode + "]]>").append("</grp_code__from>");
					valueXmlString.append("<grp_code__to>").append("<![CDATA[" + grpCode + "]]>").append("</grp_code__to>");
					valueXmlString.append("<aloc_code__from>").append("<![CDATA[" + alocCode + "]]>").append("</aloc_code__from>");
					valueXmlString.append("<aloc_code__to>").append("<![CDATA[" + alocCode + "]]>").append("</aloc_code__to>");
					valueXmlString.append("<asset_code__par_from>").append("<![CDATA[" + assetCodePar + "]]>").append("</asset_code__par_from>");
					valueXmlString.append("<asset_code__par_to>").append("<![CDATA[" + assetCodePar + "]]>").append("</asset_code__par_to>");
					valueXmlString.append("<depr_type__from>").append("<![CDATA[" + deprType + "]]>").append("</depr_type__from>");
					valueXmlString.append("<depr_type__to>").append("<![CDATA[" + deprType + "]]>").append("</depr_type__to>");
					valueXmlString.append("<cctr_code__from>").append("<![CDATA[" + cctrCode + "]]>").append("</cctr_code__from>");
					valueXmlString.append("<cctr_code__to>").append("<![CDATA[" + cctrCode + "]]>").append("</cctr_code__to>");
					//ended code by varsha v on 24-05-18 to set item_ser__to,grp_code__to,aloc_code__to,asset_code__par_to,depr_type__to,cctr_code__to

					//Others   
					valueXmlString.append("<item_code>").append("<![CDATA[" + itemCode + "]]>").append("</item_code>");
					if(itemCode.length() > 0)
						itemDescr=getNameOrDescrForCode(conn,"item","descr","item_code",itemCode);
					else
						itemDescr="";
					BaseLogger.log("3", getUserInfo(), null, "ItemDescr---->>["+itemDescr+"]");
					valueXmlString.append("<descr_1>").append("<![CDATA[" + itemCode + "]]>").append("</descr_1>");
					valueXmlString.append("<tran_id__create>").append("<![CDATA[" + tranIdCreate + "]]>").append("</tran_id__create>");
					valueXmlString.append("<tran_ser__create>").append("<![CDATA[" + tranSerCreate + "]]>").append("</tran_ser__create>");						
					valueXmlString.append("<bill_no>").append("<![CDATA[" + billNo + "]]>").append("</bill_no>");
					valueXmlString.append("<supp_code>").append("<![CDATA[" + suppCode + "]]>").append("</supp_code>");

					if(suppName.length() == 0 && suppCode.length() > 0 ){
						suppNameNew=getNameOrDescrForCode(conn,"supplier","supp_name","supp_code",suppCode);
						valueXmlString.append("<supp_name>").append("<![CDATA[" + suppNameNew + "]]>").append("</supp_name>");
					}else{
						valueXmlString.append("<supp_name>").append("<![CDATA[" + suppName + "]]>").append("</supp_name>");
					}


					valueXmlString.append("<rcp_date>").append("<![CDATA[" +rcpDateS+ "]]>").append("</rcp_date>");
					valueXmlString.append("<revalue_date>").append("<![CDATA[" +revalueDateS+ "]]>").append("</revalue_date>");
					valueXmlString.append("<inst_date>").append("<![CDATA[" + instDateS + "]]>").append("</inst_date>");
					valueXmlString.append("<curr_code>").append("<![CDATA[" + currCode + "]]>").append("</curr_code>");
					valueXmlString.append("<exch_rate>").append("<![CDATA[" + (exchRate > 0 ? exchRate : "") + "]]>").append("</exch_rate>");

					valueXmlString.append("<use_date>").append("<![CDATA[" + useDateS + "]]>").append("</use_date>");
					valueXmlString.append("<orginal_value>").append("<![CDATA[" +(orginalValue > 0 ? orginalValue : "")+ "]]>").append("</orginal_value>");
					valueXmlString.append("<total_value>").append("<![CDATA[" + (totalValue > 0 ? totalValue : "") + "]]>").append("</total_value>");
					valueXmlString.append("<tax_amt>").append("<![CDATA[" + (taxAmt > 0 ? taxAmt : "") + "]]>").append("</tax_amt>");
					valueXmlString.append("<tax_reco_amt>").append("<![CDATA[" + (taxRecoAmt > 0 ? taxRecoAmt : "") + "]]>").append("</tax_reco_amt>");
					valueXmlString.append("<diff_amt__exch>").append("<![CDATA[" + (diffAmtExch > 0 ? diffAmtExch : "") + "]]>").append("</diff_amt__exch>");						
					valueXmlString.append("<revalue_amt>").append("<![CDATA[" + (revalueAmt > 0 ? revalueAmt : "") + "]]>").append("</revalue_amt>");
					valueXmlString.append("<excise_amt>").append("<![CDATA[" + (exciseAmt > 0 ? exciseAmt : "") + "]]>").append("</excise_amt>");

					valueXmlString.append("<insur_chgs>").append("<![CDATA[" + (insurChgs > 0 ? insurChgs : "") + "]]>").append("</insur_chgs>");
					valueXmlString.append("<other_chgs>").append("<![CDATA[" + (otherChgs > 0 ? otherChgs : "") + "]]>").append("</other_chgs>");
					valueXmlString.append("<octroi_chgs>").append("<![CDATA[" + (octroiChgs > 0 ? octroiChgs : "") + "]]>").append("</octroi_chgs>");

					valueXmlString.append("<install_chgs>").append("<![CDATA[" + (installChgs > 0 ? installChgs : "") + "]]>").append("</install_chgs>");
					valueXmlString.append("<comm_chgs>").append("<![CDATA[" + (commChgs > 0 ? commChgs : "") + "]]>").append("</comm_chgs>");						

					//Depreciation 14
					valueXmlString.append("<depr_method_1>").append("<![CDATA[" + deprMethod1 + "]]>").append("</depr_method_1>");
					valueXmlString.append("<depr_amt_1>").append("<![CDATA[" + (deprAmt1 > 0 ? deprAmt1 : "") + "]]>").append("</depr_amt_1>");
					valueXmlString.append("<depr_perc_1>").append("<![CDATA[" + (deprPerc1 > 0 ? deprPerc1 : "") + "]]>").append("</depr_perc_1>");						
					valueXmlString.append("<depr_method_2>").append("<![CDATA[" +deprMethod2 + "]]>").append("</depr_method_2>");
					valueXmlString.append("<depr_amt_2>").append("<![CDATA[" +(deprAmt2 > 0 ? deprAmt2 : "") + "]]>").append("</depr_amt_2>");
					valueXmlString.append("<depr_perc_2>").append("<![CDATA[" + (deprPerc2 > 0 ? deprPerc2 : "") + "]]>").append("</depr_perc_2>");						
					valueXmlString.append("<wdv_amt_1>").append("<![CDATA[" + (wdvAmt1 > 0 ? wdvAmt1 : "") + "]]>").append("</wdv_amt_1>");
					valueXmlString.append("<wdv_amt_2>").append("<![CDATA[" + (wdvAmt2 > 0 ? wdvAmt2 : "") + "]]>").append("</wdv_amt_2>");
					valueXmlString.append("<depr_amt_revl_2>").append("<![CDATA[" + (deprAmtRevl2 > 0 ? deprAmtRevl2 : "") + "]]>").append("</depr_amt_revl_2>");
					valueXmlString.append("<wdv_amt_revl_2>").append("<![CDATA[" + (wdvAmtRevl2 > 0 ? wdvAmtRevl2 : "")+ "]]>").append("</wdv_amt_revl_2>");						
					valueXmlString.append("<profit_loss>").append("<![CDATA[" +  (profitLoss > 0 ? profitLoss : "")+ "]]>").append("</profit_loss>");
					valueXmlString.append("<acct_prd__proc>").append("<![CDATA[" + acctPrdProc+ "]]>").append("</acct_prd__proc>");						
					valueXmlString.append("<asset_code__link>").append("<![CDATA[" + assetCodeLink + "]]>").append("</asset_code__link>");
					valueXmlString.append("<total_value__bc>").append("<![CDATA[" + (totValueBc > 0 ? totValueBc : "") + "]]>").append("</total_value__bc>");	

					//Verification 5
					valueXmlString.append("<proc_date_1>").append("<![CDATA[" + procDate1S + "]]>").append("</proc_date_1>");
					valueXmlString.append("<emp_code__verify>").append("<![CDATA[" + assetCodeLink + "]]>").append("</emp_code__verify>");
					valueXmlString.append("<proc_date_2>").append("<![CDATA[" + procDate2S + "]]>").append("</proc_date_2>");
					valueXmlString.append("<verified_on>").append("<![CDATA[" + verifiedOnS + "]]>").append("</verified_on>");
					valueXmlString.append("<remarks>").append("<![CDATA[" + remarks + "]]>").append("</remarks>");						


					//Vijay Added  TAXEX--IN ASSET TRANSFER 
					System.out.println("outside itemchange=======>");
					taxClass = checkNull(genericUtility.getColumnValue( "tax_class",dom));
					taxChap = checkNull(genericUtility.getColumnValue("tax_chap", dom));
					taxEnv = checkNull(genericUtility.getColumnValue("tax_env", dom));
					siteCodeForm =checkNull(genericUtility.getColumnValue("site_code__from", dom1));//site_code__to
					siteCodeTo = checkNull(genericUtility.getColumnValue("site_code__to", dom1));//site_code__from
					tranType = checkNull(genericUtility.getColumnValue("xfr_type", dom1));

					System.out.println("tax_class==>"+taxClass);
					System.out.println("taxChap==>"+taxChap);
					System.out.println("taxEnv==>"+taxEnv);
					System.out.println("lsSiteCodeForm==>"+siteCodeForm);
					System.out.println("lsSiteCodeTo==>"+siteCodeTo);
					System.out.println("tranType==>"+tranType);

					sql ="select stan_code from site where site_code =?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1, siteCodeForm);
					rs = pstmt.executeQuery();					
					if (rs.next()) {
						stationfrom = checkNull(rs.getString("stan_code"));
						System.out.println("ls_stationfr==>"+stationfrom);

					}
					pstmt.close();
					pstmt = null;
					rs.close();
					rs = null;

					sql ="select stan_code from site where site_code =?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1, siteCodeTo);
					rs = pstmt.executeQuery();					
					if (rs.next()) {
						stationto = checkNull(rs.getString("stan_code"));
						System.out.println("ls_stationto==>"+stationto);
					}
					pstmt.close();
					pstmt = null;
					rs.close();
					rs = null;

					sql ="select item_ser from item where item_code =?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1, itemCode);
					rs = pstmt.executeQuery();					
					if (rs.next()) {
						itemSer = checkNull(rs.getString("item_ser"));
						System.out.println("itemSer==>"+itemSer);
					}
					pstmt.close();
					pstmt = null;
					rs.close();
					rs = null;

					//						ADDED BY VIJAY [ITEMCHAGE FOR TAX_CLASS,TAX_CHAP,TAX_ENV].START
					taxClass = disCommon.getTaxClass("","",itemCode,siteCodeForm, conn);
					taxChap = disCommon.getTaxChap(itemCode, itemSer, "", "", siteCodeForm, conn);	
					taxEnv = disCommon.getTaxEnv(stationfrom, stationto, taxChap, taxClass, siteCodeForm, conn);

					String isTaxNA = checkNull(finCommon.getFinparams("999999", "TAX_NA", conn));
					isTaxNA = isTaxNA.trim();
					System.out.println("isTaxNA =======> "+isTaxNA);

					//Added condition by Ajit, if entry finds in the finparm table for TAX_NA var_name then set the tax fields by default as "N/A" on 22-JAN-26
                    if(isTaxNA.equalsIgnoreCase("N/A")) {
                    	taxClass = isTaxNA;
                    	taxChap = isTaxNA;
                    	taxEnv = isTaxNA;
                    }
					
					System.out.println("taxClass itemchange=======>"+taxClass);
					valueXmlString.append("<tax_class>").append("<![CDATA["+ taxClass +  "]]>").append("</tax_class>");

					System.out.println("taxChap itemchange=======>"+taxChap);
					valueXmlString.append("<tax_chap>").append("<![CDATA[" + taxChap + "]]>").append("</tax_chap>");

					System.out.println("taxEnv itemchange=======>"+taxEnv);
					valueXmlString.append("<tax_env>").append("<![CDATA[" + taxEnv + "]]>").append("</tax_env>");
					//						ADDED BY VIJAY [ITEMCHAGE FOR TAX_CLASS,TAX_CHAP,TAX_ENV].END

				}
				

				else if (currentColumn.trim().equals("item_ser__to"))
				{
					String itemSerDescr="",itemSerTo="";
					itemSerTo = genericUtility.getColumnValue("item_ser__to",dom);
					itemSerTo=itemSerTo==null ? "" : itemSerTo.trim();
					BaseLogger.log("3", getUserInfo(), null, "itemSerTo--->["+itemSerTo+"]");
					if(itemSerTo.length() > 0){
						itemSerDescr=getNameOrDescrForCode(conn,"itemser","descr","item_ser",itemSerTo);
						valueXmlString.append("<descr>").append("<![CDATA["+itemSerDescr+"]]>").append("</descr>");
					}else{
						valueXmlString.append("<descr>").append("<![CDATA[]]>").append("</descr>");
					}						
				}

				valueXmlString.append("</Detail2>");
			}// end switch 
			valueXmlString.append("</Root>");			


		} //end try-------------------------------------------------------------
		catch(Exception e)
		{
			e.printStackTrace();
			BaseLogger.log("3", getUserInfo(), null, "Exception ::"+e.getMessage());			
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				if(conn!=null)
				{
					conn.close();
					conn = null;
				}
				if(rs != null)
				{
					rs.close();
					rs = null;
				}
				if(pstmt != null)
				{
					pstmt.close();
					pstmt = null;
				}				
			}
			catch(Exception d)
			{
				d.printStackTrace();
			}			
		}
		BaseLogger.log("3", getUserInfo(), null, "Value of valueXmlString : "+valueXmlString.toString());
		return valueXmlString.toString();

	}
	private String errorType( Connection conn , String errorCode )
	{
		String msgType = "";
		PreparedStatement pstmt = null ; 
		ResultSet rs = null;
		try
		{			
			String  sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO =   ? ";

			pstmt = conn.prepareStatement( sql );			
			pstmt.setString(1, checkNull(errorCode));			
			rs = pstmt.executeQuery();
			while( rs.next() )
			{
				msgType = rs.getString("MSG_TYPE");
			}			
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}		
		finally
		{
			try
			{
				if ( rs != null )
				{
					rs.close();
					rs = null;
				}
				if ( pstmt != null )
				{
					pstmt.close();
					pstmt = null;
				}
			}
			catch ( Exception e )
			{
				e.printStackTrace();
			}
		}		
		return msgType;
	}
	public String checkNull(String input)	
	{
		if (input == null)
		{
			input="";
		}
		return input.trim();
	}
	protected String getNameOrDescrForCode(Connection conn, String table_name, String descr_col_name,String whrCondCol, String whrCondVal)
	{
		String descr = null;

		if(conn!=null){

			ResultSet rs=null;
			PreparedStatement pstmt = null;

			String sql="SELECT "+descr_col_name+" FROM "+table_name+" WHERE "+whrCondCol+" = ?";

			BaseLogger.log("3", getUserInfo(), null, "SQL in getNameOrDescrForCode method : "+sql);
			try
			{
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,whrCondVal);
				rs = pstmt.executeQuery();
				if(rs.next())
				{
					descr = rs.getString(descr_col_name);
				}

				descr=descr==null ?"" :descr;
			}
			catch(SQLException e)
			{
				BaseLogger.log("3", getUserInfo(), null, "SQL Exception In getNameOrDescrForCode method of FixedAssetTransf Class : "+e.getMessage());
				e.printStackTrace();
			}
			catch(Exception ex)
			{
				BaseLogger.log("3", getUserInfo(), null, "Exception In getNameOrDescrForCode method of FixedAssetTransf Class : "+ex.getMessage());
				ex.printStackTrace();
			}finally{

				try{

					if(pstmt!=null){
						pstmt.close();
						pstmt = null;
					}
					if(rs!=null){
						rs.close();
						rs = null;
					}
				}catch (SQLException se) {
					se.printStackTrace();
				}
			}
		}else{
			try {
				throw new SQLException("Connection passed to FixedAssetTransf.getNameOrDescrForCode() method is null");
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		return descr;
	}
	protected int getDBRowCount(Connection conn, String table_name, String whrCondCol, String whrCondVal)
	{
		int count=-1;

		if(conn!=null){

			ResultSet rs=null;
			PreparedStatement pstmt = null;

			String sql="select count(1) from "+table_name+" where "+whrCondCol+" = ?";
			BaseLogger.log("3", getUserInfo(), null, "SQL in getDBRowCount method : "+sql);
			try
			{
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,whrCondVal);
				rs = pstmt.executeQuery();
				if(rs.next())
				{
					count = rs.getInt(1);
				}
			}
			catch(SQLException e)
			{
				BaseLogger.log("3", getUserInfo(), null, "SQL Exception In getDBRowCount method of FixedAssetTransf Class : "+e.getMessage());
				e.printStackTrace();
			}
			catch(Exception ex)
			{
				BaseLogger.log("3", getUserInfo(), null, "Exception In getDBRowCount method of FixedAssetTransf Class : "+ex.getMessage());
				ex.printStackTrace();
			}finally{

				try{

					if(pstmt!=null){
						pstmt.close();
						pstmt = null;
					}
					if(rs!=null){
						rs.close();
						rs = null;
					}
				}catch (SQLException se) {
					se.printStackTrace();
				}
			}
		}else{
			try {
				throw new SQLException("Connection passed to FixedAssetTransf.getDBRowCount() method is null");
			} catch (SQLException e) {
				e.printStackTrace();					
			}
		}

		return count;
	}
	private String getErrorType(String retString)
	{
		HashMap<String,String> sh = new HashMap<String,String>();
		Document dom = null;
		NodeList parentNodeList = null,childNodeList = null;
		Node childNode = null;		
		String errotType = "", errorCode = "";
		try
		{
			dom =  genericUtility.parseString(retString);
			parentNodeList = dom.getElementsByTagName("Errors");
			BaseLogger.log("3", getUserInfo(), null, "parentNodeList is ["+parentNodeList+"] \t length ["+parentNodeList.getLength()+"]");

			for(int ctr = 0; ctr < parentNodeList.getLength(); ctr++)
			{
				childNodeList = parentNodeList.item(ctr).getChildNodes();
				int  childNodeListlen = childNodeList.getLength();

				for(int ctrD = 0; ctrD < childNodeListlen ; ctrD++)
				{
					childNode = childNodeList.item(ctrD);

					if("error".equalsIgnoreCase(childNode.getNodeName()))
					{
						errotType = childNode.getAttributes().getNamedItem("type").getNodeValue();
						errorCode = childNode.getAttributes().getNamedItem("id").getNodeValue();
						BaseLogger.log("3", getUserInfo(), null, "getErrorType for code::["+errorCode+"] is "+errotType+"]");
					}				
				}
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			BaseLogger.log("3", getUserInfo(), null, "Error Inside Method [getErrorType] is "+e);
		}
		return errotType;
	}
	//Added By Ganpat Yeram[05/Jun/2024]
	private String isExistCurrCode(String table, String field, String value,Connection conn) throws SQLException
	{
		String sql = "",retStr="";
		PreparedStatement pstmt = null;
		ResultSet rs = null ;
		int cnt=0;

		sql = " SELECT COUNT(1) FROM "+ table + " WHERE " + field + " = ? ";
		pstmt =  conn.prepareStatement(sql);
		pstmt.setString(1,value);
		rs = pstmt.executeQuery();
		if(rs.next())
		{
			cnt = rs.getInt(1);
		}
		rs.close();
		rs = null;
		pstmt.close(); 
		pstmt = null;
		BaseLogger.log("3", getUserInfo(), null,  "COUNT["+cnt+"]");
		if( cnt > 0)
		{
			retStr = "TRUE";
		}
		if( cnt == 0 )
		{
			retStr = "FALSE";
		}
		BaseLogger.log("3", getUserInfo(), null,  "@@@@ isexist["+value+"]:::["+retStr+"]:::["+cnt+"]");
		return retStr;
	}
	//End By Ganpat Yeram[05/JUN/2024]
	private boolean isExist(Connection conn, String tableName, String columnName, String value)
			throws ITMException, RemoteException {
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = "";
		boolean status = false;
		try {
			sql = "SELECT count(*) from " + tableName + " where " + columnName + "  = ? ";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, value);
			rs = pstmt.executeQuery();

			if (rs.next()) {
				if (rs.getBoolean(1)) {
					status = true;
				}
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;
		} catch (Exception e) {
			BaseLogger.log("3", getUserInfo(), null,  "Exception in isExist ");
			e.printStackTrace();
			throw new ITMException(e);
		}
		BaseLogger.log("3", getUserInfo(), null,  "returning String from isExist ");
		return status;
	}

}
