package ibase.webitm.ejb.fin;

import java.sql.*;
import java.text.*;
import ibase.utility.CommonConstants;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.*;
import java.util.HashMap;
import ibase.webitm.ejb.*;
import org.w3c.dom.*;
public class FinCommon
{
	ValidatorEJB validator = new ValidatorEJB();
	public String sundrybalOpnUpd(HashMap sundrybalMap, Connection conn)throws ITMException
	{
		String sql = "";
		String sqlnstr = "";
		String sqlUpd = "";
		ResultSet rs = null;
		Statement stmt = null;
		PreparedStatement pstmt = null;
		java.sql.Timestamp postdate =  null;
		String closePrd = "zzzzzz";
		String cctrCode  = "";
		String errCode = "";
		String currCode = "";
		String contactCode = "";
		String prdCode = "000000"; //Gulzar 30/11/06
		int count =0;
		int sundrybalCnt = 0;
		double ll_cnt = 0.0;
		double exchRate = 0.0;
		double drAmount = 0.0;
		double crAmount = 0.0;
		double advAmount = 0.0;
		double crAmtBase = 0.0;
		double drAmtBase = 0.0;

		try
		{
			System.out.println("In SUNDRY-BAL !!!!!!!!!!!!!!!!!!!!!!!!!!");
			stmt = conn.createStatement();
			java.sql.Timestamp ld_postdate = java.sql.Timestamp.valueOf((sundrybalMap.get("tran_date").toString()));
			String finEntity  = (String)sundrybalMap.get("fin_entity");
			String siteCode   = (String)sundrybalMap.get("site_code");
			String sundryType = (String)sundrybalMap.get("sundry_type");
			String sundryCode = (String)sundrybalMap.get("sundry_code");
			String acctCode   = (String)sundrybalMap.get("acct_code");
			String acctPrd	  = (String)sundrybalMap.get("acct_prd"); //Gulzar 30/11/06
			String userId	  = (String)sundrybalMap.get("user_id"); //Gulzar 30/11/06
			java.sql.Timestamp chgDate = new java.sql.Timestamp(System.currentTimeMillis());

			String sundCctrUpd = getFinparams("999999","SUND_UPD_CCTR",conn);
			if(sundCctrUpd.trim().equals("NULLFOUND"))
			{
				errCode = "VSENVAR1";
	            return (errCode);
			}
			else if((!sundCctrUpd.trim().equalsIgnoreCase("Y")) && (!sundCctrUpd.trim().equalsIgnoreCase("N")))
			{
				errCode = "VTFINPARM1";
				return (errCode);
			}
			else if (sundCctrUpd.trim().equalsIgnoreCase("Y"))
			{
				cctrCode = (String)sundrybalMap.get("cctr_code");
			}
			else
			{
				cctrCode  = "    ";
			}
			currCode    = (String)sundrybalMap.get("curr_code");
			contactCode = (String)sundrybalMap.get("contact_code");
			exchRate  	= ((Double)sundrybalMap.get("exch_rate")).doubleValue();
			drAmount 	= ((Double)sundrybalMap.get("dr_amt")).doubleValue();
			crAmount 	= ((Double)sundrybalMap.get("cr_amt")).doubleValue();
			advAmount 	= ((Double)sundrybalMap.get("adv_amt")).doubleValue();

			if (exchRate == 0)
			{
				errCode = "VTEXRAT1";
				return (errCode);
			}

			crAmtBase = crAmount * exchRate;
			drAmtBase = drAmount * exchRate;

			if (contactCode == null)
			{
				contactCode = "";
			}
			while (true)
			{
				try
				{
					// check for period 000000
					sql = "SELECT COUNT(1) FROM SUNDRYBAL "
						+ "WHERE ACCT_PRD = '"+ acctPrd +"' AND PRD_CODE = '"+ prdCode +"' AND FIN_ENTITY = '"+ finEntity +"' "
						+ "AND SITE_CODE = '"+ siteCode +"' AND SUNDRY_TYPE = '"+ sundryType +"' AND SUNDRY_CODE = '"+ sundryCode +"' "
						+ "AND ACCT_CODE = '"+ acctCode +"' AND CCTR_CODE = '"+ cctrCode +"'";

					rs = stmt.executeQuery(sql);
					if (rs.next())
					{
						sundrybalCnt = rs.getInt(1);
					}
					System.out.println("For Opening Prd : sundrybalCnt : " + sundrybalCnt);
					stmt.close(); stmt = null;
					rs.close(); rs = null;
				}//try
				catch(SQLException se)
				{
					System.out.println("SQLException []:sundrybalOpnUpd()[Excuting Query Failed]" + sql +se.getMessage());
				}
				if (sundrybalCnt == 0)
				{
					try
					{
						// add record for period 000000
						sqlnstr = "INSERT INTO SUNDRYBAL ( ACCT_PRD, PRD_CODE, FIN_ENTITY, SITE_CODE, SUNDRY_TYPE, "
			      				+ "SUNDRY_CODE, ACCT_CODE, CCTR_CODE, CR_AMT, DR_AMT, CURR_CODE__AC, CR_AMT__BASE, "
			      				+ "DR_AMT__BASE, ADV_AMT, CONTACT_CODE, CHG_DATE, CHG_USER, CHG_TERM ) "
			      				+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )";

			      		pstmt = conn.prepareStatement(sqlnstr);
						pstmt.setString(1,acctPrd);
						pstmt.setString(2,prdCode);
						pstmt.setString(3,finEntity);
						pstmt.setString(4,siteCode);
						pstmt.setString(5,sundryType);
						pstmt.setString(6,sundryCode);
						pstmt.setString(7,acctCode);
						pstmt.setString(8,cctrCode);
						pstmt.setDouble(9,crAmount);
						pstmt.setDouble(10,drAmount);
						pstmt.setString(11,currCode);
						pstmt.setDouble(12,crAmtBase);
						pstmt.setDouble(13,drAmtBase);
						pstmt.setDouble(14,advAmount);
						pstmt.setString(15,contactCode);
						pstmt.setTimestamp(16,chgDate);
						pstmt.setString(17,userId);
						pstmt.setString(18,userId);

						count = pstmt.executeUpdate();
						if(count < 1)
					 	{
							errCode = "DS000 : Insert Into SUNDRYBAL Failed";
							System.out.println("DS000 : Insert Into SUNDRYBAL Failed For Period : " +prdCode);
							break;
					 	}
						pstmt.close(); pstmt = null;  // ADDED BY ALKA
						System.out.println("NO. OF RECORDS INSERTED FOR CURRENT PERIODE.. "+count);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:sundrybalOpnUpd()[Excuting Query Failed]" + sqlnstr +se.getMessage());
					}
				}//if
				else
				{
					try
					{
						// update existing record ( also update advance )
						sqlUpd = "UPDATE SUNDRYBAL SET CR_AMT = (CR_AMT + ( ? )), DR_AMT = (DR_AMT + ( ? )), "
							   + "CR_AMT__BASE = (CR_AMT__BASE + ( ? )),DR_AMT__BASE = (DR_AMT__BASE + ( ? )),"
							   + "ADV_AMT = (ADV_AMT + ( ? )),CHG_DATE = ? ,CHG_USER = ? ,CHG_TERM = ? "
							   + "WHERE ACCT_PRD = '"+ acctPrd +"' AND PRD_CODE = '"+ prdCode +"' AND FIN_ENTITY = '"+ finEntity +"' "
							   + "AND SITE_CODE = '"+ siteCode +"' AND SUNDRY_TYPE = '"+ sundryType +"' AND SUNDRY_CODE = '"+ sundryCode +"' "
							   + "AND ACCT_CODE = '"+ acctCode +"' AND CCTR_CODE = '"+ cctrCode +"'";

						pstmt = conn.prepareStatement(sqlUpd);
						pstmt.setDouble(1,crAmount);
						pstmt.setDouble(2,drAmount);
						pstmt.setDouble(3,crAmtBase);
						pstmt.setDouble(4,drAmtBase);
						pstmt.setDouble(5,advAmount);
						pstmt.setTimestamp(6,chgDate);
						pstmt.setString(7,userId);
						pstmt.setString(8,userId);
						count = pstmt.executeUpdate();
						if(count < 1)
					 	{
							errCode = "DS000";
							System.out.println("DS000 : Update SUNDRYBAL Failed For Period : " +prdCode);
							break;
					 	}
						pstmt.close(); pstmt = null; // ADDED BY ALKA
						System.out.println("NO. OF RECORDS UPDATED FOR CURRENT PERIODE... "+count);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:sundrybalOpnUpd()[Excuting Query Failed]" + sqlUpd +se.getMessage());
					}
				}//else
				try
				{
					if (sundrybalCnt != 0)
					{
						// check for closing balance
						sql = "SELECT COUNT(1) FROM SUNDRYBAL "
							+ "WHERE ACCT_PRD = '"+ acctPrd +"' AND PRD_CODE = '"+ closePrd +"' AND FIN_ENTITY = '"+ finEntity +"' "
							+ "AND SITE_CODE = '"+ siteCode +"' AND SUNDRY_TYPE = '"+ sundryType +"' AND SUNDRY_CODE = '"+ sundryCode +"' "
							+ "AND ACCT_CODE = '"+ acctCode +"' AND CCTR_CODE = '"+ cctrCode +"'";
						stmt = conn.createStatement();
						rs = stmt.executeQuery(sql);
						if (rs.next())
						{
							sundrybalCnt = rs.getInt(1);
						}
						stmt.close(); stmt = null;
						rs.close(); rs = null;
						System.out.println("For Closing Prd : sundrybalCnt : " + sundrybalCnt);
					}
				}//try
				catch(SQLException se)
				{
					System.out.println("SQLException []:sundrybalOpnUpd()[Excuting Query Failed]" + sql +se.getMessage());
				}
				if (sundrybalCnt == 0	)
				{
					try
					{
						// add record for closing period
						sqlnstr = "INSERT INTO SUNDRYBAL ( ACCT_PRD, PRD_CODE, FIN_ENTITY, SITE_CODE, SUNDRY_TYPE, "
			      				+ "SUNDRY_CODE, ACCT_CODE, CCTR_CODE, CR_AMT, DR_AMT, CURR_CODE__AC, CR_AMT__BASE, "
			      				+ "DR_AMT__BASE, ADV_AMT, CONTACT_CODE, CHG_DATE, CHG_USER, CHG_TERM ) "
			      				+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )";

			      		pstmt = conn.prepareStatement(sqlnstr);
						pstmt.setString(1,acctPrd);
						pstmt.setString(2,closePrd);
						pstmt.setString(3,finEntity);
						pstmt.setString(4,siteCode);
						pstmt.setString(5,sundryType);
						pstmt.setString(6,sundryCode);
						pstmt.setString(7,acctCode);
						pstmt.setString(8,cctrCode);
						pstmt.setDouble(9,crAmount);
						pstmt.setDouble(10,drAmount);
						pstmt.setString(11,currCode);
						pstmt.setDouble(12,crAmtBase);
						pstmt.setDouble(13,drAmtBase);
						pstmt.setDouble(14,advAmount);
						pstmt.setString(15,contactCode);
						pstmt.setTimestamp(16,chgDate);
						pstmt.setString(17,userId);
						pstmt.setString(18,userId);

						count = pstmt.executeUpdate();
						if(count < 1)
					 	{
							errCode = "DS000";
							System.out.println("DS000 : Insert Into SUNDRYBAL Failed For Period : " +prdCode);
							break;
					 	}
						pstmt.close(); pstmt = null; // ADDED BY ALKA
						System.out.println("NO. OF RECORDS INSERTED FOR CLOSING PERIODE.. "+count);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:sundrybalOpnUpd()[Excuting Query Failed]" + sqlnstr +se.getMessage());
					}
				}//if
				else
				{
					try
					{
						// update existing record ( also update advance )
						sqlUpd = "UPDATE SUNDRYBAL SET CR_AMT = (CR_AMT + ( ? )), DR_AMT = (DR_AMT + ( ? )), "
							   + "CR_AMT__BASE = (CR_AMT__BASE + ( ? )),DR_AMT__BASE = (DR_AMT__BASE + ( ? )),"
							   + "ADV_AMT = (ADV_AMT + ( ? )),CHG_DATE = ? ,CHG_USER = ? ,CHG_TERM = ? "
							   + "WHERE ACCT_PRD = '"+ acctPrd +"' AND PRD_CODE = '"+ closePrd +"' AND FIN_ENTITY = '"+ finEntity +"' "
							   + "AND SITE_CODE = '"+ siteCode +"' AND SUNDRY_TYPE = '"+ sundryType +"' AND SUNDRY_CODE = '"+ sundryCode +"' "
							   + "AND ACCT_CODE = '"+ acctCode +"' AND CCTR_CODE = '"+ cctrCode +"'";

						pstmt = conn.prepareStatement(sqlUpd);
						pstmt.setDouble(1,crAmount);
						pstmt.setDouble(2,drAmount);
						pstmt.setDouble(3,crAmtBase);
						pstmt.setDouble(4,drAmtBase);
						pstmt.setDouble(5,advAmount);
						pstmt.setTimestamp(6,chgDate);
						pstmt.setString(7,userId);
						pstmt.setString(8,userId);
						count = pstmt.executeUpdate();
						if(count < 1)
					 	{
							errCode = "DS000";
							System.out.println("DS000 : Update SUNDRYBAL Failed For Period : " +closePrd);
							break;
					 	}
						pstmt.close(); pstmt = null; // ADDED BY ALKA
						System.out.println("NO. OF RECORDS UPDATED FOR CLOSING PERIODE... "+count);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:sundrybalOpnUpd()[Excuting Query Failed]" + sqlUpd +se.getMessage());
					}
				}//else
				break;
			}//while
		}//try
		catch(Exception exception)
		{   System.out.println("Exception ::(MAIN).sundrybalOpnUpd():" + exception.getMessage() + ":");
			exception.printStackTrace();
			throw new ITMException(exception);
		}
		finally
		{
			try
			{
				sundrybalMap.clear();
				// ADDED BY ALKA
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
				// END ADDED BY ALKA
			}
			catch(Exception e)
			{
				System.out.println("Exception ::sundrybalOpnUpd():" + e.getMessage() + ":");
				e.printStackTrace();
			}
		}
	    return (errCode);
	}//sundrybalOpnUpd()

	public String acctbalOpnUpd(HashMap acctbalMap, Connection conn)throws ITMException
	{
		String retString = "";
		String sql=null;
		ResultSet rs = null;
		Statement stmt = null;
		PreparedStatement pstmt = null;
		String ls_errcode  = "";
		String prdCode  = "000000";
		String closePrd ="zzzzzz";
		String refSer="";
		String insertSql = null;
		int q =0;
		int count = 0;
		double lc_dramt_base = 0;
		double lc_cramt_base =0;
		int ll_cnt = 0;
		double lc_dramt = 0;
		double lc_cramt = 0;
		double lc_advamt = 0;
		double lc_cramt_b = 0;
		double lc_dramt_b = 0;

		try
		{
			stmt = conn.createStatement();
			String acctVar_contactcode = (String)acctbalMap.get("contact_code");
			String acctVar_finentity   = (String)acctbalMap.get("fin_entity");
			String acctVar_sitecode    = (String)acctbalMap.get("site_code");
			String acctVar_acctcode    = (String)acctbalMap.get("acct_code");
			String acctVar_cctrcode    = (String)acctbalMap.get("cctr_code");
			String acctVar_currcode    = (String)acctbalMap.get("curr_code");
			String acctVar_empcode     = (String)acctbalMap.get("emp_code");
			String userId  			   = (String)acctbalMap.get("user_id");
			String acctPrd			   = (String)acctbalMap.get("acct_prd");
			if (acctVar_cctrcode == null)
			{
				acctVar_cctrcode = "    ";
			}
			java.sql.Timestamp ld_postdate  	= java.sql.Timestamp.valueOf(acctbalMap.get("tran_date").toString());
			java.sql.Timestamp acctVar_trandate = java.sql.Timestamp.valueOf(acctbalMap.get("tran_date").toString());
			java.sql.Timestamp acctVar_effdate  = java.sql.Timestamp.valueOf(acctbalMap.get("eff_date").toString());
			java.sql.Timestamp chgDate = new java.sql.Timestamp(System.currentTimeMillis());

			double acctVar_exchrate    = ((Double)acctbalMap.get("exch_rate")).doubleValue();
			double acctVar_dramt	   = ((Double)acctbalMap.get("dr_amt")).doubleValue();
			double acctVar_cramt	   = ((Double)acctbalMap.get("cr_amt")).doubleValue();

			System.out.println("acctbalMap :: " + acctbalMap);
			System.out.println("acctVar_dramt :: " + acctVar_dramt);
			System.out.println("acctVar_cramt :: " + acctVar_cramt);

			//lc_dramt_base = Math.round(acctVar_dramt); // it is same as dr_amt_base as exchg rate is 1
			//lc_cramt_base = Math.round(acctVar_cramt);
			System.out.println("acctVar_effdate:" + acctVar_effdate);

			lc_cramt_b = acctVar_cramt * acctVar_exchrate;
			lc_dramt_b = acctVar_dramt * acctVar_exchrate;

			System.out.println("lc_cramt_b :: " + lc_cramt_b);
			System.out.println("lc_dramt_b :: " + lc_dramt_b);
			if (acctVar_contactcode == null)
			{
				acctVar_contactcode = "";
			}
			while (true)
			{
				try
				{
					// check for current period
					sql ="SELECT COUNT(1) FROM ACCTBAL WHERE ACCT_PRD = '"+acctPrd+"' AND PRD_CODE ='"+prdCode+"' AND "+
						 "FIN_ENTITY = '"+acctVar_finentity+"' AND SITE_CODE ='"+acctVar_sitecode+"' AND ACCT_CODE = '"+acctVar_acctcode+"' "+
						 "AND CCTR_CODE ='"+acctVar_cctrcode+"'";
					stmt = conn.createStatement();
					rs = stmt.executeQuery(sql);
					if (rs.next())
					{
						ll_cnt = rs.getInt(1);
					}
					stmt.close(); stmt = null;
					rs.close(); rs = null;
					System.out.println("For Period 000000 ll_cnt : " + ll_cnt);
				}//try
				catch(SQLException se)
				{
					System.out.println("SQLException []:acctbalOpnUpd()[Excuting Query Failed]" + sql +se.getMessage());
					se.printStackTrace();
					retString = se.getMessage();
					return retString;
				}
				if (ll_cnt == 0	)
				{
					try
					{
						// add record for current period
						sql="INSERT INTO ACCTBAL (ACCT_PRD, PRD_CODE, FIN_ENTITY, SITE_CODE,"+
							"ACCT_CODE, CCTR_CODE, CURR_CODE__AC, DR_AMT, CR_AMT,"+
							"DR_AMT__BASE, CR_AMT__BASE, CHG_DATE, CHG_USER, CHG_TERM)  "+
							"VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,? )";
						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1,acctPrd);
						pstmt.setString(2,prdCode);
						pstmt.setString(3,acctVar_finentity);
						pstmt.setString(4,acctVar_sitecode);
						pstmt.setString(5,acctVar_acctcode);
						pstmt.setString(6,acctVar_cctrcode);
						pstmt.setString(7,acctVar_currcode);
						pstmt.setDouble(8,acctVar_dramt);
						pstmt.setDouble(9,acctVar_cramt);
						pstmt.setDouble(10,lc_dramt_b);
						pstmt.setDouble(11,lc_cramt_b);
						//pstmt.setTimestamp(12,acctVar_effdate);//Gulzar 01-12-06
						pstmt.setTimestamp(12,chgDate); //Gulzar 01-12-06
						pstmt.setString(13,userId);
						pstmt.setString(14,userId);
						int cnt = pstmt.executeUpdate();
						pstmt.close(); pstmt = null; // ADDED BY ALKA
						System.out.println("INSERTED IN ACCTBAL FOR CURRENT PERIODE : " + cnt);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:acctbalOpnUpd()[Excuting Query Failed]" + sql +se.getMessage());
						se.printStackTrace();
						retString = se.getMessage();
						return retString;
					}
				}
				else
				{
					try
					{
						// update existing record ( also update advance )
						sql="UPDATE ACCTBAL SET DR_AMT = (DR_AMT + ( ? )), CR_AMT = (CR_AMT + ( ? )), DR_AMT__BASE = (DR_AMT__BASE + ( ? )), CR_AMT__BASE = (CR_AMT__BASE + ( ? )), CHG_DATE = ?, CHG_USER = ?, CHG_TERM = ? "+
							"WHERE ACCT_PRD = '"+acctPrd+"' AND PRD_CODE = '"+prdCode+"' AND "+
							"FIN_ENTITY = '"+acctVar_finentity+"' AND SITE_CODE = '"+acctVar_sitecode+"' AND "+
							"ACCT_CODE = '"+acctVar_acctcode+"' AND CCTR_CODE = '"+acctVar_cctrcode+"'";
						pstmt = conn.prepareStatement(sql);
						pstmt.setDouble(1,acctVar_dramt);
						pstmt.setDouble(2,acctVar_cramt);
						pstmt.setDouble(3,lc_dramt_b);
						pstmt.setDouble(4,lc_cramt_b);
						pstmt.setTimestamp(5,chgDate); //Gulzar 01-12-06
						pstmt.setString(6,userId); //Gulzar 01-12-06
						pstmt.setString(7,userId); //Gulzar 01-12-06
						count = pstmt.executeUpdate();
						pstmt.close(); pstmt = null; // ADDED BY ALKA
						System.out.println("NO. OF RECORDS UPDATED IN ACCTBAL...(CURRENT) :"+count);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:acctbalOpnUpd()[Excuting Query Failed]" + sql +se.getMessage());
						se.printStackTrace();
						retString = se.getMessage();
						return retString;
					}
				}
				try
				{
					if(ll_cnt > 0)
					{
						// check for closing balance
						sql="SELECT COUNT(1) FROM ACCTBAL WHERE ACCT_PRD = '"+acctPrd+"'AND PRD_CODE ='"+closePrd+"' AND "+
							" FIN_ENTITY ='"+acctVar_finentity+"' AND SITE_CODE = '"+acctVar_sitecode+"' AND ACCT_CODE = '"+acctVar_acctcode+"' AND CCTR_CODE = '"+acctVar_cctrcode+"'";

						System.out.println("Closing count sql [" + sql + "]");
						System.out.println("Closing acctPrd [" + acctPrd + "]");
						System.out.println("Closing closePrd [" + closePrd + "]");
						System.out.println("Closing acctVar_finentity [" + acctVar_finentity + "]");
						System.out.println("Closing acctVar_sitecode [" + acctVar_sitecode + "]");
						System.out.println("Closing acctVar_acctcode [" + acctVar_acctcode + "]");
						System.out.println("Closing acctVar_cctrcode [" + acctVar_cctrcode + "]");
						stmt = conn.createStatement();
						rs = stmt.executeQuery(sql);
						if (rs.next())
						{
							ll_cnt = rs.getInt(1);
						}
						stmt.close(); stmt = null;
						rs.close(); rs = null;
						System.out.println("For Period zzzzzz ll_cnt : " + ll_cnt);
					}
				}//try

				catch(SQLException se)
				{
					System.out.println("SQLException []:acctbalOpnUpd()[Excuting Query Failed]" + sql +se.getMessage());
					se.printStackTrace();
					retString = se.getMessage();
					return retString;
				}
				if(ll_cnt == 0)
				{
					// insert a record for closing balance
					sql="INSERT INTO ACCTBAL (ACCT_PRD, PRD_CODE, FIN_ENTITY, SITE_CODE,ACCT_CODE, CCTR_CODE, CURR_CODE__AC, DR_AMT, CR_AMT,"+
						" DR_AMT__BASE, CR_AMT__BASE, CHG_DATE, CHG_USER, CHG_TERM)"+
						" VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,? )";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1,acctPrd);
					pstmt.setString(2,closePrd);
					pstmt.setString(3,acctVar_finentity);
					pstmt.setString(4,acctVar_sitecode);
					pstmt.setString(5,acctVar_acctcode);
					pstmt.setString(6,acctVar_cctrcode);
					pstmt.setString(7,acctVar_currcode);
					pstmt.setDouble(8,acctVar_dramt);
					pstmt.setDouble(9,acctVar_cramt);
					pstmt.setDouble(10,lc_dramt_b);
					pstmt.setDouble(11,lc_cramt_b);
					//pstmt.setTimestamp(12,acctVar_effdate); //Gulzar 01-12-06
					pstmt.setTimestamp(12,chgDate); //Gulzar 01-12-06
					pstmt.setString(13,userId);
					pstmt.setString(14,userId);
					int cnt = pstmt.executeUpdate();
					pstmt.close(); pstmt = null; // ADDED BY ALKA
					System.out.println("INSERTED IN ACCTBAL FOR CLOSING BALANCE : " + cnt);
					 if(cnt<1)
					 {
						ls_errcode = "DS000";
						break;
					 }
				}
				else
				{
					// update closing in acctbal
					sql="UPDATE ACCTBAL SET DR_AMT = (DR_AMT + ( ? )), CR_AMT = (CR_AMT + ( ? )), DR_AMT__BASE = (DR_AMT__BASE + ( ? )), CR_AMT__BASE = (CR_AMT__BASE + ( ? )), CHG_DATE = ?, CHG_USER = ?, CHG_TERM = ? "+
						"WHERE ACCT_PRD = '"+acctPrd+"' AND PRD_CODE = '"+closePrd+"' AND "+
						"FIN_ENTITY = '"+acctVar_finentity+"'AND SITE_CODE ='"+acctVar_sitecode+"'AND "+
						"ACCT_CODE = '"+acctVar_acctcode+"' AND CCTR_CODE = '"+acctVar_cctrcode+"'";

					pstmt = conn.prepareStatement(sql);
					pstmt.setDouble(1,acctVar_dramt);
					pstmt.setDouble(2,acctVar_cramt);
					pstmt.setDouble(3,lc_dramt_b);
					pstmt.setDouble(4,lc_cramt_b);
					pstmt.setTimestamp(5,chgDate); //Gulzar 01-12-06
					pstmt.setString(6,userId); //Gulzar 01-12-06
					pstmt.setString(7,userId); //Gulzar 01-12-06
					int cnt = pstmt.executeUpdate();
					pstmt.close(); pstmt = null; // ADDED BY ALKA
    				System.out.println("NO. OF RECORDS UPDATED IN ACCTBAL...(CLOSING)" + cnt);
					 if(cnt<1)
					{
						ls_errcode = "DS000";
						break;
					}
				}
				break;
			}
		}//try
		catch(SQLException se)
		{
			System.out.println("SQLException []: :acctbalOpnUpd():" + sql + " : : " + se.getMessage() + ":");
			se.printStackTrace();
			retString = se.getMessage();
			return retString;
		}
		catch(Exception e)
		{
			System.out.println("Exception []::acctbalOpnUpd():" + e.getMessage() + ":");
			e.printStackTrace();
			retString = e.getMessage();
			throw new ITMException(e);
		}

		finally
		{
			try
			{
				acctbalMap.clear();
//				ADDED BY ALKA
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
//				 END ADDED BY ALKA
			}
			catch(Exception e)
			{
				System.out.println("Exception []:acctbalOpnUpd():" + e.getMessage() + ":");
				e.printStackTrace();
				retString = e.getMessage();
				return retString;
			}
		}
	return retString;
	}//acctbalOpnUpd()

	public String gbf_sundrybal_upd(HashMap sundrybalMap, Connection conn)throws ITMException
	{
		String sql = "";
		String sqlnstr = "";
		String sqlUpd = "";
		ResultSet rs = null;
		Statement stmt = null;
		PreparedStatement pstmt = null;
		java.sql.Timestamp postdate =  null;
		String ls_openprd = "000000";
		String ls_closeprd = "zzzzzz";
		String userId = "";
		String ls_cctrcode  = "";
		String ls_acctprd = "";
		String ls_prdcode = "";
		String ls_errcode = "";
		String ls_currcode = "";
		String ls_contactcode = "";
		int count =0;
		double ll_cnt = 0.0;
		double lc_exchrate = 0.0;
		double lc_dramt = 0.0;
		double lc_cramt = 0.0;
		double lc_advamt = 0.0;
		double lc_cramt_b = 0.0;
		double lc_dramt_b = 0.0;

		try
		{
			System.out.println("In SUNDRY-BAL !!!!!!!!!!!!!!!!!!!!!!!!!!");
			stmt = conn.createStatement();
			java.sql.Timestamp ld_postdate = java.sql.Timestamp.valueOf((sundrybalMap.get("tran_date").toString()));
			String ls_finentity  = (String)sundrybalMap.get("fin_entity");
			String ls_sitecode   = (String)sundrybalMap.get("site_code");
			String ls_sundrytype = (String)sundrybalMap.get("sundry_type");
			String ls_sundrycode = (String)sundrybalMap.get("sundry_code");
			String ls_acctcode   = (String)sundrybalMap.get("acct_code");

			String ls_cctr_upd = getFinparams("999999","SUND_UPD_CCTR",conn);
			if(ls_cctr_upd.trim().equals("NULLFOUND"))
			{
				ls_errcode = "VSENVAR1";
	            return (ls_errcode);
			}
			else if((!ls_cctr_upd.trim().equalsIgnoreCase("Y")) && (!ls_cctr_upd.trim().equalsIgnoreCase("N")))
			{
				ls_errcode = "VTFINPARM1";
				return (ls_errcode);
			}
			else if (ls_cctr_upd.trim().equalsIgnoreCase("Y"))
			{
				ls_cctrcode = (String)sundrybalMap.get("cctr_code");
			}
			else
			{
				ls_cctrcode  = "    ";
			}
			ls_currcode    = (String)sundrybalMap.get("curr_code");
			ls_contactcode = (String)sundrybalMap.get("contact_code");
			lc_exchrate  = ((Double)sundrybalMap.get("exch_rate")).doubleValue();
			lc_dramt = ((Double)sundrybalMap.get("dr_amt")).doubleValue();
			lc_cramt = ((Double)sundrybalMap.get("cr_amt")).doubleValue();
			lc_advamt = ((Double)sundrybalMap.get("adv_amt")).doubleValue();

			if (lc_exchrate == 0)
			{
				ls_errcode = "VTEXRAT1";
				return (ls_errcode);
			}

			lc_cramt_b = lc_cramt * lc_exchrate;
			lc_dramt_b = lc_dramt * lc_exchrate;

			if (ls_contactcode == null)
			{
				ls_contactcode = "";
			}
			while (true)
			{
				try
				{
					sql = "SELECT ACCT_PRD, CODE FROM PERIOD WHERE FR_DATE <= ? AND TO_DATE >= ?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setTimestamp(1,ld_postdate);
					pstmt.setTimestamp(2,ld_postdate);
					rs  = pstmt.executeQuery();
					if(!rs.next())
					{	ls_errcode = "VMDATANF";
						break;
					}
					else
					{
						ls_acctprd = rs.getString(1);
						ls_prdcode = rs.getString(2);
					}
					pstmt.close(); pstmt = null; // ADDED BY ALKA
					rs.close(); rs = null;
				}//try
				catch(SQLException se)
				{
					System.out.println("SQLException []:gbf_sundrybal_upd()[Excuting Query Failed]" + sql +se.getMessage());
				}
				try
				{
					// look for opening balance record
					sql = "SELECT COUNT(1) FROM SUNDRYBAL "
						+ "WHERE ACCT_PRD = '"+ ls_acctprd +"' AND PRD_CODE = '"+ ls_openprd +"' AND FIN_ENTITY = '"+ ls_finentity +"' "
						+ "AND SITE_CODE = '"+ ls_sitecode +"' AND SUNDRY_TYPE = '"+ ls_sundrytype +"' AND SUNDRY_CODE = '"+ ls_sundrycode +"' "
						+ "AND ACCT_CODE = '"+ ls_acctcode +"' AND CCTR_CODE = '"+ ls_cctrcode +"'";

					rs = stmt.executeQuery(sql);
					if (rs.next())
					{
						ll_cnt = rs.getInt(1);
					}
					stmt.close(); stmt = null;
					rs.close(); rs = null;
					if (ll_cnt == 0	)
					{
						try
						{
							// add record for opening balance
							sqlnstr = "INSERT INTO SUNDRYBAL ( ACCT_PRD, PRD_CODE, FIN_ENTITY, SITE_CODE, SUNDRY_TYPE, "
		      						+ "SUNDRY_CODE, ACCT_CODE, CCTR_CODE, CR_AMT, DR_AMT, CURR_CODE__AC, CR_AMT__BASE, "
		      						+ "DR_AMT__BASE, ADV_AMT, CONTACT_CODE, CHG_DATE, CHG_USER, CHG_TERM ) "
		      						+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )";

							pstmt = conn.prepareStatement(sqlnstr);
							pstmt.setString(1,ls_acctprd);
							pstmt.setString(2,ls_openprd);
							pstmt.setString(3,ls_finentity);
							pstmt.setString(4,ls_sitecode);
							pstmt.setString(5,ls_sundrytype);
							pstmt.setString(6,ls_sundrycode);
							pstmt.setString(7,ls_acctcode);
							pstmt.setString(8,ls_cctrcode);
							pstmt.setDouble(9,0);
							pstmt.setDouble(10,0);
							pstmt.setString(11,ls_currcode);
							pstmt.setDouble(12,0);
							pstmt.setDouble(13,0);
							pstmt.setDouble(14,0);
							pstmt.setString(15,ls_contactcode);
							pstmt.setTimestamp(16,ld_postdate);
							pstmt.setString(17,userId);
							pstmt.setString(18,userId);

							count = pstmt.executeUpdate();
							pstmt.close(); pstmt = null; // ADDED BY ALKA
							if(count<1)
						 	{
								ls_errcode = "DS000";
								break;
						 	}
							System.out.println("NO. OF RECORDS INSERTED FOR OPENING PERIODE.. "+count);
						}//try
						catch(SQLException se)
						{
							System.out.println("SQLException []:gbf_sundrybal_upd()[Excuting Query Failed]" + sqlnstr +se.getMessage());
						}
					}//if
				}//outer try
				catch(SQLException se)
				{
					System.out.println("SQLException []:gbf_sundrybal_upd()[Excuting Query Failed]" + sql +se.getMessage());
				}

				try
				{
					// check for current period
					sql = "SELECT COUNT(1) FROM SUNDRYBAL "
						+ "WHERE ACCT_PRD = '"+ ls_acctprd +"' AND PRD_CODE = '"+ ls_prdcode +"' AND FIN_ENTITY = '"+ ls_finentity +"' "
						+ "AND SITE_CODE = '"+ ls_sitecode +"' AND SUNDRY_TYPE = '"+ ls_sundrytype +"' AND SUNDRY_CODE = '"+ ls_sundrycode +"' "
						+ "AND ACCT_CODE = '"+ ls_acctcode +"' AND CCTR_CODE = '"+ ls_cctrcode +"'";

					stmt = conn.createStatement(); // Added as stmt is closed and asigned null above - Piyush - 26/03/08
					rs = stmt.executeQuery(sql);
					if (rs.next())
					{
						ll_cnt = rs.getInt(1);
					}
					stmt.close(); stmt = null;
					rs.close(); rs = null;
				}//try
				catch(SQLException se)
				{
					System.out.println("SQLException []:gbf_sundrybal_upd()[Excuting Query Failed]" + sql +se.getMessage());
				}
				if (ll_cnt == 0	)
				{
					try
					{
						// add record for current period
						sqlnstr = "INSERT INTO SUNDRYBAL ( ACCT_PRD, PRD_CODE, FIN_ENTITY, SITE_CODE, SUNDRY_TYPE, "
			      				+ "SUNDRY_CODE, ACCT_CODE, CCTR_CODE, CR_AMT, DR_AMT, CURR_CODE__AC, CR_AMT__BASE, "
			      				+ "DR_AMT__BASE, ADV_AMT, CONTACT_CODE, CHG_DATE, CHG_USER, CHG_TERM ) "
			      				+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )";

			      		pstmt = conn.prepareStatement(sqlnstr);
						pstmt.setString(1,ls_acctprd);
						pstmt.setString(2,ls_prdcode);
						pstmt.setString(3,ls_finentity);
						pstmt.setString(4,ls_sitecode);
						pstmt.setString(5,ls_sundrytype);
						pstmt.setString(6,ls_sundrycode);
						pstmt.setString(7,ls_acctcode);
						pstmt.setString(8,ls_cctrcode);
						pstmt.setDouble(9,lc_cramt);
						pstmt.setDouble(10,lc_dramt);
						pstmt.setString(11,ls_currcode);
						pstmt.setDouble(12,lc_cramt_b);
						pstmt.setDouble(13,lc_dramt_b);
						pstmt.setDouble(14,lc_advamt);
						pstmt.setString(15,ls_contactcode);
						pstmt.setTimestamp(16,ld_postdate);
						pstmt.setString(17,userId);
						pstmt.setString(18,userId);

						count = pstmt.executeUpdate();
						pstmt.close(); pstmt = null; // ADDED BY ALKA
						if(count<1)
					 	{
							ls_errcode = "DS000";
							break;
					 	}
						System.out.println("NO. OF RECORDS INSERTED FOR CURRENT PERIODE.. "+count);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:gbf_sundrybal_upd()[Excuting Query Failed]" + sqlnstr +se.getMessage());
					}
				}//if
				else
				{
					try
					{
						// update existing record ( also update advance )
						sqlUpd = "UPDATE SUNDRYBAL SET CR_AMT = (CR_AMT + ( ? )), DR_AMT = (DR_AMT + ( ? )), "
							   + "CR_AMT__BASE = (CR_AMT__BASE + ( ? )),DR_AMT__BASE = (DR_AMT__BASE + ( ? )),"
							   + "ADV_AMT = (ADV_AMT + ( ? )),CHG_DATE = ? ,CHG_USER = ? ,CHG_TERM = ? "
							   + "WHERE ACCT_PRD = '"+ ls_acctprd +"' AND PRD_CODE = '"+ ls_prdcode +"' AND FIN_ENTITY = '"+ ls_finentity +"' "
							   + "AND SITE_CODE = '"+ ls_sitecode +"' AND SUNDRY_TYPE = '"+ ls_sundrytype +"' AND SUNDRY_CODE = '"+ ls_sundrycode +"' "
							   + "AND ACCT_CODE = '"+ ls_acctcode +"' AND CCTR_CODE = '"+ ls_cctrcode +"'";

						pstmt = conn.prepareStatement(sqlUpd);
						pstmt.setDouble(1,lc_cramt);
						pstmt.setDouble(2,lc_dramt);
						pstmt.setDouble(3,lc_cramt_b);
						pstmt.setDouble(4,lc_dramt_b);
						pstmt.setDouble(5,lc_advamt);
						pstmt.setTimestamp(6,ld_postdate);
						pstmt.setString(7,userId);
						pstmt.setString(8,userId);
						count = pstmt.executeUpdate();
						pstmt.close(); pstmt = null; // ADDED BY ALKA
						if(count<1)
					 	{
							ls_errcode = "DS000";
							break;
					 	}
						System.out.println("NO. OF RECORDS UPDATED FOR CURRENT PERIODE... "+count);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:gbf_sundrybal_upd()[Excuting Query Failed]" + sqlUpd +se.getMessage());
					}
				}//else
				try
				{
					// check for closing balance
					sql = "SELECT COUNT(1) FROM SUNDRYBAL "
						+ "WHERE ACCT_PRD = '"+ ls_acctprd +"' AND PRD_CODE = '"+ ls_closeprd +"' AND FIN_ENTITY = '"+ ls_finentity +"' "
						+ "AND SITE_CODE = '"+ ls_sitecode +"' AND SUNDRY_TYPE = '"+ ls_sundrytype +"' AND SUNDRY_CODE = '"+ ls_sundrycode +"' "
						+ "AND ACCT_CODE = '"+ ls_acctcode +"' AND CCTR_CODE = '"+ ls_cctrcode +"'";

					stmt = conn.createStatement(); // Added as stmt is closed and asigned null above - Piyush - 26/03/08
					rs = stmt.executeQuery(sql);
					if (rs.next())
					{
						ll_cnt = rs.getInt(1);
					}
					stmt.close(); stmt = null;
					rs.close(); rs = null;
				}//try
				catch(SQLException se)
				{
					System.out.println("SQLException []:gbf_sundrybal_upd()[Excuting Query Failed]" + sql +se.getMessage());
				}
				if (ll_cnt == 0	)
				{
					try
					{
						// add record for closing period
						sqlnstr = "INSERT INTO SUNDRYBAL ( ACCT_PRD, PRD_CODE, FIN_ENTITY, SITE_CODE, SUNDRY_TYPE, "
			      				+ "SUNDRY_CODE, ACCT_CODE, CCTR_CODE, CR_AMT, DR_AMT, CURR_CODE__AC, CR_AMT__BASE, "
			      				+ "DR_AMT__BASE, ADV_AMT, CONTACT_CODE, CHG_DATE, CHG_USER, CHG_TERM ) "
			      				+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )";

			      		pstmt = conn.prepareStatement(sqlnstr);
						pstmt.setString(1,ls_acctprd);
						pstmt.setString(2,ls_closeprd);
						pstmt.setString(3,ls_finentity);
						pstmt.setString(4,ls_sitecode);
						pstmt.setString(5,ls_sundrytype);
						pstmt.setString(6,ls_sundrycode);
						pstmt.setString(7,ls_acctcode);
						pstmt.setString(8,ls_cctrcode);
						pstmt.setDouble(9,lc_cramt);
						pstmt.setDouble(10,lc_dramt);
						pstmt.setString(11,ls_currcode);
						pstmt.setDouble(12,lc_cramt_b);
						pstmt.setDouble(13,lc_dramt_b);
						pstmt.setDouble(14,lc_advamt);
						pstmt.setString(15,ls_contactcode);
						pstmt.setTimestamp(16,ld_postdate);
						pstmt.setString(17,userId);
						pstmt.setString(18,userId);

						count = pstmt.executeUpdate();
						if(count<1)
					 	{
							ls_errcode = "DS000";
							break;
					 	}
						System.out.println("NO. OF RECORDS INSERTED FOR CLOSING PERIODE.. "+count);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:gbf_sundrybal_upd()[Excuting Query Failed]" + sqlnstr +se.getMessage());
					}
				}//if
				else
				{
					try
					{
						// update existing record ( also update advance )
						sqlUpd = "UPDATE SUNDRYBAL SET CR_AMT = (CR_AMT + ( ? )), DR_AMT = (DR_AMT + ( ? )), "
							   + "CR_AMT__BASE = (CR_AMT__BASE + ( ? )),DR_AMT__BASE = (DR_AMT__BASE + ( ? )),"
							   + "ADV_AMT = (ADV_AMT + ( ? )),CHG_DATE = ? ,CHG_USER = ? ,CHG_TERM = ? "
							   + "WHERE ACCT_PRD = '"+ ls_acctprd +"' AND PRD_CODE = '"+ ls_closeprd +"' AND FIN_ENTITY = '"+ ls_finentity +"' "
							   + "AND SITE_CODE = '"+ ls_sitecode +"' AND SUNDRY_TYPE = '"+ ls_sundrytype +"' AND SUNDRY_CODE = '"+ ls_sundrycode +"' "
							   + "AND ACCT_CODE = '"+ ls_acctcode +"' AND CCTR_CODE = '"+ ls_cctrcode +"'";

						pstmt = conn.prepareStatement(sqlUpd);
						pstmt.setDouble(1,lc_cramt);
						pstmt.setDouble(2,lc_dramt);
						pstmt.setDouble(3,lc_cramt_b);
						pstmt.setDouble(4,lc_dramt_b);
						pstmt.setDouble(5,lc_advamt);
						pstmt.setTimestamp(6,ld_postdate);
						pstmt.setString(7,userId);
						pstmt.setString(8,userId);
						count = pstmt.executeUpdate();
						if(count<1)
					 	{
							ls_errcode = "DS000";
							break;
					 	}
						System.out.println("NO. OF RECORDS UPDATED FOR CLOSING PERIODE... "+count);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:gbf_sundrybal_upd()[Excuting Query Failed]" + sqlUpd +se.getMessage());
					}
				}//else
				break;
			}//while
		}//try
		catch(Exception exception)
		{   System.out.println("Exception ::(MAIN).gbf_sundrybal_upd():" + exception.getMessage() + ":");
			exception.printStackTrace();
			throw new ITMException(exception);
		}
		finally
		{
			try
			{
				//commented by chandni 14-sep
				//sundrybalMap.clear();
//				ADDED BY ALKA
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
//				 END ADDED BY ALKA
			}
			catch(Exception e)
			{
				System.out.println("Exception ::gbf_sundrybal_upd():" + e.getMessage() + ":");
				e.printStackTrace();
			}
		}
	    return (ls_errcode);
	}//gbf_sundrybal_upd()


	public String gbf_acctbal_upd(HashMap acctbalMap, Connection conn)throws ITMException
	{
		String retString = "";
		String sql=null;
		ResultSet rs = null;
		Statement stmt = null;
		PreparedStatement pstmt = null;
		String ls_errcode  = "";
		String ls_openprd  = "000000";
		String ls_closeprd ="zzzzzz";
		String refSer="";
		String insertSql = null;
		String ls_acctprd = null;
		String ls_prdcode = null;
		String ls_prd_code = null;
		int q =0;
		int count = 0;
		double lc_dramt_base = 0;
		double lc_cramt_base =0;
		double ll_cnt = 0;
		double lc_dramt = 0;
		double lc_cramt = 0;
		double lc_advamt = 0;
		double lc_cramt_b = 0;
		double lc_dramt_b = 0;

		try
		{
			stmt = conn.createStatement();
			String acctVar_contactcode = (String)acctbalMap.get("contact_code");
			String acctVar_finentity   = (String)acctbalMap.get("fin_entity");
			String acctVar_sitecode    = (String)acctbalMap.get("site_code");
			String acctVar_acctcode    = (String)acctbalMap.get("acct_code");
			String acctVar_cctrcode    = (String)acctbalMap.get("cctr_code");
			String acctVar_currcode    = (String)acctbalMap.get("curr_code");
			String acctVar_empcode     = (String)acctbalMap.get("emp_code");
			String userId  			   = (String)acctbalMap.get("user_id");
			java.sql.Timestamp ld_postdate  	= java.sql.Timestamp.valueOf(acctbalMap.get("tran_date").toString());
			java.sql.Timestamp acctVar_trandate = java.sql.Timestamp.valueOf(acctbalMap.get("tran_date").toString());
			java.sql.Timestamp acctVar_effdate  = java.sql.Timestamp.valueOf(acctbalMap.get("eff_date").toString());

			double acctVar_exchrate    = ((Double)acctbalMap.get("exch_rate")).doubleValue();
			double acctVar_dramt	   = ((Double)acctbalMap.get("dr_amt")).doubleValue();
			double acctVar_cramt	   = ((Double)acctbalMap.get("cr_amt")).doubleValue();

			//lc_dramt_base = Math.round(acctVar_dramt); // it is same as dr_amt_base as exchg rate is 1
			//lc_cramt_base = Math.round(acctVar_cramt);
			System.out.println("acctVar_effdate:" + acctVar_effdate);

			lc_cramt_b = acctVar_cramt * acctVar_exchrate;
			lc_dramt_b = acctVar_dramt * acctVar_exchrate;
			if (acctVar_contactcode == null)
			{
				acctVar_contactcode = "";
			}
			while (true)
			{
				try
				{
					sql = "SELECT ACCT_PRD, CODE FROM PERIOD WHERE FR_DATE <= ? AND TO_DATE >= ?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setTimestamp(1,ld_postdate);
					pstmt.setTimestamp(2,ld_postdate);
					rs  = pstmt.executeQuery();
					if(!rs.next())
					{
						ls_errcode = "VMDATANF";
						break;
					}
					else
					{
						ls_acctprd = rs.getString(1);
						ls_prdcode = rs.getString(2);
					}
					rs.close(); rs = null;
					System.out.println("ls_acctprd +++++++++++++++++++++++++ "+ls_acctprd);
				}
				catch(SQLException se)
				{
					System.out.println("SQLException []:gbf_acctbal_upd()[Excuting Query Failed]" + sql +se.getMessage());
					se.printStackTrace();
					retString = se.getMessage();
					return retString;
				}
				// update acctbal
				// check for existence of opening balances in acctbal
				// insert if not found
				try
				{
					sql="SELECT COUNT(1) FROM ACCTBAL WHERE ACCT_PRD ='"+ls_acctprd+"' AND PRD_CODE ='"+ls_openprd+"' AND "+
						"FIN_ENTITY = '"+acctVar_finentity+"' AND SITE_CODE ='"+acctVar_sitecode+"' AND ACCT_CODE = '"+acctVar_acctcode+"' "+
						"AND CCTR_CODE ='"+acctVar_cctrcode+"'";
					rs = stmt.executeQuery(sql);
					if (rs.next())
					{
						ll_cnt = rs.getInt(1);
					}
					stmt.close(); stmt = null;
					rs.close(); rs = null;
					if (ll_cnt == 0	)
					{
						try
						{
							sql="INSERT INTO ACCTBAL (ACCT_PRD, PRD_CODE, FIN_ENTITY, ACCT_CODE, CCTR_CODE, CR_AMT,DR_AMT,CURR_CODE__AC, "+
								"CR_AMT__BASE,DR_AMT__BASE, CHG_DATE,CHG_USER, CHG_TERM,SITE_CODE) "+
								"VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,? )";

							pstmt = conn.prepareStatement(sql);
							pstmt.setString(1,ls_acctprd);
							pstmt.setString(2,ls_openprd);
							pstmt.setString(3,acctVar_finentity);
							pstmt.setString(4,acctVar_acctcode);
							pstmt.setString(5,acctVar_cctrcode);
							pstmt.setDouble(6,0);
							pstmt.setDouble(7,0);
							pstmt.setString(8,acctVar_currcode);
							pstmt.setDouble(9,0);
							pstmt.setDouble(10,0);
							pstmt.setTimestamp(11,acctVar_effdate);
							pstmt.setString(12,userId);
							pstmt.setString(13,userId);
							pstmt.setString(14,acctVar_sitecode);
							int cnt = pstmt.executeUpdate();

							System.out.println("No of Records Inserted in ACCTBAL : " + cnt);
						}
						catch(SQLException se)
						{
							System.out.println("SQLException []:gbf_acctbal_upd()[Excuting Query Failed]" + sql +se.getMessage());
							se.printStackTrace();
							retString = se.getMessage();
							return retString;
						}
					}
				}//outer try
				catch(SQLException se)
				{
					System.out.println("SQLException []:gbf_acctbal_upd()[Excuting Query Failed]" + sql +se.getMessage());
					se.printStackTrace();
					retString = se.getMessage();
					return retString;
				}
				try
				{
					// check for current period
					sql ="SELECT COUNT(1) FROM ACCTBAL WHERE ACCT_PRD = '"+ls_acctprd+"' AND PRD_CODE ='"+ls_prdcode+"' AND "+
						 "FIN_ENTITY = '"+acctVar_finentity+"' AND SITE_CODE ='"+acctVar_sitecode+"' AND ACCT_CODE = '"+acctVar_acctcode+"' "+
						 "AND CCTR_CODE ='"+acctVar_cctrcode+"'";

					rs = stmt.executeQuery(sql);
					if (rs.next())
					{
						ll_cnt = rs.getInt(1);
					}
					stmt.close(); stmt = null;
					rs.close(); rs = null;
				}//try
				catch(SQLException se)
				{
					System.out.println("SQLException []:gbf_acctbal_upd()[Excuting Query Failed]" + sql +se.getMessage());
					se.printStackTrace();
					retString = se.getMessage();
					return retString;
				}
				if (ll_cnt == 0	)
				{
					try
					{
						// add record for current period
						sql="INSERT INTO ACCTBAL (ACCT_PRD, PRD_CODE, FIN_ENTITY, SITE_CODE,"+
							"ACCT_CODE, CCTR_CODE, CURR_CODE__AC, DR_AMT, CR_AMT,"+
							"DR_AMT__BASE, CR_AMT__BASE, CHG_DATE, CHG_USER, CHG_TERM)  "+
							"VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,? )";
						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1,ls_acctprd);
						pstmt.setString(2,ls_prdcode);
						pstmt.setString(3,acctVar_finentity);
						pstmt.setString(4,acctVar_sitecode);
						pstmt.setString(5,acctVar_acctcode);
						pstmt.setString(6,acctVar_cctrcode);
						pstmt.setString(7,acctVar_currcode);
						pstmt.setDouble(8,acctVar_dramt);
						pstmt.setDouble(9,acctVar_cramt);
						pstmt.setDouble(10,lc_dramt_base);
						pstmt.setDouble(11,lc_cramt_base);
						pstmt.setTimestamp(12,acctVar_effdate);
						pstmt.setString(13,userId);
						pstmt.setString(14,userId);
						int cnt = pstmt.executeUpdate();

						System.out.println("INSERTED IN ACCTBAL FOR CURRENT PERIODE : " + cnt);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:gbf_acctbal_upd()[Excuting Query Failed]" + sql +se.getMessage());
						se.printStackTrace();
						retString = se.getMessage();
						return retString;
					}
				}
				else
				{
					try
					{
						// update existing record ( also update advance )
						sql="UPDATE ACCTBAL SET DR_AMT = (DR_AMT + ( ? )), CR_AMT = (CR_AMT + ( ? )), DR_AMT__BASE = (DR_AMT__BASE + ( ? )), CR_AMT__BASE = (CR_AMT__BASE + ( ? )) "+
							"WHERE ACCT_PRD = '"+ls_acctprd+"' AND PRD_CODE = '"+ls_prdcode+"' AND "+
							"FIN_ENTITY = '"+acctVar_finentity+"' AND SITE_CODE = '"+acctVar_sitecode+"' AND "+
							"ACCT_CODE = '"+acctVar_acctcode+"' AND CCTR_CODE = '"+acctVar_cctrcode+"'";
						pstmt = conn.prepareStatement(sql);
						pstmt.setDouble(1,acctVar_dramt);
						pstmt.setDouble(2,acctVar_cramt);
						pstmt.setDouble(3,lc_dramt_base);
						pstmt.setDouble(4,lc_cramt_base);
						count = pstmt.executeUpdate();

						System.out.println("NO. OF RECORDS UPDATED IN ACCTBAL...(CURRENT) :"+count);
					}//try
					catch(SQLException se)
					{
						System.out.println("SQLException []:gbf_acctbal_upd()[Excuting Query Failed]" + sql +se.getMessage());
						se.printStackTrace();
						retString = se.getMessage();
						return retString;
					}
				}
				try
				{
					// check for closing balance
					sql="SELECT COUNT(1) FROM ACCTBAL WHERE ACCT_PRD = '"+ls_acctprd+"'AND PRD_CODE ='"+ls_closeprd+"' AND "+
						" FIN_ENTITY ='"+acctVar_finentity+"' AND SITE_CODE = '"+acctVar_sitecode+"' AND ACCT_CODE = '"+acctVar_acctcode+"' AND CCTR_CODE = '"+acctVar_cctrcode+"'";

					rs = stmt.executeQuery(sql);
					if (rs.next())
					{
						ll_cnt = rs.getInt(1);
					}
					stmt.close(); stmt = null;
					rs.close(); rs = null;
				}//try
				catch(SQLException se)
				{
					System.out.println("SQLException []:gbf_acctbal_upd()[Excuting Query Failed]" + sql +se.getMessage());
					se.printStackTrace();
					retString = se.getMessage();
					return retString;
				}
				if(ll_cnt == 0)
				{
					// insert a record for closing balance
					sql="INSERT INTO ACCTBAL (ACCT_PRD, PRD_CODE, FIN_ENTITY, SITE_CODE,ACCT_CODE, CCTR_CODE, CURR_CODE__AC, DR_AMT, CR_AMT,"+
						" DR_AMT__BASE, CR_AMT__BASE, CHG_DATE, CHG_USER, CHG_TERM)"+
						" VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,? )";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1,ls_acctprd);
					pstmt.setString(2,ls_closeprd);
					pstmt.setString(3,acctVar_finentity);
					pstmt.setString(4,acctVar_sitecode);
					pstmt.setString(5,acctVar_acctcode);
					pstmt.setString(6,acctVar_cctrcode);
					pstmt.setString(7,acctVar_currcode);
					pstmt.setDouble(8,acctVar_dramt);
					pstmt.setDouble(9,acctVar_cramt);
					pstmt.setDouble(10,lc_dramt_base);
					pstmt.setDouble(11,lc_cramt_base);
					pstmt.setTimestamp(12,acctVar_effdate);
					pstmt.setString(13,userId);
					pstmt.setString(14,userId);
					int cnt = pstmt.executeUpdate();

					System.out.println("INSERTED IN ACCTBAL FOR CLOSING BALANCE : " + cnt);
					 if(cnt<1)
					 {
						ls_errcode = "DS000";
						break;
					 }
				}
				else
				{
					// update closing in acctbal
					sql="UPDATE ACCTBAL SET DR_AMT = (DR_AMT + ( ? )), CR_AMT = (CR_AMT + ( ? )), DR_AMT__BASE = (DR_AMT__BASE + ( ? )), CR_AMT__BASE = (CR_AMT__BASE + ( ? )) "+
						"WHERE ACCT_PRD = '"+ls_acctprd+"' AND PRD_CODE = '"+ls_closeprd+"' AND "+
						"FIN_ENTITY = '"+acctVar_finentity+"'AND SITE_CODE ='"+acctVar_sitecode+"'AND "+
						"ACCT_CODE = '"+acctVar_acctcode+"' AND CCTR_CODE = '"+acctVar_cctrcode+"'";
					pstmt = conn.prepareStatement(sql);
					pstmt.setDouble(1,acctVar_dramt);
					pstmt.setDouble(2,acctVar_cramt);
					pstmt.setDouble(3,lc_dramt_base);
					pstmt.setDouble(4,lc_cramt_base);
					int cnt = pstmt.executeUpdate();

    				System.out.println("NO. OF RECORDS UPDATED IN ACCTBAL...(CLOSING)" + cnt);
					if(cnt<1)
					{
						ls_errcode = "DS000";
						break;
					}
				}
				break;
			}
		}//try
		catch(SQLException se)
		{
			System.out.println("SQLException []: :gbf_acctbal_upd():" + sql + " : : " + se.getMessage() + ":");
			se.printStackTrace();
			retString = se.getMessage();
			return retString;
		}
		catch(Exception e)
		{
			System.out.println("Exception []::gbf_acctbal_upd():" + e.getMessage() + ":");
			e.printStackTrace();
			retString = e.getMessage();
			throw new ITMException(e);
		}

		finally
		{
			try
			{
				acctbalMap.clear();
//				ADDED BY ALKA
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
				if (stmt != null)
				{
					stmt.close(); stmt = null;
				}
//				 END ADDED BY ALKA
			}
			catch(Exception e)
			{
				System.out.println("Exception []:gbf_acctbal_upd():" + e.getMessage() + ":");
				e.printStackTrace();
				retString = e.getMessage();
				return retString;
			}
		}
	return retString;
	}//gbf_acctbal_upd()

	public String getFinparams(String prdCode,String varName,Connection conn)throws ITMException
	{
		String retVal="";
		String sql="";
		ResultSet rs = null;
		Statement stmt = null;
		try
		{
			System.out.println("In FINPARAMS......");
			stmt = conn.createStatement();
			sql="SELECT VAR_VALUE FROM FINPARM WHERE PRD_CODE ='"+prdCode.trim()+"' AND VAR_NAME ='"+varName.trim()+"'";
			rs =stmt.executeQuery(sql);
			if(rs.next()==false)
			{
				retVal = "NULLFOUND";
			}
			else
			{
				retVal =rs.getString(1);
			}
			stmt.close(); stmt = null;
			rs.close(); rs = null;
		}
		catch(Exception e)
		{
			System.out.println("Exception []" + e.getMessage() + ":");
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally // FINALLY BLOCK ADDED BY ALKA
		{
			try
			{
				if (stmt != null)
				{
					stmt.close(); stmt = null;
				}
				if (rs != null)
				{
					rs.close(); rs = null;
				}
			}
			catch (Exception e)
			{
				System.out.println("Exception []" + e.getMessage() + ":");
			}
		}
		return(retVal);
	}//getFinparams()

	public double getDailyExchRateSellBuy(String as_curr_code,String as_curr_code__to,String as_login_site,String as_tran_date,String as_type,Connection conn)throws ITMException
	{
		String ls_fin_entity ="",ls_curr_code__to = "",var_value = "",type = "";
		double lc_exch_rate = 0.00;
		String sql = "";
		Statement stmt;
		PreparedStatement pstmt = null, pstmt1 = null;
		ResultSet rs = null, rs1 = null;
		java.sql.Timestamp tranDate = null;
		GenericUtility genericUtility = GenericUtility.getInstance();
		if (as_curr_code.trim().equalsIgnoreCase(as_curr_code__to.trim()))
		{
			return 1.00;
		}
		if (as_curr_code__to.equals(""))
		{
			try
			{
				as_tran_date = genericUtility.getValidDateString(as_tran_date, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat());
				tranDate = java.sql.Timestamp.valueOf(as_tran_date + " 00:00:00");
				stmt = conn.createStatement();
				sql = "SELECT FIN_ENTITY FROM SITE WHERE SITE_CODE ='"+as_login_site.trim()+"'";
				rs = stmt.executeQuery(sql);
				if (rs.next())
				{
					ls_fin_entity = rs.getString(1);
					sql = "SELECT CURR_CODE FROM FINENT WHERE FIN_ENTITY = '"+ls_fin_entity.trim()+"'";
					rs = stmt.executeQuery(sql);
					if (rs.next())
					{
						ls_curr_code__to = rs.getString(1);
					}
				}
				stmt.close(); stmt = null;
				rs.close(); rs = null;
			}
			catch(Exception e)
			{
				System.out.println("Exception :: [][getDailyExchRateSellBuy] ::"+e);
			}
		}
		else
		{
			ls_curr_code__to = as_curr_code__to;
		}
		if(as_type.trim().equals("B"))
		{
			type = "BUY";
		}
		else if(as_type.trim().equals("S"))
		{
			type = "SELL";
		}

		try
		{
			sql = "SELECT EXCH_RATE__"+type.trim()+" FROM DAILY_EXCH_RATE_SELL_BUY WHERE CURR_CODE = '"+as_curr_code.trim()+"' AND CURR_CODE__TO = '"+ls_curr_code__to.trim()+"' AND ? BETWEEN FROM_DATE AND TO_DATE";
			pstmt = conn.prepareStatement(sql);
			pstmt.setTimestamp(1,tranDate);
			rs = pstmt.executeQuery();
			if (rs.next())
			{
				lc_exch_rate = rs.getDouble(1);
				if (lc_exch_rate == 0)
				{
					sql = "SELECT EXCH_RATE FROM DAILY_EXCH_RATE_SELL_BUY WHERE CURR_CODE = '"+ls_curr_code__to.trim()+"' AND CURR_CODE__TO = '"+as_curr_code.trim()+"' AND ? BETWEEN FROM_DATE AND TO_DATE";
					pstmt1 = conn.prepareStatement(sql);
					pstmt1.setTimestamp(1,tranDate);
					rs1 = pstmt1.executeQuery();
					if (rs1.next())
					{
						lc_exch_rate = rs1.getDouble(1);
						if (lc_exch_rate != 0)
						{
							lc_exch_rate = (1 / lc_exch_rate);
						}
					}
					rs1.close(); rs1 = null;
					pstmt1.close(); pstmt1 = null;
				}
			}
			rs.close(); rs = null;
			pstmt.close(); pstmt = null; // ADDED BY ALKA
		}
		catch(SQLException e)
		{
			System.out.println("Exception :: [][getDailyExchRateSellBuy]"+sql+e);
		}
		catch(Exception ex)
		{
			System.out.println("Exception []::"+ex.getMessage());
			ex.printStackTrace();
		}
		finally // FINALLY BLOCK ADDED BY ALKA
		{
			try
			{
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt1 != null)
				{
					pstmt1.close(); pstmt1 = null;
				}
				if (rs1 != null)
				{
					rs1.close(); rs1 = null;
				}
			}
			catch (Exception e)
			{
				System.out.println("Exception []" + e.getMessage() + ":");
			}
		}


		if (lc_exch_rate == 0)
		{
			try
			{
				sql = "SELECT EXCH_RATE FROM DAILY_EXCH_RATE_SELL_BUY WHERE CURR_CODE = '"+as_curr_code.trim()+"' AND CURR_CODE__TO = '"+ls_curr_code__to.trim()+"' AND ? BETWEEN FROM_DATE AND TO_DATE";
				pstmt = conn.prepareStatement(sql);
				pstmt.setTimestamp(1,tranDate);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					lc_exch_rate = rs.getDouble(1);
					if (lc_exch_rate == 0)
					{
						sql = "SELECT EXCH_RATE FROM DAILY_EXCH_RATE_SELL_BUY WHERE CURR_CODE = '"+ls_curr_code__to.trim()+"' AND CURR_CODE__TO = '"+as_curr_code.trim()+"' AND ? BETWEEN FROM_DATE AND TO_DATE";
						pstmt1 = conn.prepareStatement(sql);
						pstmt1.setTimestamp(1,tranDate);
						rs1 = pstmt1.executeQuery();
						if (rs1.next())
						{
							lc_exch_rate = rs1.getDouble(1);
							if (lc_exch_rate != 0)
							{
								lc_exch_rate = (1 / lc_exch_rate);
							}
						}
						rs1.close(); rs1 = null;
						pstmt1.close(); pstmt1 = null;
					}
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null; // ADDED BY ALKA
			}
			catch(SQLException e)
			{
				System.out.println("Exception ::[][getDailyExchRateSellBuy]"+sql+e);
			}
			catch(Exception ex)
			{
				System.out.println("Exception []::"+ex.getMessage());
				ex.printStackTrace();
			}
			finally // FINALLY BLOCK ADDED BY ALKA
			{
				try
				{
					if (pstmt != null)
					{
						pstmt.close(); pstmt = null;
					}
					if (rs != null)
					{
						rs.close(); rs = null;
					}
					if (pstmt1 != null)
					{
						pstmt1.close(); pstmt1 = null;
					}
					if (rs1 != null)
					{
						rs1.close(); rs1 = null;
					}
				}
				catch (Exception e)
				{
					System.out.println("Exception []" + e.getMessage() + ":");
				}
			}
	   	}
		if (lc_exch_rate == 0)
		{
			try
			{
				stmt = conn.createStatement();
				sql = "SELECT RTRIM(CASE WHEN VAR_VALUE IS NULL THEN 'Y' ELSE VAR_VALUE END) FROM FINPARM WHERE PRD_CODE = '999999' AND VAR_NAME = 'EXCRT_CURR'";
				rs = stmt.executeQuery(sql);
				if (rs.next())
				{
					var_value = rs.getString(1);
					if(var_value.equals("Y"))
					{
						sql ="SELECT STD_EXRT FROM CURRENCY WHERE CURR_CODE = '"+as_curr_code.trim()+"'";
						System.out.println("Executing SQL ::"+sql);
						rs1 = stmt.executeQuery(sql);
						if (rs1.next())
						{
							lc_exch_rate = rs1.getDouble(1);
						}
//						stmt.close(); stmt = null;
						rs1.close(); rs1 = null;
					}
					else
					{
						return 0.00;
					}
				}
				else
				{
					sql ="SELECT STD_EXRT FROM CURRENCY WHERE CURR_CODE = '"+as_curr_code.trim()+"'";
					rs1 = stmt.executeQuery(sql);
					if (rs1.next())
					{
						lc_exch_rate = rs1.getDouble(1);
					}
//					stmt.close(); stmt = null;
					rs1.close(); rs1 = null;
				}
				stmt.close(); stmt = null;
				rs.close(); rs = null;
			}
			catch(SQLException e)
			{
				System.out.println("Exception [][getDailyExchRateSellBuy]"+e);
			}
			catch(Exception ex)
			{
				System.out.println("Exception []::"+ex.getMessage());
				ex.printStackTrace();
				throw new ITMException(ex);
			}
		}
//		try
//		{
//			conn.close();			//comment by rajendra on 21-05-07
//			conn = null;
//		}
//		catch(Exception se){}
		return lc_exch_rate;
	}//getDailyExchRateSellBuy()

	public String isAcctCode(String siteCode,String acctCode,String modName,Connection con) throws ITMException
	{
		String errCode = "", siteSpec = "";
		long counter;
		String sql1 = "";
		Statement statement1 = null;
		ResultSet resultSet1 = null;

		String sql2 = "";
		Statement stmt2 = null;
		ResultSet resultSet2 = null;

		String sql3 = "";
		Statement stmt3 = null;
		ResultSet rs3 = null;

		StringBuffer sql4 = null;
		Statement stmt4 = null;
		ResultSet rs4 = null;
 		boolean connectionState = false;
		try
		{
			/*
			if(con == null)
			{
				con = getConnection();
				connectionState = true;
			}
			*/
			sql1 = "SELECT VAR_VALUE FROM FINPARM WHERE PRD_CODE = '999999' AND VAR_NAME = 'SITE_SPECIFIC_ACCT'";
			statement1 = con.createStatement();
			resultSet1 = statement1.executeQuery(sql1);
			if (resultSet1.next())
			{
				sql2 = "SELECT COUNT(*) FROM ACCOUNTS WHERE ACCT_CODE = '" + acctCode + "'";
				stmt2 = con.createStatement();
				resultSet2 = stmt2.executeQuery(sql2);
				if (resultSet2.next())
				{
					if (resultSet2.getLong(1) != 0)
					{
						sql3 = "SELECT ACTIVE FROM ACCOUNTS WHERE ACCT_CODE = '" + acctCode + "'";
						stmt3 = con.createStatement();
						rs3 = stmt3.executeQuery(sql3);
						if (rs3.next())
						{
							if (!rs3.getString(1).equals("Y"))
							{
								// Error : A/c code not active.
								errCode = "VMACCTA";
							}
							else
							{
								siteSpec = resultSet1.getString(1).trim();
								if(siteSpec.equals("Y") && siteSpec != null)
								{
									sql4 = new StringBuffer();
									sql4.append("SELECT COUNT(*) FROM SITE_ACCOUNT WHERE SITE_CODE = '");
									sql4.append(siteCode).append("' AND ACCT_CODE = '");
									sql4.append(acctCode).append("'");
									stmt4 = con.createStatement();
									rs4 = stmt4.executeQuery(sql4.toString());
									if (rs4.next())
									{
										if (rs4.getLong(1) == 0)
										{
											errCode = "VMACCT4";
										}
									}
								}
							}
						}
					}
					else
					{
						errCode = "VMACCT1";
					}
				}
			}
			if (resultSet1 != null)      //Rakesh
			{
				resultSet1.close();
			}
			if (resultSet2 != null)
			{
				resultSet2.close();
			}
			if (rs3 != null)
			{
				rs3.close();
			}
			if (rs4 != null)
			{
				rs4.close();             //Rakesh
			}
			if(connectionState == true)
			{
				con.close();
			}
			else
			{
				con = null;
			}
		}
		catch(SQLException se)
		{
			System.out.println("SQLException :ITMDBAccessEJB :isAcctCode:" + se.getMessage() + ":");
			se.printStackTrace();
			throw new ITMException(se);
		}
		catch(Exception e)
		{
			System.out.println("Exception :ITMDBAccessEJB :isAcctCode:" + e.getMessage() + ":");
			errCode = e.getMessage();
			throw new ITMException(e);
		}
		System.out.println("errCode ::: " + errCode);
		return errCode;
	}	// isAcctCode()
	public String isCctrCode(String acctCode,String cctrCode,String modName,Connection con) throws ITMException
	{
		String errCode = "";
		long cnt = 0;
		String sql = "";
		Statement stmt = null;
		ResultSet rs = null;

		String cctrCheck = null;

		try
		{
			sql = "SELECT VAR_VALUE FROM FINPARM WHERE PRD_CODE = '999999' AND VAR_NAME = 'CCTR_CHECK'";
			stmt = con.createStatement();
			rs = stmt.executeQuery(sql);
			if (rs.next())
			{
				cctrCheck = rs.getString(1);
			}
			else
			{
				cctrCheck = "N";
			}
			rs.close();
			rs = null;
			stmt.close();
			stmt = null;
			if ("Y".equalsIgnoreCase(cctrCheck.trim() ) && cctrCode != null && cctrCode.trim().length() > 0 )
			{
				sql = "SELECT COUNT(1) AS COUNTER FROM COSTCTR WHERE CCTR_CODE = '" + cctrCode + "'" ;
				stmt = con.createStatement();
				rs = stmt.executeQuery(sql);
				if (rs.next())
				{
					cnt = rs.getInt(1);
				}
				rs.close();
				rs = null;
				stmt.close();
				stmt = null;
				if (cnt == 0 )
				{
					errCode = "VMCCTR1";
				}
				else
				{
					// chandni
					sql = "SELECT COUNT(1) FROM ACCOUNTS_CCTR WHERE ACCT_CODE = '" + acctCode + "' AND CCTR_CODE = '" + cctrCode + "'";
					stmt = con.createStatement();
					rs = stmt.executeQuery(sql);
					if (rs.next())
					{
						cnt = rs.getInt(1);
					}
					rs.close();
					rs = null;
					stmt.close();
					stmt = null;
					if (cnt == 0)
					{
						// chandni
						sql = "SELECT COUNT(1) from ACCOUNTS_CCTR WHERE ACCT_CODE = '" + acctCode + "'";
						stmt = con.createStatement();
						rs = stmt.executeQuery(sql);
						if (rs.next())
						{
							cnt = rs.getInt(1);
						}
						rs.close();
						rs = null;
						stmt.close();
						stmt = null;
						if (cnt > 0)
						{
							errCode = "VMCCTR2";
						}
						else if (cnt == 0 && cctrCode != null && cctrCode.trim().length() > 0 )
						{
							errCode = "VMCCTR2";
						}
					}
				}


			}
		}
		catch(SQLException se)
		{
			System.out.println("SQLException :ITMDBAccessEJB :isCctrCode:" + se.getMessage() + ":");
			se.printStackTrace();
			throw new ITMException(se);
		}
		catch(Exception e)
		{
			System.out.println("Exception :ITMDBAccessEJB :isCctrCode:" + e.getMessage() + ":");
			errCode = e.getMessage();
			throw new ITMException(e);
		}
		System.out.println("errCode ::: " + errCode);
		return errCode;
	}	// isAcctCode()

	public String isSundryCode(String siteCode, String sundryType, String sundryCode, String refSer, Connection conn)
	{
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = null;
		String errCode = "";
		int cnt=0;

		try
		{
			if (sundryType .equalsIgnoreCase("C"))
			{
				errCode = validator.isCustomer(siteCode,sundryCode,refSer, conn);
			}
			else if (sundryType.equalsIgnoreCase("R"))
			{
				errCode = isStrgCustomer(siteCode,sundryCode,refSer, conn);
			}
			else if (sundryType.equalsIgnoreCase("B"))
			{
				errCode = validator.isBankCode(siteCode,sundryCode,refSer);
			}
			else if (sundryType.equalsIgnoreCase("L"))
			{
				errCode = isLoanParty(siteCode,sundryCode,refSer, conn);
			}
			else if (sundryType.equalsIgnoreCase("X"))
			{
				errCode = isTaxAuth(siteCode,sundryCode,refSer, conn);
			}
			else if (sundryType.equalsIgnoreCase("S"))
			{
				errCode = isSupplier(siteCode,sundryCode,refSer, conn);
			}
			else if (sundryType.equalsIgnoreCase("E"))
			{
				errCode = isEmployee(siteCode,sundryCode,refSer, conn);
			}
			else if (sundryType.equalsIgnoreCase("P"))
			{
				errCode = isSalesPerson(siteCode,sundryCode,refSer, conn);
			}
			else if (sundryType.equalsIgnoreCase("T"))
			{
				sql = "SELECT COUNT(*) FROM TRANSPORTER WHERE TRAN_CODE = ?";
				pstmt =  conn.prepareStatement(sql);
				pstmt.setString(1, sundryCode);
				rs = pstmt.executeQuery();

				if (rs.next())
				{
					cnt = rs.getInt(1);

					if (cnt==0)
					{
						errCode = "VTTRANCD1";
					}
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
			}
			else if (sundryType.equalsIgnoreCase("O"))
			{
				if (sundryCode.trim().length() > 0)
				{
					errCode = "VTSUN1";
				}
			}
			else if (sundryType.equalsIgnoreCase("D"))
			{
				sql = "SELECT COUNT(*) FROM DEPARTMENT WHERE DEPT_CODE = ?";
				pstmt =  conn.prepareStatement(sql);
				pstmt.setString(1, sundryCode);
				rs = pstmt.executeQuery();

				if (rs.next())
				{
					cnt = rs.getInt(1);

					if (cnt==0)
					{
						errCode = "VTDEPT1";
					}
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
			}
		}
		catch(Exception e)
		{
			errCode = e.getMessage();
			System.out.println("Exception ::"+e);
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
			}
			catch(Exception e)
			{
				errCode = e.getMessage();
				System.out.println("Exception in finally block ::"+e);
				e.printStackTrace();
			}
		}
		return errCode;
	}

	public String isStrgCustomer(String siteCode,String custCode,String refSer, Connection conn)
	{
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = null;
		String errCode = null;
		int cnt = 0;
		try
		{
			sql = "SELECT COUNT(*) FROM STRG_CUSTOMER WHERE SC_CODE = ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, custCode);
			rs = pstmt.executeQuery();
			if (rs.next())
			{
				cnt = rs.getInt(1);
				if (cnt == 0)
				{
					errCode = "VTCUSTCD1";
				}
			}
			pstmt.close(); pstmt = null;
			rs.close(); rs = null;
		}
		catch(Exception e)
		{
			errCode = e.getMessage();
			System.out.println("Exception ::"+e);
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
			}
			catch(Exception e)
			{
				errCode = e.getMessage();
				System.out.println("Exception in finally block ::"+e);
				e.printStackTrace();
			}
		}
		return errCode;

	}

	public String isAnalysis(String acctCode, String analCode, String refSer, Connection conn)
	{
//		 To check Analysis code in analysis table
		PreparedStatement pstmt = null, pstmt1 = null;
		ResultSet rs = null, rs1 = null;
		String sql = null;
		String errCode = null;
		int cnt = 0;
		try
		{
			if (analCode != null && analCode.trim().length()!= 0)
			{
				sql = "SELECT COUNT(*) FROM ANALYSIS WHERE ANAL_CODE = '" + analCode + "'";  //NOT USED PREPARED STATEMENT COZ OF CHAR FIELD OF ANAL_CODE
				pstmt = conn.prepareStatement(sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					cnt = rs.getInt(1);
					if (cnt == 0)
					{
						errCode = "VMANAL1";
						return errCode;
					}
				}
				pstmt.close(); pstmt = null;
				rs.close(); rs = null;
			}

				sql = "SELECT COUNT(*) FROM ACCOUNTS_ANALYSIS WHERE ACCT_CODE = '" + acctCode + "' AND ANAL_CODE = '" + analCode + "'";
				pstmt = conn.prepareStatement(sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					cnt = rs.getInt(1);
					if (cnt == 0)
					{
						sql = "SELECT COUNT(*) FROM ACCOUNTS_ANALYSIS WHERE ACCT_CODE = '" + acctCode + "'";
						pstmt1 = conn.prepareStatement(sql);
						rs1 = pstmt1.executeQuery();
						if (rs1.next())
						{
							cnt = rs1.getInt(1);
							if (cnt > 0)
							{
								errCode = "VMANAL2";
							}
							else if (cnt == 0)
							{
								if (analCode != null && analCode.trim().length() != 0)
								{
									errCode = "VMANAL2";
								}
							}
						}
						rs1.close(); rs1 = null;
						pstmt1.close(); pstmt1 = null;
					}
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;

		}
		catch(Exception e)
		{
			errCode = e.getMessage();
			System.out.println("Exception ::"+e);
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
				if (rs1 != null)
				{
					rs1.close(); rs1 = null;
				}
				if (pstmt1 != null)
				{
					pstmt1.close(); pstmt1 = null;
				}
			}
			catch(Exception e)
			{
				errCode = e.getMessage();
				System.out.println("Exception in finally block ::"+e);
				e.printStackTrace();
			}
		}
		return errCode;
	}

	public String isLoanParty(String siteCode,String loanCode,String refSer, Connection conn)
	{
//		 CHECKING WHETHER LOANPARTY HAS TO BE CHECKED IN SITE TABLE OR NOT
//		 IF VAR VALUE IN FINPARM IS Y CHECK IN SITE_LOANPARTY AND IF 'N'
//		 THEN BYPASS CHECKING IN LOANPARTY
		String errCode = null;
		String varValue = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = null;
		int cnt = 0;
		try
		{
			varValue = getFinparams("999999","SITE_SPECIFIC_LOAN", conn);
			if (varValue.equalsIgnoreCase("Y"))
			{
				sql = "SELECT COUNT(*) FROM SITE_LOANPARTY WHERE SITE_CODE = ? AND PARTY_CODE = ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, siteCode);
				pstmt.setString(2, loanCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					cnt = rs.getInt(1);
					if (cnt == 0)
					{
						errCode = "VTLOANCD2";
					}
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
			}
//			 CHECKING IN LOANPARTY MASTER
			sql = "SELECT COUNT(*) FROM LOANPARTY WHERE PARTY_CODE = ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, loanCode);
			rs = pstmt.executeQuery();
			if (rs.next())
			{
				cnt = rs.getInt(1);
				if (cnt == 0)
				{
					errCode = "VTLOANCD1";
					return errCode;
				}
			}
			rs.close(); rs = null;
			pstmt.close(); pstmt = null;
		}
		catch (ITMException ie)
		{
			errCode = ie.getMessage();
			System.out.println("Exception ::"+ ie);
			ie.printStackTrace();
		}
		catch (Exception e)
		{
			errCode = e.getMessage();
			System.out.println("Exception ::"+ e);
			e.printStackTrace();
		}
		return errCode;

	}
	public String isTaxAuth(String siteCode,String tauthCode,String refSer, Connection conn)
	{
//		CHECKING IN TAX AUTHORITY MASTER

		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = null;
		String errCode = null;
		int cnt = 0;
		try
		{
			sql = "SELECT COUNT(*) FROM TAX_AUTHORITY WHERE TAUTH_CODE = ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, tauthCode);
			rs = pstmt.executeQuery();
			if (rs.next())
			{
				cnt = rs.getInt(1);
				if (cnt == 0)
				{
					errCode = "VTTAUTHCD1";
				}
			}
			pstmt.close(); pstmt = null;
			rs.close(); rs = null;
		}
		catch(Exception e)
		{
			errCode = e.getMessage();
			System.out.println("Exception ::"+e);
			e.printStackTrace();
		}
		return errCode;
	}
	public String isSupplier(String siteCode,String suppCode,String refSer, Connection conn)
	{
		String errCode = "";
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String varValue = "";
		String sql = "", blkList = "";
		int cnt = 0;
//		 CHECKING WHETHER SUPPLIER HAS TO BE CHECKED IN SITE TABLE OR NOT
//		 IF VAR VALUE IN DISPARM IS Y CHECK IN SITE_SUPPLIER AND IF 'N'
//		 THEN BYPASS CHECKING IN SITE_SUPPLIER

		try
		{
			varValue  = validator.getEnvDis("999999", "SITE_SPECIFIC_SUPP", conn);
			if (varValue.equalsIgnoreCase("Y"))
			{
				sql = "SELECT COUNT(*) FROM SITE_SUPPLIER WHERE SITE_CODE = ? AND SUPP_CODE = ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, siteCode);
				pstmt.setString(2, suppCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					cnt = rs.getInt(1);
					if (cnt == 0)
					{
						errCode = "VTSUPP2";
					}
				}
				pstmt.close(); pstmt = null; // Shifted from bellow - Piyush - 14/04/08
				rs.close(); rs = null; // Shifted from bellow - Piyush - 14/04/08
			}
			/* Following statements shifted in If condition - Piyush - 14/04/08
			pstmt.close(); pstmt = null;
			rs.close(); rs = null;
			*/
//			 CHECKING IN SUPPLIER MASTER
			sql = "SELECT COUNT(*) FROM SUPPLIER WHERE SUPP_CODE = ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, suppCode);
			rs = pstmt.executeQuery();
			if (rs.next())
			{
				cnt = rs.getInt(1);
				if (cnt == 0)
				{
					errCode = "VTSUPP1";
					return errCode;
				}
			}
			pstmt.close(); pstmt = null;
			rs.close(); rs = null;

			if (errCode != null && errCode.length() == 0)
			{
				sql = "SELECT CASE WHEN BLACK_LIST IS NULL THEN 'N' ELSE BLACK_LIST END FROM SUPPLIER WHERE SUPP_CODE = ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, suppCode);
				rs = pstmt.executeQuery();

				if (rs.next())
				{
					if (blkList.equalsIgnoreCase("Y"))
					{
						errCode = "VTSUPPBL";
					}
				}
				pstmt.close(); pstmt = null;
				rs.close(); rs = null;
			}
		}
		catch (Exception e)
		{
			errCode = e.getMessage();
			System.out.println("Exception ::"+ e);
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
			}
			catch(Exception e)
			{
				errCode = e.getMessage();
				System.out.println("Exception in finally block ::"+e);
				e.printStackTrace();
			}
		}
		return errCode;
	}

	public String isEmployee(String siteCode,String empCode,String refSer, Connection conn)
	{
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = null;
		String errCode = null;
		int cnt = 0;
//		CHECKING WHETHER EMPLOYEE CODE EXISTS IN EMPLOYEE MASTER
		try
		{
			sql = "SELECT COUNT(*) FROM EMPLOYEE WHERE EMP_CODE = ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, empCode);
			rs = pstmt.executeQuery();
			if (rs.next())
			{
				cnt = rs.getInt(1);
				if (cnt == 0)
				{
					errCode = "VMEMP1";
				}
			}
			pstmt.close(); pstmt = null;
			rs.close(); rs = null;
		}
		catch(Exception e)
		{
			errCode = e.getMessage();
			System.out.println("Exception ::"+e);
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
			}
			catch(Exception e)
			{
				errCode = e.getMessage();
				System.out.println("Exception in finally block ::"+e);
				e.printStackTrace();
			}
		}
		return errCode;
	}

	public String isSalesPerson(String siteCode,String spersCode,String refSer, Connection conn)
	{
//		 CHECKING WHETHER SALES_PERSON HAS TO BE CHECKED IN SITE TABLE OR NOT
//		 IF VAR VALUE IN DISPARM IS Y CHECK IN SITE_SALES_PERS AND IF 'N'
//		 THEN BYPASS CHECKING IN SITE_SALES_PERS
		String errCode = null;
		String varValue = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = null;
		int cnt = 0;

		try
		{
			varValue  = validator.getEnvDis("999999", "SITE_SPECIFIC_SPERS", conn);
			if (varValue.equalsIgnoreCase("Y"))
			{
				sql = "SELECT COUNT(*) FROM SITE_SALES_PERS WHERE SITE_CODE = ? AND SALES_PERS = ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, siteCode);
				pstmt.setString(2, spersCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					cnt = rs.getInt(1);
					if (cnt == 0)
					{
						errCode = "VTSLPERS2";
					}
				}
				pstmt.close(); pstmt = null; // Shifted from bellow - Piyush - 14/04/08
				rs.close(); rs = null; // Shifted from bellow - Piyush - 14/04/08
			}
			/* Following statements shifted in If condition - Piyush - 14/04/08
			pstmt.close(); pstmt = null;
			rs.close(); rs = null;
			*/

			

//			 CHECKING FROM SALES PERSON MASTER
			sql = "SELECT COUNT(*) FROM SALES_PERS WHERE SALES_PERS = ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, spersCode);
			rs = pstmt.executeQuery();
			if (rs.next())
			{
				cnt = rs.getInt(1);
				if (cnt == 0)
				{
					errCode = "VTSLPERS1";
					return errCode;
				}
			}
			pstmt.close(); pstmt = null;
			rs.close(); rs = null;
		}
		catch (Exception e)
		{
			errCode = e.getMessage();
			System.out.println("Exception ::"+ e);
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
			}
			catch(Exception e)
			{
				errCode = e.getMessage();
				System.out.println("Exception in finally block ::"+e);
				e.printStackTrace();
			}
		}
		return errCode;
	}

	public String isAcctType(String acctCode, String sundryCode, String sundryType, Connection conn)
	{
		String errCode = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = null, acctType = null, sType = null;

		try
		{
			sql = "SELECT ACCT_TYPE, SUNDRY_TYPE FROM ACCOUNTS WHERE ACCT_CODE = ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, acctCode);
			rs = pstmt.executeQuery();
			if (rs.next())
			{
				acctType = rs.getString(1);
				sType = rs.getString(2)==null?"O":rs.getString(2);
				System.out.println("Retrieved -- >  sType :: '" + sType + "' sundryType :: '" + sundryType + "'");
//				if (sundryCode == null || sundryCode.trim().length() == 0)
//				{
//					if (acctType != null && !acctType.equalsIgnoreCase("O"))
//					{
//						errCode = "VMACCT4"; // TYPE MUST BE OTHER IF SUNDRY CODE IS BLANK
//					}
//					
//				}
//				commented by shamim as per discussion with Shri Mam ,no validation on acctType 27-07-12 

				if (sundryCode == null || sundryCode.trim().length() == 0)
				{
					if (sType != null && "O".equalsIgnoreCase("sType"))
					{
						errCode = "VMACCT4"; // TYPE MUST BE OTHER IF SUNDRY CODE IS BLANK
					}
					
				}

				else
				{
//					if (acctType != null && acctType.equalsIgnoreCase("O"))
//					{
//						errCode = "VMACCT5"; // TYPE MUST NOT BE OTHER IF SUNDRY IS SPECIFIED
//					}
//					else
//					{
						if (sType != null && (!sType.equals(sundryType)))
						{
							errCode = "VMACCT6"; // TYPE SHOULD BE SAME AS ENTERED
						}
//					}
				}
			}
			pstmt.close(); pstmt = null;
			rs.close(); rs = null;
		}
		catch (Exception e)
		{
			errCode = e.getMessage();
			System.out.println("Exception ::"+ e);
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
			}
			catch(Exception e)
			{
				errCode = e.getMessage();
				System.out.println("Exception in finally block ::"+e);
				e.printStackTrace();
			}
		}
		return errCode;
	}

	public String checkTaxEnvStatus(String taxEnv, Timestamp date, Connection conn)
	{
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = null;
		String errCode = null;
		String status = null;
//		TYPE SHOULD BE SAME AS ENTERED
		try
		{
			sql = "SELECT (CASE WHEN STATUS IS NULL THEN 'A' ELSE STATUS END) FROM TAXENV "
				+ "WHERE TAX_ENV = ? AND STATUS_DATE  <= ? ";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, taxEnv);
			pstmt.setTimestamp(2, date);
			rs = pstmt.executeQuery();
			if (rs.next())
			{
				status = rs.getString(1);
				if (status.equalsIgnoreCase("C"))
				{
					errCode = "VTTAXENVCL";
				}
			}
			pstmt.close(); pstmt = null;
			rs.close(); rs = null;
		}
		catch(Exception e)
		{
			errCode = e.getMessage();
			System.out.println("Exception ::"+e);
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
			}
			catch(Exception e)
			{
				errCode = e.getMessage();
				System.out.println("Exception in finally block ::"+e);
				e.printStackTrace();
			}
		}
		return errCode;
	}

	public String getChequeName(String sundryType, String sundryCode, String cheque_or_name, Connection conn)
	{
		String sName = null, chqName = null, fName = null, mName = null, lName = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = null;

//		 IF CHEQUE_OR_NAME = "C" IT RETURNS CHEQUE NAME ELSE DESCRIPTION OR NAME
		try
		{
			if (sundryType.equalsIgnoreCase("O"))
			{
				sName = "";
			}
			else if (sundryType.equalsIgnoreCase("T"))
			{
				sql = "SELECT CHQ_NAME,TRAN_NAME FROM TRANSPORTER WHERE TRAN_CODE = ?";

				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, sundryCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					chqName = rs.getString(1);
					sName = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (cheque_or_name.equalsIgnoreCase("C"))
				{
					if (chqName == null && chqName.trim().length() == 0)
					{
						chqName = sName;
					}
				}
				else
				{
					chqName = sName;
				}
			}
			else if (sundryType.equalsIgnoreCase("B"))
			{
				sql = "SELECT BANK_NAME FROM BANK WHERE BANK_CODE = ?";

				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, sundryCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					chqName = rs.getString(1);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
			}
			else if (sundryType.equalsIgnoreCase("X"))
			{
				sql = "SELECT CHQ_NAME,TAUTH_NAME FROM TAX_AUTHORITY WHERE TAUTH_CODE = ?";

				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, sundryCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					chqName = rs.getString(1);
					sName = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (cheque_or_name.equalsIgnoreCase("C"))
				{
					if (chqName == null && chqName.trim().length() == 0)
					{
						chqName = sName;
					}
				}
				else
				{
					chqName = sName;
				}
			}
			else if (sundryType.equalsIgnoreCase("E"))
			{
				sql = "SELECT SHORT_NAME,(CASE WHEN EMP_FNAME IS NULL THEN ' ' ELSE EMP_FNAME END), "
					+ "(CASE WHEN EMP_LNAME IS NULL THEN ' ' ELSE EMP_LNAME END), "
					+ "(CASE WHEN EMP_MNAME IS NULL THEN ' ' ELSE EMP_MNAME END) FROM EMPLOYEE	WHERE EMP_CODE = ?";

				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, sundryCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					chqName = rs.getString(1);
					fName = rs.getString(2);
					mName = rs.getString(3);
					lName = rs.getString(4);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				sName = fName.trim() + " " + mName.trim() + " " + lName.trim();

				if (cheque_or_name.equalsIgnoreCase("C"))
				{
					if (chqName == null && chqName.trim().length() == 0)
					{
						chqName = sName;
					}
				}
				else
				{
					chqName = sName;
				}
			}
			else if (sundryType.equalsIgnoreCase("P"))
			{
				sql = " SELECT CHQ_NAME,SP_NAME	FROM SALES_PERS	WHERE SALES_PERS = ?";

				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, sundryCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					chqName = rs.getString(1);
					sName = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (cheque_or_name.equalsIgnoreCase("C"))
				{
					if (chqName == null && chqName.trim().length() == 0)
					{
						chqName = sName;
					}
				}
				else
				{
					chqName = sName;
				}
			}
			else if (sundryType.equalsIgnoreCase("S"))
			{
				sql = "SELECT CHQ_NAME,SUPP_NAME FROM SUPPLIER WHERE SUPP_CODE = ?";

				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, sundryCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					chqName = rs.getString(1);
					sName = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (cheque_or_name.equalsIgnoreCase("C"))
				{
					if (chqName == null || chqName.trim().length() == 0)
					{
						chqName = sName;
					}
				}
				else
				{
					chqName = sName;
				}
			}
			else if (sundryType.equalsIgnoreCase("C"))
			{
				sql = "SELECT CHQ_NAME,CUST_NAME FROM CUSTOMER WHERE CUST_CODE = ?";

				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, sundryCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					chqName = rs.getString(1);
					sName = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (cheque_or_name.equalsIgnoreCase("C"))
				{
					if (chqName == null || chqName.trim().length() == 0)
					{
						chqName = sName;
					}
				}
				else
				{
					chqName = sName;
				}

			}
			else if (sundryType.equalsIgnoreCase("R"))
			{
				sql = "SELECT (CASE WHEN FIRST_NAME IS NULL THEN '' ELSE FIRST_NAME END), "
					+ "(CASE WHEN MIDDLE_NAME IS NULL THEN '' ELSE MIDDLE_NAME END),"
					+ "(CASE WHEN LAST_NAME IS NULL THEN '' ELSE LAST_NAME END), "
					+ "A.CHQ_NAME FROM STRG_CUSTOMER B, CUSTOMER A "
					+ "WHERE A.CUST_CODE(+) = B.CUST_CODE	AND  B.SC_CODE = ?" ;

				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, sundryCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					fName = rs.getString(1);
					mName = rs.getString(2);
					lName = rs.getString(3);
					sName = rs.getString(4);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				chqName = fName.trim() + " " + mName.trim() + " " + lName.trim();

				if (cheque_or_name.equalsIgnoreCase("C"))
				{
					if (chqName == null || chqName.trim().length() == 0)
					{
						chqName = sName;
					}
				}
			}
			else if (sundryType.equalsIgnoreCase("L"))
			{
				sql = "SELECT CHQ_NAME,PARTY_NAME FROM LOANPARTY WHERE PARTY_CODE = ?";

				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, sundryCode);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					chqName = rs.getString(1);
					sName = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (cheque_or_name.equalsIgnoreCase("C"))
				{
					if (chqName == null || chqName.trim().length() == 0)
					{
						chqName = sName;
					}
				}
				else
				{
					chqName = sName;
				}
			}
			else if (sundryType.equalsIgnoreCase("D"))
			{
				if (!cheque_or_name.equalsIgnoreCase("C"))
				{
					sql = "SELECT FIRST_NAME,MIDDLE_NAME,LAST_NAME FROM STRG_CUSTOMER WHERE SC_CODE = ?";

					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1, sundryCode);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						fName = rs.getString(1);
						mName = rs.getString(2);
						lName = rs.getString(3);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					chqName = fName.trim() + " " + mName.trim() + " " + lName.trim();
				}
			}
		}
		catch(Exception e)
		{
			System.out.println("Exception in getChequeName ::"+e);
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
			}
			catch(Exception e)
			{
				System.out.println("Exception in getChequeName in finally block ::"+e);
				e.printStackTrace();
			}
		}
		return chqName;
	}

	public String getFromAcctDetr(String itemCode, String itemSer, String purpose, Connection conn) throws ITMException
	{
		String acctCode = null, cctrCode = null, stkOpt = null, itemSerN = null;
		String sql = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;

		System.out.println("In getFromAcctDetr --> purpose :: " + purpose + " itemCode :: " + itemCode);
		System.out.println(" itemSer :: " + itemSer);
		try
		{
			if (purpose.equalsIgnoreCase("IN"))
			{
				sql = "SELECT STK_OPT FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
				pstmt = conn.prepareStatement(sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					stkOpt = rs.getString(1);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;

//				IF STK_OPT OF ITEM IS 'N' NO INVENTORY
				if (stkOpt.equalsIgnoreCase("0"))
				{
					sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
						}
					}
				}
				else
				{
					sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("DIS"))
			{
				sql = " SELECT ACCT_CODE__DIS,CCTR_CODE__DIS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__DIS,CCTR_CODE__DIS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__DIS,CCTR_CODE__DIS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__DIS,CCTR_CODE__DIS FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("PO") || purpose.equalsIgnoreCase("POVOU")) // ACCOUNT CODE FOR AP A/C IN PO or VOUCHER CREATION OF PORCP
			{
				sql = " SELECT ACCT_CODE__AP,CCTR_CODE__AP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__AP,CCTR_CODE__AP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__AP,CCTR_CODE__AP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__AP,CCTR_CODE__AP FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("PORCP"))// ACCOUNT CODE FOR AP A/C IN PORCP
			{
				sql = " SELECT ACCT_CODE__PR,CCTR_CODE__PR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__PR,CCTR_CODE__PR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__PR,CCTR_CODE__PR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__PR,CCTR_CODE__PR FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("STKINV")) // ACCOUNT CODE FOR STOCK INVENTORY ACCOUNT CODE
			{
				sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("TAXRECO")) // ACCOUNT CODE FOR TAX RECOVERY
			{
				sql = " SELECT ACCT_CODE__RECO,CCTR_CODE__RECO FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__RECO,CCTR_CODE__RECO FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__RECO,CCTR_CODE__RECO FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__RECO,CCTR_CODE__RECO FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("WORDRCP-OH")) // ACCOUNT CODE FOR OVERHEAD EXPENSES IN WORDER_RECEIPT
			{
				sql = " SELECT ACCT_CODE__OH,CCTR_CODE__OH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__OH,CCTR_CODE__OH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__OH,CCTR_CODE__OH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__OH,CCTR_CODE__OH FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("COGS")) // ACCOUNT CODE FOR COST OF GOODS SOLD
			{
				sql = " SELECT ACCT_CODE__COGS,CCTR_CODE__COGS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__COGS,CCTR_CODE__COGS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__COGS,CCTR_CODE__COGS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__COGS,CCTR_CODE__COGS FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("ADDCOST")) // ACCOUNT CODE FOR AP CODE FOR ADDITIONAL COST
			{
				sql = " SELECT ACCT_CODE__ADCOST,CCTR_CODE__ADCOST FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__ADCOST,CCTR_CODE__ADCOST FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__ADCOST,CCTR_CODE__ADCOST FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__ADCOST,CCTR_CODE__ADCOST FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("CISS")) // ACCOUNT CODE FOR CONSUMPTION ISSUE
			{
				sql = " SELECT ACCT_CODE__CISS,CCTR_CODE__CISS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__CISS,CCTR_CODE__CISS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__CISS,CCTR_CODE__CISS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__CISS,CCTR_CODE__CISS FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("WIPRCP")) // ACCOUNT CODE FOR WIP RECEIPT
			{
				sql = " SELECT ACCT_CODE__WP_RCP,CCTR_CODE__WP_RCP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__WP_RCP,CCTR_CODE__WP_RCP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__WP_RCP,CCTR_CODE__WP_RCP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__WP_RCP,CCTR_CODE__WP_RCP FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("QCSAMPLE")) // ACCOUNT CODE FOR QC SAMPLE POSTING
			{
				sql = " SELECT ACCT_CODE__QC_SAMPLE,CCTR_CODE__QC_SAMPLE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__QC_SAMPLE,CCTR_CODE__QC_SAMPLE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__QC_SAMPLE,CCTR_CODE__QC_SAMPLE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__QC_SAMPLE,CCTR_CODE__QC_SAMPLE FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("WIP")) // ACCOUNT CODE FOR WIP ISSUE
			{
				sql = " SELECT ACCT_CODE__WP,CCTR_CODE__WP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__WP,CCTR_CODE__WP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__WP,CCTR_CODE__WP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__WP,CCTR_CODE__WP FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("YLDLOSS")) // ACCOUNT CODE FOR MFG YIELD LOSS
			{
				sql = " SELECT ACCT_CODE__YLD_LOSS,CCTR_CODE__YLD_LOSS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__YLD_LOSS,CCTR_CODE__YLD_LOSS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__YLD_LOSS,CCTR_CODE__YLD_LOSS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__YLD_LOSS,CCTR_CODE__YLD_LOSS FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("YLDGAIN")) // ACCOUNT CODE FOR MFG YIELD GAIN
			{
				sql = " SELECT ACCT_CODE__YLD_GAIN,CCTR_CODE__YLD_GAIN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__YLD_GAIN,CCTR_CODE__YLD_GAIN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__YLD_GAIN,CCTR_CODE__YLD_GAIN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__YLD_GAIN,CCTR_CODE__YLD_GAIN FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("CONVGL")) // ACCOUNT CODE FOR CONV GL ACCOUNT CODE
			{
				sql = " SELECT ACCT_CODE__CONV_GL,CCTR_CODE__CONV_GL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
//				pstmt.setString(1, itemCode);
//				pstmt.setString(2, itemSer);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__CONV_GL,CCTR_CODE__CONV_GL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
//					pstmt.setString(1, itemCode);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
//							pstmt.setString(1, itemCode);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__CONV_GL,CCTR_CODE__CONV_GL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
//						pstmt.setString(1, itemSerN);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__CONV_GL,CCTR_CODE__CONV_GL FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
//							pstmt.setString(1, itemSerN);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("PPV")) // ACCOUNT CODE FOR PRICE VARIANCE
			{
				sql = " SELECT ACCT_CODE__PPV,CCTR_CODE__PPV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__PPV,CCTR_CODE__PPV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__PPV,CCTR_CODE__PPV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__PPV,CCTR_CODE__PPV FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("PH")) // ACCOUNT CODE FOR TAX RECOVERY
			{
				sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("AREV")) // ACCOUNT CODE FOR FOR ASSET REVALUATION A/C.
			{
				sql = " SELECT ACCT_CODE__AREV,CCTR_CODE__AREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__AREV,CCTR_CODE__AREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__AREV,CCTR_CODE__AREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__AREV,CCTR_CODE__AREV FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("CRREV")) // ACCOUNT CODE FOR FOR CAPITAL RESERVE REVALUATION A/C.
			{
				sql = " SELECT ACCT_CODE__CRREV,CCTR_CODE__CRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__CRREV,CCTR_CODE__CRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__CRREV,CCTR_CODE__CRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__CRREV,CCTR_CODE__CRREV FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("DREV")) // ACCOUNT CODE FOR FOR DEPRECIATION REVALUATION A/C.
			{
				sql = " SELECT ACCT_CODE__DREV,CCTR_CODE__DREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__DREV,CCTR_CODE__DREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__DREV,CCTR_CODE__DREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__DREV,CCTR_CODE__DREV FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("DRREV")) // ACCOUNT CODE FOR DEPRECIATION RESERVE REVALUATION A/C.
			{
				sql = " SELECT ACCT_CODE__DRREV,CCTR_CODE__DRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__DRREV,CCTR_CODE__DRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						if (itemSer == null || itemSer.trim().length() == 0)
						{
							sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								itemSerN = rs.getString(1);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
						else
						{
							itemSerN = itemSer;
						}

						sql = " SELECT ACCT_CODE__DRREV,CCTR_CODE__DRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__DRREV,CCTR_CODE__DRREV FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
						}
					}
				}
			}
			if (acctCode == null) acctCode = "";
			if (cctrCode == null) cctrCode = "";
		} catch (SQLException e) {

			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
			}
			catch(Exception e)
			{
				System.out.println("Exception in finally block ::"+e);
				e.printStackTrace();
			}
		}
		System.out.println("From getFromAcctDetr [" + acctCode + "," + cctrCode + "]");
		return acctCode + "," + cctrCode;
	}

	public String getAcctDetrTtype(String itemCode, String itemSer, String purpose, String tranType, Connection conn) throws ITMException
	{
		String acctCode = null, cctrCode = null, stkOpt = null, itemSerN = null;
		String sql = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;

		System.out.println("In getAcctDetrTtype --> purpose :: " + purpose + " itemCode :: " + itemCode);
		System.out.println(" itemSer :: " + itemSer + " tranType :: " + tranType);
		try
		{
			if (purpose.equalsIgnoreCase("IN"))
			{
				sql = "SELECT STK_OPT FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
				pstmt = conn.prepareStatement(sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					stkOpt = rs.getString(1);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;

//				IF STK_OPT OF ITEM IS 'N' NO INVENTORY
				if (stkOpt.equalsIgnoreCase("0"))
				{
					sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
							+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								if (itemSer == null || itemSer.trim().length() == 0)
								{
									sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										itemSerN = rs.getString(1);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
								else
								{
									itemSerN = itemSer;
								}

								sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE '" + tranType + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
										+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
									if (acctCode == null  || acctCode.trim().length() == 0)
									{
										sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
										pstmt = conn.prepareStatement(sql);
										System.out.println("sql ::: " + sql);
										rs = pstmt.executeQuery();
										if (rs.next())
										{
											acctCode = rs.getString(1);
											cctrCode = rs.getString(2);
										}
										rs.close(); rs = null;
										pstmt.close(); pstmt = null;
									}
								}
							}
						}
					}
				}
				else
				{
					sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = ' '";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("DIS"))
			{
				sql = " SELECT ACCT_CODE__DIS,CCTR_CODE__DIS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__DIS,CCTR_CODE__DIS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__DIS,CCTR_CODE__DIS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}
//changes done by rajendra 0n 29/09/07
							//sql = " SELECT ACCT_CODE__DIS,CCTR_CODE__DIS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
							//+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE '" + tranType + "'";

							sql = " SELECT ACCT_CODE__DIS,CCTR_CODE__DIS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE ='" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__DIS,CCTR_CODE__DIS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__DIS,CCTR_CODE__DIS FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("PO") || purpose.equalsIgnoreCase("POVOU")) // ACCOUNT CODE FOR AP A/C IN PO or VOUCHER CREATION OF PORCP
			{
				sql = " SELECT ACCT_CODE__AP,CCTR_CODE__AP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__AP,CCTR_CODE__AP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__AP,CCTR_CODE__AP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__AP,CCTR_CODE__AP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__AP,CCTR_CODE__AP FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__AP,CCTR_CODE__AP FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("PORCP"))// ACCOUNT CODE FOR AP A/C IN PORCP
			{
				sql = " SELECT ACCT_CODE__PR,CCTR_CODE__PR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__PR,CCTR_CODE__PR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__PR,CCTR_CODE__PR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__PR,CCTR_CODE__PR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__PR,CCTR_CODE__PR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__PR,CCTR_CODE__PR FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("STKINV")) // ACCOUNT CODE FOR STOCK INVENTORY ACCOUNT CODE
			{
				sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__IN,CCTR_CODE__IN FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("TAXRECO")) // ACCOUNT CODE FOR TAX RECOVERY
			{
				sql = " SELECT ACCT_CODE__RECO,CCTR_CODE__RECO FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__RECO,CCTR_CODE__RECO FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__RECO,CCTR_CODE__RECO FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__RECO,CCTR_CODE__RECO FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__RECO,CCTR_CODE__RECO FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__RECO,CCTR_CODE__RECO FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("WORDRCP-OH")) // ACCOUNT CODE FOR OVERHEAD EXPENSES IN WORDER_RECEIPT
			{
				sql = " SELECT ACCT_CODE__OH,CCTR_CODE__OH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__OH,CCTR_CODE__OH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__OH,CCTR_CODE__OH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__OH,CCTR_CODE__OH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__OH,CCTR_CODE__OH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__OH,CCTR_CODE__OH FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("COGS")) // ACCOUNT CODE FOR COST OF GOODS SOLD
			{
				sql = " SELECT ACCT_CODE__COGS,CCTR_CODE__COGS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__COGS,CCTR_CODE__COGS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__COGS,CCTR_CODE__COGS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__COGS,CCTR_CODE__COGS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__COGS,CCTR_CODE__COGS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__COGS,CCTR_CODE__COGS FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("ADDCOST")) // ACCOUNT CODE FOR AP CODE FOR ADDITIONAL COST
			{
				sql = " SELECT ACCT_CODE__ADCOST,CCTR_CODE__ADCOST FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__ADCOST,CCTR_CODE__ADCOST FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__ADCOST,CCTR_CODE__ADCOST FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__ADCOST,CCTR_CODE__ADCOST FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__ADCOST,CCTR_CODE__ADCOST FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__ADCOST,CCTR_CODE__ADCOST FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("CISS")) // ACCOUNT CODE FOR CONSUMPTION ISSUE
			{
				sql = " SELECT ACCT_CODE__CISS,CCTR_CODE__CISS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__CISS,CCTR_CODE__CISS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__CISS,CCTR_CODE__CISS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__CISS,CCTR_CODE__CISS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__CISS,CCTR_CODE__CISS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__CISS,CCTR_CODE__CISS FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("XFRX")) // ACCOUNT CODE FOR TRANSFER
			{
				sql = " SELECT ACCT_CODE__TRF,CCTR_CODE__TRF FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__TRF,CCTR_CODE__TRF FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__TRF,CCTR_CODE__TRF FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__TRF,CCTR_CODE__TRF FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__TRF,CCTR_CODE__TRF FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__TRF,CCTR_CODE__TRF FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("AR")) // ACCOUNT CODE FOR AR A/C FOR FIXED ASSETS
			{
				sql = " SELECT ACCT_CODE__AR,CCTR_CODE__AR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__AR,CCTR_CODE__AR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__AR,CCTR_CODE__AR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__AR,CCTR_CODE__AR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__AR,CCTR_CODE__AR FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__AR,CCTR_CODE__AR FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("SAL")) // ACCOUNT CODE FOR SALE A/C
			{
				sql = " SELECT ACCT_CODE__SAL,CCTR_CODE__SAL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__SAL,CCTR_CODE__SAL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__SAL,CCTR_CODE__SAL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__SAL,CCTR_CODE__SAL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__SAL,CCTR_CODE__SAL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__SAL,CCTR_CODE__SAL FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("FA-PL")) // ACCOUNT CODE FOR PROFIT FOR FIXED ASSET A/C
			{
				sql = " SELECT ACCT_CODE__PL,CCTR_CODE__PL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__PL,CCTR_CODE__PL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__PL,CCTR_CODE__PL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__PL,CCTR_CODE__PL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__PL,CCTR_CODE__PL FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__PL,CCTR_CODE__PL FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("FA-LOSS")) // ACCOUNT CODE FOR LOSS FOR FIXED ASSETS A/C
			{
				sql = " SELECT ACCT_CODE__LOSS,CCTR_CODE__LOSS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__LOSS,CCTR_CODE__LOSS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__LOSS,CCTR_CODE__LOSS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__LOSS,CCTR_CODE__LOSS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__LOSS,CCTR_CODE__LOSS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__LOSS,CCTR_CODE__LOSS FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("FA")) // ACCOUNT CODE FOR FIXED ASSETS
			{
				sql = " SELECT ACCT_CODE__FA,CCTR_CODE__FA FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__FA,CCTR_CODE__FA FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__FA,CCTR_CODE__FA FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__FA,CCTR_CODE__FA FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__FA,CCTR_CODE__FA FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__FA,CCTR_CODE__FA FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("PPV")) // ACCOUNT CODE FOR PRICE VARIANCE
			{
				sql = " SELECT ACCT_CODE__PPV,CCTR_CODE__PPV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__PPV,CCTR_CODE__PPV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__PPV,CCTR_CODE__PPV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__PPV,CCTR_CODE__PPV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__PPV,CCTR_CODE__PPV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__PPV,CCTR_CODE__PPV FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("PH")) // ACCOUNT CODE FOR PURCHASE ACCOUNT CODE
			{
				sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__PH,CCTR_CODE__PH FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("AREV")) // ACCOUNT CODE FOR FOR ASSET REVALUATION A/C.
			{
				sql = " SELECT ACCT_CODE__AREV,CCTR_CODE__AREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__AREV,CCTR_CODE__AREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__AREV,CCTR_CODE__AREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__AREV,CCTR_CODE__AREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__AREV,CCTR_CODE__AREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__AREV,CCTR_CODE__AREV FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("CRREV")) // ACCOUNT CODE FOR FOR CAPITAL RESERVE REVALUATION A/C.
			{
				sql = " SELECT ACCT_CODE__CRREV,CCTR_CODE__CRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__CRREV,CCTR_CODE__CRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__CRREV,CCTR_CODE__CRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__CRREV,CCTR_CODE__CRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__CRREV,CCTR_CODE__CRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__CRREV,CCTR_CODE__CRREV FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("DREV")) // ACCOUNT CODE FOR FOR DEPRECIATION REVALUATION A/C.
			{
				sql = " SELECT ACCT_CODE__DREV,CCTR_CODE__DREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__DREV,CCTR_CODE__DREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__DREV,CCTR_CODE__DREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__DREV,CCTR_CODE__DREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__DREV,CCTR_CODE__DREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__DREV,CCTR_CODE__DREV FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("DRREV")) // ACCOUNT CODE FOR DEPRECIATION RESERVE REVALUATION A/C.
			{
				sql = " SELECT ACCT_CODE__DRREV,CCTR_CODE__DRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
				+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
				pstmt = conn.prepareStatement(sql);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close(); rs = null;
				pstmt.close(); pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " SELECT ACCT_CODE__DRREV,CCTR_CODE__DRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__DRREV,CCTR_CODE__DRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null || itemSer.trim().length() == 0)
							{
								sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									itemSerN = rs.getString(1);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
							}
							else
							{
								itemSerN = itemSer;
							}

							sql = " SELECT ACCT_CODE__DRREV,CCTR_CODE__DRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
								+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " SELECT ACCT_CODE__DRREV,CCTR_CODE__DRREV FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__DRREV,CCTR_CODE__DRREV FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
							}
						}
					}
				}
			}
//start Changes By sAkhtar on 28 june 2010
			else if(purpose.equalsIgnoreCase("ACCDEPR")) // ACCOUNT CODE ACCUMULATED DEPR FOR FIXED ASSET
			{
				sql = " select acct_code__acc_depr,cctr_code__acc_depr from item_acct_detr where item_code = ?"
				+ " and item_ser = ? and grp_code = ? ";

				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,itemCode);
				pstmt.setString(2,itemSer);
				pstmt.setString(3,tranType);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " select acct_code__acc_depr,cctr_code__acc_depr from item_acct_detr where item_code = ? "
						+ " and item_ser = ? and grp_code = ? ";

					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1," ");
					pstmt.setString(2,itemSerN);
					pstmt.setString(3,tranType);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close(); 
					pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " select acct_code__acc_depr,cctr_code__acc_depr from item_acct_detr where item_code = ?"
							+ " and item_ser = ? and grp_code = ? ";

						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1," ");
						pstmt.setString(2," ");
						pstmt.setString(3,tranType);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close();
						rs = null;
						pstmt.close();
						pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null  || itemSer.trim().length() == 0)
							{
								sql = "select item_ser from item where item_code = ? ";
								pstmt = conn.prepareStatement(sql);
								pstmt.setString(1,itemCode);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close();
								rs = null;
								pstmt.close(); 
								pstmt = null;
							}	
							else
							{
								itemSerN = itemSer;
							}
							sql = " select acct_code__acc_depr,cctr_code__acc_depr from item_acct_detr where item_code = ? "
							+ " and item_ser = ? and grp_code = ? ";

							pstmt = conn.prepareStatement(sql);
							pstmt.setString(1," ");
							pstmt.setString(2,itemSerN);
							pstmt.setString(3," ");
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close();
							rs = null;
							pstmt.close();
							pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " select acct_code__acc_depr,cctr_code__acc_depr from itemser where item_ser = ? ";
								pstmt = conn.prepareStatement(sql);
								pstmt.setString(1,itemSerN);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close();
								rs = null;
								pstmt.close();
								pstmt = null;
							}
						}
					}
				}
			}
			else if(purpose.equalsIgnoreCase("DEPR")) // ACCOUNT CODE DEPR FOR FIXED ASSET
			{
				sql = " select acct_code__depr,cctr_code__depr from item_acct_detr where item_code = ?"
				+ " and item_ser = ? and grp_code = ? ";

				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,itemCode);
				pstmt.setString(2,itemSer);
				pstmt.setString(3,tranType);
				System.out.println("sql ::: " + sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;
				if (acctCode == null  || acctCode.trim().length() == 0)
				{
					sql = " select acct_code__depr,cctr_code__depr from item_acct_detr where item_code = ? "
						+ " and item_ser = ? and grp_code = ? ";

					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1," ");
					pstmt.setString(2,itemSerN);
					pstmt.setString(3,tranType);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close(); 
					pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " select acct_code__depr,cctr_code__depr from item_acct_detr where item_code = ?"
							+ " and item_ser = ? and grp_code = ? ";

						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1," ");
						pstmt.setString(2," ");
						pstmt.setString(3,tranType);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close();
						rs = null;
						pstmt.close();
						pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							if (itemSer == null  || itemSer.trim().length() == 0)
							{
								sql = "select item_ser from item where item_code = ? ";
								pstmt = conn.prepareStatement(sql);
								pstmt.setString(1,itemCode);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close();
								rs = null;
								pstmt.close(); 
								pstmt = null;
							}	
							else
							{
								itemSerN = itemSer;
							}
							sql = " select acct_code__depr,cctr_code__depr from item_acct_detr where item_code = ? "
							+ " and item_ser = ? and grp_code = ? ";

							pstmt = conn.prepareStatement(sql);
							pstmt.setString(1," ");
							pstmt.setString(2,itemSerN);
							pstmt.setString(3," ");
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close();
							rs = null;
							pstmt.close();
							pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								sql = " select acct_code__depr,cctr_code__depr from itemser where item_ser = ? ";
								pstmt = conn.prepareStatement(sql);
								pstmt.setString(1,itemSerN);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close();
								rs = null;
								pstmt.close();
								pstmt = null;
							}
						}
					}
				}
//end Changes By sAkhtar on 28 june 2010
				else if(purpose.equalsIgnoreCase("DEPRWB")) // ACCOUNT CODE DEPR WRITTEN BACK FOR FIXED ASSET
				{
					sql = " SELECT ACCT_CODE__DEPR_WB,CCTR_CODE__DEPR_WB FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__DEPR_WB,CCTR_CODE__DEPR_WB FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__DEPR_WB,CCTR_CODE__DEPR_WB FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
							+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								if (itemSer == null || itemSer.trim().length() == 0)
								{
									sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										itemSerN = rs.getString(1);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
								else
								{
									itemSerN = itemSer;
								}

								sql = " SELECT ACCT_CODE__DEPR_WB,CCTR_CODE__DEPR_WB FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__DEPR_WB,CCTR_CODE__DEPR_WB FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
										+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
									if (acctCode == null  || acctCode.trim().length() == 0)
									{
										sql = " SELECT ACCT_CODE__DEPR_WB,CCTR_CODE__DEPR_WB FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
										pstmt = conn.prepareStatement(sql);
										System.out.println("sql ::: " + sql);
										rs = pstmt.executeQuery();
										if (rs.next())
										{
											acctCode = rs.getString(1);
											cctrCode = rs.getString(2);
										}
										rs.close(); rs = null;
										pstmt.close(); pstmt = null;
									}
								}
							}
						}
					}
				}
				else if(purpose.equalsIgnoreCase("FRECOST")) // ACCOUNT CODE FOR AP CODE FOR FREIGHT COST
				{
					sql = " SELECT ACCT_CODE__FRE,CCTR_CODE__FRE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__FRE,CCTR_CODE__FRE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__FRE,CCTR_CODE__FRE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
							+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								if (itemSer == null || itemSer.trim().length() == 0)
								{
									sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										itemSerN = rs.getString(1);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
								else
								{
									itemSerN = itemSer;
								}

								sql = " SELECT ACCT_CODE__FRE,CCTR_CODE__FRE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__FRE,CCTR_CODE__FRE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
										+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
									if (acctCode == null  || acctCode.trim().length() == 0)
									{
										sql = " SELECT ACCT_CODE__FRE,CCTR_CODE__FRE FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
										pstmt = conn.prepareStatement(sql);
										System.out.println("sql ::: " + sql);
										rs = pstmt.executeQuery();
										if (rs.next())
										{
											acctCode = rs.getString(1);
											cctrCode = rs.getString(2);
										}
										rs.close(); rs = null;
										pstmt.close(); pstmt = null;
									}
								}
							}
						}
					}
				}
				else if(purpose.equalsIgnoreCase("CLECOST")) // ACCOUNT CODE FOR AP CODE FOR CLEARING  COST
				{
					sql = " SELECT ACCT_CODE__CLE,CCTR_CODE__CLE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__CLE,CCTR_CODE__CLE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__CLE,CCTR_CODE__CLE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
							+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								if (itemSer == null || itemSer.trim().length() == 0)
								{
									sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										itemSerN = rs.getString(1);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
								else
								{
									itemSerN = itemSer;
								}

								sql = " SELECT ACCT_CODE__CLE,CCTR_CODE__CLE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__CLE,CCTR_CODE__CLE FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
										+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
									if (acctCode == null  || acctCode.trim().length() == 0)
									{
										sql = " SELECT ACCT_CODE__CLE,CCTR_CODE__CLE FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
										pstmt = conn.prepareStatement(sql);
										System.out.println("sql ::: " + sql);
										rs = pstmt.executeQuery();
										if (rs.next())
										{
											acctCode = rs.getString(1);
											cctrCode = rs.getString(2);
										}
										rs.close(); rs = null;
										pstmt.close(); pstmt = null;
									}
								}
							}
						}
					}
				}
				else if(purpose.equalsIgnoreCase("INSCOST")) // ACCOUNT CODE DEPR FOR FIXED ASSET
				{
					sql = " SELECT ACCT_CODE__INS,CCTR_CODE__INS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
					+ " AND ITEM_SER = '" + itemSer + "' AND TRAN_TYPE = '" + tranType + "'";
					pstmt = conn.prepareStatement(sql);
					System.out.println("sql ::: " + sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close(); rs = null;
					pstmt.close(); pstmt = null;
					if (acctCode == null  || acctCode.trim().length() == 0)
					{
						sql = " SELECT ACCT_CODE__INS,CCTR_CODE__INS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
						+ " AND ITEM_SER = ' ' AND TRAN_TYPE = '" + tranType + "'";
						pstmt = conn.prepareStatement(sql);
						System.out.println("sql ::: " + sql);
						rs = pstmt.executeQuery();
						if (rs.next())
						{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
						}
						rs.close(); rs = null;
						pstmt.close(); pstmt = null;
						if (acctCode == null  || acctCode.trim().length() == 0)
						{
							sql = " SELECT ACCT_CODE__INS,CCTR_CODE__INS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = '" + itemCode + "' "
							+ " AND ITEM_SER = ' ' AND TRAN_TYPE = ' '";
							pstmt = conn.prepareStatement(sql);
							System.out.println("sql ::: " + sql);
							rs = pstmt.executeQuery();
							if (rs.next())
							{
								acctCode = rs.getString(1);
								cctrCode = rs.getString(2);
							}
							rs.close(); rs = null;
							pstmt.close(); pstmt = null;
							if (acctCode == null  || acctCode.trim().length() == 0)
							{
								if (itemSer == null || itemSer.trim().length() == 0)
								{
									sql = "SELECT ITEM_SER FROM ITEM WHERE ITEM_CODE = '" + itemCode + "'";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										itemSerN = rs.getString(1);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
								}
								else
								{
									itemSerN = itemSer;
								}

								sql = " SELECT ACCT_CODE__INS,CCTR_CODE__INS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
									+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = '" + tranType + "'";
								pstmt = conn.prepareStatement(sql);
								System.out.println("sql ::: " + sql);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									acctCode = rs.getString(1);
									cctrCode = rs.getString(2);
								}
								rs.close(); rs = null;
								pstmt.close(); pstmt = null;
								if (acctCode == null  || acctCode.trim().length() == 0)
								{
									sql = " SELECT ACCT_CODE__INS,CCTR_CODE__INS FROM ITEM_ACCT_DETR WHERE ITEM_CODE = ' ' "
										+ " AND ITEM_SER = '" + itemSerN + "' AND TRAN_TYPE = ' '";
									pstmt = conn.prepareStatement(sql);
									System.out.println("sql ::: " + sql);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										acctCode = rs.getString(1);
										cctrCode = rs.getString(2);
									}
									rs.close(); rs = null;
									pstmt.close(); pstmt = null;
									if (acctCode == null  || acctCode.trim().length() == 0)
									{
										sql = " SELECT ACCT_CODE__INS,CCTR_CODE__INS FROM ITEMSER WHERE ITEM_SER = '" + itemSerN + "'";
										pstmt = conn.prepareStatement(sql);
										System.out.println("sql ::: " + sql);
										rs = pstmt.executeQuery();
										if (rs.next())
										{
											acctCode = rs.getString(1);
											cctrCode = rs.getString(2);
										}
										rs.close(); rs = null;
										pstmt.close(); pstmt = null;
									}
								}
							}
						}
					}
				}
			}
			if (acctCode == null) acctCode = "";
			if (cctrCode == null) cctrCode = "";
		} catch (SQLException e) {

			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
			}
			catch(Exception e)
			{
				System.out.println("Exception in finally block ::"+e);
				e.printStackTrace();
			}
		}
		System.out.println("From getFromAcctDetr [" + acctCode + "," + cctrCode + "]");
		return acctCode + "," + cctrCode;
	}
	/////////////
	public String glTraceUpdate(HashMap glTrace,Connection conn) throws ITMException//Added by Jiten 16/04/07
    {
        PreparedStatement pstmt = null;
        Statement stmt = null;
        ResultSet rs = null;
        String errCode = "",errString = "",finEntity = "",siteCode = "";
        String sundryType = "",sundryCode = "",acctCode = "",cctrCode = "";
        String deptCode = "",currCode = "",empCode = "",analCode = "",projCode = "";
        String refType = "",refSer = "",refId = "",remarks = "",partyDocRef = "";
        String entryBatchNo = "",postdt = "",postOnLine = "",postStat = "",finEntCurr = "",sql= "";
        String sundryTypeAc = "",acctPrd = "",code = "",keyString = "",tranId = "";
        double exchRate = 0,drAmt = 0,crAmt = 0,tempDrAmt = 0,tempCrAmt = 0;
        Timestamp tranDate = null,effDate = null,postDate = null,chgDate = null;
        ITMDBAccessEJB itmDBAccessEJB =  null;
        ValidatorEJB validatorEJB = null;
        GenericUtility genericUtility = null;
        SimpleDateFormat sdf  = null;
		HashMap glTran = null;
        try{
            genericUtility = new GenericUtility();
            chgDate = new Timestamp(System.currentTimeMillis());
            sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
            stmt = conn.createStatement();
            itmDBAccessEJB = new ITMDBAccessEJB();
            validatorEJB = new ValidatorEJB();

            tranDate = (Timestamp)glTrace.get("tran_date");
            effDate = (Timestamp)glTrace.get("eff_date");
            finEntity = (glTrace.get("fin_entity") == null ? "":glTrace.get("fin_entity").toString());
            siteCode = (glTrace.get("site_code") == null ? "":glTrace.get("site_code").toString());
            sundryType = (glTrace.get("sundry_type") == null ? "":glTrace.get("sundry_type").toString());
            sundryCode = (glTrace.get("sundry_code") == null ? "":glTrace.get("sundry_code").toString());
            acctCode = (glTrace.get("acct_code") == null ? "":glTrace.get("acct_code").toString());
            cctrCode = (glTrace.get("cctr_code") == null ? "":glTrace.get("cctr_code").toString());
            deptCode = (glTrace.get("dept_code") == null ? "":glTrace.get("dept_code").toString());
            currCode = (glTrace.get("curr_code") == null ? "":glTrace.get("curr_code").toString());
            empCode = (glTrace.get("emp_code") == null ? "":glTrace.get("emp_code").toString());
            analCode = (glTrace.get("anal_code") == null ? "":glTrace.get("anal_code").toString());
            refType = (glTrace.get("ref_type") == null ? "":glTrace.get("ref_type").toString());
            refSer = (glTrace.get("ref_ser") == null ? "":glTrace.get("ref_ser").toString());
            refId = (glTrace.get("ref_id") == null ? "":glTrace.get("ref_id").toString());
            remarks = (glTrace.get("remarks") == null ? "":glTrace.get("remarks").toString());
            partyDocRef = (glTrace.get("party_doc_ref") == null ? "":glTrace.get("party_doc_ref").toString());
            projCode = (glTrace.get("proj_code") == null ? "":glTrace.get("proj_code").toString());

            //errCode = itmDBAccessEJB.isAcctCode(siteCode,acctCode,"X",conn);//To be uncommented later - Jiten as it is giving resultset closed.
            System.out.println("errCode "+errCode);
            if(errCode.trim().length() > 0){
                errString = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
                return errString;
            }
            errCode = "";
            errCode = itmDBAccessEJB.isCctrCode(siteCode,cctrCode,"X",conn);
            if(errCode.trim().length() > 0){
                errString = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
                return errString;
            }
            entryBatchNo = (glTrace.get("entry_batch_no") == null ? "":glTrace.get("entry_batch_no").toString());
            if(entryBatchNo != null && entryBatchNo.trim().length() > 0){
                entryBatchNo = entryBatchNo.substring(0,12);
            }
            exchRate = Double.parseDouble(glTrace.get("exch_rate").toString());
            drAmt = Double.parseDouble(glTrace.get("dr_amt").toString());
            crAmt = Double.parseDouble(glTrace.get("cr_amt").toString());
            if(exchRate == 0){
                errString = itmDBAccessEJB.getErrorString("","VTEXRAT1","","",conn);
                return errString;
            }

            tempDrAmt = drAmt * exchRate;
            tempCrAmt = crAmt * exchRate;

            postdt = getFinparams("999999", "POST_ON_DATE",conn);
            if(postdt == null || postdt.equalsIgnoreCase("NULLFOUND")){
                errString = itmDBAccessEJB.getErrorString("","VTENVAR1","","",conn);
                return errString;
            }
            if("EFF_TRAN".indexOf(postdt) == -1){
                errString = itmDBAccessEJB.getErrorString("","VTENVAR1","","",conn);
                return errString;
            }
            postOnLine = getFinparams("999999", "POST_ON_LINE",conn);
            if(postOnLine == null || postOnLine.equalsIgnoreCase("")){
                errString = itmDBAccessEJB.getErrorString("","VTENVAR1","","",conn);
                return errString;
            }
            postOnLine = postOnLine.substring(0,1);
            if("Y_N".indexOf(postOnLine) == -1){
                errString = itmDBAccessEJB.getErrorString("","VTENVAR1","","",conn);
                return errString;
            }
            sql = "select curr_code from finent where fin_entity = '"+finEntity+"'";
            rs = stmt.executeQuery(sql);
            if(rs.next()){
                finEntCurr = rs.getString(1);
            }
            rs.close();
            if(currCode.equalsIgnoreCase(finEntCurr)){
                if(exchRate > 1){
                    errString = itmDBAccessEJB.getErrorString("","VGLEXRTNE","","",conn);
                    return errString;
                }
            }

            postDate = (Timestamp)glTrace.get("tran_date");
            errCode = validatorEJB.nfCheckPeriod("FIN",new java.util.Date(postDate.getTime()),siteCode);
            if(errCode.trim().length() > 0){
                errString = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
                return errString;
            }
              //coomented by rajendra on 17/10/07
//            sql = "select case when sundry_type is null then 'O' else sundry_type end from accounts where acct_code = '"+acctCode+"'";
//            System.out.println("SQL : "+sql);
//            rs = stmt.executeQuery(sql);
//            if(rs.next()){
//                sundryTypeAc = rs.getString(1);
//            }
//            rs.close();
//            if(!sundryTypeAc.equalsIgnoreCase(sundryType)){
//                errString = itmDBAccessEJB.getErrorString("","VMACCT6","","",conn);
//                return errString;
//            }else if(sundryType == null || sundryType.trim().length() == 0 || !sundryType.equalsIgnoreCase("O")){
//                errString = itmDBAccessEJB.getErrorString("","VMACCT4","","",conn);
//                return errString;
//            }
		   //added by rajendra on 17/10/07
			errCode = isAcctType(acctCode, sundryCode, sundryType, conn);
			if(errCode != null && errCode.trim().length() > 0)
			{
                errString = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
                return errString;
            }
			//ended by rajendra on 17/10/07

            sql = "select acct_prd,code from period where fr_date <= ? and to_date >= ? ";
            System.out.println("SQL : "+sql);
            pstmt = conn.prepareStatement(sql);
            pstmt.setTimestamp(1,postDate);
            pstmt.setTimestamp(2,postDate);
            rs = pstmt.executeQuery();
            if(rs.next()){
                acctPrd = rs.getString(1);
                code = rs.getString(2);
            }
            rs.close();
            pstmt.close();
            String xmlString = "<?xml version=\"1.0\"?>\r\n<Root>\r\n<header>"+
                    "\r\n</header><Detail1><item_ser></item_ser>"+
                    "\r\n<site_code>"+siteCode+"</site_code>\r\n<tran_date>"+sdf.format(new java.util.Date(tranDate.getTime()))+"</tran_date></Detail1></Root>";

            sql = "select key_string from transetup where tran_window = 't_gltrace'";
            System.out.println("SQL :"+sql);
            rs = stmt.executeQuery(sql);
            if(rs.next()){
                keyString = rs.getString(1);
            }
            rs.close();
            TransIDGenerator tg = new TransIDGenerator(xmlString, "SYSTEM", CommonConstants.DB_NAME);
            tranId = tg.generateTranSeqID("GLTRCE", "tran_id", keyString, conn);

            if(projCode == null || projCode.trim().length() == 0){
                glTrace.put("proj_code",getProject(refSer,refId,conn));
            }
            if(entryBatchNo == null || entryBatchNo.trim().length() == 0){
                glTrace.put("entry_batch_no",getEntryBatchNo(refSer,code));
                entryBatchNo = glTrace.get("entry_batch_no").toString();
            }
            System.out.println("postOnLine : "+postOnLine);
            if(postOnLine.equalsIgnoreCase("Y")){
                postStat = "Y";
                postDate = chgDate;
                glTran = new HashMap();
                glTran.put("tran_date",(glTrace.get("tran_date") == null ? "":glTrace.get("tran_date")));//Date should be in ApplDateFormat
                glTran.put("eff_date",(glTrace.get("eff_date") == null ? "":glTrace.get("eff_date")));//Date should be in ApplDateFormat
                glTran.put("fin_entity",(glTrace.get("fin_entity") == null ? "":glTrace.get("fin_entity")));
                glTran.put("site_code",(glTrace.get("site_code") == null ? "":glTrace.get("site_code")));
                glTran.put("acct_code",(glTrace.get("acct_code") == null ? "":glTrace.get("acct_code")));
                glTran.put("cctr_code",(glTrace.get("cctr_code") == null ? "":glTrace.get("cctr_code")));
                glTran.put("dept_code",(glTrace.get("dept_code") == null ? "":glTrace.get("dept_code")));
                glTran.put("emp_code",(glTrace.get("emp_code") == null ? "":glTrace.get("emp_code")));
                glTran.put("anal_code",(glTrace.get("anal_code") == null ? "":glTrace.get("anal_code")));
                glTran.put("dr_amt",(glTrace.get("dr_amt") == null ? "":glTrace.get("dr_amt")));
                glTran.put("cr_amt",(glTrace.get("cr_amt") == null ? "":glTrace.get("cr_amt")));
                glTran.put("ref_ser",(glTrace.get("ref_ser") == null ? "":glTrace.get("ref_ser")));
                glTran.put("ref_id",(glTrace.get("ref_id") == null ? "":glTrace.get("ref_id")));
                glTran.put("remarks",(glTrace.get("remarks") == null ? "":glTrace.get("remarks")));
                glTran.put("curr_code",(glTrace.get("curr_code") == null ? "":glTrace.get("curr_code")));
                glTran.put("prd_code",code);
                glTran.put("acct_prd",acctPrd);
                glTran.put("proj_code",(glTrace.get("proj_code") == null ? "":glTrace.get("proj_code")));
                glTran.put("dr_amt_base",Double.toString(tempDrAmt));
                glTran.put("cr_amt_base",Double.toString(tempCrAmt));
                glTran.put("tran_id__trace",tranId);
                glTran.put("entry_batch_no",(glTrace.get("entry_batch_no") == null ? "":glTrace.get("entry_batch_no")));

                errString = glTranUpdate(glTran,conn);
                System.out.println("errString :: From glTranUpdate(glTran,conn) "+errString);
                if(errString != null && errString.trim().length() > 0){
                    return errString;
                }
            }else{
                postStat = "N";
                postDate = null;
            }
            sql = "insert into gltrace (tran_id, tran_date, eff_date, ref_type, ref_ser," +
                    "ref_id, fin_entity, site_code, sundry_type," +
                    "sundry_code, acct_code, cctr_code, curr_code," +
                    "exch_rate, dr_amt, cr_amt,emp_code, anal_code, remarks, post_stat, post_date," +
                    "acct_prd, prd_code, chg_date, chg_user, chg_term, " +
                    "entry_batch_no, proj_code, party_doc_ref, dept_code ) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            System.out.println("SQL : "+sql);
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1,tranId);
            pstmt.setTimestamp(2,tranDate);
            pstmt.setTimestamp(3,effDate);
            pstmt.setString(4,refType);
            pstmt.setString(5,refSer);
            pstmt.setString(6,refId);
            if(finEntity == null || finEntity.trim().length() == 0){
                pstmt.setNull(7,Types.VARCHAR);
            }else{
                pstmt.setString(7,finEntity);
            }
            pstmt.setString(8,siteCode);
            pstmt.setString(9,sundryType);
            pstmt.setString(10,sundryCode);
            if(acctCode == null || acctCode.trim().length() == 0){
                pstmt.setNull(11,Types.VARCHAR);
            }else{
                pstmt.setString(11,acctCode);
            }
//            if(cctrCode == null || cctrCode.trim().length() == 0){
//                //pstmt.setNull(12,Types.VARCHAR);
//                cctrCode = "";
//            }

            //changed by shamim on 24-07-12
            if(cctrCode == null){
                cctrCode = "    ";
            }

            pstmt.setString(12,cctrCode);
            if(currCode == null || currCode.trim().length() == 0){
                pstmt.setNull(13,Types.VARCHAR);
            }else{
                pstmt.setString(13,currCode);
            }
            pstmt.setDouble(14,exchRate);
            pstmt.setDouble(15,drAmt);
            pstmt.setDouble(16,crAmt);
            if(empCode == null || empCode.trim().length() == 0){
                pstmt.setNull(17,Types.VARCHAR);
            }else{
                pstmt.setString(17,empCode);
            }
            if(analCode == null || analCode.trim().length() == 0){
                pstmt.setNull(18,Types.VARCHAR);
            }else{
                pstmt.setString(18,analCode);
            }
            pstmt.setString(19,remarks);
            if(postStat == null || postStat.trim().length() == 0){
                pstmt.setNull(20,Types.VARCHAR);
            }else{
                pstmt.setString(20,postStat);
            }
            pstmt.setTimestamp(21,postDate);
            if(acctPrd == null || acctPrd.trim().length() == 0){
                pstmt.setNull(22,Types.VARCHAR);
            }else{
                pstmt.setString(22,acctPrd);
            }
            if(code == null || code.trim().length() == 0){
                pstmt.setNull(23,Types.VARCHAR);
            }else{
                pstmt.setString(23,code);
            }
            pstmt.setTimestamp(24,chgDate);
            pstmt.setString(25,"SYSTEM");
            pstmt.setString(26,"SYSTEM");
            pstmt.setString(27,entryBatchNo);
            pstmt.setString(28,projCode);
            pstmt.setString(29,partyDocRef);
            pstmt.setString(30,deptCode);

            System.out.println("ACCT_CODE :"+acctCode);
            System.out.println("CCTR_CODE :["+cctrCode+"]");
            System.out.println("POST_STAT :"+postStat);
            System.out.println("SITE_CODE :"+siteCode);
            System.out.println("FIN_ENTITY :"+finEntity);
            System.out.println("CURR_CODE :"+currCode);
            System.out.println("EXCH_RATE :"+exchRate);
            pstmt.executeUpdate();
            pstmt.close();

            System.out.println("errString :::: "+errString);
            if(errString != null && errString.trim().length() == 0){
                System.out.println("Calling glTraceUpdatebudget....");
                errString = glTraceUpdatebudget(tranId,refId,refSer,conn);
            }
        }catch(Exception e){
            System.out.println("Exception in GlTraceUpdate "+e);
            e.printStackTrace();
            throw new ITMException(e);
        }finally{
            try{
                if(rs != null){rs.close();rs = null;}
                if(stmt != null){stmt.close();stmt = null;}
                if(pstmt != null){pstmt.close();pstmt = null;}
            }catch(Exception e){}
        }
        System.out.println("Returning String from glTraceUpdate ::"+errString);
        return errString;
    }
	    //nvo_business_object_fin - gbf_get_project()
    public String getProject(String refSer,String refId,Connection conn) throws ITMException//Added by Jiten
    {
        Statement stmt = null;
        ResultSet rs = null;
        String sql = "",projectCode = "";
        try{
            stmt = conn.createStatement();
            if(refSer.equalsIgnoreCase("JOUR")){
                sql = "select proj_code from journal where tran_id = '"+refId+"'";
            }
            if(refSer.equalsIgnoreCase("E-PAY")){
                sql = "select proj_code from payment_exp where tran_id = '"+refId+"'";
            }
            if(refSer.equalsIgnoreCase("M-VOUC")){
                sql = "select proj_code from misc_voucher where tran_id = '"+refId+"'";
            }
            if(refSer.equalsIgnoreCase("VOUCH")){
                sql = "select proj_code from voucher where tran_id = '"+refId+"'";
            }
            if(sql.trim().length() > 0){
                rs = stmt.executeQuery(sql);
                if(rs.next()){
                    projectCode = rs.getString(1);
                }
                if(projectCode == null){
                    projectCode = "";
                }
            }

        }catch(Exception e){
            System.out.println("Exception in getProject [Fincommon]"+e);
            e.printStackTrace();
            throw new ITMException(e);
        }
        finally{
            try{
                if(stmt != null) stmt.close();
                if(rs != null)rs.close();
            }catch(Exception e1){}
        }
        return projectCode;
    }
	//nvo_business_object_fin - gbf_get_entry_batch_no()
    public String getEntryBatchNo(String refSer,String periodCode) throws ITMException//Added by Jiten
    {
        String entryBatchNo = "";
        try{
            if(refSer.equalsIgnoreCase("S-INV") || refSer.equalsIgnoreCase("D-ISS") || refSer.equalsIgnoreCase("D-RCP") ||
                    refSer.equalsIgnoreCase("S-DSP") || refSer.equalsIgnoreCase("P-RCP") || refSer.equalsIgnoreCase("C-ISS") ||
                    refSer.equalsIgnoreCase("W-ISS") || refSer.equalsIgnoreCase("W-RCP") || refSer.equalsIgnoreCase("ADJISS") ||
                    refSer.equalsIgnoreCase("ADJRCP") || refSer.equalsIgnoreCase("VOUCH") || refSer.equalsIgnoreCase("CRNRCP") ||
                    refSer.equalsIgnoreCase("DRNRCP") || refSer.equalsIgnoreCase("MDRCRC") || refSer.equalsIgnoreCase("MDRCRD") ||
                    refSer.equalsIgnoreCase("P-VOUC") || refSer.equalsIgnoreCase("RCP") || refSer.equalsIgnoreCase("R-DIS") ||
                    refSer.equalsIgnoreCase("M-RCP") || refSer.equalsIgnoreCase("M-PAY") || refSer.equalsIgnoreCase("MPCANC") ||
                    refSer.equalsIgnoreCase("E-PAY") || refSer.equalsIgnoreCase("S-RET") || refSer.equalsIgnoreCase("P-RET") ||
                    refSer.equalsIgnoreCase("M-VOUC") || refSer.equalsIgnoreCase("P-IBCA") || refSer.equalsIgnoreCase("R-IBCA")){
                entryBatchNo = refSer.concat(periodCode);
            }else{
                entryBatchNo = " ";
            }
        }catch(Exception e){
            System.out.println("Exception in getEntryBatchNo[FinCommon]"+e);
            e.printStackTrace();
            throw new ITMException(e);
        }
        return entryBatchNo;
    }
	    //nvo_business_object_fin - gbf_gltran_upd()
    public String glTranUpdate(HashMap glTran,Connection conn) throws ITMException // added by Jiten
    {
        PreparedStatement pstmt = null;
        Statement stmt = null;
        ResultSet rs = null;
        String sql = "",ledgPost = "",errString = "";
        String glTranId = "",keyString = "",tranIdTrace = "";
        String openPeriod = "000000",closePeriod = "zzzzzz";
        Timestamp chgDate = null,tranDate = null,effDate = null;
        double drAmtBase = 0,crAmtBase = 0;
        SimpleDateFormat sdf = null;
        GenericUtility genericUtility = null;
        ITMDBAccessEJB itmDBAccessEJB = null;
        int cnt;
        try{
            stmt = conn.createStatement();
            genericUtility = new GenericUtility();
            sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
            itmDBAccessEJB = new ITMDBAccessEJB();
            chgDate = new Timestamp(System.currentTimeMillis());
            drAmtBase = Double.parseDouble(glTran.get("dr_amt_base").toString());
            crAmtBase = Double.parseDouble(glTran.get("cr_amt_base").toString());
            //Date should be in applDate Format
            tranDate = (Timestamp)glTran.get("tran_date");
            effDate = (Timestamp)glTran.get("eff_date");

            if(glTran.get("entry_batch_no").toString() == null || glTran.get("entry_batch_no").toString().trim().length() == 0){
                glTran.put("entry_batch_no"," ");
            }
            if(drAmtBase == 0 && crAmtBase == 0){
                return "";
            }
            sql = "select ledg_post from accounts where acct_code = '"+glTran.get("acct_code").toString()+"'";
            System.out.println("SQL :"+sql);
            rs = stmt.executeQuery(sql);
            if(rs.next()){
                ledgPost = rs.getString(1);
            }
            if(ledgPost == null){
                ledgPost = "D";
            }
            cnt = 0;
            if(ledgPost.equals("S")){
                if(glTran.get("entry_batch_no").toString().length() == 0){
                    cnt = 0;
                }
                sql = "select count(*) from gltran where prd_code = '"+glTran.get("prd_code").toString()+"' and site_code = '"+glTran.get("site_code").toString()+"' and " +
                        "acct_code = '"+glTran.get("acct_code").toString()+"' and cctr_code = '"+glTran.get("cctr_code").toString()+"' and tran_id__trace ='"+glTran.get("entry_batch_no").toString()+"'";
                System.out.println("SQL :"+sql);
                rs = stmt.executeQuery(sql);
                if(rs.next()){
                    cnt = rs.getInt(1);
                }
                rs.close();
                if(cnt > 1){
                    errString = itmDBAccessEJB.getErrorString("","VTGLTRAN1","","",conn);
                    return errString;
                }else if(cnt == 1){
                    sql = "update gltran set dr_amt = dr_amt + ? ," +
                            "cr_amt = cr_amt + ? ," +
                            "tran_date = ? ," +
                            "eff_date = ? ," +
                            "chg_date = ?," +
                            "chg_user = ?," +
                            "chg_term = ? " +
                            "where prd_code = ? and site_code = ? and acct_code = ? and cctr_code = ? " +
                            "and tran_id__trace = ? ";
                    System.out.println("SQL :"+sql);
                    pstmt = conn.prepareStatement(sql);
                    pstmt.setDouble(1,drAmtBase);
                    pstmt.setDouble(2,crAmtBase);
                    pstmt.setTimestamp(3,tranDate);
                    pstmt.setTimestamp(4,effDate);
                    pstmt.setTimestamp(5,chgDate);
                    pstmt.setString(6,"SYSTEM");
                    pstmt.setString(7,"SYSTEM");
                    pstmt.setString(8,glTran.get("prd_code").toString());
                    pstmt.setString(9,glTran.get("site_code").toString());
                    pstmt.setString(10,glTran.get("acct_code").toString());
                    pstmt.setString(11,glTran.get("cctr_code").toString());
                    pstmt.setString(12,glTran.get("entry_batch_no").toString());
                    pstmt.executeUpdate();
                }
            }
            if(cnt == 0){
                String xmlString = "<?xml version=\"1.0\"?>\r\n<Root>\r\n<header>"+
                "\r\n</header><Detail1><item_ser></item_ser>"+
                "\r\n<site_code>"+glTran.get("site_code").toString()+"</site_code>\r\n<tran_date>"+
                sdf.format((Timestamp)glTran.get("tran_date"))+"</tran_date></Detail1></Root>";

                sql = "select key_string from transetup where tran_window = 't_gltran'";
                System.out.println("SQL : "+sql);
                rs = stmt.executeQuery(sql);
                if(rs.next()){
                    keyString = rs.getString(1);
                }
                rs.close();
                TransIDGenerator tg = new TransIDGenerator(xmlString, "SYSTEM", CommonConstants.DB_NAME);
                glTranId = tg.generateTranSeqID("GLTRAN", "tran_id", keyString, conn);
                if(ledgPost.equals("S")){
                    if(glTran.get("entry_batch_no") == null || glTran.get("entry_batch_no").toString().trim().length() == 0){
                        tranIdTrace = glTran.get("tran_id__trace").toString();
                    }else{
                        glTran.put("ref_id","");
                        tranIdTrace = glTran.get("entry_batch_no").toString().trim();
                    }
                }else{
                    tranIdTrace = glTran.get("tran_id__trace").toString().trim();
                }
                sql = "insert into gltran (tran_id, tran_date, eff_date, ref_ser," +
                        "ref_id, fin_entity, site_code, acct_code, cctr_code," +
                        "dr_amt, cr_amt, emp_code, anal_code, remarks," +
                        "acct_prd, prd_code, chg_date, chg_user," +
                        "chg_term, tran_id__trace, proj_code,dept_code) " +
                        "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                System.out.println("SQL :"+sql);
                pstmt = conn.prepareStatement(sql);
                pstmt.setString(1,glTranId);
                pstmt.setTimestamp(2,tranDate);
                pstmt.setTimestamp(3,effDate);
                pstmt.setString(4,glTran.get("ref_ser").toString());
                pstmt.setString(5,glTran.get("ref_id").toString());
                String finEntity = (String)glTran.get("fin_entity");
                if(finEntity == null || finEntity.trim().length() == 0){
                    pstmt.setNull(6,Types.VARCHAR);
                }else{
                    pstmt.setString(6,finEntity);
                }
                pstmt.setString(7,glTran.get("site_code").toString());
                String acctCode = (String)glTran.get("acct_code");
                if(acctCode == null || acctCode.trim().length() == 0){
                    pstmt.setNull(8,Types.VARCHAR);
                }else{
                    pstmt.setString(8,acctCode);
                }
                String cctrCode = (String)glTran.get("cctr_code");
                if(cctrCode == null || cctrCode.trim().length() == 0){
                    pstmt.setNull(9,Types.VARCHAR);
                }else{
                    pstmt.setString(9,cctrCode);
                }
                pstmt.setDouble(10,drAmtBase);
                pstmt.setDouble(11,crAmtBase);
                String empCode = glTran.get("emp_code").toString();
                if(empCode == null || empCode.trim().length() == 0){
                    pstmt.setNull(12,Types.VARCHAR);
                }else{
                    pstmt.setString(12,empCode);
                }
                String analCode = (String)glTran.get("anal_code");
                if(analCode == null || analCode.trim().length() == 0){
                    pstmt.setNull(13,Types.VARCHAR);
                }else{
                    pstmt.setString(13,analCode);
                }
                pstmt.setString(14,glTran.get("remarks").toString());
                String acctPrd = (String)glTran.get("acct_prd");
                if(acctPrd == null || acctPrd.trim().length() == 0){
                    pstmt.setNull(15,Types.VARCHAR);
                }else{
                    pstmt.setString(15,acctPrd);
                }
                String prdCode = (String)glTran.get("prd_code");
                if(prdCode == null || prdCode.trim().length() == 0){
                    pstmt.setNull(16,Types.VARCHAR);
                }else{
                    pstmt.setString(16,prdCode);
                }
                pstmt.setTimestamp(17,chgDate);
                pstmt.setString(18,"SYSTEM");
                pstmt.setString(19,"SYSTEM");
                pstmt.setString(20,tranIdTrace);
                pstmt.setString(21,glTran.get("proj_code").toString());
                pstmt.setString(22,glTran.get("dept_code").toString());
                pstmt.executeUpdate();

                pstmt.close();
            }
            sql ="select count(*) from acctbal where acct_prd = '"+glTran.get("acct_prd").toString()+"' " +
                    "and prd_code = '"+openPeriod+"' " +
                    "and fin_entity = '"+glTran.get("fin_entity").toString()+"' " +
                    "and site_code = '"+glTran.get("site_code").toString()+"' " +
                    "and acct_code = '"+glTran.get("acct_code").toString()+"' and " +
                    "cctr_code = '"+glTran.get("cctr_code").toString()+"'";
            System.out.println("SQL :"+sql);
            rs = stmt.executeQuery(sql);
            if(rs.next()){
                cnt = rs.getInt(1);
            }
            rs.close();
            if(cnt == 0){
                sql = "insert into acctbal (acct_prd, prd_code, fin_entity, site_code, " +
                        "acct_code, cctr_code, curr_code__ac, dr_amt, cr_amt," +
                        "dr_amt__base, cr_amt__base, chg_date, chg_user, chg_term) " +
                        "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                System.out.println("SQL :"+sql);
                pstmt = conn.prepareStatement(sql);
                pstmt.setString(1,glTran.get("acct_prd").toString());
                pstmt.setString(2,openPeriod);
                pstmt.setString(3,glTran.get("fin_entity").toString());
                pstmt.setString(4,glTran.get("site_code").toString());
                pstmt.setString(5,glTran.get("acct_code").toString());
                pstmt.setString(6,glTran.get("cctr_code").toString());
                pstmt.setString(7,glTran.get("curr_code").toString());
                pstmt.setInt(8,0);
                pstmt.setInt(9,0);
                pstmt.setInt(10,0);
                pstmt.setInt(11,0);
                pstmt.setTimestamp(12,chgDate);
                pstmt.setString(13,"SYSTEM");
                pstmt.setString(14,"SYSTEM");

                pstmt.executeUpdate();

                pstmt.close();
            }
            sql = "select count(*) from acctbal where acct_prd = '"+glTran.get("acct_prd").toString()+"' " +
                    "and prd_code = '"+glTran.get("prd_code").toString()+"' " +
                    "and fin_entity = '"+glTran.get("fin_entity").toString()+"' " +
                    "and site_code = '"+glTran.get("site_code").toString()+"' " +
                    "and acct_code = '"+glTran.get("acct_code").toString()+"' " +
                    "and cctr_code = '"+glTran.get("cctr_code").toString()+"'";
            System.out.println("SQL :"+sql);
            rs = stmt.executeQuery(sql);
            if(rs.next()){
                cnt = rs.getInt(1);
            }
            if(cnt == 0){
                sql = "insert into acctbal (acct_prd, prd_code, fin_entity, site_code," +
                        "acct_code, cctr_code, curr_code__ac, dr_amt, cr_amt," +
                        "dr_amt__base, cr_amt__base, chg_date, chg_user, chg_term) " +
                        "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                System.out.println("SQL :"+sql);
                pstmt = conn.prepareStatement(sql);
                pstmt.setString(1,glTran.get("acct_prd").toString());
                pstmt.setString(2,glTran.get("prd_code").toString());
                pstmt.setString(3,glTran.get("fin_entity").toString());
                pstmt.setString(4,glTran.get("site_code").toString());
                pstmt.setString(5,glTran.get("acct_code").toString());
                pstmt.setString(6,glTran.get("cctr_code").toString());
                pstmt.setString(7,glTran.get("curr_code").toString());
                pstmt.setString(8,glTran.get("dr_amt").toString());
                pstmt.setString(9,glTran.get("cr_amt").toString());
                pstmt.setDouble(10,drAmtBase);
                pstmt.setDouble(11,crAmtBase);
                pstmt.setTimestamp(12,chgDate);
                pstmt.setString(13,"SYSTEM");
                pstmt.setString(14,"SYSTEM");

                pstmt.executeUpdate();
                pstmt.close();
            }else{
                sql = "update acctbal set dr_amt = dr_amt + "+Double.parseDouble(glTran.get("dr_amt").toString())+" ," +
                        "cr_amt = cr_amt + "+Double.parseDouble(glTran.get("cr_amt").toString())+", " +
                        "dr_amt__base = dr_amt__base + "+drAmtBase+"," +
                        "cr_amt__base = cr_amt__base + "+crAmtBase+" " +
                        "where acct_prd = '"+glTran.get("acct_prd").toString()+"' " +
                        "and prd_code = '"+glTran.get("prd_code").toString()+"' " +
                        "and fin_entity = '"+glTran.get("fin_entity").toString()+"' and " +
                        "site_code = '"+glTran.get("site_code").toString()+"' " +
                        "and acct_code = '"+glTran.get("acct_code").toString()+"' " +
                        "and cctr_code = '"+glTran.get("cctr_code").toString()+"' ";
                System.out.println("SQL :"+sql);
                pstmt = conn.prepareStatement(sql);
                pstmt.executeUpdate();
                pstmt.close();

            }
            sql = "select count(*) from acctbal where acct_prd = '"+glTran.get("acct_prd").toString()+"' " +
                    "and prd_code = '"+closePeriod+"' and fin_entity = '"+glTran.get("fin_entity").toString()+"' " +
                    "and site_code = '"+glTran.get("site_code").toString()+"' " +
                    "and acct_code = '"+glTran.get("acct_code").toString()+"' " +
                    "and cctr_code = '"+glTran.get("cctr_code").toString()+"'";
            System.out.println("SQL :"+sql);
            rs = stmt.executeQuery(sql);
            if(rs.next()){
                cnt = rs.getInt(1);
            }
            rs.close();
            if(cnt == 0){
                sql = "insert into acctbal (acct_prd, prd_code, fin_entity, site_code," +
                        "acct_code, cctr_code, curr_code__ac, dr_amt, cr_amt," +
                        "dr_amt__base, cr_amt__base, chg_date, chg_user, chg_term) " +
                        "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                System.out.println("SQL :"+sql);
                pstmt = conn.prepareStatement(sql);
                pstmt.setString(1,glTran.get("acct_prd").toString());
                pstmt.setString(2,closePeriod);
                pstmt.setString(3,glTran.get("fin_entity").toString());
                pstmt.setString(4,glTran.get("site_code").toString());
                pstmt.setString(5,glTran.get("acct_code").toString());
                pstmt.setString(6,glTran.get("cctr_code").toString());
                pstmt.setString(7,glTran.get("curr_code").toString());
                pstmt.setString(8,glTran.get("dr_amt").toString());
                pstmt.setString(9,glTran.get("cr_amt").toString());
                pstmt.setDouble(10,drAmtBase);
                pstmt.setDouble(11,crAmtBase);
                pstmt.setTimestamp(12,chgDate);
                pstmt.setString(13,"SYSTEM");
                pstmt.setString(14,"SYSTEM");
                pstmt.executeUpdate();
                pstmt.close();
            }else{
                sql = "update acctbal set dr_amt = dr_amt + "+Double.parseDouble(glTran.get("dr_amt").toString())+"," +
                        "cr_amt = cr_amt + "+Double.parseDouble(glTran.get("cr_amt").toString())+"," +
                        "dr_amt__base = dr_amt__base + "+drAmtBase+"," +
                        "cr_amt__base = cr_amt__base + "+crAmtBase+" " +
                        "where acct_prd = '"+glTran.get("acct_prd").toString()+"' " +
                        "and prd_code = '"+closePeriod+"' and fin_entity = '"+glTran.get("fin_entity").toString()+"' " +
                        "and site_code = '"+glTran.get("site_code").toString()+"' " +
                        "and acct_code = '"+glTran.get("acct_code").toString()+"' and " +
                        "cctr_code = '"+glTran.get("cctr_code").toString()+"'";
                System.out.println("SQL :"+sql);
                stmt.executeUpdate(sql);
            }
        }catch(Exception e){
            System.out.println("Exception in glTranUpdate[FinCommon]"+e);
            e.printStackTrace();
            throw new ITMException(e);
        }finally{
            try{
                if(rs != null){rs.close();rs = null;}
                if(stmt != null){stmt.close();stmt = null;}
                if(pstmt != null){pstmt.close();pstmt = null;}
            }catch(Exception t){}
        }
        return errString;
    }
	    //nvo_business_object_budget - gbf_gltrace_update_budget
    public String glTraceUpdatebudget(String tranId,String refId,String refSer,Connection conn) throws ITMException // Added by Jiten
    {
        Statement stmt = null,stmt1 = null;
        ResultSet rs = null,rs1 = null;
        StringBuffer budgetXml = null;
        String sql = "",activeBudget = "";
        String errString = "",projCode = "",siteCode = "",analCode = "";
        String acctCode = "",cctrCode = "",deptCode = "",typeBal = "";
        double drAmt = 0,crAmt = 0,amount = 0;
        GenericUtility genericUtility = null;
        SimpleDateFormat sdf = null;
        ITMDBAccessEJB itmDBAccessEJB = null;
        java.util.Date tranDate = null;
        try{
            System.out.println("In glTraceUpdatebudget ");
            genericUtility = new GenericUtility();
            sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
            itmDBAccessEJB = new ITMDBAccessEJB();
            budgetXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root>\r\n<header>\r\n</header>");
            activeBudget = getFinparams("999999","ACTIVE_BUDGET",conn);
            System.out.println("ACTIVE_BUDGET :: "+activeBudget);
            if(activeBudget != null && activeBudget.equalsIgnoreCase("NULLFOUND")){
                errString = itmDBAccessEJB.getErrorString("","VTFINPARM","");
                return errString;
            }
            if(activeBudget == null || activeBudget.equalsIgnoreCase("N")){
                return "";
            }
            stmt = conn.createStatement();
            sql = "select tran_date,proj_code,site_code,acct_code,cctr_code,dept_code,round(dr_amt * exch_rate, 3)," +
                    "round(cr_amt * exch_rate, 3),anal_code from " +
                    "gltrace where ref_ser = '"+refSer+"' and ref_id = '"+refId+"' and tran_id = '"+tranId+"'";
            System.out.println("SQL :"+sql);
            rs = stmt.executeQuery(sql);

            stmt1 = conn.createStatement();
            while(rs.next()){
                tranDate = rs.getDate(1);
                projCode = rs.getString(2);
                siteCode = rs.getString(3);
                acctCode = rs.getString(4);
                cctrCode = rs.getString(5);
                deptCode = rs.getString(6);
                drAmt = rs.getDouble(7);
                crAmt = rs.getDouble(8);
                analCode = rs.getString(9);
                if(analCode == null){
                    analCode = "";
                }
                sql = "select typ_bal from accounts where acct_code = '"+acctCode+"'";
                System.out.println("SQL : "+sql);
                rs1 = stmt1.executeQuery(sql);
                if(rs1.next()){
                    typeBal = rs1.getString(1);
                }
                if(typeBal == null){
                    typeBal = "D";
                }
                if(typeBal.equalsIgnoreCase("D")){
                    amount = drAmt - crAmt;
                }else{
                    amount = crAmt - drAmt;
                }
                budgetXml.append("<Detail1>");
                budgetXml.append("<site_code><![CDATA["+siteCode+"]]></site_code>");
                budgetXml.append("<proj_code><![CDATA["+projCode+"]]></proj_code>");
                budgetXml.append("<tran_date><![CDATA["+sdf.format(tranDate)+"]]></tran_date>");
                budgetXml.append("<acct_code><![CDATA["+acctCode+"]]></acct_code>");
                budgetXml.append("<cctr_code><![CDATA["+cctrCode+"]]></cctr_code>");
                budgetXml.append("<dept_code><![CDATA["+deptCode+"]]></dept_code>");
                budgetXml.append("<upd_type><![CDATA[C]]></upd_type>");
                budgetXml.append("<tran_type><![CDATA["+refSer+"]]></tran_type>");
                budgetXml.append("<amount><![CDATA["+amount+"]]></amount>");
                budgetXml.append("<anal_code><![CDATA["+analCode+"]]></anal_code>");
                budgetXml.append("</Detail1>");
            }
            budgetXml.append("</Root>");

            System.out.print("Budget Xml String to update Budget :: "+budgetXml.toString());
            errString = updateBudget(budgetXml.toString(),"",conn);

        }catch(Exception e){
            System.out.println("Exception in glTraceUpdatebudget[StockUpdate]"+e);
            e.printStackTrace();
            throw new ITMException(e);
        }finally{
            try{
                if(rs != null){rs.close();rs = null;}
                if(rs1 != null){rs1.close();rs1 = null;}
                if(stmt != null){stmt.close();stmt = null;}
                if(stmt1 != null){stmt1.close();stmt1 = null;}
            }catch(Exception t){}
        }
        System.out.println("Returning String glTraceUpdatebudget :"+errString);
        return errString;
    }
	    //nvo_business_object_budget - gbf_update_budget
    public String updateBudget(String budgetXmlString,String warning,Connection conn) throws ITMException// Added by Jiten
    {
        PreparedStatement pstmt= null;
        Statement stmt = null;
        ResultSet rs = null;
        Document dom = null;
        String sql = "";
        boolean acctBudget = false;
        String activeBudget = "",errString = "",acctEff = "";
        String tranDate = "",siteCode = "",acctCode = "",cctrCode = "";
        String deptCode = "",projCode = "",updType = "",tranType = "";
        String analCode = "",checkFlag = "";
        String budgetCode = "",allocation = "";
        String tranIdAlloc = "",indAmtStr = "";
        double allocBa = 0,reqAmtBa = 0,conAmtBa = 0,reqAmtPoBa = 0;
        double reqPo = 0;
        double budgetAmt = 0,conAmt = 0,reqDir = 0,reqAlloc = 0,alloc = 0;
        double amount = 0,indAmount = 0,allocAmtPo = 0;
        ITMDBAccessEJB itmDBAccessEJB = null;
        GenericUtility genericUtility = null;
        NodeList detailNodes = null;
        Node detailNode = null;
        int detailLength = 0;
        try{
            genericUtility = new GenericUtility();
            itmDBAccessEJB = new ITMDBAccessEJB();
            activeBudget = getFinparams("999999","ACTIVE_BUDGET",conn);
            if(activeBudget != null && activeBudget.equalsIgnoreCase("NULLFOUND")){
                errString = itmDBAccessEJB.getErrorString("","VTFINPARM","","",conn);
                return errString;
            }
            System.out.println("activeBudget :: "+activeBudget);
            if(activeBudget == null || activeBudget.equalsIgnoreCase("N")){
                return "";
            }
            acctEff = getFinparams("999999","INV_ACCT_PORCP",conn);
            System.out.println("acctEff :: "+acctEff);
            if(acctEff != null && acctEff.equalsIgnoreCase("NULLFOUND")){
                errString = itmDBAccessEJB.getErrorString("","VTFINPARM","","",conn);
                return errString;
            }

            System.out.println("Parsing Budget String : "+budgetXmlString);
            dom = genericUtility.parseString(budgetXmlString);
            detailNodes = dom.getElementsByTagName("Detail1");
            detailLength = detailNodes.getLength();
            if(detailLength == 0){
                errString = itmDBAccessEJB.getErrorString("","VTIMPNOREC","","",conn);
                return errString;
            }
            for(int node = 0 ;node < detailLength; node++){
                acctBudget = false;
                detailNode = detailNodes.item(node);

                tranDate = genericUtility.getColumnValueFromNode("tran_date",detailNode);
                siteCode = genericUtility.getColumnValueFromNode("site_code",detailNode);
                acctCode = genericUtility.getColumnValueFromNode("acct_code",detailNode);
                cctrCode = genericUtility.getColumnValueFromNode("cctr_code",detailNode);
                deptCode = genericUtility.getColumnValueFromNode("dept_code",detailNode);
                projCode = genericUtility.getColumnValueFromNode("proj_code",detailNode);
                amount = Double.parseDouble(genericUtility.getColumnValueFromNode("amount",detailNode));
                updType = genericUtility.getColumnValueFromNode("upd_type",detailNode);
                tranType = genericUtility.getColumnValueFromNode("tran_type",detailNode);
                indAmtStr = genericUtility.getColumnValueFromNode("ind_amount",detailNode);
                if(indAmtStr == null || indAmtStr.trim().length() == 0){
                    indAmtStr = "0";
                }
                indAmount = Double.parseDouble(indAmtStr);
                analCode = genericUtility.getColumnValueFromNode("anal_code",detailNode);

                if(deptCode == null || deptCode.trim().length() == 0){
                    deptCode = " ";
                }

                sql = "select a.budget_id, case when b.alloc_reqd is null then ' ' else b.alloc_reqd end , " +
                        "(case when a.budget_amt is null then 0 else a.budget_amt end) + " +
                        "(case when a.adhoc_amt is null then 0 else a.adhoc_amt end)," +
                        "case when a.con_amt is null then 0 else a.con_amt end, " +
                        "case when a.dir_req_amt is null then 0 else a.dir_req_amt end , "+
                        "case when a.alloc_req_amt is null then 0  else a.alloc_req_amt end, "+
                        "case when a.alloc_amt is null then 0 else a.alloc_amt end, "+
                        "check_type,a.alloc_amt_po " +
                        "from acctbudget a, budgets b    " +
                        "where a.budget_id = b.budget_id "+
                        "and a.from_date <= ? and a.to_date >= ?  and a.site_code = '"+siteCode+"' "+
                        "and a.acct_code = '"+acctCode+"' and a.cctr_code = '"+cctrCode+"' " +
                        "and b.def_budget = 'Y' "+
                        "and a.dept_code = '"+deptCode+"' "+
                        "and a.anal_code = '"+analCode+"' ";
                System.out.println("SQL :"+sql);
                pstmt = conn.prepareStatement(sql);

                pstmt.setTimestamp(1,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
                pstmt.setTimestamp(2,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));

                rs = pstmt.executeQuery();
                if(rs.next()){
                    budgetCode = rs.getString(1);
                    allocation = rs.getString(2);
                    budgetAmt = rs.getDouble(3);
                    conAmt = rs.getDouble(4);
                    reqDir = rs.getDouble(5);
                    reqAlloc = rs.getDouble(6);
                    alloc = rs.getDouble(7);
                    checkFlag = rs.getString(8);
                    allocAmtPo = rs.getDouble(9);
                }else{
                    acctBudget = true;
                }
                rs.close();
                pstmt.close();

                sql = "select a.tran_id, "+
                    "case when round(b.alloc_amt * a.exch_rate,3) IS NULL THEN 0 else round(b.alloc_amt * a.exch_rate,3) END, "+
                    "case when round(b.req_amt * a.exch_rate,3) is null then 0 else round(b.req_amt * a.exch_rate,3) end, "+
                    "case when round(b.consume_amt * a.exch_rate,3) is null then 0 else round(b.consume_amt * a.exch_rate,3) end,"+
                    "case when round(b.alloc_amt_po * a.exch_rate,3) is null then 0 else round(b.alloc_amt_po * a.exch_rate,3) end  "+
                    "from budget_alloc a, budget_alloc_det b "+
                    "where a.tran_id   = b.tran_id "+
                    "and a.site_code = '"+siteCode+"' and a.budget_id = '"+budgetCode+"' "+
                    "and a.proj_code = '"+projCode+"' "+
                    "and a.fr_date <= ? and a.to_date  >=  ? "+
                    "and b.acct_code = '"+acctCode+"' and b.cctr_code = '"+cctrCode+"' "+
                    "and b.anal_code = '"+analCode+"' "+
                    "and (case when a.confirmed is null then 'N' else a.confirmed end = 'Y')";
                System.out.println("SQL :"+sql);
                pstmt = conn.prepareStatement(sql);

                pstmt.setTimestamp(1,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
                pstmt.setTimestamp(2,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));

                rs = pstmt.executeQuery();
                if(rs.next()){
                   tranIdAlloc = rs.getString(1);
                   allocBa = rs.getDouble(2);
                   reqAmtBa = rs.getDouble(3);
                   conAmtBa = rs.getDouble(4);
                   reqAmtPoBa = rs.getDouble(5);

                   if(projCode != null && projCode.trim().length() > 0){
                       if(!checkFlag.equalsIgnoreCase("I")){
                           if(tranType.equalsIgnoreCase("VOUCH") || tranType.equalsIgnoreCase("P-RCP")){
                               reqAmtPoBa = 0;
                           }
                           if(allocBa - conAmtBa - reqAmtBa - reqAmtPoBa + indAmount < amount){
                               errString = itmDBAccessEJB.getErrorString("","VTACCTBUD1","","",conn);
                               //return errString;
                               if(checkFlag.equalsIgnoreCase("E")){
                                   break;
                               }
                               if(checkFlag.equalsIgnoreCase("W")){
                                   warning = "Voucher Amount is greater than the Budget limit";
                                   errString = "";
                               }
                           }
                       }
                       if(allocation.equalsIgnoreCase("Y")){
                           errString = itmDBAccessEJB.getErrorString("","VTBUDALLOC","","",conn);
                           break;
                       }
                   }
                   int updCnt = 0;
                   if(updType.equalsIgnoreCase("C")){
                       if((tranType.equalsIgnoreCase("VOUCH") && acctEff.equalsIgnoreCase("N")) || (tranType.equalsIgnoreCase("P-RCP") && acctEff.equalsIgnoreCase("Y"))){
                           reqPo = amount;
                       }else{
                           reqPo = 0;
                       }
                       sql = "update budget_alloc_det " +
                            "set consume_amt = consume_amt + "+amount+" ," +
                            "req_amt  = req_amt - "+indAmount+" ," +
                            "alloc_amt_po = alloc_amt_po - "+reqPo+" " +
                            "where tran_id = '"+tranIdAlloc+"' " +
                            "and acct_code = '"+acctCode+"' " +
                            "and cctr_code = '"+cctrCode+"' " +
                            "and anal_code = '"+analCode+"'";
                       System.out.println("SQL :"+sql);
                       updCnt = stmt.executeUpdate(sql);

                   }else{
                       if(tranType.equalsIgnoreCase("PORD")){
                           sql = "update budget_alloc_det " +
                                "set alloc_amt_po = alloc_amt_po + "+amount+" ," +
                                "req_amt  = req_amt - "+indAmount+" " +
                                "where tran_id = '"+tranIdAlloc+"' " +
                                "and acct_code = '"+acctCode+"' " +
                                "and cctr_code = '"+cctrCode+"' " +
                                "and anal_code = '"+analCode+"'";
                           System.out.println("SQL :"+sql);
                           updCnt = stmt.executeUpdate(sql);
                       }else{
                           sql = "update budget_alloc_det " +
                                "set req_amt = req_amt + "+amount+" " +
                                "where tran_id = '"+tranIdAlloc+"' " +
                                "and acct_code = '"+acctCode+"' " +
                                "and cctr_code = '"+cctrCode+"' " +
                                "and anal_code = '"+analCode+"'";
                           System.out.println("SQL :"+sql);
                           updCnt = stmt.executeUpdate(sql);
                       }
                       if(updCnt <= 0){
                           errString = itmDBAccessEJB.getErrorString("","VTACCTBUD","","",conn);
                           break;
                       }else{
                           continue;
                       }
                   }
                }else{//2nd sql
                    rs.close();
                    pstmt.close();
                    sql = "select a.tran_id, "+
                            "round(b.alloc_amt * a.exch_rate,3), "+
                            "round(b.req_amt * a.exch_rate,3), "+
                            "round(b.consume_amt * a.exch_rate,3),"+
                            "round(b.alloc_amt_po * a.exch_rate,3)  "+
                            "from budget_alloc a, budget_alloc_det b "+
                            "where a.tran_id   = b.tran_id "+
                            "and a.site_code = '"+siteCode+"' "+
                            "and a.proj_code = '"+projCode+"' "+
                            "and a.fr_date <= ? and a.to_date  >=  ? " +
                            "and b.acct_code = '"+acctCode+"' "+
                            "and b.cctr_code = '"+cctrCode+"' "+
                            "and b.anal_code = '"+analCode+"' " +
                            "and (case when a.confirmed is null then 'N' else a.confirmed end = 'Y') "+
                            "and (a.budget_id is null or a.budget_id = '')";
                    System.out.println("SQL :"+sql);
                    pstmt = conn.prepareStatement(sql);
                    pstmt.setTimestamp(1,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
                    pstmt.setTimestamp(2,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));

                    rs = pstmt.executeQuery();
                    if(rs.next()){
                        tranIdAlloc = rs.getString(1);
                        allocBa = rs.getDouble(2);
                        reqAmtBa = rs.getDouble(3);
                        conAmtBa = rs.getDouble(4);
                        reqAmtPoBa = rs.getDouble(5);

                        if(!checkFlag.equalsIgnoreCase("I")){
                            if(tranType.equalsIgnoreCase("VOUCH") || tranType.equalsIgnoreCase("P-RCP")){
                                reqAmtPoBa = 0;
                            }
                            if(allocBa - conAmtBa - reqAmtBa - reqAmtPoBa + indAmount < amount){
                                errString = itmDBAccessEJB.getErrorString("","VTACCTBUD1","","",conn);
                                //return errString;
                                if(checkFlag.equalsIgnoreCase("E")){
                                    break;
                                }
                                if(checkFlag.equalsIgnoreCase("W")){
                                    warning = "Voucher Amount is greater than the Allocated budget limit";
                                    errString = "";
                                }
                            }
                        }
                        int updCount = 0;
                        if(updType.equalsIgnoreCase("C")){
                            if((tranType.equalsIgnoreCase("VOUCH") && acctEff.equalsIgnoreCase("N")) || (tranType.equalsIgnoreCase("P-RCP") && acctEff.equalsIgnoreCase("Y")) ){
                                reqPo = amount;
                            }else{
                                reqPo = 0;
                            }
                            sql = "update budget_alloc_det set consume_amt = consume_amt + "+amount+"," +
                                    "alloc_amt_po = alloc_amt_po - "+reqPo+" " +
                                     "where tran_id = '"+tranIdAlloc+"' " +
                                     "and acct_code = '"+acctCode+"' " +
                                     "and cctr_code = '"+cctrCode+"' " +
                                     "and anal_code = '"+analCode+"'";
                            System.out.println("SQL :"+sql);
                            updCount = stmt.executeUpdate(sql);
                        }else{
                            if(tranType.equalsIgnoreCase("PORD")){
                                sql = "update budget_alloc_det " +
                                        "set alloc_amt_po = alloc_amt_po + "+amount+", " +
                                        "req_amt  = req_amt - "+indAmount+" " +
                                        "where tran_id = '"+tranIdAlloc+"' " +
                                        "and acct_code = '"+acctCode+"' " +
                                        "and cctr_code = '"+cctrCode+"' " +
                                        "and anal_code = '"+analCode+"'";
                                System.out.println("SQL :"+sql);
                                updCount = stmt.executeUpdate(sql);
                            }else{
                                sql = "update budget_alloc_det " +
                                        "set req_amt = req_amt + "+amount+" " +
                                        "where tran_id = '"+tranIdAlloc+"' " +
                                        "and acct_code = '"+acctCode+"' " +
                                        "and cctr_code = '"+cctrCode+"' " +
                                        "and anal_code = '"+analCode+"'";
                                System.out.println("SQL :"+sql);
                                updCount = stmt.executeUpdate(sql);
                            }
                        }
                        if(updCount <=0){
                            errString = itmDBAccessEJB.getErrorString("","VTACCTBUD","","",conn);
                            break;
                            //return errString;
                        }else{
                            continue;
                        }
                    }else{//3rd sql
                        if(acctBudget){
                            if(projCode == null || projCode.trim().length() == 0){
                                if(!checkFlag.equalsIgnoreCase("I")){
                                    if(tranType.equalsIgnoreCase("VOUCH") || tranType.equalsIgnoreCase("P-RCP")){
                                        allocAmtPo = 0;
                                    }
                                    if(budgetAmt - conAmt - alloc - reqAlloc - reqDir - allocAmtPo + indAmount < amount){
                                        errString = itmDBAccessEJB.getErrorString("","VTACCTBUD1","","",conn);
                                        //return errString;
                                        if(checkFlag.equalsIgnoreCase("E")) break;
                                        if(checkFlag.equalsIgnoreCase("W")){
                                            warning = "Voucher Amount is greater than the Budget limit";
                                            errString = "";
                                        }
                                    }
                                }
                            }else{
                                if(allocation.equalsIgnoreCase("Y")){
                                    errString = itmDBAccessEJB.getErrorString("","VTBUDALLOC","","",conn);
                                    break;
                                }
                            }
                        }else{
                            continue;
                        }
                    }
                }
                if(budgetCode != null && budgetCode.trim().length() > 0){
                    if(updType.equalsIgnoreCase("C") ){
                        if(tranType.equalsIgnoreCase("PORD")){
                            sql = "update acctbudget " +
                                    "set dir_req_amt  = dir_req_amt + "+indAmount+" ," +
                                    "alloc_amt_po  = alloc_amt_po - "+amount+" " +
                                    "where from_date <= ? and to_date >= ? " +
                                    "and site_code = '"+siteCode+"' " +
                                    "and acct_code = '"+acctCode+"' " +
                                    "and cctr_code = '"+cctrCode+"' " +
                                    "and dept_code = '"+deptCode+"' " +
                                    "and anal_code = '"+analCode+"'";
                            System.out.println("SQL :"+sql);
                            pstmt = conn.prepareStatement(sql);
                            pstmt.executeUpdate();
                        }else{
                            if((tranType.equalsIgnoreCase("VOUCH") && acctEff.equalsIgnoreCase("N")) || (tranType.equalsIgnoreCase("P-RCP") && acctEff.equalsIgnoreCase("Y"))){
                                reqPo = amount;
                            }else{
                                reqPo = 0;
                            }
                            sql = "update acctbudget " +
                                    "set con_amt = con_amt + "+amount+" ," +
                                    "alloc_amt_po  = alloc_amt_po - "+reqPo+" , " +
                                    "dir_req_amt   = dir_req_amt - "+indAmount+"  " +
                                    "where from_date <= ? and to_date >= ? " +
                                    "and site_code = '"+siteCode+"' and acct_code = '"+acctCode+"' " +
                                    "and cctr_code = '"+cctrCode+"' and dept_code = '"+deptCode+"' " +
                                    "and anal_code = '"+analCode+"'";
                            System.out.println("SQL :"+sql);
                            pstmt = conn.prepareStatement(sql);

                            pstmt.setTimestamp(1,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
                            pstmt.setTimestamp(2,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
                            pstmt.executeUpdate();
                        }
                    }else{
                        if(tranType.equalsIgnoreCase("PORD")){
                            if(indAmount > 0){
                                sql = "update acctbudget " +
                                        "set dir_req_amt = dir_req_amt - "+indAmount+" ," +
                                        "alloc_amt_po = alloc_amt_po + "+amount+" " +
                                        "where from_date <= ? and to_date >= ? " +
                                        "and site_code = '"+siteCode+"' and acct_code = '"+acctCode+"' " +
                                        "and cctr_code = '"+cctrCode+"' and dept_code = '"+deptCode+"' " +
                                        "and anal_code = '"+analCode+"'";
                                System.out.println("SQL :"+sql);
                                pstmt = conn.prepareStatement(sql);

                                pstmt.setTimestamp(1,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
                                pstmt.setTimestamp(2,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
                                pstmt.executeUpdate();

                            }else{
                                sql = "update acctbudget " +
                                        "set    alloc_amt_po = alloc_amt_po + "+amount+" " +
                                        "where from_date <= ? and to_date >= ? " +
                                        "and site_code = '"+siteCode+"' and acct_code = '"+acctCode+"' " +
                                        "and cctr_code = '"+cctrCode+"' and dept_code = '"+deptCode+"' " +
                                        "and anal_code = '"+analCode+"'";
                                System.out.println("SQL :"+sql);
                                pstmt = conn.prepareStatement(sql);

                                pstmt.setTimestamp(1,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
                                pstmt.setTimestamp(2,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
                                pstmt.executeUpdate();
                            }
                        }else{
                            sql = "update acctbudget " +
                                    "set dir_req_amt = dir_req_amt + "+amount+" " +
                                    "where from_date <= ? and to_date >= ? " +
                                    "and site_code = '"+siteCode+"' and acct_code = '"+acctCode+"' " +
                                    "and cctr_code = '"+cctrCode+"' and dept_code = '"+deptCode+"' " +
                                    "and anal_code = '"+analCode+"'" ;
                            System.out.println("SQL :"+sql);
                            pstmt = conn.prepareStatement(sql);

                            pstmt.setTimestamp(1,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
                            pstmt.setTimestamp(2,Timestamp.valueOf(genericUtility.getValidDateTimeString(tranDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
                            pstmt.executeUpdate();
                        }
                    }
                }
            }
        }catch(Exception e){
            System.out.println("Exception in updateBudget [FinCommon]"+e);
            e.printStackTrace();
            throw new ITMException(e);
        }finally{
            try{
                if(rs != null){rs.close();rs = null;}
                if(stmt != null){stmt.close();stmt = null;}
                if(pstmt != null){pstmt.close();pstmt = null;}
            }catch(Exception e){}
        }
        System.out.println("Returning String From updateBudget ::: "+errString);
        return errString;
    }
	    //nvo_business_object_fin - gbf_check_gltran_drcr()
    public String checkGlTranDrCr(String refSer,String refId,Connection conn) throws ITMException //Added by Jiten
    {
        Statement stmt = null;
        ResultSet rs = null;
        double drAmt = 0,crAmt = 0,exch = 0;
        double totDrAmt = 0,totCrAmt = 0,diffAmt = 0;
        String sql = "",errString = "",postOnLine = "",acct = "",cctr = "";
        ITMDBAccessEJB itmDBAccessEJB = null;
        GenericUtility genericUtility = null;
        SimpleDateFormat sdf = null;
        HashMap glTran = null;
        try{
            stmt = conn.createStatement();
            genericUtility = new GenericUtility();
            itmDBAccessEJB = new ITMDBAccessEJB();
            sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
            sql = "select case when dr_amt is null then 0 else dr_amt end  * exch_rate," +
                    "case when cr_amt is null then 0 else cr_amt end  * exch_rate " +
                    "from gltrace where ref_ser = '"+refSer+"' and ref_id = '"+refId+"'";
            System.out.println("SQL :"+sql);
            rs = stmt.executeQuery(sql);
            while(rs.next()){
                drAmt = getRequiredDecimal(rs.getDouble(1), 2);
                crAmt = getRequiredDecimal(rs.getDouble(2), 2);

                totDrAmt = totDrAmt + drAmt;
                totCrAmt = totCrAmt + crAmt;
            }
            rs.close();
            if(totDrAmt == totCrAmt){
                return "";
            }
            diffAmt = totDrAmt - totCrAmt;
            if(Math.abs(diffAmt) > 1){
                errString = itmDBAccessEJB.getErrorString("","VCOINDIFF1","","",conn);
                return errString;
            }
            postOnLine = getFinparams("999999","POST_ON_LINE",conn);
            if(postOnLine.equalsIgnoreCase("NULLFOUND")){
                errString = itmDBAccessEJB.getErrorString("","VTENVAR1","","",conn);
                return errString;
            }else{
                postOnLine = postOnLine.substring(0,1);
                if("Y_N".indexOf(postOnLine) == -1){
                    errString = itmDBAccessEJB.getErrorString("","VTENVAR1","","",conn);
                    return errString;
                }
            }
            if(postOnLine.equalsIgnoreCase("Y")){
                acct = getFinparams("999999","COIN_ACCT",conn);
                if(acct.equalsIgnoreCase("NULLFOUND")){
                    errString = itmDBAccessEJB.getErrorString("","VSENVAR1","","",conn);
                    return errString;
                }
                cctr = getFinparams("999999","COIN_CCTR",conn);
                if(cctr.equalsIgnoreCase("NULLFOUND")){
                    cctr = "";
                }

                //acct = acct.substring(0,10);
                //cctr = cctr.substring(0,4);

                sql = "select gltrace.tran_date, gltrace.eff_date, gltrace.fin_entity," +
                        "gltrace.acct_prd, gltrace.prd_code, gltrace.remarks," +
                        "gltrace.site_code, gltrace.entry_batch_no," +
                        "finent.curr_code " +
                        "from gltrace, finent  where ( gltrace.fin_entity = finent.fin_entity ) and " +
                        "( gltrace.ref_ser = '"+refSer+"' ) and " +
                        "( gltrace.ref_id = '"+refId+"' )";
                System.out.println("SQL :"+sql);
                rs = stmt.executeQuery(sql);
                if(rs.next()){
                    glTran = new HashMap();
                    glTran.put("tran_date",rs.getTimestamp(1));
                    glTran.put("eff_date",rs.getTimestamp(2));
                    glTran.put("fin_entity",rs.getString(3));
                    glTran.put("acct_prd",rs.getString(4));
                    glTran.put("prd_code",rs.getString(5));
                    glTran.put("remarks",rs.getString(6));
                    glTran.put("site_code",rs.getString(7));
                    glTran.put("tran_id__trace",rs.getString(8));
                    glTran.put("entry_batch_no",rs.getString(8));
                    glTran.put("curr_code",rs.getString(9));
                }
                glTran.put("acct_code",acct);
                glTran.put("cctr_code",cctr);
                glTran.put("emp_code","");
                glTran.put("anal_code","");
                glTran.put("proj_code","");
                glTran.put("dept_code","");

                if(diffAmt > 0){
                    glTran.put("dr_amt","0");
                    glTran.put("cr_amt",Double.toString(diffAmt));
                }else{
                    glTran.put("dr_amt",Double.toString(0 - diffAmt));
                    glTran.put("cr_amt","0");
                }
                glTran.put("ref_ser",refSer);
                glTran.put("ref_id",refId);

                exch = 1;

                glTran.put("dr_amt_base",Double.toString(exch * Double.parseDouble(glTran.get("dr_amt").toString())));
                glTran.put("cr_amt_base",Double.toString(exch * Double.parseDouble(glTran.get("cr_amt").toString())));

                errString = glTranUpdate(glTran,conn);
            }
        }catch(Exception e){
            System.out.println("Exception in checkGlTranDrCr [FinCommon]"+e);
            e.printStackTrace();
            throw new ITMException(e);
        }finally{
            try{
                if(rs != null){rs.close();rs = null;}
                if(stmt != null){stmt.close();stmt = null;}
            }catch(Exception t){}
        }
        System.out.println("Returning Strung :"+errString);
        return errString;
    }
	public double getRequiredDecimal(double actVal, int prec) //Added by Jiten
    {
        NumberFormat numberFormat = NumberFormat.getIntegerInstance ();
        Double DoubleValue = new Double (actVal);
        numberFormat.setMaximumFractionDigits(prec);
        String strValue = numberFormat.format(DoubleValue);
        strValue = strValue.replaceAll(",","");
        double reqVal = Double.parseDouble(strValue);
        return reqVal;
    }

	// Following methods are added as required in Pheno Project Customization - Piyush - 25/03/08
	public String bankTranLogUpdate(HashMap hMapBankTranLog, String xtraParams , Connection conn) throws ITMException
	{
		String errString = "";
		double amountBc = 0d;
		String sqlTemp = "";
		ResultSet rsTemp = null;
		Statement stmtTemp = null;
		PreparedStatement pstmt = null;
		String currCode = "";
		String keyString = "";
		int bankCntr = 0;
		String newTranId = "";
		double rndTo = 0d;
		String errCode = "";
		String rndOff = "";

		StringBuffer valueXml = new StringBuffer();

		GenericUtility genericUtility = GenericUtility.getInstance();


		try
		{
			String chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"userId");

			java.sql.Timestamp tranDate = java.sql.Timestamp.valueOf((hMapBankTranLog.get("tran_date").toString()));
			String tranSer = (String)hMapBankTranLog.get("tran_ser");
			String tranNo = (String)hMapBankTranLog.get("tran_no");
			String bankCode = (String)hMapBankTranLog.get("bank_code");
			String refNo = (String)hMapBankTranLog.get("ref_no");
			java.sql.Timestamp refDate = java.sql.Timestamp.valueOf((hMapBankTranLog.get("ref_date").toString()));
			String refMode = (String)hMapBankTranLog.get("ref_mode");
			double amount = Double.parseDouble((hMapBankTranLog.get("amount") == null || hMapBankTranLog.get("amount").toString().trim().length() == 0) ? "0" :hMapBankTranLog.get("amount").toString());
			String tranType = (String)hMapBankTranLog.get("tran_type");
			String siteCode = (String)hMapBankTranLog.get("site_code");
			String acctCode = (String)hMapBankTranLog.get("acct_code");
			String cctrCode = (String)hMapBankTranLog.get("cctr_code");
			String sundryType = (String)hMapBankTranLog.get("sundry_type");
			String sundryCode = (String)hMapBankTranLog.get("sundry_code");
			String remarks = (String)hMapBankTranLog.get("remarks");
			java.sql.Timestamp dueDate = java.sql.Timestamp.valueOf((hMapBankTranLog.get("due_date").toString()));
			double exchRate = Double.parseDouble((hMapBankTranLog.get("exch_rate").toString() == null || hMapBankTranLog.get("exch_rate").toString().trim().length() == 0) ? "0" :hMapBankTranLog.get("exch_rate").toString());
			String entryBatchNo = (String)hMapBankTranLog.get("entry_batch_no");
			currCode = (String)hMapBankTranLog.get("curr_code");

			////
			if ( exchRate == 0 )
			{
				exchRate = 1;
			}

			////
			amountBc = amount * exchRate ;

			if ( currCode == null || currCode.trim().length() == 0 )
			{
				sqlTemp = "SELECT A.CURR_CODE FROM FINENT A, SITE B WHERE B.FIN_ENTITY = A.FIN_ENTITY "
					+" AND B.SITE_CODE = '"+ siteCode +"' ";
				System.out.println("SQL for FINENT,SITE :: "+sqlTemp);
				stmtTemp = conn.createStatement();
				rsTemp = stmtTemp.executeQuery(sqlTemp);
				if (rsTemp.next())
				{
					currCode = rsTemp.getString("CURR_CODE");
				}
				rsTemp.close();
				stmtTemp.close();
			}
			

			valueXml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?><Root><Header></Header><Detail1>");
			valueXml.append("<sundry_code></sundry_code>");
			valueXml.append("<bank_code><![CDATA[" + bankCode + "]]></bank_code>");
			valueXml.append("<tran_date><![CDATA[" + tranDate + "]]></tran_date>");
			valueXml.append("<site_code><![CDATA[" + siteCode + "]]></site_code>");
			valueXml.append("</Detail1></Root>");

			do
			{
				if ( tranType.trim().equals("P") && refMode.trim().equals("Q") && !tranSer.trim().equals("R-DIS") && refNo != null )
				{
					if (tranSer.trim().equals("F-XFR") && amountBc < 0 )
					{
						//Don't check for duplicate
					}
					else
					{
						sqlTemp = "SELECT COUNT(*) AS COUNTER FROM BANKTRAN_LOG WHERE "
							+" BANK_CODE = '"+ bankCode +"' AND TRAN_TYPE = 'P' AND "
							+" TRAN_SER <> 'R-DIS' AND REF_NO = '"+ refNo +"' ";
						System.out.println("SQL for banktranlog :: "+sqlTemp);
						stmtTemp = conn.createStatement();
						rsTemp = stmtTemp.executeQuery(sqlTemp);
						if (rsTemp.next())
						{
							bankCntr = rsTemp.getInt("COUNTER");
						}
						rsTemp.close();
						stmtTemp.close();

						if (bankCntr > 0)
						{
							errCode = "VTCHQ4";
							errString = validator.getErrorString("TRAN_ID",errCode,chgUser);//errCode
							break;
						}
					}
				}
				sqlTemp = "SELECT KEY_STRING FROM TRANSETUP WHERE UPPER(TRAN_WINDOW) = 'T_BANKTRAN_LOG' ";
				System.out.println("SQL for Transetup :: "+sqlTemp);
				stmtTemp = conn.createStatement();
				rsTemp = stmtTemp.executeQuery(sqlTemp);
				if (rsTemp.next())
				{
					keyString = rsTemp.getString("KEY_STRING");
				}
				else
				{
					errCode = "VTKEYSTR";
					errString = validator.getErrorString("TRAN_ID",errCode,chgUser);//errCode
					break;
				}
				rsTemp.close();
				stmtTemp.close();

                TransIDGenerator tg = new TransIDGenerator(valueXml.toString(), chgUser, CommonConstants.DB_NAME);
                newTranId = tg.generateTranSeqID("BK-LOG", "tran_id", keyString, conn);

				if ( newTranId != null && newTranId.trim().equals("ERROR") )
				{
					errCode = "VTTRANID";
					errString = validator.getErrorString("TRAN_ID",errCode,chgUser);//errCode
					break;
				}

				sqlTemp = "SELECT ROUND, ROUND_TO FROM CURRENCY WHERE CURR_CODE = '"+ currCode +"' ";
				System.out.println("SQL for Currency :: "+sqlTemp);
				stmtTemp = conn.createStatement();
				rsTemp = stmtTemp.executeQuery(sqlTemp);
				if (rsTemp.next())
				{
					rndTo = rsTemp.getDouble("ROUND_TO");
					rndOff = rsTemp.getString("ROUND");
				}
				rsTemp.close();
				stmtTemp.close();
				//amountBc =  gf_get_rndamt(lc_amount_bc, ls_rndto, lc_rndoff)

				sqlTemp = "INSERT INTO BANKTRAN_LOG "
					+" (TRAN_ID, BANK_CODE, TRAN_DATE, TRAN_SER, TRAN_NO, REF_NO, REF_DATE, "
					+" REF_MODE, AMOUNT, TRAN_TYPE, SITE_CODE, ACCT_CODE, CCTR_CODE, SUNDRY_TYPE, "
					+" SUNDRY_CODE, STATUS,	REMARKS, AMT_ADJ, DUE_DATE, CURR_CODE, EXCH_RATE, ENTRY_BATCH_NO) "
					+" 	VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
				System.out.println(" SQL for banktran_log insert :: "+sqlTemp);
				pstmt = conn.prepareStatement(sqlTemp);
				pstmt.setString(1,newTranId);
				pstmt.setString(2,bankCode);
				pstmt.setTimestamp(3,tranDate);
				pstmt.setString(4,tranSer);
				pstmt.setString(5,tranNo);
				pstmt.setString(6,refNo);
				pstmt.setTimestamp(7,refDate);
				pstmt.setString(8,refMode);
				pstmt.setDouble(9,amountBc);
				pstmt.setString(10,tranType);
				pstmt.setString(11,siteCode);
				pstmt.setString(12,acctCode);
				pstmt.setString(13,cctrCode);
				pstmt.setString(14,sundryType);
				pstmt.setString(15,sundryCode);
				pstmt.setString(16,"E");
				pstmt.setString(17,remarks);
				pstmt.setDouble(18,0);
				pstmt.setTimestamp(19,dueDate);
				pstmt.setString(20,currCode);
				pstmt.setDouble(21,exchRate);
				pstmt.setString(22,entryBatchNo);
				int cnt = pstmt.executeUpdate();

				if ( cnt == 0)
				{
					errCode = "VTBKLOGUPD";
					errString = validator.getErrorString("TRAN_ID",errCode,chgUser);//errCode
				}
				break;
			}
			while (true);
		
		}
		catch ( SQLException sqlE)
		{
			System.out.println("Exception in hMapBankTranLog :: "+sqlE.getMessage());
			sqlE.printStackTrace();
			throw new ITMException(sqlE);
		}
		catch (Exception e)
		{
			System.out.println("Exception in hMapBankTranLog :: "+e.getMessage());
			e.printStackTrace();
			throw new ITMException(e);		
		}
		return errString;
	}


	// End addition of new methods for Pheno Project customization - Piyush - 25/03/08
	public String getAcctDetrDistTtype(String siteCodeFrom,String siteCodeTo, String itemSer,String grpCode,String itemCode, String purpose, String tranType, Connection conn) throws ITMException
	{
		String acctCode = null, cctrCode = null;
		String sql = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;

		System.out.println("In getAcctDetrTtype --> purpose :: " + purpose + " itemCode :: " + itemCode);
		System.out.println(" itemSer :: " + itemSer + " tranType :: " + tranType);
		try
		{
			if (purpose.equalsIgnoreCase("D-ISS"))
			{
				sql = "select acct_code__iss,cctr_code__iss  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = '" + tranType + "' ";
				pstmt = conn.prepareStatement(sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__iss,cctr_code__iss  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	 "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = ' ' "
					  +" and tran_type = '" + tranType + "' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__iss,cctr_code__iss  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	 "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = ' ' "
					  +" and tran_type = ' ' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__iss,cctr_code__iss  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "' "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = ' ' "
					  +" and item_ser = '"+itemSer+"'  "
					  +" and tran_type = '"+tranType+"' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__iss,cctr_code__iss  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = ' ' "
					  +" and item_ser = '"+itemSer+"'  "
					  +" and tran_type = ' ' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__iss,cctr_code__iss  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	 "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_ser = '"+itemSer+"'  "  ;
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
			} //if (purpose.equalsIgnoreCase("D-ISS"))
			if (purpose.equalsIgnoreCase("D-RCP"))
			{
				sql = "select acct_code__rcp,cctr_code__rcp  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	 "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = '" + tranType + "' ";
				pstmt = conn.prepareStatement(sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__rcp,cctr_code__rcp  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = ' ' "
					  +" and tran_type = '" + tranType + "' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__rcp,cctr_code__rcp  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = ' ' "
					  +" and tran_type = ' ' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__rcp,cctr_code__rcp  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	 "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = ' ' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = '" + tranType + "' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__rcp,cctr_code__rcp  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	 "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = ' ' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = ' ' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__rcp,cctr_code__rcp  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	 "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_ser = '" + itemSer + "' "  ;
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
			}
			if (purpose.equalsIgnoreCase("D-INV"))
			{
				sql = "select acct_code__inv,cctr_code__inv  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = '" + tranType + "' ";
				pstmt = conn.prepareStatement(sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__inv,cctr_code__inv  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = ' ' "
					  +" and tran_type = '" + tranType + "' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__inv,cctr_code__inv  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	  "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = ' ' "
					  +" and tran_type = ' ' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__inv,cctr_code__inv  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = ' ' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = '" + tranType + "' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__inv,cctr_code__inv  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "' "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = ' ' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = ' ' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__inv,cctr_code__inv  FROM item_acct_detr_dist "
				      +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_ser = '" + itemSer + "' "  ;
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
			}
			if (purpose.equalsIgnoreCase("D-COGT"))
			{
				sql = "select acct_code__cogt,cctr_code__cogt   FROM item_acct_detr_dist "
					  +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = '" + tranType + "' ";
				pstmt = conn.prepareStatement(sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__cogt,cctr_code__cogt   FROM item_acct_detr_dist "
					  +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = ' ' "
					  +" and tran_type = '" + tranType + "' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__cogt,cctr_code__cogt   FROM item_acct_detr_dist "
					  +" WHERE site_code__from = '" + siteCodeFrom + "'	 "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = ' ' "
					  +" and tran_type = ' ' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__cogt,cctr_code__cogt   FROM item_acct_detr_dist "
					  +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = ' ' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = '" + tranType + "' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql ="select acct_code__cogt,cctr_code__cogt   FROM item_acct_detr_dist "
					  +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = ' ' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = ' ' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__cogt,cctr_code__cogt   FROM item_acct_detr_dist "
					  +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_ser = '" + itemSer + "' "  ;
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
			}
			if (purpose.equalsIgnoreCase("D-BRTR"))
			{
				sql = "select acct_code__brtr,cctr_code__brtr    FROM item_acct_detr_dist"
					  +" WHERE site_code__from = '" + siteCodeFrom + "'	  "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = '" + tranType + "' ";
				pstmt = conn.prepareStatement(sql);
				rs = pstmt.executeQuery();
				if (rs.next())
				{
					acctCode = rs.getString(1);
					cctrCode = rs.getString(2);
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__brtr,cctr_code__brtr    FROM item_acct_detr_dist"
					  +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = ' ' "
					  +" and tran_type = '" + tranType + "' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__brtr,cctr_code__brtr    FROM item_acct_detr_dist"
					  +" WHERE site_code__from = '" + siteCodeFrom + "'	 "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = '" + itemCode + "' "
					  +" and item_ser = ' ' "
					  +" and tran_type = ' ' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__brtr,cctr_code__brtr    FROM item_acct_detr_dist"
					  +" WHERE site_code__from = '" + siteCodeFrom + "' "
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = ' ' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = '" + tranType + "' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql ="select acct_code__brtr,cctr_code__brtr    FROM item_acct_detr_dist"
					  +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_code = ' ' "
					  +" and item_ser = '" + itemSer + "' "
					  +" and tran_type = ' ' ";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
				if(acctCode == null || acctCode.trim().length() == 0)
				{
					sql = "select acct_code__brtr,cctr_code__brtr    FROM item_acct_detr_dist"
					  +" WHERE site_code__from = '" + siteCodeFrom + "'	"
					  +" and site_code__to = '" + siteCodeTo + "' "
					  +" and item_ser = '" + itemSer + "' "  ;
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if (rs.next())
					{
						acctCode = rs.getString(1);
						cctrCode = rs.getString(2);
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				}
			}
			if (acctCode == null) acctCode = "";
			if (cctrCode == null) cctrCode = "";
		} catch (SQLException e) {

			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close(); rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close(); pstmt = null;
				}
			}
			catch(Exception e)
			{
				System.out.println("Exception in finally block ::"+e);
				e.printStackTrace();
			}
		}
		System.out.println("From getFromAcctDetr [" + acctCode + "," + cctrCode + "]");
		return acctCode + "," + cctrCode;
	}
	//nvo_business_object_fin - gf_get_contactcode() - added by chandni - 1/07/11
	public String getContactCode(String sundryType,String SundryCode,Connection conn) throws ITMException
	{
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = "" ,tableName = "",columnName = "",contactCode = "";

		if (sundryType.equals("C"))
		{
			tableName = "CUSTOMER";
			columnName = "CUST_CODE";
		}
		else if(sundryType.equals("B"))
		{
			//tableName = "BANK";
			//columnName = "BANK_CODE"; // as in bank table contactcode field doesnot exist
			return contactCode;
		}
		else if(sundryType.equals("E"))
		{
			tableName = "EMPLOYEE";
			columnName = "EMP_CODE";
		}
		else if(sundryType.equals("P"))
		{
			tableName = "SALES_PERS";
			columnName = "SALES_PERS";
		}
		else if(sundryType.equals("T"))
		{
			tableName = "TRANSPORTER";
			columnName = "TRAN_CODE";
		}
		else if(sundryType.equals("S"))
		{
			tableName = "SUPPLIER";
			columnName = "SUPP_CODE";
		}
		else if(sundryType.equals("L"))
		{
			tableName = "LOANPARTY";
			columnName = "PARTY_CODE";
		}
		else if(sundryType.equals("X"))
		{
			return contactCode;
		}
		try
		{
			
			sql = "SELECT CONTACT_CODE FROM "+tableName+" WHERE "+columnName+" = ? ";
			pstmt = conn.prepareStatement(sql);
			//pstmt.setString(1,tableName);
			//pstmt.setString(2,columnName);
			pstmt.setString(1,SundryCode.trim());
			rs = pstmt.executeQuery();
			if(rs.next())
			{
				contactCode = rs.getString(1);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;
			System.out.println("contactCode :" +contactCode);
		}
		catch(SQLException e)
		{
			System.out.println("Exception in getContactCode[FinCommon]"+e);
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				if(rs != null){rs.close();rs = null;}
				if(pstmt != null){pstmt.close();pstmt = null;}
			}
			catch(Exception t)
			{}
		}
		return contactCode;
	}
	//nvo_business_object_fin - gf_get_party_doc_ref() - added by chandni - 23/08/11
	public String gfGetPartyDocRef(String refSer,String refNo,Connection conn) throws ITMException
	{
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = "";
		String errString = "" ; 
		GenericUtility genericUtility = null;
		ITMDBAccessEJB itmDBAccessEJB = null;
			
		java.sql.Timestamp docRefDt = null;
		String docRefNo="",returns ="",refDt ="";
		String refSerSub="";
		boolean flag = false;

		SimpleDateFormat sdf = null;
		try
		{
			genericUtility = new GenericUtility();
			sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
			itmDBAccessEJB = new ITMDBAccessEJB();
			
			refSerSub = refSer.substring(0,5);
						
			if(("S-INV".equalsIgnoreCase(refSerSub))||("R-IBC".equalsIgnoreCase(refSerSub)))
			{
				sql ="  select distinct c.gp_no,c.gp_date "
					+" from invoice a, invoice_trace b , despatch c " 
					+" where a.invoice_id = b.invoice_id and " 
					+" b.desp_id = c.desp_id and " 					
					+" a.invoice_id = ?";
				flag = true;
			}
			else if("VOUCH".equalsIgnoreCase(refSerSub))
			{
				sql =" select bill_no, bill_date from voucher where tran_id = ? ";
				flag = true;
			}
			else if(("P-IBC".equalsIgnoreCase(refSerSub))||("M-PAY".equalsIgnoreCase(refSerSub)))
			{
				sql =" select bill_no, bill_date from misc_payables where tran_ser = '"+refSer+"' and ref_no = ? ";
				flag = true;
			}
			else if("M-VOU".equalsIgnoreCase(refSerSub))
			{
				sql =" select bill_no, bill_date from misc_voucher where tran_id = ? ";
				flag = true;
			}
			else if("E-PAY".equalsIgnoreCase(refSerSub))
			{
				sql =" select ref_no, ref_date from payment_exp where tran_id = ? ";
				flag = true;
			}
			else if(("CRNRC".equalsIgnoreCase(refSerSub))||("DRNRC".equalsIgnoreCase(refSerSub)))
			{
				sql =" select gp_no, gp_date from drcr_rcp where tran_id = ? ";
				flag = true;
			}
			else if(("CRNPA".equalsIgnoreCase(refSerSub))||("DRNPA".equalsIgnoreCase(refSerSub)))
			{
				sql =" select bill_no, bill_date from drcr_pay where tran_id = ? ";
				flag = true;
			}
			
			if(flag)
			{
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,refNo);
				rs = pstmt.executeQuery();
				while(rs.next())
				{     
					docRefNo = rs.getString(1);
					docRefDt = rs.getTimestamp(2);
					
					if (docRefNo != null)
					{
						if(returns.trim().length() >0 )
						{
							returns = returns + "/"+ docRefNo.trim() ;
						}
						else
						{
							returns = returns + docRefNo.trim() ;
						}
					}
					if (docRefDt != null)
					{
						refDt=sdf.format(docRefDt);
						
						if(returns.trim().length() >0 )
						{
							returns = returns + "/"+ refDt ;
						}
						else
						{
							returns = returns + refDt ;
						}
					}
				}
				rs.close();
				rs= null;
				pstmt.close();
				pstmt=null;
			}
			if(returns.trim().length() > 100)
			{
				returns = returns.substring(0,100);
			}
			System.out.println("returns :: :: ::"+returns);
		}// end of try
		catch(Exception e)
		{
            System.out.println("Exception in checkGlTranDrCr [FinCommon]"+e);
            e.printStackTrace();
            throw new ITMException(e);
        }
		finally
		{
            try
			{
                if(rs != null){rs.close();rs = null;}
                if(pstmt != null){pstmt.close();pstmt = null;}
            }
			catch(Exception t){}
		}
		return returns;
	}//method end
	//nvo_business_object_fin - gbf_miscpay_upd() - added by chandni - 23/08/11
	public String gbfMiscPayUpd(HashMap miscPayMap,Connection conn) throws ITMException
	{
		PreparedStatement pstmt = null;
		PreparedStatement pstmt1 = null;
		ResultSet rs = null;
		ResultSet rs1 = null;
		String sql = "",sql1="";
		String errString = "" ; 
		GenericUtility genericUtility = null;
		ITMDBAccessEJB itmDBAccessEJB = null;
		
		Timestamp tranDate = null,refDate = null,billDate =null,dueDate = null;
		
		String tranSer="",refNo="",billNo="",currCode="",sundryType="",sundryCode="",acctCode="";
		String cctrCode="",siteCode="",finEntity="",bankCode="",autoPay="",payMode="",paid="",batch="";
		String keyStr="",thisWin="",payblsTranID="",refSerOrg="",suppAmt="",tdsStr="";
		double exchRate=0,totAmt=0,advAmt=0,holdAmt=0,suppBillAmt=0,tdsAmt=0;
		SimpleDateFormat sdf  = null;
		try
		{
			genericUtility = new GenericUtility();
			sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
			itmDBAccessEJB = new ITMDBAccessEJB();
			tranSer = (miscPayMap.get("tran_ser") == null ? "":miscPayMap.get("tran_ser").toString());
			tranDate=(Timestamp)miscPayMap.get("tran_date");
			refNo = (miscPayMap.get("ref_no") == null ? "":miscPayMap.get("ref_no").toString());
			refDate =(Timestamp)miscPayMap.get("ref_date");
			billNo =(miscPayMap.get("bill_no") == null ? "":miscPayMap.get("bill_no").toString());
			billDate =(Timestamp)miscPayMap.get("bill_date");
			currCode =(miscPayMap.get("curr_code") == null ? "":miscPayMap.get("curr_code").toString());
			exchRate =Double.parseDouble(miscPayMap.get("exch_rate").toString());
			sundryType =(miscPayMap.get("sundry_type") == null ? "":miscPayMap.get("sundry_type").toString()); 
			sundryCode =(miscPayMap.get("sundry_code") == null ? "":miscPayMap.get("sundry_code").toString());
			acctCode =(miscPayMap.get("acct_code") == null ? "":miscPayMap.get("acct_code").toString()); 
			cctrCode =(miscPayMap.get("cctr_code") == null ? "":miscPayMap.get("cctr_code").toString()); 
			dueDate =(Timestamp)miscPayMap.get("due_date");
			siteCode =(miscPayMap.get("site_code") == null ? "":miscPayMap.get("site_code").toString());
			finEntity =(miscPayMap.get("fin_entity") == null ? "":miscPayMap.get("fin_entity").toString());
			totAmt =Double.parseDouble(miscPayMap.get("tot_amt").toString());
			bankCode =(miscPayMap.get("bank_code") == null ? "":miscPayMap.get("bank_code").toString());
			autoPay =(miscPayMap.get("auto_pay") == null ? "":miscPayMap.get("auto_pay").toString());
			payMode =(miscPayMap.get("pay_mode") == null ? "":miscPayMap.get("pay_mode").toString());
			paid =(miscPayMap.get("paid") == null ? "":miscPayMap.get("paid").toString());
			advAmt =Double.parseDouble(miscPayMap.get("adv_amt").toString());
			batch =(miscPayMap.get("entry_batch_no") == null ? "":miscPayMap.get("entry_batch_no").toString());
			holdAmt =Double.parseDouble(miscPayMap.get("hold_amt").toString());
			suppAmt  = (String)miscPayMap.get("supp_bill_amt");
			tdsStr  = (String)miscPayMap.get("tds_amt");
			
			if (suppAmt == null || suppAmt.trim().length()== 0)
			{
				suppBillAmt = 0.0;
			}
			else
			{
				suppBillAmt =Double.parseDouble(suppAmt);
			}
			
			if (tdsStr == null || tdsStr.trim().length()== 0)
			{
				tdsAmt = 0.0;
			}
			else
			{
				tdsAmt =Double.parseDouble(tdsStr);
			}
			refSerOrg =(miscPayMap.get("ref_ser__org") == null ? "":miscPayMap.get("ref_ser__org").toString());
						
			if(batch == null || batch.trim().length() == 0)
			{
				batch =" ";
			}
			if(cctrCode == null || cctrCode.trim().length() == 0)
			{
				cctrCode=" ";
			}
			
			thisWin ="T_PAYABLES" ;
			sql = " select key_string from transetup where upper(tran_window) = ? ";
			pstmt =  conn.prepareStatement(sql);
			pstmt.setString(1,thisWin);
			rs = pstmt.executeQuery();
			if (rs.next())
			{
				keyStr = rs.getString(1);
			}
			else
			{
				thisWin ="GENERAL" ;
				sql1 = " select key_string  from transetup where upper(tran_window) = ? ";
				pstmt1 =  conn.prepareStatement(sql1);
				pstmt1.setString(1,thisWin);
				rs1 = pstmt1.executeQuery();
				if (rs1.next())
				{
					keyStr = rs1.getString(1);
				}
				rs1.close();
				rs1 = null;
				pstmt1.close();
				pstmt1 =null;
			}
			System.out.println("keyStr :::"+keyStr);
			rs.close();
			rs = null;
			pstmt.close();
			pstmt =null;
			
			String xmlString = "<?xml version=\"1.0\"?>\r\n<Root>\r\n<header>"+
					"\r\n</header><Detail1><item_ser></item_ser>"+
					"\r\n<site_code>"+siteCode+"</site_code>\r\n<tran_date>"+sdf.format(new java.util.Date(tranDate.getTime()))+"</tran_date></Detail1></Root>";
					
			TransIDGenerator tg = new TransIDGenerator(xmlString,"SYSTEM", CommonConstants.DB_NAME);
            payblsTranID = tg.generateTranSeqID("PAYL", "tran_id", keyStr, conn);
			System.out.println("Transaction Id Generated for Payables :"+payblsTranID);			
			
			sql = "INSERT INTO MISC_PAYABLES (TRAN_ID,TRAN_SER,TRAN_DATE,REF_NO,REF_DATE,CURR_CODE,EXCH_RATE,"
				   + "SUNDRY_TYPE,SUNDRY_CODE,ACCT_CODE,CCTR_CODE,DUE_DATE,FIN_ENTITY,SITE_CODE,BILL_NO,BILL_DATE,"
				   + "TOT_AMT,ADJ_AMT,STATUS,STATUS_DATE,BANK_CODE,AUTO_PAY,PAY_MODE,PAID,ADV_AMT,HOLD_AMT,"
				   + "PURC_ORDER,ENTRY_BATCH_NO,TDS_AMT,SUPP_BILL_AMT,REF_SER__ORG) "
				   + "VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,payblsTranID.trim());
			pstmt.setString(2,tranSer.trim());
			pstmt.setTimestamp(3,tranDate);
			pstmt.setString(4,refNo.trim());
			pstmt.setTimestamp(5,refDate);
			pstmt.setString(6,currCode.trim());
			pstmt.setDouble(7,exchRate);
			pstmt.setString(8,sundryType.trim());
			pstmt.setString(9,sundryCode.trim());
			pstmt.setString(10,acctCode.trim());
			pstmt.setString(11,cctrCode.trim());
			pstmt.setTimestamp(12,dueDate);
			pstmt.setString(13,finEntity.trim());
			pstmt.setString(14,siteCode.trim());
			pstmt.setString(15,billNo);
			pstmt.setTimestamp(16,billDate);
			pstmt.setDouble(17,totAmt);
			pstmt.setDouble(18,0);
			pstmt.setString(19,"U");
			pstmt.setTimestamp(20,new java.sql.Timestamp(System.currentTimeMillis()));
			pstmt.setString(21,bankCode.trim());
			pstmt.setString(22,autoPay.trim());
			pstmt.setString(23,payMode);
			pstmt.setString(24,paid);
			pstmt.setDouble(25,advAmt);
			pstmt.setDouble(26,holdAmt);
			pstmt.setString(27,(String)miscPayMap.get("purc_order"));
			pstmt.setString(28,batch);
			pstmt.setDouble(29,tdsAmt);
			pstmt.setDouble(30,suppBillAmt);
			pstmt.setString(31,refSerOrg);
			int count = pstmt.executeUpdate();
			if(count < 1)
			{
				errString = itmDBAccessEJB.getErrorString("","VMMISCPAY","","",conn);
                return errString;
			}
			pstmt.close();pstmt = null;
		}// end of try 
		catch(Exception e)
		{
            System.out.println("Exception in checkGlTranDrCr [FinCommon]"+e);
            e.printStackTrace();
            throw new ITMException(e);
        }
		finally
		{
            try
			{
                if(rs != null){rs.close();rs = null;}
                if(rs1 != null){rs1.close();rs1 = null;}
                if(pstmt != null){pstmt.close();pstmt = null;}
                if(pstmt1 != null){pstmt1.close();pstmt1 = null;}
            }
			catch(Exception t){}
		}
		return errString;
	}//method end
	
	//gbf_receivables_upd() - added by chandni - 29/09/11
	public String gbfReceivablesUpd(HashMap receivablesMap,Connection conn)throws ITMException
	{
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = "",errString = ""; 
		GenericUtility genericUtility = null;
		ITMDBAccessEJB itmDBAccessEJB = null;
		FinCommon Fcommon = new FinCommon();
		genericUtility = new GenericUtility();
				
		String siteCode="",finEntity="",currCode="",acctCode="",cctrCode="";
		String refNo="",custCode="",crTerm="",itemSer="",finScheme="";
		String salesPers="",salesPers1="",salesPers2="",contactCode="",saleOrder="";
		String status="",refSerOrg="",tranSer="",auotRcp="",bankCode="";
		String refType="",autoRcp="",lineNoRef="";
		String gpNo="",gpDate="",custRefNo="",custRefDate="",custRefAmt="";
		String keyString = "",recvTranID = "";
		
		double totAmt=0,diffAmt=0,adjAmt=0,taxAmt=0,exchRate=0,discount=0,mrpValue=0;
			
		java.sql.Timestamp dueDate = null;
		java.sql.Timestamp tranDate = null;
		java.sql.Timestamp refDate = null;
		java.sql.Timestamp statDate = null;
		java.sql.Timestamp effDate = null;
		java.util.Date toDay = new java.util.Date();
		
		try
		{
			statDate = new java.sql.Timestamp(toDay.getTime());
			tranDate = java.sql.Timestamp.valueOf(receivablesMap.get("tran_date").toString());
			refDate =  java.sql.Timestamp.valueOf(receivablesMap.get("ref_date").toString());
			dueDate = java.sql.Timestamp.valueOf(receivablesMap.get("due_date").toString());
			effDate = java.sql.Timestamp.valueOf(receivablesMap.get("eff_date").toString());
			tranSer = (String)receivablesMap.get("tran_ser");
			finEntity = (String)receivablesMap.get("fin_entity");
			siteCode = (String)receivablesMap.get("site_code");
			saleOrder = (String)receivablesMap.get("sale_order");
			acctCode = (String)receivablesMap.get("acct_code");
			cctrCode = (String)receivablesMap.get("cctr_code");
			currCode = (String)receivablesMap.get("curr_code");
			custCode = (String)receivablesMap.get("cust_code");
			refNo = (String)receivablesMap.get("ref_no");
			refType = (String)receivablesMap.get("ref_type");
			autoRcp = (String)receivablesMap.get("auto_rcp");
			bankCode = (String)receivablesMap.get("bank_code");
			salesPers = (String)receivablesMap.get("sales_pers");
			crTerm = (String)receivablesMap.get("cr_term");
			itemSer = (String)receivablesMap.get("item_ser");
			exchRate = Double.parseDouble(receivablesMap.get("exch_rate").toString());
			totAmt = Double.parseDouble(receivablesMap.get("tot_amt").toString());
			taxAmt = Double.parseDouble(receivablesMap.get("tax_amt").toString());
			discount = Double.parseDouble(receivablesMap.get("discount").toString());
			salesPers1 = (String)receivablesMap.get("sales_pers__1");
			salesPers2 = (String)receivablesMap.get("sales_pers__2");
			finScheme = (String)receivablesMap.get("fin_scheme");
			lineNoRef = (String)receivablesMap.get("line_no__ref"); 
						
			if(lineNoRef == null )
			{
				lineNoRef = "1";
			}
			
			mrpValue = Double.parseDouble(receivablesMap.get("mrp_value").toString());
			gpNo = (String)receivablesMap.get("gp_no");
			gpDate = (String)receivablesMap.get("gp_date");
			custRefNo = (String)receivablesMap.get("cust_ref_no");
			custRefDate = (String)receivablesMap.get("cust_ref_date");
			custRefAmt = (String)receivablesMap.get("cust_ref_amt");		
			
			// pickup the contact code from customer and update in receivables.
			sql =" SELECT contact_code FROM customer WHERE cust_code = ? ";
		    pstmt = conn.prepareStatement(sql);
		    pstmt.setString(1,custCode);
			rs = pstmt.executeQuery();
			if(rs.next())
			{
				contactCode = rs.getString("contact_code");
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;
			
			//if("null".equalsIgnoreCase(contactCode)) contactCode = "";
			if( contactCode ==  null)
			{
				contactCode = "";
			}
			refSerOrg = (String)receivablesMap.get("ref_ser__org");
			
			sql =" SELECT KEY_STRING FROM TRANSETUP WHERE upper(TRAN_WINDOW) = 'T_RCVABLES'";
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery(sql);
			if(rs.next())
			{
				keyString = rs.getString("KEY_STRING");
			}
			rs.close();
			rs=null;
			pstmt.close();
			pstmt = null;
			
			String XMLString = "<?xml version=\"1.0\"?>\r\n<Root>\r\n<header>"+
			"\r\n</header><Detail1><item_ser>"+itemSer+"</item_ser>"+
			"\r\n<site_code>"+siteCode+"</site_code>\r\n<tran_date>"+tranDate+"</tran_date></Detail1></Root>";
			
			CommonConstants.setIBASEHOME();
			TransIDGenerator tg = new TransIDGenerator(XMLString,"SYSTEM",CommonConstants.DB_NAME); //FOR DB2
			recvTranID = tg.generateTranSeqID("RCVL","tran_id",keyString,conn);
			System.out.println("Transaction Id Generated for Receivables :"+recvTranID);
			
			sql =" INSERT INTO RECEIVABLES (TRAN_ID,TRAN_SER,TRAN_DATE,REF_NO,REF_DATE,CURR_CODE,EXCH_RATE,"
				+" CUST_CODE,ACCT_CODE,CCTR_CODE,DUE_DATE,FIN_ENTITY,SITE_CODE,TOT_AMT,ADJ_AMT,STATUS, " 
				+" STAT_DATE,DISCOUNT,TAX_AMT,AUTO_RCP,BANK_CODE,RECD,REF_TYPE,CR_TERM,SALES_PERS,ITEM_SER, "
				+" SALES_PERS__1,SALES_PERS__2,CONTACT_CODE,EFF_DATE,FIN_SCHEME,REF_SER__ORG,SALE_ORDER, "
				+" LINE_NO__REF,mrp_value,exp_rcp_date,gp_no,gp_date,cust_ref_no,cust_ref_date,cust_ref_amt) " 
				+" VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
			pstmt = conn.prepareStatement(sql);

			pstmt.setString(1,recvTranID); 
			pstmt.setString(2,tranSer);
			pstmt.setTimestamp(3,tranDate);
			pstmt.setString(4,refNo);
			pstmt.setTimestamp(5,refDate);
			pstmt.setString(6,currCode);
			pstmt.setDouble(7,exchRate);
			pstmt.setString(8,custCode);
			pstmt.setString(9,acctCode);
			pstmt.setString(10,cctrCode);
			pstmt.setTimestamp(11,dueDate);
			pstmt.setString(12,finEntity);
			pstmt.setString(13,siteCode);
			pstmt.setDouble(14,totAmt);
			pstmt.setDouble(15,0);
			pstmt.setString(16,"U");
			pstmt.setTimestamp(17,statDate);
			pstmt.setDouble(18,discount);
			pstmt.setDouble(19,taxAmt);
			pstmt.setString(20,autoRcp);
			pstmt.setString(21,bankCode);
			pstmt.setString(22,"N");
			pstmt.setString(23,refType);
			pstmt.setString(24,crTerm);
			pstmt.setString(25,salesPers);
			pstmt.setString(26,itemSer);
			pstmt.setString(27,salesPers1);
			pstmt.setString(28,salesPers2);
			pstmt.setString(29,contactCode);
			pstmt.setTimestamp(30,effDate);
			pstmt.setString(31,finScheme);
			pstmt.setString(32,refSerOrg);
			pstmt.setString(33,saleOrder);
			pstmt.setString(34,lineNoRef);
			pstmt.setDouble(35,mrpValue);
			pstmt.setTimestamp(36,dueDate);
			pstmt.setString(37,gpNo);
			pstmt.setString(38,gpDate);
			pstmt.setString(39,custRefNo);
			pstmt.setString(40,custRefDate);
			pstmt.setString(41,custRefAmt);
			//pstmt.executeUpdate();
			int count = pstmt.executeUpdate();
			if(count < 1)
			{
				errString = "DS000 : Insert Into Receivables Failed";
				return(errString);
			}
			pstmt.close();
			pstmt =null;
			
		}
		catch(SQLException e)
		{
			System.out.println("Exception :FinCommon :gbfReceivablesUpd :SQLException :==>\n"+e.getMessage());
			errString = GenericUtility.getInstance().createErrorString(e);
			throw new ITMException(e);
		}		
		catch (Exception e)
		{
			System.out.println("Exception :FinCommon :gbfReceivablesUpd :==>"+e.getMessage());
			errString = GenericUtility.getInstance().createErrorString(e);
			throw new ITMException(e);
		}
		finally
		{
			try
			{				
				if(rs != null)
				{
					rs.close();
					rs = null;
				}
				if(pstmt != null)
				{
					pstmt.close();
					pstmt = null;
				}
				
			}
			catch(Exception e)
			{
				System.out.println("Exception : "+e);e.printStackTrace();
				throw new ITMException(e);
			}
		}
		return errString;
	}// end of method
}
