package ibase.webitm.ejb.dis.adv;

import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.ejb.Stateless;

import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.ejb.fin.CreatePoRcpVoucher;
import ibase.webitm.ejb.fin.FinCommon;

import ibase.webitm.utility.ITMException;

@Stateless

public class CreateVoucherAct extends ActionHandlerEJB implements CreateVoucherActLocal,CreateVoucherActRemote
{
	E12GenericUtility genericUtility = new  E12GenericUtility();
	FinCommon finCommon = new FinCommon();
	DistCommon distCommon = new DistCommon();
	ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
	String  retString = "";
	public String actionHandler(String tranId,String xtraParams, String forcedFlag) throws RemoteException, ITMException
	{
		PreparedStatement pstmt = null, pstmt1 = null, pstmtUpd = null;
		ResultSet rs = null, rs1 = null;
		Connection conn = null;boolean connStatus=false;
		try
		{
            
            if (conn == null)// changed by Gulzar - 25/11/11
			{
            	System.out.println("New Connection Created***");
				ConnDriver connDriver = null;
				connDriver = new ConnDriver();
				conn = connDriver.getConnectDB("DriverITM");
				conn.setAutoCommit(false);
				connDriver = null;
				connStatus = true;
			}
			System.out.println("Calling......actionHandler for Common Voucher");
			CreatePoRcpVoucher createVouc = new CreatePoRcpVoucher();
			retString = createVouc.createPoRcpVoucher(tranId,
					xtraParams, conn);
		}//try
		catch(Exception exception)
		{   try {
			conn.rollback();
		} catch (Exception e1) {
		}
			exception.printStackTrace();
			throw new ITMException(exception);
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
				if (conn != null && !conn.isClosed() && connStatus) // Gulzar -
					// 25/11/11
                   {
                     conn.close();
                     conn = null;
                   }
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		
		
		return retString;
	}
	
}
