

/********************************************************
	Title : MiscVal
	Date  : 
	Developer: Dipak Chattar

********************************************************/

package ibase.webitm.ejb.fin;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.ITMDBAccessEJB;
import java.util.*;
import java.io.*;
import java.sql.*;
import java.lang.Math;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.DecimalFormat;
import java.sql.Timestamp;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.CDATASection;
import javax.ejb.Stateless; // added for ejb3


@Stateless // added for ejb3

public class MiscVal extends ValidatorEJB implements MiscValLocal, MiscValRemote
{
	GenericUtility genericUtility = GenericUtility.getInstance();
	String winName = null;
	FinCommon finCommon = null;
	ValidatorEJB validator = null;
    
  
	//method for validation
	public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
    {
	    String errString = "";
	    Document dom = null;
		Document dom1 = null;
		Document dom2 = null;
		try
		{
			System.out.println("Val xmlString :: " + xmlString);
			System.out.println("Val xmlString1 :: " + xmlString1);
			System.out.println("Val xmlString2 :: " + xmlString2 );
			dom = parseString(xmlString);
			dom1 = parseString(xmlString1);
			if (xmlString2.trim().length() > 0 )
			{
				dom2 = parseString("<Root>" + xmlString2+ "</Root>");
			}
			errString = wfValData(dom, dom1, dom2, objContext, editFlag, xtraParams);
	    }
		catch(Exception e)
		{
			throw new ITMException(e);
		}
		return(errString);
    }

    //method for validation
	public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
    {
		NodeList parentNodeList = null;
		NodeList childNodeList = null;	
		Node parentNode = null;
		Node childNode = null;
		NodeList parentNodeList1 = null;
		NodeList childNodeList1 = null;
		Node parentNode1 = null;
		Node childNode1 = null;
		NodeList parentNodeList2 = null;
		NodeList childNodeList2 = null;
		Node parentNode2 = null;
		Node childNode2 = null;
		String errorType = "";
		String empCode = "";
		String childNodeName = null;
		String errString = "";
		String errCode = "";
		String userId = "";
		String sql = "";
		String sql1 = "";
		String sql2 = "";
		String sql3 = "";
		String sql4 = "";
		String site = "";
		String finEntity1 = "";
		String finEntity2 = "";
		String refNo = "";
		String refSer = "";
		String tranType = "";
		String siteCode = "";
		String siteCodeFor = "";
		String siteCode1 = "";
		String effDate = "";
		String sundryCode = "";
		String sundryType = "";
		String stat = "";
		String tranDate = "";
		String autoPay = "";
		String vouchType = "";
		String sundryCodePay = "";
		String sundryCode1 = "";
		String sundryTypePay = "";
		String sundryType1 = "";
		String orderRef = "";
		String billNo = "";
		String billDate = "";
		String tranId = "";
		String projectCode = "";
		String currCode = "";
		String currCode1 = "";
		String currCodeEdit = "";
		String acctCodeAp = "";
		String acctCodePay = "";
		String cctrCodeAp = "";
		String acctCodeCf = "";
		String cctrCodeCf = "";
		String acctCodeAdv = "";
		String acctCode = "";
		String cctrCodeAdv = "";
		String cctrCode = "";
		String finEntity = "";
		String taxClass = "";
		String taxChap = "";
		String taxEnv = "";
		String bankCode = "";
		String crTerm = "";
		String deptCode = "";
		String analCode = "";
		String analCode1 = "";
		String analCode2 = "";
		String sundryTypeFor ="";
		String sundryCodeFor ="";
		String lineNo = "";
		String acctSpec = "";
		String saveflag = "2";
		int ctr=0;
		int cnt = 0;
		int currentFormNo = 0;
		int childNodeListLength;
		double billAmt = 0;
		double advAmt = 0.0;
		double adjAmt = 0.0;
		double adjAmt1 = 0.0;
		double Amount = 0.0;
		double totAmt = 0.0;
		double holdAmt = 0.0;
		java.util.Date tranPdate = null;
		ArrayList<String> errList = new ArrayList<String>();
		ArrayList<String> errFields = new ArrayList<String>();
		Connection conn = null;
		PreparedStatement pstmt = null ;
		ResultSet rs = null;
		ConnDriver connDriver = new ConnDriver();
		StringBuffer errStringXml = new StringBuffer("<?xml version = \"1.0\"?> \r\n <Root> <Errors>"); 
		try
		{
			finCommon = new FinCommon();
			validator = new ValidatorEJB();
			ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
			conn = connDriver.getConnectDB("DriverITM");
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
			SimpleDateFormat dbDateFormat = new SimpleDateFormat(genericUtility.getInstance().getDBDateFormat());

			userId = getValueFromXTRA_PARAMS(xtraParams, "loginCode");
			if(objContext != null && objContext.trim().length() > 0)
			{
				currentFormNo = Integer.parseInt(objContext);
			}
			switch(currentFormNo)
			{
				case 1 :
						parentNodeList = dom.getElementsByTagName("Detail1");
						parentNode = parentNodeList.item(0);
						childNodeList = parentNode.getChildNodes();
						childNodeListLength = childNodeList.getLength();
						for(ctr = 0; ctr < childNodeListLength; ctr ++)
						{
							childNode = childNodeList.item(ctr);
							childNodeName = childNode.getNodeName();
							if(childNodeName.equalsIgnoreCase("tran_type"))
							{    
								tranType = genericUtility.getColumnValue("tran_type", dom); 
								siteCode = genericUtility.getColumnValue("site_code", dom);
								effDate = genericUtility.getColumnValue("eff_date", dom);
							}
							
							else if(childNodeName.equalsIgnoreCase("tran_date"))
					    	{
								siteCode = genericUtility.getColumnValue("site_code", dom);
								tranDate = genericUtility.getColumnValue("tran_date", dom);
								try
								{
									tranPdate = simpleDateFormat.parse(tranDate);
									errCode = validator.nfCheckPeriod("FIN",new java.util.Date(tranPdate.getTime()),siteCode);
								}
								catch (ParseException e)
								{
									System.out.println("Exception in transaction date [tran_date_validation]"+e);
									e.printStackTrace();
									throw new ITMException(e);
								}
								if(errCode != null && errCode.trim().length() > 0)
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase()); 
								}
							}
							else if(childNodeName.equalsIgnoreCase("sundry_code"))
							{ 
								sundryCode = genericUtility.getColumnValue("sundry_code", dom); 
								sundryType = genericUtility.getColumnValue("sundry_type", dom);
								siteCode = genericUtility.getColumnValue("site_code", dom);
								refSer = genericUtility.getColumnValue("ref_ser", dom);
								if(sundryCode != null && sundryType != null && siteCode != null && refSer != null && sundryCode.trim().length() > 0 && sundryType.trim().length() > 0 && siteCode.trim().length() > 0 && refSer.trim().length() > 0)
								{
									errCode = finCommon.isSundryCode(siteCode, sundryType, sundryCode, refSer, conn);
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
								if ((errCode == null || (errCode.trim().length() == 0)) && "R".equalsIgnoreCase( sundryType))
								{
									sql = " select status from strg_customer where sc_code = ? ";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,siteCode);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										stat =  rs.getString(1);
										if(!"A".equalsIgnoreCase( stat )) 
										{
											errCode = "VTSTRSTAT";
											errList.add(errCode);
											errFields.add(childNodeName.toLowerCase());	
										}									
						            }
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
								else if ((errCode == null || (errCode.trim().length() == 0)) && "E".equalsIgnoreCase( sundryType)) 
								{
									sql1 = "SELECT emp_site  FROM employee WHERE emp_code = ? ";
									pstmt =  conn.prepareStatement(sql1);
									pstmt.setString(1,sundryCode);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										site =  rs.getString(1);
										if("M-VOUC".equalsIgnoreCase(refSer))
										{
											sql2 = "SELECT fin_entity  FROM site  WHERE site_code = ?";
											pstmt =  conn.prepareStatement(sql2);
											pstmt.setString(1,siteCode);
											rs = pstmt.executeQuery();
											if (rs.next())
											{
												finEntity1 =  rs.getString(1);
										    }
											sql3 = "SELECT fin_entity  FROM site  WHERE site_code = ?";
											pstmt =  conn.prepareStatement(sql3);
											pstmt.setString(1,site);
											rs = pstmt.executeQuery();
											if (rs.next())
											{
												finEntity2 =  rs.getString(1);
										    }
											if(!finEntity2.equalsIgnoreCase(finEntity1))
											{
												errCode = "";
											}
                                        }
										else if(sundryCode != null && siteCode != null && refSer != null && sundryCode.trim().length() > 0 && siteCode.trim().length() > 0 && refSer.trim().length() > 0)
										{ 
											errCode = finCommon.isEmployee(siteCode, sundryCode, refSer , conn);
									    }
										else if(site != null  && siteCode != null && !site.trim().equalsIgnoreCase(siteCode.trim()))
										{
											errCode = "VTEMPSITE";
									    }
								    }
									if (errCode == null || (errCode.trim().length() == 0))
									{
										tranDate = genericUtility.getColumnValue("tran_date", dom); 
										sql = " select pay_site from employee where emp_code = ? ";
							            pstmt =  conn.prepareStatement(sql);
							            pstmt.setString(1,sundryCode);
							            rs = pstmt.executeQuery();
							            if(rs.next())
							            {
											stat =  rs.getString(1);
											if(siteCode != null && sundryCode != null && refSer != null && siteCode.trim().length() > 0 && sundryCode.trim().length() > 0 && refSer.trim().length() > 0)
											{
												errCode = finCommon.isEmployee(siteCode, sundryCode, refSer , conn);
											}
											if(errCode != null && (errCode.trim().length() > 0))
											{
												errList.add(errCode);
												errFields.add(childNodeName.toLowerCase());
											}
								         							
										}
								        
									}
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
						   
						        }

							}
                     
							else if(childNodeName.equalsIgnoreCase("sundry_code__pay"))
							{ 
								sundryCodePay = genericUtility.getColumnValue("sundry_code__pay", dom); 
								sundryTypePay = genericUtility.getColumnValue("sundry_type__pay", dom);
								siteCode = genericUtility.getColumnValue("site_code", dom);
								refSer = genericUtility.getColumnValue("ref_ser", dom);
								if(sundryCodePay != null && sundryTypePay != null && refSer != null && sundryCodePay.trim().length() > 0 && sundryTypePay.trim().length() > 0 && refSer.trim().length() > 0)
								{
									errCode = finCommon.isSundryCode(siteCode, sundryTypePay, sundryCodePay, refSer, conn);
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
								if ((errCode == null || (errCode.trim().length() == 0)) && "E".equalsIgnoreCase( sundryTypePay)) 
								{
									sql1 = "SELECT emp_site  FROM employee WHERE emp_code = ?";
									pstmt =  conn.prepareStatement(sql1);
									pstmt.setString(1,sundryCodePay);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										site =  rs.getString(1);  
										if("M-VOUC".equalsIgnoreCase(refSer))
										{
											sql2 = "SELECT fin_entity  FROM site  WHERE site_code = ?";
											pstmt =  conn.prepareStatement(sql2);
											pstmt.setString(1,siteCode);
											rs = pstmt.executeQuery();
											if (rs.next())
											{
												finEntity1 =  rs.getString(1);
										    }
											sql3 = "SELECT fin_entity  FROM site  WHERE site_code = ?";
											pstmt =  conn.prepareStatement(sql3);
											pstmt.setString(1,site);
											rs = pstmt.executeQuery();
											if (rs.next())
											{
												finEntity2 =  rs.getString(1);
										    }
											if(!finEntity2.equalsIgnoreCase(finEntity1))
											{
												errCode = "VTEMPSITE";
											}
                                        }
										else if(siteCode != null && sundryCodePay != null && refSer != null && siteCode.trim().length() > 0 && sundryCodePay.trim().length() > 0 && refSer.trim().length() > 0)
										{ 
											errCode = finCommon.isEmployee(siteCode, sundryCodePay, refSer , conn);
									    }
										else if(site != null && siteCode != null && !site.trim().equalsIgnoreCase(siteCode.trim()))
										{
											errCode = "VTEMPSITE";
									    }
										if(errCode != null && (errCode.trim().length() > 0))
										{
											errList.add(errCode);
											errFields.add(childNodeName.toLowerCase());
										}
								    }
									rs.close();
							        rs = null;
									pstmt.close();
									pstmt = null;
						   
								}

							} 
						
							else if(childNodeName.equalsIgnoreCase("order_ref"))
							{ 
								orderRef = genericUtility.getColumnValue("order_ref", dom); 
								if(orderRef != null && orderRef.trim().length() > 0)
								{
									sql = " select count(tran_id) from srv_order where tran_id = ? and confirmed = 'Y' ";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,orderRef);
									rs = pstmt.executeQuery();
									while(rs.next())
									{	
										cnt = rs.getInt(1);
									}
									if(cnt == 0)
									{
										sql = " select count(purc_order) from porder where purc_order = ?  and confirmed = 'Y' ";
										pstmt =  conn.prepareStatement(sql);
										pstmt.setString(1,orderRef);
										rs = pstmt.executeQuery();
										while(rs.next())
										{	
											cnt = rs.getInt(1);
										}
										if(cnt == 0)
										{
											sql = " select count(contract_id) from retainer_contract where contract_id = ?  and status = 'A' ";
											pstmt = conn.prepareStatement(sql);
											pstmt.setString(1,orderRef);
											rs = pstmt.executeQuery();
											while(rs.next())
											{	
												cnt = rs.getInt(1);
											}
											if(cnt == 0)
											{
												errCode = "VTSRV";
											}
							   
										}

									} 
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
							}   
               
							else if(childNodeName.equalsIgnoreCase("bill_date"))
							{ 
								billNo = genericUtility.getColumnValue("bill_no", dom); 
								siteCode = genericUtility.getColumnValue("site_code", dom);
								if(billNo!= null && (billNo.trim().length() > 0 ))
								{
									billDate = genericUtility.getColumnValue("bill_date", dom);
									sundryType = genericUtility.getColumnValue("sundry_type", dom);
									sundryCode = genericUtility.getColumnValue("sundry_code", dom);
									tranId = genericUtility.getColumnValue("tran_id", dom);
									if(tranId == null)
									{
										tranId = "";					   
									}
									if(billDate != null && billDate.trim().length() > 0)
									{   
										sql = "SELECT COUNT(*) FROM voucher WHERE supp_code = ? and bill_no = ? and bill_date = ? and tran_id != ?";
										pstmt =  conn.prepareStatement(sql);
										pstmt.setString(1,sundryCode);
										pstmt.setString(2,billNo);
										pstmt.setTimestamp(3,Timestamp.valueOf(dbDateFormat.format(simpleDateFormat.parse(billDate)).toString()+ " 00:00:00.0"));
										pstmt.setString(4,tranId);
										rs = pstmt.executeQuery();
										if(rs.next())
										{
											cnt =  rs.getInt(1);
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}
									else
									{
										sql = "SELECT COUNT(*) FROM voucher WHERE supp_code = ? and bill_no = ? and tran_id != ?";
										pstmt =  conn.prepareStatement(sql);
										pstmt.setString(1,sundryCode);
										pstmt.setString(2,billNo);
										pstmt.setString(3,tranId);
										rs = pstmt.executeQuery();
										if(rs.next())
										{
											cnt =  rs.getInt(1);
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}
								}
								if(cnt == 0)
								{
									if(billDate != null && billDate.trim().length() > 0)
									{
										sql = "SELECT COUNT(*) FROM misc_voucher WHERE sundry_code = ? and bill_no = ? and bill_date = ? and sundry_type = ? and tran_id != ?";
										pstmt =  conn.prepareStatement(sql);
										pstmt.setString(1,sundryCode);
										pstmt.setString(2,billNo);
										pstmt.setTimestamp(3,Timestamp.valueOf(dbDateFormat.format(simpleDateFormat.parse(billDate)).toString()+ " 00:00:00.0"));
										pstmt.setString(4,sundryType);
										pstmt.setString(5,tranId);
										rs = pstmt.executeQuery();
										if(rs.next())
										{
										cnt =  rs.getInt(1);
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}
									else
									{
										sql = "SELECT COUNT(*) FROM misc_voucher WHERE sundry_code = ? and bill_no = ? and sundry_type = ? and tran_id != ?";
										pstmt =  conn.prepareStatement(sql);
										pstmt.setString(1,sundryCode);
										pstmt.setString(2,billNo);
										pstmt.setString(3,sundryType);
										pstmt.setString(4,tranId);
										rs = pstmt.executeQuery();
										if(rs.next())
										{
											cnt =  rs.getInt(1);
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}	 
									if(cnt == 0)
									{
										if(billDate != null && billDate.trim().length() > 0)
										{
											sql = "SELECT COUNT(1) FROM misc_vouchdet WHERE bill_no = ? and bill_date = ? and sundry_code__for = ? and sundry_type__for= ? and tran_id != ?";
											pstmt =  conn.prepareStatement(sql);
											pstmt.setString(1,billNo);
											pstmt.setTimestamp(2,Timestamp.valueOf(dbDateFormat.format(simpleDateFormat.parse(billDate)).toString()+ " 00:00:00.0"));
											pstmt.setString(3,sundryCode);
											pstmt.setString(4,sundryType);
											pstmt.setString(5,tranId);
											rs = pstmt.executeQuery();
											if(rs.next())
											{
												cnt =  rs.getInt(1);
											}
											rs.close();
											rs = null;
											pstmt.close();
											pstmt = null;
										}
										else
									    {
											sql = "SELECT COUNT(1) FROM misc_vouchdet WHERE bill_no = ? and sundry_code__for = ? and sundry_type__for= ? and tran_id != ?";
											pstmt =  conn.prepareStatement(sql);
											pstmt.setString(1,billNo);
											pstmt.setString(2,sundryCode);
											pstmt.setString(3,sundryType);
											pstmt.setString(4,tranId);
											rs = pstmt.executeQuery();
											if(rs.next())
											{
												cnt =  rs.getInt(1);
											}
											rs.close();
											rs = null;
											pstmt.close();
											pstmt = null;
										}
									}
								}
								if(cnt != 0)
								{
									errCode = "VTBILL1";
								}
								else
								{
								    if(billDate != null && billDate.trim().length() > 0)
									{
										sql = "SELECT COUNT(*) FROM porcp WHERE supp_code = ? and invoice_no = ? and invoice_date= ? ";
										pstmt =  conn.prepareStatement(sql);
										pstmt.setString(1,sundryCode);
										pstmt.setString(2,billNo);
										pstmt.setTimestamp(3,Timestamp.valueOf(dbDateFormat.format(simpleDateFormat.parse(billDate)).toString()+ " 00:00:00.0"));
										rs = pstmt.executeQuery();
										if(rs.next())
										{
											cnt =  rs.getInt(1);
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}
								}
								if(cnt != 0)
							    {
									errCode = "VTBILL1";
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
							} 

							else if(childNodeName.equalsIgnoreCase("proj_code"))
							{     
								projectCode = genericUtility.getColumnValue("proj_code", dom); 
								if(projectCode!= null && (projectCode.trim().length() > 0 ))
								{
									sql = "SELECT COUNT(*) FROM PROJECT WHERE PROJ_CODE = ?";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,projectCode);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
										if(cnt == 0) 
										{
											errCode = "VMPROJ1";
											errList.add(errCode);
											errFields.add(childNodeName.toLowerCase());
										}									
									}
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
							}

							else if(childNodeName.equalsIgnoreCase( "curr_code"))
							{
								if(childNode.getFirstChild() != null)
								{
									currCode =genericUtility.getColumnValue("curr_code", dom); 
									if(currCode== null || (currCode.trim().length() == 0))
									{
										errCode = "VECUR2";
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
									sql = "SELECT COUNT(*) FROM CURRENCY WHERE CURR_CODE = ?";
									System.out.println("sql [" + sql + "]");
									System.out.println("columnValue [" + currCode + "]");
									pstmt = conn.prepareStatement(sql);
									pstmt.setString(1,currCode);
									rs = pstmt.executeQuery();
									while(rs.next())
									{	
										cnt = rs.getInt(1);
									}
									if(cnt == 0)
								    {
										errCode = "VMCUR1";
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
								    }
									if(pstmt != null)
									{
										pstmt.close();
									}
								}
							}
                           
							else if(childNodeName.equalsIgnoreCase("acct_code__ap"))
							{ 
								acctCodeAp = genericUtility.getColumnValue("acct_code__ap", dom);
								siteCode = genericUtility.getColumnValue("site_code", dom); 
								sundryCode = genericUtility.getColumnValue("sundry_code", dom);
								sundryType = genericUtility.getColumnValue("sundry_type", dom);
								if(acctCodeAp != null && siteCode != null && acctCodeAp.trim().length() > 0 && siteCode.trim().length() >0)
								{
									errCode = finCommon.isAcctCode(siteCode, acctCodeAp, "", conn);
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
								if(errCode == null || (errCode.trim().length() == 0))
								{
									if(acctCodeAp != null && sundryCode != null && sundryType != null && acctCodeAp.trim().length() > 0 && sundryCode.trim().length() > 0 && sundryType.trim().length() > 0)
									{
										errCode = finCommon.isAcctType(acctCodeAp, sundryCode, sundryType, conn);
									}
									if(errCode != null && (errCode.trim().length() > 0))
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
								}
							} 
             
							else if(childNodeName.equalsIgnoreCase("acct_code__pay"))
							{ 
								acctCodePay = genericUtility.getColumnValue("acct_code__pay", dom); 
								siteCode = genericUtility.getColumnValue("site_code", dom);
								if(siteCode != null && acctCodePay != null && siteCode.trim().length() > 0 && acctCodePay.trim().length() > 0)
								{
									errCode = finCommon.isAcctCode(siteCode, acctCodePay, "", conn);
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
								sundryCodePay = genericUtility.getColumnValue("sundry_code__pay", dom);
								sundryTypePay = genericUtility.getColumnValue("sundry_type__pay", dom);
								if(errCode == null || (errCode.trim().length()== 0))
								{
									if(acctCodePay != null && sundryCodePay != null && sundryTypePay != null && acctCodePay.trim().length() > 0 && sundryTypePay.trim().length() > 0 && sundryCodePay.trim().length() > 0)
									{
										errCode = finCommon.isAcctType(acctCodePay, sundryCodePay, sundryTypePay, conn);
									}
									if(errCode != null && (errCode.trim().length() > 0))
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
								}
							}  

							else if(childNodeName.equalsIgnoreCase("cctr_code__ap"))
							{ 
								cctrCodeAp = genericUtility.getColumnValue("cctr_code__ap", dom); 
								acctCodeAp = genericUtility.getColumnValue("acct_code__ap", dom);
								if(acctCodeAp != null && cctrCodeAp != null && acctCodeAp.trim().length() > 0 && cctrCodeAp.trim().length() > 0)
								{
									errCode = finCommon.isCctrCode(acctCodeAp, cctrCodeAp, "", conn);
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
							}  

						   else if(childNodeName.equalsIgnoreCase("acct_code__cf"))
							{ 
								acctCodeCf = genericUtility.getColumnValue("acct_code__cf", dom); 
								siteCode = genericUtility.getColumnValue("site_code", dom);
								if(siteCode != null && acctCodeCf!= null && siteCode.trim().length() > 0 && acctCodeCf.trim().length() > 0 )
								{
									errCode = finCommon.isAcctCode(siteCode, acctCodeCf, "", conn);
									if(errCode != null && (errCode.trim().length() > 0))
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
								}
								sundryCodePay = "";
								sundryTypePay = "O";
								if(errCode == null || (errCode.trim().length() == 0))
								{
									if(acctCodeCf != null && sundryCodePay != null && sundryTypePay != null && acctCodeCf.trim().length() > 0 && sundryCodePay.trim().length() > 0 && sundryTypePay.trim().length() > 0)
									{
										errCode = finCommon.isAcctType(acctCodeCf, sundryCodePay, sundryTypePay, conn);
									}
									if(errCode != null && (errCode.trim().length() > 0))
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
								}
							} 

							else if(childNodeName.equalsIgnoreCase("cctr_code__cf"))
							{ 
								cctrCodeCf = genericUtility.getColumnValue("cctr_code__cf", dom); 
								acctCodeCf = genericUtility.getColumnValue("acct_code__cf", dom);
								if(acctCodeCf!= null && (acctCodeCf.trim().length() > 0 ))
								{
									if(acctCodeCf != null && cctrCodeCf != null && acctCodeCf.trim().length() > 0 && cctrCodeCf.trim().length() > 0)
									{
										errCode = finCommon.isCctrCode(acctCodeCf, cctrCodeCf, "", conn);
									}
									if(errCode != null && (errCode.trim().length() > 0))
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
								}
							}  

							else if(childNodeName.equalsIgnoreCase("acct_code__adv"))
							{ 
								vouchType = genericUtility.getColumnValue("vouch_type", dom);
								if(vouchType != null && "A".equalsIgnoreCase(vouchType))
								{
									acctCodeAdv = genericUtility.getColumnValue("acct_code__adv", dom);
									siteCode = genericUtility.getColumnValue("site_code", dom);
									if(acctCodeAdv != null && siteCode != null && acctCodeAdv.trim().length() > 0 && siteCode.trim().length() > 0) 
									{
										errCode = finCommon.isAcctCode(siteCode, acctCodeAdv, "", conn); //added if condition extra by Dipak
									}
									if(errCode != null && (errCode.trim().length() > 0))
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
									sundryCode = genericUtility.getColumnValue("sundry_code", dom);
									sundryType = genericUtility.getColumnValue("sundry_type", dom);
									if(errCode == null || (errCode.trim().length() == 0))
									{
										if(acctCodeAdv != null && sundryCode != null && sundryType != null && acctCodeAdv.trim().length() > 0 && sundryCode.trim().length() > 0 && sundryType.trim().length() > 0) //added if condition extra by Dipak
										{
											errCode = finCommon.isAcctType(acctCodeAdv, sundryCode, sundryType, conn);
										}
										if(errCode != null && (errCode.trim().length() > 0))
										{
											errList.add(errCode);
											errFields.add(childNodeName.toLowerCase());
										}
									}
								}
							}  

							else if(childNodeName.equalsIgnoreCase("cctr_code__adv"))
							{ 
								vouchType = genericUtility.getColumnValue("vouch_type", dom);
								if(vouchType != null && "A".equalsIgnoreCase(vouchType))
								{
									cctrCodeAdv = genericUtility.getColumnValue("cctr_code__adv", dom);
									acctCodeAdv = genericUtility.getColumnValue("acct_code__adv", dom);
									if(acctCodeAdv != null && cctrCodeAdv != null && acctCodeAdv.trim().length() > 0 && cctrCodeAdv.trim().length() > 0)
									{
										errCode = finCommon.isCctrCode(acctCodeAdv, cctrCodeAdv, "", conn);
									}
									if(errCode != null && (errCode.trim().length() > 0))
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
								}
							} 
						   
							else if(childNodeName.equalsIgnoreCase("site_code"))
							{ 
								siteCode = genericUtility.getColumnValue("site_code", dom);
								if(siteCode == null || (siteCode.length() == 0))
								{
									errList.add("VMSITECOD");
									errFields.add(childNodeName.toLowerCase());
								}
								if(siteCode != null && (siteCode.trim().length() > 0))
								{
									sql = " select count(*) from site where site_code = ? ";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,siteCode);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
										if(cnt == 0) 
										{
											errCode = "VMSITE1";
											errList.add(errCode);
											errFields.add(childNodeName.toLowerCase());	
										}									
									}
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
								if(errCode == null || (errCode.trim().length() == 0))
								{
									tranDate = genericUtility.getColumnValue("tran_date", dom);
									try
									{
										tranPdate = simpleDateFormat.parse(tranDate);
										errCode = validator.nfCheckPeriod("FIN",new java.util.Date(tranPdate.getTime()),siteCode);
									}
									catch (ParseException e)
									{
										System.out.println("Exception in transaction date [tran_date_validation]"+e);
										e.printStackTrace();
										throw new ITMException(e);
									}
									if(errCode != null && errCode.trim().length() > 0)
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase()); 
									}
								}
							}  

							else if(childNodeName.equalsIgnoreCase("site_code__for"))
							{ 
								siteCodeFor = genericUtility.getColumnValue("site_code__for", dom);
								if(siteCodeFor == null || (siteCodeFor.length() == 0))
								{
									errList.add("VMSITECOD");
									errFields.add(childNodeName.toLowerCase());
								}
								if(siteCodeFor != null && (siteCodeFor.trim().length() > 0))
								{
									sql = " select count(*) from site where site_code = ? ";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,siteCodeFor);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
										if(cnt == 0) 
										{
											errCode = "VMSITE1";
											errList.add(errCode);
											errFields.add(childNodeName.toLowerCase());	
										}									
									}
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
								if(errCode == null || (errCode.trim().length() == 0))
								{
									tranDate = genericUtility.getColumnValue("tran_date", dom);
									try
									{
										tranPdate = simpleDateFormat.parse(tranDate);
										errCode = validator.nfCheckPeriod("FIN",new java.util.Date(tranPdate.getTime()),siteCodeFor);
									}
									catch (ParseException e)
									{
										System.out.println("Exception in transaction date [tran_date_validation]"+e);
										e.printStackTrace();
										throw new ITMException(e);
									}
									if(errCode != null && errCode.trim().length() > 0)
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase()); 
									}
								}
							}  

							else if(childNodeName.equalsIgnoreCase("fin_entity"))
							{ 
								finEntity = genericUtility.getColumnValue("fin_entity", dom); 
								if(finEntity != null && (finEntity.trim().length() > 0))
								{
									sql = "SELECT COUNT(*) FROM FINENT WHERE FIN_ENTITY = ?";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,finEntity);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
										if(cnt == 0) 
										{
											errCode = "VMFENTY1";
											errList.add(errCode);
											errFields.add(childNodeName.toLowerCase());   
										}									
									}
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
							}  
                            
							else if(childNodeName.equalsIgnoreCase("tax_class"))
							{
								taxClass = genericUtility.getColumnValue("tax_class", dom);
								if(taxClass!= null && (taxClass.trim().length() > 0 ))
								{
									sql = "SELECT COUNT(*) FROM taxclass WHERE tax_class = ? ";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,taxClass);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
									}
									if(cnt == 0) 
									{
										errCode = "VMTACLA1";
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}		
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
							}
                           
						   else if(childNodeName.equalsIgnoreCase("tax_chap"))
						   { 
								taxChap = genericUtility.getColumnValue("tax_chap", dom);
								if(taxChap!= null && (taxChap.trim().length() > 0 ))
								{
									sql = "SELECT COUNT(*) FROM taxchap WHERE tax_chap = ? ";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,taxChap);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
									}
									if(cnt == 0) 
									{
										errCode = "VMTACHA1";
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}		
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
							} 

							else if(childNodeName.equalsIgnoreCase("tax_env"))
							{ 
								taxEnv = genericUtility.getColumnValue("tax_env", dom);
								if(taxEnv!= null && (taxEnv.trim().length() > 0 ))
								{
									sql = "SELECT COUNT(*) FROM taxenv WHERE tax_env = ? ";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,taxEnv);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
									}
									if(cnt == 0) 
									{
										errCode = "VMTAENV1";
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}		
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
							} 

							else if(childNodeName.equalsIgnoreCase("bank_code"))
							{ 
								bankCode = genericUtility.getColumnValue("bank_code", dom);
								autoPay = genericUtility.getColumnValue("auto_pay", dom);
								siteCode = genericUtility.getColumnValue("site_code", dom);
								if(autoPay!= null && (autoPay.trim().length() > 0 ) && "Y".equalsIgnoreCase(autoPay))
								{
									errCode = validator.isBankCode(siteCode,bankCode,"");
									if(errCode != null && (errCode.trim().length() > 0))
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
								}
							} 

							else if(childNodeName.equalsIgnoreCase("adv_amt"))
							{ 
								advAmt = Double.parseDouble (genericUtility.getColumnValue("adv_amt", dom));
								sundryType = genericUtility.getColumnValue("sundry_type", dom);
								sundryTypePay = genericUtility.getColumnValue("sundry_type__pay", dom);
								vouchType = genericUtility.getColumnValue("vouch_type", dom);
								if(advAmt!= 0 && (sundryType == "O" || sundryTypePay == "O"))
								{
									errCode = "VTADV1";
								}
								else if("A".equalsIgnoreCase(vouchType) && (advAmt < 0))
								{
									errCode = "VTADV2";
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
							} 

							else if(childNodeName.equalsIgnoreCase("cr_term"))
							{ 
								crTerm = genericUtility.getColumnValue("cr_term", dom);
								if(crTerm == null || (crTerm.trim().length() == 0))
								{
									errCode = "VECRT2";
								}
								else
								{
									sql = "SELECT COUNT(*) FROM crterm WHERE cr_term = ? ";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,crTerm);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
									}
									if(cnt == 0) 
									{
										errCode = "VMCRTER1";
									}		
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
							}
						}
						break;
                   
				case 2 : 
						parentNodeList = dom1.getElementsByTagName("Detail1");
						parentNode = parentNodeList.item(0);
						parentNodeList = dom.getElementsByTagName("Detail2");
						parentNode = parentNodeList.item(0);
						childNodeList = parentNode.getChildNodes();
						childNodeListLength = childNodeList.getLength();
						for(ctr = 0; ctr < childNodeListLength; ctr ++)
						{
							childNode = childNodeList.item(ctr);
							childNodeName = childNode.getNodeName();
							if(childNodeName.equalsIgnoreCase("ref_ser"))
							{ 
								refSer = genericUtility.getColumnValue("ref_ser", dom); 
								if((refSer != null) && (!("M-ADV".equalsIgnoreCase(refSer))) && (!("P-ADV".equalsIgnoreCase(refSer)) ) && (refSer.trim().length() > 0))
								{  
									errCode = "VTREFSER3";
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
							}  

							else if(childNodeName.equalsIgnoreCase("ref_no"))
							{ 
								refNo = genericUtility.getColumnValue("ref_no", dom);
								refSer = genericUtility.getColumnValue("ref_ser", dom);
								sundryType = genericUtility.getColumnValue("sundry_type", dom1);
								sundryCode = genericUtility.getColumnValue("sundry_code", dom1);
								siteCode = genericUtility.getColumnValue("site_code", dom1);
								currCode = genericUtility.getColumnValue("curr_code", dom1);
								if(refNo != null && (refNo.trim().length() > 0 ))
								{
									sql = "SELECT sundry_type, sundry_code, site_code, curr_code FROM misc_payables WHERE tran_ser = ? and ref_no = ? ";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,refSer);
									pstmt.setString(2,refNo);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										sundryType1 = rs.getString(1);
										sundryCode1 = rs.getString(2);
										siteCode1 = rs.getString(3);
										currCode1 = rs.getString(4);
									}
									if( (sundryType1 !=null &&  sundryType !=null) && (sundryType.trim().length() > 0) && (sundryType1.trim().length() > 0) && (sundryType1.trim() != sundryType.trim())) 
									{
										errCode = "VTMPAY2";
									}	
									else if( (sundryCode1 !=null &&  sundryCode !=null) && (sundryCode.trim().length() > 0) && (sundryCode1.trim().length() > 0) && (sundryCode1.trim() != sundryCode.trim())) 
									{
										errCode = "VTMPAY1";
									}	
									else if( (siteCode1 !=null) &&  (siteCode !=null) && (siteCode.trim().length() > 0) && (siteCode1.trim().length() > 0) && (siteCode1.trim() != siteCode.trim())) 
									{
										errCode = "VTMPAYSITE";
									}	
									else if( (currCode1 !=null &&  currCode !=null) && (currCode.trim().length() > 0) && (currCode1.trim().length() > 0) && (currCode1.trim() != currCode.trim())) 
									{
										errCode = "VTMPAYCURR";
									}	
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
							}  

							else if(childNodeName.equalsIgnoreCase("adj_amt"))
							{ 
								adjAmt = Double.parseDouble (genericUtility.getColumnValue("adj_amt", dom)); 
								refSer = genericUtility.getColumnValue("ref_ser", dom);
								refNo = genericUtility.getColumnValue("ref_no", dom);
								sql = "SELECT tot_amt, adj_amt, hold_amt FROM misc_payables WHERE tran_ser = ? and ref_no = ?";
								pstmt =  conn.prepareStatement(sql);
								pstmt.setString(1,refSer);
								pstmt.setString(2,refNo);
								rs = pstmt.executeQuery();
								if(rs.next())
								{
									totAmt =  rs.getDouble(1);
									adjAmt1 =  rs.getDouble(2);
									holdAmt =  rs.getDouble(3);
									Amount = totAmt - adjAmt1;
								}
								rs.close();
								rs = null;
								pstmt.close();
								pstmt = null;	
								if((Amount < 0 && adjAmt < 0 && Amount < adjAmt) || (Amount > 0 && adjAmt > 0 && Amount < adjAmt) || (Amount < 0 && adjAmt > 0) || (Amount > 0 && adjAmt < 0))
								{
									errCode = "VTMPAY4";
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}	   
							}  

							else if(childNodeName.equalsIgnoreCase("curr_code"))
						    { 
								currCodeEdit = genericUtility.getColumnValue("curr_code", dom1); 
								currCode = genericUtility.getColumnValue("curr_code", dom); 
								if((currCodeEdit != null) && (currCode !=null) && (currCodeEdit.trim().length() > 0) && (currCode.trim().length() > 0) && (currCodeEdit.trim() != currCode.trim()))
								{   
									errCode = "VTMPAYCURR";
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
							} 
						}
						break;
            
				case 3 : 
						parentNodeList = dom1.getElementsByTagName("Detail1");
						parentNode = parentNodeList.item(0);
						parentNodeList = dom2.getElementsByTagName("Detail2");
						parentNode = parentNodeList.item(0);
						parentNodeList = dom.getElementsByTagName("Detail3");
						parentNode = parentNodeList.item(0);
						childNodeList = parentNode.getChildNodes();
						childNodeListLength = childNodeList.getLength();
						for(ctr = 0; ctr < childNodeListLength; ctr ++)
						{
							childNode = childNodeList.item(ctr);
							childNodeName = childNode.getNodeName();
							if(childNodeName.equalsIgnoreCase("acct_code"))
							{ 
								acctCode = genericUtility.getColumnValue("acct_code", dom); 
								vouchType = genericUtility.getColumnValue("vouch_type", dom1);
								acctCodeAdv = genericUtility.getColumnValue("acct_code__adv", dom1);
								siteCode = genericUtility.getColumnValue("site_code", dom1);
								if(acctCode == null || (acctCode.trim().length() == 0 ))
								{
									errCode = "VMACCTCD1";
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
								if("A".equalsIgnoreCase(vouchType))
								{	
									if(acctCode != acctCodeAdv && saveflag == "2")
									{
										errCode = "VTVACCT";
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
								} 
								else
								{
									if(acctCode != null && siteCode != null && acctCode.trim().length() > 0 && siteCode.trim().length() > 0)
									{
										errCode = finCommon.isAcctCode(siteCode, acctCode, "", conn);
									}
									if(errCode != null && (errCode.trim().length() > 0))
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
									if(errCode == null || (errCode.trim().length() == 0))
									{
										sundryCode = "";
										sundryType = "O";
										if(acctCode != null && sundryCode != null && sundryType != null && acctCode.trim().length() > 0 && sundryCode.trim().length() > 0 && sundryType.trim().length() > 0)
										{
											errCode = finCommon.isAcctType(acctCode, sundryCode, sundryType, conn);
										}
										if(errCode != null && (errCode.trim().length() > 0))
										{
											errList.add(errCode);
											errFields.add(childNodeName.toLowerCase());
										}
									}
								}
							}

							else if(childNodeName.equalsIgnoreCase("cctr_code"))
							{ 
								acctCode = genericUtility.getColumnValue("acct_code", dom2); 
								cctrCode = genericUtility.getColumnValue("cctr_code", dom2); 
								vouchType = genericUtility.getColumnValue("vouch_type", dom1); 
								cctrCodeAdv = genericUtility.getColumnValue("cctr_code__adv", dom1); 
								if("A".equalsIgnoreCase(vouchType))
								{
									if(cctrCode != cctrCodeAdv && saveflag == "2")
									{
										errCode = "VTVACCT";
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
								}
								else
								{
									if(acctCode != null && cctrCode != null && acctCode.trim().length() > 0 && cctrCode.trim().length() > 0)
									{
										errCode = finCommon.isCctrCode(acctCode, cctrCode, "", conn);
									}
									if(errCode != null && (errCode.trim().length() > 0))
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}
								}
							} 

							else if(childNodeName.equalsIgnoreCase("dept_code"))
							{ 
								deptCode = genericUtility.getColumnValue("dept_code", dom2); 
								acctCode = genericUtility.getColumnValue("acct_code", dom2); 
								if(deptCode != null && (deptCode.trim().length() > 0 ))
								{
									sql1 = "SELECT COUNT(1) FROM department WHERE dept_code = ?";
									pstmt =  conn.prepareStatement(sql1);
									pstmt.setString(1,deptCode);
									rs = pstmt.executeQuery();
									if (rs.next())
									{
										cnt = rs.getInt(1);
									}
									if (cnt == 0 )
									{
										errCode = "VMDEPT1";
									}
									else
									{
										sql2 = "SELECT VAR_VALUE FROM FINPARM WHERE PRD_CODE = ? AND VAR_NAME = ?";
										pstmt =  conn.prepareStatement(sql2);
										pstmt.setString(1,"999999");
										pstmt.setString (2, "ACCT_SPECIFIC_DEPT");
										rs = pstmt.executeQuery();
										if (rs.next())
										{
											acctSpec = rs.getString(1);
										}
										if(acctSpec != null && "Y".equalsIgnoreCase(acctSpec.trim().toUpperCase()))
										{
											sql3 = "SELECT COUNT(1) FROM accounts_dept WHERE acct_code = ?" + "AND dept_code = ?";
											pstmt =  conn.prepareStatement(sql3);
											pstmt.setString(1,acctCode);
											pstmt.setString(2,deptCode);
											rs = pstmt.executeQuery();
											if (rs.next())
											{
												cnt = rs.getInt(1);
											}
											if (cnt == 0 )
											{
												sql4 = "SELECT COUNT(1) FROM accounts_dept WHERE acct_code = ?";
												pstmt =  conn.prepareStatement(sql4);
												pstmt.setString(1,acctCode);
												rs = pstmt.executeQuery();
												if (rs.next())
												{
													cnt = rs.getInt(1);
												}
												if(cnt == 0)
												{
													if(deptCode != null && deptCode.trim().length() > 0)
													{
														errCode = "VMDEPT2";
													}
												}
												else if(cnt > 0)
												{
													errCode = "VMDEPT2";
												}
											}
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}
									if(errCode != null && (errCode.trim().length() > 0))
									{
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}								 
								}
							}	 

							else if(childNodeName.equalsIgnoreCase("emp_code"))
							{ 
								empCode = genericUtility.getColumnValue("emp_code", dom2); 
								siteCode = genericUtility.getColumnValue("site_code", dom1); 
								refSer = genericUtility.getColumnValue("ref_ser", dom1);
								if(empCode != null && (empCode.trim().length() > 0 ))
								{
									errCode = finCommon.isEmployee(siteCode, empCode, refSer, conn);
								}	
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
								
							} 

							else if(childNodeName.equalsIgnoreCase("anal_code"))
							{ 
								analCode = genericUtility.getColumnValue("anal_code", dom2); 
								acctCode = genericUtility.getColumnValue("acct_code", dom2); 
								cctrCode = genericUtility.getColumnValue("cctr_code", dom2);
								refSer = genericUtility.getColumnValue("ref_ser", dom1);
								if(acctCode != null && analCode != null && refSer != null && acctCode.trim().length() > 0 && analCode.trim().length() > 0 && refSer.trim().length() > 0)
								{
									errCode = finCommon.isAnalysis(acctCode, analCode, refSer, conn);
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
								if(errCode == null || (errCode.trim().length() == 0 ))
								{
									sql = "SELECT COUNT(*) FROM cctr_anal WHERE cctr_code = ? and anal_code = ?";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,cctrCode);
									pstmt.setString(2,analCode);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
										if(cnt == 0) 
										{
											sql = " select count(*) from cctr_anal where cctr_code = ? ";
											pstmt =  conn.prepareStatement(sql);
											pstmt.setString(1,cctrCode);
											rs = pstmt.executeQuery();
											if(rs.next())
											{
												cnt =  rs.getInt(1);
												if(cnt > 0) 
												{
													errCode = "VMANAL4";
													errList.add(errCode);
													errFields.add(childNodeName.toLowerCase());	
												}
												else
												{
													errCode = "VMANAL3";
													errList.add(errCode);
													errFields.add(childNodeName.toLowerCase());	
												}
											}									
										}
									}									
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
							} 

							else if(childNodeName.equalsIgnoreCase("anal_code__1"))
							{ 
								analCode1 = genericUtility.getColumnValue("anal_code__1", dom2); 
								acctCode = genericUtility.getColumnValue("acct_code", dom2); 
								cctrCode = genericUtility.getColumnValue("cctr_code", dom2);
								refSer = genericUtility.getColumnValue("ref_ser", dom1);
								if(acctCode != null && analCode1 != null && refSer != null && acctCode.trim().length() > 0 && analCode1.trim().length() > 0 && refSer.trim().length() > 0)
								{
									errCode = finCommon.isAnalysis(acctCode, analCode1, refSer, conn);
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
								if(errCode == null || (errCode.trim().length() == 0 ))
								{
									sql = "SELECT COUNT(*) FROM cctr_anal WHERE cctr_code = ? and anal_code = ?";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,cctrCode);
									pstmt.setString(2,analCode1);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
										if(cnt == 0) 
										{
											sql = " select count(*) from cctr_anal where cctr_code = ? ";
											pstmt =  conn.prepareStatement(sql);
											pstmt.setString(1,cctrCode);
											rs = pstmt.executeQuery();
											if(rs.next())
											{
												cnt =  rs.getInt(1);
												if(cnt > 0) 
												{
													errCode = "VMANAL4";
													errList.add(errCode);
													errFields.add(childNodeName.toLowerCase());	
												}
												else
												{
													errCode = "VMANAL3";
													errList.add(errCode);
													errFields.add(childNodeName.toLowerCase());	
												}
											}									
										}
									}									
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
							} 

							else if(childNodeName.equalsIgnoreCase("anal_code__2"))
							{ 
								analCode2 = genericUtility.getColumnValue("anal_code__2", dom2); 
								acctCode = genericUtility.getColumnValue("acct_code", dom2); 
								cctrCode = genericUtility.getColumnValue("cctr_code", dom2);
								refSer = genericUtility.getColumnValue("ref_ser", dom1);
								if(acctCode != null && analCode2 != null && refSer != null && acctCode.trim().length() > 0 && analCode2.trim().length() > 0 && refSer.trim().length() > 0)
								{
									errCode = finCommon.isAnalysis(acctCode, analCode2, refSer, conn);
								}
								if(errCode != null && (errCode.trim().length() > 0))
								{
									errList.add(errCode);
									errFields.add(childNodeName.toLowerCase());
								}
								if(errCode == null || (errCode.trim().length() == 0 ))
								{
									sql = "SELECT COUNT(*) FROM cctr_anal WHERE cctr_code = ? and anal_code = ?";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,cctrCode);
									pstmt.setString(2,analCode2);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
										if(cnt == 0) 
										{
											sql = " select count(*) from cctr_anal where cctr_code = ? ";
											pstmt =  conn.prepareStatement(sql);
											pstmt.setString(1,cctrCode);
											rs = pstmt.executeQuery();
											if(rs.next())
											{
												cnt =  rs.getInt(1);
												if(cnt > 0) 
												{
													errCode = "VMANAL4";
													errList.add(errCode);
													errFields.add(childNodeName.toLowerCase());	
												}
												else
												{
													errCode = "VMANAL3";
													errList.add(errCode);
													errFields.add(childNodeName.toLowerCase());	
												}
											}									
										}
									}									
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
							} 

							else if(childNodeName.equalsIgnoreCase("bill_date"))
							{ 
								billNo = genericUtility.getColumnValue("bill_no", dom2); 
								siteCode = genericUtility.getColumnValue("site_code", dom2);
								if(billNo!= null && (billNo.trim().length() > 0 ))
								{
									billDate = genericUtility.getColumnValue("bill_date", dom2);
									sundryTypeFor = genericUtility.getColumnValue("sundry_type__for", dom2);
									sundryCodeFor = genericUtility.getColumnValue("sundry_code__for", dom2);
									tranId = genericUtility.getColumnValue("tran_id", dom2);
									lineNo = genericUtility.getColumnValue("line_no", dom2);
									if(tranId == null)
									{
										tranId = "";					   
									}
									if(billDate != null && billDate.trim().length() > 0)
									{
										sql = "SELECT COUNT(*) FROM misc_vouchdet WHERE bill_no = ? and sundry_type__for = ? and sundry_code__for = ? and bill_date = ? and line_no != ?";
										pstmt =  conn.prepareStatement(sql);
										pstmt.setString(1,billNo);
										pstmt.setString(2,sundryTypeFor);
										pstmt.setString(3,sundryCodeFor);
										pstmt.setTimestamp(4,Timestamp.valueOf(dbDateFormat.format(simpleDateFormat.parse(billDate)).toString()+ " 00:00:00.0"));
										pstmt.setString(5,lineNo);
										rs = pstmt.executeQuery();
										if(rs.next())
										{
											cnt =  rs.getInt(1);
										}
										if(cnt > 0) 
										{
											errCode = "VTBILL1";
											errList.add(errCode);
											errFields.add(childNodeName.toLowerCase());	
											break;
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}	
									if(billDate != null && billDate.trim().length() > 0)
									{
										sql = "SELECT COUNT(*) FROM misc_vouchdet WHERE bill_no = ? and bill_date = ? and sundry_code__for = ? and sundry_type__for= ? and tran_id != ?";
										pstmt =  conn.prepareStatement(sql);
										pstmt.setString(1,billNo);
										pstmt.setTimestamp(2,Timestamp.valueOf(dbDateFormat.format(simpleDateFormat.parse(billDate)).toString()+ " 00:00:00.0"));
										pstmt.setString(3,sundryCodeFor);
										pstmt.setString(4,sundryTypeFor);
										pstmt.setString(5,tranId);
										rs = pstmt.executeQuery();
										if(rs.next())
										{
											cnt =  rs.getInt(1);
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}
									else
									{
										sql = "SELECT COUNT(*) FROM misc_vouchdet WHERE bill_no = ? and sundry_code__for = ? and sundry_type__for = ? and tran_id != ?";
										pstmt =  conn.prepareStatement(sql);
										pstmt.setString(1,billNo);
										pstmt.setString(2,sundryCodeFor);
										pstmt.setString(3,sundryTypeFor);
										pstmt.setString(4,tranId);
										rs = pstmt.executeQuery();
										if(rs.next())
										{
											cnt =  rs.getInt(1);
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}
								}
								if(cnt == 0)
								{
									if(billDate != null && billDate.trim().length() > 0)
									{
										sql = "SELECT COUNT(1) FROM misc_voucher WHERE sundry_code = ? and bill_no = ? and bill_date = ? and tran_id != ?";
										pstmt =  conn.prepareStatement(sql);
										pstmt.setString(1,sundryCode);
										pstmt.setString(2,billNo);
										pstmt.setTimestamp(3,Timestamp.valueOf(dbDateFormat.format(simpleDateFormat.parse(billDate)).toString()+ " 00:00:00.0"));
										pstmt.setString(4,tranId);
										rs = pstmt.executeQuery();
										if(rs.next())
										{
											cnt =  rs.getInt(1);
										}	
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}
									else
									{
										sql = "SELECT COUNT(1) FROM misc_voucher WHERE sundry_code = ? and bill_no = ? and sundry_type = ? and tran_id != ?";
										pstmt =  conn.prepareStatement(sql);
										pstmt.setString(1,sundryCode);
										pstmt.setString(2,billNo);
										pstmt.setString(3,sundryType);
										pstmt.setString(4,tranId);
										rs = pstmt.executeQuery();
										if(rs.next())
										{
											cnt =  rs.getInt(1);
										}
										rs.close();
										rs = null;
										pstmt.close();
										pstmt = null;
									}	 
									if(cnt != 0)
									{
										errCode = "VTBILL1";
										errList.add(errCode);
										errFields.add(childNodeName.toLowerCase());
									}    
									else
									{
										if(billDate != null && billDate.trim().length() > 0)
										{
											sql = "SELECT COUNT(*) FROM porcp WHERE supp_code = ? and invoice_no = ? and invoice_date = ? ";
											pstmt =  conn.prepareStatement(sql);
											pstmt.setString(1,sundryCodeFor);
											pstmt.setString(2,billNo);
											pstmt.setTimestamp(3,Timestamp.valueOf(dbDateFormat.format(simpleDateFormat.parse(billDate)).toString()+ " 00:00:00.0"));
											rs = pstmt.executeQuery();
											if(rs.next())
											{
												cnt =  rs.getInt(1);
											}
											if(cnt != 0)
											{
												errCode = "VTBILL1";
												errList.add(errCode);
												errFields.add(childNodeName.toLowerCase());
											}	
											rs.close();
											rs = null;
											pstmt.close();
											pstmt = null;
										}
									}
								}
							}

							else if(childNodeName.equalsIgnoreCase("proj_code"))
							{     
								projectCode = genericUtility.getColumnValue("proj_code", dom2); 
								if(projectCode!= null && (projectCode.trim().length() > 0 ))
								{
									sql = "SELECT COUNT(*) FROM PROJECT WHERE PROJ_CODE = ?";
									pstmt =  conn.prepareStatement(sql);
									pstmt.setString(1,projectCode);
									rs = pstmt.executeQuery();
									if(rs.next())
									{
										cnt =  rs.getInt(1);
										if(cnt == 0) 
										{
											errCode = "VMPROJ1";
											errList.add(errCode);
											errFields.add(childNodeName.toLowerCase());
										}									
									}
									rs.close();
									rs = null;
									pstmt.close();
									pstmt = null;
								}
							}	
						}
						break;
			}//end switch
			int errListSize = errList.size();
			cnt = 0;
			String errFldName = null;
			if(errList != null && errListSize > 0)
			{
				for(cnt = 0; cnt < errListSize; cnt ++)
				{
					errCode = errList.get(cnt);
					errFldName = errFields.get(cnt);
					System.out.println("errCode .........." + errCode);
					errString = getErrorString(errFldName, errCode, userId);
					errorType =  errorType(conn , errCode);
					if(errString.length() > 0)
					{
						String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8, errString.indexOf("<trace>"));
						bifurErrString = bifurErrString;
						bifurErrString = bifurErrString + errString.substring(errString.indexOf("</trace>") + 8, errString.indexOf("</Errors>"));
						errStringXml.append(bifurErrString);
						errString = "";
					}
					if(errorType.equalsIgnoreCase("E"))
					{
						break;
					}
				}
				errList.clear();
				errList = null;
				errFields.clear();
				errFields = null;
				errStringXml.append("</Errors> </Root> \r\n");
			}
			else
			{
				errStringXml = new StringBuffer("");
			}
		}//end try
		catch(Exception e)
		{
			e.printStackTrace();
			errString = e.getMessage();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				if(conn != null)
				{
					if(rs != null) 
					{
						rs.close();
						rs = null;
					}
					if(pstmt != null) 
					{
						pstmt.close();
						pstmt = null;
						
					}
					conn.close();
				}
				conn = null;
			} 
			catch(Exception d)
			{
				d.printStackTrace();
				throw new ITMException(d);
			}
		}
		errString = errStringXml.toString();
		return errString;
	}//end of validation

	// method for item change
	public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
	{
		Document dom = null;
		Document dom1 = null;
		Document dom2 = null;
		String valueXmlString = "";
		try
		{   
			dom = parseString(xmlString);
			dom1 = parseString(xmlString1);
			if(xmlString2.trim().length() > 0 )
			{
				dom2 = parseString(xmlString2);
			}
			valueXmlString = itemChanged(dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams);
		}
		catch(Exception e)
		{
			System.out.println("Exception : [MiscVal][itemChanged( String, String )] :==>\n" + e.getMessage());
		}
        return valueXmlString;
	}

	// method for item change
	public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
	{
		StringBuffer valueXmlString = new StringBuffer();
		NodeList parentNodeList = null;
		NodeList childNodeList = null;
		Node parentNode = null;
		Node childNode = null;
		NodeList parentNodeList1 = null ; 
		Node parentNode1 = null ; 
		String childNodeName = null;
		String columnValue = null;
		String siteCode = "";
		String acctCodeBc = "";
		String billAmt1 = "";
		Double billAmt = 0.0;
		String cctrCodeBc = "";
		String acctCodeCf = "";
		String cctrCodeCf = "";
		String acctCodeCfAp = "";
		String cctrCodeCfAp = "";
		String entryBatchNo = "";
		String exchRate = "";
		String acctPrd = "";
		String grade = "";
		String crDays1 = "";
		String lcCode = "";
		String cctrDescr = "";
		String tranDate = "";
		String effDate = "";
		String taxChap = "";
		String fldName = "";
		String acctCodeAdv = "";
		String cctrCodeAdv = "";
		String flag = "";
		String mvouch = "";
		String finEntity = "";
		String vouchType = "";
		String sundryCodePay = "";
		String sundryTypePay = "";
		String sundryCode = "";
		String stanCode = "";
		String stanName = "";
		String cctrCodePay = "";
		String cctrCodeAp = "";
		String cctrCode = "";
		String acctCode = "";
		String bankCode = "";
		String acctCodeAp = "";
		String tranId = "";
		String currCode = "";
		String currCode1 = "";
		String crTerm = "";
		String quantity = "";
		String suppCode = "";
		String billDate = "";
		String deptCode = "";
		String columnName = "";
		String analCode = "";
		String analCode1 = "";
		String analCode2 = "";
		String payMode = "";
		String sundryType = "";
		String chqName = "";
		String sundryTypeFor = "";
		String sundryCodeFor = "";
		String mdescr = "";
		String custCity = "";
		String chequeOrName = "";
		String stanCodePay = "";
		String descrType = "";
		String descName = "";
		String tranMode = "";
		String mSite = "";
		String dateNow = "";
		String payRndOff = "";
		String defCrTerm = "";
		String lineNo = "";
		String billNo = "";
		String stanNamePay = "";
		String mFname = "";
		String mLname = "";
		String mName = "";
		String cnt1 = "";
		String eventId = "";
		String designation = "";
		String projCode1 = "";
		String projCode = "";
		String orderRef = "";
		String netAmt = "";
		String taxDate1 = "";
		String dueDate1 = "";
		Double advAmt = 0.0;
		String acctCodePay = "";
		String refNo = "";
		String refSer = "";
		String val = "";
		String sql = "";
		String acctName = "";
		String custCode = "";
		String empCode = "";
		String taxEnv = "";
		String taxClass = "";
		String taxedAdjAmt = "";
		String amount1 = "";
		String lcnt = "";
		String startFrom = "";
		String linecnt = "";
		String exchRate1 = "";
		String rateClg = "";
		String rate = "";
		Double amount = 0.0;
		Double taxAmt = 0.0;
		Double totAmt = 0.0;
		Double advAmount = 0.0;
		Double mAdv = 0.0;
		Double totAmount = 0.0;
		Double diff = 0.0;
		Double adv = 0.0;
		Double diffAmtExch = 0.0;
		Double exchRateVouch = 0.0;
		Double adjAmt = 0.0;
		Double budgetAmtAnal = 0.0;
		Double budgetAmt = 0.0;
		Double consumedAmtAnal = 0.0;
		Double consumedAmt = 0.0;
		Double budgetAmtCctr = 0.0;
		Double consumedAmtCctr = 0.0;
		Double netBudget = 0.0;
		Double compute1 = 0.0;
		Double compute2 = 0.0;
		Double netBudgetCctr = 0.0;
		Double netPsexc = 0.0;
		Double mexrate = 0.0;
		java.util.Date taxDate = null;
		java.util.Date dueDate = null;
		int licnt = 0;
		int ctr = 0;
		int cnt = 0;
		int lineNum = 0;
		int currentFormNo = 0;
		int childNodeListLength1 = 0;
		int crDays = 0;
		boolean ibFlag = false;
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null ;
		GenericUtility genericUtility = GenericUtility.getInstance();
		ConnDriver connDriver = new ConnDriver();
		try
		{   
			conn = connDriver.getConnectDB("DriverITM");
			conn.setAutoCommit(false);
			connDriver = null;
			finCommon = new FinCommon();
			Calendar currentDate = Calendar.getInstance();
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
			defCrTerm = finCommon.getFinparams("999999","DEF_CR_TERM",conn);
			if(objContext != null && objContext.trim().length() > 0)
			{
				currentFormNo = Integer.parseInt(objContext);
			}
			valueXmlString = new StringBuffer("<?xml version = \"1.0\"?> <Root> <header> <editFlag>");
			valueXmlString.append(editFlag).append("</editFlag> </header>");
			switch(currentFormNo)
			{
				case 1 : 
						parentNodeList = dom.getElementsByTagName("Detail1");
						parentNode = parentNodeList.item(0);
						childNodeList = parentNode.getChildNodes();
						valueXmlString.append("<Detail1>");
						int childNodeListLength = childNodeList.getLength();
						do
						{   
							childNode = childNodeList.item(ctr);
							childNodeName = childNode.getNodeName();
							if(childNodeName.equals(currentColumn))
							{
								if(childNode.getFirstChild() != null)
								{
									columnValue = childNode.getFirstChild().getNodeValue().trim();
								}
							}
							ctr ++;
					    }while(ctr < childNodeListLength  && ! childNodeName.equals(currentColumn));
						if(currentColumn.trim().equalsIgnoreCase("itm_default"))
					    {
							siteCode =(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode"));
							valueXmlString.append("<site_code>").append("<![CDATA[" +  siteCode + "]]>").append("</site_code>");
							descName = findValue(conn, "descr" ,"site", "site_code", siteCode);
							valueXmlString.append("<site_descr>").append("<![CDATA[" + descName + "]]>").append("</site_descr>");
							entryBatchNo =(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "entry_batch_no"));
							valueXmlString.append("<entry_batch_no>").append("<![CDATA[" + entryBatchNo + "]]>").append("</entry_batch_no>");
							vouchType =(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "vouch_type"));
							valueXmlString.append("<vouch_type>").append("<![CDATA[" + vouchType + "]]>").append("</vouch_type>");
							if(!"A".equalsIgnoreCase(vouchType) )
							{
								valueXmlString.append("<sundry_type__pay protect = \"0\">").append ("</sundry_type__pay>");
								valueXmlString.append("<sundry_code__pay protect = \"0\">").append ("</sundry_code__pay>");
							}
							else
							{
								valueXmlString.append("<sundry_type__pay protect = \"0\">").append ("</sundry_type__pay>");
								valueXmlString.append("<sundry_code__pay protect = \"0\">").append ("</sundry_code__pay>");
							}
							if("T".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "X" + "]]>").append("</sundry_type>");
							}
							else if("N".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("R".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("G".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "T" + "]]>").append("</sundry_type>");
							}
							else if("F".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "E" + "]]>").append("</sundry_type>");
							}
							else if("O".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "E" + "]]>").append("</sundry_type>");
							}
							else if("S".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("P".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("A".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("D".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("C".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("L".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "L" + "]]>").append("</sundry_type>");
							}
							else if("B".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "E" + "]]>").append("</sundry_type>");
							}
							else if("H".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("E".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							dateNow = simpleDateFormat.format(currentDate.getTime());
							valueXmlString.append("<tran_date>").append("<![CDATA[" + dateNow + "]]>").append("</tran_date>");
							valueXmlString.append("<eff_date>").append("<![CDATA[" + dateNow + "]]>").append("</eff_date>");
							valueXmlString.append("<tax_date>").append("<![CDATA[" + dateNow + "]]>").append("</tax_date>");
							payRndOff = finCommon.getFinparams("999999","PAY_RND_OFF",conn);
							if(payRndOff == null || payRndOff.trim().equals("NULLFOUND"))
			                {
				              valueXmlString.append("<rnd_off>").append("<![CDATA[" + "N" + "]]>").append("</rnd_off>");
	                          valueXmlString.append("<rnd_to>").append("<![CDATA[" + 0 + "]]>").append("</rnd_to>");
			                }
							else
							{
						      valueXmlString.append("<rnd_off>").append("<![CDATA[" + payRndOff + "]]>").append("</rnd_off>");
	                          valueXmlString.append("<rnd_to>").append("<![CDATA[" + 1 + "]]>").append("</rnd_to>");
						    }

                            valueXmlString.append("<sundry_name>").append("<![CDATA[" + "" + "]]>").append("</sundry_name>");
							valueXmlString.append("<sundry_name_pay>").append("<![CDATA[" + "" + "]]>").append("</sundry_name_pay>");
							valueXmlString.append("<advance>").append("<![CDATA[" + "" + "]]>").append("</advance>");
                        }//end of if

                       else if(currentColumn.trim().equalsIgnoreCase("itm_defaultedit"))
					    {
							tranId = genericUtility.getColumnValue("tran_id", dom);
							sundryCodePay = genericUtility.getColumnValue("sundry_code__pay", dom);
							sundryTypePay = genericUtility.getColumnValue("sundry_type__pay", dom);
							sundryType = genericUtility.getColumnValue("sundry_type", dom);
							cctrCodeAp = genericUtility.getColumnValue("cctr_code__ap", dom);
							cctrCodePay = genericUtility.getColumnValue("cctr_code__pay", dom);
							currCode = genericUtility.getColumnValue("curr_code", dom);
							exchRate = genericUtility.getColumnValue("exch_rate", dom);
							finEntity = genericUtility.getColumnValue("fin_entity", dom);
							cnt = Integer.parseInt(findValue(conn, "count(tran_id)" ,"misc_vouchadv", "tran_id", tranId));
							ctr = Integer.parseInt(findValue(conn, "count(tran_id)" ,"misc_vouchdet", "tran_id", tranId));
							stanCode = getStanCode(conn , sundryTypePay,sundryCodePay);
							if(stanCode!= null && (stanCode.trim().length() > 0 ))
							{
								stanName = findValue(conn, "descr" ,"station", "stan_code", stanCode);
								stanName = stanName.trim();
								valueXmlString.append("<stan_descr_pay>").append("<![CDATA[" + stanName + "]]>").append("</stan_descr_pay>");
						    }
							else
							{
								valueXmlString.append("<stan_descr_pay>").append("<![CDATA[" + "" + "]]>").append("</stan_descr_pay>");
						    }
							stanCode = getStanCode(conn , sundryType,sundryCodePay);
							if(stanCode!= null && (stanCode.trim().length() > 0 ))
							{
								stanName = findValue(conn, "descr" ,"station", "stan_code", stanCode);
								stanName = stanName.trim();
								valueXmlString.append("<stan_descr>").append("<![CDATA[" + stanName + "]]>").append("</stan_descr>");
						    }
							else
							{
								valueXmlString.append("<stan_descr>").append("<![CDATA[" + "" + "]]>").append("</stan_descr>");
						    }
							
							chequeOrName = "N";
							descName = finCommon.getChequeName(sundryTypePay, sundryCodePay, chequeOrName, conn); 
							valueXmlString.append("<sundry_name_pay>").append("<![CDATA[" + descName + "]]>").append("</sundry_name_pay>");
							sundryCode = genericUtility.getColumnValue("sundry_code", dom);
							sundryType = genericUtility.getColumnValue("sundry_type", dom);
							vouchType = genericUtility.getColumnValue("vouch_type", dom);
							acctCodeAdv = genericUtility.getColumnValue("acct_code__adv", dom);
							cctrCodeAdv = genericUtility.getColumnValue("cctr_code__adv", dom);
							if(acctCodeAdv == null || acctCodeAdv.trim().length() == 0)
							{
								acctCodeAdv = "";
							}
							if(cctrCodeAdv == null || cctrCodeAdv.trim().length() == 0)
							{
								cctrCodeAdv = "";
							}
							chequeOrName = "N";
							descName = finCommon.getChequeName(sundryType, sundryCode, chequeOrName, conn);
							valueXmlString.append("<sundry_name>").append("<![CDATA[" + descName + "]]>").append("</sundry_name>");
							stanCode = getStanCode(conn , sundryTypePay,sundryCodePay);
							if(stanCode!= null && (stanCode.trim().length() > 0 ))
							{
								stanName = findValue(conn, "descr" ,"station", "stan_code", stanCode);
								stanName = stanName.trim();
								valueXmlString.append("<stan_descr_pay>").append("<![CDATA[" + stanName + "]]>").append("</stan_descr_pay>");
						    }
							else
							{
								valueXmlString.append("<stan_descr_pay>").append("<![CDATA[" + "" + "]]>").append("</stan_descr_pay>");
						    }
							valueXmlString.append("<advance>").append("<![CDATA[" + "" + "]]>").append("</advance>");
							if(cnt >0 || ctr >0)
							{
								valueXmlString.append("<vouch_type protect = \"1\">").append("<![CDATA[" + vouchType + "]]>").append("</vouch_type>");
						    }
							else
							{
								valueXmlString.append("<vouch_type protect = \"0\">").append("<![CDATA[" + vouchType + "]]>").append("</vouch_type>");
						    }
							if(ctr >0)
							{
								valueXmlString.append("<acct_code__adv protect = \"1\">").append("<![CDATA[" + acctCodeAdv + "]]>").append("</acct_code__adv>");
								valueXmlString.append("<cctr_code__adv protect = \"1\">").append("<![CDATA[" + cctrCodeAdv + "]]>").append("</cctr_code__adv>");
						    }
							else
							{
								valueXmlString.append("<acct_code__adv protect = \"0\">").append("<![CDATA[" + acctCodeAdv + "]]>").append("</acct_code__adv>");
								valueXmlString.append("<cctr_code__adv protect = \"0\">").append("<![CDATA[" + cctrCodeAdv + "]]>").append("</cctr_code__adv>");
						    }
							if(ctr > 0)
							{
								valueXmlString.append("<exch_rate protect = \"1\">").append("<![CDATA[" + exchRate + "]]>").append("</exch_rate>");
								valueXmlString.append("<curr_code protect = \"1\">").append("<![CDATA[" + currCode + "]]>").append("</curr_code>");
								valueXmlString.append("<sundry_type protect = \"1\">").append("<![CDATA[" + sundryType + "]]>").append("</sundry_type>");
								valueXmlString.append("<sundry_code protect = \"1\">").append("<![CDATA[" + sundryCode + "]]>").append("</sundry_code>");
								valueXmlString.append("<sundry_type__pay protect = \"1\">").append("<![CDATA[" + sundryTypePay + "]]>").append("</sundry_type__pay>");
								valueXmlString.append("<sundry_code__pay protect = \"1\">").append("<![CDATA[" + sundryCodePay + "]]>").append("</sundry_code__pay>");
								valueXmlString.append("<vouch_type protect = \"1\">").append("<![CDATA[" + vouchType + "]]>").append("</vouch_type>");
						    }
							else
							{
								valueXmlString.append("<exch_rate protect = \"0\">").append("<![CDATA[" + exchRate + "]]>").append("</exch_rate>");
								valueXmlString.append("<curr_code protect = \"0\">").append("<![CDATA[" + currCode + "]]>").append("</curr_code>");
								valueXmlString.append("<sundry_type protect = \"0\">").append("<![CDATA[" + sundryType + "]]>").append("</sundry_type>");
								valueXmlString.append("<sundry_code protect = \"0\">").append("<![CDATA[" + sundryCode + "]]>").append("</sundry_code>");
								valueXmlString.append("<sundry_type__pay protect = \"0\">").append("<![CDATA[" + sundryTypePay + "]]>").append("</sundry_type__pay>");
								valueXmlString.append("<sundry_code__pay protect = \"0\">").append("<![CDATA[" + sundryCodePay + "]]>").append("</sundry_code__pay>");
								valueXmlString.append("<vouch_type protect = \"0\">").append("<![CDATA[" + vouchType + "]]>").append("</vouch_type>");
							}
							sql = " select sum(tot_amt - adj_amt) from misc_payables where sundry_type = ? and sundry_code = ? and tran_ser = 'M-ADV' and tot_amt - adj_amt < 0";
							pstmt =  conn.prepareStatement(sql);
							pstmt.setString(1,sundryType);
							pstmt.setString(2,sundryCode);
							rs = pstmt.executeQuery();
							if(rs.next())
							{
								advAmt =  rs.getDouble(1);
							}
							rs.close();
							rs = null;
							pstmt.close();
							pstmt = null;
							if(advAmt < 0.0)
							{
								valueXmlString.append("<advance>").append("<![CDATA[" + "Advance unadjusted >>" + advAmt +"]]>").append("</advance>");
							}
							else
							{
								valueXmlString.append("<advance>").append("<![CDATA[" + "" + "]]>").append("</advance>");
							}
							valueXmlString.append("<vouch_type protect = \"1\">").append("<![CDATA[" + vouchType + "]]>").append("</vouch_type>");
							cctrDescr = findValue(conn, "descr" ,"costctr", "cctr_code", cctrCodeAp);
							valueXmlString.append("<cctr_descr__ap>").append("<![CDATA[" + cctrDescr + "]]>").append("</cctr_descr__ap>");
							cctrDescr = findValue(conn, "descr" ,"costctr", "cctr_code", cctrCodePay);
							valueXmlString.append("<cctr_descr__pay>").append("<![CDATA[" + cctrDescr + "]]>").append("</cctr_descr__pay>");
							currCode1 = findValue(conn, "curr_code" ,"finent", "fin_entity", finEntity);
							if(currCode != null && currCode1 !=null && currCode.trim().equalsIgnoreCase(currCode1.trim()))
							{
								valueXmlString.append("<exch_rate protect = \"1\">").append("<![CDATA[" + exchRate + "]]>").append("</exch_rate>");
							}
							else
							{
								valueXmlString.append("<exch_rate protect = \"0\">").append("<![CDATA[" + exchRate + "]]>").append("</exch_rate>");
							}
						}

						else if(currentColumn.trim().equalsIgnoreCase("tran_date"))
					    {
							tranDate = genericUtility.getColumnValue("tran_date", dom);
							valueXmlString.append("<eff_date>").append("<![CDATA[" + tranDate + "]]>").append("</eff_date>");
					    } 

						else if(currentColumn.trim().equalsIgnoreCase("cctr_code__ap"))
					    {
							cctrCodeAp = genericUtility.getColumnValue("cctr_code__ap", dom);
							cctrDescr = findValue(conn, "descr" ,"costctr", "cctr_code", cctrCodeAp);
							valueXmlString.append("<cctr_descr__ap>").append("<![CDATA[" + cctrDescr + "]]>").append("</cctr_descr__ap>");
							valueXmlString.append("<cctr_code__pay>").append("<![CDATA[" + cctrCodeAp + "]]>").append("</cctr_code__pay>");
							valueXmlString.append("<cctr_descr__pay>").append("<![CDATA[" + cctrDescr + "]]>").append("</cctr_descr__pay>");
						}

						else if(currentColumn.trim().equalsIgnoreCase("cctr_code__pay"))
					    {
							cctrCodePay = genericUtility.getColumnValue("cctr_code__pay", dom);
							cctrDescr = findValue(conn, "descr" ,"costctr", "cctr_code", cctrCodePay);
							valueXmlString.append("<cctr_descr__pay>").append("<![CDATA[" + cctrDescr + "]]>").append("</cctr_descr__pay>");
						}

						else if(currentColumn.trim().equalsIgnoreCase("vouch_type"))
					    {
							vouchType = genericUtility.getColumnValue("vouch_type", dom);
							if(!"A".equalsIgnoreCase(vouchType) )
							{
								valueXmlString.append("<sundry_type__pay protect = \"0\">").append ("</sundry_type__pay>");
								valueXmlString.append("<sundry_code__pay protect = \"0\">").append ("</sundry_code__pay>");
							}
							else
							{
								valueXmlString.append("<sundry_type__pay protect = \"0\">").append ("</sundry_type__pay>");
								valueXmlString.append("<sundry_code__pay protect = \"0\">").append ("</sundry_code__pay>");
							}
							if("T".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "X" + "]]>").append("</sundry_type>");
							}
							else if("N".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("R".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("G".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "T" + "]]>").append("</sundry_type>");
							}
							else if("F".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "E" + "]]>").append("</sundry_type>");
							}
							else if("O".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "E" + "]]>").append("</sundry_type>");
							}
							else if("S".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("P".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("A".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("D".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("C".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("L".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "L" + "]]>").append("</sundry_type>");
							}
							else if("B".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "E" + "]]>").append("</sundry_type>");
							}
							else if("H".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
							else if("E".equalsIgnoreCase(vouchType))
							{
								valueXmlString.append("<sundry_type>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type>");
							}
                        }

						else if(currentColumn.trim().equalsIgnoreCase("tran_date"))
					    {
							tranDate = genericUtility.getColumnValue("tran_date", dom);
							effDate = genericUtility.getColumnValue("eff_date", dom);
							crTerm = genericUtility.getColumnValue("cr_term", dom);
							billDate = genericUtility.getColumnValue("bill_date", dom);
							siteCode = genericUtility.getColumnValue("site_code", dom);
							currCode = genericUtility.getColumnValue("curr_code", dom);
							valueXmlString.append("<eff_date>").append("<![CDATA[" + tranDate + "]]>").append("</eff_date>");
							valueXmlString.append("<tax_date>").append("<![CDATA[" + tranDate + "]]>").append("</tax_date>");
							if(crTerm!= null && (crTerm.trim().length() > 0 ))
							{
								crDays = Integer.parseInt(findValue(conn, "cr_days" ,"crterm", "cr_term", crTerm));
								startFrom = findValue(conn, "start_from" ,"crterm", "cr_term", crTerm);
								dueDate = this.getDueDate(conn,simpleDateFormat,startFrom,tranDate,effDate,billDate,crDays);
								dueDate1 = simpleDateFormat.format(dueDate);
								valueXmlString.append("<due_date>").append("<![CDATA[" + dueDate1 + "]]>").append("</due_date>");
							}
							else
							{
								valueXmlString.append("<due_date>").append("<![CDATA[" + tranDate + "]]>").append("</due_date>");
							}	
							mexrate = finCommon.getDailyExchRateSellBuy(currCode, "", siteCode, tranDate, "B", conn);
							valueXmlString.append("<exch_rate>").append("<![CDATA[" + mexrate + "]]>").append("</exch_rate>");
							netAmt = genericUtility.getColumnValue("net_amt", dom);
							netPsexc = (Double.parseDouble(netAmt)) * mexrate;
							valueXmlString.append("<net_amt__bc>").append("<![CDATA[" + netPsexc + "]]>").append("</net_amt__bc>");
						}
				    
						else if(currentColumn.trim().equalsIgnoreCase("eff_date"))
					    {
							effDate = genericUtility.getColumnValue("eff_date", dom);
							crTerm = genericUtility.getColumnValue("cr_term", dom);
							tranDate = genericUtility.getColumnValue("tran_date", dom);
							billDate = genericUtility.getColumnValue("bill_date", dom);
							crDays = Integer.parseInt(findValue(conn, "cr_days" ,"crterm", "cr_term", crTerm));
							startFrom = findValue(conn, "start_from" ,"crterm", "cr_term", crTerm);
							dueDate = this.getDueDate(conn,simpleDateFormat,startFrom,tranDate,effDate,billDate,crDays);   
							dueDate1 = simpleDateFormat.format(dueDate);
							valueXmlString.append("<due_date>").append("<![CDATA[" +  dueDate1 + "]]>").append("</due_date>");
                        }

						else if(currentColumn.trim().equalsIgnoreCase("sundry_code"))
					    {
							sundryCode = genericUtility.getColumnValue("sundry_code", dom);
							sundryType = genericUtility.getColumnValue("sundry_type", dom);
							siteCode = genericUtility.getColumnValue("site_code", dom);
							valueXmlString.append("<sundry_type__pay>").append("<![CDATA[" + sundryType + "]]>").append("</sundry_type__pay>");
							valueXmlString.append("<sundry_code__pay>").append("<![CDATA[" + sundryCode + "]]>").append("</sundry_code__pay>");
							chequeOrName = "";
							descName = finCommon.getChequeName(sundryType, sundryCode, chequeOrName, conn);
							valueXmlString.append("<sundry_name>").append("<![CDATA[" + descName + "]]>").append("</sundry_name>");
							chequeOrName = "C";
							chqName = finCommon.getChequeName(sundryType, sundryCode, chequeOrName, conn);
							valueXmlString.append("<chq_name>").append("<![CDATA[" + chqName + "]]>").append("</chq_name>");
							if("C".equalsIgnoreCase(sundryType))
							{
								descName = findValue(conn, "cust_name" , "customer", "cust_code", sundryCode);
								currCode = findValue(conn, "curr_code" , "customer", "cust_code", sundryCode);
								acctCodeAp = findValue(conn, "acct_code__ar" , "customer", "cust_code", sundryCode);
								cctrCodeAp = findValue(conn, "cctr_code__ar" , "customer", "cust_code", sundryCode);
								crTerm = findValue(conn, "cr_term" , "customer", "cust_code", sundryCode);
								mSite = findValue(conn, "site_code" , "customer", "cust_code", sundryCode);
								stanCode = findValue(conn, "stan_code" , "customer", "cust_code", sundryCode);
								descrType = findValue(conn, "cust_type" , "customer", "cust_code", sundryCode);
								fldName = "CUST_TYPE";  
						    }
							else if("R".equalsIgnoreCase(sundryType))
							{
								mFname = findValue(conn, "first_name" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
								mName = findValue(conn, "middle_name" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
								mLname = findValue(conn, "last_name" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
								currCode = findValue(conn, "a.curr_code" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
								acctCodeAp = findValue(conn, "b.acct_code__ap" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
								cctrCodeAp = findValue(conn, "b.cctr_code__ap" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
								crTerm = findValue(conn, "a.cr_term" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
								mSite = findValue(conn, "a.site_code" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
								stanCode = findValue(conn, "b.stan_code" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
								descrType = findValue(conn, "a.cust_type" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
								if("null".equalsIgnoreCase(mFname))
								{
									mFname = "";
							    }
								if("null".equalsIgnoreCase(mName))
								{
									mName = "";
							    }
								if("null".equalsIgnoreCase(mLname))
								{
									mLname = "";
							    }
								if(acctCodeAp == null || (acctCodeAp.trim().length() == 0 ))
								{
									acctCodeAp = findValue(conn, "a.acct_code__ar" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
							    }
								if(cctrCodeAp == null || (cctrCodeAp.trim().length() == 0 ))
								{
									cctrCodeAp = findValue(conn, "a.cctr_code__ar" , "strg_customer b", "customer a", "b.cust_code", "b.sc_code", "a.cust_code(+)", sundryCode);
							    }
								descName = mFname.trim() + "" + mName.trim() + "" + mLname.trim();
								fldName = "CUST_TYPE";
								lcCode = getCode(conn, "fn_strg_customer_det('R',sundryCode,'L')", "dual");
								valueXmlString.append("<locality_code>").append("<![CDATA[" + lcCode + "]]>").append("</locality_code>");
								suppCode = getCode(conn, "fn_strg_customer_det('R',sundryCode,'S')", "dual");
								valueXmlString.append("<spl_code>").append("<![CDATA[" + suppCode + "]]>").append("</spl_code>");
								stanCode = getCode(conn, "fn_strg_customer_det('R',sundryCode,'T')", "dual");
								valueXmlString.append("<stan_code>").append("<![CDATA[" + stanCode + "]]>").append("</stan_code>");
							}
							else if("B".equalsIgnoreCase(sundryType))
							{
								descName = findValue(conn, "bank_name" , "bank", "bank_code", sundryCode);
								currCode = findValue(conn, "curr_code" , "bank", "bank_code", sundryCode);
								acctCodeAp = findValue(conn, "acct_code__bal" , "bank", "bank_code", sundryCode);
								cctrCodeAp = findValue(conn, "cctr_code__bal" , "bank", "bank_code", sundryCode);
								mSite = findValue(conn, "site_code" , "bank", "bank_code", sundryCode);
								descrType = findValue(conn, "bank_type" , "bank", "bank_code", sundryCode);
								fldName = "BANK_TYPE";  
						    }   
							else if("E".equalsIgnoreCase(sundryType))
							{
								mFname = findValue(conn, "a.emp_fname" , "employee a", "site b", "department c", "a.pay_site", "a.emp_code", "a.dept_code", "b.site_code", sundryCode, "c.dept_code");
								mLname = findValue(conn, "a.emp_lname" , "employee a", "site b", "department c", "a.pay_site", "a.emp_code", "a.dept_code", "b.site_code", sundryCode, "c.dept_code");
								acctCodeAp = findValue(conn, "c.acct_code__ap" , "employee a", "site b", "department c", "a.pay_site", "a.emp_code", "a.dept_code", "b.site_code", sundryCode, "c.dept_code");
								cctrCodeAp = findValue(conn, "c.cctr_code__ap" , "employee a", "site b", "department c", "a.pay_site", "a.emp_code", "a.dept_code", "b.site_code", sundryCode, "c.dept_code");
								mSite = findValue(conn, "b.site_code__acct" , "employee a", "site b", "department c", "a.pay_site", "a.emp_code", "a.dept_code", "b.site_code", sundryCode, "c.dept_code");
								payMode = findValue(conn, "a.pay_mode" , "employee a", "site b", "department c", "a.pay_site", "a.emp_code", "a.dept_code", "b.site_code", sundryCode, "c.dept_code");
								bankCode = findValue(conn, "a.bank_code" , "employee a", "site b", "department c", "a.pay_site", "a.emp_code", "a.dept_code", "b.site_code", sundryCode, "c.dept_code");
								stanCode = findValue(conn, "stan_code__hq" , "employee a", "site b", "department c", "a.pay_site", "a.emp_code", "a.dept_code", "b.site_code", sundryCode, "c.dept_code");
								designation = findValue(conn, "designation" , "employee a", "site b", "department c", "a.pay_site", "a.emp_code", "a.dept_code", "b.site_code", sundryCode, "c.dept_code");
								valueXmlString.append("<designation>").append("<![CDATA[" + designation + "]]>").append("</designation>");
								if(acctCodeAp == null || (acctCodeAp.trim().length() == 0 ))
								{
									acctCodeAp = findValue(conn, "a.acct_code__sal" , "employee a", "site b", "a.pay_site", "a.emp_code", "b.site_code", sundryCode);
							    }
								if(cctrCodeAp == null || (cctrCodeAp.trim().length() == 0 ))
								{
									cctrCodeAp = findValue(conn, "a.cctr_code__sal" , "employee a", "site b", "a.pay_site", "a.emp_code", "b.site_code", sundryCode);
							    }
								descName = mFname.trim() + "" + mLname.trim();
								currCode = findValue(conn, "curr_code", "site", "finent", "site.fin_entity", "site_code", "finent.fin_entity", siteCode);
								valueXmlString.append("<pay_mode>").append("<![CDATA[" + payMode + "]]>").append("</pay_mode>");
								if(bankCode != null && (bankCode.trim().length() > 0 ))
								{
									valueXmlString.append("<bank_code>").append("<![CDATA[" + bankCode + "]]>").append("</bank_code>");
									bankCode = bankCode.trim();
									descName = findValue(conn, "bank_name", "bank", "bank_code", bankCode);
									acctCodeCf = findValue(conn, "acct_code__cf", "bank", "bank_code", bankCode);
									cctrCodeCf = findValue(conn, "cctr_code__cf", "bank", "bank_code", bankCode);
									acctCodeCfAp = findValue(conn, "acct_code__cf_ap", "bank", "bank_code", bankCode);
									cctrCodeCfAp = findValue(conn, "cctr_code__cf_ap", "bank", "bank_code", bankCode);
									if(acctCodeCfAp != null && (acctCodeCfAp.trim().length() > 0 ))
									{
										acctCodeCf = acctCodeCfAp;
									}
									if(cctrCodeCfAp != null && (cctrCodeCfAp.trim().length() > 0 ))
									{
										cctrCodeCf = cctrCodeCfAp;
									}
									valueXmlString.append("<bank_bank_name>").append("<![CDATA[" + descName + "]]>").append("</bank_bank_name>");
									valueXmlString.append("<acct_code__cf>").append("<![CDATA[" + acctCodeCf + "]]>").append("</acct_code__cf>");
									valueXmlString.append("<cctr_code__cf>").append("<![CDATA[" + cctrCodeCf + "]]>").append("</cctr_code__cf>");
								}
								vouchType = genericUtility.getColumnValue("vouch_type", dom);
								if("F".equalsIgnoreCase(vouchType))
								{
									grade = findValue(conn, "grade", "employee", "emp_code", sundryCode);
									valueXmlString.append("<tran_type>").append("<![CDATA[" + grade.trim() + "]]>").append("</tran_type>");
								}
								else if("A".equalsIgnoreCase(vouchType))
								{
									acctCodeAp = "";
									cctrCodeAp = "";
							    }
                            }
							else if("P".equalsIgnoreCase(sundryType))
							{
								descName = findValue(conn, "sp_name" , "sales_pers", "sales_pers", sundryCode);
								crTerm = findValue(conn, "cr_term" , "sales_pers", "sales_pers", sundryCode);
								currCode = findValue(conn, "curr_code" , "sales_pers", "sales_pers", sundryCode);
								acctCodeAp = findValue(conn, "acct_code__ap" , "sales_pers", "sales_pers", sundryCode);
								cctrCodeAp = findValue(conn, "cctr_code__ap" , "sales_pers", "sales_pers", sundryCode);
								acctCodeAdv = findValue(conn, "acct_code__ap_adv" , "sales_pers", "sales_pers", sundryCode);
								cctrCodeAdv = findValue(conn, "cctr_code__ap_adv" , "sales_pers", "sales_pers", sundryCode);
								empCode = findValue(conn, "emp_code" , "sales_pers", "sales_pers", sundryCode);
								descrType = findValue(conn, "sp_type" , "sales_pers", "sales_pers", sundryCode);
								if(empCode != null && (empCode.trim().length() > 0 ))
								{
									payMode = findValue(conn, "pay_mode" , "employee", "emp_code", empCode);
									bankCode = findValue(conn, "bank_code" , "employee", "emp_code", empCode);
									stanCode = findValue(conn, "stan_code" , "employee", "emp_code", empCode);
									if(payMode != null && (payMode.trim().length() > 0 ))
									{
										valueXmlString.append("<pay_mode>").append("<![CDATA[" + payMode + "]]>").append("</pay_mode>");
								    }
									if(bankCode != null && (bankCode.trim().length() > 0 ))
									{
										valueXmlString.append("<bank_code>").append("<![CDATA[" + bankCode + "]]>").append("</bank_code>");
										bankCode = bankCode.trim();
										descName = findValue(conn, "bank_name" , "bank", "bank_code", bankCode);
										acctCodeCf = findValue(conn, "acct_code__cf" , "bank", "bank_code", bankCode);
										cctrCodeCf = findValue(conn, "cctr_code__cf" , "bank", "bank_code", bankCode);
										acctCodeCfAp = findValue(conn, "acct_code__cf_ap" , "bank", "bank_code", bankCode);
										cctrCodeCfAp = findValue(conn, "cctr_code__cf_ap" , "bank", "bank_code", bankCode);
										if(acctCodeCfAp != null && (acctCodeCfAp.trim().length() > 0 ))
										{
											acctCodeCf = acctCodeCfAp;
									    }
										if(cctrCodeCfAp != null && (cctrCodeCfAp.trim().length() > 0 ))
										{
											cctrCodeCf = cctrCodeCfAp;
									    }
										valueXmlString.append("<bank_bank_name>").append("<![CDATA[" + descName + "]]>").append("</bank_bank_name>");
										valueXmlString.append("<acct_code__cf>").append("<![CDATA[" + acctCodeCf + "]]>").append("</acct_code__cf>");
										valueXmlString.append("<cctr_code__cf>").append("<![CDATA[" + cctrCodeCf + "]]>").append("</cctr_code__cf>");
								    }
                                }
                                vouchType = genericUtility.getColumnValue("vouch_type", dom);
								if("F".equalsIgnoreCase(vouchType))
								{
                                   empCode = findValue(conn, "grade" , "employee", "emp_code", empCode);
                                   valueXmlString.append("<tran_type>").append("<![CDATA[" + empCode + "]]>").append("</tran_type>");
								}
									fldName = "SP_TYPE";
							}
							else if("T".equalsIgnoreCase(sundryType))
							{
								descName = findValue(conn, "tran_name" , "transporter", "tran_code", sundryCode);
								crTerm = findValue(conn, "cr_term" , "transporter", "tran_code", sundryCode);
								currCode = findValue(conn, "curr_code" , "transporter", "tran_code", sundryCode);
								acctCodeAp = findValue(conn, "acct_code__fp" , "transporter", "tran_code", sundryCode);
								cctrCodeAp = findValue(conn, "cctr_code__fp" , "transporter", "tran_code", sundryCode);
								stanCode = findValue(conn, "stan_code" , "transporter", "tran_code", sundryCode);
								acctCodeAdv = findValue(conn, "acct_code__adv" , "transporter", "tran_code", sundryCode);
								cctrCodeAdv = findValue(conn, "cctr_code__adv" , "transporter", "tran_code", sundryCode);
								taxEnv = findValue(conn, "tax_env" , "transporter", "tran_code", sundryCode);
								taxClass = findValue(conn, "tax_class" , "transporter", "tran_code", sundryCode);
								descrType = findValue(conn, "transporter_type" , "transporter", "tran_code", sundryCode);
								payMode = findValue(conn, "pay_mode" , "transporter", "tran_code", sundryCode);
								if(taxClass == null || taxClass.trim().length() == 0)
								{
									taxClass = "";
							    }
								if(taxEnv == null || taxEnv.trim().length() == 0)
								{
									taxEnv = "";
							    }
								valueXmlString.append("<tax_class>").append("<![CDATA[" + taxClass + "]]>").append("</tax_class>");
								valueXmlString.append("<tax_env>").append("<![CDATA[" + taxEnv + "]]>").append("</tax_env>");
								fldName = "TRANSPORTER_TYPE";
								if(payMode != null && (payMode.trim().length() > 0 ))
								{
									valueXmlString.append("<pay_mode>").append("<![CDATA[" + payMode + "]]>").append("</pay_mode>");
								}  
							}
							else if("O".equalsIgnoreCase(sundryType))
							{
								descName = findValue(conn, "descr" , "accounts", "acct_code", sundryCode);
								currCode = findValue(conn, "curr_code" , "accounts", "acct_code", sundryCode);
                           	}
							else if("S".equalsIgnoreCase(sundryType))
							{
								descName = findValue(conn, "supp_name" , "supplier", "supp_code", sundryCode);
								currCode = findValue(conn, "curr_code" , "supplier", "supp_code", sundryCode);
								acctCodeAp = findValue(conn, "acct_code__ap" , "supplier", "supp_code", sundryCode);
								cctrCodeAp = findValue(conn, "cctr_code__ap" , "supplier", "supp_code", sundryCode);
								acctCodeAdv = findValue(conn, "acct_code__ap_adv" , "supplier", "supp_code", sundryCode);
								cctrCodeAdv = findValue(conn, "cctr_code__ap_adv" , "supplier", "supp_code", sundryCode);
								stanCode = findValue(conn, "stan_code" , "supplier", "supp_code", sundryCode);
								taxClass = findValue(conn, "tax_class" , "supplier", "supp_code", sundryCode);
								taxChap = findValue(conn, "tax_chap" , "supplier", "supp_code", sundryCode);
								taxEnv = findValue(conn, "tax_env" , "supplier", "supp_code", sundryCode);
								descrType = findValue(conn, "supp_type" , "supplier", "supp_code", sundryCode);
								payMode = findValue(conn, "pay_mode" , "supplier", "supp_code", sundryCode);
								crTerm = findValue(conn, "cr_term" , "site_supplier", "supp_code", "site_code", sundryCode, siteCode);
								if(taxChap == null || taxChap.trim().length() == 0)
								{
									taxChap = "";
							    }
								if(taxClass == null || taxClass.trim().length() == 0)
								{
									taxClass = "";
							    }
								if(crTerm == null || (crTerm.trim().length() == 0 ))
								{
									crTerm = findValue(conn, "cr_term" , "supplier", "supp_code", taxClass);
								}
								if(taxEnv == null || taxEnv.trim().length() == 0)
								{
									taxEnv = "";
							    }
								if(acctCodeAdv == null || acctCodeAdv.trim().length() == 0)
								{
									acctCodeAdv = "";
							    }
								if(cctrCodeAdv == null || cctrCodeAdv.trim().length() == 0)
								{
									cctrCodeAdv = "";
							    }
								valueXmlString.append("<tax_class>").append("<![CDATA[" + taxClass + "]]>").append("</tax_class>");
								valueXmlString.append("<tax_chap>").append("<![CDATA[" + taxChap + "]]>").append("</tax_chap>");
								valueXmlString.append("<tax_env>").append("<![CDATA[" + taxEnv + "]]>").append("</tax_env>");
								valueXmlString.append("<acct_code__adv>").append("<![CDATA[" + acctCodeAdv + "]]>").append("</acct_code__adv>");
								valueXmlString.append("<cctr_code__adv>").append("<![CDATA[" + cctrCodeAdv + "]]>").append("</cctr_code__adv>");
								fldName = "SUPP_TYPE";                               
								if(payMode != null && (payMode.trim().length() > 0 ))
								{
									valueXmlString.append("<pay_mode>").append("<![CDATA[" + payMode + "]]>").append("</pay_mode>"); 
								}
							}
							else if("X".equalsIgnoreCase(sundryType))
							{
								descName = findValue(conn, "tauth_name" , "tax_authority", "tauth_code", sundryCode);
								crTerm = findValue(conn, "cr_term" , "tax_authority", "tauth_code", sundryCode);
								acctCodeAp = findValue(conn, "acct_code__ap" , "tax_authority", "tauth_code", sundryCode);
								cctrCodeAp = findValue(conn, "cctr_code__ap" , "tax_authority", "tauth_code", sundryCode);
								stanCode = findValue(conn, "stan_code" , "tax_authority", "tauth_code", sundryCode);
								descrType = findValue(conn, "tauth_type" , "tax_authority", "tauth_code", sundryCode);
								payMode = findValue(conn, "pay_mode" , "tax_authority", "tauth_code", sundryCode);
								currCode = findValue(conn, "curr_code" , "site,finent", "site.fin_entity = finent.fin_entity and site_code", siteCode);
								fldName = "TAUTH_TYPE";
								if(payMode == null || (payMode.trim().length() == 0 ))
								{
									valueXmlString.append("<pay_mode>").append("<![CDATA[" + payMode + "]]>").append("</pay_mode>");
								}
							}
							else if("L".equalsIgnoreCase(sundryType))
							{
								descName = findValue(conn, "party_name" , "loanparty", "party_code", sundryCode);
								acctCodeAp = findValue(conn, "acct_code__ap" , "loanparty", "party_code", sundryCode);
								cctrCodeAp = findValue(conn, "cctr_code__ap" , "loanparty", "party_code", sundryCode);
								acctCodeAdv = findValue(conn, "acct_code__ap_adv" , "loanparty", "party_code", sundryCode);
								cctrCodeAdv = findValue(conn, "cctr_code__ap_adv" , "loanparty", "party_code", sundryCode);
								stanCode = findValue(conn, "stan_code" , "loanparty", "party_code", sundryCode);
							}
							if(!("E".equalsIgnoreCase(vouchType)))
							{
								descrType = descrType.trim().toUpperCase();
								designation = findCodes("descr" , "gencodes", "Upper(mod_name)", "Upper(fld_name)", "Upper(fld_value)", "X", fldName , descrType,conn);
								valueXmlString.append("<designation>").append("<![CDATA[" + designation + "]]>").append("</designation>");
								descrType = "";
						    }
							if(stanCode != null && (stanCode.trim().length() > 0 ))
							{
								stanName = findValue(conn, "descr" , "station", "stan_code", stanCode);
								stanName = stanName.trim();
								valueXmlString.append("<stan_descr>").append("<![CDATA[" + stanName + "]]>").append("</stan_descr>");
						    }
							else
							{
								valueXmlString.append("<stan_descr>").append("<![CDATA[" + stanName + "]]>").append("</stan_descr>");
						    }
							valueXmlString.append("<sundry_name>").append("<![CDATA[" + descName + "]]>").append("</sundry_name>");
							chequeOrName = "N";
							descName = finCommon.getChequeName(sundryType, sundryCode, chequeOrName, conn);
							valueXmlString.append("<sundry_name_pay>").append("<![CDATA[" + descName + "]]>").append("</sundry_name_pay>");
							valueXmlString.append("<curr_code>").append("<![CDATA[" + currCode + "]]>").append("</curr_code>");
							tranDate = genericUtility.getColumnValue("tran_date", dom);
							mexrate = finCommon.getDailyExchRateSellBuy(currCode, "", siteCode, tranDate, "B", conn);
							valueXmlString.append("<exch_rate>").append("<![CDATA[" + mexrate + "]]>").append("</exch_rate>");
							siteCode = (genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode"));
							if((siteCode == null || (siteCode.trim().length() == 0 )) && (mSite.length() > 0))
							{
								valueXmlString.append("<site_code>").append("<![CDATA[" + mSite + "]]>").append("</site_code>");
								descName = findValue(conn, "descr" , "site", "site_code", mSite);
								finEntity = findValue(conn, "fin_entity" , "site", "site_code", mSite);
								valueXmlString.append("<site_descr>").append("<![CDATA[" + descName + "]]>").append("</site_descr>");
								valueXmlString.append("<fin_entity>").append("<![CDATA[" + finEntity + "]]>").append("</fin_entity>");
								if(currCode.length() == 0 )
								{
									currCode = findValue(conn, "curr_code" , "finent", "fin_entity", finEntity);
									valueXmlString.append("<curr_code>").append("<![CDATA[" + currCode + "]]>").append("</curr_code>");
									tranDate = genericUtility.getColumnValue("tran_date", dom);
									mexrate = finCommon.getDailyExchRateSellBuy(currCode, "", siteCode, tranDate, "B", conn);
									valueXmlString.append("<exch_rate>").append("<![CDATA[" + mexrate + "]]>").append("</exch_rate>");
								}
							}
                            finEntity = genericUtility.getColumnValue("fin_entity", dom);
							currCode1 = findValue(conn, "curr_code" , "finent", "fin_entity", finEntity);
							if(currCode1 != null && currCode != null && currCode1.trim().equalsIgnoreCase(currCode.trim()))
							{
								valueXmlString.append("<exch_rate protect = \"1\">").append("<![CDATA[" + mexrate + "]]>").append ("</exch_rate>");
							}
							else
							{
								valueXmlString.append("<exch_rate protect = \"0\">").append("<![CDATA[" + mexrate + "]]>").append ("</exch_rate>");
							}
					        vouchType = genericUtility.getColumnValue("vouch_type", dom);
							if("A".equalsIgnoreCase(vouchType))
							{
								if(acctCodeAdv == null || acctCodeAdv.trim().length() == 0)
								{
									acctCodeAdv = "";
							    }
								if(cctrCodeAdv == null || cctrCodeAdv.trim().length() == 0)
								{
									cctrCodeAdv = "";
							    }
								valueXmlString.append("<acct_code__ap>").append("<![CDATA[" + acctCodeAp + "]]>").append("</acct_code__ap>");
								mdescr = findValue(conn, "descr" , "accounts", "acct_code", acctCodeAdv);
								valueXmlString.append("<accounts_descr>").append("<![CDATA[" + mdescr + "]]>").append("</accounts_descr>");
								valueXmlString.append("<cctr_code__ap>").append("<![CDATA[" + cctrCodeAp + "]]>").append("</cctr_code__ap>");
								valueXmlString.append("<acct_code__adv>").append("<![CDATA[" + acctCodeAdv + "]]>").append("</acct_code__adv>");
								valueXmlString.append("<cctr_code__adv>").append("<![CDATA[" + cctrCodeAdv+ "]]>").append("</cctr_code__adv>");
							}
							else
							{
								if(acctCodeAp != null)
								{
									valueXmlString.append("<acct_code__ap>").append("<![CDATA[" + acctCodeAp + "]]>").append("</acct_code__ap>");
									mdescr = findValue(conn, "descr" , "accounts", "acct_code", acctCodeAp);
									valueXmlString.append("<accounts_descr>").append("<![CDATA[" + mdescr + "]]>").append("</accounts_descr>");
								}
								if(cctrCodeAp != null)
								{
									valueXmlString.append("<cctr_code__ap>").append("<![CDATA[" + cctrCodeAp + "]]>").append("</cctr_code__ap>");
								}
							}
							effDate = genericUtility.getColumnValue("eff_date", dom);
							tranDate = genericUtility.getColumnValue("tran_date", dom);
							billDate = genericUtility.getColumnValue("bill_date", dom);
							if(crTerm == null || (crTerm.trim().length() == 0 ))
							{
								if(defCrTerm != null && (defCrTerm.trim().length() > 0 ))
								{
									valueXmlString.append("<cr_term>").append("<![CDATA[" + defCrTerm + "]]>").append("</cr_term>");
									crDays = Integer.parseInt(findValue(conn, "cr_days" ,"crterm", "cr_term", defCrTerm));
									startFrom = findValue(conn, "start_from" ,"crterm", "cr_term", defCrTerm);
									dueDate = this.getDueDate(conn,simpleDateFormat,startFrom,tranDate,effDate,billDate,crDays);
								}
								else
								{
									dueDate = simpleDateFormat.parse(tranDate);
								}
							}
							else
						   	{
								valueXmlString.append("<cr_term>").append("<![CDATA[" + crTerm + "]]>").append("</cr_term>");
                                crDays = Integer.parseInt(findValue(conn, "cr_days" ,"crterm", "cr_term", crTerm));
							    startFrom = findValue(conn, "start_from" ,"crterm", "cr_term", crTerm);
								dueDate = this.getDueDate(conn,simpleDateFormat,startFrom,tranDate,effDate,billDate,crDays);
							}
                            dueDate1 = simpleDateFormat.format(dueDate);
							valueXmlString.append("<due_date>").append("<![CDATA[" + dueDate1 + "]]>").append("</due_date>");
							advAmt = findSum(conn, "sum(tot_amt - adj_amt)", "misc_payables", "sundry_code", "tran_ser in ('M-ADV','P-ADV','P-IBCA')", "(tot_amt - adj_amt) <= 0.0", "sundry_type", sundryCode, sundryType);
							if(advAmt != null && advAmt < 0)
							{
								valueXmlString.append("<advance>").append("<![CDATA[" + "Advance unadjusted >>" + advAmt + "]]>").append("</advance>");
							}
							else
							{
								valueXmlString.append("<advance>").append("<![CDATA[" + "" + "]]>").append("</advance>");
							}
							netAmt = genericUtility.getColumnValue("net_amt", dom);
							netPsexc = (Double.parseDouble(netAmt)) * mexrate;
							valueXmlString.append("<net_amt__bc>").append("<![CDATA[" + netPsexc + "]]>").append("</net_amt__bc>");
							if(sundryCode == null || (sundryCode.trim().length() == 0 ))
							{
								valueXmlString.append("<acct_code__pay>").append("<![CDATA[" + "" + "]]>").append("</acct_code__pay>");
								valueXmlString.append("<pay_acct_descr>").append("<![CDATA[" + "" + "]]>").append("</pay_acct_descr>");
								valueXmlString.append("<cctr_code__ap>").append("<![CDATA[" + "" + "]]>").append("</cctr_code__ap>");
								valueXmlString.append("<cctr_descr__ap>").append("<![CDATA[" + "" + "]]>").append("</cctr_descr__ap>");
								valueXmlString.append("<cctr_code__pay>").append("<![CDATA[" + "" + "]]>").append("</cctr_code__pay>");
								valueXmlString.append("<cctr_descr__pay>").append("<![CDATA[" + "" + "]]>").append("</cctr_descr__pay>");
							}
                            acctCodePay = genericUtility.getColumnValue("acct_code__pay", dom);
							if(acctCodePay == null || acctCodePay.trim().length() == 0)
							{
								acctCodePay = genericUtility.getColumnValue("acct_code__ap", dom);
								cctrCodePay = genericUtility.getColumnValue("cctr_code__ap", dom);
								sundryTypePay = genericUtility.getColumnValue("sundry_type__pay", dom);
								sundryCodePay = genericUtility.getColumnValue("sundry_code__pay", dom);
                                stanCodePay = getStanCode(conn , sundryTypePay,sundryCodePay);
								if(stanCodePay != null && (stanCodePay.trim().length() > 0 ))
								{
									stanNamePay = findValue(conn, "descr" , "station", "stan_code", stanCodePay);
									valueXmlString.append("<stan_descr_pay>").append("<![CDATA[" + stanNamePay + "]]>").append("</stan_descr_pay>");
								}
								if(acctCodePay == null)
								{
									acctCodePay = "";
								}
								if(cctrCodePay == null)
								{
									cctrCodePay = "";
								}
								acctName = findValue(conn, "descr" , "accounts", "acct_code", acctCodeAp);
								valueXmlString.append("<pay_acct_descr>").append("<![CDATA[" + acctName + "]]>").append("</pay_acct_descr>");
								valueXmlString.append("<acct_code__pay>").append("<![CDATA[" + acctCodeAp + "]]>").append("</acct_code__pay>");
								valueXmlString.append("<cctr_code__pay>").append("<![CDATA[" + cctrCodeAp + "]]>").append("</cctr_code__pay>");
							}
                            cctrCodeAp = genericUtility.getColumnValue("cctr_code__ap", dom);
							cctrDescr = findValue(conn, "descr" , "costctr", "cctr_code", cctrCodeAp);
							valueXmlString.append("<cctr_descr__ap>").append("<![CDATA[" + cctrDescr + "]]>").append("</cctr_descr__ap>");
							cctrCodePay = genericUtility.getColumnValue("cctr_code__pay", dom);
							cctrDescr = findValue(conn, "descr" , "costctr", "cctr_code", cctrCodePay);
							valueXmlString.append("<cctr_descr__pay>").append("<![CDATA[" + cctrDescr + "]]>").append("</cctr_descr__pay>");
							
						}
                        else if(currentColumn.trim().equalsIgnoreCase("order_ref"))
				        {
							orderRef = genericUtility.getColumnValue("order_ref", dom);	
							val = "Y";
							cnt = Integer.parseInt(findValue(conn, "count(tran_id)" , "srv_order", "tran_id", "confirmed", orderRef, val));
							if(cnt > 0)
							{
								acctCodePay = findValue(conn, "ACCT_CODE__CR" , "srv_order", "tran_id", orderRef);
								cctrCodePay = findValue(conn, "CCTR_CODE__CR" , "srv_order", "tran_id", orderRef);
								amount = Double.parseDouble(findValue(conn, "AMOUNT" , "srv_order", "tran_id", orderRef));
								suppCode = findValue(conn, "SUPP_CODE" , "srv_order", "tran_id", orderRef);
								taxAmt = Double.parseDouble(findValue(conn, "TAX_AMT" , "srv_order", "tran_id", orderRef));
								totAmt = Double.parseDouble(findValue(conn, "TOT_AMT" , "srv_order", "tran_id", orderRef));
								crTerm = findValue(conn, "CR_TERM" , "srv_order", "tran_id", orderRef);
								siteCode = findValue(conn, "SITE_CODE__DLV" , "srv_order", "tran_id", orderRef);
								taxDate = simpleDateFormat.parse(findValue(conn, "	_DATE" , "srv_order", "tran_id", orderRef));
								projCode = findValue(conn, "PROJ_CODE" , "srv_order", "tran_id", orderRef);
								advAmount = Double.parseDouble(findValue(conn, "VOUCH_ADV_AMT", "srv_order", "tran_id", orderRef));
								if (acctCodePay != null && cctrCodePay != null && amount !=null && suppCode != null && taxAmt != null && totAmt != null && crTerm != null && siteCode != null && taxDate != null && projCode != null && advAmount != null)
								{
									valueXmlString.append("<sundry_code>").append("<![CDATA[" + suppCode + "]]>").append("</sundry_code>");
									valueXmlString.append("<sundry_code__pay>").append("<![CDATA[" + suppCode + "]]>").append("</sundry_code__pay>");
									valueXmlString.append("<sundry_type__pay>").append("<![CDATA[" + "S" + "]]>").append("</sundry_type__pay>");
									acctName = findValue(conn, "descr" , "accounts", "acct_code", acctCodePay);
									valueXmlString.append("<acct_code__pay protect = \"1\">").append("<![CDATA[" + acctCodePay + "]]>").append("</acct_code__pay>");
									valueXmlString.append("<pay_acct_descr>").append("<![CDATA[" + acctName + "]]>").append("</pay_acct_descr>");
									valueXmlString.append("<acct_code__ap>").append("<![CDATA[" + acctCodePay + "]]>").append("</acct_code__ap>");
									valueXmlString.append("<accounts_descr>").append("<![CDATA[" + acctName + "]]>").append("</accounts_descr>");
									valueXmlString.append("<cctr_code__pay protect = \"1\">").append("<![CDATA[" + cctrCodePay + "]]>").append("</cctr_code__pay>");
									valueXmlString.append("<cctr_code__ap>").append("<![CDATA[" + cctrCodePay + "]]>").append("</cctr_code__ap>");
									valueXmlString.append("<tot_amt>").append("<![CDATA[" + totAmt + "]]>").append("</tot_amt>");
									valueXmlString.append("<tax_amt>").append("<![CDATA[" + taxAmt + "]]>").append("</tax_amt>");
									valueXmlString.append("<net_amt>").append("<![CDATA[" + amount + "]]>").append("</net_amt>");
									valueXmlString.append("<cr_term>").append("<![CDATA[" + crTerm + "]]>").append("</cr_term>");
									valueXmlString.append("<site_code>").append("<![CDATA[" + siteCode + "]]>").append("</site_code>");
									descName = findValue(conn, "descr" , "site", "site_code", siteCode);
									finEntity = findValue(conn, "fin_entity" , "site", "site_code", siteCode);
									valueXmlString.append("<site_descr>").append("<![CDATA[" + descName + "]]>").append("</site_descr>");
									valueXmlString.append("<fin_entity>").append("<![CDATA[" + finEntity + "]]>").append("</fin_entity>");
									taxDate1 = simpleDateFormat.format(taxDate);
									valueXmlString.append("<tax_date>").append("<![CDATA[" + taxDate1 + "]]>").append("</tax_date>");
									valueXmlString.append("<proj_code>").append("<![CDATA[" + projCode + "]]>").append("</proj_code>");
									if(advAmount == null)
									{
										advAmount = 0.0;
										valueXmlString.append("<adv_amt>").append("<![CDATA[" + advAmount + "]]>").append("</adv_amt>");
									}
									valueXmlString.append("<sundry_code protect = \"1\">").append ("</sundry_code>");
									valueXmlString.append("<tot_amt protect = \"1\">").append ("</tot_amt>");
									valueXmlString.append("<tax_amt protect = \"1\">").append ("</tax_amt>");
									valueXmlString.append("<net_amt protect = \"1\">").append ("</net_amt>");
									valueXmlString.append("<cr_term protect = \"1\">").append ("</cr_term>");
									valueXmlString.append("<site_code protect = \"1\">").append ("</site_code>");
									valueXmlString.append("<tax_date protect = \"1\">").append ("</tax_date>");
									valueXmlString.append("<proj_code protect = \"1\">").append ("</proj_code>");
									valueXmlString.append("<sundry_code__pay protect = \"1\">").append ("</sundry_code__pay>");
									valueXmlString.append("<sundry_type__pay protect = \"1\">").append ("</sundry_type__pay>");
									lineNo = findValue(conn, "min(line_no)", "srv_orddet", "tran_id", orderRef);
									taxChap = findValue(conn, "tax_chap", "srv_orddet", "tran_id", "line_no", orderRef, lineNo);
									taxEnv = findValue(conn, "tax_env", "srv_orddet", "tran_id", "line_no", orderRef, lineNo);
									taxClass = findValue(conn, "tax_class", "srv_orddet", "tran_id", "line_no", orderRef, lineNo);
									if(taxChap == null || taxChap.trim().length() == 0)
									{
										taxChap = "";
									}	
									if(taxClass == null || taxClass.trim().length() == 0)
									{
										taxClass = "";
									}
									if(taxEnv == null || taxEnv.trim().length() == 0)
									{
										taxEnv = "";
									}
									valueXmlString.append("<tax_chap>").append("<![CDATA[" + taxChap + "]]>").append("</tax_chap>");
									valueXmlString.append("<tax_env>").append("<![CDATA[" + taxEnv + "]]>").append("</tax_env>");
									valueXmlString.append("<tax_class>").append("<![CDATA[" + taxClass + "]]>").append("</tax_class>");
								}
								else
								{
									valueXmlString.append("<sundry_code protect = \"0\">").append ("</sundry_code>");
									valueXmlString.append("<acct_code__pay protect = \"0\">").append("<![CDATA[" + acctCodePay + "]]>").append ("</acct_code__pay>");
									valueXmlString.append("<cctr_code__pay protect = \"0\">").append("<![CDATA[" + cctrCodePay + "]]>").append ("</cctr_code__pay>");
									valueXmlString.append("<tot_amt protect = \"0\">").append ("</tot_amt>");
									valueXmlString.append("<tax_amt protect = \"0\">").append ("</tax_amt>");
									valueXmlString.append("<net_amt protect = \"0\">").append ("</net_amt>");
									valueXmlString.append("<cr_term protect = \"0\">").append ("</cr_term>");
									valueXmlString.append("<site_code protect = \"0\">").append ("</site_code>");
									valueXmlString.append("<tax_date protect = \"0\">").append ("</tax_date>");
									valueXmlString.append("<proj_code protect = \"0\">").append ("</proj_code>");
									valueXmlString.append("<sundry_code__pay protect = \"0\">").append ("</sundry_code__pay>");
									valueXmlString.append("<sundry_type__pay protect = \"0\">").append ("</sundry_type__pay>");
								}
							}
						}
                        
						else if(currentColumn.trim().equalsIgnoreCase("sundry_type__pay"))
				        {
							valueXmlString.append("<sundry_code__pay>").append("<![CDATA[" + "" + "]]>").append("</sundry_code__pay>");
							valueXmlString.append("<sundry_name_pay>").append("<![CDATA[" + "" + "]]>").append("</sundry_name_pay>");
							valueXmlString.append("<acct_code__pay>").append("<![CDATA[" + "" + "]]>").append("</acct_code__pay>");
							valueXmlString.append("<cctr_code__pay>").append("<![CDATA[" + "" + "]]>").append("</cctr_code__pay>");
							valueXmlString.append("<pay_acct_descr>").append("<![CDATA[" + "" + "]]>").append("</pay_acct_descr>");
						}
						
						else if(currentColumn.trim().equalsIgnoreCase("sundry_code__pay"))
				        {
							sundryCodePay = genericUtility.getColumnValue("sundry_code__pay", dom);
							sundryTypePay = genericUtility.getColumnValue("sundry_type__pay", dom);
							chequeOrName = "N";
							descName = finCommon.getChequeName(sundryTypePay, sundryCodePay, chequeOrName, conn);
							valueXmlString.append("<sundry_name_pay>").append("<![CDATA[" + descName + "]]>").append("</sundry_name_pay>");
							if("C".equalsIgnoreCase(sundryTypePay))
							{
								acctCodeAp = findValue(conn, "acct_code__ar" , "customer", "cust_code", sundryCodePay);
								cctrCodeAp = findValue(conn, "cctr_code__ar" , "customer", "cust_code", sundryCodePay);
								stanCode = findValue(conn, "stan_code" , "customer", "cust_code", sundryCodePay);
						    }
							else if("R".equalsIgnoreCase(sundryTypePay))
							{
								custCode = findValue(conn, "cust_code" , "strg_customer", "sc_code", sundryCodePay);
								acctCodeAp = findValue(conn, "acct_code__ar" , "customer", "cust_code", custCode);
								cctrCodeAp = findValue(conn, "cctr_code__ar" , "customer", "cust_code", custCode);
								stanCode = findValue(conn, "stan_code" , "customer", "cust_code", custCode);
						    }
							else if("B".equalsIgnoreCase(sundryTypePay))
							{
								acctCodeAp = findValue(conn, "acct_code__bal" , "bank", "bank_code", sundryCodePay);
								cctrCodeAp = findValue(conn, "cctr_code__bal" , "bank", "bank_code", sundryCodePay);
							}
							else if("E".equalsIgnoreCase(sundryTypePay))
							{
								acctCodeAp = findValue(conn, "acct_code__sal" , "employee", "emp_code", sundryCodePay);
								cctrCodeAp = findValue(conn, "cctr_code__sal" , "employee", "emp_code", sundryCodePay);
								stanCode = findValue(conn, "stan_code__hq" , "employee", "emp_code", sundryCodePay);
							}
							else if("P".equalsIgnoreCase(sundryTypePay))
							{
								acctCodeAp = findValue(conn, "acct_code__ap" , "sales_pers", "sales_pers", sundryCodePay);
								cctrCodeAp = findValue(conn, "cctr_code__ap" , "sales_pers", "sales_pers", sundryCodePay);
								empCode = findValue(conn, "emp_code" , "sales_pers", "sales_pers", sundryCodePay);
								if(empCode == null || (empCode.trim().length() == 0 ))
								{
									stanCode = findValue(conn, "stan_code" , "employee", "emp_code", empCode);
							    }
							}
							else if("T".equalsIgnoreCase(sundryTypePay))
							{
								acctCodeAp = findValue(conn, "acct_code__fp" , "transporter", "tran_code", sundryCodePay);
								cctrCodeAp = findValue(conn, "cctr_code__fp" , "transporter", "tran_code", sundryCodePay);
								stanCode = findValue(conn, "stan_code" , "transporter", "tran_code", sundryCodePay);
							}
							else if("S".equalsIgnoreCase(sundryTypePay))
							{
								acctCodeAp = findValue(conn, "acct_code__ap" , "supplier", "supp_code", sundryCodePay);
								cctrCodeAp = findValue(conn, "cctr_code__ap" , "supplier", "supp_code", sundryCodePay);
								stanCode = findValue(conn, "stan_code" , "supplier", "supp_code", sundryCodePay);
							}
							else if("X".equalsIgnoreCase(sundryTypePay))
							{
								acctCodeAp = findValue(conn, "acct_code__ap" , "tax_authority", "tauth_code", sundryCodePay);
								cctrCodeAp = findValue(conn, "cctr_code__ap" , "tax_authority", "tauth_code", sundryCodePay);
								stanCode = findValue(conn, "stan_code" , "tax_authority", "tauth_code", sundryCodePay);
							}
							else if("L".equalsIgnoreCase(sundryTypePay))
							{
								acctCodeAp = findValue(conn, "acct_code__ap" , "loanparty", "party_code", sundryCodePay);
								cctrCodeAp = findValue(conn, "cctr_code__ap" , "loanparty", "party_code", sundryCodePay);
								stanCode = findValue(conn, "stan_code" , "loanparty", "party_code", sundryCodePay);
							}
							valueXmlString.append("<acct_code__pay>").append("<![CDATA[" + acctCodeAp + "]]>").append("</acct_code__pay>");  
							acctName = findValue(conn, "descr" , "accounts", "acct_code", acctCodeAp);
							valueXmlString.append("<pay_acct_descr>").append("<![CDATA[" + acctName + "]]>").append("</pay_acct_descr>");
							valueXmlString.append("<cctr_code__pay>").append("<![CDATA[" + cctrCodeAp + "]]>").append("</cctr_code__pay>");
							if(stanCode != null && (stanCode.trim().length() > 0 ))
							{
								stanName = findValue(conn, "descr" , "station", "stan_code", stanCode);
								stanName = stanName.trim();
								valueXmlString.append("<stan_descr_pay>").append("<![CDATA[" + stanName + "]]>").append("</stan_descr_pay>");
							}
							else
							{
								valueXmlString.append("<stan_descr_pay>").append("<![CDATA[" + "" + "]]>").append("</stan_descr_pay>");
							}
						}
   
						else if(currentColumn.trim().equalsIgnoreCase("acct_code__pay"))
				        {
							acctCodePay = genericUtility.getColumnValue("acct_code__pay", dom);
							acctName = findValue(conn, "descr" , "accounts", "acct_code", acctCodePay);
							valueXmlString.append("<pay_acct_descr>").append("<![CDATA[" + acctName + "]]>").append("</pay_acct_descr>");
				        }

						else if(currentColumn.trim().equalsIgnoreCase("curr_code"))
				        {
							currCode = genericUtility.getColumnValue("curr_code", dom);
							siteCode = genericUtility.getColumnValue("site_code", dom);
							tranDate = genericUtility.getColumnValue("tran_date", dom);
							mexrate = finCommon.getDailyExchRateSellBuy(currCode, "", siteCode, tranDate, "B", conn);
							netAmt = genericUtility.getColumnValue("net_amt", dom);
							netPsexc = (Double.parseDouble(netAmt)) * mexrate;
							valueXmlString.append("<net_amt__bc>").append("<![CDATA[" + netPsexc + "]]>").append("</net_amt__bc>");
							finEntity = genericUtility.getColumnValue("fin_entity", dom);
							currCode1 = findValue(conn, "curr_code" , "finent", "fin_entity", finEntity);
							if(currCode != null && currCode1 != null && currCode.trim().equalsIgnoreCase(currCode1.trim()))
							{
								valueXmlString.append("<exch_rate protect = \"1\">").append("<![CDATA[" + mexrate + "]]>").append ("</exch_rate>");
							}
							else
							{
								valueXmlString.append("<exch_rate protect = \"0\">").append("<![CDATA[" + mexrate + "]]>").append ("</exch_rate>");
							}
							valueXmlString.append("<net_amt__bc>").append("<![CDATA[" + netPsexc + "]]>").append("</net_amt__bc>");
				        }

						else if(currentColumn.trim().equalsIgnoreCase("exch_rate"))
						{
							mexrate = Double.parseDouble(genericUtility.getColumnValue("exch_rate", dom));
							netAmt = genericUtility.getColumnValue("net_amt", dom);
							netPsexc = (Double.parseDouble(netAmt)) * mexrate;
							valueXmlString.append("<net_amt__bc>").append("<![CDATA[" + netPsexc + "]]>").append("</net_amt__bc>");
						}

						else if(currentColumn.trim().equalsIgnoreCase("acct_code__ap"))
						{
							acctCodeAp = genericUtility.getColumnValue("acct_code__ap", dom);
							siteCode = genericUtility.getColumnValue("site_code", dom);
							tranDate = genericUtility.getColumnValue("tran_date", dom);
							valueXmlString.append("<acct_code__pay>").append("<![CDATA[" + acctCodeAp + "]]>").append("</acct_code__pay>");
							mdescr = findValue(conn, "descr" , "accounts", "acct_code", acctCodeAp);
							currCode = findValue(conn, "curr_code" , "accounts", "acct_code", acctCodeAp);
							valueXmlString.append("<accounts_descr>").append("<![CDATA[" + mdescr + "]]>").append("</accounts_descr>");
							valueXmlString.append("<curr_code>").append("<![CDATA[" + currCode + "]]>").append("</curr_code>");
							valueXmlString.append("<pay_acct_descr>").append("<![CDATA[" + mdescr + "]]>").append("</pay_acct_descr>");
							mexrate = finCommon.getDailyExchRateSellBuy(currCode, "", siteCode, tranDate, "B", conn);
							valueXmlString.append("<exch_rate protect = \"1\">").append("<![CDATA[" + mexrate + "]]>").append("</exch_rate>");
							netAmt = genericUtility.getColumnValue("net_amt", dom);
							netPsexc = (Double.parseDouble(netAmt)) * mexrate;
							valueXmlString.append("<net_amt__bc>").append("<![CDATA[" + netPsexc + "]]>").append("</net_amt__bc>");
						}

						else if(currentColumn.trim().equalsIgnoreCase("site_code"))
						{
							siteCode = genericUtility.getColumnValue("site_code", dom);
							tranDate = genericUtility.getColumnValue("tran_date", dom);
							descName = findValue(conn, "descr" , "site", "site_code", siteCode);
							finEntity = findValue(conn, "fin_entity" , "site", "site_code", siteCode);
							valueXmlString.append("<site_descr>").append("<![CDATA[" + descName + "]]>").append("</site_descr>");
							valueXmlString.append("<fin_entity>").append("<![CDATA[" + finEntity + "]]>").append("</fin_entity>");
							currCode = findValue(conn, "curr_code" , "finent", "fin_entity", finEntity);
							mexrate = finCommon.getDailyExchRateSellBuy(currCode, "", siteCode, tranDate, "B", conn);
							valueXmlString.append("<exch_rate protect = \"1\">").append("<![CDATA[" + mexrate + "]]>").append("</exch_rate>");
							payMode = genericUtility.getColumnValue("pay_mode", dom);
							if("C".equalsIgnoreCase(payMode))
							{
								bankCode = findValue(conn, "cash_code" , "site", "site_code", siteCode);
							}
							else
							{
								bankCode = findValue(conn, "bank_code" , "site", "site_code", siteCode);
							}
							descName = findValue(conn, "bank_name" , "bank", "bank_code", bankCode);
							bankCode = bankCode.trim();
							valueXmlString.append("<bank_code>").append("<![CDATA[" + bankCode + "]]>").append("</bank_code>");
							valueXmlString.append("<bank_bank_name>").append("<![CDATA[" + descName + "]]>").append("</bank_bank_name>");
							currCode = findValue(conn, "curr_code" , "bank", "bank_code", bankCode);
							acctCodeBc = findValue(conn, "acct_code__bc" , "bank", "bank_code", bankCode);
							cctrCodeBc = findValue(conn, "cctr_code__bc" , "bank", "bank_code", bankCode);
							acctCodeCf = findValue(conn, "acct_code__cf" , "bank", "bank_code", bankCode);
							cctrCodeCf = findValue(conn, "cctr_code__cf" , "bank", "bank_code", bankCode);
							acctCodeCfAp = findValue(conn, "acct_code__cf_ap" , "bank", "bank_code", bankCode);
							cctrCodeCfAp = findValue(conn, "cctr_code__cf_ap" , "bank", "bank_code", bankCode);
							if(acctCodeCfAp != null && (acctCodeCfAp.trim().length() > 0 ))
							{
								acctCodeCf = acctCodeCfAp; 
							}
							if(cctrCodeCfAp != null && (cctrCodeCfAp.trim().length() > 0 ))
							{
								cctrCodeCf = cctrCodeCfAp; 
							}
							valueXmlString.append("<acct_code__cf>").append("<![CDATA[" + acctCodeCf + "]]>").append("</acct_code__cf>");
							valueXmlString.append("<cctr_code__cf>").append("<![CDATA[" + cctrCodeCf + "]]>").append("</cctr_code__cf>");
							netAmt = genericUtility.getColumnValue("net_amt", dom);
							netPsexc = (Double.parseDouble(netAmt)) * mexrate;
							valueXmlString.append("<net_amt__bc>").append("<![CDATA[" + netPsexc + "]]>").append("</net_amt__bc>");
						}
                   
						else if(currentColumn.trim().equalsIgnoreCase("pay_mode"))
						{
							payMode = genericUtility.getColumnValue("pay_mode", dom);
							siteCode = genericUtility.getColumnValue("site_code", dom);
							if("C".equalsIgnoreCase(payMode))
							{
								bankCode = findValue(conn, "cash_code" , "site", "site_code", siteCode);
							}
							else
							{
								bankCode = findValue(conn, "bank_code" , "site", "site_code", siteCode);
							}
							descName = findValue(conn, "bank_name" , "bank", "bank_code", bankCode);
							valueXmlString.append("<bank_code>").append("<![CDATA[" + bankCode + "]]>").append("</bank_code>");
							valueXmlString.append("<bank_bank_name>").append("<![CDATA[" + descName + "]]>").append("</bank_bank_name>");
						}
                     
						else if(currentColumn.trim().equalsIgnoreCase("bill_amt"))
						{
							billAmt = Double.parseDouble(genericUtility.getColumnValue("bill_amt", dom));
							sundryType = genericUtility.getColumnValue("sundry_type", dom);
							if(!("O".equalsIgnoreCase(sundryType)))
							{
								effDate = genericUtility.getColumnValue("eff_date", dom);
								sundryCode = genericUtility.getColumnValue("sundry_code", dom);
								finEntity = genericUtility.getColumnValue("fin_entity", dom);
								acctPrd = findValue(conn, "acct_prd" , "period", "fr_date <", "to_date >", effDate, effDate);
								if(mAdv > billAmt)
								{
									mAdv = billAmt;
								}
								mAdv = (mAdv * (-1));
								advAmt = Double.parseDouble(genericUtility.getColumnValue("adv_amt", dom));
								if(advAmt != null && advAmt == 0)
								{
									valueXmlString.append("<adv_amt>").append("<![CDATA[" + mAdv + "]]>").append("</adv_amt>");
								}
							}
							billAmt = Double.parseDouble(genericUtility.getColumnValue("bill_amt", dom));
							advAmt = Double.parseDouble(genericUtility.getColumnValue("adv_amt", dom));
							taxAmt = Double.parseDouble(genericUtility.getColumnValue("tax_amt", dom));
							totAmount = billAmt + advAmt;
							totAmount = totAmount + taxAmt;
							valueXmlString.append("<tot_amt>").append("<![CDATA[" + totAmount + "]]>").append("</tot_amt>");
						}
						
						else if(currentColumn.trim().equalsIgnoreCase("adv_amt"))
						{
							advAmt = Double.parseDouble(genericUtility.getColumnValue("adv_amt", dom));
							billAmt = Double.parseDouble(genericUtility.getColumnValue("bill_amt", dom));
							taxAmt = Double.parseDouble(genericUtility.getColumnValue("tax_amt", dom));
							totAmount = billAmt + advAmt;
							totAmount = totAmount + taxAmt;
							valueXmlString.append("<tot_amt>").append("<![CDATA[" + totAmount + "]]>").append("</tot_amt>");
						}
						
						else if(currentColumn.trim().equalsIgnoreCase("tax_amt"))
						{
							advAmt = Double.parseDouble(genericUtility.getColumnValue("adv_amt", dom));
							billAmt = Double.parseDouble(genericUtility.getColumnValue("bill_amt", dom));
							taxAmt = Double.parseDouble(genericUtility.getColumnValue("tax_amt", dom));
							totAmount = billAmt + advAmt;
							totAmount = totAmount + taxAmt;
							valueXmlString.append("<tot_amt>").append("<![CDATA[" + totAmount + "]]>").append("</tot_amt>");
						}
						
						else if(currentColumn.trim().equalsIgnoreCase("bank_code"))
						{
							bankCode = genericUtility.getColumnValue("bank_code", dom);
							bankCode = bankCode.trim();
							descName = findValue(conn, "bank_name" , "bank", "bank_code", bankCode);
							acctCodeCf = findValue(conn, "acct_code__cf" , "bank", "bank_code", bankCode);
							cctrCodeCf = findValue(conn, "cctr_code__cf" , "bank", "bank_code", bankCode);
							acctCodeCfAp = findValue(conn, "acct_code__cf_ap" , "bank", "bank_code", bankCode);
							cctrCodeCfAp = findValue(conn, "cctr_code__cf_ap" , "bank", "bank_code", bankCode);
							valueXmlString.append("<bank_bank_name>").append("<![CDATA[" + descName + "]]>").append("</bank_bank_name>");
							if(acctCodeCfAp != null && (acctCodeCfAp.trim().length() > 0 ))
							{
								acctCodeCf = acctCodeCfAp; 
							}
							if(cctrCodeCfAp != null && (cctrCodeCfAp.trim().length() > 0 ))
							{
								cctrCodeCf = cctrCodeCfAp; 
							}
							valueXmlString.append("<acct_code__cf>").append("<![CDATA[" + acctCodeCf + "]]>").append("</acct_code__cf>");
							valueXmlString.append("<cctr_code__cf>").append("<![CDATA[" + cctrCodeCf + "]]>").append("</cctr_code__cf>");
							if(bankCode != null && bankCode.length() > 0)
							{
								valueXmlString.append("<acct_code protect = \"1\">").append ("</acct_code>");
								valueXmlString.append("<cctr_code protect = \"1\">").append ("</cctr_code>");
							}
							else
							{
								valueXmlString.append("<acct_code protect = \"0\">").append ("</acct_code>");
								valueXmlString.append("<cctr_code protect = \"0\">").append ("</cctr_code>");
							}
						}
					   
						else if(currentColumn.trim().equalsIgnoreCase("cr_term"))
						{
							crTerm = genericUtility.getColumnValue("cr_term", dom);
							tranDate = genericUtility.getColumnValue("tran_date", dom);
							billDate = genericUtility.getColumnValue("bill_date", dom);
							effDate = genericUtility.getColumnValue("eff_date", dom);
							crDays1 = findValue(conn, "cr_days" ,"crterm", "cr_term", crTerm);
							if(crDays1 != null && crDays1.trim().length() > 0)
							{
								crDays = Integer.parseInt(crDays1);
							}
							startFrom = findValue(conn, "start_from" ,"crterm", "cr_term", crTerm);
							dueDate = this.getDueDate(conn,simpleDateFormat,startFrom,tranDate,effDate,billDate,crDays);
							dueDate1 = simpleDateFormat.format(dueDate);
							valueXmlString.append("<due_date>").append("<![CDATA[" + dueDate1 + "]]>").append("</due_date>");
						}

						else if(currentColumn.trim().equalsIgnoreCase("bill_no"))
						{
							billNo = genericUtility.getColumnValue("bill_no", dom);
							descName = findValue(conn, "descr" , "period", "code", billNo);
							valueXmlString.append("<remarks>").append("<![CDATA[" + "Expense" + descName + "]]>").append("</remarks>");
						}
						valueXmlString.append("</Detail1>");
		                break;       

				case 2 : 
						parentNodeList = dom1.getElementsByTagName("Detail1");
						parentNode = parentNodeList.item(0);
						winName = getObjName(parentNode);
						System.out.println( "winName :: " + winName );
						parentNodeList = dom.getElementsByTagName("Detail2");
						parentNode = parentNodeList.item(0);
						childNodeList = parentNode.getChildNodes();
						ctr = 0;
						valueXmlString.append("<Detail2>");
						childNodeListLength = childNodeList.getLength();
						do
					    {   
							childNode = childNodeList.item(ctr);
							childNodeName = childNode.getNodeName();
							if(childNodeName.equals(currentColumn))
							{
								if(childNode.getFirstChild() != null)
								{
									columnValue = childNode.getFirstChild().getNodeValue().trim();
								}
							}
							ctr ++;
					    }while(ctr < childNodeListLength  && ! childNodeName.equals(currentColumn));
                       
						if(currentColumn.trim().equalsIgnoreCase("itm_default"))
				        {   
							linecnt = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "detCnt");
							if (linecnt != null)
							{
								lineNum = Integer.parseInt(linecnt);
							}
							tranId = genericUtility.getColumnValue("tran_id", dom);
							valueXmlString.append("<tran_id>").append("<![CDATA[" + tranId + "]]>").append("</tran_id>");
							if(lineNum > 0)
							{
								valueXmlString.append("<exch_rate protect = \"1\">").append ("</exch_rate>");
								valueXmlString.append("<curr_code protect = \"1\">").append ("</curr_code>");
								valueXmlString.append("<vouch_type protect = \"1\">").append ("</vouch_type>");
							}
							else
							{
								valueXmlString.append("<exch_rate protect = \"0\">").append ("</exch_rate>");
								valueXmlString.append("<curr_code protect = \"0\">").append ("</curr_code>");
							}
						}
 
						else if(currentColumn.trim().equalsIgnoreCase("ref_no"))
				        {
							refNo = genericUtility.getColumnValue("ref_no", dom);
							refSer = genericUtility.getColumnValue("ref_ser", dom);
							siteCode = genericUtility.getColumnValue("site_code", dom);
							mexrate = Double.parseDouble(genericUtility.getColumnValue("exch_rate", dom1));
							currCode = findValue(conn, "curr_code" , "misc_payables", "tran_ser", "ref_no", refSer, refNo);
							exchRate1 = findValue(conn, "exch_rate" , "misc_payables", "tran_ser", "ref_no", refSer, refNo);
							acctCode = findValue(conn, "acct_code" , "misc_payables", "tran_ser", "ref_no", refSer, refNo);
							cctrCode = findValue(conn, "cctr_code" , "misc_payables", "tran_ser", "ref_no", refSer, refNo);
							totAmt = Double.parseDouble(findValue(conn, "tot_amt" , "misc_payables", "tran_ser", "ref_no", refSer, refNo));
							adv = Double.parseDouble(getAdjAmt(conn, "(tot_amt - adj_amt)" , "misc_payables", "tran_ser", "ref_no", refSer, refNo));
							valueXmlString.append("<curr_code>").append("<![CDATA[" + currCode + "]]>").append("</curr_code>");
							valueXmlString.append("<exch_rate__vouch>").append("<![CDATA[" + exchRate1 + "]]>").append("</exch_rate__vouch>");
							valueXmlString.append("<tot_amt>").append("<![CDATA[" + totAmt + "]]>").append("</tot_amt>");
							valueXmlString.append("<adj_amt>").append("<![CDATA[" + adv + "]]>").append("</adj_amt>");
							valueXmlString.append("<acct_code>").append("<![CDATA[" + acctCode + "]]>").append("</acct_code>");
							valueXmlString.append("<cctr_code>").append("<![CDATA[" + cctrCode + "]]>").append("</cctr_code>");
							valueXmlString.append("<exch_rate protect = \"1\">").append ("</exch_rate>");
							valueXmlString.append("<vouch_type protect = \"1\">").append ("</vouch_type>");
							valueXmlString.append("<sundry_type protect = \"1\">").append ("</sundry_type>");
							valueXmlString.append("<sundry_code protect = \"1\">").append ("</sundry_code>");
							diffAmtExch = (adv * Double.parseDouble(exchRate1)) - (adv * mexrate);
							valueXmlString.append("<diff_amt__exch>").append("<![CDATA[" + diffAmtExch + "]]>").append("</diff_amt__exch>");
						}

						else if(currentColumn.trim().equalsIgnoreCase("adj_amt"))
						{
							adjAmt = Double.parseDouble(genericUtility.getColumnValue("adj_amt", dom));
							mexrate = Double.parseDouble(genericUtility.getColumnValue("exch_rate", dom1));
							exchRateVouch = Double.parseDouble(genericUtility.getColumnValue("exch_rate__vouch", dom));
							refNo = genericUtility.getColumnValue("ref_no", dom);
							mvouch = "M-VOUC";
							flag = "Y";
							diffAmtExch = (adjAmt * exchRateVouch) - (adjAmt * mexrate);
							valueXmlString.append("<diff_amt__exch>").append("<![CDATA[" + diffAmtExch + "]]>").append("</diff_amt__exch>");
							licnt = findSum(conn, "count(1)" , "taxtran", "tran_code", "tran_id", "pay_tax", mvouch, refNo, flag).intValue();
							if(licnt > 0)
							{
								valueXmlString.append("<taxed_adj_amt>").append("<![CDATA[" + adjAmt + "]]>").append("</taxed_adj_amt>");
							}
							else
							{
								valueXmlString.append("<taxed_adj_amt>").append("<![CDATA[" + "0" + "]]>").append("</taxed_adj_amt>");
							}
						}
						valueXmlString.append("</Detail2>");
				        break;
			  
				case 3 : 
						parentNodeList = dom1.getElementsByTagName("Detail1");
						parentNode = parentNodeList.item(0);;
						parentNodeList = dom2.getElementsByTagName("Detail2");
						parentNode = parentNodeList.item(0);
						parentNodeList = dom.getElementsByTagName("Detail3");
						parentNode = parentNodeList.item(0);
						childNodeList = parentNode.getChildNodes();
						ctr = 0;
						valueXmlString.append("<Detail3>");
						childNodeListLength = childNodeList.getLength();
						do
						{   
							childNode = childNodeList.item(ctr);
							childNodeName = childNode.getNodeName();
							if(childNodeName.equals(currentColumn))
							{
								if(childNode.getFirstChild() != null)
								{
									columnValue = childNode.getFirstChild().getNodeValue().trim();
								}
							}
							ctr ++;
					    }while(ctr < childNodeListLength  && ! childNodeName.equals(currentColumn));
                      
						if(currentColumn.trim().equalsIgnoreCase("itm_default"))
				        {   
							linecnt = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "focusRow");
							if (linecnt != null) 
							{
								lineNum = Integer.parseInt(linecnt);
							}
							if(lineNum > 0)
						    {
								valueXmlString.append("<line_no>").append("<![CDATA[" + lineNum + "]]>").append("</line_no>");
							}
							tranId = genericUtility.getColumnValue("tran_id", dom1);
							vouchType = genericUtility.getColumnValue("vouch_type", dom1);
							valueXmlString.append("<tran_id>").append("<![CDATA[" + tranId + "]]>").append("</tran_id>");
							if("A".equalsIgnoreCase(vouchType))
							{
								acctCodeAdv = genericUtility.getColumnValue("acct_code__adv", dom1);
								cctrCodeAdv = genericUtility.getColumnValue("cctr_code__adv", dom1);
								valueXmlString.append("<acct_code>").append("<![CDATA[" + acctCodeAdv + "]]>").append("</acct_code>");
								valueXmlString.append("<cctr_code>").append("<![CDATA[" + cctrCodeAdv + "]]>").append("</cctr_code>");
								mdescr = findValue(conn, "descr" , "accounts", "acct_code", acctCodeAdv );
								valueXmlString.append("<accounts_descr>").append("<![CDATA[" + mdescr + "]]>").append("</accounts_descr>");
							}
							valueXmlString.append("<sundry_name>").append("<![CDATA[" + "" + "]]>").append("</sundry_name>");
							valueXmlString.append("<sudcity>").append("<![CDATA[" + "" + "]]>").append("</sudcity>");
							taxClass = genericUtility.getColumnValue("tax_class", dom1);
							taxChap = genericUtility.getColumnValue("tax_chap", dom1);
							taxEnv = genericUtility.getColumnValue("tax_env", dom1);
							linecnt = (genericUtility.getValueFromXTRA_PARAMS(xtraParams, "detCnt"));
							licnt = Integer.parseInt(linecnt);
							if(licnt > 0)
							{ 
								valueXmlString.append("<acct_code__adv protect = \"1\">").append("<![CDATA[" + acctCodeAdv + "]]>").append ("</acct_code__adv>");
								valueXmlString.append("<cctr_code__adv protect = \"1\">").append("<![CDATA[" + cctrCodeAdv + "]]>").append ("</cctr_code__adv>");
								valueXmlString.append("<vouch_type protect = \"1\">").append ("</vouch_type>");
							}
							else
							{
								valueXmlString.append("<acct_code__adv protect = \"0\">").append("<![CDATA[" + acctCodeAdv + "]]>").append ("</acct_code__adv>");
								valueXmlString.append("<cctr_code__adv protect = \"0\">").append("<![CDATA[" + cctrCodeAdv + "]]>").append ("</cctr_code__adv>");
							}
							taxEnv = genericUtility.getColumnValue("tax_env", dom1);
							if(taxEnv != null && (taxEnv.trim().length() > 0 ))
							{
								valueXmlString.append("<apply_tax>").append("<![CDATA[" + "Y" + "]]>").append("</apply_tax>");
							}
							dateNow = simpleDateFormat.format(currentDate.getTime());
							valueXmlString.append("<bill_date>").append("<![CDATA[" + dateNow + "]]>").append("</bill_date>");
							taxedAdjAmt = genericUtility.getColumnValue("taxed_adj_amt", dom1);
							vouchType = genericUtility.getColumnValue("vouch_type", dom1);
							if("A".equalsIgnoreCase(vouchType) || "E".equalsIgnoreCase(vouchType))
							{
								parentNodeList1 = dom2.getElementsByTagName("Detail3"); 
								childNodeListLength1 = parentNodeList1.getLength();
								int ctr1;
								for(ctr1 = 0; ctr1 < childNodeListLength1; ctr1++)
								{
									parentNode1 = parentNodeList1.item(ctr1);
									lineNum = Integer.parseInt(genericUtility.getColumnValue("line_no", dom));
									cnt = Integer.parseInt(genericUtility.getColumnValueFromNode("line_no",parentNode1)) ;
									if (lineNum == cnt)
									{
										valueXmlString.append("<taxed_adj_amt>").append("<![CDATA[" + taxedAdjAmt + "]]>").append("</taxed_adj_amt>");
									}
									else
									{
										valueXmlString.append("<taxed_adj_amt>").append("<![CDATA[" + "0" + "]]>").append("</taxed_adj_amt>");
									}
								}
								if(ctr1 == 0)
								{
									valueXmlString.append("<taxed_adj_amt>").append("<![CDATA[" + taxedAdjAmt + "]]>").append("</taxed_adj_amt>");
								}
							}
							projCode = genericUtility.getColumnValue("proj_code", dom);
							projCode1 = genericUtility.getColumnValue("proj_code", dom1);
							if(projCode == null || (projCode.trim().length() == 0 ))
							{
								valueXmlString.append("<proj_code>").append("<![CDATA[" + projCode1 + "]]>").append("</proj_code>");
							}
						}
                        
						else if(currentColumn.trim().equalsIgnoreCase("itm_defaultedit"))
					    {
							sundryTypeFor = genericUtility.getColumnValue("sundry_type__for", dom);
							sundryCodeFor = genericUtility.getColumnValue("sundry_code__for", dom);
							if(sundryTypeFor == null || sundryTypeFor.trim().length() > 0)
							{
								sundryTypeFor = "";
							}
							if(sundryCodeFor == null || sundryCodeFor.trim().length() > 0)
							{
								sundryCodeFor = "";
							}
							if("C".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "cust_name" , "customer", "cust_code", sundryCodeFor);
								custCity = findValue(conn, "city" , "customer", "cust_code", sundryCodeFor);
							}
							else if("R".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "case when first_name is null then middle_name when middle_name is null then last_name else first_name end as Name" , "strg_customer", "sc_code", sundryCodeFor);
								custCity = findValue(conn, "city" , "strg_customer", "sc_code", sundryCodeFor);
							}
							else if("B".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "bank_name" , "bank", "bank_code", sundryCodeFor);
								custCity = findValue(conn, "city" , "bank", "bank_code", sundryCodeFor);
							}
							else if("E".equalsIgnoreCase(sundryTypeFor))
							{
								mFname = findValue(conn, "emp_fname" , "employee", "emp_code", sundryCodeFor);
								mLname = findValue(conn, "emp_lname" , "employee", "emp_code", sundryCodeFor);
								custCity = findValue(conn, "cur_city" , "employee", "emp_code", sundryCodeFor);
								mdescr = mFname.trim() + "" + mLname.trim();
							}
							else if("P".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "sp_name" , "sales_pers", "sales_pers", sundryCodeFor);
								custCity = findValue(conn, "city" , "sales_pers", "sales_pers", sundryCodeFor);
							}
							else if("T".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "tran_name" , "transporter", "tran_code", sundryCodeFor);
								custCity = findValue(conn, "city" , "transporter", "tran_code", sundryCodeFor);
							}
							else if("O".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "descr" , "accounts", "acct_code", sundryCodeFor);
							}
							else if("S".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "supp_name" , "supplier", "supp_code", sundryCodeFor);
								custCity = findValue(conn, "city" , "supplier", "supp_code", sundryCodeFor);
							}
							else if("X".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "tauth_name", "tax_authority", "tauth_code", sundryCodeFor);
								custCity = findValue(conn, "city", "tax_authority", "tauth_code", sundryCodeFor);
							}
							else if("L".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "party_name", "loanparty", "party_code", sundryCodeFor);
								custCity = findValue(conn, "city", "loanparty", "party_code", sundryCodeFor);
							}
							else if("D".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "case when first_name is null then middle_name when middle_name is null then last_name else first_name end as Name", "strg_customer", "sc_code", sundryCodeFor);
								custCity = findValue(conn, "city", "strg_customer", "sc_code", sundryCodeFor);
							}
							valueXmlString.append("<sudcity>").append("<![CDATA[" + custCity + "]]>").append("</sudcity>");
							tranMode = genericUtility.getColumnValue("tran_mode", dom1);
							amount1 = genericUtility.getColumnValue("amount", dom);
							acctCode = genericUtility.getColumnValue("acct_code", dom);
							quantity = genericUtility.getColumnValue("quantity", dom);
							rate = genericUtility.getColumnValue("rate", dom);
							rateClg = genericUtility.getColumnValue("rate__clg", dom);
							billNo = genericUtility.getColumnValue("bill_no", dom);
							billDate = genericUtility.getColumnValue("bill_date", dom);
							billAmt1 = genericUtility.getColumnValue("bill_amt", dom);
							deptCode = genericUtility.getColumnValue("dept_code", dom);
							empCode = genericUtility.getColumnValue("emp_code", dom);
							cctrCode = genericUtility.getColumnValue("cctr_code", dom);
							analCode = genericUtility.getColumnValue("anal_code", dom);
							if((quantity == null) || (quantity.trim().length() == 0))
							{
								quantity = "";
							}
							if((rate == null) || (rate.trim().length() == 0))
							{
								rate = "";
							}
							if((rateClg == null) || (rateClg.trim().length() == 0))
							{
								rateClg = "";
							}
							if((billDate == null) || (billDate.trim().length() == 0))
							{
								billDate = "";
							}
							if((billNo == null) || (billNo.trim().length() == 0))
							{
								billNo = "";
							}
							if((billAmt1 == null) || (billAmt1.trim().length() == 0))
							{
								billAmt1 = "";
							}
							if((deptCode == null) || (deptCode.trim().length() == 0))
							{
								deptCode = "";
							}
							if((empCode == null) || (empCode.trim().length() == 0))
							{
								empCode = "";
							}
							if((cctrCode == null) || (cctrCode.trim().length() == 0))
							{
								cctrCode = "";
							}
							if((analCode == null) || (analCode.trim().length() == 0))
							{
								analCode = "";
							}
							if("A".equalsIgnoreCase(tranMode))
							{
								valueXmlString.append("<amount protect = \"1\">").append("<![CDATA[" + amount1 + "]]>").append ("</amount>");
								valueXmlString.append("<acct_code protect = \"1\">").append("<![CDATA[" + acctCode + "]]>").append ("</acct_code>");
								valueXmlString.append("<quantity protect = \"1\">").append("<![CDATA[" + quantity + "]]>").append ("</quantity>");
								valueXmlString.append("<rate protect = \"1\">").append("<![CDATA[" + rate + "]]>").append ("</rate>");
								valueXmlString.append("<rate__clg protect = \"1\">").append("<![CDATA[" + rateClg + "]]>").append ("</rate__clg>");
								valueXmlString.append("<sundry_type__for protect = \"1\">").append("<![CDATA[" + sundryTypeFor + "]]>").append ("</sundry_type__for>");
								valueXmlString.append("<sundry_code__for protect = \"1\">").append("<![CDATA[" + sundryCodeFor + "]]>").append ("</sundry_code__for>");
								valueXmlString.append("<bill_no protect = \"1\">").append("<![CDATA[" + billNo + "]]>").append ("</bill_no>");
								valueXmlString.append("<bill_date protect = \"1\">").append("<![CDATA[" + billDate + "]]>").append ("</bill_date>");
								valueXmlString.append("<bill_amt protect = \"1\">").append("<![CDATA[" + billAmt1 + "]]>").append ("</bill_amt>");
								valueXmlString.append("<dept_code protect = \"1\">").append("<![CDATA[" + deptCode + "]]>").append ("</dept_code>");
								valueXmlString.append("<emp_code protect = \"1\">").append("<![CDATA[" + empCode + "]]>").append ("</emp_code>");
						    }
							else
							{
								valueXmlString.append("<amount protect = \"0\">").append("<![CDATA[" + amount1 + "]]>").append ("</amount>");
								valueXmlString.append("<acct_code protect = \"0\">").append("<![CDATA[" + acctCode + "]]>").append ("</acct_code>");
								valueXmlString.append("<quantity protect = \"0\">").append("<![CDATA[" + quantity + "]]>").append ("</quantity>");
								valueXmlString.append("<rate protect = \"0\">").append("<![CDATA[" + rate + "]]>").append ("</rate>");
								valueXmlString.append("<rate__clg protect = \"0\">").append("<![CDATA[" + rateClg + "]]>").append ("</rate__clg>");
								valueXmlString.append("<sundry_type__for protect = \"0\">").append("<![CDATA[" + sundryTypeFor + "]]>").append ("</sundry_type__for>");
								valueXmlString.append("<sundry_code__for protect = \"0\">").append("<![CDATA[" + sundryCodeFor + "]]>").append ("</sundry_code__for>");
								valueXmlString.append("<bill_no protect = \"0\">").append("<![CDATA[" + billNo + "]]>").append ("</bill_no>");
								valueXmlString.append("<bill_date protect = \"0\">").append("<![CDATA[" + billDate + "]]>").append ("</bill_date>");
								valueXmlString.append("<bill_amt protect = \"0\">").append("<![CDATA[" + billAmt1 + "]]>").append ("</bill_amt>");
								valueXmlString.append("<dept_code protect = \"0\">").append("<![CDATA[" + deptCode + "]]>").append ("</dept_code>");
								valueXmlString.append("<emp_code protect = \"0\">").append("<![CDATA[" + empCode + "]]>").append ("</emp_code>");
								valueXmlString.append("<cctr_code protect = \"0\">").append("<![CDATA[" + cctrCode + "]]>").append ("</cctr_code>");
								valueXmlString.append("<anal_code protect = \"0\">").append("<![CDATA[" + analCode + "]]>").append ("</anal_code>");
						    }	
						}

						else if(currentColumn.trim().equalsIgnoreCase("amount"))
				        {
							amount1 = genericUtility.getColumnValue("amount", dom);
							ibFlag = true;
					    }

						else if(currentColumn.trim().equalsIgnoreCase("acct_code"))
				        {
							acctCode = genericUtility.getColumnValue("acct_code", dom);
							mdescr = findValue(conn, "descr" , "accounts", "acct_code",  acctCode);
							valueXmlString.append("<accounts_descr>").append("<![CDATA[" + mdescr + "]]>").append("</accounts_descr>");
							cctrCode = genericUtility.getColumnValue("cctr_code", dom);
							analCode = genericUtility.getColumnValue("anal_code", dom);
							deptCode = genericUtility.getColumnValue("dept_code", dom);
							mdescr = genericUtility.getColumnValue("tran_id", dom1);
							siteCode = genericUtility.getColumnValue("site_code", dom2);
							amount1 = genericUtility.getColumnValue("amount", dom);
							if(acctCode != null && cctrCode != null && (acctCode.trim().length() > 0 ) && (cctrCode.trim().length() > 0 ))
							{
								budgetAmtAnal = Double.parseDouble(getAmt(conn, "fn_get_budget_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'A')", "dual"));	
								consumedAmtAnal = Double.parseDouble(getAmt(conn, "fn_get_cons_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'A')", "dual"));	
								budgetAmtCctr = Double.parseDouble(getAmt(conn, "fn_get_budget_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'C')", "dual"));	 
								consumedAmtCctr = Double.parseDouble(getAmt(conn, "fn_get_cons_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'C')", "dual"));
								valueXmlString.append("<budget_amt_anal>").append("<![CDATA[" + budgetAmtAnal + "]]>").append("</budget_amt_anal>");
								valueXmlString.append("<consumed_amt_anal>").append("<![CDATA[" + consumedAmtAnal + "]]>").append("</consumed_amt_anal>");
								valueXmlString.append("<budget_amt_cctr>").append("<![CDATA[" + budgetAmtCctr + "]]>").append("</budget_amt_cctr>");
								valueXmlString.append("<consumed_amt_cctr>").append("<![CDATA[" + consumedAmtCctr + "]]>").append("</consumed_amt_cctr>");
								netBudget = budgetAmtAnal - consumedAmtAnal;
								valueXmlString.append("<net_budget>").append("<![CDATA[" + netBudget + "]]>").append("</net_budget>");
								if(netBudget != null && netBudget > 0)
								{
									compute2 = netBudget - Double.parseDouble(amount1);
							    }
								else
								{
									compute2 = 0.0;
							    }
								valueXmlString.append("<compute_2>").append("<![CDATA[" + compute2 + "]]>").append("</compute_2>");
								netBudgetCctr = budgetAmtCctr - consumedAmtCctr;
								valueXmlString.append("<net_budget_cctr>").append("<![CDATA[" + netBudget + "]]>").append("</net_budget_cctr>");
								if(netBudgetCctr > 0)
								{
									compute1 = netBudgetCctr - Double.parseDouble(amount1);
							    }
								else
								{
									compute1 = netBudgetCctr - Double.parseDouble(amount1);
							    }
									valueXmlString.append("<compute_1>").append("<![CDATA[" + compute1 + "]]>").append("</compute_1>");
							}
						}

						else if(currentColumn.trim().equalsIgnoreCase("sundry_code__for"))
				        {
							sundryCodeFor = genericUtility.getColumnValue("sundry_code__for", dom);
							sundryTypeFor = genericUtility.getColumnValue("sundry_type__for", dom);
							if("C".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "cust_name" , "customer", "cust_code", sundryCodeFor);
								custCity = findValue(conn, "city" , "customer", "cust_code", sundryCodeFor);
                            }
							else if("R".equalsIgnoreCase(sundryTypeFor))
						    {
								mdescr = findValue(conn, "case when first_name is null then middle_name when middle_name is null then last_name else first_name end as Name" , "strg_customer", "sc_code", sundryCodeFor);
								custCity = findValue(conn, "city" , "strg_customer", "sc_code", sundryCodeFor);
						    }
							else if("B".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "bank_name" , "bank", "bank_code", sundryCodeFor);
								custCity = findValue(conn, "city" , "bank", "bank_code", sundryCodeFor);
							}
							else if("E".equalsIgnoreCase(sundryTypeFor))
							{
								mFname = findValue(conn, "emp_fname" , "employee", "emp_code", sundryCodeFor);
								mLname = findValue(conn, "emp_lname" , "employee", "emp_code", sundryCodeFor);
								custCity = findValue(conn, "cur_city" , "employee", "emp_code", sundryCodeFor);
								mdescr = mFname.trim() + "" + mLname.trim();
							}
							else if("P".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "sp_name" , "sales_pers", "sales_pers", sundryCodeFor);
								custCity = findValue(conn, "city" , "sales_pers", "sales_pers", sundryCodeFor);
							}
							else if("T".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "tran_name" , "transporter", "tran_code", sundryCodeFor);
								custCity = findValue(conn, "city" , "transporter", "tran_code", sundryCodeFor);
							}
							else if("O".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "descr" , "accounts", "acct_code", sundryCodeFor);
							}
							else if("S".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "supp_name" , "supplier", "supp_code", sundryCodeFor);
								custCity = findValue(conn, "city" , "supplier", "supp_code", sundryCodeFor);
							}
							else if("X".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "tauth_name", "tax_authority", "tauth_code", sundryCodeFor);
								custCity = findValue(conn, "city", "tax_authority", "tauth_code", sundryCodeFor);
							}
							else if("L".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "party_name", "loanparty", "party_code", sundryCodeFor);
								custCity = findValue(conn, "city", "loanparty", "party_code", sundryCodeFor);
							}
							else if("D".equalsIgnoreCase(sundryTypeFor))
							{
								mdescr = findValue(conn, "case when first_name is null then middle_name when middle_name is null then last_name else first_name end as Name", "strg_customer", "sc_code", sundryCodeFor);
								custCity = findValue(conn, "city", "strg_customer", "sc_code", sundryCodeFor);
							}
							valueXmlString.append("<sudcity>").append("<![CDATA[" + custCity + "]]>").append("</sudcity>");
							valueXmlString.append("<sundry_name>").append("<![CDATA[" + mdescr + "]]>").append("</sundry_name>");
                        }
					   
						else if(currentColumn.trim().equalsIgnoreCase("cctr_code"))
				        {
							cctrCode = genericUtility.getColumnValue("cctr_code", dom);
							acctCode = genericUtility.getColumnValue("acct_code", dom);
							tranId = genericUtility.getColumnValue("tran_id", dom1);
							analCode = genericUtility.getColumnValue("anal_code", dom);
							deptCode = genericUtility.getColumnValue("dept_code", dom);
							siteCode = genericUtility.getColumnValue("site_code", dom2);
							amount1 = genericUtility.getColumnValue("amount", dom);
							if(cctrCode != null && acctCode != null && cctrCode.trim().length() > 0 && acctCode.trim().length() > 0)
							{
								budgetAmtAnal = Double.parseDouble(getAmt(conn, "fn_get_budget_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'A')", "dual"));	
								consumedAmtAnal = Double.parseDouble(getAmt(conn, "fn_get_cons_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'A')", "dual"));	
								budgetAmtCctr = Double.parseDouble(getAmt(conn, "fn_get_budget_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'C')", "dual"));	 
								consumedAmtCctr = Double.parseDouble(getAmt(conn, "fn_get_cons_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'C')", "dual"));
								budgetAmt = budgetAmtAnal;
								consumedAmt = consumedAmtAnal;
								valueXmlString.append("<budget_amt_cctr>").append("<![CDATA[" + budgetAmtCctr + "]]>").append("</budget_amt_cctr>");
								valueXmlString.append("<consumed_amt_cctr>").append("<![CDATA[" + consumedAmtCctr + "]]>").append("</consumed_amt_cctr>");
								if(budgetAmt == 0)
								{
									valueXmlString.append("<budget_amt_anal>").append("<![CDATA[" + "0" + "]]>").append("</budget_amt_anal>");
								}
								else
								{
									valueXmlString.append("<budget_amt_anal>").append("<![CDATA[" + budgetAmt + "]]>").append("</budget_amt_anal>");
								}
								if(consumedAmt != null && consumedAmt == 0)
								{
									valueXmlString.append("<consumed_amt_anal>").append("<![CDATA[" + "0" + "]]>").append("</consumed_amt_anal>");
								}
								else
								{
									valueXmlString.append("<consumed_amt_anal>").append("<![CDATA[" + consumedAmt + "]]>").append("</consumed_amt_anal>");
								}
								netBudget = budgetAmtAnal - consumedAmtAnal;
								if(netBudget == 0)
								{
									valueXmlString.append("<net_budget>").append("<![CDATA[" + "0" + "]]>").append("</net_budget>");
								}
								else
								{
									valueXmlString.append("<net_budget>").append("<![CDATA[" + netBudget + "]]>").append("</net_budget>");
								}
								if(netBudget != null && netBudget > 0)
								{
									compute2 = netBudget - Double.parseDouble(amount1);
								}
								else
								{
									compute2 = 0.0;
								}
								valueXmlString.append("<compute_2>").append("<![CDATA[" + compute2 + "]]>").append("</compute_2>");
								netBudgetCctr = budgetAmtCctr - consumedAmtCctr;
								valueXmlString.append("<net_budget_cctr>").append("<![CDATA[" + netBudget + "]]>").append("</net_budget_cctr>");
								if(netBudgetCctr > 0)
								{
									compute1 = netBudgetCctr - Double.parseDouble(amount1);
								}
								else
								{
									compute1 = 0.0;
								}
								valueXmlString.append("<compute_1>").append("<![CDATA[" + compute1 + "]]>").append("</compute_1>");
								mdescr = findValue(conn, "descr", "costctr", "cctr_code", cctrCode);
								valueXmlString.append("<costctr_descr>").append("<![CDATA[" + mdescr + "]]>").append("</costctr_descr>");
							}
						}

						else if(currentColumn.trim().equalsIgnoreCase("emp_code"))
				        {
							empCode = genericUtility.getColumnValue("emp_code", dom);
							deptCode = findValue(conn, "dept_code", "employee", "emp_code", empCode);
							valueXmlString.append("<dept_code>").append("<![CDATA[" + deptCode + "]]>").append("</dept_code>");
					    }

						else if(currentColumn.trim().equalsIgnoreCase("dept_code"))
				        {
							deptCode = genericUtility.getColumnValue("dept_code", dom);
							acctCode = genericUtility.getColumnValue("acct_code", dom);
							tranId = genericUtility.getColumnValue("tran_id", dom1);
							analCode = genericUtility.getColumnValue("anal_code", dom);
							cctrCode = genericUtility.getColumnValue("cctr_code", dom);
							siteCode = genericUtility.getColumnValue("site_code", dom2);
							amount1 = genericUtility.getColumnValue("amount", dom);
							if(deptCode != null && acctCode != null && deptCode.trim().length() > 0 && acctCode.trim().length() > 0)
							{
								budgetAmtAnal = Double.parseDouble(getAmt(conn, "fn_get_budget_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'A')", "dual"));	
								consumedAmtAnal = Double.parseDouble(getAmt(conn, "fn_get_cons_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'A')", "dual"));	
								budgetAmtCctr = Double.parseDouble(getAmt(conn, "fn_get_budget_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'C')", "dual"));	 
								consumedAmtCctr = Double.parseDouble(getAmt(conn, "fn_get_cons_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'C')", "dual"));
								budgetAmt = budgetAmtAnal;
								consumedAmt = consumedAmtAnal;
								valueXmlString.append("<budget_amt_cctr>").append("<![CDATA[" + budgetAmtCctr + "]]>").append("</budget_amt_cctr>");
								valueXmlString.append("<consumed_amt_cctr>").append("<![CDATA[" + consumedAmtCctr + "]]>").append("</consumed_amt_cctr>");
								if(budgetAmt != null && budgetAmt == 0)
								{
									valueXmlString.append("<budget_amt_anal>").append("<![CDATA[" + "0" + "]]>").append("</budget_amt_anal>");
								}
								else
								{
									valueXmlString.append("<budget_amt_anal>").append("<![CDATA[" + budgetAmt + "]]>").append("</budget_amt_anal>");
								}
								if(consumedAmt != null && consumedAmt == 0)
								{
									valueXmlString.append("<consumed_amt_anal>").append("<![CDATA[" + "0" + "]]>").append("</consumed_amt_anal>");
								}
								else
								{
									valueXmlString.append("<consumed_amt_anal>").append("<![CDATA[" + consumedAmt + "]]>").append("</consumed_amt_anal>");
								}
								netBudget = budgetAmtAnal - consumedAmtAnal;
								valueXmlString.append("<net_budget>").append("<![CDATA[" + netBudget + "]]>").append("</net_budget>");
								if(netBudget > 0)
								{
									compute2 = netBudget - Double.parseDouble(amount1);
								}
								else
								{
									compute2 = 0.0;
								}
								valueXmlString.append("<compute_2>").append("<![CDATA[" + compute2 + "]]>").append("</compute_2>");
								netBudgetCctr = budgetAmtCctr - consumedAmtCctr;
								valueXmlString.append("<net_budget_cctr>").append("<![CDATA[" + netBudget + "]]>").append("</net_budget_cctr>");
								if(netBudgetCctr != null && netBudgetCctr > 0)
								{
									compute1 = netBudgetCctr - Double.parseDouble(amount1);
								}
								else
								{
									compute1 = 0.0;
								}
								valueXmlString.append("<compute_1>").append("<![CDATA[" + compute1 + "]]>").append("</compute_1>");
								mdescr = findValue(conn, "descr", "department", "dept_code", deptCode);
								valueXmlString.append("<department_descr>").append("<![CDATA[" + mdescr + "]]>").append("</department_descr>");
							}
					    }

						else if(currentColumn.trim().equalsIgnoreCase("anal_code"))
				        {
							analCode = genericUtility.getColumnValue("anal_code", dom);
							acctCode = genericUtility.getColumnValue("acct_code", dom);
							tranId = genericUtility.getColumnValue("tran_id", dom1);
							deptCode = genericUtility.getColumnValue("dept_code", dom);
							cctrCode = genericUtility.getColumnValue("cctr_code", dom);
							siteCode = genericUtility.getColumnValue("site_code", dom2);
							amount1 = genericUtility.getColumnValue("amount", dom);
							budgetAmtAnal = Double.parseDouble(getAmt(conn, "fn_get_budget_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'A')", "dual"));	
							consumedAmtAnal = Double.parseDouble(getAmt(conn, "fn_get_cons_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'A')", "dual"));	
							budgetAmtCctr = Double.parseDouble(getAmt(conn, "fn_get_budget_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'C')", "dual"));	 
							consumedAmtCctr = Double.parseDouble(getAmt(conn, "fn_get_cons_amt('M-VOUC',",siteCode,acctCode,cctrCode,analCode,deptCode,"'C')", "dual"));
							valueXmlString.append("<budget_amt_anal>").append("<![CDATA[" + budgetAmtAnal + "]]>").append("</budget_amt_anal>");
							valueXmlString.append("<consumed_amt_anal>").append("<![CDATA[" + consumedAmtAnal + "]]>").append("</consumed_amt_anal>");
							netBudget = budgetAmtAnal - consumedAmtAnal;
							valueXmlString.append("<net_budget>").append("<![CDATA[" + netBudget + "]]>").append("</net_budget>");
							valueXmlString.append("<budget_amt_cctr>").append("<![CDATA[" + budgetAmtCctr + "]]>").append("</budget_amt_cctr>");
							valueXmlString.append("<consumed_amt_cctr>").append("<![CDATA[" + consumedAmtCctr + "]]>").append("</consumed_amt_cctr>");
							if(netBudget != null && netBudget > 0)
							{
								compute2 = netBudget - Double.parseDouble(amount1);
							}
							else
							{
								compute2 = 0.0;
						    }
							valueXmlString.append("<compute_2>").append("<![CDATA[" + compute2 + "]]>").append("</compute_2>");
							netBudgetCctr = budgetAmtCctr - consumedAmtCctr;
						    valueXmlString.append("<net_budget_cctr>").append("<![CDATA[" + netBudget + "]]>").append("</net_budget_cctr>");
							if(netBudgetCctr > 0)
							{
								compute1 = netBudgetCctr - Double.parseDouble(amount1);
							}
							else
							{
								compute1 = 0.0;
							}
							valueXmlString.append("<compute_1>").append("<![CDATA[" + compute1 + "]]>").append("</compute_1>");
                            mdescr = findValue(conn, "descr", "analysis", "anal_code", analCode);
							valueXmlString.append("<analysis_descr>").append("<![CDATA[" + mdescr + "]]>").append("</analysis_descr>");
						}

						else if(currentColumn.trim().equalsIgnoreCase("anal_code__1"))
				        {
							analCode1 = genericUtility.getColumnValue("anal_code__1", dom);
							mdescr = findValue(conn, "descr", "analysis", "anal_code", analCode1);
							valueXmlString.append("<analysis_descr_1>").append("<![CDATA[" + mdescr + "]]>").append("</analysis_descr_1>");
					    }

						else if(currentColumn.trim().equalsIgnoreCase("anal_code__2"))
				        {
							analCode2 = genericUtility.getColumnValue("anal_code__2", dom);
							mdescr = findValue(conn, "descr", "analysis", "anal_code", analCode2);
							valueXmlString.append("<analysis_descr_2>").append("<![CDATA[" + mdescr + "]]>").append("</analysis_descr_2>");
					    }
						valueXmlString.append("</Detail3>");
				        break;

				case 4 :
						parentNodeList = dom1.getElementsByTagName("Detail1");
						parentNode = parentNodeList.item(0);;
						parentNodeList = dom2.getElementsByTagName("Detail2");
						parentNode = parentNodeList.item(0);
						parentNodeList = dom.getElementsByTagName("Detail4");
						parentNode = parentNodeList.item(0);
						childNodeList = parentNode.getChildNodes();
						ctr = 0;
						valueXmlString.append("<Detail4>");
						childNodeListLength = childNodeList.getLength();
						do
						{   
							childNode = childNodeList.item(ctr);
							childNodeName = childNode.getNodeName();
							if(childNodeName.equals(currentColumn))
							{
								if(childNode.getFirstChild() != null)
								{
									columnValue = childNode.getFirstChild().getNodeValue().trim();
								}
							}
							ctr ++;
					    }while(ctr < childNodeListLength  && ! childNodeName.equals(currentColumn));
                      
						if(currentColumn.trim().equalsIgnoreCase("itm_default"))
				        {   
							vouchType = genericUtility.getColumnValue("vouch_type", dom2);
							if("A".equalsIgnoreCase(vouchType))
							{
								acctCodeAdv = genericUtility.getColumnValue("acct_code__adv", dom2);
								cctrCodeAdv = genericUtility.getColumnValue("cctr_code__adv", dom2);
								sundryType = genericUtility.getColumnValue("sundry_type", dom2);
								valueXmlString.append("<acct_code>").append("<![CDATA[" + acctCodeAdv + "]]>").append("</acct_code>");
								valueXmlString.append("<cctr_code>").append("<![CDATA[" + cctrCodeAdv + "]]>").append("</cctr_code>");
							} 
							else if("E".equalsIgnoreCase(vouchType) && "E".equalsIgnoreCase(sundryType))
							{
								sundryCode = genericUtility.getColumnValue("sundry_code", dom2);
								siteCode = genericUtility.getColumnValue("site_code", dom2);
								deptCode = findValue(conn, "dept_code" , "employee", "emp_code", sundryCode );
								acctCode = findValue(conn, "acct_code" , "department", "dept_code", deptCode );
								cctrCode = findValue(conn, "cctr_code" , "department", "dept_code", deptCode );
								if((acctCode != null && acctCode.trim().length() > 0) && (cctrCode != null && cctrCode.trim().length() > 0))
								{
									valueXmlString.append("<acct_code>").append("<![CDATA[" + acctCode + "]]>").append("</acct_code>");
									valueXmlString.append("<cctr_code>").append("<![CDATA[" + cctrCode + "]]>").append("</cctr_code>");
								}
								else
								{
									acctCode = findValue(conn, "a.acct_code__sal" , "employee a", "site b", "a.pay_site", "a.emp_code", "b.site_code", "b.site_code", sundryCode, siteCode);
									cctrCode = findValue(conn, "a.cctr_code__sal" , "employee a", "site b", "a.pay_site", "a.emp_code", "b.site_code", "b.site_code", sundryCode, siteCode);
									valueXmlString.append("<acct_code>").append("<![CDATA[" + acctCode + "]]>").append("</acct_code>");
									valueXmlString.append("<cctr_code>").append("<![CDATA[" + cctrCode + "]]>").append("</cctr_code>");
								}
							}
						}
						 
						else if(currentColumn.trim().equalsIgnoreCase("acct_code"))
				        {
							acctCode = genericUtility.getColumnValue("acct_code", dom);
							deptCode = findValue(conn, "descr", "accounts", "acct_code", acctCode);
						}
						valueXmlString.append("</Detail4>");
				        break;
            }
			valueXmlString.append("</Root>");
		}
		catch(Exception e)
		{
			e.printStackTrace();
			System.out.println("Exception ::"+ e.getMessage());
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				if(conn != null)
				{
					if(pstmt != null)
					pstmt.close();
					if(rs != null)
					rs.close();
					rs = null;
					pstmt = null;
					conn.close();
					conn = null;
				}
			}
			catch(Exception d)
			{
				d.printStackTrace();
			}			
		}
		return valueXmlString.toString();
	}	 

	private java.util.Date getDueDate(Connection conn ,SimpleDateFormat simpleDateFormat, String startFrom, String tranDate, String effDate, String billDate, int crDays) throws ITMException
	{
		Calendar cal = Calendar.getInstance();
		java.util.Date dueDate = null;
		try
		{
			
		  if("R".equalsIgnoreCase(startFrom))
			{
				cal.setTime((simpleDateFormat.parse(tranDate)));
				cal.getTime();
				cal.add(Calendar.DATE,crDays);
				dueDate = cal.getTime();
			}
			else if("D".equalsIgnoreCase(startFrom))
	        {
				cal.setTime((simpleDateFormat.parse(effDate)));
				cal.getTime();
				cal.add(Calendar.DATE,crDays);
				dueDate = cal.getTime();
            }
			else if("Q".equalsIgnoreCase(startFrom))
			{
				cal.setTime((simpleDateFormat.parse(effDate)));
				cal.getTime();
				cal.add(Calendar.DATE,crDays);
				dueDate = cal.getTime();
			}
			else if("B".equalsIgnoreCase(startFrom))
			{
				cal.setTime((simpleDateFormat.parse(billDate)));
				cal.getTime();
				cal.add(Calendar.DATE,crDays);
				dueDate = cal.getTime();
			}

		} 
		catch (ParseException e)
		{
			System.out.println("Exception in  date [duedate]"+e);
            e.printStackTrace();
            throw new ITMException(e);
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
		System.out.println("Returning Due date [duedate] from function"+dueDate);
		return dueDate;
	}

	private String getStanCode(Connection conn , String sundryType, String sundryCode) 
	{
		String stanCode = "";
		String empCode = "";
		try
		{
			if("O".equalsIgnoreCase(sundryType))
			{
				stanCode = "";
			}
			else if("T".equalsIgnoreCase(sundryType))
			{
				stanCode = findValue(conn, "stan_code" ,"transporter", "tran_code", sundryCode);
			}
			else if("B".equalsIgnoreCase(sundryType))
			{
				stanCode = "";
			}
			else if("X".equalsIgnoreCase(sundryType))
			{
				stanCode = findValue(conn, "stan_code" ,"tax_authority", "tauth_code", sundryCode);
			}
			else if("E".equalsIgnoreCase(sundryType))
			{
				stanCode = findValue(conn, "stan_code__hq" ,"employee", "emp_code", sundryCode);
			}
			else if("P".equalsIgnoreCase(sundryType))
			{
				empCode = findValue(conn, "emp_code" ,"sales_pers", "sales_pers", sundryCode);
				if(empCode != null && empCode.trim().length() > 0)
				{
					stanCode = findValue(conn, "stan_code" ,"employee", "emp_code", empCode);
				}
				else
				{
					stanCode = "";
				}
			} 
			else if("S".equalsIgnoreCase(sundryType))
			{
				stanCode = findValue(conn, "stan_code" ,"supplier", "supp_code", sundryCode);
			}
			else if("C".equalsIgnoreCase(sundryType))
			{
				stanCode = findValue(conn, "stan_code" ,"customer", "cust_code", sundryCode);
			}
			else if("R".equalsIgnoreCase(sundryType))
			{
				stanCode = findValue(conn, "stan_code" ,"strg_customer", "sc_code", sundryCode);
			}
			else if("L".equalsIgnoreCase(sundryType))
			{
				stanCode = findValue(conn, "stan_code" ,"loanparty", "party_code", sundryCode);
			}
			else if("D".equalsIgnoreCase(sundryType))
			{
				stanCode = findValue(conn, "stan_code" ,"strg_customer", "sc_code", sundryCode);
			}     
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
		return stanCode;
	}

	
	private String getAmt(Connection conn, String columnName ,String value1, String value2, String value3, String value4, String value5, String columnName1, String tableName) throws  ITMException, RemoteException
	{
		PreparedStatement pstmt = null ;
		ResultSet rs = null ; 
		String sql = "";
		String getAmt = "";
		try
		{			
			sql = "SELECT " + columnName + "?" + "," + "?" + "," + "?"+ "," + "?" + "," + "?" + "," + columnName1 + " from " + tableName ;
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,value1);
			pstmt.setString(2,value2);
			pstmt.setString(3,value3);
			pstmt.setString(4,value4);
			pstmt.setString(5,value5);
			rs = pstmt.executeQuery();
			if(rs.next())
			{					
				getAmt = rs.getString(1);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;		        
		}
		catch(Exception e)
		{
			System.out.println("Exception in getAmt ");
			e.printStackTrace();
			throw new ITMException(e); 
		}
		System.out.println("returning String from getAmt " + getAmt);
		return getAmt;
	}

	private String findValue(Connection conn, String columnName ,String tableName, String columnName2, String value) throws  ITMException, RemoteException
	{
		PreparedStatement pstmt = null ;
		ResultSet rs = null ; 
		String sql = "";
		String findValue = "";
		try
		{			
			sql = "SELECT " + columnName + " from " + tableName + " where " + columnName2 +"= ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,value);
			rs = pstmt.executeQuery();
			if(rs.next())
			{					
				findValue = rs.getString(1);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;	        
		}
		catch(Exception e)
		{
			System.out.println("Exception in findValue ");
			e.printStackTrace();
			throw new ITMException(e); 
		}
		System.out.println("returning String from findValue " + findValue);
		return findValue;
	}

	private String findValue(Connection conn, String columnName, String tableName, String columnName1, String columnName2, String value1, String value2) throws  ITMException, RemoteException
	{
		PreparedStatement pstmt = null ;
		ResultSet rs = null ; 
		String sql = "";
		String findValue = "";
		try
		{
			sql = "SELECT " + columnName + " from " + tableName + " where " + columnName1 +"= ?" + " and " + columnName2 +"= ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,value1);
			pstmt.setString(2,value2);
			rs = pstmt.executeQuery();
			if(rs.next())
			{					
				findValue = rs.getString(1);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;	        
		}
		catch(Exception e)
		{
			System.out.println("Exception in findValue ");
			e.printStackTrace();
			throw new ITMException(e); 
		}
		System.out.println("returning String from findValue " + findValue);
		return findValue;
	}
   

	private String findValue(Connection conn, String columnName, String tableName, String columnName1, String columnName2, String columnName3, String columnName4, String value1, String value2, String value3) throws  ITMException, RemoteException
	{
		PreparedStatement pstmt = null ;
		ResultSet rs = null ; 
		String sql = "";
		String findValue = "";
		try
		{
			sql = "SELECT " + columnName + " from " + tableName + " where " + columnName1 +"= ?" + " and " + columnName2 +"= ?" + " and " + columnName3 +"= ?" + " and " + columnName4;
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,value1);
			pstmt.setString(2,value2);
			pstmt.setString(3,value3);
			rs = pstmt.executeQuery();
			if(rs.next())
			{					
				findValue = rs.getString(columnName);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;	        
		}
		catch(Exception e)
		{
			System.out.println("Exception in findValue " + findValue);
			e.printStackTrace();
			throw new ITMException(e); 
		}
		System.out.println("returning String from findValue " + findValue);
		return findValue;
	}
	

	private String findValue(Connection conn, String columnName, String tableName1, String tableName2, String columnName1, String columnName2, String value1, String value2) throws  ITMException, RemoteException
	{
		PreparedStatement pstmt = null ;
		ResultSet rs = null ; 
		String sql = "";
		String findValue = "";
		try
		{
			sql = "SELECT " + columnName + " from " + tableName1 + "," + tableName2 + " where " + columnName1 +"= ?" + " and " + columnName2 +"= ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,value1);
			pstmt.setString(2,value2);
			rs = pstmt.executeQuery();
			if(rs.next())
			{					
				findValue = rs.getString(columnName);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;	        
		}
		catch(Exception e)
		{
			System.out.println("Exception in findValue ");
			e.printStackTrace();
			throw new ITMException(e); 
		}
		System.out.println("returning String from findValue " + findValue);
		return findValue;
	}

	private String findValue(Connection conn, String columnName, String tableName1, String tableName2, String tableName3, String columnName1, String columnName2, String columnName3, String value1, String value2, String value3) throws  ITMException, RemoteException
	{
		PreparedStatement pstmt = null ;
		ResultSet rs = null ; 
		String sql = "";
		String findValue = "";
		try
		{
			sql = "SELECT " + columnName + " from " + tableName1 + "," + tableName2 + "," + tableName3 + " where " + columnName1 + "= ?" + " and " + columnName2 + "= ?" + " and " + columnName3 + "= ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,value1);
			pstmt.setString(2,value2);
			pstmt.setString(3,value3);
			rs = pstmt.executeQuery();
			if(rs.next())
			{					
				findValue = rs.getString(columnName);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;	        
		}
		catch(Exception e)
		{
			System.out.println("Exception in findValue ");
			e.printStackTrace();
			throw new ITMException(e); 
		}
		System.out.println("returning String from findValue " + findValue);
		return findValue;
	}
	
	private String getAdjAmt(Connection conn, String columnName, String tableName, String columnName1, String columnName2, String value1, String value2) throws  ITMException, RemoteException
	{
		PreparedStatement pstmt = null ;
		ResultSet rs = null ; 
		String sql = "";
		String getAdjAmt = "";
		try
		{
			sql = "SELECT " + columnName + " from " + tableName + " where " + columnName1 +"= ?" + " and " + columnName2 +"= ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,value1);
			pstmt.setString(2,value2);
			rs = pstmt.executeQuery();
			if(rs.next())
			{					
				getAdjAmt = rs.getString(1);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;	        
		}
		catch(Exception e)
		{
			System.out.println("Exception in getAdjAmt ");
			e.printStackTrace();
			throw new ITMException(e); 
		}
		System.out.println("returning String from getAdjAmt " + getAdjAmt);
		return getAdjAmt;
	}
	
	private String findCodes(String columnName, String tableName, String columnName1, String columnName2, String columnName3, String value1, String value2, String value3, Connection conn) throws  ITMException, RemoteException
	{
		PreparedStatement pstmt = null ;
		ResultSet rs = null ; 
		String sql = "";
		String findCodes = "";
		try
		{
			sql = "SELECT " + columnName + " from " + tableName + " where " + columnName1 +"=?" + " and " + columnName2 + "=?" + " and " + columnName3 + "=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,value1);
			pstmt.setString(2,value2);
			pstmt.setString(3,value3);
			rs = pstmt.executeQuery();
			if(rs.next())
			{					
				findCodes = rs.getString(columnName);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;	        
		}
		catch(Exception e)
		{
			System.out.println("Exception in findCodes ");
			e.printStackTrace();
			throw new ITMException(e); 
		}
		System.out.println("returning String from findCodes ");
		return findCodes;
	}

	private Double findSum(Connection conn, String columnName, String tableName, String columnName1, String columnName2, String columnName3, String columnName4, String value1, String value2) throws  ITMException, RemoteException
	{

		PreparedStatement pstmt = null ;
		ResultSet rs = null ; 
		String sql = "";
		Double findSum = 0.0;
		try
		{
			sql = "SELECT " + columnName + " from " + tableName + " where " + columnName1 +"= ?" + " and " + columnName2 + " and " + columnName3 + " and " + columnName4 + "= ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,value1);
			pstmt.setString(2,value2);
			rs = pstmt.executeQuery();
	    	if(rs.next())
			{					
				findSum = rs.getDouble(1);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;	        
		}
		catch(Exception e)
		{
			System.out.println("Exception in findSum ");
			e.printStackTrace();
			throw new ITMException(e); 
		}
		System.out.println("returning Double from findSum " + findSum);
		return findSum;
	}

	private Double findExch(String columnName, String tableName, String columnName1, String columnName2,  String value1, String value2, java.sql.Timestamp value3 ,Connection conn) throws  ITMException, RemoteException
	{
		PreparedStatement pstmt = null ;
		ResultSet rs = null ; 
		String sql = "";
		Double findExch = 0.0;
		try
		{
			sql = "SELECT " + columnName + " from " + tableName +  " where " + columnName1 + "= ?" + " and " + columnName2 + "= ?" + " and " + "?" + " between from_date and to_date";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,value1);
			pstmt.setString(2,value2);
			pstmt.setTimestamp(3,value3);
			rs = pstmt.executeQuery();
			if(rs.next())
			{					
				findExch = rs.getDouble(columnName);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;	        
		}
		catch(Exception e)
		{
			System.out.println("Exception in findExch ");
			e.printStackTrace();
			throw new ITMException(e); 
		}
		System.out.println("returning Double from findExch " + findExch);
		return findExch;
	}

	private String getCode(Connection conn, String columnName ,String tableName) throws  ITMException, RemoteException
	{
		PreparedStatement pstmt = null ;
		ResultSet rs = null ; 
		String sql = "";
		String getCode = "";
		try
		{			
			sql = "SELECT " + columnName + " from " + "?" ;
			pstmt =  conn.prepareStatement(sql);
			pstmt.setString(1,tableName);
			rs = pstmt.executeQuery();
			if(rs.next())
			{					
				getCode = rs.getString(columnName);
			}
			rs.close();
			rs = null;
			pstmt.close();
			pstmt = null;	        
		}
		catch(Exception e)
		{
			System.out.println("Exception in getCode ");
			e.printStackTrace();
			throw new ITMException(e); 
		}
		System.out.println("returning String from getCode " + getCode);
		return getCode;
	}

	private String errorType(Connection conn , String errorCode)
	{
		String msgType = "";
		PreparedStatement pstmt = null ; 
		ResultSet rs = null;
		try
		{			
			String  sql = "SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ?";
			pstmt = conn.prepareStatement(sql);			
			pstmt.setString(1,errorCode);			
			rs = pstmt.executeQuery();
			while(rs.next())
			{
				msgType = rs.getString("MSG_TYPE");
			}			
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}		
		finally
		{
			try
			{
				if(rs != null)
				{
					rs.close();
					rs = null;
				}
				if(pstmt != null)
				{
					pstmt.close();
					pstmt = null;
				}
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}		
		return msgType;
	}

	private String getObjName(Node node) throws Exception
	{
		String objName = null;
		NodeList nodeList = null;
		Node detaulNode = null;
		Node detailNode = null;
		nodeList = node.getChildNodes();
		NamedNodeMap attrMap = node.getAttributes();
		objName = attrMap.getNamedItem( "objName" ).getNodeValue();
		return "w_" + objName;
	}
	
}	
	