//Win Name = bank_reco21
package ibase.webitm.ejb.fin;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import org.xml.sax.InputSource;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import java.rmi.RemoteException;
import java.util.*;
import java.util.Date;
import java.sql.*;
import java.io.*;
import org.omg.CORBA.ORB;
import org.w3c.dom.*;
import java.util.Properties;
import javax.xml.parsers.*;
import javax.ejb.*;
import javax.naming.InitialContext;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.*;
import ibase.webitm.utility.TransIDGenerator;
import ibase.utility.CommonConstants;
import ibase.ejb.*;
import ibase.system.config.*;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class ManualBankRecoPrc extends ProcessEJB implements  ManualBankRecoPrcLocal,ManualBankRecoPrcRemote //SessionBean
{
	Connection conn = null;
	GenericUtility genericUtility = GenericUtility.getInstance();
	ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
	ConnDriver connDriver = new ConnDriver();
	CommonConstants commonConstants = new CommonConstants();
	ArrayList bankTranList = new ArrayList();
	double totAmt =0.0;
	String bankCode = "";
	String tranType = "";
	String tranDate = "";
	String siteCode = "";
	String tranSer = "";
	String tranNo = "";
	String refNo = "";
	String refDate = "";
	String refMode = "";
	String acctCode = "";
	String cctrCode =  "";
	String	remark = "";
	String tranId = "";
	String amount = "";	
	String	adjAmt = "";
	String chgUser = "";
	String chgTerm = "";
	String currCode = "";
	String sundryCode ="";
	String tranIdBs = "";
	/*public void ejbCreate() throws RemoteException, CreateException
	{
		try
		{
			conn = connDriver.getConnectDB("DriverITM");
			System.out.println("ManualBankRecoPrcEJB ejbCreate called.........");
		}
		catch (Exception e)
		{
			System.out.println("Exception :ManualBankRecoPrcEJB :ejbCreate :==>"+e);
			throw new CreateException();
		} 
	}
	public void ejbRemove()
	{
	}
	public void ejbActivate() 
	{
	}
	public void ejbPassivate() 
	{
	}*/
	public String process() throws RemoteException,ITMException
	{
		return "";
	}
	public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
	{
		Document headerDom = null;
		Document detailDom = null;
		System.out.println("xmlString:::::::::::::;"+ xmlString);
		System.out.println("xmlString2:::::::::::::;"+ xmlString2);
		System.out.println("windowName:::::::::::::;"+ windowName);
		System.out.println("xtraParams:::::::::::::;"+ xtraParams);
		String  rtrStr ="";
		try
		{
			if(xmlString != null && xmlString.trim().length()!=0)
			{
				System.out.println("XML String :"+xmlString);
				headerDom = genericUtility.parseString(xmlString); 				
			}
			if(xmlString2 != null && xmlString2.trim().length()!=0)
			{
				System.out.println("XML String :"+xmlString2);
				detailDom = genericUtility.parseString(xmlString2); 				
			}
			rtrStr = getData(headerDom, detailDom, windowName, xtraParams);
		}
		catch (Exception e)
		{
			System.out.println("Exception :ManualBankRecoPrcEJB :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
			rtrStr = e.getMessage();
		}
		return rtrStr; 
	}//END OF GETDATA(1)
	public String getData(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
	{
		String errCode = "";
		String errString = "";
		String resultString = "";
		String getDataSql= "" ;
		ResultSet rs = null;
		PreparedStatement pstmt = null;
		Connection conn = null;
		StringBuffer retTabSepStrBuff = new StringBuffer();
		try
		{
			conn = connDriver.getConnectDB("DriverITM");
			System.out.println("ManualBankRecoPrcEJB ejbCreate called.........");
		}
		catch (Exception e)
		{
			System.out.println("Exception :ManualBankRecoPrcEJB :ejbCreate :==>"+e);
		} 
		try
		{
			bankCode = genericUtility.getColumnValue("bank_code",headerDom);
			System.out.println("Bankcode>>>>>>>>>>>>>>>>>>>>>>>>>"+bankCode);
			if ( bankCode == null || bankCode.trim().length() == 0 )
			{
				bankCode = "";
				System.out.println("bankCode From is Null...");
				errString = itmDBAccessEJB.getErrorString("","VTMRPPARM","","",conn);
				return errString;
			} 
			getDataSql = " SELECT TRAN_ID,REF_NO,REF_DATE,AMOUNT,CURR_CODE,ENTRY_BATCH_NO,TRAN_TYPE,SUNDRY_CODE,AMT_ADJ,"
						+"TRAN_DATE,REF_MODE,TRAN_SER,TRAN_NO,BANK_CODE,SITE_CODE,ACCT_CODE,CCTR_CODE,STATUS,REMARKS,EXCH_RATE "
						+"  FROM BANKTRAN_LOG  WHERE ( BANK_CODE = ? ) AND(STATUS = 'P' ) OR ( STATUS = 'E' )";
						    
			System.out.println("getDataSql"+getDataSql);
			System.out.println("conn==="+conn);
			pstmt = conn.prepareStatement(getDataSql);
			pstmt.setString(1,bankCode);
			rs = pstmt.executeQuery();
			while(rs.next())
			{
						//TRAN_ID
						retTabSepStrBuff.append(rs.getString(1)).append("\t");
						//REF_NO
			          	retTabSepStrBuff.append(rs.getString(2)).append("\t");
						//REF_DATE
						retTabSepStrBuff.append(rs.getTimestamp(3)).append("\t");
						//AMOUNT
						retTabSepStrBuff.append(rs.getDouble(4)).append("\t");
						//(AMOUNT/EXCHRATE)
						retTabSepStrBuff.append(rs.getDouble(4)/rs.getDouble(20)).append("\t");
						//CURR_CODE
						retTabSepStrBuff.append(rs.getString(5)).append("\t");
						//ENTRY_BATCH_NO
						retTabSepStrBuff.append(rs.getString(6)).append("\t");
						//TRAN_TYPE
						retTabSepStrBuff.append(rs.getString(7)).append("\t");
						//SUNDRY_CODE
						retTabSepStrBuff.append(rs.getString(8)).append("\t");
						//AMT_ADJ
						retTabSepStrBuff.append(rs.getString(9)).append("\t");
						//TRAN_DATE
						retTabSepStrBuff.append(rs.getTimestamp(10)).append("\t");
						//REF_MODE
						retTabSepStrBuff.append(rs.getString(11)).append("\t");
						//TRAN_SER
						retTabSepStrBuff.append(rs.getString(12)).append("\t");
						//TRAN_NO
						retTabSepStrBuff.append(rs.getString(13)).append("\t");
						//BANK_CODE
						retTabSepStrBuff.append(rs.getString(14)).append("\t");
						//SITE_CODE
						retTabSepStrBuff.append(rs.getString(15)).append("\t");
						//ACCT_CODE,,
						retTabSepStrBuff.append(rs.getString(16)).append("\t");
						//CCTR_CODE
						retTabSepStrBuff.append(rs.getString(17)).append("\t");
						//STATUS
						retTabSepStrBuff.append(rs.getString(18)).append("\t");
						//REMARKS
						retTabSepStrBuff.append(rs.getString(19)).append("\t");
						//EXCH_RATE
						retTabSepStrBuff.append(rs.getDouble(20)).append("\t");
						retTabSepStrBuff.append("  ").append("\n"); 
		}
		System.out.println("retTabSepStrBuff:::::::::::::"+retTabSepStrBuff);
		resultString = retTabSepStrBuff.toString();
	}
	catch (SQLException e)
	{
		System.out.println("SQLException :ManualBankRecoPrcEJB :getData(Document headerDom, Document detailDom, String windowName, String xtraParams):" + e.getMessage() + ":");
		throw new ITMException(e);
	}
	catch (Exception e)
	{
		System.out.println("Exception :ManualBankRecoPrcEJB :getData(Document headerDom, Document detailDom, String windowName, String xtraParams):" + e.getMessage() + ":");
		throw new ITMException(e);
	}
	finally
	{
		try
		{
			retTabSepStrBuff = null;
			if(conn != null)
			{					
				if(pstmt != null)
				{
					pstmt.close();
					pstmt=null;
				}
				conn.close();
				conn = null;
			}
		}
		catch(Exception e)
		{
			errString = e.getMessage();
			e.printStackTrace();
			throw new ITMException(e);
		}
	}
		return resultString;	
}//END OF GETDATA(2)
	//PROCESS
	public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
	{
			System.out.println("xmlString::::::::::;;;"+xmlString);
			System.out.println("xmlString2::::::::::;;;"+xmlString2);
			System.out.println("windowName::::::::::;;;"+windowName);
			System.out.println("xtraParams::::::::::;;;"+xtraParams);
			String retStr = "";
			Document detailDom = null;
			Document headerDom = null;
			GenericUtility genericUtility = GenericUtility.getInstance();
			System.out.println("xmlString::::::::::"+xmlString);
			System.out.println("xmlString2::::::::::"+xmlString2);
			System.out.println("below genericUtility:::");
			try
			{	
				if(xmlString != null && xmlString.trim().length()!=0)
				{
					headerDom = genericUtility.parseString(xmlString); 
					System.out.println("headerDom" + headerDom);
				}
				if(xmlString2 != null && xmlString2.trim().length()!=0)
				{
					detailDom = genericUtility.parseString(xmlString2); 
					System.out.println("detailDom" + detailDom);
				}
										
			    retStr = process(headerDom, detailDom, windowName, xtraParams);
			}
			catch (Exception e)
			{
				System.out.println("Exception :StockAllocationPrcEJB :process(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
				e.printStackTrace();
				retStr = e.getMessage();
			}
			return retStr;
		
	}//END OF PROCESS (1)
	public String process(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
	{
	
		NodeList parentNodeList = null;
		NodeList childNodeList = null;
		int parentNodeListLength =0;
		int childNodeListLength = 0;
		String childNodeName = "";
		Node parentNode = null;
		Node childNode = null;
		Connection conn = null;
		ResultSet rs = null;
		ResultSet rs1 = null;
		ResultSet rs2 = null;
		PreparedStatement pstmt = null;
		Statement st = null; 
		String exchRate ="";
		String deductedAmt ="";
		String errString = "";
		ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
		try
		{
			chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
			chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId");
			conn = connDriver.getConnectDB("DriverITM");
			parentNodeList = detailDom.getElementsByTagName("Detail2");
			parentNodeListLength = parentNodeList.getLength(); 
			System.out.println("parentNodeListLength:::::::::"+parentNodeListLength);
			for (int selectedRow = 0; selectedRow < parentNodeListLength; selectedRow++)
			{
				parentNode = parentNodeList.item(selectedRow);
				childNodeList = parentNode.getChildNodes();
				childNodeListLength = childNodeList.getLength();
			//	System.out.println("childNodeListLength::: "+ childNodeListLength);
				for (int childRow = 0; childRow < childNodeListLength; childRow++)
				{
					childNode = childNodeList.item(childRow);
					childNodeName = childNode.getNodeName(); 
					//System.out.println("childNodeName::::::::"+childNodeName);
					if (childNodeName.equals("tran_type"))
					{
						tranType = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("curr_code"))
					{
						currCode = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("tran_date")) 
					{
						tranDate = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("bank_code"))
					{
						bankCode = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("site_code"))
					{
						siteCode = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("tran_ser"))
					{
						tranSer = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("tran_no"))
					{
						tranNo = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("ref_no"))
					{
						refNo = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("ref_date"))
					{
						refDate = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("ref_mode"))
					{
						refMode = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("sundry_code"))
					{
						sundryCode = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("acct_code"))
					{
						acctCode = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("cctr_code"))
					{
						cctrCode = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("remarks"))
					{
						remark = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("tran_id"))
					{
						tranId = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("amount"))
					{
						amount = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("exch_rate"))
					{   
						exchRate = childNode.getFirstChild().getNodeValue();
					}
					if (childNodeName.equals("amt_adj"))
					{
						adjAmt = childNode.getFirstChild().getNodeValue();
					}
				}//INNER FOR LOOP
				HashMap bankTranMap = new HashMap();
				bankTranMap.put("tran_type",tranType); 
				bankTranMap.put("curr_code",currCode);
				bankTranMap.put("tran_date",adjAmt);
				bankTranMap.put("bank_code",bankCode);
				bankTranMap.put("site_code",siteCode);
				bankTranMap.put("tran_no",tranNo);
				bankTranMap.put("tran_ser",bankCode);
				bankTranMap.put("ref_no",refNo);
				bankTranMap.put("ref_date",refDate);
				bankTranMap.put("ref_mode",refMode);
				bankTranMap.put("acct_code",bankCode);
				bankTranMap.put("cctr_code",cctrCode);
				bankTranMap.put("remarks",remark);
				bankTranMap.put("tran_id",tranId);
				bankTranMap.put("amount",amount);
				bankTranMap.put("exch_rate",exchRate);
				bankTranMap.put("amt_adj",adjAmt);
				System.out.println("AMOUNT:::::::::"+amount);
				System.out.println("ADJAMT:::::::::"+adjAmt);
				deductedAmt = new Double(Double.parseDouble(amount)-Double.parseDouble(adjAmt)).toString();
				System.out.println("deductedAmt:::::::::"+deductedAmt);
				bankTranMap.put("deducted_amt",deductedAmt);
				totAmt = totAmt+Double.parseDouble(deductedAmt);
				bankTranList.add(bankTranMap); 
		}
		tranIdBs= generateTranId("W_BANK_STATEMENT",conn);
		System.out.println("Bank Statement Generated tranId !!!!!!!!!!!!!!!!!!!!"+tranIdBs);
		System.out.println("total record selected======"+bankTranList.size());
		insertBankStatement(bankTranList,tranIdBs);
		insertUpdateTraceLog(bankTranList,tranIdBs); 
		}//try end	
		catch(Exception e)
		{
			System.out.println("Exception :FrsDbt CreationPrcEJB :process(String xmlString2, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
			e.printStackTrace();
			throw new ITMException(e);
		} 
		finally
		{
			System.out.println("Closing Connection...."+errString);
			try
			{
				
				if(conn != null)
				{	
				bankTranList.clear();				
					if(pstmt != null)
					{ 
						pstmt.close();
						pstmt=null;
					}
					conn.close();
					conn = null; 
				}
			}
			catch(Exception e)
			{
				errString = e.getMessage();
				e.printStackTrace();
				return errString ;
			}
			if (errString == null || errString.trim().length() == 0)
			{
				errString="VTCOMPL";
				errString = itmDBAccessEJB.getErrorString("",errString,"","",conn);
				return errString;
			}
			else
			{
				errString="VTPRCERR";
				errString = itmDBAccessEJB.getErrorString("",errString,"","",conn);
				return errString;
			}
		}
	}//END OF PROCESS(2)
	//FRR  GENERATION
	
private void insertBankStatement(ArrayList bankTranList,String tranIdBs)  throws ITMException
{
		System.out.println("Inserting a recorg in bank statement .....................");
		PreparedStatement pstmt = null;
		String 	insert = "";
		HashMap bankTranMap = (HashMap)bankTranList.get(0);
		String bankCode = bankTranMap.get("bank_code").toString();
		String siteCode = bankTranMap.get("site_code").toString();
		String refNo = bankTranMap.get("ref_no").toString();
		String refDate = bankTranMap.get("ref_date").toString();
		String refMode = bankTranMap.get("ref_mode").toString();
		String tranType = bankTranMap.get("tran_type").toString();
		//String ediRef = bankTranMap.get("edi_ref").toString();
		String remark = bankTranMap.get("remarks").toString();
		String currCode = bankTranMap.get("curr_code").toString();
		double exchRate = Double.parseDouble(bankTranMap.get("exch_rate").toString());
		java.sql.Timestamp chgDate=  new java.sql.Timestamp(System.currentTimeMillis());
		System.out.println("Insert the following value in bank statement:");
		System.out.println("tranIdBs:::"+tranIdBs);
		System.out.println("totAmt:::"+totAmt);
		System.out.println("bankCode:::"+bankCode);
		System.out.println("siteCode:::"+siteCode);
		System.out.println("refNo:::"+refNo);
		System.out.println("refDate:::"+refDate);
		System.out.println("refMode:::"+refMode);
		System.out.println("tranType:::"+tranType);
		System.out.println("remark:::"+remark);
		System.out.println("currCode:::"+currCode);
		System.out.println("exchRate:::"+exchRate);
		System.out.println("chgUser:::"+chgUser);
		System.out.println("chgTerm:::"+chgTerm);
		try
		{ 
			//String dateToDb = genericUtility.getValidDateString(refDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat());
			//java.sql.Timestamp trefDate=  java.sql.Timestamp.valueOf(refDate + " 00:00:00");
			insert= "INSERT INTO BANK_STATEMENT ( TRAN_ID, BANK_CODE, SITE_CODE, REF_NO, REF_DATE, REF_MODE, AMOUNT, "
				+"  TRAN_TYPE, EDI_REF, REMARKS, STATUS, CHG_DATE, CHG_USER, CHG_TERM,  AMT_ADJ,  AUTO_ENTRY, STATUS_DATE, EXCH_RATE, CURR_CODE )  "
				+"VALUES ( ?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?)" ;
				pstmt = conn.prepareStatement(insert);
				pstmt.setString(1,tranIdBs.trim());
				pstmt.setString(2,bankCode.trim());				
				pstmt.setString(3,siteCode.trim());	
				pstmt.setString(4,refNo.trim());
				pstmt.setTimestamp(5,java.sql.Timestamp.valueOf(refDate.trim()));
				pstmt.setString(6,refMode.trim());
				pstmt.setDouble(7,totAmt);
				pstmt.setString(8,tranType.trim());
				pstmt.setString(9," ");
				pstmt.setString(10,remark.trim());
				pstmt.setString(11,"R");
				pstmt.setTimestamp(12,chgDate);
				pstmt.setString(13,chgUser.trim());
				pstmt.setString(14,chgTerm.trim());
				pstmt.setDouble(15,totAmt);
				pstmt.setString(16,"Y");
				pstmt.setTimestamp(17,chgDate);
				pstmt.setDouble(18,exchRate);
				pstmt.setString(19,currCode.trim());
				pstmt.execute();
				conn.commit();
				pstmt.close();
				System.out.println("Successfully INSERT into BankStatement..................");
		}
		catch(SQLException seinsert)
		{
				System.out.println("SQLException(insert in to in bankStarement) :[Excuting Query Failed ]" + insert + seinsert.getMessage());
				seinsert.printStackTrace();
				throw new ITMException(seinsert);
		}
		catch(Exception exinsert)
		{
			System.out.println("Exception(insert in to in bankStarement) ::"+insert +exinsert.getMessage());
			exinsert.printStackTrace();
			throw new ITMException(exinsert);
			
		}
	}
	private String generateTranId(String windowName,Connection conn)throws ITMException
	{
		Statement stmt = null;
		ResultSet rs = null;
		String sql = "";
		String tranId = "";
		String newKeystring = "";
		 try
	     {
	    	sql = "SELECT KEY_STRING, TRAN_ID_COL, REF_SER FROM TRANSETUP WHERE UPPER(TRAN_WINDOW)= '"+windowName+"'";
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			System.out.println("keyString :"+rs.toString());
			String tranSer1 = "";
			String keyString = "";
			String keyCol = "";
			if (rs.next())
			{
				keyString = rs.getString(1);
				keyCol = rs.getString(2);
				tranSer1 = rs.getString(3);				
			}
			System.out.println("keyString :"+keyString);
			System.out.println("keyCol :"+keyCol);
			System.out.println("tranSer1 :"+tranSer1);
			String xmlValues = "";
			xmlValues ="<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>";
			xmlValues = xmlValues + "<Header></Header>";
			xmlValues = xmlValues + "<Detail1>";
			xmlValues = xmlValues +	"<tran_id></tran_id>";
//			xmlValues = xmlValues + "<site_code>" + siteCode + "</site_code>";
//			xmlValues = xmlValues + "<tran_date>"+ orderDate + "</tran_date>";
			xmlValues = xmlValues + "</Detail1></Root>";
			System.out.println("xmlValues  :["+xmlValues+"]");
			TransIDGenerator tg = new TransIDGenerator(xmlValues, "BASE", commonConstants.DB_NAME);
			tranId = tg.generateTranSeqID(tranSer1, keyCol, keyString, conn);
			System.out.println("tranId :"+tranId);
		}
		catch (SQLException ex)
		{
			System.out.println("Exception ::" +sql+ ex.getMessage() + ":");
			ex.printStackTrace();
			throw new ITMException(ex);
		}
		catch (Exception e)
		{
			System.out.println("Exception ::" + e.getMessage() + ":");
			e.printStackTrace();
			throw new ITMException(e);
		}
		return tranId;
	}//generateTranTd()
	//// INSERTS DATA INTO THE 'BANKRECO_TRACE' AND UPDATES  'BANKTRAN_LOG' 
	private void insertUpdateTraceLog(ArrayList bankTranList,String tranidBs) throws ITMException
	{
		System.out.println("//// inserts data into the 'bankreco_trace' and Updates //////// 'banktran_log' ");
		PreparedStatement pstmt = null;
		PreparedStatement pstmt1 = null;
		HashMap hm = (HashMap)bankTranList.get(0);
		String tranNo = hm.get("tran_no").toString();
		String tranSer = hm.get("tran_ser").toString();
		double exchRate = Double.parseDouble(hm.get("exch_rate").toString());
		String currCode = hm.get("curr_code").toString();
		if(exchRate == 0)
		{
			exchRate= calcExchRate(tranSer,tranNo);
		}
		String bankrecoTracesql = "	INSERT INTO BANKRECO_TRACE ( TRAN_ID__STAT, TRAN_ID__LOG, AMOUNT ) "
		+"VALUES ( ?,?,?)";//:ls_tranidbs, :ls_tranid[ll_cnt], :lc_amt);
		String bankTranLogsql = "UPDATE BANKTRAN_LOG SET STATUS = ?, AMT_ADJ =AMT_ADJ + ?,EXCH_RATE = ?,"
		 +"CURR_CODE = ? WHERE TRAN_ID = ?";
		 try
		 {
		 	pstmt = conn.prepareStatement(bankrecoTracesql);
		 	pstmt1 = conn.prepareStatement(bankTranLogsql);
		 	System.out.println("No of selected record======>>>"+bankTranList.size());
			for(int cnt=0;cnt<bankTranList.size();cnt++)
			{
				hm= (HashMap)bankTranList.get(cnt);
				String tranidBTL = hm.get("tran_id").toString();
				double deductedAmt =  Double.parseDouble(hm.get("deducted_amt").toString());
				System.out.println("bankStatement tranId = "+tranidBs);
				System.out.println("bankTranLog tranId = "+tranidBTL);
				System.out.println("deductedAmt  = "+deductedAmt);
				pstmt.setString(1,tranidBs);
				pstmt.setString(2,tranidBTL);
				pstmt.setDouble(3,deductedAmt);
				pstmt.addBatch();
				pstmt1.setString(1,"R");
				pstmt1.setDouble(2,deductedAmt);
				pstmt1.setDouble(3,exchRate);
				pstmt1.setString(4,currCode);
				pstmt1.setString(5,tranidBTL);
				pstmt1.addBatch();
			}
			pstmt.executeBatch();
			pstmt1.executeBatch();
			pstmt.close();
			pstmt1.close();
		}
		catch (SQLException sx)
		{
			System.out.println("SQLException (insertUpdateTraceLog)::" +bankrecoTracesql+ sx.getMessage() + ":");
			System.out.println("next Exception ========"+sx.getNextException());
			sx.printStackTrace();
			throw new ITMException(sx);
		}
		catch (Exception e)
		{
			System.out.println("Exception (insertUpdateTraceLog) ::" + e.getMessage() + ":");
			e.printStackTrace();
			throw new ITMException(e);
		}
	}
private double 	calcExchRate(String tranSer,String tranNo)throws ITMException
{
	System.out.println("Calculating exchange Rate........");
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	double exchRate = 0.0;
	System.out.println("TranNo::::::"+tranNo);
	System.out.println("TranSer::::::::::"+tranSer);
	// Accepts 2 parameters, and depending upon series and tran no. gets the exch. rate
	String sql ="";
	if(tranSer.equalsIgnoreCase("E-PAY"))
	{
		sql = "select exch_rate  from payment_exp where tran_id = ?";
	}
	else if(tranSer.equalsIgnoreCase("F-XFR"))
	{
		sql = "select  exch_rate   from fundtransfer where tran_id = ?";
	}
	else if(tranSer.equalsIgnoreCase("M-PAY"))
	{
			sql ="select  exch_rate  from misc_payment where tran_id = ?";
	}
	else if(tranSer.equalsIgnoreCase("M-PAY"))
	{	
		sql = "select  exch_rate  from misc_receipt where tran_id = ?" ;
	}
	else if(tranSer.equalsIgnoreCase("MPCANC"))
	{
		sql ="select  exch_rate  from misc_payment_canc where tran_id = ?" ;
	}
	else if(tranSer.equalsIgnoreCase("R-DIS"))
	{
		sql ="select  exch_rate  from rcpdishnr where tran_id = ?"; ;
	}
	else if(tranSer.equalsIgnoreCase("RCP"))
	{
	 sql = "select  exch_rate  from receipt where tran_id = ?" ;
	}
	else if(tranSer.equalsIgnoreCase("E-FUND"))
	{
		sql ="select  exch_rate   from export_fund where tran_id = ?" ;		
	}
	try
	{
		pstmt = conn.prepareStatement(sql);
		rs = pstmt.executeQuery();
		if(rs.next())
		{
			exchRate = rs.getDouble(1);
		}
		pstmt.close();
	}
	catch (SQLException sx11)
	{
		System.out.println("SQLException (calcExchRate)::" +sql+ sx11.getMessage() + ":");
		sx11.printStackTrace();
		throw new ITMException(sx11);
	}
	catch (Exception e11)
	{
		System.out.println("Exception (calcExchRate) ::" + e11.getMessage() + ":");
		e11.printStackTrace();
		throw new ITMException(e11);
	}
	return exchRate;
}

}//END OF EJB