package ibase.webitm.ejb.adm.adv;

import java.rmi.RemoteException;
//import java.util.*;
//import java.util.Date;
import java.util.Calendar;
import java.sql.*;

import org.w3c.dom.*;
import javax.ejb.*;
import java.text.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.GenericUtility;
import ibase.system.config.*;
import java.text.SimpleDateFormat;
import javax.ejb.Stateless; // added for ejb3

@Stateless // added for ejb3

public class FullFinalAct extends ActionHandlerEJB implements FullFinalActLocal,FullFinalActRemote	//SessionBean
{
	//UPDATED BY NISAR ON 13/12/07 
	LogWriter log = new LogWriter();//added by nisar on 27/11/07 

	/*public void ejbCreate() throws RemoteException, CreateException 
	{
		log.setNameOfLog("FullFinalactEJB");
		log.setLogOn(true);		
		log.write("================ejbCreate() method called=====================");
		System.out.println("================ejbCreate() method called=====================");
	}

   	public void ejbRemove()
	{
		log.write("================ejbRemove() method called=====================");
		System.out.println("================ejbRemove() method called=====================");
	}

   	public void ejbActivate() 
	{
		log.write("================ejbActivate() method called=====================");
		System.out.println("================ejbActivate() method called=====================");
	}

   	public void ejbPassivate() 
	{
		log.write("================ejbPassivate() method called=====================");
		System.out.println("================ejbPassivate() method called=====================");
	}*/

    public String actionHandler() throws RemoteException,ITMException
	{
		return "";
	}

	public String actionHandler(String actionType, String xmlString, String xmlString1,String objContext, String xtraParams) throws RemoteException,ITMException
	{
		log.setNameOfLog("FullFinalactEJB");
		log.setLogOn(true);		
		log.write("================ejbCreate() method called=====================");
		System.out.println("================ejbCreate() method called=====================");
	    System.out.println("FullFinalActEJB called..............");
		log.write("..................FullFinalActEJB called..............");
		Document dom = null;
		Document dom1 = null;
		
		String  resString = null;
		try
		{	
			GenericUtility genericUtility = GenericUtility.getInstance(); 
			if(xmlString != null && xmlString.trim().length()!=0)
			{
				System.out.println( "XML String :" + xmlString );
				dom = genericUtility.parseString( xmlString ); 
			}
			if( xmlString1 != null && xmlString1.trim().length() !=0 )
			{
				System.out.println( "XML String1 :" + xmlString1 );
				dom1 = genericUtility.parseString( xmlString1 ); 
			}			
			System.out.println( "actionType:" + actionType + ":" );
			if (actionType.equalsIgnoreCase( "Default" ))
			{
			  resString = actionDefault( dom, dom1,objContext, xtraParams );
			}
		}catch(Exception e)										
		{
			System.out.println("Exception :FullFinalActEJB :actionHandler(String xmlString):" + e.getMessage() + ":");
			log.write("Exception :FullFinalActEJB :actionHandler(String xmlString):" + e.getMessage() + ":");
			e.printStackTrace();
			log.writeException(e);
			throw new ITMException(e);
		}
		System.out.println("returning from actionMETHOD :actionHandler"+resString);
		//log.write("returning from actionMETHOD :actionHandler"+resString);
	    return resString;
	}

	private String actionDefault(Document dom,Document dom1, String objContext, String xtraParams) throws RemoteException , ITMException
	{
		String empCode = "", tranID = "", relieveDt = "", sqlStr ="";
		String resLnint ="", resAllwdedn ="", resMiscpay ="", resNp="", resGratuity ="";
		String returnString = "";
		Connection conn = null;
		ResultSet rs = null;
		Statement stmst = null;
		ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB(); 
		
		System.out.println("\t =====================================================");
		System.out.println("\t actionDefault Starts .........");
		System.out.println("\t =====================================================");

		log.write("===================actionDefault() method called=============================");

		NodeList nlist = dom1.getElementsByTagName("Detail2");

		System.out.println("[FullFinalActEJB] detail2 length==================>"+nlist.getLength());
		log.write("[FullFinalActEJB] dom2 length==================>"+nlist.getLength());
		StringBuffer valueXmlString = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root>\r\n");

		if(nlist.getLength() > 1)//added by nisar on 13/12/07  
		{		
			valueXmlString.append("</Root>\r\n");
			return valueXmlString.toString();
		}
		/*END*/
		resLnint = wf_calc_lnint(dom1);
		log.write("[FullFinalActEJB] resLnint=============>"+resLnint+"<====");
		if (resLnint != null && resLnint.indexOf("ERROR") > 0)
		{
			returnString = itmDBAccessEJB.getErrorString("", resLnint.substring(0,resLnint.indexOf(":")), "");
			return returnString;
		}
		valueXmlString = valueXmlString.append(resLnint);
		resAllwdedn = wf_calc_allwdedn(dom1);
		log.write("[FullFinalActEJB] resAllwdedn=============>"+resAllwdedn+"<====");
		if (resAllwdedn.indexOf("ERROR") > 0)
		{
			returnString = itmDBAccessEJB.getErrorString("", resAllwdedn.substring(0,resAllwdedn.indexOf(":")), "");
			return returnString;
		}
		valueXmlString = valueXmlString.append(resAllwdedn);
		resMiscpay = wf_calc_miscpay(dom1);
		log.write("[FullFinalActEJB] resMiscpay=============>"+resMiscpay+"<====");
		if (resMiscpay.indexOf("ERROR") > 0)
		{
			returnString = itmDBAccessEJB.getErrorString("", resMiscpay.substring(0,resMiscpay.indexOf(":")), "");
			return returnString;
		}	  	
		valueXmlString = valueXmlString.append(resMiscpay);
		resNp= wf_calc_np(dom1);
		log.write("[FullFinalActEJB] resNp=============>"+resNp+"<====");
		if (resNp.indexOf("ERROR") > 0)
		{
			returnString = itmDBAccessEJB.getErrorString("", resNp.substring(0,resNp.indexOf(":")), "");
			return returnString;
		}
		valueXmlString = valueXmlString.append(resNp);
		resGratuity = wf_calc_gratuity(dom1);
		log.write("[FullFinalActEJB] resGratuity=============>"+resGratuity+"<====");
		if (resGratuity.indexOf("ERROR") > 0)
		{
			returnString = itmDBAccessEJB.getErrorString("", resGratuity.substring(0,resGratuity.indexOf(":")), "");
			return returnString;
		}
		valueXmlString = valueXmlString.append(resGratuity);			
		valueXmlString.append("</Root>\r\n");
		log.write("[FullFinalActEJB] final valueXmlString=============>"+valueXmlString+"<====");					
		return valueXmlString.toString();
	}
	private String wf_calc_lnint(Document dom1) throws ITMException //calcOfLoanInt
	{
		String empCode = "", tranID = "", relieveDt = "", currCode = "", trDate ="", detInsert = "", remarks = "";
		String sqlStr ="", retString = "", prdCode = "", relieveDate = "";
		String cctrSalEmp ="", paySite ="", acctCodeSal = "", cctrSalAllwdedn = "", descr = "";
		String loanNo = "", schemeNo = "", adCodeDed = "", adCodeInt = "", finEntity = "", currCodeTo = ""; 
		double loanAmt = 0d, balanceAmt = 0d,intAmt = 0d, intDecucted = 0d, loanReco = 0d, retdAmt = 0d;
		double dailyExchrate = 0d;
		Connection conn = null;
		Statement stmt = null, stmt1 = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null, rsMain = null;
		java.sql.Timestamp effDate = null, expDate = null;
		System.out.println("\t =====================================================");
		System.out.println("\t calcOfLoanInt Starts .........");
		System.out.println("\t =====================================================");

		log.write("====================================wf_calc_lnint() method called=====================");
		try
		{
			ConnDriver connDriver = new ConnDriver();
			conn = connDriver.getConnectDB("DriverITM");
			conn.setAutoCommit(false);
		     stmt = conn.createStatement();
			
			GenericUtility genericUtility = GenericUtility.getInstance();
			
			empCode 	= genericUtility.getColumnValue("emp_code", dom1,"1");
			tranID  	= genericUtility.getColumnValue("tran_id", dom1,"1");
			relieveDt 	= genericUtility.getColumnValue("relieve_date", dom1,"1");
			currCode	= genericUtility.getColumnValue("curr_code", dom1,"1");
			trDate		= genericUtility.getColumnValue("tran_date", dom1,"1");

			System.out.println("[FullFinalActEJB] wf_calc_lnint() :empCode ===============>"+empCode);
			System.out.println("[FullFinalActEJB] wf_calc_lnint() :tranID ===============>"+tranID);
			System.out.println("[FullFinalActEJB] wf_calc_lnint() :relieveDt ===============>"+relieveDt);
			System.out.println("[FullFinalActEJB] wf_calc_lnint() :currCode ===============>"+currCode);
			System.out.println("[FullFinalActEJB] wf_calc_lnint() :trDate ===============>"+trDate);

			log.write("[FullFinalActEJB] wf_calc_lnint() :empCode ===============>"+empCode);
			log.write("[FullFinalActEJB] wf_calc_lnint() :tranID ===============>"+tranID);
			log.write("[FullFinalActEJB] wf_calc_lnint() :relieveDt ===============>"+relieveDt);
			log.write("[FullFinalActEJB] wf_calc_lnint() :currCode ===============>"+currCode);
			log.write("[FullFinalActEJB] wf_calc_lnint() :trDate ===============>"+trDate);


			
			java.util.Date tranDate = new java.util.Date();
			tranDate = new SimpleDateFormat(genericUtility.getApplDateFormat()).parse(trDate);
			
			relieveDate = genericUtility.getValidDateTimeString(relieveDt, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat());
			/*
			sqlStr = "SELECT CODE, FR_DATE, TO_DATE FROM PERIOD WHERE 	'"+relieveDate+"' BETWEEN FR_DATE AND TO_DATE ";
			System.out.println("Sql String : "+sqlStr);
			rs	= stmt.executeQuery(sqlStr);
			if(rs.next())
			{
				prdCode = rs.getString("CODE");
				effDate = rs.getTimestamp("FR_DATE");
				expDate = rs.getTimestamp("TO_DATE");
			}
			rs.close();
			rs = null;
			*/
			System.out.println("[FullFinalActEJB] wf_calc_lnint() :relieveDate ===============>"+relieveDate);
			log.write("[FullFinalActEJB] wf_calc_lnint() :relieveDate ===============>"+relieveDate);

			sqlStr = "SELECT CODE, FR_DATE, TO_DATE FROM PERIOD WHERE 	? BETWEEN FR_DATE AND TO_DATE ";
			
			System.out.println("Sql String : "+sqlStr);
			System.out.println("Sql String : "+sqlStr);
			
			pstmt = conn.prepareStatement(sqlStr);
			pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(relieveDate));
			rs	= pstmt.executeQuery();
			if(rs.next())
			{
				prdCode = rs.getString("CODE");
				effDate = rs.getTimestamp("FR_DATE");
				expDate = rs.getTimestamp("TO_DATE");
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;
			  
			System.out.println("[FullFinalActEJB] wf_calc_lnint() :prdCode ===============>"+prdCode);
			System.out.println("[FullFinalActEJB] wf_calc_lnint() :effDate ===============>"+effDate);
			System.out.println("[FullFinalActEJB] wf_calc_lnint() :expDate ===============>"+expDate);

			log.write("[FullFinalActEJB] wf_calc_lnint() :prdCode ===============>"+prdCode);
			log.write("[FullFinalActEJB] wf_calc_lnint() :effDate ===============>"+effDate);
			log.write("[FullFinalActEJB] wf_calc_lnint() :expDate ===============>"+expDate);

			sqlStr = "SELECT CCTR_CODE__SAL, PAY_SITE FROM EMPLOYEE WHERE EMP_CODE = '"+empCode+"'";

			System.out.println("Sql String : "+sqlStr);
			log.write("Sql String : "+sqlStr);
			
			rs = stmt.executeQuery(sqlStr);
			if(rs.next())
			{
				cctrSalEmp	= rs.getString("CCTR_CODE__SAL");
				paySite 	= rs.getString("PAY_SITE");
			}
			rs.close();
			rs = null;

			System.out.println("[FullFinalActEJB] wf_calc_lnint() :cctrSalEmp ===============>"+cctrSalEmp);
			System.out.println("[FullFinalActEJB] wf_calc_lnint() :paySite ===============>"+paySite);

			log.write("[FullFinalActEJB] wf_calc_lnint() :cctrSalEmp ===============>"+cctrSalEmp);
			log.write("[FullFinalActEJB] wf_calc_lnint() :paySite ===============>"+paySite);
			
			sqlStr = "SELECT A.LOAN_NO," +
					 " A.LOAN_AMT, " +
					 " A.BALANCE_AMT, " +
					 " A.SCHEME_NO, " +
					 " B.AD_CODE__DED, " +
					 " B.AD_CODE__INT, " +
					 " SUM( C.INTEREST_AMT )" +
					 " FROM LOANS A, LOAN_SCHEME B, LOANS_INTEREST C " +
					 " WHERE ( A.SCHEME_NO = B.SCHEME_NO ) AND " +
					 " ( A.LOAN_NO = C.LOAN_NO ) AND " +
					 " ( ( A.EMP_CODE = '"+empCode+"' ) AND " +
					 " ( B.SCHEME_NO = A.SCHEME_NO ) AND " +
					 " ( CASE WHEN C.CONFIRMED IS NULL THEN 'N' ELSE C.CONFIRMED END = 'Y' ) AND " +
					 " ( CASE WHEN A.STATUS IS NULL THEN 'U' ELSE A.STATUS END = 'A' ) ) " +
					 " GROUP BY A.LOAN_NO, A.LOAN_AMT, A.BALANCE_AMT, A.SCHEME_NO, B.AD_CODE__DED,  B.AD_CODE__INT " +
					 " ORDER BY A.LOAN_NO ASC, A.LOAN_AMT ASC, A.BALANCE_AMT ASC, A.SCHEME_NO ASC, B.AD_CODE__DED ASC, B.AD_CODE__INT ASC ";
			
			System.out.println("Sql String : "+sqlStr);
			log.write("Sql String : "+sqlStr);

			rsMain = stmt.executeQuery(sqlStr);
			if(rsMain.next())
			{
				do
				{
					loanNo 		= rsMain.getString("loan_no");
					loanAmt 	= rsMain.getDouble("loan_amt");
					balanceAmt 	= rsMain.getDouble("balance_amt");
					schemeNo 	= rsMain.getString("scheme_no");
					adCodeDed 	= rsMain.getString("ad_code__ded");
					adCodeInt 	= rsMain.getString("ad_code__int");
					intAmt 		= rsMain.getDouble("interest_amt");

					System.out.println("[FullFinalActEJB] wf_calc_lnint() :loanNo ===============>"+loanNo);
					System.out.println("[FullFinalActEJB] wf_calc_lnint() :loanAmt ===============>"+loanAmt);
					System.out.println("[FullFinalActEJB] wf_calc_lnint() :balanceAmt ===============>"+balanceAmt);
					System.out.println("[FullFinalActEJB] wf_calc_lnint() :schemeNo ===============>"+schemeNo);
					System.out.println("[FullFinalActEJB] wf_calc_lnint() :adCodeDed ===============>"+adCodeDed);
					System.out.println("[FullFinalActEJB] wf_calc_lnint() :adCodeInt ===============>"+adCodeInt);
					System.out.println("[FullFinalActEJB] wf_calc_lnint() :intAmt ===============>"+intAmt);

					log.write("[FullFinalActEJB] wf_calc_lnint() :loanNo ===============>"+loanNo);
					log.write("[FullFinalActEJB] wf_calc_lnint() :loanAmt ===============>"+loanAmt);
					log.write("[FullFinalActEJB] wf_calc_lnint() :balanceAmt ===============>"+balanceAmt);
					log.write("[FullFinalActEJB] wf_calc_lnint() :schemeNo ===============>"+schemeNo);
					log.write("[FullFinalActEJB] wf_calc_lnint() :adCodeDed ===============>"+adCodeDed);
					log.write("[FullFinalActEJB] wf_calc_lnint() :adCodeInt ===============>"+adCodeInt);
					log.write("[FullFinalActEJB] wf_calc_lnint() :intAmt ===============>"+intAmt);
					
					intDecucted = 0d;
					loanReco = 0d;
					// --- Collect total direct rercoverry against each loans
					sqlStr = "";
					sqlStr = "SELECT CASE WHEN SUM(CASE WHEN RECO_AMT IS NULL THEN 0 ELSE RECO_AMT END) IS NULL THEN 0 " +
							" ELSE SUM(CASE WHEN RECO_AMT IS NULL THEN 0 ELSE RECO_AMT END) END " +
							" FROM LOAN_RECO " +
							" WHERE LOAN_NO = '"+loanNo+"'"; 

					System.out.println("Sql String : "+sqlStr);
					log.write("Sql String : "+sqlStr);
					
					stmt1 = conn.createStatement();
					rs = stmt1.executeQuery(sqlStr);
					if (rs.next())
					{
						loanReco = rs.getDouble(1);
					}
					else
					{
						loanNo = "0";
					}
					rs.close();
					rs = null;
					stmt1.close();
					stmt1 = null;

					System.out.println("[FullFinalActEJB] wf_calc_lnint() :loanReco ===============>"+loanReco);
					System.out.println("[FullFinalActEJB] wf_calc_lnint() :loanNo ===============>"+loanNo);
					
					log.write("[FullFinalActEJB] wf_calc_lnint() :loanReco ===============>"+loanReco);
					log.write("[FullFinalActEJB] wf_calc_lnint() :loanNo ===============>"+loanNo);

					//--- Collect total rercovery done thru payroll (including interest) against each loans
					sqlStr = "SELECT CASE WHEN SUM(CASE WHEN PAYROLLDET.AMOUNT IS NULL THEN 0 ELSE PAYROLLDET.AMOUNT END) IS NULL THEN 0 " +
							" ELSE SUM(CASE WHEN PAYROLLDET.AMOUNT IS NULL THEN 0 ELSE PAYROLLDET.AMOUNT END) END " +
							" FROM PAYROLLDET,PERIOD" +
							" WHERE PAYROLLDET.EMP_CODE = '"+empCode+"'" +
							" AND PAYROLLDET.PRD_CODE = PERIOD.CODE" +
							" AND PERIOD.CODE > '0'" +
							" AND AYROLLDET.AD_CODE IN( '"+adCodeDed+"' , '"+adCodeInt+"')" +
							" AND AYROLLDET.REF_NO = '"+loanNo+"'";

					System.out.println("Sql String : "+sqlStr);
					log.write("Sql String : "+sqlStr);
					
					stmt1 = conn.createStatement();
					rs = stmt1.executeQuery(sqlStr);
					if (rs.next())
					{
						retdAmt = rs.getDouble(1);
					}
					else
					{
						retdAmt = 0d;
						intDecucted = 0d;
					}
					rs.close();
					rs = null;
					stmt1.close();
					stmt1 = null;
					System.out.println("[FullFinalActEJB] wf_calc_lnint() :retdAmt ===============>"+retdAmt);
					System.out.println("[FullFinalActEJB] wf_calc_lnint() :intDecucted ===============>"+intDecucted);

					log.write("[FullFinalActEJB] wf_calc_lnint() :retdAmt ===============>"+retdAmt);
					log.write("[FullFinalActEJB] wf_calc_lnint() :intDecucted ===============>"+intDecucted);

					//--- Calculate interest recovered
					intDecucted = ( retdAmt + loanReco ) - ( loanAmt - balanceAmt );
					if (intDecucted < intAmt)
					{
						//--- Calculate balance interest recoverable
						intAmt = intAmt - intDecucted;
					}
					else
					{
						//--- Interest recoverable is zero
						intAmt = 0d;
					}

					System.out.println("[FullFinalActEJB] wf_calc_lnint() : intAmt==>"+intAmt);
					System.out.println("[FullFinalActEJB] wf_calc_lnint() : intDecucted==>"+intDecucted);

					log.write("[FullFinalActEJB] wf_calc_lnint() : intAmt==>"+intAmt);
					log.write("[FullFinalActEJB] wf_calc_lnint() : intDecucted==>"+intDecucted);
					
					if (intAmt != 0)
					{
						remarks = "Interest On Loan No. : "+ loanNo;
						intAmt = intAmt *(-1);
						sqlStr = "SELECT ACCT_CODE__SAL, CCTR_CODE__SAL, DESCR " +
								 " FROM ALLWDEDN" +
								 " WHERE AD_CODE = '"+adCodeInt+"'";

						System.out.println("Sql String : "+sqlStr);
						log.write("Sql String : "+sqlStr);

						stmt1 = conn.createStatement();
						rs = stmt1.executeQuery(sqlStr);
						if(rs.next())
						{
							acctCodeSal 	= rs.getString("ACCT_CODE__SAL");
							cctrSalAllwdedn = rs.getString("CCTR_CODE__SAL");
							descr 			= rs.getString("DESCR");
						}
						rs.close();
						rs = null;
						stmt1.close();
						stmt1 = null;

						System.out.println("[FullFinalActEJB] wf_calc_lnint() :acctCodeSal ===============>"+acctCodeSal);
						System.out.println("[FullFinalActEJB] wf_calc_lnint() :cctrSalAllwdedn ===============>"+cctrSalAllwdedn);
						System.out.println("[FullFinalActEJB] wf_calc_lnint() :descr ===============>"+descr);

						log.write("[FullFinalActEJB] wf_calc_lnint() :acctCodeSal ===============>"+acctCodeSal);
						log.write("[FullFinalActEJB] wf_calc_lnint() :cctrSalAllwdedn ===============>"+cctrSalAllwdedn);
						log.write("[FullFinalActEJB] wf_calc_lnint() :descr ===============>"+descr);

						if (cctrSalAllwdedn == null)
						{
							cctrSalAllwdedn = cctrSalEmp;
						}
						sqlStr = "SELECT FIN_ENTITY FROM SITE WHERE SITE_CODE = '"+paySite+"'";

						System.out.println("Sql String : "+sqlStr);
						log.write("Sql String : "+sqlStr);
						
						stmt1 = conn.createStatement();
						rs = stmt1.executeQuery(sqlStr);
						if (rs.next())
						{
							finEntity = rs.getString("FIN_ENTITY");
						}
						rs.close();
						rs = null;
						stmt1.close();
						stmt1 = null;
						sqlStr = "SELECT CURR_CODE FROM FINENT WHERE FIN_ENTITY = '"+finEntity+"'";

						System.out.println("Sql String : "+sqlStr);
						log.write("Sql String : "+sqlStr);

						stmt1 = conn.createStatement();
						rs = stmt1.executeQuery(sqlStr);
						if (rs.next())
						{
							currCodeTo = rs.getString("CURR_CODE");	
							System.out.println("[FullFinalActEJB] wf_calc_lnint() :currCodeTo ===============>"+currCodeTo);
							log.write("[FullFinalActEJB] wf_calc_lnint() :currCodeTo ===============>"+currCodeTo);
						}
						else
						{
							System.out.println("[FullFinalActEJB] wf_calc_lnint() :errorCode ===============>VTNOROWS:ERROR");
							log.write("[FullFinalActEJB] wf_calc_lnint() :errorCode ===============>VTNOROWS:ERROR");  

							return "VTNOROWS:ERROR";
						}
						rs.close();
						rs = null;
						stmt1.close();
						stmt1 = null;
						java.util.Date nullDate = null;
						ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
						dailyExchrate = itmDBAccessEJB.getDailyExchRateSellBuy(currCode, currCodeTo, paySite, tranDate, 'B', conn);
						detInsert = detInsert + wf_det_insert(tranID,adCodeInt,descr,intAmt,nullDate,"","",acctCodeSal,cctrSalAllwdedn,remarks,"","",currCode,1,intAmt,dailyExchrate);
						//updated by nisar on 08/12/07 
					}
				}while(rsMain.next());
			}
			else
			{
				//return "VTNOROWS:ERROR";
				return "";
			}
		}
		catch(SQLException se)
		{
			System.out.println("SQLException[] :[FullFinalActEJB : wf_calc_lnint()][Excuting Query Failed]" + sqlStr + se.getMessage());
			log.write("SQLException[] :[FullFinalActEJB : wf_calc_lnint()][Excuting Query Failed]" + sqlStr + se.getMessage());

			se.printStackTrace();
			throw new ITMException(se);
		}
		catch(Exception e)
		{
			System.out.println("Exception :[FullFinalActEJB][function::wf_calc_lnint()] :==>\n"+e.getMessage());
			log.write("Exception :[FullFinalActEJB][function::wf_calc_lnint()] :==>\n"+e.getMessage());
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				System.out.println("Closing Connection.....");
				log.write("Closing Connection.....");
				if(stmt != null)
				{
					stmt.close();
					stmt = null;
				}
				if(stmt1 != null)
				{
					stmt1.close();
					stmt1 = null;
				}
				if(conn != null)
				{
					conn.close();
					conn = null;
				}
			}
			catch(Exception e)
			{
				System.out.println("[FullFinalActEJB]	Exception : wf_calc_lnint(): Exception Occured =>>"+e.getMessage());
				log.write("[FullFinalActEJB]	Exception : wf_calc_lnint(): Exception Occured =>>"+e.getMessage());
				e.printStackTrace();
				throw new ITMException(e);
			}
		}
		return detInsert;
	}
	private String wf_calc_allwdedn(Document dom1) throws ITMException
	{
		String empCode = "", tranID = "", relieveDt = "", currCode = "", toDate ="", detInsert = "", remarks = "";
		String adCode = "", cctrSalEmp = "", paySite = "", refType = "", refNo ="", acctCodeSal = "", shDescr = "", payable = "", cctrCode = "";
		String finEntity = "", currCodeTo = "", trDate = "";
		String sqlStr = "", sqlStr1 = "", retString = "";
		String startDt = "", endDt = "";
		double amount = 0.0, adjAmt = 0.0, balanceAmt = 0.0, dailyExchrate = 0.0, amount1 = 0.0;
		int days1 = 0, days2 = 0;
		java.sql.Timestamp startDate = null, endDate = null;
		
		Connection conn = null;
		ResultSet rs = null, rsMain = null;
		PreparedStatement stmt = null, stmt1 = null;
		ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
		System.out.println("\t =====================================================");
		System.out.println("\t calcOfAllwDedn Starts .........");
		System.out.println("\t =====================================================");

		log.write("\t =====================================================");
		log.write("\t calcOfAllwDedn Starts .........");
		log.write("\t =====================================================");

		
		try
		{
			ConnDriver connDriver = new ConnDriver();
			conn = connDriver.getConnectDB("DriverITM");
			//stmt = conn.createStatement();
			
			GenericUtility genericUtility = GenericUtility.getInstance();
			
			empCode 	= genericUtility.getColumnValue("emp_code", dom1,"1");//UPDATED BY NISAR ON 13/12/07 
			tranID  	= genericUtility.getColumnValue("tran_id", dom1,"1");
			relieveDt 	= genericUtility.getColumnValue("relieve_date", dom1,"1");
			currCode 	= genericUtility.getColumnValue("curr_code", dom1,"1");
			trDate 		= genericUtility.getColumnValue("tran_date", dom1,"1");
			java.util.Date tranDate = new java.util.Date();
			tranDate = new SimpleDateFormat(genericUtility.getApplDateFormat()).parse(trDate);
			
			sqlStr = "SELECT CCTR_CODE__SAL, PAY_SITE FROM EMPLOYEE WHERE EMP_CODE = '"+empCode+"'";

			System.out.println("sqlStr..:: " + sqlStr);
			log.write("sqlStr..:: " + sqlStr);
			
			stmt = conn.prepareStatement( sqlStr );
			//rs = stmt.executeQuery(sqlStr);
			rs = stmt.executeQuery( );
			if( rs.next() )
			{
				cctrSalEmp = rs.getString("CCTR_CODE__SAL");
				paySite = rs.getString("PAY_SITE");
			}
			rs.close();
			rs = null;
			stmt.close();
			stmt = null;
			
			System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :cctrSalEmp ===============>"+cctrSalEmp);
			System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :paySite ===============>"+paySite); 
			
			log.write("[FullFinalActEJB] wf_calc_allwdedn() :cctrSalEmp ===============>"+cctrSalEmp);
			log.write("[FullFinalActEJB] wf_calc_allwdedn() :paySite ===============>"+paySite);

			sqlStr = "SELECT AD_CODE, START_DATE, END_DATE" +
					" FROM ALLOWDEDN_BAL" +
					" WHERE EMP_CODE = '"+empCode+"' and AMT_BAL <> 0";

			System.out.println("sqlStr..:: " + sqlStr);
			log.write("sqlStr..:: " + sqlStr);
			
			stmt = conn.prepareStatement( sqlStr );
			//rsMain = stmt.executeQuery(sqlStr);    changes on 31/08/09 by manazir 
			rsMain = stmt.executeQuery();
			while( rsMain.next() )
			{
				adCode		= rsMain.getString( "AD_CODE" );
				startDate	= rsMain.getTimestamp( "START_DATE" );
				endDate 	= rsMain.getTimestamp( "END_DATE" );
				
				startDt = genericUtility.getValidDateString(startDate.toString(), genericUtility.getDBDateFormat(), genericUtility.getApplDateFormat());
				endDt 	= genericUtility.getValidDateString(endDate.toString(), genericUtility.getDBDateFormat(), genericUtility.getApplDateFormat());
				
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :adCode ===============>"+adCode);
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :startDate ===============>"+startDate);
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :endDate ===============>"+endDate);

				log.write("[FullFinalActEJB] wf_calc_allwdedn() :adCode ===============>"+adCode);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :startDate ===============>"+startDate);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :endDate ===============>"+endDate);				

				sqlStr = "SELECT AMOUNT, AMT_ADJ, AMT_BAL, REF_TYPE, REF_NO" +
						 " FROM ALLOWDEDN_BAL" +
						 //" WHERE EMP_CODE = '"+empCode+"' AND AD_CODE = '"+adCode+"' AND START_DATE = '"+startDate+"' AND END_DATE = '"+endDate+"'";
						 " WHERE EMP_CODE = '"+empCode+"' AND AD_CODE = '"+adCode+"' AND START_DATE = ? AND END_DATE = ? ";
				System.out.println("sqlStr..:: " + sqlStr);
				log.write("sqlStr..:: " + sqlStr);
				stmt1 = conn.prepareStatement( sqlStr );
				
				stmt1.setTimestamp( 1, startDate );
				stmt1.setTimestamp( 2, endDate );
				
				//rs = stmt.executeQuery(sqlStr);
				rs = stmt1.executeQuery( );

				//stmt1 = conn.createStatement();
				 // rs = stmt1.executeQuery( ); changes on 31/08/09 by manazir 
				if( rs.next() )
				{
					amount 		= rs.getDouble("AMOUNT");
					adjAmt 		= rs.getDouble("AMT_ADJ");
					balanceAmt 	= rs.getDouble("AMT_BAL");
					refType 	= rs.getString("REF_TYPE");
					refNo 		= rs.getString("REF_NO");	
				}
				rs.close();
				stmt1.close();
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :amount ===============>"+amount);
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :adjAmt ===============>"+adjAmt);
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :balanceAmt ===============>"+balanceAmt);
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :refType ===============>"+refType);
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :refNo ===============>"+refNo);

				log.write("[FullFinalActEJB] wf_calc_allwdedn() :amount ===============>"+amount);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :adjAmt ===============>"+adjAmt);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :balanceAmt ===============>"+balanceAmt);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :refType ===============>"+refType);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :refNo ===============>"+refNo);
				
				sqlStr = "SELECT SH_DESCR, PAYABLE, ACCT_CODE__SAL, CCTR_CODE__SAL " +
					 	" FROM ALLWDEDN WHERE AD_CODE = '" + adCode + "'";

				System.out.println( "sqlStr..:: " + sqlStr );
				log.write( "sqlStr..:: " + sqlStr );

				stmt1 = conn.prepareStatement( sqlStr );
				//rs = stmt1.executeQuery(sqlStr);
				rs = stmt1.executeQuery( );
				
				if(rs.next())
				{
					shDescr 	= rs.getString("SH_DESCR");
					payable 	= rs.getString("PAYABLE");
					acctCodeSal = rs.getString("ACCT_CODE__SAL");
					cctrCode 	= rs.getString("CCTR_CODE__SAL");	 
				}
				rs.close();
				stmt1.close();
				
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :payable ===============>"+payable);
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :acctCodeSal ===============>"+acctCodeSal);
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :cctrCode ===============>"+cctrCode);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :payable ===============>"+payable);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :acctCodeSal ===============>"+acctCodeSal);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :cctrCode ===============>"+cctrCode);

				sqlStr = "SELECT FIN_ENTITY FROM SITE WHERE SITE_CODE = '"+paySite+"'";

				System.out.println("sqlStr..:: " + sqlStr);
				log.write("sqlStr..:: " + sqlStr);

				stmt1 = conn.prepareStatement( sqlStr );
				rs = stmt1.executeQuery( );
				if (rs.next())
				{
					finEntity = rs.getString( "FIN_ENTITY" );
				}
				rs.close();
				stmt1.close();
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :finEntity ===============>"+finEntity);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :finEntity ===============>"+finEntity);

				sqlStr = "SELECT CURR_CODE FROM FINENT WHERE FIN_ENTITY = '"+finEntity+"'";

				System.out.println("sqlStr..:: " + sqlStr);
				log.write("sqlStr..:: " + sqlStr);
				
				stmt1 = conn.prepareStatement( sqlStr );
				rs = stmt1.executeQuery( );
				if (rs.next())
				{
					currCodeTo = rs.getString("CURR_CODE");
				}
				rs.close();
				stmt1.close();
				
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :currCodeTo ===============>"+currCodeTo);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :currCodeTo ===============>"+currCodeTo);

				dailyExchrate = itmDBAccessEJB.getDailyExchRateSellBuy(currCode, currCodeTo, paySite, tranDate, 'B', conn);
				
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :dailyExchrate ===============>"+dailyExchrate);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :dailyExchrate ===============>"+dailyExchrate);

				if (cctrSalEmp != null)
				{
					cctrCode = cctrSalEmp;
				}
				remarks = ""+ shDescr + "for " + startDt + " to " + endDt ;
				
				System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :remarks ===============>"+remarks);
				System.out.println("[FullFinalActEJB] payable========>"+payable);
				log.write("[FullFinalActEJB] wf_calc_allwdedn() :remarks ===============>"+remarks);
				log.write("[FullFinalActEJB] payable========>"+payable);

				if(payable.equals("D"))
				{
					amount1 = balanceAmt * ( -1 );				

					System.out.println("[FullFinalActEJB] amount1========>"+amount1);
					System.out.println("[FullFinalActEJB] balanceAmt========>"+balanceAmt);
					log.write("[FullFinalActEJB] amount1========>"+amount1);
					log.write("[FullFinalActEJB] balanceAmt========>"+balanceAmt);				

					detInsert = detInsert + wf_det_insert(tranID,adCode,shDescr,amount1,startDate,refType,refNo,acctCodeSal,cctrCode,remarks,"","",currCode,1,amount1,dailyExchrate);
					//updated by nisar on 08/12/07 
				}
				else if(payable.equals("N"))
				{
					detInsert = detInsert + wf_det_insert(tranID,adCode,shDescr,balanceAmt,startDate,refType,refNo,acctCodeSal,cctrCode,remarks,"","",currCode,1,balanceAmt,dailyExchrate);
					//updated by nisar on 08/12/07 
				}
				else if(payable.equals("A") || payable.equals("P"))
				{
					days1 = daysAfter(startDt, endDt) + 1;
					days2 = daysAfter(startDt, relieveDt) + 1;

					System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :days1 ===============>"+days1);
					System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :days2 ===============>"+days2);	
					System.out.println("[FullFinalActEJB] wf_calc_allwdedn() :adjAmt ===============>"+adjAmt);
					log.write("[FullFinalActEJB] wf_calc_allwdedn() :days1 ===============>"+days1);
					log.write("[FullFinalActEJB] wf_calc_allwdedn() :days2 ===============>"+days2);	
					log.write("[FullFinalActEJB] wf_calc_allwdedn() :adjAmt ===============>"+adjAmt);

					/*commented by nisar on 29/11/07  as per discussion with mr. subrata
					if(days2 > 0)
					{
						if(days1 > 0 )
						{//added by nisar on 27/11/07 
							amount1 = balanceAmt * days2 / days1;
						}
						amount1 = amount1 - adjAmt;
					}
					else
					{ //comment ends here*/
						amount1 = balanceAmt;
					//}
					detInsert = detInsert + wf_det_insert(tranID,adCode,shDescr,amount1,startDate,refType,refNo,acctCodeSal,cctrCode,remarks,"","",currCode,1,amount1,dailyExchrate);
					//UPDATED BY NISAR ON 08/12/07 
				}
			}
			rsMain.close();
			rsMain = null;
		}
		catch(SQLException se)
		{
			System.out.println("SQLException[] :[FullFinalActEJB : wf_calc_allwdedn()][Excuting Query Failed]" + sqlStr + se.getMessage());
			log.write("SQLException[] :[FullFinalActEJB : wf_calc_allwdedn()][Excuting Query Failed]" + sqlStr + se.getMessage());
			se.printStackTrace();
			retString = se.getMessage();
			throw new ITMException(se);
		}
		catch(Exception e)
		{
			System.out.println("Exception :[FullFinalActEJB][function::wf_calc_allwdedn()] :==>\n"+e.getMessage());
			log.write("Exception :[FullFinalActEJB][function::wf_calc_allwdedn()] :==>\n"+e.getMessage());
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				System.out.println("Closing Connection.....");
				log.write("Closing Connection.....");
				if(rsMain != null)
				{
					rsMain.close();
					rsMain = null;
				}
				if(stmt != null)
				{
					stmt.close();
					stmt = null;
				}
				if(conn != null)
				{
					conn.close();
					conn = null;
				}
			}
			catch(Exception e)
			{
				System.out.println("[FullFinalActEJB]	Exception : wf_calc_allwdedn(): Exception Occured =>>"+e.getMessage());
				log.write("[FullFinalActEJB]	Exception : wf_calc_allwdedn(): Exception Occured =>>"+e.getMessage());
				e.printStackTrace();
				throw new ITMException(e);
			}
		}
		
		return detInsert;
	}
	private String wf_calc_miscpay(Document dom1) throws ITMException
	{
		String empCode = "", tranID = "", cadreCode = "", currCode = "", detInsert = "", remarks = "", gradeCode = "", refSer = "";
		String adCode = "", cctrSalEmp = "", paySite = "", refType = "", refNo ="", cctrCode = "";
		String finEntity = "", currCodeTo = "", trDate = "", acctCode = "", currFluc = "", descr = "";
		String sqlStr = "", sqlStr1 = "", retString = "", errorCode = "", errString = "";
		double diffExchrate = 0.0, diffAmt = 0.0, balanceAmt = 0.0, dailyExchrate = 0.0, exchRate = 0.0, netAmt = 0.0;
		java.sql.Date nullDate = null, endDate = null;
		
		Connection conn = null;
		ResultSet rs = null, rsMain = null;
		Statement stmt = null, stmt1 = null;
		ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
		System.out.println("\t =====================================================");
		System.out.println("\t calcOfMiscPay Starts .........");
		System.out.println("\t =====================================================");

		log.write("===================wf_calc_miscpay() method called==================================");
		
		try
		{
			ConnDriver connDriver = new ConnDriver();
			conn = connDriver.getConnectDB("DriverITM");
			stmt = conn.createStatement();
			
			GenericUtility genericUtility = GenericUtility.getInstance();
			
			empCode 	= genericUtility.getColumnValue("emp_code", dom1,"1");//UPDATED BY NISAR ON 13/12/07 
			tranID  	= genericUtility.getColumnValue("tran_id", dom1,"1");
			trDate 		= genericUtility.getColumnValue("tran_date", dom1,"1");
			java.util.Date tranDate = new java.util.Date();
			tranDate = new SimpleDateFormat(genericUtility.getApplDateFormat()).parse(trDate);
			sqlStr = "SELECT CCTR_CODE__SAL, PAY_SITE, CADRE, GRADE FROM EMPLOYEE WHERE EMP_CODE = '"+empCode+"'";
			System.out.println("sqlStr1....:: " + sqlStr);
			log.write("sqlStr1....:: " + sqlStr);
			rs = stmt.executeQuery(sqlStr);
			if(rs.next())
			{
				cctrSalEmp	= rs.getString("CCTR_CODE__SAL");
				paySite		= rs.getString("PAY_SITE");
				cadreCode	= rs.getString("CADRE");
				gradeCode	= rs.getString("GRADE");
			}
			rs.close();

			System.out.println("[FullFinalActEJB] wf_calc_miscpay() :cctrSalEmp ===============>"+cctrSalEmp);
			System.out.println("[FullFinalActEJB] wf_calc_miscpay() :paySite ===============>"+paySite);
			System.out.println("[FullFinalActEJB] wf_calc_miscpay() :cadreCode ===============>"+cadreCode);
			System.out.println("[FullFinalActEJB] wf_calc_miscpay() :gradeCode ===============>"+gradeCode);

			log.write("[FullFinalActEJB] wf_calc_miscpay() :cctrSalEmp ===============>"+cctrSalEmp);
			log.write("[FullFinalActEJB] wf_calc_miscpay() :paySite ===============>"+paySite);
			log.write("[FullFinalActEJB] wf_calc_miscpay() :cadreCode ===============>"+cadreCode);
			log.write("[FullFinalActEJB] wf_calc_miscpay() :gradeCode ===============>"+gradeCode);

			sqlStr = "";
			sqlStr = "SELECT TRAN_SER, REF_NO FROM MISC_PAYABLES " +
					" WHERE SUNDRY_TYPE = 'E' AND SUNDRY_CODE = '"+empCode+"' AND TOT_AMT - ADJ_AMT <> 0 ";
			
			System.out.println("sqlStr2....:: " + sqlStr);
			log.write("sqlStr2....:: " + sqlStr);

			rsMain = stmt.executeQuery(sqlStr);
			while(rsMain.next())
			{
				refSer	= rsMain.getString("TRAN_SER");
				refNo	= rsMain.getString("REF_NO");
				sqlStr = "SELECT TOT_AMT - ADJ_AMT, ACCT_CODE, CCTR_CODE, CURR_CODE, EXCH_RATE " +
						" FROM MISC_PAYABLES" +
						" WHERE TRAN_SER = '"+refSer+"' AND REF_NO = '"+refNo+"'";
				
				System.out.println("sqlStr3....:: " + sqlStr);
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :refSer ===============>"+refSer);
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :refNo ===============>"+refNo);

				log.write("sqlStr3....:: " + sqlStr);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :refSer ===============>"+refSer);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :refNo ===============>"+refNo);

				stmt1 = conn.createStatement();
				rs = stmt1.executeQuery(sqlStr);
				while(rs.next())
				{
					balanceAmt	= rs.getDouble(1);
					acctCode	= rs.getString("ACCT_CODE");
					cctrCode	= rs.getString("CCTR_CODE");
					currCode	= rs.getString("CURR_CODE");
					exchRate	= rs.getDouble("EXCH_RATE");
				}
				rs.close();
				stmt1.close();
				stmt1 = null;

				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :balanceAmt ===============>"+balanceAmt);
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :acctCode ===============>"+acctCode);
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :cctrCode ===============>"+cctrCode);
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :currCode ===============>"+currCode);
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :exchRate ===============>"+exchRate);

				log.write("[FullFinalActEJB] wf_calc_miscpay() :balanceAmt ===============>"+balanceAmt);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :acctCode ===============>"+acctCode);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :cctrCode ===============>"+cctrCode);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :currCode ===============>"+currCode);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :exchRate ===============>"+exchRate);

				if(cctrSalEmp != null)
				{
					cctrCode = cctrSalEmp;
				}
				netAmt = balanceAmt * exchRate;
				sqlStr = "SELECT FIN_ENTITY FROM SITE WHERE SITE_CODE = '"+paySite+"'";

				System.out.println("sqlStr4....:: " + sqlStr);
				log.write("sqlStr4....:: " + sqlStr);
				
				stmt1 = conn.createStatement();
				rs = stmt1.executeQuery(sqlStr);
				while(rs.next())
				{
					finEntity = rs.getString("FIN_ENTITY");
				}
				rs.close();
				stmt1.close();
				stmt1 = null;

				sqlStr = "SELECT CURR_CODE FROM FINENT WHERE FIN_ENTITY = '"+finEntity+"'";

				System.out.println("sqlStr5....:: " + sqlStr);
				log.write("sqlStr5....:: " + sqlStr);

				stmt1 = conn.createStatement();
				rs = stmt1.executeQuery(sqlStr);
				while(rs.next())
				{
					currCodeTo = rs.getString("CURR_CODE");
				}
				rs.close();
				stmt1.close();
				stmt1 = null;
				
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :currCodeTo ===============>"+currCodeTo);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :currCodeTo ===============>"+currCodeTo);

				dailyExchrate = itmDBAccessEJB.getDailyExchRateSellBuy(currCode, currCodeTo, paySite, tranDate, 'B', conn);
				
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :dailyExchrate ===============>"+dailyExchrate);
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :refSer ===============>"+refSer);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :dailyExchrate ===============>"+dailyExchrate);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :refSer ===============>"+refSer);

				if(refSer.trim().equals("M-VOUC") || refSer.trim().equals("M-ADV"))
				{
					sqlStr = "SELECT REMARKS FROM MISC_VOUCHER WHERE TRAN_ID = '"+refNo+"'";
					System.out.println("sqlStr6....:: " + sqlStr);
					log.write("sqlStr6....:: " + sqlStr);
					stmt1 = conn.createStatement();
					rs = stmt1.executeQuery(sqlStr);
					if(rs.next())
					{
						remarks = rs.getString("REMARKS");
					}
					rs.close();
					stmt1.close();
					stmt1 = null;
				}
				else if(refSer.trim().equals("P-VOUC"))
				{
					sqlStr = "SELECT REMARKS FROM PAYR_VOUCHER WHERE TRAN_ID = '"+refNo+"'";

					System.out.println("sqlStr6....:: " + sqlStr);
					log.write("sqlStr6....:: " + sqlStr);
					
					stmt1 = conn.createStatement();
					rs = stmt1.executeQuery(sqlStr);
					if(rs.next())
					{
						remarks = rs.getString("REMARKS");
					}
					rs.close();
					stmt1.close();
					stmt1 = null;
				}
				if(dailyExchrate > exchRate)
				{
					diffExchrate = dailyExchrate - exchRate;
					diffAmt = diffAmt + (balanceAmt * diffExchrate);
				}
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :diffExchrate ===============>"+diffExchrate);
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :diffAmt ===============>"+diffAmt);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :diffExchrate ===============>"+diffExchrate);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :diffAmt ===============>"+diffAmt);

				detInsert = detInsert + wf_det_insert(tranID,"","",balanceAmt,nullDate,"","",acctCode,cctrCode,remarks,refSer,refNo,currCode,exchRate,netAmt,dailyExchrate);//updated on 08/12/07  
			}//end of while(rsMain.next())
			rsMain.close();
			stmt.close();
			stmt = null;
			acctCode = ""; cctrCode = ""; 
			if(diffAmt != 0)
			{
				currFluc = getEnvAdm(paySite,cadreCode,gradeCode,"CURR_FLUCTUATION",tranDate,conn);
				
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :currFluc ===============>"+currFluc);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :currFluc ===============>"+currFluc);

				if(currFluc.trim().equals("NULLFOUND"))
				{
					errorCode = "VSENVAR";
					errString = itmDBAccessEJB.getErrorString("",errorCode,"","",conn);

					System.out.println("errString:"+errString+":");
					log.write("errString:"+errString+":");

					return errString;
				}
				sqlStr = "SELECT ACCT_CODE__SAL, CCTR_CODE__SAL, DESCR FROM ALLWDEDN WHERE AD_CODE = '"+currFluc+"'";
				System.out.println("sqlStr7....:: " + sqlStr);
				log.write("sqlStr7....:: " + sqlStr);
				stmt = conn.createStatement();
				rs = stmt.executeQuery(sqlStr);
				if(rs.next())
				{
					acctCode	= rs.getString("ACCT_CODE__SAL");
					cctrCode	= rs.getString("CCTR_CODE__SAL");
					descr		= rs.getString("DESCR");
				}
				rs.close();
				stmt.close();
				stmt = null;

				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :acctCode ===============>"+acctCode);
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :cctrCode ===============>"+cctrCode);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :acctCode ===============>"+acctCode);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :cctrCode ===============>"+cctrCode);				
												
				if(cctrSalEmp != null)
				{
					cctrCode = cctrSalEmp;
				}
				netAmt = diffAmt;
				balanceAmt = netAmt;
				remarks = "Towards Currency Fluctuation";

				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :netAmt ===============>"+netAmt);
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :balanceAmt ===============>"+balanceAmt);
				System.out.println("[FullFinalActEJB] wf_calc_miscpay() :remarks ===============>"+remarks);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :netAmt ===============>"+netAmt);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :balanceAmt ===============>"+balanceAmt);
				log.write("[FullFinalActEJB] wf_calc_miscpay() :remarks ===============>"+remarks);

				detInsert = detInsert + wf_det_insert(tranID,currFluc,descr,balanceAmt,nullDate,"","",acctCode,cctrCode,remarks,"","",currCode,1,netAmt,1);
				//updated by nisar on 08/12/07 
			}
		}
		catch(SQLException se)
		{
			System.out.println("SQLException[] :[FullFinalActEJB : wf_calc_miscpay()][Excuting Query Failed]" + sqlStr + se.getMessage());
			log.write("SQLException[] :[FullFinalActEJB : wf_calc_miscpay()][Excuting Query Failed]" + sqlStr + se.getMessage());
			se.printStackTrace();
			retString = se.getMessage();
			throw new ITMException(se);
		}
		catch(Exception e)
		{
			System.out.println("Exception :[FullFinalActEJB][function::wf_calc_miscpay()] :==>\n"+e.getMessage());
			log.write("Exception :[FullFinalActEJB][function::wf_calc_miscpay()] :==>\n"+e.getMessage());
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				System.out.println("Closing Connection.....");
				log.write("Closing Connection.....");
				if(stmt != null)
				{
					stmt.close();
					stmt = null;
				}
				if(stmt1 != null)
				{
					stmt1.close();
					stmt1 = null;
				}
				if(conn != null)
				{
					conn.close();
					conn = null;
				}
			}
			catch(Exception e)
			{
				e.printStackTrace();
				log.write("Exception :[FullFinalActEJB][function::wf_calc_miscpay()] :==>\n"+e.getMessage());
				System.out.println("Exception :[FullFinalActEJB][function::wf_calc_miscpay()] :==>\n"+e.getMessage());
			}
		}
		return detInsert;
	}
	private String wf_calc_np(Document dom1) throws ITMException
	{
		String empCode = "", tranID = "", relieveDt = "", currCode = "", detInsert = "", remarks = "", refSer = "";
		String adCode = "", cctrCodeSal = "", paySite = "", refType = "", refNo ="", cctrCode = "";
		String finEntity = "", currCodeTo = "", trDate = "", acctCode = "", currFluc = "", descr = "";
		String prdCode = "", plad = "", errorCode = "", leaveDays = "", absentDays = "", plprop = "";
		String  noticeAd = "", gradeCode = "", cadreCode = "", workSite = "", leaveTblNo = "", leaveCode = "";
		String plEncash = "", plEncon = "", plDescr = "", adDescr = "", errString = "";
		String sqlStr = "", sqlStr1 = "", retString = "";
		String resignDt = "", relvDate = "", cctrCodeSalEmp = "";
		double diffExchrate = 0.0, amount = 0.0, balanceAmt = 0.0, dailyExchrate = 0.0, exchRate = 0.0, amount1 = 0.0;
		double balanceDays = 0.0, amount2 = 0.0;
		int noticePrd = 0, noOfDays = 0, sumOfDays = 0, noticeDays = 0, diff = 0, daysAfter1 = 0;
		int sumOfLeaveDays = 0, sumOfPaidDays = 0, days1 = 0, diffDays = 0, totalDays = 0;
		java.sql.Date nullDate = null, endDate = null, resignDate= null, relieveDateDb = null;
		java.sql.Timestamp 	resignDateT = null,	relieveDateDbT = null;
		
		Connection conn = null;
		ResultSet rs = null, rs1 = null;
		PreparedStatement stmt = null, stmt1 = null;
		PreparedStatement pstmt = null;
		ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
		System.out.println("\t =====================================================");
		System.out.println("\t calcOfNoticePay Starts .........");
		System.out.println("\t =====================================================");

		log.write("=====================wf_calc_np() method called=============================");
		
		try
		{
			ConnDriver connDriver = new ConnDriver();
			conn = connDriver.getConnectDB("DriverITM");
			//stmt = conn.createStatement();
			
			GenericUtility genericUtility = GenericUtility.getInstance();
			
			empCode 	= genericUtility.getColumnValue("emp_code", dom1,"1");//UPDATED BY NISAR ON 13/12/07 
			tranID  	= genericUtility.getColumnValue("tran_id", dom1,"1");
			currCode  	= genericUtility.getColumnValue("curr_code", dom1,"1");
			relieveDt  	= genericUtility.getColumnValue("relieve_date", dom1,"1");
			trDate 		= genericUtility.getColumnValue("tran_date", dom1,"1");
			java.util.Date tranDate = new java.util.Date();
			java.sql.Timestamp relieveDate = null;
			relieveDate = java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(relieveDt,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()));
			tranDate	= new SimpleDateFormat(genericUtility.getApplDateFormat()).parse(trDate);
			
			sqlStr = "SELECT RESI_DATE, NOTICE_PRD, RELIEVE_DATE, CCTR_CODE__SAL, PAY_SITE, GRADE, CADRE " +
					" FROM EMPLOYEE WHERE EMP_CODE = '"+empCode+"'";
			System.out.println("sqlStr1 : " + sqlStr);
			log.write("sqlStr1 : " + sqlStr);
			stmt = conn.prepareStatement( sqlStr );
			rs = stmt.executeQuery( );
			if(rs.next())
			{
				resignDate		= rs.getDate("RESI_DATE");
				resignDateT		= rs.getTimestamp("RESI_DATE");	//added by nisar on 27/11/07 
				noticePrd 		= rs.getInt("NOTICE_PRD");
				relieveDateDb 	= rs.getDate("RELIEVE_DATE");
				relieveDateDbT	= rs.getTimestamp("RELIEVE_DATE");//added by nisar on 27/11/07 	
				cctrCodeSal 	= rs.getString("CCTR_CODE__SAL");
				paySite 		= rs.getString("PAY_SITE");
				gradeCode		= rs.getString("GRADE");
				cadreCode		= rs.getString("CADRE");
			}
			rs.close();
			
			System.out.println("[FullFinalActEJB] wf_calc_np() :resignDate ===============>"+resignDate);
			System.out.println("[FullFinalActEJB] wf_calc_np() :noticePrd ===============>"+noticePrd);
			System.out.println("[FullFinalActEJB] wf_calc_np() :relieveDateDb ===============>"+relieveDateDb);
			System.out.println("[FullFinalActEJB] wf_calc_np() :cctrCodeSal ===============>"+cctrCodeSal);
			System.out.println("[FullFinalActEJB] wf_calc_np() :paySite ===============>"+paySite);
			System.out.println("[FullFinalActEJB] wf_calc_np() :gradeCode ===============>"+gradeCode);
			System.out.println("[FullFinalActEJB] wf_calc_np() :cadreCode ===============>"+cadreCode);
			log.write("[FullFinalActEJB] wf_calc_np() :resignDate ===============>"+resignDate);
			log.write("[FullFinalActEJB] wf_calc_np() :noticePrd ===============>"+noticePrd);
			log.write("[FullFinalActEJB] wf_calc_np() :relieveDateDb ===============>"+relieveDateDb);
			log.write("[FullFinalActEJB] wf_calc_np() :cctrCodeSal ===============>"+cctrCodeSal);
			log.write("[FullFinalActEJB] wf_calc_np() :paySite ===============>"+paySite);
			log.write("[FullFinalActEJB] wf_calc_np() :gradeCode ===============>"+gradeCode);
			log.write("[FullFinalActEJB] wf_calc_np() :cadreCode ===============>"+cadreCode);
			
			resignDt	= genericUtility.getValidDateString(resignDate.toString(), genericUtility.getDBDateFormat(), genericUtility.getApplDateFormat());
			relvDate 	= genericUtility.getValidDateString(relieveDateDb.toString(), genericUtility.getDBDateFormat(), genericUtility.getApplDateFormat());
			System.out.println("[FullFinalActEJB]relvDate===================>"+relvDate);
			System.out.println("[FullFinalActEJB]resignDt===================>"+resignDt);
			log.write("[FullFinalActEJB]relvDate===================>"+relvDate);
			log.write("[FullFinalActEJB]resignDt===================>"+resignDt);

			plad = getEnv("999999","NOTICPAYON",conn);
			
			System.out.println("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"NOTICPAYON\",conn) ===============>"+plad);
			log.write("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"NOTICPAYON\",conn) ===============>"+plad);

			if(plad.trim().equals("NULLFOUND") || plad == null || plad.trim().length() == 0)
			{
				plad = "";
				plad = getEnv("999999","PL_ENCON",conn);

				System.out.println("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"PL_ENCON\",conn) ===============>"+plad);
				log.write("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"PL_ENCON\",conn) ===============>"+plad);
				
				if(plad.trim().equals("NULLFOUND"))
				{
					errorCode = "VSENVAR1:ERROR";
					System.out.println("errString: "+errorCode);
					log.write("errString: "+errorCode);
					return errorCode;
				}
			}
			/*
			sqlStr = "SELECT CODE FROM PERIOD WHERE '"+relieveDate+"' >= FR_DATE AND '"+relieveDate+"' <= TO_DATE ";
			System.out.println("sqlStr2 : " + sqlStr);
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sqlStr);
			if(rs.next())
			{
				prdCode = rs.getString("CODE");
			}
			rs.close();
			stmt.close();
			stmt = null;
			*/
			sqlStr = "SELECT CODE FROM PERIOD WHERE ? >= FR_DATE AND ? <= TO_DATE ";
			
			System.out.println("sqlStr2 : " + sqlStr);
			log.write("sqlStr2 : " + sqlStr);

			pstmt = conn.prepareStatement( sqlStr );
			pstmt.setTimestamp( 1, java.sql.Timestamp.valueOf(relieveDate.toString()));
			pstmt.setTimestamp( 2, java.sql.Timestamp.valueOf(relieveDate.toString()));
			rs = pstmt.executeQuery();
			if( rs.next() )
			{
				prdCode = rs.getString("CODE");
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;
			
			System.out.println("prdCode : " + prdCode);
			log.write("prdCode : " + prdCode);

			noticeAd = getEnv("999999","NOTICE_RCP",conn);
			
			System.out.println("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"NOTICE_RCP\",conn) ===============>"+noticeAd);
			log.write("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"NOTICE_RCP\",conn) ===============>"+noticeAd);

			if(noticeAd.trim().equals("NULLFOUND"))
			{
				errorCode = "VSENVAR1:ERROR";
				System.out.println("errString: "+errorCode);
				log.write("errString: "+errorCode);
				return errorCode;
			}

			sqlStr = "SELECT FIN_ENTITY FROM SITE WHERE SITE_CODE = '"+paySite+"'";
			System.out.println("sqlStr3 : " + sqlStr);
			log.write("sqlStr3 : " + sqlStr);
			stmt = conn.prepareStatement( sqlStr );
			rs = stmt.executeQuery( );

			//rs = stmt.executeQuery(sqlStr);
			if ( rs.next() )				
			{
				finEntity = rs.getString( "FIN_ENTITY" );
			}
			rs.close();
			rs = null;
			stmt.close();
			stmt = null;
			sqlStr = " SELECT CURR_CODE FROM FINENT WHERE FIN_ENTITY = '" + finEntity + "'";
			System.out.println("sqlStr4 : " + sqlStr);
			log.write("sqlStr4 : " + sqlStr);

			stmt = conn.prepareStatement( sqlStr );
			rs = stmt.executeQuery( );

			//rs = stmt.executeQuery(sqlStr);
			if (rs.next())
			{
				currCodeTo = rs.getString( "CURR_CODE" );
			}

			rs.close();
			rs = null;
			stmt.close();
			stmt = null;

			dailyExchrate = itmDBAccessEJB.getDailyExchRateSellBuy( currCode, currCodeTo, paySite, tranDate, 'B', conn );
			days1 = daysAfter(resignDt,relvDate);
			noticeDays = days1;

			System.out.println("[FullFinalActEJB] wf_calc_np() :noticeDays ===============>"+noticeDays);
			log.write("[FullFinalActEJB] wf_calc_np() :noticeDays ===============>"+noticeDays);
			
			//Calendar calendar1 = Calendar.getInstance();
			java.util.Date todayDate = new java.util.Date();
			//leaveDays = getSiteEnv("99999","ADM","X","ZZZZZ","LEAVE_DAYS",todayDate,conn);
			leaveDays = getEnvAdm( paySite, cadreCode, gradeCode, "LEAVE_DAYS", todayDate, conn );

			System.out.println("[FullFinalActEJB] wf_calc_np() :leaveDays ===============>"+leaveDays);
			log.write("[FullFinalActEJB] wf_calc_np() :leaveDays ===============>"+leaveDays);

			if(leaveDays.trim().equals("NULLFOUND"))
			{
				leaveDays = "N";
			}
			//absentDays = getSiteEnv("99999","ADM","X","ZZZZZ","ABSENT_DAYS",todayDate,conn);
			absentDays = getEnvAdm(paySite,cadreCode,gradeCode,"ABSENT_DAYS",todayDate,conn);
			System.out.println("[FullFinalActEJB] wf_calc_np() :absentDays ===============>"+absentDays);
			log.write("[FullFinalActEJB] wf_calc_np() :absentDays ===============>"+absentDays);

			if(absentDays.trim().equals("NULLFOUND"))
			{
				leaveDays = "N";
			}
			if( leaveDays.equals("Y") && absentDays.equals("Y") )
			{
				sqlStr = "SELECT SUM(LEAVE_DAYS) FROM ATTD_REG " +
						" WHERE EMP_CODE = '"+empCode+"' AND" +
						" LEAVE_DAYS <= 1 AND " +
						//" AND   ATTD_DATE >= '"+resignDate+"'" +
						//" AND   ATTD_DATE <= '"+relieveDateDb+"'";
						" ATTD_DATE >= ? AND" +
						" ATTD_DATE <= ? ";

				System.out.println("sqlStr5 : " + sqlStr);
				log.write("sqlStr5 : " + sqlStr);

				stmt = conn.prepareStatement( sqlStr );
				stmt.setTimestamp( 1, resignDateT);//updated by nisar original:( 1, java.sql.Timestamp.valueOf( resignDate.toString() ) );
				stmt.setTimestamp( 2, relieveDateDbT);//updated by nisar on 27/11/07  original:( 2, java.sql.Timestamp.valueOf( relieveDateDb.toString() ) );
				rs = stmt.executeQuery( );

				//rs = stmt.executeQuery(sqlStr);
				if (rs.next())
				{
					sumOfLeaveDays = rs.getInt(1);
				}			 
				rs.close();
				rs = null;
				stmt.close();
				stmt = null;
				System.out.println("[FullFinalActEJB] wf_calc_np() :sumOfLeaveDays ===============>"+sumOfLeaveDays);
				log.write("[FullFinalActEJB] wf_calc_np() :sumOfLeaveDays ===============>"+sumOfLeaveDays);

				sqlStr = "SELECT SUM(CASE WHEN PAID_DAYS = 0 THEN 1 ELSE PAID_DAYS END) FROM ATTD_REG " +
						" WHERE EMP_CODE = '"+empCode+"' AND" +
						" PAID_DAYS < 1 AND " +
						//" AND ATTD_DATE >= '"+resignDate+"'" +
						//" AND ATTD_DATE <= '"+relieveDateDb+"'";
						"  ATTD_DATE >= ? " +
						" AND ATTD_DATE <= ? ";

				System.out.println("sqlStr6 : " + sqlStr);
				log.write("sqlStr6 : " + sqlStr);

				stmt = conn.prepareStatement( sqlStr );
				stmt.setTimestamp( 1, resignDateT);	//updated by nisar on 27/11/07 
				stmt.setTimestamp( 2, relieveDateDbT); //updated by nisar on 27/11/07 
				rs = stmt.executeQuery( );
				if( rs.next() )
				{
					sumOfPaidDays = rs.getInt(1);
				}  
				rs.close();
				rs = null;
				stmt.close();
				stmt = null;
								
				noOfDays = sumOfLeaveDays + sumOfPaidDays;

				System.out.println("[FullFinalActEJB] wf_calc_np() :sumOfPaidDays ===============>"+sumOfPaidDays);	  
				System.out.println("[FullFinalActEJB] wf_calc_np() :noOfDays ===============>"+noOfDays);
				log.write("[FullFinalActEJB] wf_calc_np() :sumOfPaidDays ===============>"+sumOfPaidDays);	  
				log.write("[FullFinalActEJB] wf_calc_np() :noOfDays ===============>"+noOfDays);

			}
			else if(absentDays.equals("Y"))
			{
				sqlStr = "SELECT SUM(CASE WHEN PAID_DAYS = 0 THEN 1 ELSE PAID_DAYS END) FROM ATTD_REG " +
						" WHERE EMP_CODE = '" + empCode + "' AND" +
						" PAID_DAYS < 1 AND " +
						//" AND ATTD_DATE >= '" + resignDate + "'" +
						//" AND ATTD_DATE <= '" + relieveDateDb + "'";
						"  ATTD_DATE >= ? " +
						" AND ATTD_DATE <= ? ";

				System.out.println("sqlStr5 : " + sqlStr);
				log.write("sqlStr5 : " + sqlStr);

				stmt = conn.prepareStatement( sqlStr );
				stmt.setTimestamp( 1, resignDateT);//updated by nisar on 27/11/07 
				stmt.setTimestamp( 2, relieveDateDbT);//updated by nisar on 27/11/07 
				rs = stmt.executeQuery( );

				//rs = stmt.executeQuery(sqlStr);
				if (rs.next())
				{
					sumOfPaidDays = rs.getInt(1);
				}
				rs.close();
				rs = null;
				stmt.close();
				stmt = null;
				
				noOfDays = sumOfPaidDays;
				System.out.println("[FullFinalActEJB] wf_calc_np() :sumOfPaidDays ===============>"+sumOfPaidDays);
				System.out.println("[FullFinalActEJB] wf_calc_np() :noOfDays ===============>"+noOfDays);
				log.write("[FullFinalActEJB] wf_calc_np() :sumOfPaidDays ===============>"+sumOfPaidDays);
				log.write("[FullFinalActEJB] wf_calc_np() :noOfDays ===============>"+noOfDays);
			}
			else if(leaveDays.equals("Y"))
			{
				sqlStr = "SELECT SUM( LEAVE_DAYS ) FROM ATTD_REG " +
						" WHERE EMP_CODE = '" + empCode + "' AND" +
						" LEAVE_DAYS <= 1 AND " +
						//" AND ATTD_DATE >= '" + resignDate + "'" +
						//" AND ATTD_DATE <= '" + relieveDateDb + "'";
						" ATTD_DATE >=  ? " +
						" AND ATTD_DATE <=  ? ";

				System.out.println( "sqlStr5 : " + sqlStr );
				log.write( "sqlStr5 : " + sqlStr );

				stmt = conn.prepareStatement( sqlStr );
				stmt.setTimestamp( 1, resignDateT);//updated by nisar on 27/11/07 
				stmt.setTimestamp( 2, relieveDateDbT);//updated by nisar on 27/11/07 
				rs = stmt.executeQuery( );

				//rs = stmt.executeQuery(sqlStr);
				if( rs.next() )
				{
					sumOfLeaveDays = rs.getInt(1);
				}

				rs.close();
				rs = null;
				stmt.close();
				stmt = null;

				noOfDays = sumOfLeaveDays;
				System.out.println("[FullFinalActEJB] wf_calc_np() :sumOfLeaveDays ===============>"+sumOfLeaveDays);
				System.out.println("[FullFinalActEJB] wf_calc_np() :noOfDays ===============>"+noOfDays);
				log.write("[FullFinalActEJB] wf_calc_np() :sumOfLeaveDays ===============>"+sumOfLeaveDays);
				log.write("[FullFinalActEJB] wf_calc_np() :noOfDays ===============>"+noOfDays);
			}
			if (noticePrd > 0)
			{
				noticePrd = noticePrd * 30;
			}
			System.out.println("[FullFinalActEJB] wf_calc_np() :noticePrd ===============>"+noticePrd);
			log.write("[FullFinalActEJB] wf_calc_np() :noticePrd ===============>"+noticePrd);

			if (noOfDays > 0 && (noticePrd == days1))
			{
				days1		= days1 - noOfDays;
				diffDays	= noticePrd - days1;
			}
			else if (noOfDays >= 0 && noticePrd > days1)
			{
				days1	 = noOfDays +(noticePrd - days1);
				diffDays = days1;
			}
			System.out.println("[FullFinalActEJB] wf_calc_np() :days1 ===============>"+days1);
			System.out.println("[FullFinalActEJB] wf_calc_np() :noOfDays ===============>"+noOfDays);
			System.out.println("[FullFinalActEJB] wf_calc_np() :diffDays ===============>"+diffDays);
			log.write("[FullFinalActEJB] wf_calc_np() :days1 ===============>"+days1);
			log.write("[FullFinalActEJB] wf_calc_np() :noOfDays ===============>"+noOfDays);
			log.write("[FullFinalActEJB] wf_calc_np() :diffDays ===============>"+diffDays);

			plprop = getEnv("999999","NOTICEPAYPROP",conn);

			System.out.println("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"NOTICEPAYPROP\",conn) ===============>"+plprop);
			log.write("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"NOTICEPAYPROP\",conn) ===============>"+plprop);
						
			if(plprop.trim().equals("NULLFOUND") || plprop == null || plprop.trim().length() == 0)
			{
				plprop = getEnv("999999","PL_PROP",conn);

				System.out.println("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"PL_PROP\",conn) ===============>"+plprop);
				log.write("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"PL_PROP\",conn) ===============>"+plprop);

				if(plprop.trim().equals("NULLFOUND"))
				{
					errorCode = "VSENVAR1:ERROR";
					System.out.println("errString:"+errorCode);
					log.write("errString:"+errorCode);
					return errorCode;
				}
			}
			long plpropVar = Long.parseLong(plprop.trim());
			sqlStr = "SELECT AMOUNT FROM PAYROLL_PROJDET " +
					" WHERE PRD_CODE = '" + prdCode + "' AND EMP_CODE = '" + empCode + "' AND AD_CODE = '" + plad + "'";
			System.out.println("sqlStr7 : " + sqlStr);
			log.write("sqlStr7 : " + sqlStr);
			stmt = conn.prepareStatement( sqlStr );
			rs = stmt.executeQuery( );
			if( rs.next() )
			{
				amount = rs.getDouble("AMOUNT");
			}
			else
			{
				errorCode = "VTPPNOT:ERROR";
				System.out.println("errString:"+errorCode);
				log.write("errString:"+errorCode);
				return errorCode;
			}

			rs.close();
			rs = null;
			stmt.close();
			stmt = null;
			
			if (noOfDays > 0 && noticeDays > noticePrd)
			{
				totalDays = noticeDays - noticePrd;
				if (noOfDays <= totalDays)
				{
					diffDays = 0;
				}
				else if (noOfDays > totalDays)
				{
					noOfDays = noOfDays - totalDays;
					diffDays = noOfDays;
				}
			}
			amount1 = (amount/plpropVar) * diffDays;
			
			System.out.println("[FullFinalEJB] wf_calc_np() : noticeDays=====>"+noticeDays);
			System.out.println("[FullFinalEJB] wf_calc_np() : noticePrd=====>"+noticePrd);
			System.out.println("[FullFinalEJB] wf_calc_np() : totalDays=====>"+totalDays);
			System.out.println("[FullFinalEJB] wf_calc_np() : amount=====>"+amount);
			System.out.println("[FullFinalEJB] wf_calc_np() : plpropVar=====>"+plpropVar);
			System.out.println("[FullFinalEJB] wf_calc_np() : diffDays=====>"+diffDays);
			System.out.println("[FullFinalEJB] wf_calc_np() : amount1=====>"+amount1);
			
			log.write("[FullFinalEJB] wf_calc_np() : noticeDays=====>"+noticeDays);
			log.write("[FullFinalEJB] wf_calc_np() : noticePrd=====>"+noticePrd);
			log.write("[FullFinalEJB] wf_calc_np() : totalDays=====>"+totalDays);
			log.write("[FullFinalEJB] wf_calc_np() : amount=====>"+amount);
			log.write("[FullFinalEJB] wf_calc_np() : plpropVar=====>"+plpropVar);
			log.write("[FullFinalEJB] wf_calc_np() : diffDays=====>"+diffDays);
			log.write("[FullFinalEJB] wf_calc_np() : amount1=====>"+amount1);


			amount1 = amount1 *(-1);
			amount1 = getRequiredDecimal(amount1 ,3);

			sqlStr = "SELECT ACCT_CODE__SAL, CCTR_CODE__SAL, DESCR FROM ALLWDEDN WHERE AD_CODE = '" + noticeAd + "'";
			
			System.out.println("sqlStr8 : " + sqlStr);
			log.write("sqlStr8 : " + sqlStr);

			stmt = conn.prepareStatement( sqlStr );
			rs = stmt.executeQuery( );
			//rs = stmt.executeQuery(sqlStr);
			if( rs.next() )
			{
				acctCode = rs.getString("ACCT_CODE__SAL");
				cctrCode = rs.getString("CCTR_CODE__SAL");
				descr	 = rs.getString("DESCR");
			}

			rs.close();
			rs = null;
			stmt.close();
			stmt = null;
			System.out.println("[FullFinalActEJB] wf_calc_np() :acctCode ===============>"+acctCode);
			System.out.println("[FullFinalActEJB] wf_calc_np() :cctrCode ===============>"+cctrCode);
			log.write("[FullFinalActEJB] wf_calc_np() :acctCode ===============>"+acctCode);
			log.write("[FullFinalActEJB] wf_calc_np() :cctrCode ===============>"+cctrCode);
						
			if(cctrCodeSal != null)
			{
				cctrCode = cctrCodeSal;
			}
			remarks = "Towards Notice Pay Recovery of " +  diffDays + "days";
			detInsert = wf_det_insert(tranID,noticeAd,descr,amount1,nullDate,"","",acctCode,cctrCode,remarks,"","",currCode,1,amount1,1);
			noticeAd = "";
			noticeAd = getEnv("999999","NOTICE_PAY",conn);
			
			System.out.println("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"NOTICE_PAY\",conn) ===============>"+noticeAd);
			log.write("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"NOTICE_PAY\",conn) ===============>"+noticeAd);

			if(noticeAd.trim().equals("NULLFOUND"))
			{
				errorCode = "VSENVAR1:ERROR";
				System.out.println("errString:"+errorCode);
				log.write("errString:"+errorCode);
				return errorCode;
			}
			java.util.Date relieveDate2 = null, relieveDate3 = null;
			relieveDate2 = new SimpleDateFormat(genericUtility.getApplDateFormat()).parse(relvDate);

			relieveDate3 = new SimpleDateFormat(genericUtility.getApplDateFormat()).parse(relieveDt.toString());
			
			//java.sql.Timestamp relvDateTs = null;
			//relvDateTs =	java.sql.Timestamp.valueOf(relieveDate2 + " 00:00:00.0");
			//java.sql.Timestamp relieveDtTs = null;
			//relieveDtTs =	java.sql.Timestamp.valueOf(relieveDate3 + " 00:00:00.0");

			//long longDay = DaysAfter1(relieveDtTs,relvDateTs);
			//log.write("[FullFinalActEJB] wf_calc_np() :longDay rajendra ===============>"+longDay);
			//log.write("[FullFinalActEJB] wf_calc_np() :relvDateTs rajendra ===============>"+relvDateTs);
			//log.write("[FullFinalActEJB] wf_calc_np() :relieveDtTs rajendra ===============>"+relieveDtTs);
			log.write("[FullFinalActEJB] wf_calc_np() :relieveDate2 rajendra ===============>"+relieveDate2);
			log.write("[FullFinalActEJB] wf_calc_np() :relieveDate3 rajendra ===============>"+relieveDate3);
			//updated by nisar on 27/11/07  
			//original : relieveDate3 = new SimpleDateFormat(genericUtility.getApplDateFormat()).parse(relieveDate.toString());
			
			
			///if(relieveDate3.compareTo(relieveDate2) < -1)
			if(relieveDate3.before(relieveDate2)) 
			{
				System.out.println(" inside before date ===============");
				
				//daysAfter1 = daysAfter(relvDate,relieveDt) + 1;

				//daysAfter1 = daysAfter(relvDate,relieveDt) ;  //by rajendra change
				daysAfter1 = daysAfter(relieveDt,relvDate) + 1;
				
			}
			else
			{
				daysAfter1 = 0;
			}
				
			
			System.out.println("[FullFinalActEJB] wf_calc_np() :daysAfter1 rajendra ===============>"+daysAfter1);
			log.write("[FullFinalActEJB] wf_calc_np() :daysAfter1 rajendra ===============>"+daysAfter1);

			if(daysAfter1 > 0)
			{
				amount = 0d;
				//comment by rajendra on 2/25/2008
//				sqlStr = "SELECT AMOUNT FROM PAYROLL_PROJDET " +
//				" WHERE PRD_CODE = '" + prdCode + "' AND EMP_CODE = '" + empCode + "' AND AD_CODE = '" + plEncash + "'";

				//plad
				sqlStr = "SELECT AMOUNT FROM PAYROLL_PROJDET " +
				" WHERE PRD_CODE = '" + prdCode + "' AND EMP_CODE = '" + empCode + "' AND AD_CODE = '" + plad + "'";

				System.out.println("sqlStr9 : " + sqlStr);
				log.write("sqlStr9 : " + sqlStr);
				stmt = conn.prepareStatement( sqlStr );
				rs = stmt.executeQuery( );
				if( rs.next() )
				{
					amount = rs.getDouble( "AMOUNT" );
				}
				else
				{
					errorCode = "VTPPNOT:ERROR";
					System.out.println("errString:"+errorCode);
					log.write("errString:"+errorCode);
					return errorCode;
				}
				rs.close();
				rs = null;
				stmt.close();
				stmt = null;
				
				if(plpropVar!=0 && daysAfter1!=0)
				{//added by nisar on 27/11/07 
					//commented by rajendra on 2/25/2008
					//amount2 = amount/(plpropVar * daysAfter1);
					amount2 = (amount / plpropVar ) * daysAfter1 ;
					amount2 = getRequiredDecimal(amount2,3);
				}

				
				System.out.println("[FullFinalEJB] wf_calc_np() : amount=====>"+amount);
				System.out.println("[FullFinalEJB] wf_calc_np() : plpropVar=====>"+plpropVar);
				System.out.println("[FullFinalEJB] wf_calc_np() : daysAfter1=====>"+daysAfter1);
				System.out.println("[FullFinalEJB] wf_calc_np() : amount2=====>"+amount2);

				log.write("[FullFinalEJB] wf_calc_np() : amount=====>"+amount);
				log.write("[FullFinalEJB] wf_calc_np() : plpropVar=====>"+plpropVar);
				log.write("[FullFinalEJB] wf_calc_np() : daysAfter1=====>"+daysAfter1);
				log.write("[FullFinalEJB] wf_calc_np() : amount2=====>"+amount2);

				sqlStr = "";
				sqlStr = "SELECT CCTR_CODE__SAL FROM EMPLOYEE WHERE EMP_CODE = '" + empCode + "'";
				System.out.println( "sqlStr10 : " + sqlStr );
				log.write( "sqlStr10 : " + sqlStr );
		
				stmt = conn.prepareStatement( sqlStr );
				rs = stmt.executeQuery( );

				while(rs.next())
				{
					cctrCodeSal = rs.getString("CCTR_CODE__SAL");
				}
				rs.close();

				System.out.println("[FullFinalActEJB] wf_calc_np() :cctrCodeSal ===============>"+cctrCodeSal);
				log.write("[FullFinalActEJB] wf_calc_np() :cctrCodeSal ===============>"+cctrCodeSal);

				sqlStr = "SELECT ACCT_CODE__SAL, CCTR_CODE__SAL, DESCR FROM ALLWDEDN WHERE AD_CODE = '" + noticeAd + "'";
				System.out.println("sqlStr11 : " + sqlStr);
				log.write("sqlStr11 : " + sqlStr);
				stmt = conn.prepareStatement( sqlStr );
				rs = stmt.executeQuery( );
				if( rs.next() )
				{
					acctCode = rs.getString("ACCT_CODE__SAL");
					cctrCode = rs.getString("CCTR_CODE__SAL");
					adDescr	 = rs.getString("DESCR");
				}

				rs.close();
				rs = null;
				stmt.close();
				stmt = null;
				System.out.println("[FullFinalActEJB] wf_calc_np() :acctCode ===============>"+acctCode);
				System.out.println("[FullFinalActEJB] wf_calc_np() :cctrCode ===============>"+cctrCode);
				log.write("[FullFinalActEJB] wf_calc_np() :acctCode ===============>"+acctCode);
				log.write("[FullFinalActEJB] wf_calc_np() :cctrCode ===============>"+cctrCode);
				
				if(cctrCodeSal != null)
				{
					cctrCode = cctrCodeSal;
				}
				remarks = "Towards Notice Pay Payable of " +  daysAfter1 + "days";
				detInsert = detInsert + wf_det_insert(tranID,noticeAd,adDescr,amount2,nullDate,"","",acctCode,cctrCode,remarks,"","",currCode,1,amount2,1);
				//updated by nisar on 08/12/07 
			} //end of if(daysAfter1 > 0)
			amount1 = 0.0;
			sqlStr = "SELECT GRADE, CADRE, WORK_SITE FROM EMPLOYEE WHERE EMP_CODE = '"+empCode+"'";
			System.out.println("sqlStr12 : " + sqlStr);
			log.write("sqlStr12 : " + sqlStr);
			stmt = conn.prepareStatement( sqlStr );
			rs = stmt.executeQuery( );
			if( rs.next() )
			{
				gradeCode = rs.getString("GRADE");
				cadreCode = rs.getString("CADRE");
				workSite  = rs.getString("WORK_SITE");
			}
			else
			{
				return "";
			}
			rs.close();
			
			System.out.println("[FullFinalActEJB] wf_calc_np() :gradeCode ===============>"+gradeCode);
			System.out.println("[FullFinalActEJB] wf_calc_np() :cadreCode ===============>"+cadreCode);
			System.out.println("[FullFinalActEJB] wf_calc_np() :workSite ===============>"+workSite);
			log.write("[FullFinalActEJB] wf_calc_np() :gradeCode ===============>"+gradeCode);
			log.write("[FullFinalActEJB] wf_calc_np() :cadreCode ===============>"+cadreCode);
			log.write("[FullFinalActEJB] wf_calc_np() :workSite ===============>"+workSite);

			sqlStr = "SELECT LVE_TBLNO FROM GRADE_SITE_LVETBL WHERE SITE_CODE = '"+workSite+"' AND GRADE_CODE = '" + gradeCode + "'";
			System.out.println("sqlStr13 : " + sqlStr);
			log.write("sqlStr13 : " + sqlStr);
			stmt = conn.prepareStatement( sqlStr );
			rs = stmt.executeQuery( );
			if( rs.next() )
			{
				leaveTblNo = rs.getString("LVE_TBLNO");
			}
			rs.close();
			rs = null;
			stmt.close();
			stmt = null;

			System.out.println("[FullFinalActEJB] wf_calc_np() :leaveTblNo ===============>"+leaveTblNo);
			log.write("[FullFinalActEJB] wf_calc_np() :leaveTblNo ===============>"+leaveTblNo);
			
			if (leaveTblNo == null || leaveTblNo.trim().length() == 0)
			{
				sqlStr = "SELECT LVE_TBLNO FROM CADRE_SITE_LVETBL WHERE SITE_CODE = '"+workSite+"' AND CADRE_CODE = '"+cadreCode+"'";
				System.out.println("sqlStr13 : " + sqlStr);
				log.write("sqlStr13 : " + sqlStr);
				stmt = conn.prepareStatement( sqlStr );
				rs = stmt.executeQuery( );
				if( rs.next() )
				{
					leaveTblNo = rs.getString("LVE_TBLNO");
				}
				rs.close();
				rs = null;
				stmt.close();
				stmt = null;
			}
			System.out.println("[FullFinalActEJB] wf_calc_np() :leaveTblNo ===============>"+leaveTblNo);
			log.write("[FullFinalActEJB] wf_calc_np() :leaveTblNo ===============>"+leaveTblNo);

			sqlStr = "SELECT LVE_CODE FROM LVETABLE WHERE LVE_TBLNO = '" + leaveTblNo + "' AND ENC_FOR_FFS = 'Y'";
			System.out.println("sqlStr14 : " + sqlStr);
			log.write("sqlStr14 : " + sqlStr);
			stmt = conn.prepareStatement( sqlStr );
			rs = stmt.executeQuery( );
			double balanceDays1 = 0.0;
			while( rs.next() )
			{
				balanceDays1 = 0;
				leaveCode = rs.getString("LVE_CODE");
				
				System.out.println("[FullFinalActEJB] wf_calc_np() :leaveCode ===============>"+leaveCode);
				log.write("[FullFinalActEJB] wf_calc_np() :leaveCode ===============>"+leaveCode);

				sqlStr = "SELECT SUM(BAL_DAYS) FROM LEAVEBAL " +
						//" WHERE EMP_CODE = '"+empCode+"' AND LVE_CODE = '"+leaveCode+"' AND EXP_DATE > '"+relieveDate+"'";
						" WHERE EMP_CODE = '"+empCode+"' AND LVE_CODE = '" +leaveCode+"' AND EXP_DATE > ? ";
				System.out.println("sqlStr15 : " + sqlStr);
				log.write("sqlStr15 : " + sqlStr);
				stmt1 = conn.prepareStatement( sqlStr );
				stmt1.setTimestamp( 1, java.sql.Timestamp.valueOf( relieveDate.toString() ) );
				//rs = stmt1.executeQuery( );

				rs1 = stmt1.executeQuery();

				if( rs1.next() )
				{
					balanceDays = rs1.getDouble(1);
				}
				else
				{
					return "";
				}
				balanceDays1 = balanceDays1 + balanceDays;
				rs1.close();
				rs1 = null;
				stmt1.close();
				stmt1 = null;

				System.out.println("[FullFinalActEJB] wf_calc_np() :balanceDays1 ===============>"+balanceDays1);
				log.write("[FullFinalActEJB] wf_calc_np() :balanceDays1 ===============>"+balanceDays1);
				
				sqlStr = "SELECT AD_CODE__ENCH FROM LEAVES WHERE LVE_CODE = '" + leaveCode + "'";
				System.out.println( "sqlStr16 : " + sqlStr );
				log.write( "sqlStr16 : " + sqlStr );
				stmt1 = conn.prepareStatement( sqlStr );
				rs1 = stmt1.executeQuery( );
				
				//rs1 = stmt1.executeQuery( sqlStr );
				if( rs1.next() )
				{
					plEncash = rs1.getString("AD_CODE__ENCH");
				}

				rs1.close();
				rs1 = null;
				stmt1.close();
				stmt1 = null;

				System.out.println("[FullFinalActEJB] wf_calc_np() :plEncash ===============>"+plEncash);
				log.write("[FullFinalActEJB] wf_calc_np() :plEncash ===============>"+plEncash);
				
				if ( plEncash == null )
				{
					continue;
				}
				
				plEncon = getEnv("999999","PL_ENCON",conn);

				System.out.println("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"PL_ENCON\",conn) ===============>"+plEncash);
				log.write("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"PL_ENCON\",conn) ===============>"+plEncash);
				
				if(plEncon.trim().equals("NULLFOUND"))
				{
					errorCode = "VSENVAR1:ERROR";
					System.out.println("[FullFinalActEJB] wf_calc_np() :errorCode ===============>"+errorCode);
					log.write("[FullFinalActEJB] wf_calc_np() :errorCode ===============>"+errorCode);
					return errorCode;
				}
				
				plprop = getEnv("999999","PL_PROP",conn);
				System.out.println("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"PL_PROP\",conn) ===============>"+plprop);
				log.write("[FullFinalActEJB] wf_calc_np() :getEnv(\"999999\",\"PL_PROP\",conn) ===============>"+plprop);

				if(plprop.trim().equals("NULLFOUND"))
				{
					errorCode = "VSENVAR1:ERROR";
					System.out.println("[FullFinalActEJB] wf_calc_np() :errorCode ===============>"+errorCode);
					log.write("[FullFinalActEJB] wf_calc_np() :errorCode ===============>"+errorCode);
					return errorCode;
				}
				if(balanceDays1 != 0)
				{
					sqlStr = "SELECT AMOUNT FROM PAYROLL_PROJDET " +
							" WHERE PRD_CODE = '"+prdCode+"' AND EMP_CODE = '"+empCode+"' AND AD_CODE = '"+plEncon+"'";
					System.out.println( "sqlStr17 : " + sqlStr );
					log.write( "sqlStr17 : " + sqlStr );
					stmt1 = conn.prepareStatement( sqlStr );
					rs1 = stmt1.executeQuery( );

					//rs1 = stmt1.executeQuery(sqlStr);
					if( rs1.next() )
					{
						amount2 = rs1.getDouble("AMOUNT");
					}
					else
					{
						errorCode = "VTPPNOT:ERROR";
						System.out.println("[FullFinalActEJB] wf_calc_np() :errorCode ===============>"+errorCode);
						log.write("[FullFinalActEJB] wf_calc_np() :errorCode ===============>"+errorCode);

						rs1.close();
						rs1 = null;
						stmt1.close();
						stmt1 = null;
						
						return errorCode;
					}
					if( rs1 != null )
					{
						rs1.close();
						rs1 = null;
					}
					if( stmt1 != null )
					{
						stmt1.close();
						stmt1 = null;
					}
				}
				System.out.println("[FullFinalActEJB] wf_calc_np() :amount2 ===============>"+amount2);
				log.write("[FullFinalActEJB] wf_calc_np() :amount2 ===============>"+amount2);

				sqlStr = "SELECT CCTR_CODE__SAL FROM EMPLOYEE WHERE EMP_CODE = '"+empCode+"'";
				System.out.println("sqlStr18 : " + sqlStr);
				log.write("sqlStr18 : " + sqlStr);

				stmt1 = conn.prepareStatement( sqlStr );
				rs1 = stmt1.executeQuery( );
				
				//rs1 = stmt1.executeQuery(sqlStr);
				while(rs1.next())
				{
					cctrCodeSalEmp = rs1.getString("CCTR_CODE__SAL");
				}
				rs1.close();
				rs1 = null;
				stmt1.close();
				stmt1 = null;
				System.out.println("[FullFinalActEJB] wf_calc_np() :cctrCodeSalEmp ===============>"+cctrCodeSalEmp);
				log.write("[FullFinalActEJB] wf_calc_np() :cctrCodeSalEmp ===============>"+cctrCodeSalEmp);
				
				sqlStr = "SELECT ACCT_CODE__SAL, CCTR_CODE__SAL, DESCR FROM ALLWDEDN WHERE AD_CODE = '"+plEncash+"'";
				System.out.println("sqlStr18 : " + sqlStr);
				log.write("sqlStr18 : " + sqlStr);

				stmt1 = conn.prepareStatement( sqlStr );
				rs1 = stmt1.executeQuery( );

				if( rs1.next() )
				{
					acctCode	= rs1.getString("ACCT_CODE__SAL");
					cctrCode	= rs1.getString("CCTR_CODE__SAL");
					plDescr		= rs1.getString("DESCR");
				}
				rs1.close();
				rs1 = null;
				stmt1.close();
				stmt1 = null;

				System.out.println("[FullFinalActEJB] wf_calc_np() :acctCode ===============>"+acctCode);
				System.out.println("[FullFinalActEJB] wf_calc_np() :cctrCode ===============>"+cctrCode);
				log.write("[FullFinalActEJB] wf_calc_np() :acctCode ===============>"+acctCode);
				log.write("[FullFinalActEJB] wf_calc_np() :cctrCode ===============>"+cctrCode);
				
				if(cctrCodeSalEmp != null)
				{
					cctrCode = cctrCodeSalEmp;
				}
				if(plpropVar!=0 && balanceDays1!=0)
				{//added by nisar on 27/11/07 

				   //commented by rajendra on 2/25/2008
					//amount1 = amount/(plpropVar * balanceDays1);
					amount1 =( amount2 / plpropVar ) * balanceDays1  ;
					

				}

				System.out.println("[FullFinalEJB] wf_calc_np() : amount=====>"+amount);
				System.out.println("[FullFinalEJB] wf_calc_np() : plpropVar=====>"+plpropVar);
				System.out.println("[FullFinalEJB] wf_calc_np() : balanceDays1=====>"+balanceDays1);
				System.out.println("[FullFinalEJB] wf_calc_np() : amount1=====>"+amount1);

				log.write("[FullFinalEJB] wf_calc_np() : amount=====>"+amount);
				log.write("[FullFinalEJB] wf_calc_np() : plpropVar=====>"+plpropVar);
				log.write("[FullFinalEJB] wf_calc_np() : balanceDays1=====>"+balanceDays1);
				log.write("[FullFinalEJB] wf_calc_np() : amount1=====>"+amount1);

				remarks = "Towards Leave Encashment of " +  balanceDays1 + "days";
				detInsert = detInsert + wf_det_insert(tranID,plEncash,plDescr,amount1,nullDate,"","",acctCode,cctrCode,remarks,"","",currCode,1,amount1,1);

				
			}
			rs.close();
		}
		catch(SQLException se)
		{
			System.out.println("SQLException[] :[FullFinalActEJB : wf_calc_np()][Excuting Query Failed]" + sqlStr + se.getMessage());
			log.write("SQLException[] :[FullFinalActEJB : wf_calc_np()][Excuting Query Failed]" + sqlStr + se.getMessage());
			se.printStackTrace();
			retString = se.getMessage();
			return retString;
		}
		catch(Exception e)
		{
			System.out.println("Exception :FullFinalActEJB :wf_calc_np():" + e.getMessage() + ":");
			log.write("Exception :FullFinalActEJB :wf_calc_np():" + e.getMessage() + ":");
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				System.out.println("Closing Connection.....");
				log.write("Closing Connection.....");
				if(stmt != null)
				{
					stmt.close();
					stmt = null;
				}
				if(stmt1 != null)
				{
					stmt1.close();
					stmt1 = null;
				}
				if(conn != null)
				{
					conn.close();
					conn = null;
				}
			}catch(Exception e)
			{
				System.out.println("[FullFinalActEJB]	Exception : wf_calc_np(): Exception Occured =>>"+e.getMessage());
				log.write("[FullFinalActEJB]	Exception : wf_calc_np(): Exception Occured =>>"+e.getMessage());
				e.printStackTrace();
				throw new ITMException(e);
			}
		}
		return detInsert;
	}
	private String wf_calc_gratuity(Document dom1) throws RemoteException , ITMException
	{
		String empCode = "", tranID = "", relieveDt = "", currCode = "", detInsertString = "", remarks = "";
		String adCode = "", cctrCodeSal = "", paySite = "", cctrCode = "";
		String finEntity = "", currCodeTo = "", trDate = "", acctCode = "";
		String prdCode = "", errorCode = "";
		String gradeCode = "", cadreCode = "", workSite = "";
		String adDescr = "", propDays = "";
		String sqlStr = "", sqlStr1 = "", retString = "", errString = "";
		String gredAppl = "", minService = "", daysPa = "", baseAdCode = "";
		String joinDt = "";
		double mService = 0.0, daysPAnum = 0.0, totalDays = 0.0, properDays = 0.0;
		double diffExchrate = 0.0, amount = 0.0, totalAmt = 0.0, dailyExchrate = 0.0;
		int daysDiff = 0, totalYear = 0;
		//int noticePrd = 0, noOfDays = 0, sumOfDays = 0, noticeDays = 0, diff = 0, daysAfter1 = 0;
		java.sql.Date nullDate = null, frDate = null, toDate = null, relvDate = null, joinDate = null;
		java.util.Date maxDate = null;
		Connection conn = null;
		ResultSet rs = null, rs1 = null;
		Statement stmt = null;
		PreparedStatement pstmt = null;
		
		ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();

		System.out.println("[FullFinalActEJB] wf_calc_gratuity() : method called.....................");
		log.write("[FullFinalActEJB] wf_calc_gratuity() : method called.....................");
		
		try
		{
			ConnDriver connDriver = new ConnDriver();
			conn = connDriver.getConnectDB("DriverITM");
			stmt = conn.createStatement();
			
			GenericUtility genericUtility = GenericUtility.getInstance();
			
			empCode 	= genericUtility.getColumnValue( "emp_code", dom1,"1");//UPDATED BY NISAR ON 13/12/07 
			tranID  	= genericUtility.getColumnValue( "tran_id", dom1,"1");
			currCode  	= genericUtility.getColumnValue( "curr_code", dom1,"1");
			relieveDt  	= genericUtility.getColumnValue( "relieve_date", dom1,"1");
			trDate 		= genericUtility.getColumnValue( "tran_date", dom1,"1");
			java.util.Date tranDate = new java.util.Date();
			java.util.Date relieveDate = new java.util.Date();
			tranDate = new SimpleDateFormat( genericUtility.getApplDateFormat() ).parse( trDate );
			relieveDate = new SimpleDateFormat( genericUtility.getApplDateFormat() ).parse( relieveDt );
			
			sqlStr = "SELECT WORK_SITE, CADRE, GRADE ,RELIEVE_DATE, DATE_JOIN,PAY_SITE" +
					" FROM EMPLOYEE WHERE EMP_CODE = '" + empCode+ "'";
			
			log.write(" sqlStr=>"+sqlStr);

			rs = stmt.executeQuery( sqlStr );
			if ( rs.next() )
			{
				workSite  = rs.getString("WORK_SITE");
				cadreCode = rs.getString("CADRE");
				gradeCode = rs.getString("GRADE");
				relvDate = rs.getDate("RELIEVE_DATE");
				joinDate = rs.getDate("DATE_JOIN");
				paySite   = rs.getString("PAY_SITE");
			}
			rs.close();
			joinDt = joinDate.toString();
			
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : workSite============>"+workSite);
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : cadreCode============>"+cadreCode);
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : gradeCode============>"+gradeCode);
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : relvDate============>"+relvDate);
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : joinDate============>"+joinDate);
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : paySite============>"+paySite);

			log.write("[FullFinalActEJB] wf_calc_gratuity() : workSite============>"+workSite);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : cadreCode============>"+cadreCode);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : gradeCode============>"+gradeCode);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : relvDate============>"+relvDate);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : joinDate============>"+joinDate);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : paySite============>"+paySite);


			gredAppl = getEnvAdm(workSite,cadreCode,gradeCode,"GRATUITY_APPLICABLE",relieveDate,conn);

			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_APPLICABLE\",relieveDate,conn)============>"+gredAppl);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_APPLICABLE\",relieveDate,conn)============>"+gredAppl);

			if(gredAppl.trim().equals("NULLFOUND"))
			{
				gredAppl = getEnv("999999","GRATUITY_APPLICABLE",conn);

				System.out.println("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_APPLICABLE\",relieveDate,conn)============>"+gredAppl);
				log.write("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_APPLICABLE\",relieveDate,conn)============>"+gredAppl);
				
				if(gredAppl.trim().equals("NULLFOUND"))
				{
					errorCode = "VSENVAR1:ERROR";
					log.write("[FullFinalActEJB] wf_calc_gratuity() : errorCode==>"+errorCode);
					return errorCode;
				}
			}
			if(!gredAppl.equals("Y"))
			{
				System.out.println("GRATUITY_APPLICABLE is :"+gredAppl+ "It should be Y :");
				log.write("GRATUITY_APPLICABLE is :"+gredAppl+ "It should be Y :");
				return "";
			}
			minService = getEnvAdm(workSite,cadreCode,gradeCode,"GRATUITY_MINSERVICE",relieveDate,conn);
			
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_MINSERVICE\",relieveDate,conn)============>"+minService);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_MINSERVICE\",relieveDate,conn)============>"+minService);

			if(minService.trim().equals("NULLFOUND"))
			{
				minService = getEnv("999999","GRATUITY_MINSERVICE",conn);
				if( minService.trim().equals( "NULLFOUND" ) )
				{
					errorCode = "VSENVAR1:ERROR";
					log.write("[FullFinalActEJB] wf_calc_gratuity() : errorCode==>"+errorCode);
					return errorCode;
				}
			}
			mService = Double.parseDouble(minService);
			//Calculation Of Relative Date Pending
			int no  = -1;
			maxDate = calcOfRelativeDate(joinDt,no,minService);

			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : maxDate ===========>"+maxDate);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : maxDate ===========>"+maxDate);
			
			if(relieveDate.compareTo(maxDate) < 0)
			{
				return "";
			}
			
			SimpleDateFormat sdfDB = new SimpleDateFormat(genericUtility.getDBDateFormat());//added by nisar on 08/12/07 
			Object obj = sdfDB.parse(joinDt); //added by nisar on 08/12/07 
			joinDt = (new SimpleDateFormat(genericUtility.getApplDateFormat()).format(obj)).toString();	 //added by nisar on 08/12/07 

			daysDiff  = daysAfter(joinDt,relieveDt);  //daysAfter parameter date format- dd/mm/yy
			
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : daysDiff============>"+daysDiff);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : daysDiff============>"+daysDiff);

			//totalYear = (int)Math.floor((float)daysDiff/365 + 0.0f);//commented by nisar on 08/12/07 
			totalYear = (int)Math.round((float)daysDiff/365 + 0.0f);
					
			daysPa = getEnvAdm(workSite,cadreCode,gradeCode,"GRATUITY_DAY_PA",relieveDate,conn);

			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : daysPa============>"+daysPa);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : daysPa============>"+daysPa);

			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : totalYear============>"+totalYear);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : totalYear============>"+totalYear);
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_DAY_PA\",relieveDate,conn)============>"+daysPa);

			if(daysPa.trim().equals("NULLFOUND"))
			{
				daysPa = getEnv("999999","GRATUITY_DAY_PA",conn);
				
				System.out.println("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_DAY_PA\",relieveDate,conn)============>"+daysPa);
				log.write("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_DAY_PA\",relieveDate,conn)============>"+daysPa);
				
				if(daysPa.trim().equals("NULLFOUND"))
				{
					errorCode = "VSENVAR1:ERROR";
					return errorCode;
				}
			}
			daysPAnum = Double.parseDouble(daysPa);
			propDays  = getEnvAdm( workSite, cadreCode, gradeCode, "GRATUITY_PROPDAYS", relieveDate, conn );
			
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_PROPDAYS\",relieveDate,conn)============>"+propDays);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_PROPDAYS\",relieveDate,conn)============>"+propDays);
			
			if(propDays.trim().equals("NULLFOUND"))
			{
				propDays = getEnv("999999","GRATUITY_PROPDAYS",conn);
				
				System.out.println("[FullFinalActEJB] wf_calc_gratuity() : getEnv(\"999999\",\"GRATUITY_PROPDAYS\",conn)============>"+propDays);
				log.write("[FullFinalActEJB] wf_calc_gratuity() : getEnv(\"999999\",\"GRATUITY_PROPDAYS\",conn)============>"+propDays);
				
				if(propDays.trim().equals("NULLFOUND"))
				{
					errorCode = "VSENVAR1:ERROR";
					return errorCode;
				}
			}
			properDays = Double.parseDouble(propDays);
			
			baseAdCode = getEnvAdm(workSite,cadreCode,gradeCode,"GRATUITY_BASEADCODE",relieveDate,conn);

			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_BASEADCODE\",relieveDate,conn)============>"+baseAdCode);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_BASEADCODE\",relieveDate,conn)============>"+baseAdCode);

			if(baseAdCode.trim().equals("NULLFOUND"))
			{
				baseAdCode = getEnv("999999","GRATUITY_BASEADCODE",conn);
				
				System.out.println("[FullFinalActEJB] wf_calc_gratuity() : getEnv(\"999999\",\"GRATUITY_BASEADCODE\",conn)==>"+baseAdCode);
				log.write("[FullFinalActEJB] wf_calc_gratuity() : getEnv(\"999999\",\"GRATUITY_BASEADCODE\",conn)==>"+baseAdCode);

				if(baseAdCode.trim().equals("NULLFOUND"))
				{
					errorCode = "VSENVAR1:ERROR";
					return errorCode;
				}
			}
			//sqlStr = "SELECT CODE,FR_DATE, TO_DATE FROM PERIOD WHERE '"+relieveDate+"' BETWEEN FR_DATE AND TO_DATE";
			sqlStr = "SELECT CODE,FR_DATE, TO_DATE FROM PERIOD WHERE ? BETWEEN FR_DATE AND TO_DATE";

			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : sqlStr==>"+sqlStr);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : sqlStr==>"+sqlStr);

			
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : relieveDate==---------------->"+relieveDate);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : relieveDate==--------------->"+relieveDate);

			String relieveDateStr = (new SimpleDateFormat(genericUtility.getDBDateFormat()).format(relieveDate)).toString(); //added by nisar on 08/12/07 

			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : relieveDateStr==---------------->"+relieveDateStr);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : relieveDateStr==--------------->"+relieveDateStr);

			pstmt = conn.prepareStatement( sqlStr );
			pstmt.setTimestamp( 1, java.sql.Timestamp.valueOf( relieveDateStr+" 00:00:00.0"));

			//rs = stmt.executeQuery(sqlStr);
			rs = pstmt.executeQuery( );
			if(rs.next())
			{
				prdCode = rs.getString("CODE");
				frDate  = rs.getDate("FR_DATE");
				toDate  = rs.getDate("TO_DATE");
			}
			else
			{
				errorCode = "VTRELPRD:ERROR";
				System.out.println("[FullFinalActEJB] wf_calc_gratuity() : errorCode==>"+errorCode);
				log.write("[FullFinalActEJB] wf_calc_gratuity() : errorCode==>"+errorCode);
				return errorCode;
			}
			rs.close();

			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : prdCode==>"+prdCode);
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : frDate==>"+frDate);
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : toDate==>"+toDate);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : prdCode==>"+prdCode);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : frDate==>"+frDate);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : toDate==>"+toDate);

			sqlStr = "SELECT AMOUNT FROM PAYROLL_PROJDET WHERE PRD_CODE = '"+prdCode+"' AND EMP_CODE = '"+empCode+"' AND AD_CODE = '"+baseAdCode+"'";
			rs = stmt.executeQuery(sqlStr);
			if(rs.next())
			{
				amount = rs.getDouble("AMOUNT");
				System.out.println("[FullFinalActEJB] wf_calc_gratuity() : amount==>"+amount);
				log.write("[FullFinalActEJB] wf_calc_gratuity() : amount==>"+amount);
			}
			else
			{	
				errorCode = "VTBADPRJ:ERROR";
				System.out.println("[FullFinalActEJB] wf_calc_gratuity() : errorCode==>"+errorCode);
				log.write("[FullFinalActEJB] wf_calc_gratuity() : errorCode==>"+errorCode);
				return errorCode;
			}
			rs.close();
			adCode = getEnvAdm(workSite,cadreCode,gradeCode,"GRATUITY_ADCODE",relieveDate,conn);
			System.out.println("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_ADCODE\",relieveDate,conn)============>"+adCode);
			log.write("[FullFinalActEJB] wf_calc_gratuity() : getEnvAdm(workSite,cadreCode,gradeCode,\"GRATUITY_ADCODE\",relieveDate,conn)============>"+adCode);

			if(adCode.trim().equals("NULLFOUND"))
			{
				adCode = getEnv( "999999", "GRATUITY_ADCODE", conn);

				System.out.println("[FullFinalActEJB] wf_calc_gratuity() : GRATUITY_ADCODE============>"+adCode);
				log.write("[FullFinalActEJB] wf_calc_gratuity() : GRATUITY_ADCODE============>"+adCode);

				if(adCode.trim().equals("NULLFOUND"))
				{
					errorCode = "VSENVAR1:ERROR";
					System.out.println("[FullFinalActEJB] wf_calc_gratuity() : errorCode============>"+errorCode);
					log.write("[FullFinalActEJB] wf_calc_gratuity() : errorCode============>"+errorCode);
					return errorCode;
				}
			}
			totalDays = totalYear * daysPAnum;
			if(	properDays!=0)
			{//added by nisar on 27/11/07 
				totalAmt = (amount * totalDays)/properDays;
				totalAmt = getRequiredDecimal(totalAmt,0);
			}


			System.out.println("[FullFinalEJB] wf_calc_gratuity() : amount=====>"+amount);
			System.out.println("[FullFinalEJB] wf_calc_gratuity() : totalDays=====>"+totalDays);
			System.out.println("[FullFinalEJB] wf_calc_gratuity() : properDays=====>"+properDays);
			System.out.println("[FullFinalEJB] wf_calc_gratuity() : totalAmt=====>"+totalAmt);

			log.write("[FullFinalEJB] wf_calc_gratuity() : amount=====>"+amount);
			log.write("[FullFinalEJB] wf_calc_gratuity() : totalDays=====>"+totalDays);
			log.write("[FullFinalEJB] wf_calc_gratuity() : properDays=====>"+properDays);
			log.write("[FullFinalEJB] wf_calc_gratuity() : totalAmt=====>"+totalAmt);

			sqlStr = "SELECT FIN_ENTITY FROM SITE WHERE SITE_CODE = '"+paySite+"'";

			System.out.println("[FullFinalEJB] wf_calc_gratuity() : sqlStr=====>"+sqlStr);
			log.write("[FullFinalEJB] wf_calc_gratuity() : sqlStr=====>"+sqlStr);

			rs = stmt.executeQuery(sqlStr);
			if (rs.next())
			{
				finEntity = rs.getString("FIN_ENTITY");
			}
			rs.close();
			sqlStr = "SELECT CURR_CODE FROM FINENT WHERE FIN_ENTITY = '"+finEntity+"'";

			System.out.println("[FullFinalEJB] wf_calc_gratuity() : sqlStr=====>"+sqlStr);
			log.write("[FullFinalEJB] wf_calc_gratuity() : sqlStr=====>"+sqlStr);

			rs = stmt.executeQuery(sqlStr);
			if (rs.next())
			{
				currCodeTo = rs.getString("CURR_CODE");
			}
			rs.close();
			dailyExchrate = itmDBAccessEJB.getDailyExchRateSellBuy(currCode, currCodeTo, paySite, tranDate, 'B', conn);

			System.out.println("[FullFinalEJB] wf_calc_gratuity() : dailyExchrate=====>"+dailyExchrate);
			log.write("[FullFinalEJB] wf_calc_gratuity() : dailyExchrate=====>"+dailyExchrate);

			sqlStr = "SELECT CCTR_CODE__SAL FROM EMPLOYEE WHERE EMP_CODE = '"+empCode+"'";
			
			System.out.println("[FullFinalEJB] wf_calc_gratuity() : sqlStr=====>"+sqlStr);
			log.write("[FullFinalEJB] wf_calc_gratuity() : sqlStr=====>"+sqlStr);

			rs = stmt.executeQuery(sqlStr);
			if (rs.next())
			{
				cctrCodeSal = rs.getString("CCTR_CODE__SAL");
			}
			rs.close();

			System.out.println("[FullFinalEJB] wf_calc_gratuity() : cctrCodeSal=====>"+cctrCodeSal);
			log.write("[FullFinalEJB] wf_calc_gratuity() : cctrCodeSal=====>"+cctrCodeSal);
			
			sqlStr = "SELECT ACCT_CODE__SAL, CCTR_CODE__SAL, DESCR FROM ALLWDEDN WHERE AD_CODE = '"+adCode+"'";

			System.out.println("[FullFinalEJB] wf_calc_gratuity() : sqlStr=====>"+sqlStr);
			log.write("[FullFinalEJB] wf_calc_gratuity() : sqlStr=====>"+sqlStr);

			rs = stmt.executeQuery(sqlStr);
			if (rs.next())
			{
				acctCode = rs.getString("ACCT_CODE__SAL");
				cctrCode = rs.getString("CCTR_CODE__SAL");
				adDescr = rs.getString("DESCR");
			}
			else
			{
				errorCode = "VTIADC2:ERROR";
				System.out.println("[FullFinalEJB] wf_calc_gratuity() : errorCode=====>"+errorCode);
				log.write("[FullFinalEJB] wf_calc_gratuity() : errorCode=====>"+errorCode);
				return errorCode;
			}
			rs.close();
			if(cctrCodeSal != null)
			{
				cctrCode = cctrCodeSal;
			}
			remarks = "Towards Gratuity For " +  totalDays + "days";

			detInsertString = wf_det_insert(tranID,adCode,adDescr,totalAmt,nullDate,"","",acctCode,cctrCode,remarks,"","",currCode,1,totalAmt,1);
			
		}
		catch(SQLException se)
		{
			System.out.println("SQLException[] :[FullFinalActEJB : wf_calc_gratuity()][Excuting Query Failed]" + sqlStr + se.getMessage());
			log.write("SQLException[] :[FullFinalActEJB : wf_calc_gratuity()][Excuting Query Failed]" + sqlStr + se.getMessage());
			se.printStackTrace();
			retString = se.getMessage();
			return retString;
		}
		catch(Exception e)
		{
			System.out.println("Exception :FullFinalActEJB :wf_calc_gratuity():" + e.getMessage() + ":");
			log.write("Exception :FullFinalActEJB :wf_calc_gratuity():" + e.getMessage() + ":");
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				System.out.println("Closing Connection.....");
				log.write("Closing Connection.....");
				if(stmt != null)
				{
					stmt.close();
					stmt = null;
				}
				if(conn != null)
				{
					conn.close();
					conn = null;
				}
			}
			catch(Exception e)
			{
				System.out.println("[FullFinalActEJB]	Exception : wf_calc_gratuity(): Exception Occured =>>"+e.getMessage());
				log.write("[FullFinalActEJB]	Exception : wf_calc_gratuity(): Exception Occured =>>"+e.getMessage());
				e.printStackTrace();
				throw new ITMException(e);
			}
		}
		return detInsertString;
	}
	private String getEnv(String prdCode, String varName, Connection conn)throws RemoteException,ITMException
	{
		String varValue = "";
		String sql = "";
		Statement stmt = null;
		ResultSet rs = null;
		try
		{
			log.write("===================getEnv() method called=======================");
			sql = "SELECT VAR_VALUE FROM PAYRPARM WHERE PRD_CODE = '"+prdCode+"' AND VAR_NAME = '"+varName+"'";
			System.out.println("sql in [getEnv]..:: " + sql);
			log.write("sql in [getEnv]..:: " + sql);

			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			if(rs.next())
			{
				varValue = rs.getString("VAR_VALUE");
			}
			else 
			{
				varValue = "NULLFOUND";
			}
		}
		catch(Exception e)
		{
			System.out.println("Exception :FullFinalActEJB :getEnv:" + e.getMessage() + ":");
			log.write("Exception :FullFinalActEJB :getEnv:" + e.getMessage() + ":");
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				//System.out.println("Closing Connection.....");
				//commented by msalam on 26/11/07 as not needed
				/*
				if(conn != null)
				{
					conn.close();
					conn = null;
				}
				*/
				//commented by msalam on 26/11/07 as not needed
			}
			catch(Exception e)
			{
				System.out.println("[FullFinalActEJB]	Exception : getEnv(): Exception Occured =>>"+e.getMessage());
				log.write("[FullFinalActEJB]	Exception : getEnv(): Exception Occured =>>"+e.getMessage());
				e.printStackTrace();
				throw new ITMException(e);
			}
		}
		System.out.println("Returning Value From getEnv() :: "+varValue); 
		log.write("Returning Value From getEnv() :: "+varValue); 
		return varValue;
	}
	private String getSiteEnv(String siteCode, String modName, String levelType, String levelCode, String parName, java.util.Date adDate, Connection conn)throws RemoteException,ITMException
	{
		String varValue = "";
		String sql = "";
		Statement stmt = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null, rs1 = null;
		//boolean connectionState = false;
		try
		{
			log.write("===================getSiteEnv() method called=======================");
			GenericUtility genericUtility = GenericUtility.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
 			stmt = conn.createStatement();
 			
 			sql = "SELECT PAR_VALUE FROM SITE_ENV" +
				 " WHERE SITE_CODE = '"+siteCode+"' AND MODULE_CODE	= '"+modName+"' AND" + 
				 " LEVEL_TYPE = '"+levelType+"' AND LEVEL_CODE	= '"+levelCode+"' AND" +
				 " PAR_NAME = '"+parName+"' AND EFF_DATE <= ? AND UPTO_DATE	>= ? ";
			System.out.println("sql1 in [getSiteEnv]..:: " + sql);
			log.write("sql1 in [getSiteEnv]..:: " + sql);

			pstmt = conn.prepareStatement(sql);
			pstmt.setTimestamp( 1, java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(sdf.format(adDate),genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
			pstmt.setTimestamp( 2, java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(sdf.format(adDate),genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
 			rs = pstmt.executeQuery();
 			if(rs.next())
 			{
 				varValue = rs.getString("PAR_VALUE");
 			}
 			else 
 			{
				if(levelType.equals("X") && modName != "ADM")
 				{
 					sql = "";
 					siteCode = "99999";
 					sql = "SELECT PAR_VALUE FROM SITE_ENV" +
					 	 " WHERE SITE_CODE = '"+siteCode+"' AND MODULE_CODE	= '"+modName+"' AND" + 
						 " LEVEL_TYPE = '"+levelType+"' AND LEVEL_CODE	= '"+levelCode+"' AND" +
						 " PAR_NAME = '"+parName+"' AND EFF_DATE <= ? AND UPTO_DATE	>= ? ";
					
					System.out.println("sql2 in [getSiteEnv]..:: " + sql);
					log.write("sql2 in [getSiteEnv]..:: " + sql);

					pstmt = conn.prepareStatement(sql);
					pstmt.setTimestamp( 1, java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(sdf.format(adDate.toString()),genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
					pstmt.setTimestamp( 2, java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(sdf.format(adDate.toString()),genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
					rs1 = pstmt.executeQuery();
 					if(rs1.next())
 					{
 						varValue = rs1.getString("PAR_VALUE");
 					}
					else
					{
						varValue = "NULLFOUND";
					}
 				}
 				else
 				{
 					varValue = "NULLFOUND";
 				}
 			}
		}
 		catch (Exception e)
		{
			System.out.println("Exception :FullFinalActEJB :getSiteEnv:" + e.getMessage() + ":");
			log.write("Exception :FullFinalActEJB :getSiteEnv:" + e.getMessage() + ":");
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				System.out.println("Closing Connection.....");
				log.write("Closing Connection.....");
				if(rs != null)
				{
					rs.close();
					rs = null;
				}
				if(rs1 != null)
				{
					rs1.close();
					rs1 = null;
				}
				if(pstmt != null)
				{
					pstmt.close();
					pstmt = null;
				}
			}
			catch(Exception e)
			{
				System.out.println("[FullFinalActEJB]	Exception : getSiteEnv(): Exception Occured =>>"+e.getMessage());
				log.write("[FullFinalActEJB]	Exception : getSiteEnv(): Exception Occured =>>"+e.getMessage());
				e.printStackTrace();
				throw new ITMException(e);
			}
		}
		System.out.println("Returning Value From getSiteEnv() :: "+varValue);
		log.write("Returning Value From getSiteEnv() :: "+varValue);
		return varValue;
	}
	private String getEnvAdm(String siteCode, String cadreCode, String gradeCode, String envName, java.util.Date adDate, Connection conn)throws RemoteException,ITMException
	{
		String varValue = "";
		String sql = "";
 		//boolean connectionState = false;
 		
 		try	
		{
			log.write("===================getEnvAdm() method called=======================");
 			/*if(conn == null)
			{
				conn = getConnection();
				connectionState = true;
			}*/

 			varValue = getSiteEnv(siteCode,"ADM","G",gradeCode,envName,adDate,conn);
 			if(varValue.trim().equals("NULLFOUND"))
 			{
 				varValue = getSiteEnv(siteCode,"ADM","C",cadreCode,envName,adDate,conn);
 				if(varValue.trim().equals("NULLFOUND"))
 				{
 					varValue = getSiteEnv(siteCode,"ADM","X","ZZZZZ",envName,adDate,conn);
 					if(varValue.trim().equals("NULLFOUND"))
 					{
 						varValue = getSiteEnv("99999","ADM","G",gradeCode,envName,adDate,conn);
 						if(varValue.trim().equals("NULLFOUND"))
 						{
 							varValue = getSiteEnv("99999","ADM","C",cadreCode,envName,adDate,conn);
 							if(varValue.trim().equals("NULLFOUND"))
 	 						{
 	 							varValue = getSiteEnv("99999","ADM","X","ZZZZZ",envName,adDate,conn);
 	 						}
 						}
 					}
 				}
 			}
		}
 		catch (Exception e)
		{
			System.out.println("Exception :FullFinalActEJB :getEnvAdm:" + e.getMessage() + ":");
			log.write("Exception :FullFinalActEJB :getEnvAdm:" + e.getMessage() + ":");
			throw new ITMException(e);
		}
		System.out.println("Returning Value From getEnvAdm() :: "+varValue);  
		log.write("Returning Value From getEnvAdm() :: "+varValue);  
		return varValue;
	}
	private int daysAfter( String startDt, String endDt )throws RemoteException , ITMException
	{
		java.util.Date joinDate = new java.util.Date();
		java.util.Date relieveDate = new java.util.Date();
		long time1 = 0, time2 = 0;
		float hr1, hr2, totYr;
		int hour1 = 0, hour2 = 0, totalHr = 0, daysDiff = 0;
		try
		{
			System.out.println("[FullFinalActEJB] daysAfter() method called-----------------------");
			System.out.println("startDt in [daysAfter]..:: " + startDt);
			System.out.println("endDt in   [daysAfter]..:: " + endDt);

			log.write("[FullFinalActEJB] daysAfter() method called-----------------------");
			log.write("startDt in [daysAfter]..:: " + startDt);
			log.write("endDt in   [daysAfter]..:: " + endDt);

			GenericUtility genericUtility = GenericUtility.getInstance();

			joinDate = new SimpleDateFormat(genericUtility.getApplDateFormat()).parse(startDt); 
			
			relieveDate = new SimpleDateFormat(genericUtility.getApplDateFormat()).parse(endDt); 

			time1 = joinDate.getTime();
			time2 = relieveDate.getTime();
			hr1  = (float)((float)time1/(60.00f*1000.00f*60.00f));
			hour1 = (int)Math.floor(hr1 + 0.5f);
			hr2  = (float)((float)time2/(60.00f*1000.00f*60.00f));
			hour2 = (int)Math.floor(hr2 + 0.5f);
			totalHr = hour2 - hour1;
			daysDiff = totalHr/24;
			System.out.println("Total days : " +daysDiff);
			log.write("Total days : " +daysDiff);
		}
		catch(Exception e)
		{
			System.out.println("Exception :[FullFinalActEJB][function::daysAfter()] :==>\n"+e.getMessage());
			log.write("Exception :[FullFinalActEJB][function::daysAfter()] :==>\n"+e.getMessage());
			e.printStackTrace();
			throw new ITMException(e);
		}
		return daysDiff;
	}
	private java.util.Date calcOfRelativeDate(String joinDt, int no, String minService) throws RemoteException , ITMException
	{
		String relativeDate ="";
		int mService = 0;
		java.util.Date dateOfJoin = new java.util.Date();
		java.util.Date relativeDt = new java.util.Date();

		try
		{	
			System.out.println("[FullFinalActEJB] calcOfRelativeDate() method called-----------------------");
			log.write("[FullFinalActEJB] calcOfRelativeDate() method called-----------------------");

			mService = Integer.parseInt(minService);
			GenericUtility genericUtility = GenericUtility.getInstance();
			System.out.println("[FullFinalActEJB] calcOfRelativeDate() : joinDt(YYYY/MM/DD)================>"+joinDt);
			log.write("[FullFinalActEJB] calcOfRelativeDate() : joinDt(YYYY/MM/DD)================>"+joinDt);
			
			SimpleDateFormat sdfDB = new SimpleDateFormat(genericUtility.getDBDateFormat());//added by nisar on 27/11/07 
			Object obj = sdfDB.parse(joinDt);
			joinDt = (new SimpleDateFormat(genericUtility.getApplDateFormat()).format(obj)).toString();
			
			System.out.println("[FullFinalActEJB] calcOfRelativeDate() : joinDt(MM/DD/YYYY)================>"+joinDt);
			log.write("[FullFinalActEJB] calcOfRelativeDate() : joinDt(MM/DD/YYYY)================>"+joinDt);

			SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
			dateOfJoin = sdf.parse(joinDt);
			Calendar calendar1 = Calendar.getInstance();
			calendar1.setTime(dateOfJoin);
			calendar1.add(calendar1.DATE,no);
			calendar1.add(calendar1.YEAR,mService);
			dateOfJoin = calendar1.getTime();
			System.out.println(" time : " + dateOfJoin.toString());
			log.write(" time : " + dateOfJoin.toString());
			relativeDate = new SimpleDateFormat().format(dateOfJoin);
			System.out.println(" relativeDate : " +relativeDate);
			log.write(" relativeDate : " +relativeDate);
			relativeDt = sdf.parse(relativeDate);
		}
		catch(Exception e)
		{
			System.out.println("Exception :[FullFinalActEJB][function::calcOfRelativeDate()] :==>\n"+e.getMessage());
			log.write("Exception :[FullFinalActEJB][function::calcOfRelativeDate()] :==>\n"+e.getMessage());
			e.printStackTrace();
			throw new ITMException(e);
		}

		return relativeDt;
	}
	private String wf_det_insert(String tranID, String adCodeInt, String descr, double intAmt, java.util.Date startDate, String refType, String refNo, String acctCodeSale, String cctrCode, String remarks, String refSer, String refNo1, String currCode, double exchRate, double netAmt, double dailyExchrate)throws RemoteException , ITMException
	{
		StringBuffer valueXmlString = new StringBuffer("<Detail>\r\n");
		String sqlStr = "", acctDescr = "",startDateStr = "";
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try
		{
			System.out.println("[FullFinalActEJB] wf_det_insert() method called-----------------------");
			log.write("[FullFinalActEJB] wf_det_insert() method called-----------------------");

			if(startDate!=null)
			{ //added by nisar on 27/11/07 
				GenericUtility genericUtility = GenericUtility.getInstance();
				Object obj = new SimpleDateFormat(genericUtility.getDBDateFormat()).parse(startDate.toString()); //added by nisar on 27/11/07 
				startDateStr = (new SimpleDateFormat(genericUtility.getApplDateFormat()).format(obj)).toString();//added by nisar on 27/11/07 
			}	
			System.out.println("[FullFinalActEJB] wf_det_insert() : intAmt++++++++++++++++=======>"+intAmt);
			log.write("[FullFinalActEJB] wf_det_insert() : intAmt++++++++++++++++=======>"+intAmt);

			ConnDriver connDriver = new ConnDriver();
			conn = connDriver.getConnectDB("DriverITM");
			stmt = conn.createStatement();
			sqlStr = "SELECT DESCR FROM ACCOUNTS WHERE ACCT_CODE = '"+acctCodeSale+"'";
			rs = stmt.executeQuery(sqlStr);
			while(rs.next())
			{
				acctDescr = rs.getString("DESCR");
			}
			
			valueXmlString.append("<tran_id>").append(tranID==null?"":tranID).append("</tran_id>");
			valueXmlString.append("<ad_code>").append(adCodeInt==null?"":adCodeInt.trim()).append("</ad_code>");
			valueXmlString.append("<descr><![CDATA[").append(descr==null?"":descr).append("]]></descr>");
			valueXmlString.append("<amount>").append(log.getFormatedValue(intAmt,3)).append("</amount>");
			valueXmlString.append("<payroll_voucher>").append("V").append("</payroll_voucher>");
			valueXmlString.append("<start_date>").append((startDateStr==null?"":startDateStr)).append("</start_date>");
			valueXmlString.append("<acct_code>").append(acctCodeSale==null?"":acctCodeSale).append("</acct_code>");
			valueXmlString.append("<cctr_code>").append(cctrCode==null?"":cctrCode).append("</cctr_code>");
			valueXmlString.append("<ref_ser>").append(refSer==null?"":refSer).append("</ref_ser>");
			valueXmlString.append("<ref_no>").append(refNo1==null?"":refNo1).append("</ref_no>");
			valueXmlString.append("<remarks><![CDATA[").append(remarks==null?"":remarks).append("]]></remarks>");
			valueXmlString.append("<accounts_descr><![CDATA[").append(acctDescr==null?"":acctDescr).append("]]></accounts_descr>");
			valueXmlString.append("<curr_code>").append(currCode==null?"":currCode).append("</curr_code>");
			valueXmlString.append("<exch_rate>").append(exchRate).append("</exch_rate>");
			valueXmlString.append("<daily_exchrate>").append(dailyExchrate).append("</daily_exchrate>");
			valueXmlString.append("<net_amt>").append(log.getFormatedValue(netAmt,3)).append("</net_amt>");
			if(refType.equalsIgnoreCase("L"))
			{
				valueXmlString.append("<loan_no>").append(refNo.trim()).append("</loan_no>");
			}
			valueXmlString.append("</Detail>\r\n");
		}
		catch(SQLException se)
		{
			System.out.println("SQLException ::"+se.getMessage());
			log.write("SQLException ::"+se.getMessage());
			se.printStackTrace();
			throw new ITMException(se);
		}
		catch(Exception e)
		{
			System.out.println("Exception :[FullFinalActEJB][function::wf_det_insert()] :==>\n"+e.getMessage());
			log.write("Exception :[FullFinalActEJB][function::wf_det_insert()] :==>\n"+e.getMessage());
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				System.out.println("Closing Connection.....");
				log.write("Closing Connection.....");
				if(rs != null)
				{
					rs.close();
					rs = null;
				}
				if(stmt != null)
				{
					stmt.close();
					stmt = null;
				}
				if(conn != null)
				{
					conn.close();
					conn = null;
				}
			}
			catch(Exception e)
			{
				System.out.println("[FullFinalActEJB]	Exception : wf_det_insert(): Exception Occured =>>"+e.getMessage());
				log.write("[FullFinalActEJB]	Exception : wf_det_insert(): Exception Occured =>>"+e.getMessage());
				e.printStackTrace();
				throw new ITMException(e);
			}
		}
		log.write("[FullFinalActEJB]  wf_det_insert () : xmlData===================>"+valueXmlString.toString());
		return valueXmlString.toString();
	}
	public double getRequiredDecimal(double actVal, int prec)
    {
        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;
    }

	
}