/*
	This EJB is invoked from ActionHandlerService 
*/
package ibase.webitm.ejb.fin;

import ibase.webitm.utility.*;
//import ibase.utility.*;
import ibase.webitm.ejb.*;
import ibase.system.config.*;

import ibase.utility.CommonConstants;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.TransIDGenerator;
import java.rmi.RemoteException;
import java.util.*;
import java.sql.*;
import javax.ejb.*;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class  PayablesOpeningConf  extends ActionHandlerEJB implements PayablesOpeningConfLocal,PayablesOpeningConfRemote // SessionBean
{
	String blankTaxString = null;
	Connection conn = null;
	String userId = "";
	
	GenericUtility genericUtility = GenericUtility.getInstance();
	ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
	
	/*public void ejbCreate() throws RemoteException, CreateException 
	{
		System.out.println("Entering the PayablesOpeningConfEJB................");
	}
	public void ejbRemove()
	{
	}
	public void ejbActivate() 
	{
	}
	public void ejbPassivate() 
	{
	}*/
	
	public String confirm(String tranID,String xtraParams, String forcedFlag) throws RemoteException,ITMException
	{
		String result = "";
		try
		{
			System.out.println("Confirming Payables Opening.......");
			result =  confirmPayablesOpening(tranID,xtraParams);
		}
		catch(Exception e)
		{
			System.out.println("Exception [01]::"+e.getMessage());
			throw new ITMException(e);
		}
		System.out.println("Returning Result ::"+result);
		return result;
	}
	private	String confirmPayablesOpening(String tranID,String xtraParams)throws RemoteException,ITMException
	{
		Statement stmt = null,stmt1 = null,stmtcc = null,stmtUpd = null, stmt2 = null, stmt3 = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null,rscc = null,rsMast = null,rsDtl = null;
		java.sql.Timestamp tranDate = null;	
		java.sql.Timestamp refDate = null;
		java.sql.Timestamp dueDate = null;
		java.sql.Timestamp billDate = null;
		String sqlHdr = "",sqlDtl = "",sql = "",sqlIns = "",sqlUpd = "",update = "",confirmed = "",table = "",column = "";
		String format = "",retString = "",saleOrder ="",keyCol = "",itemCode = "";
		String siteCode = "",finEntity = "",currCode = "",sundryType = "",sundryCode = "",tranSer = "",refNo = "";
		String refType = "",acctCode = "",cctrCode = "",billNo = "",payMode = "",purcOrder = "",entryBatchNo = "";
		double totAmtHdr = 0.0,adjAmtHdr = 0.0,exchRate = 1,totAmount = 0.0,adjAmount = 0.0,suppBillAmt = 0.0,advAmount = 0.0,drAmount = 0.0,crAmount = 0.0,amountDiff = 0.0;
		double crAmtOld = 0d, drAmtOld = 0d, crAmtNew = 0d, drAmtNew = 0d, totAmtOld = 0d;
		String acctPrd = "";
		int cnt = 0,count = 0,updCnt = 0,updInstr = 0;
		HashMap sundrybalMap = new HashMap();
		HashMap acctbalMap = new HashMap();
		String contactCode = "";
		String ls_errcode = "";
		String ls_errcode2 = "";
		
		GenericUtility genericUtility = GenericUtility.getInstance();
		ConnDriver connDriver = new ConnDriver();
		String empCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginEmpCode");
		userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"userId");
		System.out.println("userId ::>"+userId);
		try
		{
			conn = connDriver.getConnectDB("DriverITM");
			conn.setAutoCommit(false);
		}
		catch(Exception ex)
		{
			System.out.println("[Exception :][]"+ex);
			ex.printStackTrace();
		}
			
		// select data from payables_hdr 
		try
		{
			sqlHdr = "SELECT TRAN_DATE,SITE_CODE,FIN_ENTITY,CURR_CODE,TOT_AMT,ADJ_AMT,CONFIRMED, ACCT_PRD FROM PAYABLES_HDR WHERE TRAN_ID ='"+tranID.trim()+"'";	 
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sqlHdr);
			if (rs.next())
			{
				System.out.println("Entering into Header if...................");
				tranDate	= rs.getTimestamp("TRAN_DATE");
				siteCode	= rs.getString("SITE_CODE");
				finEntity	= rs.getString("FIN_ENTITY");
				currCode	= rs.getString("CURR_CODE"); 
				totAmtHdr	= rs.getDouble("TOT_AMT");
				adjAmtHdr	= rs.getDouble("ADJ_AMT");
				confirmed	= rs.getString("CONFIRMED");
				acctPrd		= rs.getString("ACCT_PRD"); //Gulzar 04-12-06
				System.out.println("Tran_Id ::-"+tranID);
			}	
		}//try
		catch(SQLException se)
		{
			System.out.println("SQLException []:[PayablesOpeningConfEJB][Excuting Query Failed]" + sqlHdr + se.getMessage());
		}
		catch(Exception ex)
		{
			System.out.println("Exception []"+ ex.getMessage());
			ex.printStackTrace();
		}
		if(confirmed == null)
		{
			confirmed = "";
		}
		if(confirmed.trim().equalsIgnoreCase("Y"))
		{
			retString =	itmDBAccessEJB.getErrorString("","VTMCONF2","","",conn);
		}
		else
		{
			//select data from payables_dtl 
			try
			{
				sqlDtl = "SELECT SUNDRY_TYPE,SUNDRY_CODE,TRAN_SER,REF_NO,REF_TYPE,ACCT_CODE,CCTR_CODE,"
					   + "EXCH_RATE,DUE_DATE,TOT_AMT,ADJ_AMT,DIFF_AMOUNT,TRAN_DATE,REF_DATE,BILL_NO,"
					   + "BILL_DATE,SUPP_BILL_AMT,PAY_MODE,ADV_AMT,PURC_ORDER,ENTRY_BATCH_NO "
					   + "FROM PAYABLES_DTL WHERE TRAN_ID ='"+tranID+"'";	 
				stmt = conn.createStatement();
				rsDtl = stmt.executeQuery(sqlDtl);
				while (rsDtl.next())
				{	
					System.out.println("Entering into while...................");					
					sundryType = rsDtl.getString("SUNDRY_TYPE");
					sundryCode = rsDtl.getString("SUNDRY_CODE");
					tranSer = rsDtl.getString("TRAN_SER");
					refNo = rsDtl.getString("REF_NO");
					refType = rsDtl.getString("REF_TYPE");
					acctCode = rsDtl.getString("ACCT_CODE");
					cctrCode = rsDtl.getString("CCTR_CODE");
					exchRate = rsDtl.getDouble("EXCH_RATE");
					dueDate = rsDtl.getTimestamp("DUE_DATE");
					totAmount = rsDtl.getDouble("TOT_AMT");
					adjAmount = rsDtl.getDouble("ADJ_AMT");
					amountDiff = rsDtl.getDouble("DIFF_AMOUNT");
					tranDate = rsDtl.getTimestamp("TRAN_DATE");
					refDate = rsDtl.getTimestamp("REF_DATE");
					billNo = rsDtl.getString("BILL_NO");
					billDate = rsDtl.getTimestamp("BILL_DATE");
					suppBillAmt = rsDtl.getDouble("SUPP_BILL_AMT");
					payMode = rsDtl.getString("PAY_MODE");
					advAmount = rsDtl.getDouble("ADV_AMT");
					purcOrder = rsDtl.getString("PURC_ORDER");
					entryBatchNo = rsDtl.getString("ENTRY_BATCH_NO");
					
					try
					{
						sql = "SELECT COUNT(1) AS COUNT  FROM MISC_PAYABLES "
							+ "WHERE TRAN_SER = '"+tranSer.trim()+"' "
							+ "AND REF_NO = '"+refNo.trim()+"' "
							+ "AND SITE_CODE = '"+siteCode.trim() +"'";
						stmt1 = conn.createStatement();
						rsMast = stmt1.executeQuery(sql);
						if (rsMast.next())
						{
							cnt = rsMast.getInt("COUNT");
						}			
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:[PayablesOpeningConfEJB][Excuting Query Failed]" + sql +se.getMessage());
					}
					catch(Exception ex)
					{
							
						System.out.println("Exception []::"+ex.getMessage());
						ex.printStackTrace();
					}
					totAmtOld = 0;//added by nisar on 06/02/08
					//Added by Gulzar 04-12-06
					sql = "SELECT TOT_AMT FROM MISC_PAYABLES "
							+ "WHERE TRAN_SER = '"+ tranSer +"' AND REF_NO = '"+ refNo +"' AND SITE_CODE = '"+ siteCode +"'";
					
					stmt2 = conn.createStatement();
					rs = stmt2.executeQuery(sql);
					
					if (rs.next())
					{
						totAmtOld = rs.getDouble("TOT_AMT");
					}
					rs.close();
					amountDiff = totAmount - totAmtOld;
					System.out.println("amountDiff = totAmount - totAmtOld : " + amountDiff);
					if (totAmtOld < 0)
					{
						drAmtOld = totAmtOld *(-1);
						crAmtOld = 0d;
					}
					else
					{
						drAmtOld = 0d;
						crAmtOld = totAmtOld;
					}
					if (totAmount < 0)
					{
						drAmtNew = totAmount *(-1);
						crAmtNew = 0d;
					}
					else
					{
						drAmtNew = 0d;
						crAmtNew = totAmount;
					}
					stmt2.close();
					drAmount = drAmtNew - drAmtOld;
					crAmount = crAmtNew - crAmtOld;
					System.out.println("drAmount = drAmtNew - drAmtOld : " + drAmount);
					System.out.println("crAmount = crAmtNew - crAmtOld : " + crAmount);
					//End Added Gulzar 01-12-06

					if (cnt == 0)
					{
						try
						{
							//Added by Gulzar For TranId Generation - 04-12-06 /////
							String keyString = "",payblsTranID = "";
							sql = "SELECT KEY_STRING FROM TRANSETUP WHERE TRAN_WINDOW = 'T_PAYABLES'"; 
							
							stmt3 = conn.createStatement();
							rs = stmt3.executeQuery(sql);
							if(rs.next())
							{
								keyString = rs.getString("KEY_STRING");
							}
							rs.close();
							String XMLString = "<?xml version=\"1.0\"?>\r\n<Root>\r\n<header>"+
							"\r\n</header><Detail1>"+
							"\r\n<site_code>"+siteCode+"</site_code>\r\n<tran_date>"+tranDate+"</tran_date></Detail1></Root>";
							
							CommonConstants.setIBASEHOME();
							TransIDGenerator tg = new TransIDGenerator(XMLString, userId, CommonConstants.DB_NAME); //FOR DB2
						
							//payblsTranID = tg.generateTranSeqID("M-PABL", "tran_id", keyString, conn);//Commented by jaimin on 23/07/2008 (FI89PHE008)
							payblsTranID = tg.generateTranSeqID("PAYL", "tran_id", keyString, conn);//Added by jaimin on 23/07/2008 (FI89PHE008)

							System.out.println("Transaction Id Generated for Payables :"+payblsTranID);
							//End Added Gulzar 04-12-06//
							System.out.println("Inside try of (cnt == 0)........");
							
							sqlIns = "INSERT INTO MISC_PAYABLES (TRAN_ID,TRAN_SER,TRAN_DATE,REF_NO,REF_DATE,"
								   + "BILL_NO,BILL_DATE,CURR_CODE,EXCH_RATE,SUNDRY_CODE,ACCT_CODE,CCTR_CODE,"
								   + "DUE_DATE,SITE_CODE,FIN_ENTITY,TOT_AMT,ADJ_AMT,SUNDRY_TYPE,PAY_MODE,"
								   + "ADV_AMT,PURC_ORDER,ENTRY_BATCH_NO,REF_TYPE,SUPP_BILL_AMT,STATUS,STATUS_DATE) "
							   	   + "VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							
							pstmt = conn.prepareStatement(sqlIns);
							//pstmt.setString(1,tranID);//Gulzar 04-12-06
							pstmt.setString(1,payblsTranID.trim()); //Gulzar 04-12-06
							pstmt.setString(2,tranSer.trim());
							//pstmt.setTimestamp(3,tranDate);
							pstmt.setTimestamp(3,new java.sql.Timestamp(System.currentTimeMillis()));
							pstmt.setString(4,refNo.trim());
							pstmt.setTimestamp(5,refDate);
							pstmt.setString(6,billNo.trim());
							pstmt.setTimestamp(7,billDate);
							pstmt.setString(8,currCode.trim());
							pstmt.setDouble(9,exchRate);
							pstmt.setString(10,sundryCode.trim());
							pstmt.setString(11,acctCode.trim());
							pstmt.setString(12,cctrCode.trim());
							pstmt.setTimestamp(13,dueDate);
							pstmt.setString(14,siteCode.trim());
							pstmt.setString(15,finEntity.trim());
							pstmt.setDouble(16,totAmount);
							pstmt.setDouble(17,adjAmount);
							pstmt.setString(18,sundryType.trim());
							pstmt.setString(19,payMode);
							pstmt.setDouble(20,advAmount);
							pstmt.setString(21,purcOrder);
							pstmt.setString(22,entryBatchNo);
							pstmt.setString(23,refType.trim());
							pstmt.setDouble(24,suppBillAmt);
							pstmt.setString(25,"U");
							//pstmt.setTimestamp(26,tranDate);
							pstmt.setTimestamp(26,new java.sql.Timestamp(System.currentTimeMillis()));
						
							pstmt.executeUpdate();
							System.out.println("INSERT QUERY EXECUTED.................................");
						}//try
						catch(SQLException se)
						{
							System.out.println("SQLException [10][confirmReceivables][Excuting Query Failed]" + sqlIns + se.getMessage());
							try
							{
								conn.rollback();	
							}
							catch(Exception e)
							{
								System.out.println("Exception In Rollback Transaction");
							}
							se.printStackTrace();
							retString = se.getMessage();
							return retString;
						}
						catch(Exception e)
						{
							System.out.println("Exception [11][confirmPayablesOpening][Excuting Query Failed]" + sqlIns + e.getMessage());
							e.printStackTrace();
							retString = e.getMessage();
							return retString;
						}
						finally
						{
							try
							{
								pstmt.close();
								pstmt = null;
								stmt3.close();
								
							}
							catch(Exception e)
							{
								System.out.println("Exception [12][confirmPayablesOpening]" + sqlIns + e.getMessage());
								e.printStackTrace();
								retString = e.getMessage();	
								return retString;
							}
						}
					
					}//if
						
					//Record found in misc_payables
					else
					{
						System.out.println("RECORD FOUND IN MASTER, UPDATE IS IN PROGRESS...........");
						try
						{
							sqlUpd = "UPDATE MISC_PAYABLES SET TRAN_SER = ?,TRAN_DATE = ?, REF_DATE = ?, BILL_NO = ?, " +
									 "BILL_DATE = ?,CURR_CODE = ?, EXCH_RATE = ?,SUNDRY_CODE = ?,ACCT_CODE = ?,CCTR_CODE = ?, " +
									 "DUE_DATE = ?, FIN_ENTITY = ?,TOT_AMT = TOT_AMT + ( ? ), ADJ_AMT = ?,STATUS = ?,STATUS_DATE = ?, SUNDRY_TYPE = ?,PAY_MODE = ?, " +
									 "ADV_AMT = ?,  PURC_ORDER = ?, ENTRY_BATCH_NO = ?, REF_TYPE = ?, SUPP_BILL_AMT = ? "+
									 "WHERE TRAN_SER = '"+ tranSer.trim() +"' AND REF_NO = '"+ refNo.trim() +"' AND SITE_CODE = '"+ siteCode.trim() +"'";
									  
							pstmt = conn.prepareStatement(sqlUpd);
							//pstmt.setString(1,tranID.trim());
							pstmt.setString(1,tranSer.trim());
							//pstmt.setTimestamp(3,tranDate);
							pstmt.setTimestamp(2,new java.sql.Timestamp(System.currentTimeMillis()));
							pstmt.setTimestamp(3,refDate);
							pstmt.setString(4,billNo.trim());
							pstmt.setTimestamp(5,billDate);
							pstmt.setString(6,currCode.trim());
							pstmt.setDouble(7,exchRate);
							pstmt.setString(8,sundryCode.trim());
							pstmt.setString(9,acctCode.trim());
							pstmt.setString(10,cctrCode.trim());
							pstmt.setTimestamp(11,dueDate);
							pstmt.setString(12,finEntity.trim());
							pstmt.setDouble(13,amountDiff);
							pstmt.setDouble(14,adjAmount);
							pstmt.setString(15,"U");
							pstmt.setTimestamp(16,new java.sql.Timestamp(System.currentTimeMillis()));
							//pstmt.setTimestamp(17,tranDate);
							pstmt.setString(17,sundryType.trim());
							pstmt.setString(18,payMode);
							pstmt.setDouble(19,advAmount);
							pstmt.setString(20,purcOrder);
							pstmt.setString(21,entryBatchNo);
							pstmt.setString(22,refType);
							pstmt.setDouble(23,suppBillAmt);
			
							System.out.println("Setting Twenty Four Fields ..........24");
							updInstr = pstmt.executeUpdate();	
							System.out.println("QUERY !!!!!!!!!------"+	sqlUpd);		
							System.out.println("QUERY EXECUTED::UPDATE MASTER .........:: "+ updInstr);		
						}//try
						catch(SQLException se)
						{
							System.out.println("SQLException [10][confirmPayablesOpening][Excuting Query Failed]" + sqlUpd + se.getMessage());
							try
							{
								conn.rollback();	
							}
							catch(Exception e)
							{
								System.out.println("Exception In Rollback Transaction");
							}
							se.printStackTrace();
							retString = se.getMessage();
							return retString;
						}
						catch(Exception e)
						{
							System.out.println("Exception [11][confirmPayablesOpening][Excuting Query Failed]" + sqlUpd + e.getMessage());
							e.printStackTrace();
							retString = e.getMessage();
							return retString;
						}
						finally
						{
							try
							{
								pstmt.close();
								pstmt = null;
								
							}
							catch(Exception e)
							{
								System.out.println("Exception [12][confirmPayablesOpening]" + sqlUpd + e.getMessage());
								e.printStackTrace();
								retString = e.getMessage();	
								return retString;
							}
						}
					
					}//else
					
					//Inserting || Updating in SUNDRYBAL......
					System.out.println("Inserting || Updating in SUNDRYBAL...(((((((*))))))...");
					tranDate = new  java.sql.Timestamp(System.currentTimeMillis());
					System.out.println("xxxxxxxx CURRENT DATE xxxxxxxxxxx "+tranDate);
					sundrybalMap.put("tran_date",tranDate);
					sundrybalMap.put("fin_entity",finEntity.trim());
					sundrybalMap.put("site_code",siteCode.trim());
					sundrybalMap.put("sundry_type",sundryType.trim());
					sundrybalMap.put("sundry_code",sundryCode.trim());
					sundrybalMap.put("acct_code",acctCode.trim());
					sundrybalMap.put("cctr_code",cctrCode);
					sundrybalMap.put("curr_code",currCode.trim());
					sundrybalMap.put("acct_prd",acctPrd.trim()); //Gulzar 04-12-06
					
					if (sundryType.equals("C"))
					{
						table = "CUSTOMER";
						column = "CUST_CODE";
					}
					else if(sundryType.equals("B"))
					{
						table = "BANK";
						column = "BANK_CODE";
					}
					else if(sundryType.equals("E"))
					{
						table = "EMPLOYEE";
						column = "EMP_CODE";
					}
					else if(sundryType.equals("P"))
					{
						table = "SALES_PERS";
						column = "SALES_PERS";
					}
					else if(sundryType.equals("T"))
					{
						table = "TRANSPORTER";
						column = "TRAN_CODE";
					}
					else if(sundryType.equals("S"))
					{
						table = "SUPPLIER";
						column = "SUPP_CODE";
					}
					else if(sundryType.equals("L"))
					{
						table = "LOANPARTY";
						column = "PARTY_CODE";
					}
					try
					{
						sql = "SELECT CONTACT_CODE FROM "+table+" WHERE "+column+" = '"+sundryCode.trim()+"'";
						stmtcc = conn.createStatement();
						rscc = stmtcc.executeQuery(sql);
						if(rscc.next())
						{
							contactCode = rscc.getString(1);
						}
						
					}
					catch(SQLException se)
					{
						System.out.println("SQLException []:[PayablesOpeningConfEJB][Excuting Query Failed]" +sql+ se.getMessage());
					}			
					sundrybalMap.put("contact_code",contactCode);
					sundrybalMap.put("exch_rate",new Double(exchRate));
					/* --Commented By Gulzar 04-12-06
					if (amountDiff<0)
					{
						drAmount = amountDiff;
					}
					else 
					{
						crAmount = amountDiff;
					}*///End Comment Gulzar 04-12-06
					sundrybalMap.put("dr_amt",new Double(drAmount));
					sundrybalMap.put("cr_amt",new Double(crAmount));
					sundrybalMap.put("adv_amt",new Double(advAmount));
					FinCommon finCommon = new FinCommon();
					//ls_errcode = finCommon.gbf_sundrybal_upd(sundrybalMap,conn);//Gulzar 04-12-06
					ls_errcode = finCommon.sundrybalOpnUpd(sundrybalMap,conn);//Gulzar 04-12-06
					sundrybalMap.clear();//Gulzar 04-12-06
					System.out.println("Error Code........"+ls_errcode);
					if(ls_errcode.trim().length()>0)
					{
						retString = itmDBAccessEJB.getErrorString("", "ls_errcode", userId);
						break;
					}
					System.out.println("RETURN FROM SUNDRYBAL ENTRIES");
					
					//Inserting || Updating in ACCTBAL........
					System.out.println("Inserting || Updating in ACCTBAL...(((((((*))))))...");
					acctbalMap.put("contact_code",contactCode);
					acctbalMap.put("tran_date",tranDate);
					acctbalMap.put("eff_date",tranDate);
					acctbalMap.put("fin_entity",finEntity.trim());
					acctbalMap.put("site_code",siteCode.trim());
					acctbalMap.put("acct_code",acctCode.trim());
					acctbalMap.put("cctr_code",cctrCode);
					acctbalMap.put("curr_code",currCode.trim());
					acctbalMap.put("emp_code",empCode.trim());
					acctbalMap.put("user_id",userId.trim());
					acctbalMap.put("exch_rate",new Double(exchRate));
					acctbalMap.put("dr_amt",new Double(drAmount));
					acctbalMap.put("cr_amt",new Double(crAmount));
					acctbalMap.put("acct_prd",acctPrd.trim()); //Gulzar 04-12-06

					//ls_errcode2 = finCommon.gbf_acctbal_upd(acctbalMap,conn); //Gulzar 04-12-06
					ls_errcode2 = finCommon.acctbalOpnUpd(acctbalMap,conn);//Gulzar 04-12-06
					acctbalMap.clear(); //Gulzar 04-12-06
					if(ls_errcode2.trim().length()>0)
					{
						break;
					}
					System.out.println("RETURN FROM ACCTBAL ENTRIES");
					//conn.commit(); //Gulzar 04-12-06
				}//while
				try
				{
					System.out.println("emp code:="+empCode);
					update = "UPDATE PAYABLES_HDR SET CONFIRMED = 'Y', CONF_DATE = ? ,EMP_CODE__APRV = ? where TRAN_ID = ?";
					System.out.println("Confirm update SQL ::"+ update);
					pstmt = conn.prepareStatement(update);
					pstmt.setTimestamp(1,new java.sql.Timestamp(System.currentTimeMillis()));
					pstmt.setString(2,empCode);
					pstmt.setString(3,tranID);
					updCnt = pstmt.executeUpdate();	
					System.out.println("No of PAYABLES_HDR records updated ::*> "+updCnt);	
					if (updCnt == 1)
					{
						System.out.println("PAYABLES_HDR Updated...(Confirmed)" + userId);
						conn.commit();						
						retString = itmDBAccessEJB.getErrorString("","VTMCONF2",userId);
						System.out.println("Ret String: " + retString);
					}
					else
					{
						System.out.println("PAYABLES_HDR Not Updated...(Not Confirmed)");
					}
				}	
				catch(SQLException se)
				{
					System.out.println("SQLException [][Excuting Query Failed]" + update + se.getMessage());
					se.printStackTrace();
					conn.rollback();//Gulzar 04-12-06
					retString = se.getMessage();
					return retString;
				}
				catch(Exception e)
				{
					retString = "Not Confirmed";
					conn.rollback();
					System.out.println("Exception[17] ::"+e.getMessage());
					e.printStackTrace();
					retString = "Not Confirmed :" + e.getMessage();
				}
				finally
				{
					try
					{
						if(pstmt != null)
						{
							pstmt.close();
							pstmt = null;
						}
						if(conn != null)
						{
							System.out.println("Closing Connection......");
							conn = null;
						}
					}
					catch(SQLException se)
					{
						System.out.println("SQLException [18] Connection Error Closed :" + se.getMessage());
						se.printStackTrace();
						retString = "Connection Not Closed :" + se.getMessage();
						return retString;
					}
				}//finally
			}//try
			catch(SQLException se)
			{
				System.out.println("SQLException []:[PayablesOpeningConfEJB][Excuting Query Failed]" + sqlDtl + se.getMessage());
				se.printStackTrace();
			}
			catch(Exception ex1)
			{
				try
				{
					conn.rollback();	
				}
				catch(Exception ex)
				{
				}
				retString = "Not Confirmed";
				System.out.println("Exception []::"+ex1.getMessage());
				ex1.printStackTrace();
				throw new ITMException(ex1);
			}
			finally
			{
				try
				{
					System.out.println("Closing Connection......");
					if (rsDtl != null )
					{
						rsDtl.close();
						rsDtl = null;
					}
					if (stmt != null)
					{
						stmt.close();
						stmt = null;
					}
					if (conn != null)
					{
						conn.close();
						conn = null;
					}
				}
				catch(Exception e)
				{
					System.out.println("Exception [20][confirmReceivables]" + sqlHdr + e.getMessage());
					e.printStackTrace();
					retString = e.getMessage();
					return retString;
				}
			}//finally
			/*-- Commented Gulzar - Gulzar 04-12-06
			if(updCnt > 0)
			{
				
				retString =	itmDBAccess.getErrorString("","VTMCONF2","","",conn);//confirmed
			}
			else
			{
				retString =	itmDBAccess.getErrorString("","VTCREDIT01","","",conn);//not confirmed
			}
			*///End Comment Gulzar 04-12-06
		}//most outer else	
		System.out.println("retString ::"+retString);
		return retString;	
	}//confirm()
}//class