 /* w_fullfinal voucher button   nvo_business_object_adm_ffs (gbf_post_logic)*/


package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import ibase.utility.CommonConstants;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import java.util.*;
import java.sql.*;
import java.io.*;
import org.w3c.dom.*; 
import javax.ejb.*;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.*;
import ibase.system.config.*;
import java.util.*;
import ibase.webitm.ejb.dis.DistCommon;
import javax.ejb.Stateless; // added for ejb3

@Stateless // added for ejb3
public class FullFinalPrc extends ProcessEJB implements FullFinalPrcLocal,FullFinalPrcRemote //SessionBean
{
	GenericUtility genericUtility = GenericUtility.getInstance();

	Connection conn = null;
	String processErrString = null;
	String messagePrStr = null;
	//Globle variable Declaration
	//process
	ArrayList contList = null;
	Vector tranIdVector = null;
	Vector empCodeVector = null;
	Vector tranIdVec = new Vector();//tranIdVec;
	//view Data
	String chgUser = null;  
	String chgTerm  = null; 
	String loginSite = null;
	String userId = null;
	String errString =  null;
	String loginEmpCode = null;
	String runMode = null;

	/*public void ejbCreate() throws RemoteException, CreateException	{}
	public void ejbRemove(){}
	public void ejbActivate(){}
	public void ejbPassivate(){}*/
	public String process() throws RemoteException,ITMException
	{return "";}

	public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
	{
		Document detailDom = null;
		Document headerDom = null;
		String retStr = "";
		try
		{	
			System.out.println("xmlString[process]::::::::::;;;"+xmlString);
			System.out.println("xmlString2[process]::::::::::;;;"+xmlString2);
			System.out.println("windowName[process]::::::::::;;;"+windowName);
			System.out.println("xtraParams[process]:::::::::;;;"+xtraParams);
			if(xmlString != null && xmlString.trim().length()!=0)
			{
				headerDom = genericUtility.parseString(xmlString); 
				System.out.println("headerDom" + headerDom);
			}
			if(xmlString2 != null && xmlString2.trim().length()!=0)
			{
				detailDom = genericUtility.parseString(xmlString2); 
				System.out.println("detailDom" + detailDom);
			}
		    retStr = process(headerDom, detailDom, windowName, xtraParams);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return retStr;
}//END OF PROCESS (1)
	
	public String process(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
	{
		Vector tranIdVec = null;
		tranIdVec = new Vector();
		ArrayList contList = null;
		contList = new ArrayList();
		messagePrStr = null;
		processErrString = null;
	
		NodeList parentNodeList = null;
		NodeList childNodeList = null;
		Node parentNode = null;
		Node childNode = null; 
		
		int parentNodeListLength = 0;
		int childNodeListLength = 0;
		String childNodeName =  null;
		String contCode=null;
		String tranId=null;
		String empCode = null;
		//filter field
		//brow field
	
		try 
		{
			if(conn==null)
			{
				ConnDriver connDriver = new ConnDriver();
				conn = connDriver.getConnectDB("DriverITM");
				conn.setAutoCommit(false);
				DatabaseMetaData dbmd = conn.getMetaData();
				System.out.println("DriverName["+dbmd.getDriverName()+"]");
				System.out.println("DriverURI["+dbmd.getURL()+"]"  );
				System.out.println("DriverUSER["+dbmd.getUserName()+"]" );
				System.out.println("ApplDateFormat["+genericUtility.getApplDateFormat()+"]");
				System.out.println("DBDateFormat["+genericUtility.getDBDateFormat()+"]");
				connDriver = null;
				dbmd = null;
			}
			//Fetching the chgUser,chgDate,chgTerm
			loginSite = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode");
			loginEmpCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginEmpCode");
			userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"userId");
			chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");  
			chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId");
			
			runMode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "runMode");
			parentNodeList = detailDom.getElementsByTagName("Detail1");
			parentNodeListLength = parentNodeList.getLength(); 
			System.out.println("parentNodeListLength:::::::::"+parentNodeListLength);
			for (int selectedRow = 0; selectedRow < parentNodeListLength; selectedRow++)
			{
				contCode = null;
				parentNode = parentNodeList.item(selectedRow);
				childNodeList = parentNode.getChildNodes();
				childNodeListLength = childNodeList.getLength();
				System.out.println("childNodeListLength::: "+ childNodeListLength+"\n");
				for (int childRow = 0; childRow < childNodeListLength; childRow++)
				{
					childNode = childNodeList.item(childRow);
					childNodeName = childNode.getNodeName();
					if (childNodeName.equalsIgnoreCase("supp_code__con"))
					{
						if(childNode.getFirstChild()!=null)
						{
							contCode = childNode.getFirstChild().getNodeValue();
						}
					}
					if (childNodeName.equalsIgnoreCase("emp_code"))
					{
						if(childNode.getFirstChild()!=null)
						{
							empCode = childNode.getFirstChild().getNodeValue();
						}
					}
									
				}//inner loop
				//********************
				if(contCode!=null)
				{
				 	messagePrStr = PopulateCustomer(contList,contCode,empCode,conn);
				}
				//**********************
			}// OUT FOR LOOP 
			//VOUCHER CREATION LOGIC CALL
			//********************
			if(processErrString == null && messagePrStr == null)
			{
				messagePrStr = createVoucher(contList);
			}
			//********************
			if(processErrString == null && messagePrStr == null)
			{
				try{conn.commit();}catch(Exception d){}
				System.out.println("Transaction commit for contract Code["+contCode+"]");
			}
			else
			{
				try{conn.rollback();}catch(Exception d){}
					
				if(messagePrStr!=null)
				{
					ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
					String errString1 = itmDBAccessEJB.getErrorString("","VTMRPPARM","","",conn);
					String begPart = errString1.substring(0,errString1.indexOf("<trace>")+7);
					String endPart = errString1.substring(errString1.indexOf("</trace>"));
					System.out.println("begPart:::"+begPart);
					System.out.println("endPart:::"+endPart);
					String mainStr = begPart+messagePrStr+endPart;
					errString1 = mainStr;
					System.out.println("errString1="+errString1);
					processErrString  = errString1;
					itmDBAccessEJB = null;
				}
				System.out.println("Transaction RollBack for contract Code["+contCode+"]");
			}
		
		}//try end	
		catch(Exception e)
		{
			processErrString = "Exception";
			e.printStackTrace();
		}
		finally
		{
			System.out.println("Closing Connection....");
			try
			{ genericUtility =null;
			contList = null;
			tranIdVector = null;
			empCodeVector = null;
			tranIdVec = null;
				if(conn != null){conn.close();conn = null;}}
			catch(Exception e)
			{e.printStackTrace();}
		}
		return processErrString;
	}//END OF PROCESS(2)
	
	
	public String  PopulateCustomer(ArrayList contList,String contCode,String empCode,Connection conn)
	{
		
		Vector empVector =null;
		empVector = new Vector();
		
		String	adCode = null;
		String 	acctCode = null;
		String 	cctrCode= null;
		double amount= 0;
		String tranId=null;
		
		PreparedStatement pstmt = null;
		PreparedStatement pstmt1 = null;
		ResultSet rs= null;
		ResultSet rs1= null;
	
		String sql = null;
		String sqlDet = null;
		String acctCOdeSqlemp=null;
		int flag = 0;
		boolean recordFound = false;
		try
		{
			//sql ="SELECT EMPLOYEE.EMP_CODE,FULLFINAL_HDR.emp_code FROM EMPLOYEE,FULLFINAL_HDR WHERE "
			//+" EMPLOYEE.emp_code = FULLFINAL_HDR.emp_code and EMPLOYEE.SUPP_CODE__CON  = '"+contCode+"' and upper(FULLFINAL_HDR.CONFIRMED)='I'";
			//sql = "SELECT EMP_CODE FROM EMPLOYEE WHERE SUPP_CODE__CON  = '"+contCode+"'";
		//	pstmt = conn.prepareStatement(sql);
			//rs = pstmt.executeQuery();
			//while(rs.next())
			//{
				//empVector.add(rs.getString(1));
			//}
		//	rs.close();
			//pstmt.close();
			empVector.add(empCode);
			
			System.out.println("Total no of (FULLFINAL ITAX PROCESS) employee under contractor["+contCode+"]["+empVector.size()+"]");
			
			for(int i = 0;i<empVector.size();i++)
			{
				acctCode =null;
				cctrCode =null;
				empCode = (String)empVector.get(i);
				System.out.println("Processing for Employee:::["+empCode+"]");
				//******************
					sql = "SELECT ACCT_CODE__SAL , CCTR_CODE__SAL FROM EMPLOYEE WHERE EMP_CODE ='"+empCode+"'";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if(rs.next())
					{
							acctCode = rs.getString(1);
							cctrCode = rs.getString(2);
					}
					pstmt.close();
					rs.close();
				//******************** 
				flag = 0;
				sql = "SELECT TRAN_ID   FROM FULLFINAL_HDR WHERE EMP_CODE='"+empCode+"' and upper(CONFIRMED)='I' ";
				System.out.println("FULLFINAL_HDR:::::::["+sql+"]");
				
				pstmt = conn.prepareStatement(sql);
				rs = pstmt.executeQuery();
				while(rs.next())
				{
					recordFound = true;
					
					tranId = rs.getString(1);flag++;
					if(flag==2)break;
					        
 					//tranIdVector.add(tranId);
     
					sqlDet = "SELECT  FULLFINAL_DET.AD_CODE , FULLFINAL_DET.AMOUNT , FULLFINAL_DET.ACCT_CODE ,  FULLFINAL_DET.CCTR_CODE ,"
					+" FULLFINAL_DET.LOAN_NO,FULLFINAL_DET.REF_NO ,FULLFINAL_DET.START_DATE	FROM FULLFINAL_DET , ALLWDEDN     WHERE ( FULLFINAL_DET.AD_CODE = ALLWDEDN.AD_CODE (+)) AND ( ( FULLFINAL_DET.TRAN_ID = '"+tranId+"' ) AND "
					+"( FULLFINAL_DET.PAYROLL_VOUCHER = 'V' ) ) ";
					System.out.println("FULLFINAL_DET:::::::["+sqlDet+"]");
					
					pstmt1 = conn.prepareStatement(sqlDet);
					rs1 = pstmt1.executeQuery();
					while(rs1.next())
					{
						adCode = rs1.getString(1);
						amount= rs1.getDouble(2);
						if(acctCode==null)
						acctCode= rs1.getString(3);
						if(cctrCode==null)
						cctrCode= rs1.getString(4);

						Customer customer= new Customer();
						customer.setEmpCode(empCode);
						customer.setAdCode((adCode==null?"  ":adCode));
						customer.setAcctCode(acctCode);
						customer.setCctrCode(cctrCode);
						customer.setAmount(amount);
						customer.setTarnId(tranId);
						
						//******************
						customer.setLoanNo(rs1.getString(5));
						customer.setRefNo(rs1.getString(6));
						customer.setStartDate(rs1.getTimestamp(7));
						System.out.println("START DATE   ["+rs1.getTimestamp(7)+"]");
						//**********************
						int ele = getExistanceOfContCode(contList, contCode);
						System.out.println("ContractorCode exist/not["+ele+","+contCode+"]");
						Suppliers supplier = null ;
						if (ele == -1)
						{
							supplier = new Suppliers();
							supplier.setSuppCode(contCode);
							supplier.setGenInfo(conn);
							contList.add(supplier);
							ele = contList.size() -1;
							System.out.println("The size of the element is "+ele);
						}
						else 
						{
							supplier = (Suppliers)contList.get(ele);
						}
						supplier.setCustomerList(customer);
						contList.set(ele,supplier);	
						
					}//end of inner while
					rs1.close();
					pstmt1.close();
					
				}//end of outer while
				rs.close();
				pstmt.close();
				if(flag == 2 ) 
				{
					messagePrStr = "More Than on record found in the header fullfinal_hdr"; 
					return messagePrStr;
				}
				if(recordFound == false)
				{
						messagePrStr = "Employee tax process not Done"; 
					
				}
				
			}//end For
		}
		catch(SQLException se)
		{
			processErrString = "EXCEPTION";
			se.printStackTrace();
		}
		catch(Exception e)
		{
			processErrString = "EXCEPTION";
			e.printStackTrace();
		}
			return messagePrStr;
	}//end PupolateCustomer
	
	public String  createVoucher(ArrayList contList)
	{
		System.out.println("contList"+contList.size());
		StringBuffer masterXmlString = new StringBuffer();
		String contCode = null;
		String taxClass=null;
		String	taxChap=null;
		String	taxEnv=null;
		String	currCode=null;
		String	siteCode=null;
		String	bankCode=null;
		String	finEntity=null;
		double	exchRate=0;
		String	acctCodeAp=null;
		String	cctrCodeAp=null;
		String	prdCode =null;
		String lineNo = null;
		String entryBatchNo =null;
		String adCode = null;
		double	amt =   0;
		String acctCode =  null;
		String empCode=null;
		String tranId =null;
		String cctrCode =null;
	   //String cctrCode =null;
		Suppliers supplier = null;
		Customer customer = null;
		ArrayList customerList = null;
		String acctPay = null;
		String cctrPay = null;
	
		for(int supp=0;supp<contList.size();supp++)
		{
			masterXmlString.append("<DocumentRoot>");
			masterXmlString.append("<description>").append("Datawindow Root").append("</description>");
			masterXmlString.append("<group0>");
			masterXmlString.append("<description>").append("Group0 description").append("</description>");
			masterXmlString.append("<Header0>");
			masterXmlString.append("<objName><![CDATA[").append("misc_voucher").append("]]></objName>");
			masterXmlString.append("<pageContext><![CDATA[").append("2").append("]]></pageContext>");
			masterXmlString.append("<objContext><![CDATA[").append("1").append("]]></objContext>");
			masterXmlString.append("<editFlag><![CDATA[").append("A").append("]]></editFlag>");
			masterXmlString.append("<focusedColumn><![CDATA[").append("").append("]]></focusedColumn>");
			masterXmlString.append("<action><![CDATA[").append("SAVE").append("]]></action>");
			masterXmlString.append("<elementName><![CDATA[").append("").append("]]></elementName>");
			masterXmlString.append("<keyValue><![CDATA[").append("1").append("]]></keyValue>");
			masterXmlString.append("<taxKeyValue><![CDATA[").append("").append("]]></taxKeyValue>");
			masterXmlString.append("<saveLevel><![CDATA[").append("1").append("]]></saveLevel>");
			masterXmlString.append("<forcedSave><![CDATA[").append(true).append("]]></forcedSave>");
			masterXmlString.append("<taxInFocus><![CDATA[").append(false).append("]]></taxInFocus>");
			masterXmlString.append("<description>").append("Header0 members").append("</description>");
			
			supplier = (Suppliers)contList.get(supp);
			
			contCode=supplier.getSuppCode(); 
			taxClass=supplier.getTaxClass();
			taxChap=supplier.getTaxChap();
			taxEnv=supplier.getTaxEnv();
			currCode=supplier.getCurrCode();
			siteCode=supplier.getSiteCode();
			bankCode=supplier.getBankCode();
			finEntity=supplier.getFinEntity();
			exchRate=supplier.getExchRate();
			acctCodeAp=supplier.getAcctCodeAp();
			cctrCodeAp=supplier.getCctrCodeAp();
			prdCode =  supplier.getPrdCode();
			entryBatchNo = prdCode + supplier.getSiteCode();
			acctPay =supplier.getAcctCodeAp();
			cctrPay = supplier.getCctrCodeAp();
			
			masterXmlString.append("<Detail1 dbID=\"\" domID=\"1\" objName=\"misc_voucher\" objContext=\"1\">");
			masterXmlString.append("<attribute pkNames=\"\" status=\"N\" updateFlag=\"A\" selected=\"N\"/>");
			masterXmlString.append("<tran_id/>");
			masterXmlString.append("<vouch_type><![CDATA[").append("E").append("]]></vouch_type>");
			masterXmlString.append("<tran_date><![CDATA[").append(getCurrdateInAppFormat()).append("]]></tran_date>");
			masterXmlString.append("<tran_type><![CDATA[").append("FFS").append("]]></tran_type>"); 
	    	masterXmlString.append("<eff_date><![CDATA[").append(getCurrdateInAppFormat()).append("]]></eff_date>");	
			masterXmlString.append("<sundry_type><![CDATA[").append("S").append("]]></sundry_type>");
			masterXmlString.append("<sundry_code ><![CDATA[").append((contCode==null?" ":contCode.trim())).append("]]></sundry_code>");
			masterXmlString.append("<acct_code__ap><![CDATA[").append((acctCodeAp==null?"":acctCodeAp.trim())).append("]]></acct_code__ap>");
			masterXmlString.append("<cctr_code__ap><![CDATA[").append((cctrCodeAp==null?"":cctrCodeAp.trim())).append("]]></cctr_code__ap>");
			masterXmlString.append("<bill_no><![CDATA[").append("").append("]]></bill_no>");
			masterXmlString.append("<bill_date><![CDATA[").append(getCurrdateInAppFormat()).append("]]></bill_date>");
			masterXmlString.append("<order_ref><![CDATA[").append("").append("]]></order_ref>");
			masterXmlString.append("<site_code><![CDATA[").append((siteCode==null?" ":siteCode.trim())).append("]]></site_code>");
			masterXmlString.append("<fin_entity><![CDATA[").append((finEntity==null?"":finEntity.trim())).append("]]></fin_entity>");
			masterXmlString.append("<curr_code><![CDATA[").append((currCode==null?"":currCode.trim())).append("]]></curr_code>");
			masterXmlString.append("<proj_code><![CDATA[").append("").append("]]></proj_code>");
			masterXmlString.append("<cr_term><![CDATA[").append("").append("]]></cr_term>");
			masterXmlString.append("<due_date><![CDATA[").append(getCurrdateInAppFormat()).append("]]></due_date>");
			masterXmlString.append("<bill_amt><![CDATA[").append("0").append("]]></bill_amt>");
			masterXmlString.append("<tax_class><![CDATA[").append((taxClass==null?"":taxClass.trim())).append("]]></tax_class>");
			masterXmlString.append("<tax_chap><![CDATA[").append((taxChap==null?"":taxChap.trim())).append("]]></tax_chap>");
			masterXmlString.append("<tax_env><![CDATA[").append((taxEnv==null?"":taxEnv.trim())).append("]]></tax_env>");
			masterXmlString.append("<tax_date><![CDATA[").append(getCurrdateInAppFormat()).append("]]></tax_date>");
			masterXmlString.append("<tax_amt><![CDATA[").append("0").append("]]></tax_amt>");  //cross update
			masterXmlString.append("<tot_amt><![CDATA[").append("0").append("]]></tot_amt>");  //cross update
			masterXmlString.append("<adv_amt><![CDATA[").append("0").append("]]></adv_amt>");
			masterXmlString.append("<acct_code__adv><![CDATA[").append("").append("]]></acct_code__adv>");
			masterXmlString.append("<cctr_code__adv><![CDATA[").append("").append("]]></cctr_code__adv>");
			masterXmlString.append("<net_amt><![CDATA[").append("0").append("]]></net_amt>");  //cross update
			masterXmlString.append("<net_amt__bc><![CDATA[").append("0").append("]]></net_amt__bc>");  //cross update
			masterXmlString.append("<auto_pay><![CDATA[").append("Y").append("]]></auto_pay>");
			masterXmlString.append("<pay_mode><![CDATA[").append("").append("]]></pay_mode>");
			masterXmlString.append("<bank_code><![CDATA[").append((bankCode==null?"":bankCode.trim())).append("]]></bank_code>");
			masterXmlString.append("<entry_batch_no><![CDATA[").append((entryBatchNo==null?" ":entryBatchNo.trim())).append("]]></entry_batch_no>");
			masterXmlString.append("<anal_code><![CDATA[").append("").append("]]></anal_code>");
			masterXmlString.append("<emp_code><![CDATA[").append("").append("]]></emp_code>");
			masterXmlString.append("<diff_amt__exch><![CDATA[").append("").append("]]></diff_amt__exch>");
			masterXmlString.append("<acct_code__cf><![CDATA[").append("").append("]]></acct_code__cf>");
			masterXmlString.append("<cctr_code__cf><![CDATA[").append("").append("]]></cctr_code__cf>");
			masterXmlString.append("<confirmed><![CDATA[").append("N").append("]]></confirmed>");
			masterXmlString.append("<conf_date><![CDATA[").append("").append("]]></conf_date>");
			masterXmlString.append("<emp_code__aprv><![CDATA[").append("").append("]]></emp_code__aprv>");
			masterXmlString.append("<site_descr><![CDATA[").append("").append("]]></site_descr>");
			masterXmlString.append("<chg_date/>");
			masterXmlString.append("<chg_user/>"); 
			masterXmlString.append("<chg_term/>");
			masterXmlString.append("<remarks><![CDATA[").append("").append("]]></remarks>");
			masterXmlString.append("<supp_bill_amt><![CDATA[").append("00").append("]]></supp_bill_amt>");
			masterXmlString.append("<exch_rate ><![CDATA[").append("1").append("]]></exch_rate>");
			masterXmlString.append("<rnd_off><![CDATA[").append("R").append("]]></rnd_off>");
			masterXmlString.append("<rnd_to><![CDATA[").append("1").append("]]></rnd_to>");
			masterXmlString.append("<rnd_amt><![CDATA[").append("00").append("]]></rnd_amt>");
			masterXmlString.append("<sundry_type__pay><![CDATA[").append("S").append("]]></sundry_type__pay>");	
			masterXmlString.append("<sundry_code__pay><![CDATA[").append((contCode==null?" ":contCode.trim())).append("]]></sundry_code__pay>"); 
			masterXmlString.append("<acct_code__pay><![CDATA[").append((acctPay==null?"":acctPay.trim())).append("]]></acct_code__pay>");
			masterXmlString.append("<cctr_code__pay><![CDATA[").append((cctrPay==null?"":cctrPay.trim())).append("]]></cctr_code__pay>");
			masterXmlString.append("<chq_name><![CDATA[").append("").append("]]></chq_name>");
			masterXmlString.append("</Detail1>");	
			tranIdVector = null;
			tranIdVector = new Vector();
			empCodeVector = null;
			empCodeVector = new Vector();
			customerList = (ArrayList)supplier.getCustomerList();
			for(int cust=0;cust<customerList.size();cust++)
			{
				
				Customer custObj = (Customer)customerList.get(cust);
				empCode = custObj.getEmpCode();
				amt =   custObj.getAmount();
				acctCode =  custObj.getAcctCode();
				cctrCode =  custObj.getCctrCode();
				adCode = custObj.getAdCode();
				tranId = custObj.getTarnId();
				
				
				if(!tranIdVector.contains(tranId))
				{ 
					tranIdVector.add(tranId);//= new Vector();
				}
				if(!empCodeVector.contains(empCode))
				{ 
					empCodeVector.add(empCode);//= new Vector();
				}
				
				if(acctCode == null)
				{
					messagePrStr="No Account Code Not found for the customer "+empCode+" and adCode["+adCode+"]";
					break;
				}
				int line = cust+1;
				lineNo = new Integer(line).toString(); 
				messagePrStr = ProcessTransaction(custObj,conn);	
				
				masterXmlString.append("<Detail3 dbID=\"\" domID='"+lineNo+"'  objName=\"misc_voucher\"  objContext=\"3\">");
				masterXmlString.append("<attribute  pkNames=\"tran_id:line_no:\" status=\"N\" updateFlag=\"A\" selected=\"N\"/>");
				masterXmlString.append("<tran_id/>");
				masterXmlString.append("<line_no><![CDATA[").append(lineNo).append("]]></line_no>");
				masterXmlString.append("<tran_date><![CDATA[").append(getCurrdateInAppFormat()).append("]]></tran_date>");
				masterXmlString.append("<acct_code><![CDATA[").append((acctCode==null?" ":acctCode.trim())).append("]]></acct_code>");
				masterXmlString.append("<cctr_code><![CDATA[").append((cctrCode==null?" ":cctrCode.trim())).append("]]></cctr_code>");
				masterXmlString.append("<amount><![CDATA[").append(new Double(amt).toString()).append("]]></amount>");
				masterXmlString.append("<anal_code><![CDATA[").append("").append("]]></anal_code>");  //9/8/2006
				masterXmlString.append("<emp_code><![CDATA[").append(empCode).append("]]></emp_code>");
				masterXmlString.append("<apply_tax><![CDATA[").append("Y").append("]]></apply_tax>");
				masterXmlString.append("<tax_amt><![CDATA[").append("").append("]]></tax_amt>");
				masterXmlString.append("<remarks/>");
				masterXmlString.append("<sundry_type__for><![CDATA[").append("").append("]]></sundry_type__for>");
				masterXmlString.append("<sundry_code__for><![CDATA[").append("").append("]]></sundry_code__for>");
				masterXmlString.append("<acct_code__dr><![CDATA[").append("").append("]]></acct_code__dr>");
				masterXmlString.append("<cctr_code__dr><![CDATA[").append("").append("]]></cctr_code__dr>");
				masterXmlString.append("<acct_code__cr><![CDATA[").append("").append("]]></acct_code__cr>");
				masterXmlString.append("<cctr_code__cr><![CDATA[").append("").append("]]></cctr_code__cr>");
				masterXmlString.append("<prcp_id><![CDATA[").append("").append("]]></prcp_id>");
				masterXmlString.append("<line_no__rcp><![CDATA[").append("").append("]]></line_no__rcp>");
				masterXmlString.append("<item_code><![CDATA[").append("").append("]]></item_code>");
				masterXmlString.append("<quantity><![CDATA[").append("").append("]]></quantity>");
				masterXmlString.append("<rate><![CDATA[").append("").append("]]></rate>");
				masterXmlString.append("<rate__clg><![CDATA[").append("").append("]]></rate__clg>");
				masterXmlString.append("<bill_no><![CDATA[").append("").append("]]></bill_no>");
				masterXmlString.append("<bill_date><![CDATA[").append(getCurrdateInAppFormat()).append("]]></bill_date>");
				masterXmlString.append("<bill_amt><![CDATA[").append("").append("]]></bill_amt>");
				masterXmlString.append("<tax_class><![CDATA[").append((taxClass==null?" ":taxClass.trim())).append("]]></tax_class>");
				masterXmlString.append("<tax_chap><![CDATA[").append((taxChap==null?" ":taxChap.trim())).append("]]></tax_chap>");
				masterXmlString.append("<tax_env><![CDATA[").append((taxEnv==null?"":taxEnv.trim())).append("]]></tax_env>");
				masterXmlString.append("</Detail3>");	
			}
		masterXmlString.append("</Header0>");
		masterXmlString.append("</group0>");
		masterXmlString.append("</DocumentRoot>");
		String retString = null;
		try
		{
			if(messagePrStr==null && processErrString==null)
			{
				PayRollVoucPrc payRollVoucPrcEJB = null;
				payRollVoucPrcEJB = new PayRollVoucPrc();//added for ejb3
			
				String convertXmlString = masterXmlString.toString();
				//writting going xmlstring to masterstatefull
				payRollVoucPrcEJB.writeXmlInFile(convertXmlString,"FFS",contCode);
				//end
				String returnArrFromSave [] = payRollVoucPrcEJB.saveXmlData(convertXmlString,userId,loginSite);	
				for (int a =0 ;a<returnArrFromSave.length; a++)
				{
					retString = retString +returnArrFromSave[a];
					retString = retString +"@";
				}
				System.out.println("retString:::::::::::::"+retString);
				String tranIdG = retString.substring(retString.indexOf("@")+1,retString.length()-1);
				System.out.println("Return Transaction Id:::::::["+tranIdG+"]");
				//payRollVoucPrcEJB.updateMiscVoucherDet(tranIdG,conn);
				//payRollVoucPrcEJB.updateMiscVoucher(tranIdG,conn);
				SeperateEmpUpdateFullFinal(empCodeVector,tranIdVector);
			}
		
		}
		catch(Exception e)
		{
			
			processErrString = "EXCEPTION";
			e.printStackTrace();
			
		}
		
	}
		return messagePrStr;
}
	public void SeperateEmpUpdateFullFinal(Vector empCodeVector,Vector tranIdVector)
	{
		System.out.println("Total Employee ................["+empCodeVector.size()+"]");
		System.out.println("Total Tranid ................["+tranIdVector.size()+"]");
		ResultSet rs = null;
		PreparedStatement pstmt = null;
		String sql =null;
		Timestamp releaveDate = null;
		String tranId =null;
		String empCode = null;
		try
		{
		
			for(int custCount =0;custCount<empCodeVector.size();custCount++)
			{
				empCode = (String)empCodeVector.get(custCount);
				sql = "SELECT RELIEVE_DATE FROM FULLFINAL_HDR WHERE  EMP_CODE='"+empCode+"'";  
				System.out.println("RELIEVE_DATE from  FULLFINAL Query :::["+sql+"]");
				
				pstmt = conn.prepareStatement(sql);
				rs = pstmt.executeQuery();
				if(rs.next())
				{
					releaveDate  =  rs.getTimestamp(1);
					
				}
				rs.close();
				pstmt.close();
				sql = "	UPDATE EMPLOYEE SET RELIEVE_DATE = ?, STATUS = 'S',	 CHG_DATE = ?, CHG_TERM = ?, CHG_USER = ?"
				+"WHERE EMP_CODE = '"+empCode+"'";
				System.out.println("EMPLOYEE EMPLOREE QUERY :::["+sql+"]");
				pstmt = conn.prepareStatement(sql);
				pstmt.setTimestamp(1,releaveDate);
				pstmt.setTimestamp(2,new java.sql.Timestamp(System.currentTimeMillis()));
				pstmt.setString(3,chgTerm);
				pstmt.setString(4,chgUser);
				System.out.println("Number of record update in employee :::["+pstmt.executeUpdate()+"]");
				pstmt.close();
				sql = "	UPDATE USERS SET STATUS = 'C' 	WHERE EMP_CODE =  '"+empCode+"'";
				System.out.println("EMPLOYEE USERS QUERY :::["+sql+"]");
				pstmt = conn.prepareStatement(sql);
				System.out.println("Number of record update in users :::["+pstmt.executeUpdate()+"]");
				pstmt.close();
				sql = "	UPDATE SALES_PERS 	SET ACTIVE = 'N' WHERE  EMP_CODE =  '"+empCode+"'";
				System.out.println("EMPLOYEE SALES_PERS QUERY :::["+sql+"]");
				pstmt = conn.prepareStatement(sql);
				System.out.println("Number of record update in sales_pers :::["+pstmt.executeUpdate()+"]");
			}
			for(int tranIdCnt =0;tranIdCnt<empCodeVector.size();tranIdCnt++)
			{
				tranId = (String)tranIdVector.get(tranIdCnt);
				sql = "UPDATE FULLFINAL_HDR SET CONFIRMED = 'Y', CONF_DATE = ?, EMP_CODE__APRV = ? WHERE TRAN_ID = '"+tranId+"'";
				System.out.println("EMPLOYEE FULLFINAL_HDR QUERY :::["+sql+"]");
				pstmt = conn.prepareStatement(sql);
				pstmt.setTimestamp(1,new java.sql.Timestamp(System.currentTimeMillis()));
				pstmt.setString(2,loginEmpCode);
				System.out.println("Number of record update in fullfinal_hdr :::["+pstmt.executeUpdate()+"]");
				pstmt.executeUpdate();
			}
		}
		catch(SQLException se)
		{
			processErrString = "EXCEPTION";
			se.printStackTrace();
		}
		catch(Exception e)
		{	
			processErrString = "EXCEPTION";
			e.printStackTrace();
		}
	
	}
	public String 	ProcessTransaction(Customer cust, Connection conn)
	{
		
		ResultSet rs = null;
		PreparedStatement pstmt = null;
		String sql =null;
		String loanNo = null;
		String refNo = null;
		Timestamp startDate = null;
		String tranId = null;
		String adCode = null;
		String schemeNo = null;
		double interest=0;
		String monInst= null;
		double loanAmt= 0;
		String loanAd= null;
		Timestamp startRecoDate= null;
		double amount = cust.getAmount();
		String remark = null;
		String empCode =null;
		String recoNo= null;
		try
		{
			
			loanNo = cust.getLoanNo();
			startDate = cust.getStartDate();
			tranId = cust.getTarnId();
			adCode = cust.getAdCode();
			empCode = cust.getEmpCode();
			
			
			System.out.println("ProcessTransaction::::::::startDate["+startDate+"]"); 
			if(!tranIdVec.contains(tranId))
			{
				 //messagePrStr = AdjustMent(tranId);
				if(messagePrStr!=null) 
				{
					return messagePrStr;
				}
			
			}
			if(loanNo!=null)
			{
				if(runMode.equalsIgnoreCase("I"))
				{
					sql = "	SELECT LOANS.SCHEME_NO, LOANS.INTEREST, LOANS.MON_INST, LOANS.LOAN_AMT , AD_CODE__DED, LOANS.START_RECO "
					+"	FROM LOANS , LOAN_SCHEME WHERE LOANS.SCHEME_NO =LOAN_SCHEME.SCHEME_NO AND LOAN_NO = '"+loanNo+"'";
					pstmt = conn.prepareStatement(sql);
					rs = pstmt.executeQuery();
					if(rs.next())
					{
						 schemeNo = rs.getString(1);
						 interest = rs.getDouble(2);
						 monInst = rs.getString(3);
						 loanAmt = rs.getDouble(4);
						 loanAd = rs.getString(5);
						 startRecoDate = rs.getTimestamp(6);
					}
					else
					{
						 messagePrStr = "No data found in loan table for loan no :["+loanNo+"]";
					}
					rs.close();
					pstmt.close();
				}
				amount = (-1)*amount;
				recoNo =  generateTranId("W_LOAN_RECO",getCurrdateInAppFormat(),loginSite,conn);
				 messagePrStr= "Through full and final settlement " + adCode;
				sql = " INSERT INTO LOAN_RECO "
				+" (RECO_NO, RECO_DATE, LOAN_NO, SCHEME_NO, EMP_CODE, "
				+" START_DATE, LOAN_AMT, LOAN_INTEREST, MON_INST, AD_CODE, "
				+" RECO_AMT, CHG_DATE, CHG_USER, CHG_TERM, REMARKS, CONFIRMED , INT_CALCULATED)"
				+" VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,? ,'Y' , 'Y')";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,recoNo);
				pstmt.setTimestamp(2,new java.sql.Timestamp(System.currentTimeMillis()));
				pstmt.setString(3,loanNo);
				pstmt.setString(4,schemeNo);
				pstmt.setString(5,empCode);
				pstmt.setTimestamp(6,startRecoDate);
				pstmt.setDouble(7,loanAmt);
				pstmt.setDouble(8,interest);
				pstmt.setString(9,monInst);
				pstmt.setDouble(10,amount);
				pstmt.setString(11,userId);
				pstmt.setString(12,chgTerm);
				pstmt.setString(13,remark);
				System.out.println("No of record insert ["+pstmt.executeUpdate()+"]");
				pstmt.close();
				/*// call function for direct loan recovery adjustment of installments
				lds_loan_reco.reset()
				lds_loan_reco.retrieve(ls_refno)
				// Replaced gunction with nvo - piyush - 25/09/01
				// if gf_loan_reco(ls_recono, lds_loan_reco) = -1 then
				ls_errcode = nvo_loan_reco.gbf_loan_reco_retrieve(ls_recono , ls_recono , 1)
				if not isnull(ls_errcode) and len(trim(ls_errcode)) > 0 then
					//// Direct Loan recovery error
					//	ls_errcode = "VMDLOANRECO" // Remarked - piyush - 25/09/01
					exit
				end if
 			
				if lds_loan_reco.update() <> 1 then
					ls_errcode = 'DS000' + string(sqlca.sqldbcode) + '~t ' + sqlca.sqlerrtext + & 
						"~t Faild to update loan_reco table "
					exit
				end if
				***************
				select ledg_post_conf
				  into :ls_ledg_post_conf
				  from transetup 
				 where upper(tran_window) = 'W_FULLFINAL';
				if get_sqlcode() = 100 then
					ls_errcode = 'VTSEQ'
					exit
				elseif get_sqlcode() <> 0 then
					ls_errcode = 'DS000'+ TRIM(STRING(SQLCA.SQLDBCODE)) + '~t ' + sqlca.sqlerrtext
					exit
				end if		 
				if ls_ledg_post_conf = 'Y' then
					if ld_tran <> ld_currdate then
						ld_tran =  ld_currdate
					end if	
				end if*/
			}
			else if (startDate!=null && adCode !=null)
			{
				messagePrStr = updAllowdednBal(empCode,adCode,amount,startDate,conn);
				
			}	
		}
		catch(Exception e)
		{
			processErrString = "EXCEPTION";
			e.printStackTrace();
		}
	return 	messagePrStr;
	}
protected String  updAllowdednBal(String empCode,String adCode,double amt,Timestamp startDate,Connection conn)
{
	System.out.println("startDate ::: ["+startDate+"]");
	System.out.println("adCode ::: ["+adCode+"]");
	
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		double amountBAl = 0;
		try
		{
			String sql = " SELECT AMT_BAL FROM  ALLOWDEDN_BAL 		WHERE EMP_CODE = '"+empCode+"'	AND AD_CODE    = '"+adCode+"' 	AND START_DATE = ? 	";
			pstmt = conn.prepareStatement(sql);
			pstmt.setTimestamp(1,startDate);
			rs = pstmt.executeQuery();
			if(rs.next())
			{
				amountBAl = rs.getDouble(1);
			}
			else
			{
				messagePrStr = "No data found in allowdedn_bal table for employee code : " + empCode+" and ad code : " + adCode+	" and start date : " + startDate;
				return  messagePrStr;
			}
			if((amountBAl - amt) <0)
			{
				messagePrStr ="Not Enough Balance For Ad Code " + adCode;
			}
			else
			{
				 sql = " UPDATE ALLOWDEDN_BAL 	SET 	AMT_BAL	= AMT_BAL - ?,AMT_ADJ  = AMT_ADJ + ? "
				+"	WHERE EMP_CODE = '"+empCode+"'	AND AD_CODE    = '"+adCode+"' 	AND START_DATE = ? 	";
				System.out.println("ALLOWDEDN_BAL ::: "+sql);
				pstmt = conn.prepareStatement(sql);
				pstmt.setDouble(1,amt);
				pstmt.setDouble(2,amt);
				System.out.println("StartDate:::["+startDate+"]");
				pstmt.setTimestamp(3,startDate);
				System.out.println("NO Of Record update in the ALLOWDEDN_BAL is ["+pstmt.executeUpdate()+"]");
				pstmt.close();
			}
		}  
		catch(Exception e)
		{
			processErrString = "EXCEPTION";
			e.printStackTrace();
		}
		return messagePrStr;
}
	//TO FIND WHEATHER A CONTRACTOR CODE PRESENT IN LIST OR NOT
	private int getExistanceOfContCode(ArrayList contList,String contCode)
	{
			int ctr = 0;
			int retVal = -1;
			Suppliers encashSupp;
			for (ctr = 0;ctr < contList.size();ctr++)
			{
				encashSupp = (Suppliers)contList.get(ctr);
				if (encashSupp.getSuppCode().trim().equalsIgnoreCase(contCode.trim()))
				{
					retVal = ctr;
					break;
				}
			}
			return retVal;
	}

//GENERATING TRAN ID 
private String generateTranId(String windowName,String tranDate,String siteCode,Connection conn)
{
		Statement stmt = null;
		ResultSet rs = null;
		String sql = null;
		String tranId = null;
		String xmlValues = null;
		 try
	     {
	    	sql = "SELECT KEY_STRING, TRAN_ID_COL, REF_SER FROM TRANSETUP WHERE UPPER(TRAN_WINDOW)= '"+windowName+"'";
	    	System.out.println("Tran generator Sql"+sql);
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			System.out.println("keyString :"+rs.toString());
			String tranSer1 = "";
			String keyString = "";
			String keyCol = "";
			if (rs.next())
			{
				keyString = rs.getString(1);
				keyCol = rs.getString(2);
				tranSer1 = rs.getString(3);				
			}
			System.out.println("keyString :"+keyString);
			System.out.println("keyCol :"+keyCol);
			System.out.println("tranSer1 :"+tranSer1);
			xmlValues ="<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>";
			xmlValues = xmlValues + "<Header></Header>";
			xmlValues = xmlValues + "<Detail1>";
			xmlValues = xmlValues +	"<tran_id></tran_id>";
			xmlValues = xmlValues + "<site_code>" + siteCode + "</site_code>";
			xmlValues = xmlValues + "<tran_date>"+ tranDate + "</tran_date>";
			xmlValues = xmlValues + "</Detail1></Root>";
			System.out.println("xmlValues  :["+xmlValues+"]");
			TransIDGenerator tg = new TransIDGenerator(xmlValues, "BASE", CommonConstants.DB_NAME);
			tranId = tg.generateTranSeqID(tranSer1, keyCol, keyString, conn);
			System.out.println("tranId :"+tranId);
		}
		catch (SQLException ex)
		{
			processErrString = "Exception";
			ex.printStackTrace();
		}
		catch (Exception e)
		{
			processErrString = "Exception";
			e.printStackTrace();
		}
		return tranId;
	}
//CONVERTING APPLICATION DATE TO DB DATE AND VICE VERSA
	public String getValidDateTimeString(String dateTimeStr, String sourceDateTimeFormat, String targetDateTimeFormat) throws ITMException
	{
		System.out.println("Getting the valid datetime string for dateTimeStr :"+dateTimeStr+": which is in format :"+sourceDateTimeFormat);
		Object date = null;
		String retDateStr = "";
		try
		{
			if (!(sourceDateTimeFormat.equalsIgnoreCase(targetDateTimeFormat)))
			{
				if (sourceDateTimeFormat.indexOf("/") != -1)
				{
					dateTimeStr.replace('/', '-');
				}
				else if (sourceDateTimeFormat.indexOf(".") != -1)
				{
					dateTimeStr.replace('.', '-');
				}
				date = new SimpleDateFormat(sourceDateTimeFormat).parse(dateTimeStr);
				SimpleDateFormat sdfOutput = new SimpleDateFormat(targetDateTimeFormat);
				retDateStr = sdfOutput.format(date);
			}
			else
			{
				retDateStr = dateTimeStr;
			}
		}
		catch (Exception e)
		{
			System.out.println("Exception :GenericUtility :getValidDateString :==>"+e.getMessage());
			throw new ITMException(e);
		}
		System.out.println("retDateStr :"+retDateStr);
		return retDateStr;
	}
//GETTING CURRENT DATE IN APPLICATION DATE FORMAT
private String getCurrdateInAppFormat()
{
	String currAppdate =null;
	java.sql.Timestamp currDate = null;
	Object date = null;
	SimpleDateFormat DBDate=null;
	try
	{
			currDate =new java.sql.Timestamp(System.currentTimeMillis()) ;
			System.out.println(genericUtility.getDBDateFormat());
		 	DBDate= new SimpleDateFormat(genericUtility.getDBDateFormat());
			date = DBDate.parse(currDate.toString());
			currDate =	java.sql.Timestamp.valueOf(DBDate.format(date).toString() + " 00:00:00.0");
			currAppdate = new SimpleDateFormat(genericUtility.getApplDateFormat()).format(currDate).toString();
	}
	catch(Exception e)
	{
		System.out.println("Exception in  getCurrdateInAppFormat:::"+e.getMessage());
	}
	return (currAppdate);
}

private String  AdjustMent(String tranId)
{
		AdmCommon admCommon = new AdmCommon();
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		String sql =null;
		String empCode =null;
		double totAmt =0;
		String workSite = null;
		String grade = null;
		String cadre = null;
		String rndOff = null;
		String ffsRndTo =null;
		double rndAmound =0;
		String 	acctCodeAd = null;
		String cctrCodeSalAd = null;
		double lineNo = 0;
		String rndOffAD = null;
		String cctrCodeSal =null;
		double amount = 0;
		String paySite = null; 
		try
		{
			sql ="SELECT EMP_CODE,TOTAL_AMT  FROM FULLFINAL_HDR WHERE TRAN_ID = '"+tranId+"'";
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			if(rs.next())
			{ 
				empCode = rs.getString(1);
				totAmt = rs.getDouble(2);
				System.out.println("EmpCode :::["+empCode+"]");
				System.out.println("totAmt :::["+totAmt+"]");
			}
			rs.close();
			pstmt.close();
			sql = "SELECT WORK_SITE, GRADE, CADRE FROM EMPLOYEE WHERE EMP_CODE = '"+empCode+"'";
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			if(rs.next())
			{
				workSite = rs.getString(1);
				grade = rs.getString(2);
				cadre = rs.getString(3);
				System.out.println("work site ["+workSite+"]");
				System.out.println("work site ["+grade+"]");
				System.out.println("work site ["+cadre+"]");
			}
			rs.close();
			pstmt.close();
			rndOff = admCommon.getAdmEnv(workSite, cadre, grade, "FFS_RNDOFF", new java.sql.Timestamp(System.currentTimeMillis()), conn) ;
			if(rndOff.equalsIgnoreCase("NULLFOUND"))
			{
				messagePrStr = "write messageVSENVAR~t Variable (FFS_RNDOFF) is not defined properly"; 
					return messagePrStr;
			}
			if((!rndOff.equalsIgnoreCase("NULLFOUND")) &&(!rndOff.equalsIgnoreCase("N")))
			{
				rndOffAD = admCommon.getAdmEnv(workSite, cadre, grade, "FFS_RNDOFF_AD", new java.sql.Timestamp(System.currentTimeMillis()), conn) ;
				if(rndOffAD.equalsIgnoreCase("NULLFOUND"))
				{
					messagePrStr = "VSENVAR~t Variable (FFS_RNDOFF_AD) is not defined properly"; 
						return messagePrStr;
				}
			}
			ffsRndTo = admCommon.getAdmEnv(workSite, cadre, grade, "FFS_RNDTO",new java.sql.Timestamp(System.currentTimeMillis()), conn) ;
			if(ffsRndTo.equalsIgnoreCase("NULLFOUND"))
			{
				messagePrStr = "VSENVAR~t Variable (FFS_RNDTO) is not defined properly";
					return messagePrStr;
			}
			System.out.println("parameter pass to getRndamt method .....");
			System.out.println("totAmt   ["+totAmt+"]");
			System.out.println("rndOff   ["+rndOff+"]");
			System.out.println("ffsRndTo   ["+ffsRndTo+"]");
			DistCommon disCommon = new DistCommon();
			rndAmound = disCommon.getRndamt(totAmt, rndOff, Double.parseDouble(ffsRndTo));
			
			
			
			 disCommon = null;
			System.out.println("Round Amount   ["+rndAmound+"]");
			sql = "SELECT CCTR_CODE__SAL, PAY_SITE  FROM EMPLOYEE WHERE EMP_CODE = '"+empCode+"'";
			pstmt = conn.prepareStatement(sql);
			if(rs.next())
			{
				cctrCodeSal = rs.getString(1);
				paySite = rs.getString(2);
			}
			rs.close();
			pstmt.close();
			sql = "SELECT ACCT_CODE__SAL, CCTR_CODE__SAL FROM ALLWDEDN WHERE AD_CODE = '"+rndOffAD+"'";
			pstmt = conn.prepareStatement(sql);
			if(rs.next())
			{
				acctCodeAd = rs.getString(1);
				cctrCodeSalAd = rs.getString(2);
			}
			rs.close();
			pstmt.close();
			if(cctrCodeSal!=null)cctrCodeSalAd = cctrCodeSal;
			sql = "SELECT MAX(LINE_NO)  FROM FULLFINAL_DET WHERE TRAN_ID = '"+tranId+"'";
			pstmt = conn.prepareStatement(sql);
			if(rs.next())
			{
				lineNo =  rs.getDouble(1);
			}
			rs.close();
			pstmt.close();
			lineNo++;
			amount = rndAmound - totAmt;
			sql = "INSERT INTO FULLFINAL_DET "
			+"	(TRAN_ID, AD_CODE, AMOUNT, REMARKS , ACCT_CODE, CCTR_CODE, LINE_NO, PAYROLL_VOUCHER, NET_AMT,"
			+"	CURR_CODE, EXCH_RATE, DAILY_EXCHRATE)"
			+"VALUES (?, ?, ?, 'TOWARDS ROUND AMOUNT',?, ?, ?,'V', ?, ?, 1, 1)";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,tranId);
			pstmt.setString(2,rndOffAD);
			pstmt.setDouble(3,amount);
			pstmt.setString(4,acctCodeAd);
			pstmt.setString(5,cctrCodeSalAd);
			pstmt.setDouble(6,lineNo);
			pstmt.setDouble(7,amount);
			pstmt.setString(8," ");
			System.out.println("Inserting fullfinal_det ["+	pstmt.executeUpdate()+"]");
			pstmt.close();
			sql = "UPDATE FULLFINAL_HDR SET TOTAL_AMT = ? WHERE TRAN_ID = '"+tranId+"'";
			pstmt = conn.prepareStatement(sql);
			pstmt.setDouble(1,amount);
			System.out.println("Upadate fullfinal_det ["+	pstmt.executeUpdate()+"]");
			
		}
		catch(Exception e)
		{
			
			processErrString = "EXCEPTION";
			e.printStackTrace();
		}
		finally
		{
			admCommon =null;
		}
		return messagePrStr;
}
}//END OF EJB