
package ibase.webitm.ejb.wms;

import java.rmi.RemoteException;
import java.util.*;
import java.util.Date;
import java.sql.*;
import java.io.*;

import org.omg.CORBA.ORB;
import org.w3c.dom.*;
import java.util.Properties;

import javax.swing.text.NumberFormatter;
import javax.xml.parsers.*;
import javax.ejb.*;
import javax.naming.InitialContext;

import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.TransIDGenerator;

import ibase.utility.BaseException;
import ibase.utility.CommonConstants;
import ibase.ejb.*;
import ibase.system.config.*;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.*;
//Change by Rohan 0n 04/04/12 [WM1FSUN005]For implementing Maths opreration
import java.math.*;
import java.net.InetAddress;

@javax.ejb.Stateless
public class PhysicalCountPrcEJB extends ProcessEJB implements PhysicalCountPrcLocal,PhysicalCountPrcRemote //SessionBean
{
	
	GenericUtility genericUtility = GenericUtility.getInstance();
	ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
	//ConnDriver connDriver = new ConnDriver();
	CommonConstants commonConstants = new CommonConstants();
	String chgUser = null;
	String chgTerm = null;
	static long count_records=0;
	boolean isError = false;
	//Change by Rohan on 2/7/12
	String loginSiteCode = "";
	
	static ArrayList tranIdList= new ArrayList();
	static ArrayList itemCodeList= new ArrayList();
	static ArrayList analysisClassList= new ArrayList();
	static ArrayList currentDateList= new ArrayList();
	static ArrayList numberOfItemProcessRecordsList= new ArrayList();
	static ArrayList chgUserList= new ArrayList();
	static ArrayList currentDate1List= new ArrayList();
	static ArrayList clientIpList= new ArrayList();


	

	//ArrayList holidayListB = new ArrayList();
	public String process() throws RemoteException,ITMException
	{
		return "";
	}

	private Connection getConnection()throws BaseException
	{
		Connection con = null;
		try
		{
			ConnDriver connDriver = new ConnDriver();
			con = connDriver.getConnectDB(CommonConstants.WRKFLW_DB);
		}
		catch(BaseException be)
		{
			throw be;
		}
		catch (Exception e)
		{
			throw new BaseException(e);
		}
		return con;
	}
	
	private String generateTranId( String windowName, Connection conn )throws
	ITMException
	    {
	                PreparedStatement pstmt = null;
	                ResultSet rs = null;
	                String selSql = "";
	                String tranId = "";
	                String tranSer = "";
	                String keyString = "";
	                String keyCol = "";
	                String xmlValues = "";
	                String paySiteCode = "";
	                String effectiveDate = "";

	                java.sql.Date effDate = null;

	                 try
	         {
	                        selSql = "SELECT KEY_STRING, TRAN_ID_COL, REF_SER FROM TRANSETUP WHERE	TRAN_WINDOW = ? ";
	                                //System.out.println("selSql :"+selSql);
	                        pstmt = conn.prepareStatement(selSql);
	                        pstmt.setString( 1, windowName );
	                        rs = pstmt.executeQuery();
	                        if (rs.next())
	                        {
	                                        keyString = rs.getString("KEY_STRING");
	                                        keyCol = rs.getString("TRAN_ID_COL");
	                                        tranSer = rs.getString("REF_SER");
	                        }
	                        rs.close();
	                        rs = null;
	                        pstmt.close();
	                        pstmt = null;
	                        System.out.println("keyString :"+keyString);
	                        System.out.println("keyCol :"+keyCol);
	                        System.out.println("tranSer :"+tranSer);

	                        xmlValues ="<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>";
	                        xmlValues = xmlValues + "<Header></Header>";
	                        xmlValues = xmlValues + "<Detail1>";
	                        xmlValues = xmlValues +        "<tran_id></tran_id>";
	                        xmlValues = xmlValues + "</Detail1></Root>";
	                        System.out.println("xmlValues  :["+xmlValues+"]");
	                        TransIDGenerator tg = new TransIDGenerator(xmlValues, "BASE",
	CommonConstants.DB_NAME);
	                        tranId = tg.generateTranSeqID(tranSer, keyCol, keyString, conn);
	                        System.out.println("tranId :"+tranId);
	         }
	                catch (SQLException ex)
	                {
	                        System.out.println("Exception ::" +selSql+ ex.getMessage() + ":");
	                        ex.printStackTrace();
	                        throw new ITMException(ex);
	                }
	                catch (Exception e)
	                {
	                        System.out.println("Exception ::" + e.getMessage() + ":");
	                        e.printStackTrace();
	                        throw new ITMException(e);
	                }
	                finally
	                {
	                        try
	                        {
	                                if (rs != null)
	                                {
	                                        rs.close();
	                                        rs = null;
	                                }
	                                if (pstmt != null)
	                                {
	                                        pstmt.close();
	                                        pstmt = null;
	                                }
	                        }
	                        catch(Exception e){}
	                }
	        return tranId;
	     }//generateTranTd()
	
	//getData Method
	public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
	{
		String rtrStr = "";
		Document headerDom = null;
		Document detailDom = null;
		System.out.println("getData(xmlString,xmlString2,windowName,xtraParams CALLED..."+ xmlString);
		try
		{
			if(xmlString != null && xmlString.trim().length()!=0)
			{
				System.out.println("XML String :"+xmlString);
				headerDom = genericUtility.parseString(xmlString); 				
			}
			if(xmlString2 != null && xmlString2.trim().length()!=0)
			{
				System.out.println("XML String :"+xmlString2);
				detailDom = genericUtility.parseString(xmlString2); 				
			}
			System.out.println("Before calling getData ");
			rtrStr = getData(headerDom, detailDom, windowName, xtraParams);
			System.out.println("After calling getData ");
		}
		catch (Exception e)
		{
			System.out.println("Exception :PhysicalCountPrcEJB :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
			rtrStr = e.getMessage();
		}
		return rtrStr; 
	}

	public String getData(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
	{
		String resultString = "";
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String siteCode = "";
		String invStat = "";
		String dateFrom = "";
		String dateTo = "";
		String analysisClass = "";
		String errString = "";
		String sSQL = "";
		int seq = 0, count1 = 0;
		
		java.util.Date orderDate = new java.util.Date();
		//Changed by Rohan on 10-MAR-2012 [WM1FSUN005] To get current date
		java.util.Date todayDate = new java.util.Date();
		StringBuffer xmlString = new StringBuffer();
		Timestamp dateToTs = null;
		Timestamp dateFrmTs = null;
		
		//Changed By Pragyan 1/12/2012.start
		String itemCode = "";
		String lotNo = "";
		String lotSl = "";
		String locCode = "";
		String clientIp="";
		String machineName="";
		String tranId="";
		String queryString="";
		//Changed By Pragyan 1/12/2012.end
		
		
		PreparedStatement pstmtInsert = null;
		
		java.sql.Date chgDate=null;
		
		String currentMonthInString="";
		String currentQuarterMonth1InString="";
		String currentQuarterMonth2InString="";
		String currentHalfYearMonth1InString="";
		String currentHalfYearMonth2InString="";
		String currentHalfYearMonth3InString="";
		String insertItemProcess="";
		
		
		
		int currentMonth=0;
		int currentYear=0;
		int numberOfItemsA=0;
		int numberOfItemsB=0;
		int numberOfItemsC=0;
		int numberOfWorkingDaysA=0;
		int numberOfWorkingDaysB=0;
		int numberOfWorkingDaysC=0;
		int numberOfItemsPerdayA=0;
		int numberOfItemsPerdayB=0;
		int numberOfItemsPerdayC=0;
		int numberOfItemsPerdayATemp=0;
		int numberOfItemsPerdayA_rem=0;
		int numberOfItemsPerdayBTemp=0;
		int numberOfItemsPerdayB_rem=0;
		int numberOfItemsPerdayCTemp=0;
		int numberOfItemsPerdayC_rem=0;	
		int numberOfItemProcessRecords=0;
		int noOfRecordsToday = 0;
		int iA=0;
		int iB=0;
		int iC=0;
		
		try
		{
			//ConnDriver connDriver = new ConnDriver();
			//SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getDBDateFormat());
			//conn = connDriver.getConnectDB("DriverITM");
			
			//loginSiteCode = genericUtility.getColumnValue("site_code",headerDom);
			loginSiteCode = genericUtility.getValueFromXTRA_PARAMS( xtraParams, "loginSiteCode" );
			System.out.println("loginSiteCode="+loginSiteCode);
			String loginEmpCode = genericUtility.getValueFromXTRA_PARAMS( xtraParams, "loginEmpCode" );
			
			
			clientIp = InetAddress.getLocalHost().getHostAddress();
			machineName = InetAddress.getLocalHost().getHostName();
			
			conn = getConnection();
			conn.setAutoCommit(false);
			tranId=generateTranId("w_item_process",conn);			
			queryString="select count(*) from item_process where to_date(tran_date,'DD-MON-YY')=to_date(sysdate,'DD-MON-YY')";
			pstmt=conn.prepareStatement(queryString);
			rs=pstmt.executeQuery();
			if(rs.next())
			{
				noOfRecordsToday = rs.getInt(1);
			}
			
			if(pstmt!=null)
			{
				pstmt.close();
				pstmt=null;
			}
			
			if(rs!=null)
			{
				rs.close();
				rs=null;
			}
			
			if(noOfRecordsToday>0)
			{
				System.out.println("Already Records Inserted");
			}
			else
			{
				
			
				chgUser="WMS";
				todayDate = new java.util.Date();
				
				todayDate=new java.util.Date();
				System.out.println("date="+todayDate);
				String month="";
				String dStr=todayDate.toString();
				System.out.println("dStr="+dStr);
				System.out.println("Month="+dStr.substring(4,7));
				month=dStr.substring(4,7).toUpperCase();
				System.out.println("Month="+month);
				System.out.println("Year="+dStr.substring(dStr.length()-4));
				currentYear=Integer.parseInt(dStr.substring(dStr.length()-2));
				System.out.println("currentYear="+currentYear);
				
				if(month.equals("JAN"))
				{
					currentMonthInString="JAN";
					currentQuarterMonth1InString="FEB";
					currentQuarterMonth2InString="MAR";
					currentHalfYearMonth1InString="OCT";
					currentHalfYearMonth2InString="NOV";
					currentHalfYearMonth3InString="DEC";
				}
				else
				if(month.equals("FEB"))
				{
					currentMonthInString="FEB";
					currentQuarterMonth1InString="JAN";
					currentQuarterMonth2InString="MAR";
					currentHalfYearMonth1InString="OCT";
					currentHalfYearMonth2InString="NOV";
					currentHalfYearMonth3InString="DEC";	
				}
				else
				if(month.equals("MAR"))
				{
					currentMonthInString="MAR";
					currentQuarterMonth1InString="FEB";
					currentQuarterMonth2InString="JAN";
					currentHalfYearMonth1InString="OCT";
					currentHalfYearMonth2InString="NOV";
					currentHalfYearMonth3InString="DEC";
				}
				else
				if(month.equals("APR"))
				{
					currentMonthInString="APR";
					currentQuarterMonth1InString="MAY";
					currentQuarterMonth2InString="JUN";
					currentHalfYearMonth1InString="JUL";
					currentHalfYearMonth2InString="AUG";
					currentHalfYearMonth3InString="SEP";		
				}
				else
				if(month.equals("MAY"))
				{
					currentMonthInString="MAY";
					currentQuarterMonth1InString="APR";
					currentQuarterMonth2InString="JUN";
					currentHalfYearMonth1InString="JUL";
					currentHalfYearMonth2InString="AUG";
					currentHalfYearMonth3InString="SEP";	
				}
				else
				if(month.equals("JUN"))
				{
					currentMonthInString="JUN";
					currentQuarterMonth1InString="MAY";
					currentQuarterMonth2InString="APR";
					currentHalfYearMonth1InString="JUL";
					currentHalfYearMonth2InString="AUG";
					currentHalfYearMonth3InString="SEP";		
				}
				else
				if(month.equals("JUL"))
				{
					currentMonthInString="JUL";
					currentQuarterMonth1InString="AUG";
					currentQuarterMonth2InString="SEP";
					currentHalfYearMonth1InString="APR";
					currentHalfYearMonth2InString="MAY";
					currentHalfYearMonth3InString="JUN";	
				}
				else
				if(month.equals("AUG"))
				{
					currentMonthInString="AUG";
					currentQuarterMonth1InString="JUL";
					currentQuarterMonth2InString="SEP";
					currentHalfYearMonth1InString="APR";
					currentHalfYearMonth2InString="MAY";
					currentHalfYearMonth3InString="JUN";			
				}
				else
				if(month.equals("SEP"))
				{
					currentMonthInString="SEP";
					currentQuarterMonth1InString="AUG";
					currentQuarterMonth2InString="JUL";
					currentHalfYearMonth1InString="APR";
					currentHalfYearMonth2InString="MAY";
					currentHalfYearMonth3InString="JUN";			
				}
				else
				if(month.equals("OCT"))
				{
					currentMonthInString="OCT";
					currentQuarterMonth1InString="NOV";
					currentQuarterMonth2InString="DEC";
					currentHalfYearMonth1InString="JAN";
					currentHalfYearMonth2InString="FEB";
					currentHalfYearMonth3InString="MAR";					
				}
				else
				if(month.equals("NOV"))
				{
					currentMonthInString="NOV";
					currentQuarterMonth1InString="OCT";
					currentQuarterMonth2InString="DEC";
					currentHalfYearMonth1InString="JAN";
					currentHalfYearMonth2InString="FEB";
					currentHalfYearMonth3InString="MAR";						
				}
				else
				if(month.equals("DEC"))
				{
					currentMonthInString="DEC";
					currentQuarterMonth1InString="NOV";
					currentQuarterMonth2InString="OCT";
					currentHalfYearMonth1InString="JAN";
					currentHalfYearMonth2InString="FEB";
					currentHalfYearMonth3InString="MAR";					
				}
				
				System.out.println("currentMonthInString="+currentMonthInString);
				
				
				
				queryString="select count(*) from item where analysis_class='A' and item_code not in (select item_code from item_process where analysis_class='A' and to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?)";
				pstmt=conn.prepareStatement(queryString);
				pstmt.setString(1,currentMonthInString);
				pstmt.setInt(2,currentYear);
				
				rs=pstmt.executeQuery();
				
				while(rs.next())
				{
					numberOfItemsA=rs.getInt(1);
				}
				
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
				
				queryString="select count(*) from item where analysis_class='B' and item_code not in (select item_code from item_process where analysis_class='B' and ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) ) )";
				pstmt=conn.prepareStatement(queryString);
				pstmt.setString(1,currentMonthInString);
				pstmt.setInt(2,currentYear);
				pstmt.setString(3,currentQuarterMonth1InString);
				pstmt.setInt(4,currentYear);
				pstmt.setString(5,currentQuarterMonth2InString);
				pstmt.setInt(6,currentYear);
				
				rs=pstmt.executeQuery();
				while(rs.next())
				{
					numberOfItemsB=rs.getInt(1);
				}			
	
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
				
				if( month.equals("APR") || month.equals("MAY") || month.equals("JUN") || month.equals("JUL") || month.equals("AUG") || month.equals("SEP") )
				{
					queryString="select count(*) from item where analysis_class='C' and item_code not in (select item_code from item_process where analysis_class='C' and ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) ) )";
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,currentMonthInString);
					pstmt.setInt(2,currentYear);
					pstmt.setString(3,currentQuarterMonth1InString);
					pstmt.setInt(4,currentYear);
					pstmt.setString(5,currentQuarterMonth2InString);
					pstmt.setInt(6,currentYear);
					pstmt.setString(7,currentHalfYearMonth1InString);
					pstmt.setInt(8,currentYear);
					pstmt.setString(9,currentHalfYearMonth2InString);
					pstmt.setInt(10,currentYear);
					pstmt.setString(11,currentHalfYearMonth3InString);
					pstmt.setInt(12,currentYear);
				}
				else
				if( month.equals("JAN") || month.equals("FEB") || month.equals("MAR") )
				{
					queryString="select count(*) from item where analysis_class='C' and item_code not in (select item_code from item_process where analysis_class='C' and ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) ) )";
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,currentMonthInString);
					pstmt.setInt(2,currentYear);
					pstmt.setString(3,currentQuarterMonth1InString);
					pstmt.setInt(4,currentYear);
					pstmt.setString(5,currentQuarterMonth2InString);
					pstmt.setInt(6,currentYear);
					pstmt.setString(7,currentHalfYearMonth1InString);
					pstmt.setInt(8,(currentYear-1));
					pstmt.setString(9,currentHalfYearMonth2InString);
					pstmt.setInt(10,(currentYear-1));
					pstmt.setString(11,currentHalfYearMonth3InString);
					pstmt.setInt(12,(currentYear-1));
				}
				else
				if( month.equals("OCT") || month.equals("NOV") || month.equals("DEC") )
				{	
					queryString="select count(*) from item where analysis_class='C' and item_code not in (select item_code from item_process where analysis_class='C' and ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) ) )";
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,currentMonthInString);
					pstmt.setInt(2,currentYear);
					pstmt.setString(3,currentQuarterMonth1InString);
					pstmt.setInt(4,currentYear);
					pstmt.setString(5,currentQuarterMonth2InString);
					pstmt.setInt(6,currentYear);
					pstmt.setString(7,currentHalfYearMonth1InString);
					pstmt.setInt(8,(currentYear+1));
					pstmt.setString(9,currentHalfYearMonth2InString);
					pstmt.setInt(10,(currentYear+1));
					pstmt.setString(11,currentHalfYearMonth3InString);
					pstmt.setInt(12,(currentYear+1));
				}
				rs=pstmt.executeQuery();
				while(rs.next())
				{
					numberOfItemsC=rs.getInt(1);
				}
	
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
				//Change by Rohan on 7/2/12 To add site Code 
				//queryString="select count(distinct(work_date)) from work_calendar where WORKING='Y' and WORK_DATE>=to_date(sysdate,'DD-MON-YY') and WORK_DATE like '%"+currentMonthInString+"%' and to_char(WORK_DATE, 'YY')=?";
				queryString="select count(distinct(work_date)) from work_calendar where WORKING='Y' and WORK_DATE>=to_date(sysdate,'DD-MON-YY') "
					+" and site_code = ? and WORK_DATE like '%"+currentMonthInString+"%' and to_char(WORK_DATE, 'YY')=?";
				pstmt=conn.prepareStatement(queryString);
				//Change by Rohan on 7/2/12 To add site Code 
				//pstmt.setInt(1,currentYear);
				pstmt.setString(1,loginSiteCode);
				pstmt.setInt(2,currentYear);
				//System.out.println("HELLO11");
				rs=pstmt.executeQuery();
				while(rs.next())
				{
					numberOfWorkingDaysA=rs.getInt(1);
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
				//Changed by Rohan on 2/7/12
				//queryString="select count(distinct(work_date)) from work_calendar where WORKING='Y' and WORK_DATE>=to_date(sysdate,'DD-MON-YY') and (WORK_DATE like '%"+currentMonthInString+"%' or WORK_DATE like '%"+currentQuarterMonth1InString+"%' or WORK_DATE like '%"+currentQuarterMonth2InString+"%') and to_char(WORK_DATE, 'YY')=?";
				queryString="select count(distinct(work_date)) from work_calendar where WORKING='Y' and WORK_DATE>=to_date(sysdate,'DD-MON-YY') "
					     +" and site_code = ? and (WORK_DATE like '%"+currentMonthInString+"%' or WORK_DATE like '%"+currentQuarterMonth1InString+"%' or WORK_DATE like '%"+currentQuarterMonth2InString+"%') and to_char(WORK_DATE, 'YY')=?";
				pstmt=conn.prepareStatement(queryString);
				pstmt.setString(1,loginSiteCode);
				pstmt.setInt(2,currentYear);
				rs=pstmt.executeQuery();
				while(rs.next())
				{
					numberOfWorkingDaysB=rs.getInt(1);
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
				
				if( month.equals("APR") || month.equals("MAY") || month.equals("JUN") || month.equals("JUL") || month.equals("AUG") || month.equals("SEP") )
				{
					//Changed by Rohan on 2/7/12.start
					//queryString="select count(distinct(work_date)) from work_calendar where WORKING='Y' and WORK_DATE>=to_date(sysdate,'DD-MON-YY') and (WORK_DATE like '%"+currentMonthInString+"%' or WORK_DATE like '%"+currentQuarterMonth1InString+"%' or WORK_DATE like '%"+currentQuarterMonth2InString+"%' or WORK_DATE like '%"+currentHalfYearMonth1InString+"%' or WORK_DATE like '%"+currentHalfYearMonth2InString+"%' or WORK_DATE like '%"+currentHalfYearMonth3InString+"%') and to_char(WORK_DATE, 'YY')=?";
					queryString="select count(distinct(work_date)) from work_calendar where WORKING='Y' and WORK_DATE>=to_date(sysdate,'DD-MON-YY') "
						+" and site_code = ? and (WORK_DATE like '%"+currentMonthInString+"%' or WORK_DATE like '%"+currentQuarterMonth1InString+"%' or WORK_DATE like '%"+currentQuarterMonth2InString+"%' or WORK_DATE like '%"+currentHalfYearMonth1InString+"%' or WORK_DATE like '%"+currentHalfYearMonth2InString+"%' or WORK_DATE like '%"+currentHalfYearMonth3InString+"%') and to_char(WORK_DATE, 'YY')=?";
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,loginSiteCode);
					pstmt.setInt(2,currentYear);
				}
				else
				if( month.equals("JAN") || month.equals("FEB") || month.equals("MAR") )
				{
					//Change by Rohan on 7/2/12
					//queryString="select count(distinct(work_date)) from work_calendar where WORKING='Y' and WORK_DATE>=to_date(sysdate,'DD-MON-YY') and ( ( (WORK_DATE like '%"+currentMonthInString+"%' or WORK_DATE like '%"+currentQuarterMonth1InString+"%' or WORK_DATE like '%"+currentQuarterMonth2InString+"%' ) and to_char(WORK_DATE, 'YY')='"+currentYear+"') or ( ( WORK_DATE like '%"+currentHalfYearMonth1InString+"%' or WORK_DATE like '%"+currentHalfYearMonth2InString+"%' or WORK_DATE like '%"+currentHalfYearMonth3InString+"%') and to_char(WORK_DATE, 'YY')=? ) ) ";
					queryString="select count(distinct(work_date)) from work_calendar where WORKING='Y' and WORK_DATE>=to_date(sysdate,'DD-MON-YY') "
						+"  and site_code = ?  and ( ( (WORK_DATE like '%"+currentMonthInString+"%' or WORK_DATE like '%"+currentQuarterMonth1InString+"%' or WORK_DATE like '%"+currentQuarterMonth2InString+"%' ) and to_char(WORK_DATE, 'YY')='"+currentYear+"') or ( ( WORK_DATE like '%"+currentHalfYearMonth1InString+"%' or WORK_DATE like '%"+currentHalfYearMonth2InString+"%' or WORK_DATE like '%"+currentHalfYearMonth3InString+"%') and to_char(WORK_DATE, 'YY')=? ) ) ";
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,loginSiteCode);
					pstmt.setInt(2,currentYear);
				}
				else
				if( month.equals("OCT") || month.equals("NOV") || month.equals("DEC") )
				{
					//Change by Rohan on 2/7/12.start
					//queryString="select count(distinct(work_date)) from work_calendar where WORKING='Y' and WORK_DATE>=to_date(sysdate,'DD-MON-YY') and ( ( (WORK_DATE like '%"+currentMonthInString+"%' or WORK_DATE like '%"+currentQuarterMonth1InString+"%' or WORK_DATE like '%"+currentQuarterMonth2InString+"%' ) and to_char(WORK_DATE, 'YY')='"+currentYear+"') or ( ( WORK_DATE like '%"+currentHalfYearMonth1InString+"%' or WORK_DATE like '%"+currentHalfYearMonth2InString+"%' or WORK_DATE like '%"+currentHalfYearMonth3InString+"%') and to_char(WORK_DATE, 'YY')=? ) ) ";
					queryString="select count(distinct(work_date)) from work_calendar where WORKING='Y' and WORK_DATE>=to_date(sysdate,'DD-MON-YY') "
						+" and site_code = ?  and ( ( (WORK_DATE like '%"+currentMonthInString+"%' or WORK_DATE like '%"+currentQuarterMonth1InString+"%' or WORK_DATE like '%"+currentQuarterMonth2InString+"%' ) and to_char(WORK_DATE, 'YY')='"+currentYear+"') or ( ( WORK_DATE like '%"+currentHalfYearMonth1InString+"%' or WORK_DATE like '%"+currentHalfYearMonth2InString+"%' or WORK_DATE like '%"+currentHalfYearMonth3InString+"%') and to_char(WORK_DATE, 'YY')=? ) ) ";
					
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,loginSiteCode);
					pstmt.setInt(2,currentYear);
				}
				rs=pstmt.executeQuery();
				while(rs.next())
				{
					numberOfWorkingDaysC=rs.getInt(1);
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
							
				System.out.println("numberOfItemsA="+numberOfItemsA);
				System.out.println("numberOfItemsB="+numberOfItemsB);
				System.out.println("numberOfItemsC="+numberOfItemsC);
				System.out.println("numberOfWorkingDaysA="+numberOfWorkingDaysA);
				System.out.println("numberOfWorkingDaysB="+numberOfWorkingDaysB);
				System.out.println("numberOfWorkingDaysC="+numberOfWorkingDaysC);
				
				
				//Changed by Rohan on 7/2/12
				//if(numberOfItemsA>0)
				if(numberOfItemsA > 0 && numberOfWorkingDaysA > 0)
				{
					numberOfItemsPerdayATemp=(numberOfItemsA/numberOfWorkingDaysA);
					numberOfItemsPerdayA_rem=(numberOfItemsA%numberOfWorkingDaysA);
					if(numberOfItemsPerdayA_rem > (numberOfWorkingDaysA/2) )
						numberOfItemsPerdayA=numberOfItemsPerdayATemp+1;
					else
						numberOfItemsPerdayA=numberOfItemsPerdayATemp;				
				}
				//Changed by Rohan on 7/2/12
				//if(numberOfItemsB>0)
				if(numberOfItemsB > 0 && numberOfWorkingDaysB > 0)
				{
					numberOfItemsPerdayBTemp=(numberOfItemsB/numberOfWorkingDaysB);
					numberOfItemsPerdayB_rem=(numberOfItemsB%numberOfWorkingDaysB);
					if(numberOfItemsPerdayB_rem > (numberOfWorkingDaysB/2) )
						numberOfItemsPerdayB=numberOfItemsPerdayBTemp+1;
					else
						numberOfItemsPerdayB=numberOfItemsPerdayBTemp;				
				}
				//Changed by Rohan on 7/2/12
				//if(numberOfItemsC>0)
				if(numberOfItemsC > 0 && numberOfWorkingDaysC > 0 )
				{
					numberOfItemsPerdayCTemp=(numberOfItemsC/numberOfWorkingDaysC);
					numberOfItemsPerdayC_rem=(numberOfItemsC%numberOfWorkingDaysC);
					if(numberOfItemsPerdayC_rem > (numberOfWorkingDaysC/2) )
						numberOfItemsPerdayC=numberOfItemsPerdayCTemp+1;
					else
						numberOfItemsPerdayC=numberOfItemsPerdayCTemp;				
				}
				
				//java.sql.Date currTrandate = new java.sql.Date( System.currentTimeMillis() );
				///*
				
	
				System.out.println("numberOfItemsPerdayA="+numberOfItemsPerdayA);
				System.out.println("numberOfItemsPerdayB="+numberOfItemsPerdayB);
				System.out.println("numberOfItemsPerdayC="+numberOfItemsPerdayC);
				
				/*queryString="select count(*) from item_process";
				pstmt=conn.prepareStatement(queryString);
				rs=pstmt.executeQuery();
				
				if(rs.next())
				{
					numberOfItemProcessRecords=rs.getInt(1);
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}*/
				numberOfItemProcessRecords=0;
				System.out.println("HELLO");
				queryString="select ITEM_CODE,ANALYSIS_CLASS,SITE_CODE,LOC_CODE,CHG_USER,CHG_TERM,to_date(CHG_DATE,'DD-MON-YY') CHG_DATE from item where analysis_class='A' and item_code not in (select item_code from item_process where analysis_class='A' and to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?)";
				pstmt=conn.prepareStatement(queryString);
				pstmt.setString(1,currentMonthInString);
				pstmt.setInt(2,currentYear);
				System.out.println("HELLO1");
				rs=pstmt.executeQuery();
				System.out.println("HELLO2");
				iA=0;
				java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
				java.sql.Timestamp currentDate1 = new java.sql.Timestamp(System.currentTimeMillis());
				System.out.println("currentDate============="+currentDate);
				System.out.println("currentDate1============="+currentDate1);
				while(rs.next() && iA < numberOfItemsPerdayA)
				{
					numberOfItemProcessRecords++;
					itemCode=rs.getString("ITEM_CODE");
					System.out.println("itemCode="+itemCode);
					analysisClass=rs.getString("ANALYSIS_CLASS");
					System.out.println("analysisClass="+analysisClass);
					siteCode=rs.getString("SITE_CODE");
					System.out.println("siteCode="+siteCode);
					locCode=rs.getString("LOC_CODE");
					System.out.println("locCode="+locCode);
					chgTerm=rs.getString("CHG_TERM");
					System.out.println("HELLO3");
					siteCode = siteCode != null?siteCode:"";
					System.out.println("HELLO4");
					xmlString.append(tranId).append("\t");
					xmlString.append(itemCode).append("\t");
					xmlString.append(analysisClass).append("\t");
					xmlString.append(currentDate).append("\t");
					xmlString.append(numberOfItemProcessRecords).append("\t");
					xmlString.append(chgUser).append("\t");
					xmlString.append(currentDate1).append("\t");
					xmlString.append(clientIp).append("\t");
					xmlString.append("\n");
					tranIdList.add(tranId);
					itemCodeList.add(itemCode);
					analysisClassList.add(analysisClass);
					currentDateList.add(currentDate);
					numberOfItemProcessRecordsList.add(numberOfItemProcessRecords);
					chgUserList.add(chgUser);
					currentDate1List.add(currentDate1);
					clientIpList.add(clientIp);
					System.out.println("HELLO5");
					/*insertItemProcess="insert into item_process(TRAN_ID,item_code,analysis_class,tran_date," +
							"priority_seq,CHG_USER,CHG_DATE,CHG_TERM) " +
							"values(?,?,?,?,?,?,?,?)";
					pstmtInsert = conn.prepareStatement(insertItemProcess);
					
					pstmtInsert.setString(1,tranId);
					pstmtInsert.setString(2,itemCode);
					pstmtInsert.setString(3,analysisClass);
					pstmtInsert.setDate(4,currentDate);
					//pstmtInsert.setString(5,siteCode);
					//pstmtInsert.setString(6,locCode);
					pstmtInsert.setInt(5,numberOfItemProcessRecords);
					pstmtInsert.setString(6,chgUser);
					pstmtInsert.setTimestamp(7,currentDate1);
					pstmtInsert.setString(8,clientIp);
					int updatedRecords = pstmtInsert.executeUpdate();
					System.out.println("HELLO5");
					//Changed by Rohan on 2/7/12
					if(pstmtInsert != null)
					{
						pstmtInsert.close();
						pstmtInsert = null;
					}*/
					iA++;
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				/*if(pstmtInsert!=null)
				{
					pstmtInsert.close();
					pstmtInsert=null;
				}*/
				
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
				
				queryString="select ITEM_CODE,ANALYSIS_CLASS,SITE_CODE,LOC_CODE,CHG_USER,CHG_TERM,to_date(CHG_DATE,'DD-MON-YY') CHG_DATE from item where analysis_class='B' and item_code not in (select item_code from item_process where analysis_class='B' and ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) ))";
				pstmt=conn.prepareStatement(queryString);
				pstmt.setString(1,currentMonthInString);
				pstmt.setInt(2,currentYear);
				pstmt.setString(3,currentQuarterMonth1InString);
				pstmt.setInt(4,currentYear);
				pstmt.setString(5,currentQuarterMonth2InString);
				pstmt.setInt(6,currentYear);
				rs=pstmt.executeQuery();
				iB=0;
				while(rs.next() && iB<numberOfItemsPerdayB)
				{
					numberOfItemProcessRecords++;
					itemCode=rs.getString("ITEM_CODE");
					analysisClass=rs.getString("ANALYSIS_CLASS");
					siteCode=rs.getString("SITE_CODE");
					locCode=rs.getString("LOC_CODE");		
					chgTerm=rs.getString("CHG_TERM");
					tranIdList.add(tranId);
					itemCodeList.add(itemCode);
					analysisClassList.add(analysisClass);
					currentDateList.add(currentDate);
					numberOfItemProcessRecordsList.add(numberOfItemProcessRecords);
					chgUserList.add(chgUser);
					currentDate1List.add(currentDate1);
					clientIpList.add(clientIp);
					xmlString.append(tranId).append("\t");
					xmlString.append(itemCode).append("\t");
					xmlString.append(analysisClass).append("\t");
					xmlString.append(currentDate).append("\t");
					xmlString.append(numberOfItemProcessRecords).append("\t");
					xmlString.append(chgUser).append("\t");
					xmlString.append(currentDate1).append("\t");
					xmlString.append(clientIp).append("\t");
					xmlString.append("\n");
					/*
					insertItemProcess="insert into item_process(TRAN_ID,item_code,analysis_class,tran_date," +
					"priority_seq,CHG_USER,CHG_DATE,CHG_TERM) " +
					"values(?,?,?,?,?,?,?,?)";
					pstmtInsert = conn.prepareStatement(insertItemProcess);
					pstmtInsert.setString(1,tranId);
					pstmtInsert.setString(2,itemCode);
					pstmtInsert.setString(3,analysisClass);
					pstmtInsert.setDate(4,currentDate);
					//pstmtInsert.setString(5,siteCode);
					//pstmtInsert.setString(6,locCode);
					pstmtInsert.setInt(5,numberOfItemProcessRecords);
					pstmtInsert.setString(6,chgUser);
					pstmtInsert.setTimestamp(7,currentDate1);
					pstmtInsert.setString(8,clientIp);
					int updatedRecords = pstmtInsert.executeUpdate();
					if(pstmtInsert != null)
					{
						pstmtInsert.close();
						pstmtInsert = null;
					}*/
					iB++;
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				/*if(pstmtInsert!=null)
				{
					pstmtInsert.close();
					pstmtInsert=null;
				}*/
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
				
				if( month.equals("APR") || month.equals("MAY") || month.equals("JUN") || month.equals("JUL") || month.equals("AUG") || month.equals("SEP") )
				{
					queryString="select ITEM_CODE,ANALYSIS_CLASS,SITE_CODE,LOC_CODE,CHG_USER,CHG_TERM,to_date(CHG_DATE,'DD-MON-YY')" +
							" CHG_DATE from item where analysis_class='C' and item_code not in " +
							" (select item_code from item_process where analysis_class='C' and " +
							" ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=?" +
							"  and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) " +
							" or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? " +
							" and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) ))";
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,currentMonthInString);
					pstmt.setInt(2,currentYear);
					pstmt.setString(3,currentQuarterMonth1InString);
					pstmt.setInt(4,currentYear);
					pstmt.setString(5,currentQuarterMonth2InString);
					pstmt.setInt(6,currentYear);
					pstmt.setString(7,currentHalfYearMonth1InString);
					pstmt.setInt(8,currentYear);
					pstmt.setString(9,currentHalfYearMonth2InString);
					pstmt.setInt(10,currentYear);
					pstmt.setString(11,currentHalfYearMonth3InString);
					pstmt.setInt(12,currentYear);
									
				}
				else
				if( month.equals("JAN") || month.equals("FEB") || month.equals("MAR") )
				{
					queryString="select ITEM_CODE,ANALYSIS_CLASS,SITE_CODE,LOC_CODE,CHG_USER,CHG_TERM,to_date(CHG_DATE,'DD-MON-YY') " +
							" CHG_DATE from item where analysis_class='C' and item_code not in " +
							" (select item_code from item_process where analysis_class='C' and " +
							" ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? " +
							" and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or" +
							"  ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and " +
							" to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) ))";
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,currentMonthInString);
					pstmt.setInt(2,currentYear);
					pstmt.setString(3,currentQuarterMonth1InString);
					pstmt.setInt(4,currentYear);
					pstmt.setString(5,currentQuarterMonth2InString);
					pstmt.setInt(6,currentYear);
					pstmt.setString(7,currentHalfYearMonth1InString);
					pstmt.setInt(8,(currentYear-1));
					pstmt.setString(9,currentHalfYearMonth2InString);
					pstmt.setInt(10,(currentYear-1));
					pstmt.setString(11,currentHalfYearMonth3InString);
					pstmt.setInt(12,(currentYear-1));
				
					
				}
				else
				if( month.equals("OCT") || month.equals("NOV") || month.equals("DEC") )
				{
					queryString="select ITEM_CODE,ANALYSIS_CLASS,SITE_CODE,LOC_CODE,CHG_USER,CHG_TERM,to_date(CHG_DATE,'DD-MON-YY') CHG_DATE from item where analysis_class='C' and item_code not in (select item_code from item_process where analysis_class='C' " +
							" and ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? " +
							" and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and " +
							" to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) " +
							" or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? " +
							" and to_char(tran_DATE, 'yy')=?) ))";
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,currentMonthInString);
					pstmt.setInt(2,currentYear);
					pstmt.setString(3,currentQuarterMonth1InString);
					pstmt.setInt(4,currentYear);
					pstmt.setString(5,currentQuarterMonth2InString);
					pstmt.setInt(6,currentYear);
					pstmt.setString(7,currentHalfYearMonth1InString);
					pstmt.setInt(8,(currentYear+1));
					pstmt.setString(9,currentHalfYearMonth2InString);
					pstmt.setInt(10,(currentYear+1));
					pstmt.setString(11,currentHalfYearMonth3InString);
					pstmt.setInt(12,(currentYear+1));
				
					
				}
				rs = pstmt.executeQuery();
				
				iC=0;
				while(rs.next() && iC < numberOfItemsPerdayC)
				{
					numberOfItemProcessRecords++;
					itemCode=rs.getString("ITEM_CODE");
					analysisClass=rs.getString("ANALYSIS_CLASS");
					siteCode=rs.getString("SITE_CODE");
					locCode=rs.getString("LOC_CODE");	
					
					//dateInString = new SimpleDateFormat("dd-MMM-yy").format(chgDate);
					chgTerm=rs.getString("CHG_TERM");
					
					tranIdList.add(tranId);
					itemCodeList.add(itemCode);
					analysisClassList.add(analysisClass);
					currentDateList.add(currentDate);
					numberOfItemProcessRecordsList.add(numberOfItemProcessRecords);
					chgUserList.add(chgUser);
					currentDate1List.add(currentDate1);
					clientIpList.add(clientIp);
					xmlString.append(tranId).append("\t");
					xmlString.append(itemCode).append("\t");
					xmlString.append(analysisClass).append("\t");
					xmlString.append(currentDate).append("\t");
					xmlString.append(numberOfItemProcessRecords).append("\t");
					xmlString.append(chgUser).append("\t");
					xmlString.append(currentDate1).append("\t");
					xmlString.append(clientIp).append("\t");
					xmlString.append("\n");
					/*
					insertItemProcess="insert into item_process(TRAN_ID,item_code,analysis_class,tran_date," +
					"priority_seq,CHG_USER,CHG_DATE,CHG_TERM) " +
					"values(?,?,?,?,?,?,?,?)";
					pstmtInsert = conn.prepareStatement(insertItemProcess);
					pstmtInsert.setString(1,tranId);
					pstmtInsert.setString(2,itemCode);
					pstmtInsert.setString(3,analysisClass);
					pstmtInsert.setDate(4,currentDate);
					//pstmtInsert.setString(5,siteCode);
					//pstmtInsert.setString(6,locCode);
					pstmtInsert.setInt(5,numberOfItemProcessRecords);
					pstmtInsert.setString(6,chgUser);
					pstmtInsert.setTimestamp(7,currentDate1);
					pstmtInsert.setString(8,clientIp);
					int updatedRecords = pstmtInsert.executeUpdate();*/
					iC++;
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				/*if(pstmtInsert!=null)
				{
					pstmtInsert.close();
					pstmtInsert=null;
				}*/
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
				
				
				}
			
			
			
			resultString=xmlString.toString();
			System.out.println("resultString>>>>["+resultString+"]<<<<<");			
		
		}
		catch (SQLException e)
		{
			//System.out.println("SQLException :StockAllocationPrcEJB :getData(Document headerDom, Document detailDom, String windowName, String xtraParams):" + e.getMessage() + ":");
			//throw new ITMException(e);
		}
		catch (Exception e)
		{
			System.out.println("Exception :StockAllocationPrcEJB :getData(Document headerDom, Document detailDom, String windowName, String xtraParams):" + e.getMessage() + ":");
			throw new ITMException(e);
		}
		finally
		{
			
			System.out.println("in finally");
			try
			{
				if(pstmt != null)
				{
					pstmt.close();
					pstmt=null;
				}
				System.out.println("in finally before conn close");
				if(conn != null)
				{					
					System.out.println("in finally conn closeing");
					conn.close();
					System.out.println("in finally conn closeing 1");
					conn = null;					
					System.out.println("in finally conn closeing 2");
				}
				System.out.println("in finally after conn close");
			}
			catch(Exception e)
			{
				errString = e.getMessage();
				e.printStackTrace();
				throw new ITMException(e);
			}
		}		
		return resultString;	
	}
	//Changed by Rohan on 23-Mar-12 To implementating monthly logic.start
	private ArrayList<String> monthlySchedule(Connection conn,String invStat,String siteCode,Date dateSchedule,String loginEmpCode)
	{
		System.out.println("ENTER IN MONTHLY SCHEDULE=====================================>");
		//String lastDateStr = "";
		String lastDateStr = "";
		String firstDateStr = "";
		String monthEnd = "";
		String sqlWorking = "";
		String sqlholiday = "";
		String itemsql = "";
		String fileName = "monthlySchedule.txt";
		String sqlInsert = "";
		String sqlUpdate = "";
		String sqlIns = "";
		int workingDays = 0;
		int holidays = 0;
		int noOfDays = 0;
		
		boolean flag = false; 
		
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		ArrayList itemListA = new ArrayList();
		ArrayList holidayList  = new ArrayList();
		  
		Calendar calendar = Calendar.getInstance();
		java.util.Date checkDate = new java.util.Date();
		java.sql.Date lastDate = null;
		FileOutputStream fos1 = null;
			
		NumberFormat nf = NumberFormat.getNumberInstance();
		
		try
		{
			
			/*
			//Convert Two days in java.sql.Date.start
			java.sql.Date sqlDate = new java.sql.Date(checkDate.getTime());
			java.sql.Date sqlDateCmp = null;
			System.out.println("ENTER IN TRYsqlDate"+sqlDate);
			System.out.println("DATE SCHEDULE["+dateSchedule+"]");
			//if(!(dateSchedule.toString().equalsIgnoreCase("")))
			if(dateSchedule != null)
			{	
			    sqlDateCmp = new java.sql.Date(dateSchedule.getTime());
			    System.out.println("ENTER IN TRYsqlDatesqlDateCmp"+sqlDateCmp);
			}	
			//Convert Two days in java.sql.Date.end
			System.out.println("sqlDate.toString()"+sqlDate.toString()+"sqlDateCmp.toString()"+sqlDateCmp.toString());
			if(sqlDateCmp == null  || sqlDate.toString().equalsIgnoreCase(sqlDateCmp.toString()))
			{	
			*/
			  //Convert Two days in java.sql.Date.start
			java.sql.Date sqlDate = new java.sql.Date(checkDate.getTime());
			java.sql.Date sqlDateCmp = null;
			
			if(dateSchedule != null)
			{	
			    sqlDateCmp = new java.sql.Date(dateSchedule.getTime());
			}	
		    //Convert Two days in java.sql.Date.end
			
		   if(sqlDateCmp == null || sqlDate.toString().equalsIgnoreCase(sqlDateCmp.toString()))
		   {
				flag = true;
				
				java.util.Date startDate = new java.util.Date();
				//java.util.Date startDate = new java.util.Date();
				   java.sql.Date startDateSql = new java.sql.Date(startDate.getTime());
			   
				monthEnd = "SELECT ADD_MONTHS(TO_DATE(?),1) AS NEXT_SCHEDULE_DATE from DUAL";
				pstmt = conn.prepareStatement(monthEnd);
				pstmt.setDate(1,sqlDate);		
		    	rs = pstmt.executeQuery();
		    	if(rs.next())
		    	{
		    		lastDate = rs.getDate("NEXT_SCHEDULE_DATE");
		    	}  	
						
		    	if(rs!=null) 
				{
					rs.close();
					rs = null;
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt = null;
				}
			   
				sqlWorking = "SELECT TO_DATE(?) - TO_DATE(?) NO_OF_DAYS FROM DUAL";
				pstmt = conn.prepareStatement(sqlWorking);
				pstmt.setDate(1,lastDate);
				pstmt.setDate(2,sqlDate);
				
		    	rs = pstmt.executeQuery();
		    	if(rs.next())
		    	{
		    		noOfDays = rs.getInt("NO_OF_DAYS");
		    	}
		    	//coding for holidays from Calender.start
		    	
		    	java.sql.Date sqlDateHolidayList = new java.sql.Date(startDate.getTime());
		    	holidayList = getHolidayList( conn, loginEmpCode, sqlDateHolidayList ,noOfDays );
		    	System.out.println("======NO OF HOLIDAYS FOR MONTHLY SCHEDULY==="+holidayList.size());
		    	holidays = holidayList.size();
		    	//coding for holidays from Calender.end
		    	
		    	workingDays = noOfDays-holidays;
	
			   //sql to find out working days in months.end
				
			   System.out.println("NO OF Working Days FOR MONTHLY SCHEDULY============>"+workingDays);
			   ibase.webitm.utility.GenericUtility genericUtility = ibase.webitm.utility.GenericUtility.getInstance();
			   SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
			   
			   /*
			   fos1 = new FileOutputStream(CommonConstants.JBOSSHOME + File.separator +"WMS"+File.separator+fileName);
              			  
               firstDateStr = sdf.format(startDate)+"\n";
               lastDateStr = sdf.format(lastDate)+"\n";
			  
			   fos1.write(firstDateStr.getBytes());
			   fos1.write(lastDateStr.getBytes());
			   //Convert int to string.start
			   
			   String workDay = nf.format(workingDays)+"\n";
			   fos1.write(workDay.getBytes());
			   */
			   
			   if(pstmt!=null)
			   {
					pstmt.close();
					pstmt = null;
			   }
			   if(sqlDateCmp == null)
               {
					sqlInsert = "INSERT INTO DATESCHEDULE(analysis_class,start_date,end_date,working_days)"
			               +" VALUES(?,?,?,?) ";
               }
			   else
               {
				   sqlInsert = "UPDATE DATESCHEDULE SET start_date = ?,end_date = ?,working_days = ? "
				   +" WHERE analysis_class = ?";
			   }
				   
			   pstmt = conn.prepareStatement(sqlInsert);
			   if(sqlDateCmp == null)
               {
				   pstmt.setString(1,"A");
				   pstmt.setDate(2,startDateSql);
				   pstmt.setDate(3,lastDate);
				   pstmt.setInt(4,workingDays);
			   }
			   else
               {
				   pstmt.setDate(1,startDateSql);
				   pstmt.setDate(2,lastDate);
				   pstmt.setInt(3,workingDays);
				   pstmt.setString(4,"A");
			   }
		       int count = pstmt.executeUpdate();
		       if(count == 1)
		       {
		    	   conn.commit();
		       }
			  
		   }
		   if(pstmt != null)
	       {
	    	 pstmt.close();
	    	 pstmt = null;
	        }
	    	if(rs != null)
	    	{ 
	    		rs.close();
	    		rs = null;
	    	}
			itemsql = "SELECT ITEM_CODE FROM ITEM WHERE ANALYSIS_CLASS= ? ";
			pstmt =conn.prepareStatement(itemsql);
			pstmt.setString(1,"A");  
	        rs= pstmt.executeQuery();
	        while(rs.next())
	        { 
	        	itemListA.add(rs.getString("ITEM_CODE"));
	           	
	        }
	        if(flag)
	        { 
	        	 
	        	 int noOfItemPerDay = 0;
	        	 int noOfDayPerItem = 0;
	        	 if(itemListA.size() >= workingDays)
		    	 {
		    		noOfItemPerDay = (int) Math.ceil(itemListA.size()/workingDays);
		    	 }
		    	 else
		    	 {
		    		 noOfDayPerItem = (int) Math.ceil(workingDays/itemListA.size());
		         }
	        	 if(noOfItemPerDay != 0)
	        	 {
	        		 /*
	        		 String noOfItemPerDays = nf.format(noOfItemPerDay)+"\n";
	        		 fos1.write(noOfItemPerDays.getBytes());
	        		 */
	        		 if(pstmt!=null)
	  			   	 {
	 					pstmt.close();
	 					pstmt = null;
	  			   	 }
	        		 
	        		 sqlIns = "INSERT INTO DATESCHEDULE(no_of_item)"
	        				 +" VALUES(?) "
	        		         +" WHERE ANALYSIS_CLASS = ?";
	        	     pstmt = conn.prepareStatement(sqlIns);
	        	     pstmt.setInt(1,noOfItemPerDay);
	        	     pstmt.setString(1,"A"); 	
	  			   
	  		         int count = pstmt.executeUpdate();
	  		         if(count == 1)
	  		         {
	  		    	   conn.commit();
	  		         }
	        	 }
	        	 else
	        	 {
	        		 noOfDayPerItem = -(noOfDayPerItem); 
	        		 /*
	        		 String noOfDayPerItems = nf.format(noOfDayPerItem)+"\n";
	        		 fos1.write(noOfDayPerItems.getBytes());
	        		 */
	        		 sqlIns = "INSERT INTO DATESCHEDULE(no_of_item)"
	        				 +" VALUES(?) "
	        		         +" WHERE ANALYSIS_CLASS = ?";
	        	     pstmt = conn.prepareStatement(sqlIns);
	        	     pstmt.setInt(1,noOfDayPerItem);
	        	     pstmt.setString(1,"A"); 	
	  			   
	  		         int count = pstmt.executeUpdate();
	  		         if(count == 1)
	  		         {
	  		    	   conn.commit();
	  		         }
	        	 }
	        	 
	        }
		   	  
		}
		catch(Exception e )
		{
			   System.out.println("Error"+e);
		}
	    
		
    return itemListA; 
	}
	//Changed by Rohan on 23-Mar-12 To implementating monthly logic.end
    //Coding start Quartly 
	//Changed by Rohan on 23-Mar-12 To implementating Quarly logic.start
	private ArrayList<String> quartlySchedule(Connection conn,String invStat,String siteCode,Date dateSchedule,String loginEmpCode)
	{
		System.out.println("ENTER IN Quartly SCHEDULE=====================================>");
		FileOutputStream fos1 = null;

		String lastDateStr = null;
		String firstDateStr = null;
		String monthEnd = "";
		String sqlWorking = "";
		String sqlholiday = "";
		String itemsql = "";
		
		String sqlInsert = "";
		String sqlIns = "";
		
		String sqlUpdate = "";
		String sqlUpd = "";

		
		int workingDays = 0;
		int holidays = 0;
		int noOfDays = 0;
		
		boolean flg = false; 
		
		java.sql.Date lastDate = null;
		Calendar calendar = Calendar.getInstance();
		java.util.Date checkDate = new java.util.Date();
		
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		ArrayList itemListB = new ArrayList();
		ArrayList holidayListB = new ArrayList();
		
		NumberFormat nf = NumberFormat.getNumberInstance();
		
		String fileName = "quartlySchedule.txt";
		try
		{
		   //Convert Two days in java.sql.Date.start
			java.sql.Date sqlDate = new java.sql.Date(checkDate.getTime());
			java.sql.Date sqlDateCmp = null;
			if(dateSchedule != null)
			{	
			    sqlDateCmp = new java.sql.Date(dateSchedule.getTime());
			}	
		    //Convert Two days in java.sql.Date.end
			
		   if(sqlDateCmp == null || sqlDate.toString().equalsIgnoreCase(sqlDateCmp.toString()))
		   {	
			   flg = true;
			   
			   java.util.Date startDate = new java.util.Date();
			   java.sql.Date startDateSql = new java.sql.Date(startDate.getTime());
			   
			   //sql to find out last date of month
				monthEnd = "SELECT ADD_MONTHS(TO_DATE(?),3) AS NEXT_SCHEDULE_DATE from DUAL";
				pstmt = conn.prepareStatement(monthEnd);
				pstmt.setDate(1,sqlDate);		
		    	rs = pstmt.executeQuery();
		    	if(rs.next())
		    	{
		    		lastDate = rs.getDate("NEXT_SCHEDULE_DATE");
		    	}  	
						
		    	if(rs!=null) 
				{
					rs.close();
					rs = null;
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt = null;
				}
			   
		    	
				sqlWorking = "SELECT TO_DATE(?) - TO_DATE(?) NO_OF_DAYS FROM DUAL";
				pstmt = conn.prepareStatement(sqlWorking);
				pstmt.setDate(1,lastDate);
				pstmt.setDate(2,sqlDate);
		    	rs = pstmt.executeQuery();
		    	if(rs.next())
		    	{
		    		noOfDays = rs.getInt("NO_OF_DAYS");//working dates in months
		    	}
		    	//coding for holidays from Calender.start
		    	java.sql.Date sqlDateHolidayList = new java.sql.Date(startDate.getTime());
		    
		    	holidayListB = getHolidayList( conn, loginEmpCode, sqlDateHolidayList ,noOfDays );
		    	System.out.println("======NO OF HOLIDAYS in Quarter==="+holidayListB.size());
		    	holidays = holidayListB.size();
		    	//coding for holidays from Calender.end
		    	workingDays = noOfDays-holidays;
				//sql to find out working days in months.end
				
			   System.out.println(" No OF WORKING DAYS in Quartly==========>"+workingDays);
			   /*
			   ibase.webitm.utility.GenericUtility genericUtility = ibase.webitm.utility.GenericUtility.getInstance();
			   SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
			   
			   fos1 = new FileOutputStream(CommonConstants.JBOSSHOME + File.separator +"WMS"+File.separator+fileName);
               			  
               firstDateStr = sdf.format(startDate)+"\n";
               lastDateStr = sdf.format(lastDate)+"\n";
			   
			   fos1.write(firstDateStr.getBytes());
			   
			   fos1.write(lastDateStr.getBytes());
			   //Convert int to string.start
			   
			   String workDay = nf.format(workingDays)+"\n";
			   fos1.write(workDay.getBytes());
			   */
			   System.out.println(" GOING FOR DATESCHEDULE");
			   if(pstmt!=null)
			   {
					pstmt.close();
					pstmt = null;
			   }
			   if(sqlDateCmp == null)
               {
					sqlInsert = "INSERT INTO DATESCHEDULE(analysis_class,start_date,end_date,working_days)"
			               +" VALUES(?,?,?,?) ";
               }
			   else
               {
				   sqlInsert = "UPDATE DATESCHEDULE SET start_date = ?,end_date = ?,working_days = ? "
				   +" WHERE analysis_class = ?";
			   }
				   
			   pstmt = conn.prepareStatement(sqlInsert);
			   if(sqlDateCmp == null)
               {
				   pstmt.setString(1,"B");
				   pstmt.setDate(2,startDateSql);
				   pstmt.setDate(3,lastDate);
				   pstmt.setInt(4,workingDays);
			   }
			   else
               {
				   pstmt.setDate(1,startDateSql);
				   pstmt.setDate(2,lastDate);
				   pstmt.setInt(3,workingDays);
				   pstmt.setString(4,"B");
			   }
		       int count = pstmt.executeUpdate();
		       if(count == 1)
		       {
		    	   conn.commit();
		       }
		    }
			if(pstmt != null)
			{
				pstmt.close();
				pstmt = null;
			}
			if(rs != null)
			{ 
				rs.close();
				rs = null;
			}
		   	itemsql = "SELECT ITEM_CODE FROM ITEM WHERE ANALYSIS_CLASS= ? ";
			pstmt =conn.prepareStatement(itemsql);
			pstmt.setString(1,"B");
			 
	        rs= pstmt.executeQuery();
	        while(rs.next())
	        { 
	        	itemListB.add(rs.getString("ITEM_CODE"));  	   
		    }
	        if(flg)
	        { 
	             sqlIns = "UPDATE DATESCHEDULE SET no_of_item = ?  WHERE ANALYSIS_CLASS = ?";
       				
	        	 pstmt = conn.prepareStatement(sqlIns);
	        	 int noOfItemPerDay = 0;
	        	 int noOfDayPerItem = 0;
	        	 if(itemListB.size() >= workingDays)
		    	 {
		    		noOfItemPerDay = (int) Math.ceil(itemListB.size()/workingDays);
		    		
		    	 }
		    	 else
		    	 {
		    		 noOfDayPerItem = (int) Math.ceil(workingDays/itemListB.size());		    		
		         }
	        	 if(noOfItemPerDay != 0)
	        	 {
	        		 /*
	        		 String noOfItemPerDays = nf.format(noOfItemPerDay)+"\n";
	        		 fos1.write(noOfItemPerDays.getBytes());
	        		 */
	        		
	        	     pstmt.setInt(1,noOfItemPerDay);
	        	     pstmt.setString(2,"B"); 	
	  			   
	  		         int count = pstmt.executeUpdate();
	  		         if(count == 1)
	  		         {
	  		    	   conn.commit();
	  		         }
	        	 }
	        	 else
	        	 {
	        		 noOfDayPerItem = -(noOfDayPerItem);
	        		 /*
	        		 String noOfDayPerItems = nf.format(noOfDayPerItem)+"\n";
	        		 fos1.write(noOfDayPerItems.getBytes());
	        		 */
	        		 
	        	     pstmt.setInt(1,noOfDayPerItem);
	        	     pstmt.setString(2,"B"); 	
	  			   
	  		         int count = pstmt.executeUpdate();
	  		         if(count == 1)
	  		         {
	  		    	   conn.commit();
	  		         }
	        		 
	        	 }
	    
	        }
		   	  
		}
		catch(Exception e )
		{
			   System.out.println("Error"+ e);
		}
	    
		
    return itemListB; 
	}
	//Changed by Rohan on 23-Mar-12 To implementating Quarly logic.end
    //Changed by Rohan on 27-Mar-12 To implementating Half Yearly logic.start
	private ArrayList<String> halfYearlySchedule(Connection conn,String invStat,String siteCode,Date dateSchedule,String loginEmpCode)
	{
		System.out.println("ENTER IN HALF YEARLY SCHEDULE=====================================>");
		FileOutputStream fos1 = null;

		String lastDateStr = null;
		String firstDateStr = null;
		String monthEnd = "";
		String sqlWorking = "";
		String sqlholiday = "";
		String itemsql = "";
		int workingDays = 0;
		int holidays = 0;
		int noOfDays = 0;
		String sqlInsert = "";
		String sqlIns = "";
		
		String sqlUpdate = "";
		String sqlUpd = "";
		boolean flg = false;
		
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		ArrayList itemListC = new ArrayList();
		ArrayList holidayListC = new ArrayList();
		  
		Calendar calendar = Calendar.getInstance();
		java.util.Date checkDateC = new java.util.Date();
		java.sql.Date lastDate = null;
		
		NumberFormat nf = NumberFormat.getNumberInstance();
		
		String fileName = "halfYearlySchedule.txt";
		try
		{
			
		   //Convert Two days in java.sql.Date.start
			java.sql.Date sqlDate = new java.sql.Date(checkDateC.getTime());
			java.sql.Date sqlDateCmp = null;
			
			if(dateSchedule != null)
			{	
			    sqlDateCmp = new java.sql.Date(dateSchedule.getTime());
			}	
		    //Convert Two days in java.sql.Date.end
			
		   if(sqlDateCmp == null || sqlDateCmp.toString().equalsIgnoreCase(dateSchedule.toString()))
		   {	
			   flg = true;
			   java.util.Date startDate = new java.util.Date();
			   java.sql.Date startDateSql = new java.sql.Date(startDate.getTime());
			   
			   //sql to find out last date of month
				monthEnd = "SELECT ADD_MONTHS(TO_DATE(?),6) AS NEXT_SCHEDULE_DATE from DUAL";
				pstmt = conn.prepareStatement(monthEnd);
				pstmt.setDate(1,sqlDate);		
		    	rs = pstmt.executeQuery();
		    	if(rs.next())
		    	{
		    		lastDate = rs.getDate("NEXT_SCHEDULE_DATE");
		    	}  	
						
		    	if(rs!=null) 
				{
					rs.close();
					rs = null;
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt = null;
				}
			 
				sqlholiday = "SELECT COUNT(*) AS HOLYDAYS FROM HOLIDAY WHERE HOL_DATE BETWEEN ? AND ? ";
				System.out.println("sqlDate"+sqlDate+"lastDate"+lastDate);
				pstmt = conn.prepareStatement(sqlholiday);
				
				pstmt.setDate(1,sqlDate);
				pstmt.setDate(2,lastDate);
		    	rs = pstmt.executeQuery();
		    	if(rs.next())
		    	{
		    		holidays = rs.getInt("HOLYDAYS");//working dates in months
		    	}
		    	
		    	if(rs!=null) 
				{
					rs.close();
					rs = null;
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt = null;
				}
			
				sqlWorking = "SELECT TO_DATE(?) - TO_DATE(?) NO_OF_DAYS FROM DUAL";
				pstmt = conn.prepareStatement(sqlWorking);
				pstmt.setDate(1,lastDate);
				pstmt.setDate(2,sqlDate);
		    	rs = pstmt.executeQuery();
		    	if(rs.next())
		    	{
		    		noOfDays = rs.getInt("NO_OF_DAYS");//working dates in months
		    	}
		    	//coding for holidays from Calender.start
		    	//int daysInMonth = Integer.parseInt(noOfDays)
		    	java.sql.Date sqlDateHolidayList = new java.sql.Date(startDate.getTime());
		    	holidayListC = getHolidayList( conn, loginEmpCode, sqlDateHolidayList ,noOfDays );
		    	System.out.println("======NO OF HOLIDAYS in HALF YEAR==="+holidayListC.size());
		    	holidays = holidayListC.size();
		    	//coding for holidays from Calender.end
		    	workingDays = noOfDays-holidays;
		    	
				//sql to find out working days in months.end
				
			    System.out.println("noOfWorkingDays in HALF YEAR============>"+workingDays);
			    /*
			    ibase.webitm.utility.GenericUtility genericUtility = ibase.webitm.utility.GenericUtility.getInstance();
			   SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
			   //if(fos1.)
			   fos1 = new FileOutputStream(CommonConstants.JBOSSHOME + File.separator +"WMS"+File.separator+fileName);
               
               firstDateStr = sdf.format(startDate)+"\n";
               lastDateStr = sdf.format(lastDate)+"\n";
			  
			   fos1.write(firstDateStr.getBytes());
			   fos1.write(lastDateStr.getBytes());
			  
			   String workDay = nf.format(workingDays)+"\n";
			   fos1.write(workDay.getBytes());
			   */
			    System.out.println(" GOING FOR DATESCHEDULE");
			   if(pstmt!=null)
			   {
					pstmt.close();
					pstmt = null;
			   }
			    if(sqlDateCmp == null)
               {
					sqlInsert = "INSERT INTO DATESCHEDULE(analysis_class,start_date,end_date,working_days)"
			               +" VALUES(?,?,?,?) ";
               }
			   else
               {
				   sqlInsert = "UPDATE DATESCHEDULE SET start_date = ?,end_date = ?,working_days = ? "
				   +" WHERE analysis_class = ?";
			   }
				   
			   pstmt = conn.prepareStatement(sqlInsert);
			   if(sqlDateCmp == null)
               {
				   pstmt.setString(1,"C");
				   pstmt.setDate(2,startDateSql);
				   pstmt.setDate(3,lastDate);
				   pstmt.setInt(4,workingDays);
			   }
			   else
               {
				   pstmt.setDate(1,startDateSql);
				   pstmt.setDate(2,lastDate);
				   pstmt.setInt(3,workingDays);
				   pstmt.setString(4,"C");
			   }
		       int count = pstmt.executeUpdate();
		       if(count == 1)
		       {
		    	   conn.commit();
		       }
			   
		   }
		   if(pstmt != null)
		   {
				pstmt.close();
				pstmt = null;
		    }
			if(rs != null)
			{ 
				rs.close();
				rs = null;
			}
		    itemsql = "SELECT ITEM_CODE FROM ITEM WHERE ANALYSIS_CLASS= ? ";
		    System.out.println("SQL HERE"+itemsql);
			pstmt =conn.prepareStatement(itemsql);
			pstmt.setString(1,"C"); 
	        rs= pstmt.executeQuery();
	        while(rs.next())
	        { 
	        	itemListC.add(rs.getString("ITEM_CODE"));
	        }
	        if(flg)
	        { 
	        	 sqlIns = "UPDATE DATESCHEDULE SET no_of_item = ?  WHERE ANALYSIS_CLASS = ?";
	        	 pstmt = conn.prepareStatement(sqlIns);
	        	 int noOfItemPerDay = 0;
	        	 int noOfDayPerItem = 0;
	        	 if(itemListC.size() >= workingDays)
	        	 {		
		    		noOfItemPerDay = (int) Math.ceil(itemListC.size()/workingDays);
		    		
		    	 }
		    	 else
		    	 {
		    		 noOfDayPerItem = (int) Math.ceil(workingDays/itemListC.size());
		         }
	        	 if(noOfItemPerDay != 0)
	        	 {
	        		 /*
	        		 String noOfItemPerDays = nf.format(noOfItemPerDay)+"\n";
	        		 fos1.write(noOfItemPerDays.getBytes());
	        		 */
	        		 pstmt.setInt(1,noOfItemPerDay);
	        	     pstmt.setString(2,"C"); 	
	  			   
	  		         int count = pstmt.executeUpdate();
	  		         if(count == 1)
	  		         {
	  		    	   conn.commit();
	  		         }
	        	 }
	        	 else
	        	 {
	        		 noOfDayPerItem = -(noOfDayPerItem); 
	        		 /*
	        		 String noOfDayPerItems = nf.format(noOfDayPerItem)+"\n";
	        		 fos1.write(noOfDayPerItems.getBytes());
	        		 */
	        		 System.out.println("ENTER");
	        	     pstmt.setInt(1,noOfDayPerItem);
	        	     pstmt.setString(2,"C"); 	
	  			   
	  		         int count = pstmt.executeUpdate();
	  		         if(count == 1)
	  		         {
	  		    	   conn.commit();
	  		         }
	  
	        	 }
	   
	        }  
		}
		catch(Exception e )
		{
			   System.out.println("Error"+ e);
		}
	    
		
    return itemListC; 
	}
	//Changed by Rohan on 27-Mar-12 To implementating Half Yearly logic.end
	public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
	{
		String retStr = "";
		Document detailDom = null;
		Document headerDom = null;
		
		GenericUtility genericUtility = GenericUtility.getInstance();
		
		try
		{	
			if(xmlString != null && xmlString.trim().length()!=0)
			{
				headerDom = genericUtility.parseString(xmlString); 
				System.out.println("headerDom" + headerDom);
			}
			if(xmlString2 != null && xmlString2.trim().length()!=0)
			{
				detailDom = genericUtility.parseString(xmlString2); 
				System.out.println("detailDom" + detailDom);
			}
									
		    retStr = process(headerDom, detailDom, windowName, xtraParams);
		    
		}
		catch (Exception e)
		{
			System.out.println("Exception :StockAllocationPrcEJB :process(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
			e.printStackTrace();
			retStr = e.getMessage();
		}
		return retStr;
		
	}
	public String process(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
	{
		int noOfRecords=0;
		int iRecord=0;
		String insertItemProcess="";
		Connection conn = null;
		PreparedStatement pstmtInsert = null;	
		try
		{
			conn = getConnection();
			conn.setAutoCommit(false);
			noOfRecords=tranIdList.size();		
			insertItemProcess="insert into item_process(TRAN_ID,item_code,analysis_class,tran_date," +
			"priority_seq,CHG_USER,CHG_DATE,CHG_TERM) " +
			"values(?,?,?,?,?,?,?,?)";
			pstmtInsert = conn.prepareStatement(insertItemProcess);
			while(iRecord<noOfRecords)
			{
				pstmtInsert.setString(1,(String)tranIdList.get(iRecord));
				pstmtInsert.setString(2,(String)itemCodeList.get(iRecord));
				pstmtInsert.setString(3,(String)analysisClassList.get(iRecord));
				pstmtInsert.setDate(4,(java.sql.Date)currentDateList.get(iRecord));
				//pstmtInsert.setString(5,siteCode);
				//pstmtInsert.setString(6,locCode);
				pstmtInsert.setInt(5,(Integer)numberOfItemProcessRecordsList.get(iRecord));
				pstmtInsert.setString(6,(String)chgUserList.get(iRecord));
				pstmtInsert.setTimestamp(7,(java.sql.Timestamp)currentDate1List.get(iRecord));
				pstmtInsert.setString(8,(String)clientIpList.get(iRecord));
				int updatedRecords = pstmtInsert.executeUpdate();	
				iRecord++;
			}
			tranIdList=null;
			itemCodeList=null;
			analysisClassList=null;
			currentDateList=null;
			numberOfItemProcessRecordsList=null;
			chgUserList=null;
			currentDate1List=null;
			clientIpList=null;
		}
		catch(Exception e)
		{
			
		}
		finally
		{
			try
			{
				if(pstmtInsert != null)
			   {
					pstmtInsert.close();
					pstmtInsert = null;
			    }
				if(conn != null)
				{					
					conn.close();
					conn = null;
				}
			}
			catch(Exception e)
			{
				
			}
		}
		return "";
	}
	/*
	public String process(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
	{
		Connection conn = null;
		PreparedStatement pstmt = null;
		PreparedStatement pstmtInsert = null;
		ResultSet rs = null;	
		
		java.util.Date todayDate=null;
		java.sql.Date chgDate=null;
		
		String currentMonthInString="";
		String currentQuarterMonth1InString="";
		String currentQuarterMonth2InString="";
		String currentHalfYearMonth1InString="";
		String currentHalfYearMonth2InString="";
		String currentHalfYearMonth3InString="";
		String insertItemProcess="";
		String itemCode="";
		String analysisClass="";
		String siteCode="";
		
		String locCode="";
		String chgUser="";		
		String chgTerm="";
		String queryString="";
		String machineName="";
		String clientIp="";
		String tranId="";
		
		
		int currentMonth=0;
		int currentYear=0;
		int numberOfItemsA=0;
		int numberOfItemsB=0;
		int numberOfItemsC=0;
		int numberOfWorkingDaysA=0;
		int numberOfWorkingDaysB=0;
		int numberOfWorkingDaysC=0;
		int numberOfItemsPerdayA=0;
		int numberOfItemsPerdayB=0;
		int numberOfItemsPerdayC=0;
		int numberOfItemsPerdayATemp=0;
		int numberOfItemsPerdayA_rem=0;
		int numberOfItemsPerdayBTemp=0;
		int numberOfItemsPerdayB_rem=0;
		int numberOfItemsPerdayCTemp=0;
		int numberOfItemsPerdayC_rem=0;	
		int numberOfItemProcessRecords=0;
		int noOfRecordsToday = 0;
		int iA=0;
		int iB=0;
		int iC=0;
		
		

		try
		{
			clientIp = InetAddress.getLocalHost().getHostAddress();
			//Changed by Gayatri Yadav on 01-04-2011 [To store machine name in status log][SY12SUN004]
			machineName = InetAddress.getLocalHost().getHostName();	
			//Class.forName("oracle.jdbc.driver.OracleDriver");
			//conn = DriverManager.getConnection("jdbc:oracle:thin:@//172.16.100.70:1521/orcl", "erp", "erp");
			siteCode = genericUtility.getColumnValue("site_code",headerDom);
			String loginEmpCode = genericUtility.getValueFromXTRA_PARAMS( xtraParams, "loginEmpCode" );
			conn = getConnection();
			conn.setAutoCommit(false);
			tranId=generateTranId("w_item_process",conn);			
			queryString="select count(*) from item_process where to_date(tran_date,'DD-MON-YY')=to_date(sysdate,'DD-MON-YY')";
			pstmt=conn.prepareStatement(queryString);
			rs=pstmt.executeQuery();
			ibase.utility.UserInfoBean userInfo = null;
			try
			{
				
				//System.out.println("************ ["+scheduleParamXML+"]");
				//userInfo = new ibase.utility.UserInfoBean( scheduleParamXML );
				loginSiteCode = userInfo.getSiteCode();
				System.out.println("Site code======**************====> "+loginSiteCode);
				
			}
			catch(Exception e)
			{
				throw new Exception(e);
			}
			
			
			if(noOfRecordsToday>0)
			{
				System.out.println("Already Records Inserted");
			}
			else
			{
				
			
				chgUser="WMS";
				todayDate = new java.util.Date();
				
				todayDate=new java.util.Date();
				System.out.println("date="+todayDate);
				String month="";
				String dStr=todayDate.toString();
				System.out.println("dStr="+dStr);
				System.out.println("Month="+dStr.substring(4,7));
				month=dStr.substring(4,7).toUpperCase();
				System.out.println("Month="+month);
				System.out.println("Year="+dStr.substring(dStr.length()-4));
				currentYear=Integer.parseInt(dStr.substring(dStr.length()-2));
				System.out.println("currentYear="+currentYear);
				
				
				
				
				
				
				
				
				
				
				
							
				System.out.println("numberOfItemsA="+numberOfItemsA);
				System.out.println("numberOfItemsB="+numberOfItemsB);
				System.out.println("numberOfItemsC="+numberOfItemsC);
				System.out.println("numberOfWorkingDaysA="+numberOfWorkingDaysA);
				System.out.println("numberOfWorkingDaysB="+numberOfWorkingDaysB);
				System.out.println("numberOfWorkingDaysC="+numberOfWorkingDaysC);
				
				
				
				
				
				
				
				
				numberOfItemProcessRecords=0;
				System.out.println("HELLO");
				queryString="select ITEM_CODE,ANALYSIS_CLASS,SITE_CODE,LOC_CODE,CHG_USER,CHG_TERM,to_date(CHG_DATE,'DD-MON-YY') CHG_DATE from item where analysis_class='A' and item_code not in (select item_code from item_process where analysis_class='A' and to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?)";
				pstmt=conn.prepareStatement(queryString);
				pstmt.setString(1,currentMonthInString);
				pstmt.setInt(2,currentYear);
				System.out.println("HELLO1");
				rs=pstmt.executeQuery();
				System.out.println("HELLO2");
				iA=0;
				java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
				java.sql.Timestamp currentDate1 = new java.sql.Timestamp(System.currentTimeMillis());
				System.out.println("currentDate============="+currentDate);
				System.out.println("currentDate1============="+currentDate1);
				while(rs.next() && iA < numberOfItemsPerdayA)
				{
					numberOfItemProcessRecords++;
					itemCode=rs.getString("ITEM_CODE");
					System.out.println("itemCode="+itemCode);
					analysisClass=rs.getString("ANALYSIS_CLASS");
					System.out.println("analysisClass="+analysisClass);
					siteCode=rs.getString("SITE_CODE");
					System.out.println("siteCode="+siteCode);
					locCode=rs.getString("LOC_CODE");
					System.out.println("locCode="+locCode);
					chgTerm=rs.getString("CHG_TERM");
					System.out.println("HELLO3");
					siteCode = siteCode != null?siteCode:"";
					insertItemProcess="insert into item_process(TRAN_ID,item_code,analysis_class,tran_date," +
							"priority_seq,CHG_USER,CHG_DATE,CHG_TERM) " +
							"values(?,?,?,?,?,?,?,?)";
					pstmtInsert = conn.prepareStatement(insertItemProcess);
					
					pstmtInsert.setString(1,tranId);
					pstmtInsert.setString(2,itemCode);
					pstmtInsert.setString(3,analysisClass);
					pstmtInsert.setDate(4,currentDate);
					//pstmtInsert.setString(5,siteCode);
					//pstmtInsert.setString(6,locCode);
					pstmtInsert.setInt(5,numberOfItemProcessRecords);
					pstmtInsert.setString(6,chgUser);
					pstmtInsert.setTimestamp(7,currentDate1);
					pstmtInsert.setString(8,clientIp);
					int updatedRecords = pstmtInsert.executeUpdate();
					System.out.println("HELLO5");
					//Changed by Rohan on 2/7/12
					if(pstmtInsert != null)
					{
						pstmtInsert.close();
						pstmtInsert = null;
					}
					iA++;
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				if(pstmtInsert!=null)
				{
					pstmtInsert.close();
					pstmtInsert=null;
				}
				
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
				
				queryString="select ITEM_CODE,ANALYSIS_CLASS,SITE_CODE,LOC_CODE,CHG_USER,CHG_TERM,to_date(CHG_DATE,'DD-MON-YY') CHG_DATE from item where analysis_class='B' and item_code not in (select item_code from item_process where analysis_class='B' and ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) ))";
				pstmt=conn.prepareStatement(queryString);
				pstmt.setString(1,currentMonthInString);
				pstmt.setInt(2,currentYear);
				pstmt.setString(3,currentQuarterMonth1InString);
				pstmt.setInt(4,currentYear);
				pstmt.setString(5,currentQuarterMonth2InString);
				pstmt.setInt(6,currentYear);
				rs=pstmt.executeQuery();
				iB=0;
				while(rs.next() && iB<numberOfItemsPerdayB)
				{
					numberOfItemProcessRecords++;
					itemCode=rs.getString("ITEM_CODE");
					analysisClass=rs.getString("ANALYSIS_CLASS");
					siteCode=rs.getString("SITE_CODE");
					locCode=rs.getString("LOC_CODE");		
					chgTerm=rs.getString("CHG_TERM");
					insertItemProcess="insert into item_process(TRAN_ID,item_code,analysis_class,tran_date," +
					"priority_seq,CHG_USER,CHG_DATE,CHG_TERM) " +
					"values(?,?,?,?,?,?,?,?)";
					pstmtInsert = conn.prepareStatement(insertItemProcess);
					pstmtInsert.setString(1,tranId);
					pstmtInsert.setString(2,itemCode);
					pstmtInsert.setString(3,analysisClass);
					pstmtInsert.setDate(4,currentDate);
					//pstmtInsert.setString(5,siteCode);
					//pstmtInsert.setString(6,locCode);
					pstmtInsert.setInt(5,numberOfItemProcessRecords);
					pstmtInsert.setString(6,chgUser);
					pstmtInsert.setTimestamp(7,currentDate1);
					pstmtInsert.setString(8,clientIp);
					int updatedRecords = pstmtInsert.executeUpdate();
					if(pstmtInsert != null)
					{
						pstmtInsert.close();
						pstmtInsert = null;
					}
					iB++;
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				if(pstmtInsert!=null)
				{
					pstmtInsert.close();
					pstmtInsert=null;
				}
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
				
				if( month.equals("APR") || month.equals("MAY") || month.equals("JUN") || month.equals("JUL") || month.equals("AUG") || month.equals("SEP") )
				{
					queryString="select ITEM_CODE,ANALYSIS_CLASS,SITE_CODE,LOC_CODE,CHG_USER,CHG_TERM,to_date(CHG_DATE,'DD-MON-YY')" +
							" CHG_DATE from item where analysis_class='C' and item_code not in " +
							" (select item_code from item_process where analysis_class='C' and " +
							" ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=?" +
							"  and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) " +
							" or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? " +
							" and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) ))";
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,currentMonthInString);
					pstmt.setInt(2,currentYear);
					pstmt.setString(3,currentQuarterMonth1InString);
					pstmt.setInt(4,currentYear);
					pstmt.setString(5,currentQuarterMonth2InString);
					pstmt.setInt(6,currentYear);
					pstmt.setString(7,currentHalfYearMonth1InString);
					pstmt.setInt(8,currentYear);
					pstmt.setString(9,currentHalfYearMonth2InString);
					pstmt.setInt(10,currentYear);
					pstmt.setString(11,currentHalfYearMonth3InString);
					pstmt.setInt(12,currentYear);
									
				}
				else
				if( month.equals("JAN") || month.equals("FEB") || month.equals("MAR") )
				{
					queryString="select ITEM_CODE,ANALYSIS_CLASS,SITE_CODE,LOC_CODE,CHG_USER,CHG_TERM,to_date(CHG_DATE,'DD-MON-YY') " +
							" CHG_DATE from item where analysis_class='C' and item_code not in " +
							" (select item_code from item_process where analysis_class='C' and " +
							" ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? " +
							" and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or" +
							"  ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and " +
							" to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) ))";
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,currentMonthInString);
					pstmt.setInt(2,currentYear);
					pstmt.setString(3,currentQuarterMonth1InString);
					pstmt.setInt(4,currentYear);
					pstmt.setString(5,currentQuarterMonth2InString);
					pstmt.setInt(6,currentYear);
					pstmt.setString(7,currentHalfYearMonth1InString);
					pstmt.setInt(8,(currentYear-1));
					pstmt.setString(9,currentHalfYearMonth2InString);
					pstmt.setInt(10,(currentYear-1));
					pstmt.setString(11,currentHalfYearMonth3InString);
					pstmt.setInt(12,(currentYear-1));
				
					
				}
				else
				if( month.equals("OCT") || month.equals("NOV") || month.equals("DEC") )
				{
					queryString="select ITEM_CODE,ANALYSIS_CLASS,SITE_CODE,LOC_CODE,CHG_USER,CHG_TERM,to_date(CHG_DATE,'DD-MON-YY') CHG_DATE from item where analysis_class='C' and item_code not in (select item_code from item_process where analysis_class='C' " +
							" and ( ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? " +
							" and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and " +
							" to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) " +
							" or ( to_char(tran_DATE, 'MON')=? and to_char(tran_DATE, 'yy')=?) or ( to_char(tran_DATE, 'MON')=? " +
							" and to_char(tran_DATE, 'yy')=?) ))";
					pstmt=conn.prepareStatement(queryString);
					pstmt.setString(1,currentMonthInString);
					pstmt.setInt(2,currentYear);
					pstmt.setString(3,currentQuarterMonth1InString);
					pstmt.setInt(4,currentYear);
					pstmt.setString(5,currentQuarterMonth2InString);
					pstmt.setInt(6,currentYear);
					pstmt.setString(7,currentHalfYearMonth1InString);
					pstmt.setInt(8,(currentYear+1));
					pstmt.setString(9,currentHalfYearMonth2InString);
					pstmt.setInt(10,(currentYear+1));
					pstmt.setString(11,currentHalfYearMonth3InString);
					pstmt.setInt(12,(currentYear+1));
				
					
				}
				rs = pstmt.executeQuery();
				
				iC=0;
				while(rs.next() && iC < numberOfItemsPerdayC)
				{
					numberOfItemProcessRecords++;
					itemCode=rs.getString("ITEM_CODE");
					analysisClass=rs.getString("ANALYSIS_CLASS");
					siteCode=rs.getString("SITE_CODE");
					locCode=rs.getString("LOC_CODE");	
					
					//dateInString = new SimpleDateFormat("dd-MMM-yy").format(chgDate);
					chgTerm=rs.getString("CHG_TERM");
					insertItemProcess="insert into item_process(TRAN_ID,item_code,analysis_class,tran_date," +
					"priority_seq,CHG_USER,CHG_DATE,CHG_TERM) " +
					"values(?,?,?,?,?,?,?,?)";
					pstmtInsert = conn.prepareStatement(insertItemProcess);
					pstmtInsert.setString(1,tranId);
					pstmtInsert.setString(2,itemCode);
					pstmtInsert.setString(3,analysisClass);
					pstmtInsert.setDate(4,currentDate);
					//pstmtInsert.setString(5,siteCode);
					//pstmtInsert.setString(6,locCode);
					pstmtInsert.setInt(5,numberOfItemProcessRecords);
					pstmtInsert.setString(6,chgUser);
					pstmtInsert.setTimestamp(7,currentDate1);
					pstmtInsert.setString(8,clientIp);
					int updatedRecords = pstmtInsert.executeUpdate();
					iC++;
				}
				if(pstmt!=null)
				{
					pstmt.close();
					pstmt=null;
				}
				if(pstmtInsert!=null)
				{
					pstmtInsert.close();
					pstmtInsert=null;
				}
				if(rs!=null)
				{
					rs.close();
					rs=null;
				}
				
				
				}
			
		}
		catch(Exception e)
		{
			isError = true;
			System.out.println("Exception is "+e.getMessage());
			System.out.println("Exception is "+e);
			e.printStackTrace();
		}
		finally
		{
			
			try
			{
				if(!isError)
				{						
					conn.commit();					
				}
				else
				{
					conn.rollback();
				}
				if(conn != null)
				{
					if(pstmt!=null)
					{
						pstmt.close();
						pstmt=null;
					}
					if(pstmtInsert!=null)
					{
						pstmtInsert.close();
						pstmtInsert=null;
					}
					if(rs!=null)
					{
						rs.close();
						rs=null;
					}
				
					conn.commit();
					conn.close();
				}
			}
			catch(Exception e)
			{
				isError = true;
				System.out.println("Exception is "+e.getMessage());
			}
			
		}
		return "";
		
	}
	
	*/
	private String getTranId(String windowName, Connection conn) throws Exception
	{
		
		String keyStringQuery = "", errString = "";
		String xmlValues = "";
		String tranId = "";	
		ResultSet rSet = null ;
		PreparedStatement pstmt = null;
		
		try
		{
			
			keyStringQuery = "SELECT KEY_STRING, TRAN_ID_COL, REF_SER FROM TRANSETUP WHERE TRAN_WINDOW = ?";
	    	System.out.println("keyStringQuery--------->>"+keyStringQuery);
	    	
	    	pstmt = conn.prepareStatement(keyStringQuery);
	    	pstmt.setString(1,windowName);
	    	rSet = pstmt.executeQuery();	    	
			String tranSer1 = "";
			String keyString = "";
			String keyCol = "";
			if (rSet.next())
			{
				keyString = rSet.getString("KEY_STRING");
				keyCol = rSet.getString("TRAN_ID_COL");
				tranSer1 = rSet.getString("REF_SER");				
			}
			rSet.close(); rSet = null;
			pstmt.close();pstmt =null;
			
			System.out.println("keyString :"+keyString);
			System.out.println("keyCol :"+keyCol);
			System.out.println("tranSer1 :"+tranSer1);
			
			xmlValues ="<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>";
			xmlValues = xmlValues + "<Header></Header>";
			xmlValues = xmlValues + "<Detail1>";
			xmlValues = xmlValues +"</Detail1></Root>";
			System.out.println("xmlValues  :["+xmlValues+"]");
			TransIDGenerator tg = new TransIDGenerator(xmlValues, "BASE", CommonConstants.DB_NAME);
			// Creating tran_id 
			tranId = tg.generateTranSeqID(tranSer1, keyCol, keyString, conn);
			System.out.println("************ Tran id ************"+tranId);
						
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{	
				if(rSet != null)
				{
					rSet.close();
					rSet=null;
				}	
				if(pstmt != null)
				{
					pstmt.close();
					pstmt=null;
				}				
				
			}
			catch(Exception e)
			{
				e.printStackTrace();
				throw new ITMException(e);
			}
		}
		return tranId;
	}
	
	//Changed by Rohan 04/04/12 To get list of holiday.start
	private java.util.ArrayList getHolidayList( Connection conn, String employeeCode,java.sql.Date dateFrom, int daysInMonth ) 
	{
		System.out.println("Getting Holidays Information ..... ");
		
		java.sql.PreparedStatement pstmtHolday = null;
		java.sql.ResultSet rsetHolday = null;
		GenericUtility genericUtility = GenericUtility.getInstance();
	
		java.util.ArrayList holidayArray = new java.util.ArrayList();
		java.util.Calendar calendar = java.util.Calendar.getInstance();		
		
		try
		{
			String periodCode = "";
			String formatWorkDate = "";
			String holidayDate = "";
			String prdCodeSql = "SELECT CODE FROM PERIOD WHERE FR_DATE = ?";

			pstmtHolday = conn.prepareStatement( prdCodeSql );
			pstmtHolday.setDate(1, dateFrom );
			rsetHolday = pstmtHolday.executeQuery();
			if ( rsetHolday.next() )
			{
				periodCode = rsetHolday.getString("CODE");
			}

			java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( genericUtility.getApplDateFormat() );
			calendar.setTimeInMillis( dateFrom.getTime() );

			for (int count=0; count!=daysInMonth; count++ )
			{
				//System.out.println("ENTER");
				calendar.setTimeInMillis( calendar.getTimeInMillis() );
				formatWorkDate = sdf.format( calendar.getTime() );
				java.sql.Timestamp  workDate = java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(formatWorkDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()));
                System.out.println("WORK DATES iN TIMESTAMP FORMA"+workDate);
				String getHolidaySQL = "SELECT DDF_GET_EMP_HOLIDAY( ?, ?, ?, ? )AS HOL_DATE FROM DUAL";
				pstmtHolday = conn.prepareStatement( getHolidaySQL );
				pstmtHolday.setString(1, employeeCode );
				pstmtHolday.setString(2, periodCode );
				pstmtHolday.setString(3, periodCode );
				pstmtHolday.setTimestamp(4, workDate );

				rsetHolday = pstmtHolday.executeQuery();

				if( rsetHolday.next() )
				{
					holidayDate = checkNull(rsetHolday.getString("HOL_DATE"));
					if( holidayDate.trim().length() > 0 )
					{
						System.out.println("ENTER IN  if( holidayDate.trim().length() > 0 )");
						//Changed By Sumit Sakore On 24/02/2009 [ This DateFormat will be there As per Nilesh Parikh ]
						//holidayArray.add( genericUtility.getValidDateString(holidayDate, genericUtility.getDBDateFormat(), genericUtility.getApplDateFormat()).toUpperCase() ) ;
						holidayArray.add( genericUtility.getValidDateString(holidayDate, "dd-MMM-yyyy", genericUtility.getApplDateFormat()).toUpperCase() ) ;
					}					
				}
				calendar.add( calendar.DATE, 1 );
			}
			     if(pstmtHolday != null)//added by darshan for ejb 3
				{
					pstmtHolday.close();
				}
				if (rsetHolday !=null )//added by darshan for ejb 3
				{
					rsetHolday.close();
				}
			System.out.println("PhysicalCountPrcEJB :: getHolidayList :: holidayArray ==> ["+holidayArray+"]");
		}
		catch ( Exception eHolday )
		{
			System.out.println("ExpenseProcessEJB : getHolidayList => ");
			eHolday.printStackTrace();
		}
		finally
		{
			try
			{
				if(pstmtHolday != null)
				{
					pstmtHolday.close();
				}
				if (rsetHolday !=null )
				{
					rsetHolday.close();
				}
			}
			catch(Exception closeRsc )
			{
				closeRsc.printStackTrace();
			}
		}
		return holidayArray;
	}
	//Changed by Rohan 04/04/12 To get list of holiday.end
//Changed By Rohan Sakore On 04/04/12 to check null value.start
private String checkNull(String input)
{
	if (input==null)
	{
		input="";
	}
	return input;
}
//Changed By Rohan Sakore On 04/04/12 to check null value.end

	

}