package com.csc.library.databean;

import com.csc.library.utilities.MyLog;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;

import com.csc.library.database.CscConnection;
import com.csc.library.database.FieldManager;
import com.csc.library.database.MyHashMap;
import com.csc.library.database.PropertyField;
import com.csc.library.database.StaticConfig;
import com.csc.library.database.StaticProperties;
import com.csc.library.formula.FormulaString;
import com.csc.library.process.CalOT;
import com.csc.library.process.RoundingTime;
import com.csc.library.process.TransferTimeLog;
import com.csc.library.service.ServiceTimeWorking;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.DbRecord;
import com.csc.library.session.InitialInquiry;
import com.csc.library.session.InitialRecord;
import com.csc.library.session.RecordCmp;
import com.csc.library.timeattendance.DayCalculation;
import com.csc.library.timeattendance.MyTimeZone;
import com.csc.library.timeattendance.TimeZone;
import com.csc.library.timeattendance.WorkingShift;
import com.csc.library.timeinterface.TimeResult;
import com.csc.library.utilities.CscCalendar;
import com.csc.library.utilities.CscTime;
import com.csc.library.utilities.MessagePools;
import com.csc.library.utilities.MyTreeMap;
import com.csc.library.utilities.UProfile;
import com.csc.library.utility.DiffTime;

/*
 * �红����š�÷ӧҹ�ͧ��ѡ�ҹ
 */
public class Ttime_current1 extends RecordCmp {	
	HashMap hm = new HashMap();	
	private boolean b = false;
	private MyHashMap hmTime; //����������´㹵��ҧ Mtime0
	private MyHashMap hmDayTime; //����������´㹵��ҧ Mtime1
	private DbRecord empRec; //record �ͧ��ѡ�ҹ
	private MyTreeMap hmOT; 
	private MyHashMap hmHoliday; //�红������ѹ��ش���ླ�	
	private CalOT calOT; //class �����㹡�äӹdz�ͷ�
	private String empTimeCode = null; //���ʡТͧ��ѡ�ҹ
	private DbRecord timeRec; //record �ͧ���ҧ��÷ӧҹ
	private MyHashMap hmOTAdjust = null; //�红������ͷ�Ẻ��͡�ͧ
	private MyHashMap hmCostcenter = null; //�红����š��������
	private MyHashMap hmBusLate = null; //�红����š������¡Ѻö�Ѻ��
	private MyHashMap hmUnused = null; //�红����ŵ���ê��Ǥ���
	
	private DbInquiry inqEmp = null;
	private DbInquiry inqTime0 = null;
	private DbInquiry inqTime1 = null;
	private DbInquiry inqTime2 = null;
	private DbInquiry inqFormula = null;
	private DbInquiry inqEvent = null;
	private DbInquiry inqHoliday = null;
	private DbInquiry inqHistory = null;
	private DbInquiry inqOTAdjust = null;
	private DbInquiry inqBusLate = null;
	private DbInquiry inqCostcenter = null;
	private DbInquiry inqUnused = null;
	private DbInquiry inqTLeave_summary = null;
	private DbRecord recTLeave_summary = null;
	private DbRecord recHistory = null;
	private DbRecord recPayroll = null;	
	//private DbRecord recEmp_leave = null;
	
	private boolean flag = false;
	private boolean calOTAdjust = false; //�֧�������ͷ�Ẻ��͡�ͧ�����������
	private boolean calCostcenter = false; //�֧�����š�������������������
	private boolean calBusLate = false; //�֧�����š������¡Ѻö�Ѻ�������������
	private boolean calUnused = false;  //�֧�����ŵ���ê��Ǥ��������������
	public boolean calotflag = true; 	// ��觤ӹdz�ͷ�������� �������ҡ����Ҩҡ˹�Ҥӹdz��鹰ҹ����ʶҹ���ҵ�ͧ�ӹdz�ͷ��������
	
	private boolean inBreak=false; //���ҷ��ŧ���� �����ǧ�ѡ�ͧ��ѡ�ҹ�������
	private float hourBreakEmp=0; //��.���Ҿѡ�ͧ��ѡ�ҹ
		
	private DecimalFormat df = new DecimalFormat("0.00");
	private DecimalFormat df2 = new DecimalFormat("00.00");
	
	private float actual_late = 0;	/* ���������Թ͹������� �������ӹdz ��. �ӧҹ����ѹ  */
	private HashMap hmExpFromWorkFlow ;	/* ��ʶҹФ��ö����� ��Ф����������§ ����͡�ҡ㺢��ͷ������˹�� */

	/* ����ͷա�͹�Ѵ���  */
	private float late_noround = 0f;
	private float leave_noround = 0f;
	private float ac_ot_noround = 0f;
	private float ot_before_noround = 0f;
	private float ot_after_noround = 0f;
	
	/* log */
	private TransferTimeLog ttl;
	
	private HashMap<String,MyTimeZone> hmZone = new HashMap<String,MyTimeZone>();
	
	public Ttime_current1() {
		super("Ttime_current1", "Ttime_current1  Table");
	}
	
	/*
	 * �����ʡТͧ��ѡ�ҹ �������㹻���ѵԾ�ѡ�ҹ
	 */
	private void setEmpTimeCode() {
		if (this.empRec!=null) {
			try { 
				this.empTimeCode = this.empRec.getString("time0");
		 	} catch (Exception e) {
				MyLog.error(this, e);
			}
		}
		if (this.empTimeCode==null) {
			try {
				if (this.inqEmp == null) {
					this.inqEmp = new InitialInquiry(this.userPro).getDbInquiry();		
					this.inqEmp.setSchemaName(this.userPro.getSchemaName());
					this.inqEmp.initMyTable("Memployee", "", "");			
					//this.inqEmp.setColumn("employeeid, time0, companyid");
					this.inqEmp.setGroupfield("requisition");
				}
				this.inqEmp.setFilter("employeeid='"+this.getString("employeeid")+"'");
				this.inqEmp.refresh();
				if (this.inqEmp.next()) {					
					this.empRec = this.inqEmp.getCurrentDbRecord().cloneRecord(true);
					this.empTimeCode = this.empRec.getString("time0");
				}
			} catch (Exception e) {
				MyLog.error(this, e);				
			}
			finally{
				try{
					inqEmp.closeConnection();
				}catch(Exception e){
					MyLog.error(this, e);
				}
			}
		}
	}
	
	private void calulateDayTran() {
		try {
 			this.setEmpTimeCode();
						
			this.inBreak = false;
			this.hourBreakEmp = 0;
			
			CscCalendar csc = new CscCalendar();
			csc.setCSCTime(0f);
			
			CscCalendar m_dt_in=null, m_dt_out=null, cs_breakin=null, cs_breakout=null;
			
			/* ��˹���������´�С�÷ӧҹ */
			String strTime0id = this.getString("time0id");
	        if (strTime0id.equals("")) {
	           	strTime0id = this.empTimeCode;
	        }
            HashMap propertyShf = (HashMap) this.hmTime.get(strTime0id); //��������´�ͧ��㹵��ҧ��÷ӧҹ
            this.set("hour_s", (String) propertyShf.get("hour_d"));
								
			//��˹�������������͡�ͧ��ѡ�ҹ����ͧŧ����
			CscCalendar o_dt_in = new CscCalendar(this.getString("o_dt_bg"));
			o_dt_in.setCSCTime(this.getFloat("o_tm_bg"));
			CscCalendar o_dt_out = new CscCalendar(this.getString("o_dt_en"));
			o_dt_out.setCSCTime(this.getFloat("o_tm_en"));
			
			//��˹�������������͡�ͧ��ѡ�ҹ������ҧ��÷ӧҹ
			CscCalendar sh_dt_in = new CscCalendar(this.getString("sh_dt_bg"));
			sh_dt_in.setCSCTime(this.getFloat("sh_tm_bg"));
			CscCalendar sh_dt_out = new CscCalendar(this.getString("sh_dt_en"));
			sh_dt_out.setCSCTime(this.getFloat("sh_tm_en"));
						
			//��˹�������������͡�ͧ��ѡ�ҹ����ͧŧ����
			CscCalendar c_dt_in = new CscCalendar(this.getString("c_dt_bg"));
			c_dt_in.setCSCTime(this.getFloat("c_tm_bg"));
			CscCalendar c_dt_out = new CscCalendar(this.getString("c_dt_en"));
			c_dt_out.setCSCTime(this.getFloat("c_tm_en"));
			
			//��˹�����ѹ���ҷ�边ѡ�ҹ�ٴ�ѵ����
			try {
				m_dt_in = new CscCalendar(this.getString("m_dt_bg"));
				m_dt_in.setCSCTime(this.getFloat("m_tm_bg"));
				if (m_dt_in.getYYYYMMDD().equals(csc.getYYYYMMDD())) {
					if (m_dt_in.getCSCTime()==csc.getCSCTime()) {	
						m_dt_in=null;
					}
				}
			} catch (Exception e1) {
				MyLog.error(this, e1);				
			}
			
			//��˹�����ѹ���ҷ�边ѡ�ҹ�ٴ�ѵ��͡
			try {
				m_dt_out = new CscCalendar(this.getString("m_dt_en"));	
				m_dt_out.setCSCTime(this.getFloat("m_tm_en"));
				if (m_dt_out.getYYYYMMDD().equals(csc.getYYYYMMDD())) {
					if (m_dt_out.getCSCTime()==csc.getCSCTime()) {	
						m_dt_out=null;
					}
				}
			} catch (Exception e2) {
				MyLog.error(this, e2);				
			}	
			
			//��˹��ѹ���Ҫ�ǧ�ѡ�ͧ��ѡ�ҹ
			try {
				cs_breakin = new CscCalendar(this.getString("dt_breakin"));
				cs_breakin.setCSCTime(this.getFloat("tm_breakin"));		
				cs_breakout = new CscCalendar(this.getString("dt_breakout"));
				cs_breakout.setCSCTime(this.getFloat("tm_breakout"));
			} catch (Exception e3) {
				MyLog.error(this, e3);				
			}
			
			TimeZone tz=null;
			if (cs_breakin!=null && cs_breakout!=null){
				tz = new TimeZone(cs_breakin, cs_breakout);
				
				CscCalendar t1 = m_dt_in;
				CscCalendar t2 = m_dt_out;
				if (this.getString("tr_type").indexOf("A")>-1) { //����繡��� ��������ٴ�ѵ��������͡�����ҷ�����
					t1 = c_dt_in;
					t2 = c_dt_out;
				}
				
				//��Ǩ�ͺ������ҷ�� ��� �ٴ�ѵù�� �ç�Ѻ��ǧ�ѡ�ͧ��ѡ�ҹ������� ����Ҩӹǹ���Ҿѡ��������
				if (t1!=null && t2!=null && !t1.equals(t2)){					
					if (t1.afterEquals(cs_breakin) && t2.beforeEquals(cs_breakout)) {
						MyLog.debug(this, "CASE 1 : ����㹪�ǧ�ѡ���§");
						this.inBreak = true;
						this.hourBreakEmp = cs_breakout.subForHour(cs_breakin); //����㹪�ǧ�ѡ���§
					} else if (t1.after(cs_breakin) && t1.before(cs_breakout) && t2.afterEquals(cs_breakout)) {
						MyLog.debug(this, "CASE 2 : �����ѧ���§");
						this.inBreak = true;
						this.hourBreakEmp = cs_breakout.subForHour(t1); //�����ѧ���§
					} else if (t1.before(cs_breakin) && t2.after(cs_breakin) && t2.beforeEquals(cs_breakout) && (!o_dt_out.equals(cs_breakin))) {
						MyLog.debug(this, "CASE 4 : xxxxx");
						this.inBreak = true;						
						this.hourBreakEmp = cs_breakout.subForHour(t2);
					} else if (t2.after(cs_breakout) && t1.before(cs_breakout) && t1.afterEquals(cs_breakin)) {
						MyLog.debug(this, "CASE 5 : yyyyy");
						this.inBreak = true;						
						this.hourBreakEmp = t1.subForHour(cs_breakin);
					} else if (t1.afterEquals(cs_breakin) && t2.beforeEquals(cs_breakout)) {
						MyLog.debug(this, "CASE 6 : �������͡��ѧ���§");
						this.inBreak = true;						
						this.hourBreakEmp = cs_breakout.subForHour(cs_breakin);
					} else if (t1.before(cs_breakin) && t2.after(cs_breakout)) {
						MyLog.debug(this, "CASE 7 : ��ҡ�͹���§����͡��ѧ���§");
						this.inBreak = true;						
						this.hourBreakEmp = cs_breakout.subForHour(cs_breakin);
					}
					
					//�óա�˹� �ͷշӨ�ԧ �ҡ�����ٴ��������͡��������ǧ�ѡ����Ѻ������ҡѺ��������������ش�ѡ  (mod. 13-01-2014)
					/* OT_COUNT ��ùѺ���ҷ����ͷ�
					 * 0 = ���͹��ѵ�
					 * 1 = ��÷Ө�ԧ
					 * 2 = �к��Ѻ���
					 */
					int OT_COUNT = Integer.parseInt((String) propertyShf.get("OT_COUNT"));
					if(OT_COUNT == 1){
						/* in */
						if(t1.afterEqualsDateTime(cs_breakin) && t1.beforeEqualsDateTime(cs_breakout)){
							m_dt_in = new CscCalendar(cs_breakout.getYYYYMMDDHHMMSS());
						}
						/* out */
						if(t2.afterEqualsDateTime(cs_breakin) && t2.beforeEqualsDateTime(cs_breakout)){
							m_dt_out = new CscCalendar(cs_breakin.getYYYYMMDDHHMMSS());
						}
					}
								
					//�óբҴ�ҹ����ѹ
					//if ((m_dt_in==null && m_dt_out==null) || (m_dt_in.equals(m_dt_out))) {
					if ((m_dt_in==null && m_dt_out==null) || (m_dt_in != null && m_dt_out != null && m_dt_in.equals(m_dt_out))) {
						if (!this.getString("TR_TYPE").equals("") && !this.getString("TR_TYPE").substring(0,1).equals("O")) {
							this.inBreak = true;
							this.hourBreakEmp = cs_breakout.subForHour(cs_breakin);
						} else {
							this.inBreak = false;
						}
					}
				}
			}			
            
            String previousShiftType = this.getString("previousshift");
            String nextShiftType = this.getString("nextshift");
            
            long startCal=System.currentTimeMillis();	
            DayCalculation DC = new DayCalculation(); //�ӡ���� ������� �ͷ�

            DC.setTime1(this);	/* �觢����� ttime_current1 ���ҹ */
			DC.calculate(propertyShf, c_dt_in, c_dt_out, m_dt_in, m_dt_out, tz, previousShiftType, nextShiftType, o_dt_in, o_dt_out, sh_dt_in, sh_dt_out, this.getString("tr_type")
					,this.getString("doctype")); //�ӹdz �Ҵ �� ����� �ͷ�
			
			long endCal = System.currentTimeMillis();			 
							
			String OT_Count = propertyShf.get("OT_COUNT").toString(); //��������ٻẺ��äԴ�ͷ�		
			
			float late = this.changSignNumber(DC.getLate());
			float tmp_actual_late = this.changSignNumber(DC.getActualLate());	/* ������ ��͹��º͹������� */ 
			float leave = this.changSignNumber(DC.getAbsentAll());
			float ot  = this.changSignNumber(DC.getOT_All()); 
			float ot_before = this.changSignNumber(DC.getOT_Before());
			float ot_after = this.changSignNumber(DC.getOT_After());
			
			this.set("hour_d", DC.getHourD());	//����Ѻ�Ӥú��� ��. ������ �Фӹdz ��. �ӧҹ����ѹ���
						
			if (!this.getString("TR_TYPE").equals("") && (!this.getString("DOCTYPE").equals("") || (this.getString("DOCTYPE").equals("") && (this.getString("EVENTGRP").equals("H")||this.getString("EVENTGRP").equals("I"))))) {
				if (this.getString("TR_TYPE").substring(0,1).equals("A")&&this.getString("DOCTYPE").equals("S")) {
					late = 0;
					leave = this.getHourD();
					ot = 0;
					ot_before = 0;
					ot_after = 0;
					b=true;
				} else if (this.getString("TR_TYPE").substring(0,1).equals("A")&&this.getString("DOCTYPE").equals("A")) {
					late = 0;
					ot = 0;				
					ot_before = 0;
					ot_after = 0;
					if (this.getFloat("m_lv")>0)						
						leave = this.getFloat("m_lv");
					else leave = this.getFloat("c_lv");
					b=true;
				} else if (this.getString("TR_TYPE").substring(0,1).equals("O")||
						this.getString("TR_TYPE").substring(0,1).equals("H")){
					float otAll=0;
					if (m_dt_in!=null && m_dt_out!=null && !m_dt_in.equals(m_dt_out)) {	
						if (OT_Count.equals("2")) {
							CscCalendar t_in = null;
							CscCalendar t_out = null;
							if (m_dt_in.before(c_dt_in)) {
						 		t_in = c_dt_in;
						 	} else t_in = m_dt_in;
						 	if (m_dt_out.before(c_dt_out)) {
						 		t_out = m_dt_out;
						 	} else t_out = c_dt_out;
						 	otAll = deductBreak(t_out.subForHour(t_in));
						} else if(OT_Count.equals("0")){
							if(this.getString("doctype").equals("O") || this.getString("doctype").equals("OM") || this.getString("doctype").equals("B")){
								otAll = m_dt_out.subForHour(m_dt_in);
							}
						}else{
							otAll = m_dt_out.subForHour(m_dt_in);						
						}
					} else { 
						otAll=DC.getOT_All();
						//b=true;
					}
					ot =  this.changSignNumber(otAll);
					if (!this.getString("eventgrp").equalsIgnoreCase("H") 
							&& !this.getString("eventgrp").equalsIgnoreCase("I")) {
						late = 0;
						leave = 0;
					}
				}			
			}	
					
			//����� �Ѻ ��. �ͷ� ���ҧ�� ���硨ҡ����� OT_COUNT � MTIME0
			if (OT_Count.equalsIgnoreCase("0")) { //�ҡ���͹��ѵ�
				ot = this.getFloat("AP_OT");
				if (c_dt_in.before(sh_dt_in)) {
					ot_before = sh_dt_in.subForHour(c_dt_in);
				}else{
					//ot_before = 0.0f; /*�����Ҩ��������ͷ��� ��ӹdz����ͷա�͹��� (��������Ҩй����)*/
				}
				if (c_dt_out.after(sh_dt_out)) {
					if(c_dt_in.afterDateTime(sh_dt_out)){ /* �ͷ���ѧ����͡л��� �ӹdz�ҡ������鹢� ����������������شἹ���� */
						ot_after = c_dt_out.subForHour(c_dt_in);	
					}else{
						ot_after = c_dt_out.subForHour(sh_dt_out);
					}
				}else{
					//ot_after = 0.0f; 	/*�����Ҩ��������ͷ��� ��ӹdz����ͷ���ѧ��� (��������Ҩй����)*/
				}
			} else if (OT_Count.equalsIgnoreCase("1")) { //�ҡ��÷Ө�ԧ
				//ot = this.getFloat("AC_OT");
			} else if (OT_Count.equalsIgnoreCase("2")) { //�ҡ�����ͷշ����·���ش				
				if (this.getFloat("AP_OT")<ot) {
					ot = this.getFloat("AP_OT");
					if (late>0) {
						CscTime ct = new CscTime(ot);
						ct.sub(late);
						ot = ct.getFloat();
					}
				}				
			} else if (OT_Count.equalsIgnoreCase("3")) { //�ҡ��÷Ө�ԧ �������ͷա�͹���ҧҹ
				ot = DC.getOT_After();
			} else if (OT_Count.equalsIgnoreCase("4")) { //�ҡ��÷Ө�ԧ �������ͷ���ѧ���ҧҹ
				ot = DC.getOT_Before();
			} else if (OT_Count.equalsIgnoreCase("5")) { //�ҡ���͹��ѵ� ����ͷա�͹���ҧҹ
				CscTime ct = new CscTime(this.getFloat("AP_OT"));
				ct.add(DC.getOT_Before());
				ot = ct.getFloat();
			}  else if (OT_Count.equalsIgnoreCase("6")) { //�ҡ���͹��ѵ� ����ͷ���ѧ���ҧҹ
				CscTime ct = new CscTime(this.getFloat("AP_OT"));
				ct.add(DC.getOT_After());
				ot = ct.getFloat();
			}				
			
			setO_TM_Datetime(propertyShf);	/* ��˹���ǧ����������� ����ش�ͷ� �����÷ӧҹ��ԧ */
			
			//������ͷշ��Өе�ͧ�դ�����ҧ���¡Ѻ�ͷյ���ش
			 float min_ot = Float.valueOf((String) propertyShf.get("MIN_OT")).floatValue();
			 if (ot<min_ot) {
				ot = 0;
				ot_before = 0;
				ot_after = 0;
			}
			
			//���������Թ���ҷ���˹�����٧�ش������� �����ӡ���ѡ���Ҿѡ����
			String sticktm = propertyShf.get("STICKTM").toString();
			float mxlate = Float.valueOf(propertyShf.get("MAXLATE").toString()).floatValue();			
			/* ����Ѻ �Ӥú ��� ��. ������ */
			if(sticktm.equals("T")){
				if(DC.getAbsentAll() > 0){
					this.hm.put("late_type", (String) propertyShf.get("ABSENT"));
				}else {
					this.hm.put("late_type", "NULL");	
				}
			}else if (!sticktm.equals("N") && DC.getAbsentAll()>0 && this.getString("tr_type").indexOf("A")<=-1) {
				/* ��� ��. ����ҡ����͹������� �����͡��͹������ԡ�ҹ �������繢Ҵ�ҹ */
				if(DC.getAbsentIn()>= mxlate || DC.getAbsentOut() > 0){
					this.hm.put("late_type", (String) propertyShf.get("ABSENT"));
					this.set("eventgrp", (String) propertyShf.get("ABSENT"));
				}
				
				boolean chkInStopZone = false; //������ҡ��������㹪�ǧ�ͧ��þѡ����ѡ�ѡ����
				if (m_dt_in.afterEquals(cs_breakin) && m_dt_out.beforeEquals(cs_breakout)) {
					chkInStopZone = true;
				}
					
				if (this.inBreak==true && this.hourBreakEmp>0 && !chkInStopZone && m_dt_in.after(cs_breakin)) {
					CscTime ct = new CscTime(leave);
					/**
					 * Author : Nuiss 
					 * Date : 21/10/2552
					 * Logic : ��� ʹ��ٴ������ҧ���� ��� �ٴ��� ��ѧ �����͡�ͧ�ѡ���§ 
					 * ���� ź ������ �͡���� �� �ѡ���§
					 */
					if(sticktm.equals("I")){
						if(m_dt_in.after(cs_breakout)){
							ct.sub(this.hourBreakEmp);
						}//end if 
					}else{
						//�ͧ��� ����
						//ct.sub(this.hourBreakEmp); 
					}//end if 			
					leave = ct.getFloat();
				}			
			} else this.hm.put("late_type", "NULL");	
			
			//��������ѹ��ش �������բ����š��ŧ���Ҥú�ͧ�� ������ͷ�
			if (this.getString("forget_in").equals("") && this.getString("forget_out").equals("")) {
				if(!this.getString("eventgrp").equalsIgnoreCase("H")&&!this.getString("eventgrp").equalsIgnoreCase("I")){ /* MPT ��ͧ������ӹdz ��. �ͷա�͹�����ѧ��ѹ��ش���� */
					ot = 0;
					ot_before = 0;
					ot_after = 0;		
				}
			}
			
			//��������ٴ�ѵ��������͡���������ǡѹ �������ҢҴ�ҹ
			if (!sticktm.equals("N") && m_dt_in!=null && m_dt_out!=null) {
				if (m_dt_in.equals(m_dt_out) && this.getString("eventgrp").equals("T")) {
					this.hm.put("late_type", (String) propertyShf.get("ABSENT"));
					this.set("eventgrp", (String) propertyShf.get("ABSENT"));
					this.set("lv_ty", (String) propertyShf.get("ABSENT"));
				}			
			}
			
			//��� ��.�ҷ��Դ�� �ҡ���� �ӹǹ ��.�ӧҹ/�ѹ ����.��=��.�ӧҹ/�ѹ
			if (leave>this.getFloat("hour_s")) {
				leave = this.getFloat("hour_s");
			}

			//LATESTANG = �Ѵ�����, OTSTANG  = �Ѵ�ͷ�, STOPSTANG = �Ѵ�����		
			MyHashMap hmTmp = (MyHashMap) this.hmTime.get(this.getString("time0id"));
			try {
				this.hm.put("tmp_late", new Double (this.getRoudingValue(hmTmp.get("LATESTANG").toString(), Double.parseDouble(String.valueOf(late)))));
				this.hm.put("tmp_leave", new Double (this.getRoudingValue(hmTmp.get("STOPSTANG").toString(), Double.parseDouble(String.valueOf(leave)))));
				this.hm.put("tmp_otwork", new Double (this.getRoudingValue(hmTmp.get("OTSTANG").toString(), Double.parseDouble(String.valueOf(ot)))));
				this.hm.put("tmp_otbefore", new Double (this.getRoudingValue(hmTmp.get("OTSTANG").toString(), Double.parseDouble(String.valueOf(ot_before)))));
				this.hm.put("tmp_otafter", new Double (this.getRoudingValue(hmTmp.get("OTSTANG").toString(), Double.parseDouble(String.valueOf(ot_after)))));
				this.hm.put("tmp_actual_late", new Double(tmp_actual_late));	/* ��¡�͹��º͹������� */
				
				/* ����ͷա�͹�Ѵ��� */
				this.hm.put("late_noround", new Double (Double.parseDouble(String.valueOf(late))));
				this.hm.put("leave_noround", new Double (Double.parseDouble(String.valueOf(leave))));
				this.hm.put("ac_ot_noround", new Double (Double.parseDouble(String.valueOf(ot))));
				this.hm.put("ot_before_noround", new Double (Double.parseDouble(String.valueOf(ot_before))));
				this.hm.put("ot_after_noround", new Double (Double.parseDouble(String.valueOf(ot_after))));
			} catch (Exception e5) {
				MyLog.error(this, e5);
				this.hm.put("tmp_late", new Double (String.valueOf(late)));
				this.hm.put("tmp_leave", new Double (String.valueOf(leave)));
				this.hm.put("tmp_otwork",new Double (String.valueOf(ot)));
				this.hm.put("tmp_otbefore",new Double (String.valueOf(ot_before)));
				this.hm.put("tmp_otafter",new Double (String.valueOf(ot_after)));
				this.hm.put("tmp_actual_late", new Double(tmp_actual_late));	/* ��¡�͹��º͹������� */
				
				/* ����ͷա�͹�Ѵ��� */
				this.hm.put("late_noround", new Double (String.valueOf(late)));
				this.hm.put("leave_noround", new Double (String.valueOf(leave)));
				this.hm.put("ac_ot_noround",new Double (String.valueOf(ot)));
				this.hm.put("ot_before_noround",new Double (String.valueOf(ot_before)));
				this.hm.put("ot_after_noround",new Double (String.valueOf(ot_after)));
			}
		} catch (Exception e) {
			MyLog.error(this, e);	
			this.ttl.addDateError("ERROR", this.getString("dateid"), e.getMessage());	/* err log */
		}
	}
	
	private float deductBreak(float ot_after){
		try {
			MyHashMap hmTmp = (MyHashMap) this.hmTime.get(this.getString("time0id"));
			float stp_ot = Float.valueOf(hmTmp.get("STP_OT").toString()).floatValue();
			
			/* Ἱ */
			CscCalendar csshstart = this.getCscCalendar("sh_dt_bg");
			csshstart.setCSCTime(this.getFloat("sh_tm_bg"));

			CscCalendar csshend = this.getCscCalendar("sh_dt_en");
			csshend.setCSCTime(this.getFloat("sh_tm_en"));
			
			/* Ἱ���ͷ� */
			CscCalendar cscstart = this.getCscCalendar("c_dt_bg");
			cscstart.setCSCTime(this.getFloat("c_tm_bg"));
			
			CscCalendar cscend = this.getCscCalendar("c_dt_en");
			cscend.setCSCTime(this.getFloat("c_tm_en"));			
			
			if (cscstart.beforeEqualsDateTime(csshend) && cscend.afterDateTime(csshend)) {
				if (ot_after >= stp_ot) {
					CscTime c2 = new CscTime(ot_after);
					c2.sub(stp_ot);
					ot_after = c2.getFloat();
				} else {
					ot_after = 0;
				}
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return ot_after ;
	}
	
	private float changSignNumber(float data){		
		if (data<0) {
			return data*(-1);
		} else return data;
	}	
		
	public FieldManager getField(String fieldName) {
		/**
		 * @author aGaziin
		 * cuz : ���ͧ�ҡ�ͧ����� indexOf �������������¡ field ot ������仴��� �����������������˵�
		 * sol : ��� prority sign (���ͧ���� �١���)
		 */
        String fieldCal = ",tmp_actual_late,tmp_late,tmp_leave,tmp_otwork,late_type,tmp_otbefore,tmp_otafter,late_noround,leave_noround,ac_ot_noround,ot_before_noround,ot_after_noround,";
        FieldManager fm = super.getField(fieldName);
        if (fieldCal.toLowerCase().indexOf(","+fieldName.toLowerCase()+",") > -1) {
            if (this.hm.isEmpty()) {
                this.calulateDayTran();
            }
            
            /**  check null */
            double data = 0.0d;
            if(this.hm.containsKey(fieldName.toLowerCase())){
            	data =((Double) this.hm.get(fieldName.toLowerCase())).doubleValue();
            }//end if 
            
            fm = this.initField("String", "", 100, 0, "");
            fm.setWorking(true);
            fm.setUProfile(this.userPro);
            fm.setDescription(fieldName);
            fm.setName(fieldName.toLowerCase());
            fm.set(data);
        } else if (fieldName.equalsIgnoreCase("action")) {
            this.action();
        } else if (fieldName.equalsIgnoreCase("simhour_d")) {
            fm = (FieldManager) this.initField("simhour_d");
            double data = 0;
            data = this.getDouble("hour_d") + Double.parseDouble(this.getSimHour());
            fm.set(data);
        } else if (fieldName.equalsIgnoreCase("countEmpBu1")) {
            fm = (FieldManager) this.initField("countEmpBu1");
        } else if (fieldName.equalsIgnoreCase("countEmpBu2")) {
            fm = (FieldManager) this.initField("countEmpBu2");
        } else if (fieldName.equalsIgnoreCase("countEmpBu3")) {
            fm = (FieldManager) this.initField("countEmpBu3");
        } else if (fieldName.equalsIgnoreCase("countEmpBu4")) {
            fm = (FieldManager) this.initField("countEmpBu4");
        } else if (fieldName.equalsIgnoreCase("countEmpBu5")) {
            fm = (FieldManager) this.initField("countEmpBu5");
        } else if (fieldName.equalsIgnoreCase("countEmpBranch")) {
            fm = (FieldManager) this.initField("countEmpBranch");
        } else if (fieldName.equalsIgnoreCase("countEmpJob")) {
            fm = (FieldManager) this.initField("countEmpJob");
        } else if (fieldName.equalsIgnoreCase("countEmpPosition")) {
            fm = (FieldManager) this.initField("countEmpPosition");
        } else if (fieldName.equalsIgnoreCase("sumOt")) {            
            fm = (FieldManager) this.initField("sumOt");
            FormulaString fs = new FormulaString();
            int ot1 = 0, ot2 = 0, ot3 = 0, ot5 = 0;
            double otsum = 0;
            ot1 = fs.Tm_To_Min(Double.valueOf(this.getString("ot1")).doubleValue());
            ot2 = fs.Tm_To_Min(Double.valueOf(this.getString("ot2")).doubleValue());
            ot3 = fs.Tm_To_Min(Double.valueOf(this.getString("ot3")).doubleValue());
            ot5 = fs.Tm_To_Min(Double.valueOf(this.getString("ot5")).doubleValue());
            otsum = Double.valueOf(fs.Min_to_tm(ot1 + ot2 + ot3 + ot5)).doubleValue();
            fm.set(otsum);
        } else if (fieldName.equalsIgnoreCase("timeoutsubin")) { //�����͡-������Ңͧ��ѡ�ҹ ���ѡ�ѡ���§
			try {
				CscCalendar time_in = new CscCalendar(this.getString("m_dt_bg"));
				time_in.setCSCTime(this.getFloat("m_tm_bg"));
				CscCalendar time_out = new CscCalendar(this.getString("m_dt_en"));
				time_out.setCSCTime(this.getFloat("m_tm_en"));
				CscCalendar break_in = new CscCalendar(this.getString("dt_breakin"));
				break_in.setCSCTime(this.getFloat("tm_breakin"));			
				CscCalendar break_out = new CscCalendar(this.getString("dt_breakout"));
				break_out.setCSCTime(this.getFloat("tm_breakout"));
				
				DiffTime dt = new DiffTime();
				float time = dt.TimeOutDiffTimeIn(time_in, time_out, break_in, break_out);

				fm = this.initField("String", "", 100, 0, "");
	            fm.setWorking(true);
	            fm.setUProfile(this.userPro);
	            fm.setDescription(fieldName);
	            fm.setName(fieldName.toLowerCase());
	            fm.set(this.df.format(Double.parseDouble(String.valueOf(time))));	            
			} catch (Exception e) {
				MyLog.error(this, e);
			}
        }else if (fieldName.toLowerCase().indexOf("leaveremain_")>-1){ //�Ҩӹǹ ��.�ҷբͧ��÷������ͨҡ�����ҹ
	    	fm = this.initField("Float", fieldName, 20, 0, "LEAVE REMAIN");
			fm.setWorking(true);
			ServiceTimeWorking st = new ServiceTimeWorking();
			st.setUProfile(this.userPro);
			String lv_type = fieldName.substring(fieldName.indexOf("_")+1, fieldName.length());
			fm.set(st.getLeaveRemain(this.getString("employeeid"), lv_type));
	    } else if (fieldName.toLowerCase().indexOf("leaveuse_")>-1){ //�Ҩӹǹ ��.�ҷբͧ��� ��
	    	
	    	/** �ӹǹ���ѹ�ҷ����� */
	    	fm = this.initField("Float", fieldName, 20, 0, "LEAVE USE");
			fm.setWorking(true);
			ServiceTimeWorking st = new ServiceTimeWorking();
			st.setUProfile(this.userPro);
			String lv_type = fieldName.substring(fieldName.indexOf("_")+1, fieldName.length());
			
			CscCalendar cscLeaveStart = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1001"));
			CscCalendar cscLeaveEnd = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1002"));
	 
			fm.set(st.getTimeLeaveUse(this.getString("employeeid"), cscLeaveStart.getYYYYMMDD(),cscLeaveEnd.getYYYYMMDD(),lv_type));
	    } else if (fieldName.toLowerCase().indexOf("curlvuse_")>-1){ //�Ҩӹǹ ��.�ҷբͧ��� ��
	    	/** �ӹǹ���ѹ�ҷ����� �¨ФԴ �ѹ�ش���¶֧  ���ѹ�����ѧ process ������ҹ�� */
	    	fm = this.initField("Float", fieldName, 20, 0, "CURRENT LEAVE USE");
			fm.setWorking(true);
			ServiceTimeWorking st = new ServiceTimeWorking();
			st.setUProfile(this.userPro);
			String[] dataFromFormula = fieldName.split("_");
			String lv_type="";
			String curDate="";
			if(dataFromFormula.length<3){
				lv_type = dataFromFormula[1];
				curDate = (String) StaticConfig.getConfigCompany(this.userPro, "ta1002");
			}else{
				lv_type = dataFromFormula[1];
				curDate = dataFromFormula[2];
			}//end if  
			CscCalendar cscLeaveStart = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1001"));
			CscCalendar cscLeaveEnd = new CscCalendar(curDate);
	 
			fm.set(st.getTimeLeaveUse(this.getString("employeeid"), cscLeaveStart.getYYYYMMDD(),cscLeaveEnd.getYYYYMMDD(),lv_type));
	    } else if (fieldName.toLowerCase().indexOf("curvacuse_")>-1){ //�Ҩӹǹ ��.�ҷբͧ��� ��
	    	/** �ӹǹ���ѹ�ҷ�����(੾�оѡ��͹) �¨ФԴ �ѹ�ش���¶֧���ѹ�����ѧ process ������ҹ�� */
	    	fm = this.initField("Float", fieldName, 20, 0, "CURRENT VACATION USE");
			fm.setWorking(true);
			ServiceTimeWorking st = new ServiceTimeWorking();
			st.setUProfile(this.userPro);
			String[] dataFromFormula = fieldName.split("_");
			String lv_type="";
			String curDate="";
			if(dataFromFormula.length<3){
				lv_type = dataFromFormula[1];
				curDate = (String) StaticConfig.getConfigCompany(this.userPro, "ta1004");
			}else{
				lv_type = dataFromFormula[1];
				curDate = dataFromFormula[2];
			}//end if 
			CscCalendar cscVacationStart = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1003"));
			CscCalendar cscVacationEnd = new CscCalendar(curDate);
	 
			fm.set(st.getTimeLeaveUse(this.getString("employeeid"), cscVacationStart.getYYYYMMDD(),cscVacationEnd.getYYYYMMDD(),lv_type));
	    } else if (fieldName.toLowerCase().indexOf("vacationuse_")>-1){ //�Ҩӹǹ ��.�ҷբͧ��� ��
	   	 	/** �ӹǹ���ѹ��(੾�оѡ��͹)������ */
	    	fm = this.initField("Float", fieldName, 20, 0, "VACATION USE");
			fm.setWorking(true);
			ServiceTimeWorking st = new ServiceTimeWorking();
			st.setUProfile(this.userPro);
			String lv_type = fieldName.substring(fieldName.indexOf("_")+1, fieldName.length());
			
 			CscCalendar cscVacationStart = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1003"));
			CscCalendar cscVacationEnd = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1004"));

			fm.set(st.getTimeLeaveUse(this.getString("employeeid"), cscVacationStart.getYYYYMMDD(),cscVacationEnd.getYYYYMMDD(),lv_type));
	    } else if (fieldName.toLowerCase().indexOf("timelate")==0){
	    	/** �ӹǹ ��. ��� ���Ѻ�ѹ��ش */
	    	fm = this.initField("Float", fieldName, 20, 0, "TIME LATE");
			fm.setWorking(true);
			ServiceTimeWorking st = new ServiceTimeWorking();
			st.setUProfile(this.userPro);
			String[] dataFromFormula = fieldName.split("_");
			String curDate="";
			if(dataFromFormula.length<2){
				curDate = (String) StaticConfig.getConfigCompany(this.userPro, "ta1002");
			}else{
				curDate = dataFromFormula[1];
			}//end if 
			CscCalendar cscLateStart = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1001"));
			CscCalendar cscLateEnd = new CscCalendar(curDate);
	 
			fm.set(st.getTimeLate(this.getString("employeeid"), cscLateStart.getYYYYMMDD(),cscLateEnd.getYYYYMMDD()));
	    }
        
        return fm;
    }	
	
	private String getSimHour(){
		String hr="";
		DbInquiry inq = null;
		try{
			CscCalendar cs=new CscCalendar(this.getString("dateid"));
			String sql="employeeid='"+this.getString("employeeid")+"' and companyid='"+this.getString("companyid")+"' and dateid='"+cs.getYYYYMMDD()+"'";			
			inq = new InitialInquiry(this.userPro).getDbInquiry();
			inq.setParam(this.param);	
			inq.setSchemaName(this.userPro.getSchemaName());
			inq.initMyTable("Ttime_history1",sql, "");
	    	inq.setColumn("*");
	    	inq.refresh();
	    	inq.next();	    	
	    	hr=inq.getString("hour_d");	
		} catch(Exception e){
			MyLog.error(this, e);						
		}
		finally{
			try{
				inq.closeConnection();
			}catch(Exception e){
				MyLog.error(this, e);
			}
		}
		return hr;
	}
	
	/* ��˹���������´�ͧ ��ѡ�ҹŧ㹿�Ŵ�� system (�͹�����ͧ FW ᷹) */
	private void setEmployeeDetail(){
		try {
			DbRecord rec = this.getEmpRecord();
			this.set("emp_position",rec.getString("emp_position"));
			this.set("emp_group",rec.getString("emp_group"));				
			this.set("branch",rec.getString("branch"));
			this.set("jobcode",rec.getString("job"));
			this.set("bu1",rec.getString("bu1"));
			this.set("bu2",rec.getString("bu2"));
			this.set("bu3",rec.getString("bu3"));
			this.set("bu4",rec.getString("bu4"));
			this.set("bu5",rec.getString("bu5"));
			this.set("bossid",rec.getString("bossid"));
			this.set("emp_level",rec.getString("emp_level"));
			this.set("costcenter",rec.getString("costcenter"));
			this.set("salatype",rec.getString("salatype"));
			this.set("currency",rec.getString("costcenter"));
			this.set("salary",rec.getString("salary"));
			this.set("every",rec.getString("emp_every"));			
			this.set("workarea",rec.getString("workarea"));	
			CscCalendar csc = new CscCalendar(this.getString("dateid"));
			this.set("daytype", csc.getCSCDOW());	
		} catch (Exception e) {
			MyLog.error(this, e);			
		}		
	}
	
	/** ��㹡�ûѴ��ɵ�ҧ�  */
	public double getRoudingValue(String roundid, double value) {
		double result=0;
		try {
			RoundingTime rt = new RoundingTime(roundid, value);
			rt.setUProfile(this.userPro);
			result = rt.getRounding();			
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
		return result;
	}

	protected boolean action(){
		try {
			hm.clear();
			this.setEmpTimeCode();			
			long start=System.currentTimeMillis();
			
			String flag_ot = "0"; 
			try {
				flag_ot = (String) StaticConfig.getConfigCompany(this.userPro, "ta1008");
				if (flag_ot.equals("1")) {
					this.calOTAdjust = true;
					this.loadOTAdjust();
				} else this.calOTAdjust = false;
			} catch (Exception e) {
				MyLog.error("Can't get ConfigCompany TA1008", e);
			}
			
			String flag_cost = "0";
			try {
				flag_cost = (String) StaticConfig.getConfigCompany(this.userPro, "ta1009");
				if (flag_cost.equals("1")) {
					this.calCostcenter = true;
					this.loadCostcenter();
				} else this.calCostcenter = false;
			} catch (Exception e) {
				MyLog.debug("Can't get ConfigCompany TA1009");
			}			
			
			String flag_buslate = "0";
			try {
				flag_buslate = (String) StaticConfig.getConfigCompany(this.userPro, "ta1010");
				if (flag_buslate.equals("1")) {
					this.calBusLate = true;
					this.loadBusLate();
				} else this.calBusLate = false;
			} catch (Exception e) {
				MyLog.debug("Can't get ConfigCompany TA1010");
			}			
			
			String flag_unused = "0";
			try {
				flag_unused = (String) StaticConfig.getConfigCompany(this.userPro, "ta1011");
				if (flag_unused.equals("1")) {
					this.calUnused = true;
					this.loadUnused();
				} else this.calUnused = false;
			} catch (Exception e) {
				MyLog.debug("Can't get ConfigCompany TA1011");
			}	
					
			this.loadTimeData(); //�֧��������������´�ͧ��� Mtime0
			this.loadDayTimeData(); //�֧������� Mtime1

			this.hm.remove("tmp_late");	/* always clear hashmap before calculate lt,m_lv,ac_ot,ot_before,ot_after */
			this.hm.remove("tmp_leave");
			this.hm.remove("tmp_otwork");
			this.hm.remove("tmp_otbefore");
			this.hm.remove("tmp_otafter");
			this.hm.remove("late_type");
			
    		this.set("lt", this.getField("tmp_late").getString());			
    		this.set("m_lv", this.getField("tmp_leave").getString());			
    		this.set("ac_ot", this.getField("tmp_otwork").getString());
    		this.set("ot_before", this.getField("tmp_otbefore").getString());
    		this.set("ot_after", this.getField("tmp_otafter").getString());
    		this.actual_late = this.getField("tmp_actual_late").getFloat();
    		
    		/*��͹�Ѵ��� */
    		this.late_noround = this.getField("late_noround").getFloat();			
    		this.leave_noround = this.getField("leave_noround").getFloat();			
    		this.ac_ot_noround = this.getField("ac_ot_noround").getFloat();
    		this.ot_before_noround = this.getField("ot_before_noround").getFloat();
    		this.ot_after_noround = this.getField("ot_after_noround").getFloat();
    		
    		/* �ӹdz AP �ͷ� ������ͧ�ҡ������ա�� adjust �ͷ�ŧ�Ἱ */
			// this.CalAPOvertime(this); ����͡��͹ ��������׹ 
    		
    		this.setDefaultDate(); //��˹��������������Ѻ field ��ҧ�
    		
    		//��Ǩ�ͺ�������¡Ѻö
    		CscCalendar dateLate = new CscCalendar(this.getString("dateid"));
    		if (this.calBusLate) {
	    		if (this.hmBusLate==null) this.getBusLate();
	    		if (this.getFloat("lt")>0 && this.hmBusLate.containsKey(dateLate.getDDMMYYYY())) {
	    			CscCalendar c1 = new CscCalendar(this.getString("m_dt_bg"));
	    			c1.setCSCTime(this.getFloat("m_tm_bg"));
	    			
	    			CscCalendar c2 = new CscCalendar(this.getString("c_dt_bg"));
	    			c2.setCSCTime(Float.parseFloat(this.hmBusLate.getString(dateLate.getDDMMYYYY())));
	    			
	    			float s1 = c1.subForHour(c2);
	    			if (s1 > 0) {
	    				this.set("lt", s1);
	    			} else this.set("lt", 0);
	    		}
    		}	
    		
    		/* �����ʡлѨ�غѹ�����㹡�û����ż� (���ʢͧ���ҷӧҹ��ԧ��ѹ���) ��������ʢͧ�з�������ʡ�����ͧ���ҧ��÷���繤�ҿ�Ŵ� Time0 � Memployee)*/
            String strTime0id = this.getString("time0id");
            if (strTime0id.equals("")) {
            	strTime0id = this.empTimeCode;
            } 
            
    		MyHashMap hmTime = (MyHashMap) this.hmTime.get(strTime0id);
    		String stick_type = (String) hmTime.get("STICKTM");
    		float h = 0;
   		    if( stick_type.equalsIgnoreCase("T") && this.getString("tr_type").indexOf("A") == -1){
   		    	h = this.getFloat("hour_d");// flexible time �١�ӹǹ�ҡ DayCalculation �ҡ��ҹ��
   		    }else{
   		    	h = this.calulateHourD(); //�ӹdz ��. ��÷ӧҹ��ѹ���
   		    }
   		    
   		    /* __hour_count is 0 */
   		    try {
	   		    String hour_count = (String) hmTime.get("HOUR_COUNT");
	   		    if(hour_count.equals("0")){
	   		    	if(this.getString("eventgrp").equals("O")
	   		    			|| ( (this.getString("eventgrp").equals("H") || this.getString("eventgrp").equals("I"))
	   		    					&& this.getFloat("ap_ot") > 0)) {
		   		    	if(h > this.getFloat("ap_ot")){
		   		    		h = this.getFloat("ap_ot");
		   		    	}
	   		    	}else{
	   		    		if(h > Float.parseFloat((String)hmTime.get("HOUR_D"))){
		   		    		h = Float.parseFloat((String)hmTime.get("HOUR_D"));
		   		    	}
	   		    	}
	   		    }
   		    }catch(Exception e){
   		    	MyLog.error(this,e);
   		    }

    		if (h<0) {
    			this.set("hour_d", 0);
    		} else {
    			this.set("hour_d", h);
    			/*
    			if(!stick_type.equals("T")){
    				this.set("hour_d", h);
    			}*/
    		}
    		
    		try {
    			if (this.getFloat("hour_s")==0) {
    				this.set("hour_s", this.getHourD()); //chk hour_s ��. �ӧҹ����ѹ
    			}
    		} catch (Exception e) {
    			MyLog.error(this, e);
    		}
    		
    		if (stick_type.equals("N")) { //���ʹ���������͡ ��� �� ��÷ӧҹ = �� ����ѹ����
    			/* 
    			 * ੾���ѹ���ӧҹ��ҹ�� �� ��. �ӧҹ�Դ�ҡ Ἱ����͡ �ҡ ��. �ӧҹ�ҡ���ҡ��� hour_s ����Ѻ��ҡѺ hour_s  
    			 * */
    			CscCalendar st = this.getCscCalendar("c_dt_bg");
				CscCalendar en = this.getCscCalendar("c_dt_en");
				st.setCSCTime(this.getFloat("c_tm_bg"));
				en.setCSCTime(this.getFloat("c_tm_en"));
				
    			if(this.getString("eventgrp").equals("T")){	
    				float whr = en.subForHour(st);
    				if(whr > this.getFloat("hour_s")){
    					this.set("hour_d", this.getString("hour_s"));
    				}else{
    					this.set("hour_d", whr);
    				}
    			}
    		}
    		
    		if (!this.hm.get("late_type").equals("NULL") && !this.getString("doctype").equals("A")) { //����ա������ҡ���ҡ�˹� ����������� ��˹��������ѹ����繡�âҴ�ҹ
    			MyHashMap hmTmp = (MyHashMap) this.hmTime.get(strTime0id); //edit on 18-08-2010
    			
    			/* �óջ�Ѻ��� ��. �Ҵ�ҹ ��ͧ���ա���� ��� ��. �Ҵ�ҹ �ҡ���� 0 �֧�С�˹��������繢Ҵ�ҹ */
    			if(this.getFloat("m_lv") > 0){
    				this.set("eventgrp", (String) hmTmp.get("ABSENT"));
    			}else{
    				if(this.getString("eventgrp").equals("J")){
    					this.set("eventgrp", "T");
    				}
    			}
    			
    			
    			this.set("lv_ty", (String) hmTmp.get("ABSENT"));
    			if (this.getFloat("m_lv") > this.getFloat("hour_s")) { //��� ��.�ҷ��Դ�� �ҡ���� �ӹǹ ��.�ӧҹ/�ѹ ����.��=��.�ӧҹ/�ѹ
	    			this.set("m_lv", this.getString("hour_s"));
	    			this.set("tmp_leave", this.getString("hour_s"));
    			} 
    		}
    		    		
    		//������ѹ��ش��Ш��ѻ���������ѹ��ش���ླ� ��������㺢��ͷ� ��˹�����ҵ�ҧ� �� 0
    		if ((this.getString("EVENTGRP").equals("H") || this.getString("EVENTGRP").equals("I")) && this.getString("DOCNO").equals("")) { 
    			this.set("lt", 0);
    			this.set("m_lv", 0);
    			this.set("c_lv", 0);
    			//this.set("ap_ot", 0);
    			//this.set("ot_before", 0);
    			//this.set("ot_after", 0);
    			//this.set("hour_d", 0);	/* ���Զ�����ѹ��ش�е�ͧ �ա�� ��. ��÷ӧҹ �� MPT ��ͧ������ӹdz�͡�Ҵ��� �֧ comment ��÷Ѵ����͡ (�� ���Ǥ���) */
    			this.hm.put("late_type", "NULL");
    			this.hm.put("tmp_late", new Double (String.valueOf(0)));
				this.hm.put("tmp_leave", new Double (String.valueOf(0)));
				this.hm.put("tmp_otwork", new Double (String.valueOf(0)));
				//this.hm.put("tmp_otbefore", new Double (String.valueOf(0)));
				//this.hm.put("tmp_otafter", new Double (String.valueOf(0)));
    		}
    		  
    		//chk Actual Working Day
    		try {
    			double times = Double.parseDouble(StaticConfig.getConfigCompany(this.userPro, "ta1005"));
    			    			
    			CscCalendar c_in = new CscCalendar(this.getString("sh_dt_bg"));
    			c_in.setCSCTime(this.getFloat("sh_tm_bg"));
    			CscCalendar c_out = new CscCalendar(this.getString("sh_dt_en"));
    			c_out.setCSCTime(this.getFloat("sh_tm_en"));
    			
    			if (this.getString("doctype").equals("B") || this.getString("doctype").equals("O") || this.getString("doctype").equals("OM")) {
    				c_in = new CscCalendar(this.getString("c_dt_bg"));
        			c_in.setCSCTime(this.getFloat("c_tm_bg"));
        			c_out = new CscCalendar(this.getString("c_dt_en"));
        			c_out.setCSCTime(this.getFloat("c_tm_en"));
    			}
    			
    			CscCalendar cscDate = new CscCalendar(this.getString("dateid"));
    			cscDate.setCSCTime(times);
    			
    			if (!c_in.equalsDate(c_out) && c_in.getCSCTime()==times) { //�ѹ����������͡���ç�ѹ ��������ҵç�����ҷ���˹�
    				cscDate.incDate();
    			} else if (c_in.equalsDate(c_out) && c_out.getCSCTime()==times) { //�ѹ�����������͡�ç�ѹ �������͡�ç�������͡����˹�
    				cscDate.incDate();
    			} else if (c_in.equalsDate(c_out) && c_in.before(cscDate)) { //�ѹ�������͡�ç��չ �����ҹ��¡��ҡ�ùѺ�ѹ����
    				cscDate.decDate();
    			}
    			
    			this.set("date_actual", cscDate.getYYYYMMDD());
    		} catch (Exception e) {
    			MyLog.error(this, e);
    		}
    		
    		//��������ѹ��ش�������� �ҡ���������
    		/*
    		if (!this.getString("TR_TYPE").equals("") && !this.getString("TR_TYPE").substring(0,1).equals("A")) {
    			this.chkIsNonWorkDay();    			
    		}  */ 		    		
   		    		    		
    		CscCalendar csc = new CscCalendar(this.getString("dateid"));
			this.set("daytype", csc.getCSCDOW());	//��˹��ٻẺ�ѹ 1=�ѹ��� 7=�ҷԵ��
    		    		
    		if (this.getString("cost_borrow").trim().equals("") || this.getString("cost_borrow").trim().equals("NONE")) {
	        	this.set("cost_borrow", this.getString("costcenter"));
	        }
	        if (this.getString("ot_salatype").trim().equals("") || this.getString("ot_salatype").trim().equals("NONE")) {
	        	this.set("ot_salatype", this.getString("costcenter"));
	        }
	        
	        /* ����Ѻ��� PG �ж١���͡�������͡�ҡ MyNote ���Щ��鹨֧�����繵�ͧ set ���ʡ�������� */
	        /*
	        if (!this.getString("ot_time0").equals("")) { //����ա�á�͡���ʡз����ͷ��Ҩ�˹�Ҩ� �ӡ������¹������Ѻ���ҷ��ӧҹ ������Ҿѡ�ͧ��
	        	if (!this.hmDayTime.containsKey(this.getString("ot_time0"))) {				
					this.hmDayTime.put(this.getString("ot_time0"), this.refreshRecLoadDayTimeData(this.getString("ot_time0")));
				} 
	        	MyHashMap hCode = (MyHashMap) this.hmDayTime.get(this.getString("ot_time0"));
	        	if (hCode!=null && !hCode.isEmpty()) {
		        	MyHashMap hDay = (MyHashMap) hCode.get(this.getString("daytype"));
		        	if (hDay!=null) {
			        	this.set("sh_tm_bg", hDay.getDouble("timein1"));
			        	this.set("sh_tm_en", hDay.getDouble("timeout2"));
			        	this.set("tm_breakin", hDay.getDouble("timeout1"));
			        	this.set("tm_breakout", hDay.getDouble("timein2"));
			        	CscCalendar cDay = new CscCalendar(this.getString("dateid"));
		        		cDay.incDate();
			        	if (hDay.getDouble("timeout2")<hDay.getDouble("timein1")) {			        		
			        		this.set("sh_dt_en", cDay.getDDMMYYYY());			        		
			        	}
			        	
			        	if (hDay.getDouble("timeout1")<hDay.getDouble("timein1")) {
			        		this.set("dt_breakin", cDay.getDDMMYYYY());		
			        	}
			        	if (hDay.getDouble("timein2")<hDay.getDouble("timein1")) {
			        		this.set("dt_breakout", cDay.getDDMMYYYY());		
			        	}
		        	}
	        	}
	        }
	        */
	        /*
    		if (this.calOTAdjust && !this.getString("eventgrp").equals("J")) { //��˹�����ͷշ�����͡����ͧ �ҡ�˹�������Ѻ field
    			try {
	    			CscCalendar cs = new CscCalendar(this.getString("dateid"));
	    			if (this.hmOTAdjust==null) this.loadOTAdjust();
	    			if (this.hmOTAdjust.containsKey(cs.getDDMMYYYY())) {
		    			MyHashMap hmAdj = (MyHashMap) this.hmOTAdjust.get(cs.getDDMMYYYY());
		    			this.set("ac_ot", hmAdj.getDouble("ot_total"));
		    			this.set("ap_ot", hmAdj.getDouble("ot_total"));
		    			this.set("ot1", hmAdj.getDouble("ot1_total"));
		    			this.set("ot5", hmAdj.getDouble("ot5_total"));
		    			this.set("ot2", hmAdj.getDouble("ot2_total"));
		    			this.set("ot3", hmAdj.getDouble("ot3_total"));
		    			this.hm.put("tmp_otwork", new Double (hmAdj.getString("ot_total")));
	    			} else {
	    				if(this.calotflag){
	    					this.processOT();
	    				}else{
	    					MyLog.debug("!! OT will not be process coz input flage is 0 from TAU151 page !!");
	    				}
	    			}
    			} catch (Exception e) {}
    		} else this.processOT(); //�ҡ�����ԴẺ�ͷ�Ẻ��͡�ͧ �������к��ӹdz�ͷյ���ٵ÷����¹���
    		
    		if (this.calCostcenter) { //����ա�������Ǿ�ѡ�ҹ
    			CscCalendar cs = new CscCalendar(this.getString("dateid"));
    			if (this.hmCostcenter==null) this.loadCostcenter();
    			if(this.hmCostcenter != null){
	    			if (this.hmCostcenter.containsKey(cs.getDDMMYYYY())) {
	    				String cosCode = (String) this.hmCostcenter.get(cs.getDDMMYYYY());
	    				this.set("cost_borrow", cosCode);
	    			}
    			}
    		}    	
    		
    		if (!stick_type.equals("N")) {
    			this.setWarningMsg();
    		}*/
    		
			long end = System.currentTimeMillis();

			return true;
		} catch (Exception e) {
			MyLog.error(this, e);				
			return false;
		}
	}
	
	public void PreProcessOT(){
		try {
			String strTime0id = this.getString("time0id");
			HashMap propertyShf = (HashMap) this.hmTime.get(strTime0id); //��������´�ͧ��㹵��ҧ��÷ӧҹ
			String stick_type = (String) propertyShf.get("STICKTM");
			
			if (this.calOTAdjust && !this.getString("eventgrp").equals("J")) { //��˹�����ͷշ�����͡����ͧ �ҡ�˹�������Ѻ field
    			try {
	    			CscCalendar cs = new CscCalendar(this.getString("dateid"));
	    			if (this.hmOTAdjust==null) this.loadOTAdjust();
	    			if (this.hmOTAdjust.containsKey(cs.getDDMMYYYY())) {
		    			MyHashMap hmAdj = (MyHashMap) this.hmOTAdjust.get(cs.getDDMMYYYY());
		    			this.set("ac_ot", hmAdj.getDouble("ot_total"));
		    			this.set("ap_ot", hmAdj.getDouble("ot_total"));
		    			this.set("ot1", hmAdj.getDouble("ot1_total"));
		    			this.set("ot5", hmAdj.getDouble("ot5_total"));
		    			this.set("ot2", hmAdj.getDouble("ot2_total"));
		    			this.set("ot3", hmAdj.getDouble("ot3_total"));
		    			this.hm.put("tmp_otwork", new Double (hmAdj.getString("ot_total")));
	    			} else {
	    				if(this.calotflag){
	    					this.processOT();
	    				}else{
	    					MyLog.debug("!! OT will not be process coz input flage is 0 from TAU151 page !!");
	    				}
	    			}
    			} catch (Exception e) {}
    		} else this.processOT(); //�ҡ�����ԴẺ�ͷ�Ẻ��͡�ͧ �������к��ӹdz�ͷյ���ٵ÷����¹���
    		
    		if (this.calCostcenter) { //����ա�������Ǿ�ѡ�ҹ
    			CscCalendar cs = new CscCalendar(this.getString("dateid"));
    			if (this.hmCostcenter==null) this.loadCostcenter();
    			if(this.hmCostcenter != null){
	    			if (this.hmCostcenter.containsKey(cs.getDDMMYYYY())) {
	    				String cosCode = (String) this.hmCostcenter.get(cs.getDDMMYYYY());
	    				this.set("cost_borrow", cosCode);
	    			}
    			}
    		}    	
    		
    		if (!stick_type.equals("N")) {
    			this.setWarningMsg();
    		}
		}catch(Exception e){
			MyLog.error(this,e);
		}
	}
			
	/*
	 * �����������к��ӹdz�ͷյ���ٵ÷������¹���
	 */
	public void processOT() {
		try {
			String stick_type = (String) hmTime.get("STICKTM");
			
			long start = System.currentTimeMillis();			
			
			if (this.timeRec == null) {
				this.timeRec = new InitialRecord(this.userPro).getDbRecord("Mtime0");
				this.timeRec.set("time0id", this.getString("time0id"));
				this.timeRec.set("companyid", this.getString("companyid"));
				this.timeRec.search();
			}
			
			MyHashMap result = new MyHashMap();		
			MyTreeMap hFormulaOT = this.getOTHashMap(); //��Ŵ�ٵ��ͷշ�����¹���
			Memployee_ta rec = this.getEmpTARecord();
			if (!hFormulaOT.isEmpty()) {
				long startProcess=System.currentTimeMillis();
				
				this.calOT = this.getCalOTProcess();
				this.calOT.setTTimecurent1(this); /* debug */
				
				HashMap hol = null;
				try {
					//For Statndard
					if (this.hmHoliday==null || this.hmHoliday.isEmpty()) {
						this.loadHolidayData();
					}
					hol = (HashMap) this.hmHoliday.get(((MyHashMap) this.hmTime.get(this.getString("time0id"))).getString("HOLIDAYCODE"));
				} catch (Exception e) {
					MyLog.error(this, e);
				}				
				if (hol==null) hol = new HashMap();
				
				HashMap eventgrp = null;
				try {
					//For Statndard				
					eventgrp = (HashMap) this.refreshRecLoadEventData();
				} catch (Exception e) {
					MyLog.error(this, e);
				}
				if (eventgrp==null) eventgrp = new HashMap();						
					
				Ttime_current tRec = (Ttime_current) this.getParent();
				
				if (this.calOT==null) {
					this.calOT = new CalOT(this.userPro);
					DiffTime dt = new DiffTime();
					this.calOT.initValue(rec, this, (Mtime0) timeRec, hol, eventgrp, tRec, dt, StaticProperties.messagePools); //��˹��������������äӹdz�ͷ�
				} else { 
					this.calOT.setRuntimeValue(rec, this, (Mtime0) timeRec, hol, eventgrp, tRec); //��˹��������������äӹdz�ͷ�
				}				
						        
				MyHashMap varResult  = this.calOT.processOT(hFormulaOT, result); //�ӡ�û����ż��ͷ� �����纤�ҷ��ӹdz��ŧ� MyHashMap
				long endProcess=System.currentTimeMillis();
				MessagePools msg = new MessagePools();
				msg.loadMessage();
				String strNoSwipeDataTH = msg.getMessage("MSGTA0001", "THA");
				String strNoSwipeDataEN = msg.getMessage("MSGTA0001", "ENG");
				//===============================================
				//�Ӥ�ҷ����ҡ��äӹdz�ͷա�� set ���Ѻ field ��ҧ�
				long startSetOT = System.currentTimeMillis();
				Iterator it = varResult.keySet().iterator();
				String key, var;
				boolean isNumber = false;
				while (it.hasNext()) {
					key = it.next().toString();
					var = varResult.getString(key);
					isNumber = false;
					
					try {
						if (!var.equals("") && Double.parseDouble(var)<0) { 
							var="0";
							isNumber = true;
						}
					} catch (Exception e) {
						MyLog.warn("VARIABLE IS NOT NUMBER!!! :"+key+"     VALUE:"+var);
					}
					
					if (!key.equals("") && key.substring(0,1).equals("_")) {
						this.set(key.substring(1, key.length()), var);
						if (isNumber) { 
							this.hmOT.put(key.substring(1, key.length()), new Double (String.valueOf(var)));
							if (key.indexOf("AC_OT")>-1) {
								this.hm.put("tmp_otwork",new Double (String.valueOf(var)));
								//this.set("tmp_otwork", var);
							}
						}
					} else if (!key.equals("") && key.substring(0,1).equals("#")) {	
							/**
							 * Author : Nuiss
							 * Date : 10/04/2552
							 * Logic : �ա� �� ����ͧ �� wording "����բ����š�úѹ�֡����" 
							 */
							if(key.toUpperCase().indexOf("TDESC")>=0){
								if(var.indexOf("��")>=0 && var.indexOf("����")>=0){
									if(var.indexOf(strNoSwipeDataTH)>=0){
										var = var.replace(strNoSwipeDataTH, "");
										if(var.trim().equals("")){
											var = strNoSwipeDataTH;
										}//end if 
									}//end if 
								}//end if 
							}//end if 
							
							if(key.toUpperCase().indexOf("EDESC")>=0){
								if(var.toLowerCase().indexOf("leave")>=0){
									if(var.indexOf(strNoSwipeDataEN)>=0){
										var = var.replace(strNoSwipeDataEN, "");
									}//end if 
								}//end if 
							}//end if 
							
							tRec.set(key.substring(1, key.length()), var); //�絤�����Ѻ������
	 				}//end if 
				}//end while 
				
				//�ӡ�ûѴ��ɤ���ͷյ�ҧ� ���ӹdz��
				this.loadTimeData();
				
				String roundCode = ((MyHashMap) this.hmTime.get(this.getString("time0id"))).getString("OTSTANG");
				this.set("ot1", this.getRoudingValue(roundCode, this.getDouble("ot1")));
				this.set("ot5", this.getRoudingValue(roundCode, this.getDouble("ot5")));
				this.set("ot2", this.getRoudingValue(roundCode, this.getDouble("ot2")));
				this.set("ot3", this.getRoudingValue(roundCode, this.getDouble("ot3")));
				this.set("ac_ot", this.getRoudingValue(roundCode, this.getDouble("ac_ot")));
				
				long endSetOT=System.currentTimeMillis();
			}
			long end=System.currentTimeMillis();
		} catch (Exception e) {
			MyLog.error(this, e);	
			ttl.addDateError("ERROR", this.getString("dateid"), e.getMessage());
		}
	}
		
	/*
	 * ���Ǩ�ͺ������ѹ��ش���ླ��������
	 */
	private boolean chkHoliday(String date) {	
		
        /* new version on 18-08-2010 �����ʡлѨ�غѹ�����㹡�û����ż� (���ʢͧ���ҷӧҹ��ԧ��ѹ���) ��������ʢͧ�з�������ʡ�����ͧ���ҧ���)*/
        String strTime0id = this.getString("time0id");
        if (strTime0id.equals("")) {
        	strTime0id = this.empTimeCode;
        }
		
		CscCalendar cs = new CscCalendar(date);		
		HashMap propertyShf = (HashMap) this.hmTime.get(strTime0id); // edit on 18-08-2010
		String hol =  (String) propertyShf.get("HOLIDAYCODE");		
		if (!this.getHolidayHashMap().containsKey(hol)) { //����ѧ��������ѹ��ش ��������Ŵ�ѹ��ش�����
			this.loadHolidayData();
		}
		MyHashMap hm = (MyHashMap) this.hmHoliday.get(hol);
		if (hm.containsKey(cs.getYYYYMMDD())) {
			return true;
		}
		return false;
	}
	
	/*
	 * ��Ǩ�ͺ�������ش�������
	 */
	private void chkStopInShift() {
		try {
			CscCalendar cs = new CscCalendar(this.getString("date_actual"));
			CscCalendar cs1 = new CscCalendar(this.getString("m_dt_en"));

			MyHashMap hmProp = (MyHashMap) this.hmTime.get(this.getString("time0id"));
			if (hmProp.getString("STATUS").equalsIgnoreCase("1")) { //��㹡óշ���繵��ҧ���	
				String filter = "time0id='"+this.empTimeCode+"' and monthid="+(cs.getMonth()+1)+" and yearid="+cs.getYear();
				if (this.inqTime2 == null) {
					this.inqTime2 = new InitialInquiry(this.userPro).getDbInquiry();
					this.inqTime2.setParam(this.param);
					this.inqTime2.setSchemaName(this.userPro.getSchemaName());
					this.inqTime2.initMyTable("Mtime2","", "");
					this.inqTime2.setColumn("*");
				}
				this.inqTime2.setFilter(filter);
				this.inqTime2.refresh();
				if  (this.inqTime2.next()) {
					String shiftID = this.inqTime2.getString("TIME"+cs.getDD()+"1");
					String shiftOutID = this.inqTime2.getString("TIME"+cs1.getDD()+"1");
					
					if (!this.getTimeHashMap().containsKey(shiftID)||!this.getTimeHashMap().containsKey(shiftOutID)) {
						this.loadDayTimeData(shiftID);
						this.loadDayTimeData(shiftOutID);
					}
					
					MyHashMap hm = (MyHashMap) this.hmDayTime.get(shiftID);
					MyHashMap propertiesDayTime = (MyHashMap) hm.get(String.valueOf(cs.getCSCDOW()));
					if (propertiesDayTime.getString("stopday").equals("1")) {
						this.set("eventgrp","H");
					}
					
					if (!shiftOutID.equals("")) {
						hm = (MyHashMap) this.hmDayTime.get(shiftOutID);
						propertiesDayTime = (MyHashMap) hm.get(String.valueOf(cs1.getCSCDOW()));
						if (propertiesDayTime.getString("stopday").equals("1")) {
							this.set("lv_ty","H");
						}
					}
				} else {
					if (this.chkStopDay(this.getString("m_dt_en"))) {
						this.set("lv_ty","H");
					}
				}
				inqTime2.closeConnection();
			} else {	//// ��㹡óշ���繵��ҧ��÷ӧҹ	
				/**
				 * Author : Nuiss
				 * Date : 01/06/2553
				 * Logic : �����ѹ������� �ત �ͧ�������ѹ �͡ m_dt_en
				 */
				if (this.chkStopDay(this.getString("m_dt_bg"))) {
					this.set("lv_ty","H");
				}
			}
			
			//����� �Ҩҡ�����¹�������š�� �������ѹ��ش ����� EVENTGRP=H
			if ((this.getString("doctype").equals("C") || this.getString("doctype").equals("CH")) && this.getString("eventgrp").equals("H")) {
				this.set("lv_ty", "H");
			}
		} catch (RemoteException e) {
			MyLog.error(this, e);			
		}
	}	
	
	/*
	 * ��Ǩ�ͺ����ѹ����ٴ�ѵ��͡����ش�������
	 */
	private boolean chkStopDay(String date) {
		if ((!this.getString("doctype").equals("CH") && !this.getString("olddoctype").equals("CH"))) { //�����������¹���� �������
			CscCalendar cs = new CscCalendar(date);
			String day = String.valueOf(cs.getCSCDOW());
			MyHashMap hm = null;

			/* ��� PG ����ͧʹ㨤�ҡз���Ҩҡ MyNote �͹���ͷ� �����ʡТͧ������ѹ���� */
			this.loadDayTimeData(this.getString("time0id"));
			hm = (MyHashMap) this.hmDayTime.get(this.getString("time0id"));
			
			/*
			if (!this.getString("ot_time0").equals("") && !this.getString("ot_time0").equals("NONE")) {
				this.loadDayTimeData(this.getString("time0id"));
				hm = (MyHashMap) this.hmDayTime.get(this.getString("time0id"));
			} else {
				hm = (MyHashMap) this.hmDayTime.get(this.getString("time0id"));
			}
			*/ 
			
			if (hm!=null && !hm.isEmpty()) {
				MyHashMap propertiesDayTime = (MyHashMap) hm.get(day);
				if (propertiesDayTime!=null && !propertiesDayTime.isEmpty()) {
					if (propertiesDayTime.getString("stopday").equals("1")) {
						//MyLog.error("11/12/2008 Nuiss Debug:>>>> �ѹ ["+date+"]  ���ѹ��ش");
						return true;
					}
				}
			}
		}
		return false;
	}
		
	/*
	 * ��Ǩ�ͺ�������ش�������
	 */
	private void chkIsNonWorkDay() {		
		this.chkStopInShift();			
		boolean chkStop = this.chkStopDay(this.getString("date_actual"));
		boolean chkHoliday = this.chkHoliday(this.getString("date_actual"));
		/*if (chkStop && this.getString("eventgrp").equals("O")) {
			this.set("eventgrp","H");
		} elseif (chkStop==false  && this.getString("eventgrp").equals("H") && !this.getString("doctype").equals("CH")) { //������ѹ��ش ��������ѹ�� H
			this.set("eventgrp","T");
		} else*/ 
		
		//���ѹ��ش ����ա�â��ͷ� ���������ѹ�� H
		if (chkStop && this.getString("eventgrp").equals("O")) {			
			this.set("eventgrp", "H");
		}
		
		if (chkHoliday) { //���ѹ��ش���ġ�� �����������չ�� I
			this.set("eventgrp","I");
		} else if (chkHoliday==false && this.getString("eventgrp").equals("I")) { //������ѹ��ش ��������ѹ�� I
			this.set("eventgrp","T");
		}
		
		if (this.chkHoliday(this.getString("m_dt_en"))) {
			this.set("lv_ty","I");
		}	
	}
	
	/*
	 * �ӹdz �� �ӧҹ��ѹ��� [ Hour_d ]
	 */
	private float calulateHourD() {
		float hourD = 0;
		try {					
            /* �����ʡлѨ�غѹ�����㹡�û����ż� (���ʢͧ���ҷӧҹ��ԧ��ѹ���) ��������ʢͧ�з�������ʡ�����ͧ���ҧ���)*/
            String strTime0id = this.getString("time0id");
            if (strTime0id.equals("")) {
            	strTime0id = this.empTimeCode;
            }

			MyHashMap hmTmp = (MyHashMap) this.hmTime.get(strTime0id); /* edit on 18-08-2010 */
			String value = hmTmp.getString("HOUR_COUNT"); 	//�ٻẺ��ùѺ��. ��÷ӧҹ
			String stick_type = hmTmp.getString("STICKTM"); //�ӧҹ������
			
			CscTime c = new CscTime(0f);			
			if (this.getString("DOCTYPE").equals("A")) { 	// ����繡��� ������繡��������ѹ �����ѹ �� ��.	
				if(this.getFloat("m_lv") == this.getFloat("hour_s")){	/* �繡��������ѹ ��Ҫ�. �ӧҹ����ѹ����� */
					c = new CscTime(this.getFloat("hour_s"));
				}else{
					c = new CscTime(this.getHourDAdjust(value));	
				}
			} else {	/* �й����������������� ���ӹdz ��. �ӧҹ�������ٴ�ѵ� */
				if (stick_type.equals("N")) { //���ʹ����ҷӧҹ����������͡
					CscCalendar c1 = new CscCalendar(this.getString("c_dt_bg"));
					c1.setCSCTime(this.getFloat("c_tm_bg"));
					CscCalendar c2 = new CscCalendar(this.getString("c_dt_en"));
					c2.setCSCTime(this.getFloat("c_tm_en"));
					c = new CscTime(c2.subForHour(c1));	
				} else { 
					c = new CscTime(this.getHourDAdjust(value));
				}
			}
			
			if (this.getString("EVENTGRP").equalsIgnoreCase("O")) {
				//㹡ó����繡� OT ���ͷӧҹ��ѹ��ش ����./�ѹ ��ҡѺ�ӹǹ�����ͷ�
				hourD = this.getFloat("ac_ot");
			} else if(this.getString("EVENTGRP").equalsIgnoreCase("H") ||
					this.getString("EVENTGRP").equalsIgnoreCase("I")) { /* �óբͧ MPT �е�ͧ�ӹdz ��. �ӧҹ��ѹ��ش���� ���ִ�ҡ����ٴ�ѵ�  */
				CscCalendar st = new CscCalendar(this.getString("m_dt_bg"));
				CscCalendar en = new CscCalendar(this.getString("m_dt_en"));
				st.setCSCTime(Float.parseFloat(this.getString("m_tm_bg")));
				en.setCSCTime(Float.parseFloat(this.getString("m_tm_en")));
				
				hourD = en.subForHour(st); /* ����ٴ�͡ź�����ٴ��Ҩ��� ��. �ӧҹ������ */
				hourD = calHourPerDay(hourD);
			} else {
				if (value.equalsIgnoreCase("0")) { //������ҧ��÷ӧҹ 				
					//c.sub(this.getFloat("m_lv")); /* ��. �ӧҹ�ӹdz�ҡ �����ٴ�ѵ� ��º�ѺἹ��÷ӧҹ���� �ѧ�������ͧ�ѡ�Ҵ�ҹ�����«�� */
					//c.sub(this.getFloat("lt"));
					
					/* �ӹdz ��. �ӧҹ ੾�з���������� */
					if(!this.getString("doctype").equals("A")){
						/* �ó��ջѴ��ɢҴ�ҹ ��ͧ��ѡ ��. �ӧҹ���� �������ǡź ���ǵ�ͧ��ҡѺ��. �ӧҹ㹡� (���������� ��ТҴ�ҹ����ѹ) */
						if((this.getString("eventgrp").equals("T") || this.getString("eventgrp").equals("J")) 
								&& this.getFloat("m_lv") < this.getFloat("hour_s")
								&& this.getFloat("m_lv") != this.leave_noround){
							CscTime ctemp = new CscTime();
							
							if(this.getFloat("m_lv") > this.leave_noround){ /* �Ѵ��������ҡ���ҢҴ�ҹ��ԧ ����ѡ ��. �ӧҹ�����ա */
								ctemp.add(this.getFloat("m_lv"));
								ctemp.sub(this.leave_noround);
								c.sub(ctemp);
							}else{ /* �Ѵ������� ��. �Ҵ�ҹ���¡��� �Ҵ�ҹ��ԧ ��ͧ�ǡ�����׹ */
								ctemp.add(this.leave_noround);
								ctemp.sub(this.getFloat("m_lv"));
								c.add(ctemp);
							}
						}
						
						/* �óբҴ�ҹ�١�Ѵ���������ҡѺ ��. �ӧҹ����ѹ �ʴ���ҢҴ�ҹ����ѹ  */
						if(this.getFloat("m_lv") == this.getFloat("hour_s")){
							hourD = 0;
						}else{
							hourD = c.getFloat();
						}
					}
				} else if (value.equalsIgnoreCase("1")) { //������ŧ���ҧҹ	
					if(!stick_type.equals("T")){ /* ��������� Flexible ��ͧ�ѡ�����ТҴ�ҹ (�͡��͹) ��ǹẺ flex �ж١�ӹdz� TransferTimeProcess �͹�ش���·���ͧ�����������ѹ��ҨТҴ�ҹ������� */
						c.sub(this.getFloat("m_lv"));
						c.sub(this.getFloat("lt"));
					}
					//c.add(this.getFloat("ac_ot"));
					hourD = c.getFloat();
				}			
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return hourD;
	}	
	
	/* �ѡ�ѡ���§�͡�ҡ ��. �ӧҹ����ѹ ������䢹��ҡ MCONFIG ��ҵ�ͧ�ѡ������� (TA1030 Y or N) */
	private float calHourPerDay(float hour_d){
		try {
			if(hour_d > 0){	/* ����ѹ��� � �ա�÷ӧҹ��ԧ �֧�Фӹdz ��. ��� */
				//String flag = (String) StaticConfig.getConfigCompany(this.userPro, "TA1030");
				String flag = "Y"; /* ���Ԩд֧��Ҩҡ mconfig ��Ҥ�è��ѡ������� ��㹡óբͧ MPT ��ͧ��äӹdz ��. �ӧҹ�ѹ��ش Ẻ���Ǥ��� �֧��˹��������� Y �������������Ǩ�ź code ��÷Ѵ����͡ ������÷Ѵ�� ������ѧ */
				float breakHour = 0;				/* ��. �ѡ���§ ���е�ͧ�١�ѡ�ҡ ��. �ӧҹ����ѹ */
				CscTime ct = new CscTime(hour_d);	/* ��. �ӧҹ����ѹ���Դ�ҡ����ٴ�ѵ� */
				if(flag.equals("Y")){	/* ���������ѡ�ѡ�͡ */
					CscCalendar swipeIn = new CscCalendar(this.getString("m_dt_bg"));	/* �ѹ����ٴ��� */
					CscCalendar swipeOut = new CscCalendar(this.getString("m_dt_en"));	/* �ѹ����ٴ�͡ */
					
					CscCalendar breakIn = new CscCalendar(this.getString("dt_breakin"));	/* �ѹ�����������Ҿѡ���§*/
					CscCalendar breakOut = new CscCalendar(this.getString("dt_breakout"));	/* �ѹ�������ش���Ҿѡ���§ */
					
					swipeIn.setCSCTime(this.getDouble("m_tm_bg"));	/* �����ٴ��� */
					swipeOut.setCSCTime(this.getDouble("m_tm_en"));	/* �����ٴ�͡ */
					
					breakIn.setCSCTime(this.getDouble("tm_breakin"));	/* ����������ѡ���§ */
					breakOut.setCSCTime(this.getDouble("tm_breakout"));	/* ��������ش�ѡ���§ */
					
					/* �ӹǹ ��. �ѡ���§ */
					if(swipeIn.beforeEqualsDateTime(breakIn) && swipeOut.afterEqualsDateTime(breakOut)){ /* �ӧҹ�������ǧ���Ҿѡ���§ �ѡ ��� ��. �ѡ */
						breakHour = breakOut.subForHour(breakIn);
					} else if(swipeIn.afterEqualsDateTime(breakIn) && swipeIn.beforeEqualsDateTime(breakOut) && swipeOut.afterDateTime(breakOut)) { /* �ٴ�ѵ���Ҫ�ǧ�ѡ ����ٴ�ѵ��͡��ѧ�ѡ ��ͧ�ѡ੾����ǹ����繾ѡ���§ */
						breakHour = breakOut.subForHour(swipeIn);
					} else if(swipeIn.beforeDateTime(breakIn) && swipeOut.afterDateTime(breakIn) && swipeOut.beforeEqualsDateTime(breakOut)){ /* �ٴ��ҡ�͹�ѡ ����ٴ�͡�����ҧ�ѡ���§ */
						breakHour = swipeOut.subForHour(breakIn);
					} else {
						breakHour = 0f;
					}

					ct.sub(breakHour);	/* �ѡ ��. �ѡ���§�͡�ҡ ��. �ӧҹ����ѹ */
					return ct.getFloat();
				}
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return hour_d;
	}
		
	private void setDefaultDate() {		
		if (b==true) {
			this.set("m_dt_bg",this.getField("dateid").getString());
			this.set("m_dt_en",this.getField("dateid").getString());
			this.set("dt_breakin",this.getField("dateid").getString());
			this.set("dt_breakout",this.getField("dateid").getString());
			this.set("dt_in_inzone",this.getField("dateid").getString());
			this.set("dt_out_inzone",this.getField("dateid").getString());
			this.set("dt_in_outzone",this.getField("dateid").getString());
			this.set("dt_out_outzone",this.getField("dateid").getString());
		}
	}
	
	/*
	 * move �����š�÷ӧҹŧ������ѵԡ�÷ӧҹ
	 * TTIME_CURRENT1 ---> TTIME_HISTORY1
	 */
	public void moveTimeHistory() {
		try {
			DbRecord rec = this.cloneRecord(true);
			if (this.recHistory == null) {
				this.recHistory = new InitialRecord(this.userPro).getDbRecord("Ttime_History1");
				this.recHistory.setColumn("*");
			}
			this.recHistory.clearField();
			this.recHistory.setData(this);
			this.recHistory.save();				
			rec.delete();
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
	}
	
	/*
	 * copy �����š�÷ӧҹŧ����к��Թ��͹
	 * TTIME_CURRENT1 ---> TPTIME_CURRENT1
	 */
	public void moveToPayroll() {
		try {				
			if (this.recPayroll == null) {
				this.recPayroll = new InitialRecord(this.userPro).getDbRecord("Tptime_current1");
				this.recPayroll.setColumn("*");
			}
			this.recPayroll.clearField();
			this.recPayroll.setData(this);
			this.recPayroll.save();
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
	}
		
	public void setOTHashMap(MyTreeMap hm) {
		this.hmOT = hm;		
		if (this.hmOT==null) {
			this.hmOT = this.loadOTFormula();
		}
	}
	
	public MyTreeMap getOTHashMap() {
		if (this.hmOT==null) {
			this.hmOT = this.loadOTFormula();
		}
		return this.hmOT;
	}
	
	public void setHolidayHashMap(MyHashMap hm) {
		this.hmHoliday = hm;		
		if (this.hmHoliday==null) this.loadHolidayData();
	}
	
	public MyHashMap getHolidayHashMap() {
		if (this.hmHoliday==null) this.loadHolidayData();
		return this.hmHoliday;
	}
	
	/*
	 * ��Ŵ�ٵõ�ҧ� �����㹡�äӹdz�ͷ�
	 */
	private MyTreeMap loadOTFormula() {
		MyTreeMap hFormula = new MyTreeMap();
		try {
			DbRecord rec = null;
			String key = "", field = "";
			StringTokenizer str= null;
			MyHashMap hProp = null;
			
			if (this.inqFormula == null) {
				this.inqFormula = new InitialInquiry(this.userPro).getDbInquiry();
				this.inqFormula.setParam(this.param);
				this.inqFormula.setSchemaName(this.userPro.getSchemaName());
				this.inqFormula.initMyTable("Otformula", "", "formulaid");
				this.inqFormula.setColumn("*");
				this.inqFormula.setOrderBy("formulaid");
			}
			this.inqFormula.refresh();			
			while (this.inqFormula.next()) {
				rec = this.inqFormula.getCurrentDbRecord();
				key = rec.getString("formulaid");
				hProp = new MyHashMap();
				str = new StringTokenizer(rec.getFieldList(),",");
				while (str.hasMoreTokens()) {
					field = str.nextToken();
					hProp.put(field, rec.getString(field));
				}
				hFormula.put(key, hProp);
			}
			inqFormula.closeConnection();
		} catch (Exception e) {
			MyLog.error(this, e);
		}	
		return hFormula;
	}
	
	public void setTimeHashMap(MyHashMap hm) {
		this.hmTime = hm;		
		if (this.hmTime==null) this.loadTimeData();
	}
	
	public void setDayTimeHashMap(MyHashMap hm) {
		this.hmDayTime = hm;		
		if (this.hmDayTime==null) this.loadDayTimeData();
	}
	
	public MyHashMap getTimeHashMap() {
		if (this.hmTime==null) this.loadTimeData();
		return this.hmTime;
	}
	
	public MyHashMap getDayTimeHashMap() {
		if (this.hmDayTime==null) this.loadDayTimeData();
		return this.hmDayTime;
	}
	
	/*
	 * ��˹����Ѻ record ��ѡ�ҹ
	 */
	public void setEmpRecord(DbRecord rec) {
		this.empRec = rec;
		if (this.empRec==null) {
			try {			
				this.empRec = new InitialRecord(this.userPro).getDbRecord("Memployee");
				this.empRec.set("employeeid", this.getString("employeeid"));
				this.empRec.set("companyid", this.getString("companyid"));
				this.empRec.search();				
			} catch (Exception e) {
				MyLog.error(this, e);
			}
		}
	}
	
	public DbRecord getEmpRecord() {
		if (this.empRec==null) {
			try {			
				this.empRec = new InitialRecord(this.userPro).getDbRecord("Memployee_ta");
				//=====================================================
				/**
				 * Author : Nuiss
				 * Date : 03/04/2552 
				 * Logic : ���� setGroupfield �����ѹ�� Fields salary �����
				 */
				this.empRec.setGroupfield("requisition");
				//=====================================================
				this.empRec.set("employeeid", this.getString("employeeid"));
				this.empRec.set("companyid", this.getString("companyid"));				
				this.empRec.search();			
			} catch (Exception e) {
				MyLog.error(this, e);
			}
		}else{
			try {	
				this.empRec.setGroupfield("requisition");
			}catch(Exception e){
				MyLog.error("ERROR in Ttime_current1.getEmpRecord()");
			}//end try
		}//end if 
		return this.empRec;		
	}
	
	public Memployee_ta getEmpTARecord() {
		Memployee_ta emp = null;
		try {			
			emp = (Memployee_ta) new InitialRecord(this.userPro).getDbRecord("Memployee_ta");
			//emp.setGroupfield("requisition");
			emp.setParam("rsc_skip","true");
			emp.setColumn("*");
			emp.set("employeeid", this.getString("employeeid"));
			emp.set("companyid", this.getString("companyid"));				
			emp.search();			
		} catch (Exception e) {
			MyLog.error(this, e);
		}
		return emp;
	}
	
	
	/*
	 * ��˹����Ѻ record ���ҧ��÷ӧҹ
	 */
	public void setTimeRecord(DbRecord rec) {
		this.timeRec = rec;
		if (this.timeRec==null) {
			try {			
				this.timeRec = new InitialRecord(this.userPro).getDbRecord("Mtime0");
				this.timeRec.set("time0id", this.getString("time0id"));
				this.timeRec.set("companyid", this.getString("companyid"));
				this.timeRec.search();
			} catch (Exception e) {
				MyLog.error(this, e);
			}
		}
	}
	
	public DbRecord getTimeRecord() {
		if (this.timeRec==null) {
			try {			
				this.timeRec = new InitialRecord(this.userPro).getDbRecord("Mtime0");
				this.timeRec.set("time0id", this.getString("time0id"));
				this.timeRec.set("companyid", this.getString("companyid"));
				this.timeRec.search();
			} catch (Exception e) {
				MyLog.error(this, e);
			}
		}
		return this.timeRec;		
	}
	
	public DbRecord getTimeRecord(String timeCode) {
		if (this.timeRec==null) {
			try {			
				this.timeRec = new InitialRecord(this.userPro).getDbRecord("Mtime0");
				this.timeRec.set("time0id", timeCode);
				this.timeRec.set("companyid", this.getString("companyid"));
				this.timeRec.search();
			} catch (Exception e) {
				MyLog.error(this, e);
			}
		}
		return this.timeRec;		
	}
	
	/*
	 * ��Ŵ��ҵ��ҧ��÷ӧҹ� Mtime1
	 */
	private MyHashMap refreshRecLoadDayTimeData(String code) {
		MyHashMap hmTimeTmp = new MyHashMap();	
		try {			
			String filter = "time0id='"+code+"'";
			if (this.inqTime1 == null) {
				this.inqTime1 = new InitialInquiry(this.userPro).getDbInquiry();
				this.inqTime1.setParam(this.param);
				this.inqTime1.setSchemaName(this.userPro.getSchemaName());
				this.inqTime1.initMyTable("Mtime1", "", "");
				this.inqTime1.setColumn("*");
			}
			this.inqTime1.setFilter(filter);
			this.inqTime1.refresh();
			while (this.inqTime1.next()) {
				MyHashMap hmDetail = new MyHashMap();
				DbRecord rec = this.inqTime1.getCurrentDbRecord();
				StringTokenizer str = new StringTokenizer(rec.getFieldList(),",");
				String key = "";
				while (str.hasMoreTokens()) {
					key = str.nextToken();
					hmDetail.put(key.toLowerCase(), rec.getString(key));
				}				
				hmTimeTmp.put(rec.getString("dayweekid"), hmDetail);
			}
		} catch (Exception e) {
			MyLog.error(this, e);			
		} 	
		finally{
			try{
				this.inqTime1.closeConnection();
			}catch(Exception e){
				MyLog.error(this, e);
			}
		}
		return hmTimeTmp;
	}
	
	private void loadDayTimeData() {		
		try {
			if (this.hmDayTime == null) {
				this.hmDayTime = new MyHashMap();
			}			
			if (!this.hmDayTime.containsKey(this.getString("time0id"))) {				
				this.hmDayTime.put(this.getString("time0id"), this.refreshRecLoadDayTimeData(this.getString("time0id")));
			} 
			/* why have to load DayTimeDate twice ?? */
			/* comment the second loading out ,mod on 18-08-2010 */
			if (!this.hmDayTime.containsKey(this.empTimeCode)) {
				this.hmDayTime.put(this.empTimeCode, this.refreshRecLoadDayTimeData(this.empTimeCode));
			} 
		} catch (Exception e) {
			MyLog.error(this, e);			
		}		
	}
		
	private void loadDayTimeData(String shift) {		
		try {
			if (this.hmDayTime == null) {
				this.hmDayTime = new MyHashMap();
			}			
			if (!this.hmDayTime.containsKey(shift)) {
				this.hmDayTime.put(shift, this.refreshRecLoadDayTimeData(shift));
			}			
		} catch (Exception e) {
			MyLog.error(this, e);			
		}		
	}
	
	/*
	 * ��Ŵ��ҵ��ҧ��÷ӧҹ� Mtime0
	 */
	public void loadTimeData() {		
		try {		
			this.setEmpTimeCode();
			
			if (this.hmTime == null) {
				this.hmTime = new MyHashMap();
			}			
			if (!this.hmTime.containsKey(this.getString("time0id"))) {
				this.hmTime.put(this.getString("time0id"), this.refreshRecLoadTimeData(this.getString("time0id")));
			}
			/* why have to load Timedata twice ?? */
			/* get rid the second loading out , modified on 18-08-2010 */
			if (!this.hmTime.containsKey(this.empTimeCode)) {
				this.hmTime.put(this.empTimeCode, this.refreshRecLoadTimeData(this.empTimeCode));
			}
		} catch (Exception e) {
			MyLog.error(this, e);			
		}		
	}
	
	private MyHashMap refreshRecLoadTimeData(String code) {
		MyHashMap hmTimeTmp = new MyHashMap();	
		try {
			String filter = "time0id='"+code+"'";
			if (this.inqTime0 == null) {
				this.inqTime0 = new InitialInquiry(this.userPro).getDbInquiry();
				this.inqTime0.setParam(this.param);
				this.inqTime0.setSchemaName(this.userPro.getSchemaName());
				this.inqTime0.initMyTable("Mtime0", "", "");
				this.inqTime0.setColumn("*");
			}
			this.inqTime0.setFilter(filter);
			this.inqTime0.refresh();
			if (this.inqTime0.next()) {
				DbRecord rec = this.inqTime0 .getCurrentDbRecord();
				StringTokenizer str = new StringTokenizer(rec.getFieldList(),",");
				String key = "";
				while (str.hasMoreTokens()) {
					key = str.nextToken();
					hmTimeTmp.put(key.toUpperCase(), rec.getString(key));
				}
			}
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
		finally{
			try{
				this.inqTime0.closeConnection();
			}catch(Exception e){
				MyLog.error(this, e);
			}
		}
		return hmTimeTmp;
	}
	
	/*
	 * ��Ŵ��ҵ��ҧ�ѹ��ش
	 */
	private void loadHolidayData() {
		try {
			if (this.hmHoliday == null) {
				this.hmHoliday = new MyHashMap();
			}
			HashMap propertyShf = (HashMap) this.hmTime.get(this.getString("time0id"));
			if (propertyShf==null || propertyShf.isEmpty()) { 
				this.loadTimeData();
				propertyShf = (MyHashMap) this.hmTime.get(this.getString("time0id"));
			}
			String hol =  (String) propertyShf.get("HOLIDAYCODE");
			if (!this.hmHoliday.containsKey(hol)) {				
				this.hmHoliday.put(hol, this.refreshRecLoadHolidayData(hol));
			}
			
			HashMap propertyShf2 = (MyHashMap) this.hmTime.get(this.empTimeCode);
			if (propertyShf2==null || propertyShf2.isEmpty()) { 
				this.loadTimeData();
				propertyShf2 = (HashMap) this.hmTime.get(this.empTimeCode);
			}
			String hol2 =  (String) propertyShf2.get("HOLIDAYCODE");
			if (!this.hmHoliday.containsKey(hol2)) {				
				this.hmHoliday.put(hol2, this.refreshRecLoadHolidayData(hol2));
			}
		} catch (Exception e) {
			MyLog.error(this, e);			
		}		
	}
	
	private MyHashMap refreshRecLoadHolidayData(String code) {
		MyHashMap hmDetail = new MyHashMap();
		try {
			String filter = "holidayid='"+code+"'"; 
			if (this.inqHoliday == null) {
				this.inqHoliday = new InitialInquiry(this.userPro).getDbInquiry();
				this.inqHoliday.setParam(this.param);
				this.inqHoliday.setSchemaName(this.userPro.getSchemaName());
				this.inqHoliday.initMyTable("Mholiday1", "", "");
				this.inqHoliday.setColumn("*");
			}
			this.inqHoliday.setFilter(filter);
			this.inqHoliday.refresh();
			while (this.inqHoliday.next()) {					
				CscCalendar cs = new CscCalendar(this.inqHoliday.getString("hdate"));
				hmDetail.put(cs.getYYYYMMDD()+"_tdesc", this.inqHoliday.getString("tdesc"));
				hmDetail.put(cs.getYYYYMMDD()+"_edesc", this.inqHoliday.getString("edesc"));
				if (this.userPro.get("lang").equalsIgnoreCase("THA")) {
					hmDetail.put(cs.getYYYYMMDD()+"_desc", this.inqHoliday.getString("tdesc"));
				} else {
					hmDetail.put(cs.getYYYYMMDD()+"_desc", this.inqHoliday.getString("edesc"));
				}
				hmDetail.put(cs.getYYYYMMDD(), cs.getYYYYMMDD());
			}
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
		finally{
			try{
				this.inqHoliday.closeConnection();
			}catch(Exception e){
				MyLog.error(this, e);
			}
		}
		return hmDetail;
	}
	
	private MyHashMap refreshRecLoadEventData() {
		MyHashMap hmDetail = new MyHashMap();
		try {
			if (this.inqEvent == null) {
				this.inqEvent = new InitialInquiry(this.userPro).getDbInquiry();
				this.inqEvent.setParam(this.param);
				this.inqEvent.setSchemaName(this.userPro.getSchemaName());
				this.inqEvent.initMyTable("Meventgrp", "", "");
				this.inqEvent.setColumn("*");
			}
			this.inqEvent.refresh();
			while (this.inqEvent.next()) {			
				hmDetail.put(this.inqEvent.getString("eventgrpid")+"_tdesc", this.inqEvent.getString("tdesc"));
				hmDetail.put(this.inqEvent.getString("eventgrpid")+"_edesc", this.inqEvent.getString("edesc"));
				if (this.userPro.get("lang").equalsIgnoreCase("THA")) {
					hmDetail.put(this.inqEvent.getString("eventgrpid")+"_desc", this.inqEvent.getString("tdesc"));
				} else {
					hmDetail.put(this.inqEvent.getString("eventgrpid")+"_desc", this.inqEvent.getString("edesc"));
				}
				hmDetail.put(this.inqEvent.getString("eventgrpid"), this.inqEvent.getString("eventgrpid"));
			}
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
		finally{
			try{
				inqEvent.closeConnection();
			}catch(Exception e){
				MyLog.error(this, e);
			}
		}
		return hmDetail;
	}
	
	/** �� ��.�ӧҹ���ѡ���Ҿѡ�͡ */
	private float getHourDAdjust(String caltype) {
		float hour = 0; 
		loadDayTimeData();	//Check For Data in Mtime is not null
		try {
			CscCalendar cs = new CscCalendar(this.getString("dateid"));
			MyHashMap hmDayTime = (MyHashMap) this.hmDayTime.get(this.getString("time0id"));
			HashMap shProp =  (HashMap) this.hmTime.get(this.getString("time0id"));
			String stick_type = (String) shProp.get("STICKTM"); //�ӧҹ������
			
			String day = String.valueOf(cs.getCSCDOW());
			MyHashMap propertiesDayTime = (MyHashMap) hmDayTime.get(day);

			/* break hour */
			CscCalendar break_in = new CscCalendar(this.getString("dt_breakin"));
			break_in.setCSCTime(this.getFloat("tm_breakin"));			
			CscCalendar break_out = new CscCalendar(this.getString("dt_breakout"));
			break_out.setCSCTime(this.getFloat("tm_breakout"));
			
			/* Working Hour by workshift */
			CscCalendar sh_dt_in = new CscCalendar(this.getString("sh_dt_bg"));
			sh_dt_in.setCSCTime(this.getFloat("sh_tm_bg"));
			CscCalendar sh_dt_out = new CscCalendar(this.getString("sh_dt_bg"));
			sh_dt_out.setCSCTime(this.getFloat("sh_tm_en"));
			if(sh_dt_out.beforeDateTime(sh_dt_in)){ sh_dt_out.incDate(); }
			
			/* Working Hour by workshift after adjust */
			CscCalendar cc_dt_in = new CscCalendar(this.getString("c_dt_bg"));
			cc_dt_in.setCSCTime(this.getFloat("c_tm_bg"));
			CscCalendar cc_dt_out = new CscCalendar(this.getString("c_dt_en"));
			cc_dt_out.setCSCTime(this.getFloat("c_tm_en"));
			
			/* Working Hour by swipe in-out */
			CscCalendar m_dt_in = new CscCalendar(this.getString("m_dt_bg"));
			m_dt_in.setCSCTime(this.getFloat("m_tm_bg"));
			CscCalendar m_dt_out = new CscCalendar(this.getString("m_dt_en"));
			m_dt_out.setCSCTime(this.getFloat("m_tm_en"));
			
			CscCalendar c_dt_in = null;
			CscCalendar c_dt_out = null;
			
			
			if(caltype.equals("0")){	/* ������ҧ��÷ӧҹ */
				c_dt_in = new CscCalendar(sh_dt_in.getYYYYMMDDHHMMSS());
				c_dt_out = new CscCalendar(sh_dt_out.getYYYYMMDDHHMMSS());
				
				/* Ἱ����Թ����Ἱ��駵� */
				if(cc_dt_in.afterDateTime(c_dt_in) && cc_dt_in.beforeDateTime(c_dt_out)){
					c_dt_in = new CscCalendar(cc_dt_in.getYYYYMMDDHHMMSS());
				}
				
				/* �ٴ�ѵ���ѧ��������� ��ͧ��Ѻ������������� */
				if(m_dt_in.afterDateTime(c_dt_in) && m_dt_in.beforeDateTime(c_dt_out)){
					//if(!(this.getString("doctype").equals("A"))){	
						c_dt_in = new CscCalendar(m_dt_in.getYYYYMMDDHHMMSS());
					//}
				}
				
				/* Ἱ�͡�Թ����Ἱ�͡��駵� */
				if(cc_dt_out.afterDateTime(c_dt_in) && cc_dt_out.beforeDateTime(c_dt_out)){
					c_dt_out = new CscCalendar(cc_dt_out.getYYYYMMDDHHMMSS());
				}
				
				/* �ٴ�ѵá�͹��������ش ��ͧ��Ѻ��������ش���� ���� ��������͡ �ç�ѹ (����ٴ��㴢�˹��) */
				if(m_dt_out.afterEqualsDateTime(c_dt_in) && m_dt_out.beforeDateTime(c_dt_out) 
						|| m_dt_in.equalsDateTime(m_dt_out)){
					//if(!(this.getString("doctype").equals("A"))){
						c_dt_out = new CscCalendar(m_dt_out.getYYYYMMDDHHMMSS());
					//}
				}
				
				if( this.getString("tr_type").indexOf("A") > -1){
					/* �ó��Ҥ�����ѧ��ͧ��ѺἹ��÷ӧҹ ����� �����ѹ��ѧ */
					/*if(cc_dt_in.afterEqualsDateTime(break_in) && cc_dt_out.afterEqualsDateTime(c_dt_out)){
						c_dt_in = new CscCalendar(break_out.getYYYYMMDDHHMMSS());
						c_dt_out = new CscCalendar(sh_dt_out.getYYYYMMDDHHMMSS());
					}else if(cc_dt_in.equalsDateTime(c_dt_in) &&  cc_dt_out.equalsDateTime(break_in)){//�Ҥ������
						c_dt_in = new CscCalendar(sh_dt_in.getYYYYMMDDHHMMSS());
						c_dt_out = new CscCalendar(break_in.getYYYYMMDDHHMMSS());
					}*/
					c_dt_in = cc_dt_in;
					c_dt_out = cc_dt_out;
				}
				
				
				if(!stick_type.equalsIgnoreCase("N")){	/* ੾�С�ʹ����ҷӧҹ  */
					/* �ç�������ͧ�ѡ��� ��ТҴ�ҹ ������ӴѺ�Ѵ� �й� m_lv ��� lt ���ѡ�ҡ hour_d �͡ (����������͡���ѡ��� ������� hour_d ���¡��Ҥ����繨�ԧ) */
					/*
					if(m_dt_in.afterDateTime(c_dt_in)) {	// ��ҧҹ��� ��ͧ��Ѻ����������� 
						c_dt_in = new CscCalendar(m_dt_in.getYYYYMMDDHHMMSS());
					}
					
					if(m_dt_out.beforeDateTime(c_dt_out)) {	// �͡�ҡ�ҹ��͹���� 
						c_dt_out = new CscCalendar(m_dt_out.getYYYYMMDDHHMMSS());
					}*/
				}
			}else{	/* ����ٴ�ѵ�  */
				c_dt_in = new CscCalendar(m_dt_in.getYYYYMMDDHHMMSS());
				c_dt_out = new CscCalendar(m_dt_out.getYYYYMMDDHHMMSS());
			}
			if(c_dt_out.beforeDateTime(c_dt_in)){ c_dt_out = new CscCalendar(c_dt_in.getYYYYMMDDHHMMSS()); }
			

			CscTime c = new CscTime(c_dt_out.subForHour(c_dt_in));	/* ��. �ӧҹ���Ἱ */
			
			/* cal brak hour */
			float break_hour = 0;
			
			if(c_dt_in.beforeDateTime(break_in) && c_dt_out.afterDateTime(break_out)){	/* �Ф�����ѡ */
				break_hour = break_out.subForHour(break_in);
			}else if(c_dt_in.beforeDateTime(break_in) && c_dt_out.afterDateTime(break_in) && c_dt_out.beforeEqualsDateTime(break_out)){
				break_hour = c_dt_out.subForHour(break_in);
			}else if(c_dt_in.afterEqualsDateTime(break_in) && c_dt_in.beforeDateTime(break_out) && c_dt_out.afterDateTime(break_out)){
				break_hour = break_out.subForHour(c_dt_in);
			}else if(c_dt_in.afterEqualsDateTime(break_in) && c_dt_out.beforeEqualsDateTime(break_out)){
				break_hour = c_dt_out.subForHour(c_dt_in);
			}else{
				break_hour = 0;
			}
			
			if(this.getString("eventgrp").equals("T") || this.getString("doctype").equals("A") || this.getString("eventgrp").equals("J")){
				if(this.getFloat("LT") > 0){	/* �ó���� ��лѴ��������� ��. �ӧҹ����ѹ�Фӹdz��       ��.�ӧҹ��ԧ = ��. �ӧҹ����ѹ - ��.���(�Ѵ�������) */
					float hour_s = Float.parseFloat(propertiesDayTime.getString("hour_d"));
					c = new CscTime(c_dt_out.subForHour(cc_dt_in));
					c.sub(this.getFloat("LT"));
				}else{
					c.add(this.actual_late); /* �ó������ ������Թ͹������µ�ͧ�ǡ �����¡�Ѻ����� ��. �ӧҹ����ѹ */
				}
				c.sub(break_hour);
				hour = c.getFloat();

				/* hour_d never exceed hour_s */
				float hour_s = Float.parseFloat(propertiesDayTime.getString("hour_d"));
				if (hour_s < hour) {
					hour = hour_s;
				}
			}
		}catch (Exception e) {
			MyLog.error(this, e);			
		}
		return hour;
	}
		
	/** �� ��.�ӧҹ���ѡ���Ҿѡ�͡ */
	/* ���������
	private float getHourDAdjust() {
		float hour = 0; 
		loadDayTimeData();	//Check For Data in Mtime is not null
		try {
			CscCalendar cs = new CscCalendar(this.getString("dateid"));
			String day = String.valueOf(cs.getCSCDOW());
			MyHashMap hmDayTime = (MyHashMap) this.hmDayTime.get(this.getString("time0id"));
			MyHashMap propertiesDayTime = (MyHashMap) hmDayTime.get(day);
									
			float break_hour = 0;
			CscCalendar cs1=null, cs2=null;		
			cs1 = new CscCalendar(this.getString("c_dt_bg"));
			cs1.setCSCTime(Float.valueOf(propertiesDayTime.getString("timeout1")).floatValue());
			cs2 = new CscCalendar(this.getString("c_dt_bg"));
			cs2.setCSCTime(Float.valueOf(propertiesDayTime.getString("timein2")).floatValue());
			if (Float.valueOf(propertiesDayTime.getString("timein2")).floatValue() < 
					Float.valueOf(propertiesDayTime.getString("timeout1")).floatValue()) {
				cs2.incDate();
			}
			break_hour = cs2.subForHour(cs1);
			
			//Working Hour
			CscCalendar cs3 = new CscCalendar(this.getString("c_dt_bg"));
			cs3.setCSCTime(Float.valueOf(propertiesDayTime.getString("timein1")).floatValue());
			CscCalendar cs4 = new CscCalendar(this.getString("c_dt_bg"));
			cs4.setCSCTime(Float.valueOf(propertiesDayTime.getString("timeout2")).floatValue());
			if (Float.valueOf(propertiesDayTime.getString("timeout2")).floatValue() < 
					Float.valueOf(propertiesDayTime.getString("timein1")).floatValue()) {
				cs4.incDate();
			}
			CscTime c = new CscTime(cs4.subForHour(cs3));
			c.sub(break_hour);
			hour = c.getFloat();		
			
			CscCalendar c_dt_in = new CscCalendar(this.getString("o_dt_bg"));
			c_dt_in.setCSCTime(this.getFloat("o_tm_bg"));
			CscCalendar c_dt_out = new CscCalendar(this.getString("o_dt_en"));
			c_dt_out.setCSCTime(this.getFloat("o_tm_en"));
			float hourCom = c_dt_out.subForHour(c_dt_in);
			
			CscCalendar m_dt_in = new CscCalendar(this.getString("m_dt_bg"));
			m_dt_in.setCSCTime(this.getFloat("m_tm_bg"));
			CscCalendar m_dt_out = new CscCalendar(this.getString("m_dt_en"));
			m_dt_out.setCSCTime(this.getFloat("m_tm_en"));
			
			CscCalendar break_in = new CscCalendar(this.getString("dt_breakin"));
			break_in.setCSCTime(this.getFloat("tm_breakin"));			
			CscCalendar break_out = new CscCalendar(this.getString("dt_breakout"));
			break_out.setCSCTime(this.getFloat("tm_breakout"));
			
 			if (this.inBreak==true && this.hourBreakEmp>0 && (m_dt_in.beforeEquals(break_in) && m_dt_out.afterEquals(break_out))) {
 				if (c_dt_in.beforeEquals(break_in) && c_dt_out.afterEquals(break_out)) {
					CscTime ct = new CscTime(hourCom);
					ct.sub(hourBreakEmp);
					hourCom = ct.getFloat();
 				}
			}else{
				if(this.inBreak==true && this.hourBreakEmp>0 && this.getString("TR_TYPE").indexOf("A")>-1){
					CscTime ct = new CscTime(hourCom);
					ct.sub(hourBreakEmp);
					hourCom = ct.getFloat();
				}
			}
									
			if (this.getString("TR_TYPE").indexOf("O")>-1) { //���ͷ�
				if (hourCom<hour) {
					hour=hourCom;
				}
			} else { //������ ���ҡ�÷ӧҹ��ͧ����Թ �ӹǹ��.�ӧҹ/�ѹ
				if (hourCom < hour) {
					hour=hourCom;
				}
				
				float hour_s = Float.parseFloat(propertiesDayTime.getString("hour_d"));
				
				if (hour_s<hour) {
					hour = hour_s;
				}
			}
			
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
		return hour;
	}*/
	
	/*
	 * �֧��� ��.�ӧҹ/�ѹ �ҡ���ҧ��÷ӧҹ
	 */
	private float getHourD() {
		float hour = 0;		
		this.loadDayTimeData(); //Check For Data in Mtime is not null
		
		try {
			CscCalendar cs = new CscCalendar(this.getString("dateid"));
			String day = String.valueOf(cs.getCSCDOW());
			MyHashMap hmDayTime = (MyHashMap) this.hmDayTime.get(this.getString("time0id"));
			MyHashMap propertiesDayTime = (MyHashMap) hmDayTime.get(day);		
			hour = Float.valueOf(propertiesDayTime.getString("hour_d")).floatValue();			
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
		return hour;
	}
	
	public void setCalOTProcess(CalOT calOT) {
		this.calOT = calOT;
	}
	
	public CalOT getCalOTProcess() {		
		return this.calOT;
	}
	
	public void setCostcenter(MyHashMap hm) {
		this.hmCostcenter = hm;
	}
	
	public MyHashMap getCostcenter() {		
		if (this.hmCostcenter==null) this.loadCostcenter();
		return this.hmCostcenter;
	}
	
	/*
	 * ��Ŵ��ҵ��ҧ��������Ǿ�ѡ�ҹ
	 */
	private MyHashMap loadCostcenter() {
    	MyHashMap hm = new MyHashMap();    	
    	
    	if (this.calCostcenter) {
	        try {
		        if (this.inqCostcenter == null) {
					this.inqCostcenter = new InitialInquiry(this.userPro).getDbInquiry();
					this.inqCostcenter.setSchemaName(this.userPro.getSchemaName());
					this.inqCostcenter.initMyTable("Tborrow_emp1", "", "");
					this.inqCostcenter.setColumn("*");
				}
		        CscCalendar cs = new CscCalendar(this.getString("dateid"));
		    	this.inqCostcenter.setFilter("employeeid='"+this.getString("employeeid")+"' and " +
		    			"(start_date >='"+cs.getYYYYMMDD()+"' and end_date<='"+cs.getYYYYMMDD()+"')");
				this.inqCostcenter.refresh();			
				while (this.inqCostcenter.next()) {
					DbRecord rec = this.inqCostcenter.getCurrentDbRecord();
					
					String costCode = rec.getString("new_costcenter");
					CscCalendar c1 = new CscCalendar(rec.getString("start_date"));
					CscCalendar c2 = new CscCalendar(rec.getString("end_date"));
					while (c1.beforeEqualsDate(c2)) {					
						hm.put(c1.getDDMMYYYY(), costCode);
						c1.incDate();
					}				
				}
	        } catch (Exception e) {
	        	MyLog.error("Can't Load Costcenter ", e);
	        }
	    	finally{
	    		try{
	    			if(this.inqCostcenter != null) this.inqCostcenter.closeConnection();
	    		}catch(Exception e){
	    			MyLog.error(this, e);
	    		}
	    	}
    	}
    	return hm;
    }
	
	public void setOTAdjust(MyHashMap hm) {
		this.hmOTAdjust = hm;
	}
	
	public MyHashMap getOTAdjust() {		
		if (this.hmOTAdjust==null) this.loadOTAdjust();
		return this.hmOTAdjust;
	}
		
	/*
	 * ��Ŵ��ҵ��ҧ��á�͡�ͷ�
	 */
	private MyHashMap loadOTAdjust() {
    	MyHashMap hm = new MyHashMap();
    	
		if (this.calOTAdjust) {
	        try {        	
	        	CscCalendar csDate = new CscCalendar(this.getString("dateid"));
		        if (this.inqOTAdjust == null) {
					this.inqOTAdjust = new InitialInquiry(this.userPro).getDbInquiry();
					this.inqOTAdjust.setSchemaName(this.userPro.getSchemaName());
					this.inqOTAdjust.initMyTable("Totadjust1", "", "");
					this.inqOTAdjust.setColumn("*");
				}	        
		    	this.inqOTAdjust.setFilter("employeeid='"+this.getString("employeeid")+"' and " +
		    			"ot_date='"+csDate.getYYYYMMDD()+"'");
				this.inqOTAdjust.refresh();			
				while (this.inqOTAdjust.next()) {
					MyHashMap hmSub = new MyHashMap(); 
					DbRecord rec = this.inqOTAdjust.getCurrentDbRecord();
					
					hmSub.put("ot_total", rec.getDouble("ot_total"));
					hmSub.put("ot1_total", rec.getDouble("ot1_total"));
					hmSub.put("ot5_total", rec.getDouble("ot5_total"));
					hmSub.put("ot2_total", rec.getDouble("ot2_total"));
					hmSub.put("ot3_total", rec.getDouble("ot3_total"));
					
					CscCalendar cs = new CscCalendar();
					hm.put(cs.getDDMMYYYY(), hmSub);
				}
	        } catch (Exception e) {
	        	MyLog.error("Can't Load OTAdjust ", e);
	        }
	        finally{
	        	try{
	        		if(this.inqOTAdjust != null) inqOTAdjust.closeConnection();
	        	}catch(Exception e){
	        		MyLog.error(this, e);
	        	}
	        }
		}
    	return hm;
    }
	
	public void setBusLate(MyHashMap hm) {
		this.hmBusLate = hm;
	}
	
	public MyHashMap getBusLate() {		
		if (this.hmBusLate==null) this.loadBusLate();
		return this.hmBusLate;
	}
	
	/*
	 * ��Ŵ��ҵ��ҧ�������¡Ѻö�Ѻ��
	 */
	private MyHashMap loadBusLate() {
    	MyHashMap hm = new MyHashMap();    	
    	
    	if (this.calBusLate) {
	        try {
		        if (this.inqBusLate == null) {
					this.inqBusLate = new InitialInquiry(this.userPro).getDbInquiry();
					this.inqBusLate.setSchemaName(this.userPro.getSchemaName());
					this.inqBusLate.initMyTable("Mbus_late1", "", "");
					this.inqBusLate.setColumn("*");
				}
		        CscCalendar cs = new CscCalendar(this.getString("dateid"));
		    	this.inqBusLate.setFilter("employeeid='"+this.getString("employeeid")+"' and " +
		    			"(datelate >='"+cs.getYYYYMMDD()+"' and datelate<='"+cs.getYYYYMMDD()+"')");
				this.inqBusLate.refresh();			
				while (this.inqBusLate.next()) {
					DbRecord rec = this.inqBusLate.getCurrentDbRecord();
					
					CscCalendar cs1 = new CscCalendar(rec.getString("datelate"));
					hm.put(cs1.getDDMMYYYY(), rec.getString("timelate"));
				}
	        } catch (Exception e) {
	        	MyLog.error("Can't Load BusLate ", e);
	        }
	        finally{
	        	try{
					this.inqBusLate.closeConnection();
	        	}catch(Exception e){
	        		MyLog.error(this, e);
	        	}
	        }
    	}
    	return hm;
    }
	
	public void setUnused(MyHashMap hm) {
		this.hmUnused = hm;
	}
	
	public MyHashMap getUnused() {		
		if (this.hmUnused==null) this.loadBusLate();
		return this.hmUnused;
	}
	
	/*
	 * ��Ŵ��ҵ��ҧ����â��Ǥ���
	 */
	private MyHashMap loadUnused() {
    	MyHashMap hm = new MyHashMap();    	
    	
    	if (this.calUnused) {
	        try {
		        if (this.inqUnused == null) {
					this.inqUnused = new InitialInquiry(this.userPro).getDbInquiry();
					this.inqUnused.setSchemaName(this.userPro.getSchemaName());
					this.inqUnused.initMyTable("Mempl_unused", "", "");
					this.inqUnused.setColumn("*");
				}
		        CscCalendar cs = new CscCalendar(this.getString("dateid"));
		    	this.inqUnused.setFilter("employeeid='"+this.getString("employeeid")+"' and " +
		    			"(dateid >='"+cs.getYYYYMMDD()+"' and dateid<='"+cs.getYYYYMMDD()+"')");
				this.inqUnused.refresh();			
				while (this.inqUnused.next()) {
					DbRecord rec = this.inqUnused.getCurrentDbRecord();
					
					MyHashMap hmTemp = new MyHashMap();
					hmTemp.put("un1_value", rec.getString("un1_value"));
					hmTemp.put("un1_doctype", rec.getString("un1_doctype"));
					hmTemp.put("un1_docno", rec.getString("un1_docno"));
					hmTemp.put("un2_value", rec.getString("un2_value"));
					hmTemp.put("un2_doctype", rec.getString("un2_doctype"));
					hmTemp.put("un2_docno", rec.getString("un2_docno"));
					hmTemp.put("un3_value", rec.getString("un3_value"));
					hmTemp.put("un3_doctype", rec.getString("un3_doctype"));
					hmTemp.put("un3_docno", rec.getString("un3_docno"));
					hmTemp.put("un4_value", rec.getString("un4_value"));
					hmTemp.put("un4_doctype", rec.getString("un4_doctype"));
					hmTemp.put("un4_docno", rec.getString("un4_docno"));
					hmTemp.put("un5_value", rec.getString("un5_value"));
					hmTemp.put("un5_doctype", rec.getString("un5_doctype"));
					hmTemp.put("un5_docno", rec.getString("un5_docno"));
					hm.put(cs.getDDMMYYYY(), hmTemp);
				}
	        } catch (Exception e) {
	        	MyLog.error("Can't Load BusLate ", e);
	        }
    	}
    	return hm;
    }
	
	public boolean deleteOldLeave(String type) {
		boolean result = false;
		Statement stmt = null;
		CscConnection conn = null;
		try {
			StringBuffer sql = new StringBuffer();
			sql.append("delete tleave_summary where ");
			/* �ѧ �� � ������ҷ�����ͧ�觤������ T , P �ѹ��ҧ�ѹ�ѧ� (�ʹٵ���)*/
			if (type.equals("T")) {
				sql.append("employeeid='").append(this.getString("employeeid")).append("' and docid='").append(this.getString("docid")).append("' ");
				sql.append(" and ( doctype='").append(this.getString("doctype")).append("' or doctype='ABSENT')") ;				
			} else if (type.equals("P")) { 
				sql.append("employeeid='").append(this.pRemote.getString("employeeid")).append("' and docid='").append(this.pRemote.getString("docid")).append("' ");
				sql.append(" and (doctype='").append(this.pRemote.getString("doctype")).append("' or doctype='ABSENT') ");				
			}
			
			conn = (CscConnection) StaticProperties.myConnection.getConnection(this.userPro.get("dbname"));
			stmt = conn.createStatement();
			stmt.executeUpdate(sql.toString());
			
			result = true; /* ����öź������� Error �竵���ʶҹ������ True */
		} catch (Exception e){
			MyLog.error("!! Error : Can't delete tleave_summary : ", e);
		}
		finally{
    		try{
    			if(stmt != null) stmt.close();
    			if(conn != null) conn.close();
    		}catch(Exception e){
    			MyLog.error("!! Error : can't close statement or connection in TransferTimeProcess.deleteDate!!",e);
    		}
			return result; 
		}
	}
	
	/** �ѹ�֡������š���� ���͹����㹡�����ʶԵԡ���� �����㹡�õ�Ǩ�ͺ�����š���� ��С�÷��ͷ� */
	private void saveLeave() {
		try {
			if (this.recTLeave_summary == null) {
				this.recTLeave_summary = new InitialRecord(this.userPro).getDbRecord("Tleave_summary");
				this.recTLeave_summary.setColumn("*");
			}
			this.recTLeave_summary.clearField();
			
			if (!this.getString("docno").equals("")) {
				this.recTLeave_summary.set("DOCID", this.getString("docno"));	
			} else this.recTLeave_summary.set("DOCID", "A");
			
			if (!this.getString("doctype").equals("")) {
				this.recTLeave_summary.set("DOCTYPE", this.getString("doctype"));
			} else this.recTLeave_summary.set("DOCTYPE", "A"); 
			
			this.recTLeave_summary.set("DATEID", this.getString("dateid"));
			this.recTLeave_summary.set("EMPLOYEEID", this.getString("employeeid"));
			this.recTLeave_summary.set("TABLE_NAME","TTIME_CURRENT1");

			this.recTLeave_summary.set("LV_BG_DATE", this.getString("c_dt_bg"));
			this.recTLeave_summary.set("LV_EN_DATE", this.getString("c_dt_en"));
			this.recTLeave_summary.set("HOUR_S", this.getDouble("hour_s"));
			this.recTLeave_summary.set("BU1", this.getString("bu1"));
			this.recTLeave_summary.set("BU2", this.getString("bu2"));
			this.recTLeave_summary.set("BU3", this.getString("bu3"));
			this.recTLeave_summary.set("BU4", this.getString("bu4"));
			this.recTLeave_summary.set("BU5", this.getString("bu5"));
			this.recTLeave_summary.set("BRANCH", this.getString("branch"));
			this.recTLeave_summary.set("EMP_POSITION", this.getString("emp_position"));
			this.recTLeave_summary.set("EMP_GROUP", this.getString("emp_group"));
			this.recTLeave_summary.set("JOBCODE", this.getString("jobcode"));
			this.recTLeave_summary.set("COSTCENTER", this.getString("costcenter"));
			this.recTLeave_summary.set("SALATYPE", this.getString("salatype"));
			this.recTLeave_summary.set("APPROVE", "P");	/* ��ҹ������� */
			
			if (this.getString("EVENTGRP").equals("T") && this.getFloat("LT")>0) { /* for status Late */
				this.recTLeave_summary.set("M_LV", this.getFloat("LT"));			
				this.recTLeave_summary.set("LV_TYPE", "LT"); /* if lt > 0 set "LT" (LATE) for LV_TYPE */
				this.recTLeave_summary.set("DOCTYPE", "LT"); 
				this.recTLeave_summary.set("DOCID", "LT"); 
				
				/** case Late : LV_BG_TIME will be C_TM_BG (working start time) **/
				this.recTLeave_summary.set("LV_BG_TIME", this.getDouble("c_tm_bg"));
				/** case Late : LV_EN_TIME will be M_TM_BG (swipe in) **/
				this.recTLeave_summary.set("LV_EN_TIME", this.getDouble("m_tm_en"));
			} else { /* for another absent type except late */
				/* 㹡óշ���շ������� ����͡�ҡ�ҹ��͹ (�Ҵ�ҹ ) �е�ͧ૿��� 2 ������ŧ Tleave_summary ��ͷ�������ТҴ�ҹ ��������Ūش��� ��ҧ�ѹ�� ������ ('J','LT') */
				if(this.getDouble("lt") > 0) {
					this.recTLeave_summary.set("M_LV", this.getFloat("LT"));			
					this.recTLeave_summary.set("LV_TYPE", "LT"); /* if lt > 0 set "LT" (LATE) for LV_TYPE */
					this.recTLeave_summary.set("DOCTYPE", "LT"); 
					this.recTLeave_summary.set("DOCID", "LT"); 
					
					/** case Late : LV_BG_TIME will be M_TM_BG (working start time) **/
					this.recTLeave_summary.set("LV_BG_TIME", this.getDouble("m_tm_bg"));
					/** case Late : LV_EN_TIME will be M_TM_EN (swipe in) **/
					this.recTLeave_summary.set("LV_EN_TIME", this.getDouble("m_tm_en"));
					
					this.recTLeave_summary.save();
				}
				/* 㹡óշ���繢Ҵ�ҹ ��૵��� doctype,docid ����� J */
				if(this.getString("eventgrp").equals("J")){
					this.recTLeave_summary.set("DOCTYPE", "J"); 
					this.recTLeave_summary.set("DOCID", "J"); 
					this.recTLeave_summary.set("LV_TYPE", "J");
					this.recTLeave_summary.set("M_LV", this.getDouble("m_lv"));

					/** case Late : LV_BG_TIME will be M_TM_BG (working start time) **/
					this.recTLeave_summary.set("LV_BG_TIME", this.getDouble("m_tm_bg"));
					/** case Late : LV_EN_TIME will be M_TM_EN (swipe in) **/
					this.recTLeave_summary.set("LV_EN_TIME", this.getDouble("m_tm_en"));
				} else { /* �óջ��� �����૵������ ��� TTimeCurrent1 */
					this.recTLeave_summary.set("M_LV", this.getDouble("m_lv"));			
					this.recTLeave_summary.set("LV_TYPE", this.getString("lv_ty"));
					this.recTLeave_summary.set("DOCTYPE", this.getString("DOCTYPE")); 
					this.recTLeave_summary.set("DOCID", this.getString("DOCNO")); 
					this.recTLeave_summary.set("LV_BG_TIME", this.getDouble("c_tm_bg"));
					this.recTLeave_summary.set("LV_EN_TIME", this.getDouble("c_tm_en"));
				}
			}
			
			this.recTLeave_summary.save();
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
	}	
	
	protected void postDeleteTrigger() throws Exception {
		super.postDeleteTrigger();
		if ((!this.getString("TR_TYPE").equals("") && this.getString("TR_TYPE").indexOf("A")>-1) || this.getString("eventgrp").equals("J")
				|| (this.getString("EVENTGRP").equals("T") && this.getFloat("LT") > 0) ) {
			try {
				//ź������㹡���� Transaction
				this.deleteOldLeave("T");
			} catch (Exception e) {
				MyLog.error(this, e);
			}
		}
	}
	
	protected boolean preUpdateTrigger() throws Exception {
		boolean result = super.preUpdateTrigger();		
		if ((!pRemote.getString("TR_TYPE").equals("") && pRemote.getString("TR_TYPE").indexOf("A")>-1) || pRemote.getString("eventgrp").equals("J")
				|| (this.getString("EVENTGRP").equals("T") && this.getFloat("LT") > 0) ) {
			try {
				//ź������㹡���� Transaction
				this.flag = this.deleteOldLeave("P");				
			} catch (Exception e) {
				MyLog.error(this, e);
			}
		}		
		return result;
	}
	
	protected void postUpdateTrigger() throws Exception {
		super.postUpdateTrigger();
		if ((!this.getString("TR_TYPE").equals("") && this.getString("TR_TYPE").indexOf("A")>-1) || this.getString("EVENTGRP").equals("J")
				|| (this.getString("EVENTGRP").equals("T") && this.getFloat("LT") > 0) ) {
			try {
				saveLeave();
			} catch (Exception e) {
				MyLog.error(this, e);
			}
		}
	}
	protected boolean preInsertTrigger() throws Exception {
		return super.preInsertTrigger();
	}
	
 	protected void postInsertTrigger() throws Exception {
		super.postInsertTrigger();
		
		/*
		 * �ѹ�֡ŧ�ʹ����������͹� �ѧ���
		 * 1. �������ѹ (TR_TYPE) ����繪�ͧ��� ��� �繡���� 'A' 
		 * 2. �������ѹ (TR_TYPE) ���ѹ�ӧҹ 'T' ����ա������� (LT > 0)
		 * 3. �Ҵ�ҹ (EVENTGRP �� 'J')
		 * 4. �ա�â��ͷ� ���纤���ͷ����ʹ�����ѹ��ش�����᷹ (IS_OTL �� 1)
		 */
		if ((!this.getString("TR_TYPE").equals("") && this.getString("TR_TYPE").indexOf("A")>-1) 
				|| this.getString("EVENTGRP").equals("J")
				|| (this.getString("EVENTGRP").equals("T") && this.getFloat("LT") > 0)) {
			try {
				saveLeave();
			} catch (Exception e) {
				MyLog.error(this, e);
			}//end try
		}//end if 
	}//end method postInsertTrigger
	
	public String getString(String fieldName) {
		if(fieldName.equalsIgnoreCase("late_noround")){
			return Double.toString(this.late_noround);
		}else if(fieldName.equalsIgnoreCase("leave_noround")){
			return Double.toString(this.leave_noround);
		}else if(fieldName.equalsIgnoreCase("ac_ot_noround")){
			return Double.toString(this.ac_ot_noround);
		}else if(fieldName.equalsIgnoreCase("ot_before_noround")){
			return Double.toString(this.ot_before_noround);
		}else if(fieldName.equalsIgnoreCase("ot_after_noround")){
			return Double.toString(this.ot_after_noround);
		}else if (fieldName.equalsIgnoreCase("swremark")) {	// swipe time remark
			return getSwipeRemark();
		}else if (fieldName.equalsIgnoreCase("outbefore")) { //�͡��͹����
			String result = "";
			try {
				CscCalendar m_in = new CscCalendar(this.getString("m_dt_bg"));
				m_in.setCSCTime(this.getFloat("m_tm_bg"));
				CscCalendar m_out = new CscCalendar(this.getString("m_dt_en"));
				m_out.setCSCTime(this.getFloat("m_tm_en"));				
				
				CscCalendar time_in = new CscCalendar(this.getString("m_dt_en"));
				time_in.setCSCTime(this.getFloat("m_tm_en"));
				CscCalendar time_out = new CscCalendar(this.getString("o_dt_en"));
				time_out.setCSCTime(this.getFloat("o_tm_en"));
				CscCalendar break_in = new CscCalendar(this.getString("dt_breakin"));
				break_in.setCSCTime(this.getFloat("tm_breakin"));			
				CscCalendar break_out = new CscCalendar(this.getString("dt_breakout"));
				break_out.setCSCTime(this.getFloat("tm_breakout"));
				
				if (time_in.before(time_out) && !m_in.equals(m_out)) {
					DiffTime dt = new DiffTime();
					float time = dt.TimeOutDiffTimeIn(time_in, time_out, break_in, break_out);
					if (time>0) {
						result = String.valueOf(time);
					} else return "0.0";
				} else return "0.0";
			} catch (Exception e) {
				MyLog.error(this, e);
				return "";
			}
			return result;
		} else if (fieldName.equalsIgnoreCase("timebefore")) { //��ҡ�͹����
			try {
				CscCalendar m_in = new CscCalendar(this.getString("m_dt_bg"));
				m_in.setCSCTime(this.getFloat("m_tm_bg"));
				CscCalendar m_out = new CscCalendar(this.getString("m_dt_en"));
				m_out.setCSCTime(this.getFloat("m_tm_en"));
				
				if (!this.getString("eventgrp").equals("H") && this.getDouble("ac_ot")>=this.getDouble("ap_ot")  && !m_in.equals(m_out)) {
					CscCalendar time_in = new CscCalendar(this.getString("c_dt_bg"));
					time_in.setCSCTime(this.getFloat("c_tm_bg"));
					CscCalendar time_out = new CscCalendar(this.getString("m_dt_bg"));
					time_out.setCSCTime(this.getFloat("m_tm_bg"));
					CscCalendar break_in = new CscCalendar(this.getString("dt_breakin"));
					break_in.setCSCTime(this.getFloat("tm_breakin"));			
					CscCalendar break_out = new CscCalendar(this.getString("dt_breakout"));
					break_out.setCSCTime(this.getFloat("tm_breakout"));
					
					DiffTime dt = new DiffTime();
					float time = dt.TimeOutDiffTimeIn(time_out, time_in, break_in, break_out);
					if (time>1) {
						return String.valueOf(time);
					} else return "0.0";
				} else return "0.0";
			} catch (Exception e) {
				return "0.0";
			}
		} else if (fieldName.equalsIgnoreCase("timeafter")){ //�͡��ѧ����
			try {
				CscCalendar m_in = new CscCalendar(this.getString("m_dt_bg"));
				m_in.setCSCTime(this.getFloat("m_tm_bg"));
				CscCalendar m_out = new CscCalendar(this.getString("m_dt_en"));
				m_out.setCSCTime(this.getFloat("m_tm_en"));
				
				if (!this.getString("eventgrp").equals("H") && this.getDouble("ac_ot")>=this.getDouble("ap_ot") && !m_in.equals(m_out)) {
					CscCalendar time_in = new CscCalendar(this.getString("c_dt_en"));
					time_in.setCSCTime(this.getFloat("c_tm_en"));
					CscCalendar time_out = new CscCalendar(this.getString("m_dt_en"));
					time_out.setCSCTime(this.getFloat("m_tm_en"));
					CscCalendar break_in = new CscCalendar(this.getString("dt_breakin"));
					break_in.setCSCTime(this.getFloat("tm_breakin"));			
					CscCalendar break_out = new CscCalendar(this.getString("dt_breakout"));
					break_out.setCSCTime(this.getFloat("tm_breakout"));
					
					DiffTime dt = new DiffTime();
					float time = dt.TimeOutDiffTimeIn(time_in, time_out, break_in, break_out);
					if (time>1) {
						return String.valueOf(time);
					} else return "0.0";
				} else return "0.0";
			} catch (Exception e) {
				return "0.0";
			}
		} else if (fieldName.equalsIgnoreCase("timeholiday")) { //�ӧҹ��ѹ��ش
			try {
				CscCalendar m_in = new CscCalendar(this.getString("m_dt_bg"));
				m_in.setCSCTime(this.getFloat("m_tm_bg"));
				CscCalendar m_out = new CscCalendar(this.getString("m_dt_en"));
				m_out.setCSCTime(this.getFloat("m_tm_en"));
				
				if ((this.getString("eventgrp").equals("H")||this.getString("eventgrp").equals("I")) && this.getDouble("ac_ot")>=this.getDouble("ap_ot") 
						&& (!this.getString("source_in").equals("")&&!this.getString("source_out").equals(""))  && !m_in.equals(m_out)) {
					CscCalendar time_in = new CscCalendar(this.getString("m_dt_bg"));
					time_in.setCSCTime(this.getFloat("m_tm_bg"));
					CscCalendar time_out = new CscCalendar(this.getString("m_dt_en"));
					time_out.setCSCTime(this.getFloat("m_tm_en"));
					CscCalendar break_in = new CscCalendar(this.getString("dt_breakin"));
					break_in.setCSCTime(this.getFloat("tm_breakin"));			
					CscCalendar break_out = new CscCalendar(this.getString("dt_breakout"));
					break_out.setCSCTime(this.getFloat("tm_breakout"));
					
					DiffTime dt = new DiffTime();
					float time = dt.TimeOutDiffTimeIn(time_in, time_out, break_in, break_out);
					if (time>1) {
						return String.valueOf(time);
					} else return "0.0";
				} else return "0.0";
			} catch (Exception e) {
				return "0.0";
			}
		}
		return super.getString(fieldName);
	}
	
	/*
	 * �������Ѻ�֧�ѹ���� �¨й�������բ�¹�ٵ�
	 */
	public CscCalendar getCscDateTime(String date, float time) {
		try {
			CscCalendar c = new CscCalendar(date);
			c.setCSCTime(time);
			return c;
		} catch (Exception e) {
			return null;
		}
	}
	
	public CscCalendar getCscDateTime(String fieldDate, String fieldTime) {
		try {
			CscCalendar c = new CscCalendar(this.getString(fieldDate));
			c.setCSCTime(this.getFloat(fieldTime));
			return c;
		} catch (Exception e) {
			return null;
		}
	}
	
	/*
	 * �ӡ���絢�ͼԴ��Ҵ����Դ���
	 * Error_Type
	 *		����ٴ��� = FORGOT-IN ---> 0
	 * 		����ٴ�͡ = FORGOT-OUT ---> 1
	 * 		��� = LATE ---> 2		
	 * 		�ͷա�͹���� = OT-BEFORE ---> 3
	 * 		�ͷ���ѧ���� = OT-AFTER ---> 4
	 * 		�͡��͹���� = OUT-ABSENT ---> 5
	 * 		��Ҫ�� = IN-ABSENT ---> 6
	 * 		//�ٴ������¤��� = IN-MORE ---> 7
	 * 		//�ٴ�͡���¤��� = OUT-MORE ---> 8
	 * 		//�ӧҹ��͹���ҧҹ WK-BEFORE ---> 9
	 * 		//�ӧҹ��ѧ���ҧҹ WK-AFTER ---> 10
	 * 		�ٴ�ѵ���ѹ��ش�ҹ WK-HOLIDAY ---> 11
	 * 		�ͷ��Թ��͹���� OT-OVER-BEFORE ---> 12
	 * 		�ͷ��Թ��ѧ���� OT-OVER-AFTER ---> 13
	 *    	�ͷբҴ��͹���� OT-LESS-BEFORE ---> 14
	 * 		�ͷբҴ��ѧ���� OT-LESS-AFTER ---> 15
	 */
	private void setWarningMsg() {
		try {
			//��Ǩ�ͺ��� ���ʵ��ҧ���ҡ�÷ӧҹ�ͧ ��� �դ��������� �����������ӡ����Ŵ
			if (this.empTimeCode==null || this.empTimeCode.equals("")) {
				this.setEmpTimeCode();				
			} 
			DbRecord timeTable = this.getTimeRecord(this.empTimeCode); //�֧������㹵��ҧ��÷ӧҹ�ͧ ��� �͡��
			
			CscCalendar o_dt_bg = new CscCalendar(this.getString("o_dt_bg"));
			o_dt_bg.setCSCTime(this.getFloat("o_tm_bg"));
			CscCalendar o_dt_en = new CscCalendar(this.getString("o_dt_en"));
			o_dt_en.setCSCTime(this.getFloat("o_tm_en"));
			CscCalendar c_dt_bg = new CscCalendar(this.getString("o_dt_bg"));
			c_dt_bg.setCSCTime(this.getFloat("c_tm_bg"));
			CscCalendar c_dt_en = new CscCalendar(this.getString("c_dt_en"));
			c_dt_en.setCSCTime(this.getFloat("c_tm_en"));
			CscCalendar m_dt_bg = new CscCalendar(this.getString("m_dt_bg"));
			m_dt_bg.setCSCTime(this.getFloat("m_tm_bg"));
			CscCalendar m_dt_en = new CscCalendar(this.getString("m_dt_en"));
			m_dt_en.setCSCTime(this.getFloat("m_tm_en"));
				
			if (this.getString("forget_in").equals("1")) { //����ٴ��� = FORGOT-IN ---> 0
				CscCalendar c = new CscCalendar(this.getString("c_dt_bg"));
				this.set("warn00", c.getDDMMYYYY()+" "+this.df2.format(this.getDouble("c_tm_bg")));
			}
			if (this.getString("forget_out").equals("1")) { //����ٴ�͡ = FORGOT-OUT ---> 1
				CscCalendar c = new CscCalendar(this.getString("c_dt_en"));
				this.set("warn01", c.getDDMMYYYY()+" "+this.df2.format(this.getDouble("c_tm_en")));
			}
			
			if (this.getString("eventgrp").equals("O") || this.getString("eventgrp").equals("H")|| this.getString("eventgrp").equals("I ")) {
				if (!m_dt_bg.equals(m_dt_en) && m_dt_bg.getCSCTime()!=0.00 && m_dt_en.getCSCTime()!=0.00) {
					if (m_dt_bg.before(c_dt_bg)) { //�ͷ��Թ��͹���� OT-OVER-BEFORE ---> 12
						this.set("warn12", this.df.format(Double.parseDouble(String.valueOf(c_dt_bg.subForHour(m_dt_bg)))));
					}
					if (c_dt_en.before(m_dt_en)) { //�ͷ��Թ��ѧ���� OT-OVER-AFTER ---> 13
						this.set("warn13", this.df.format(Double.parseDouble(String.valueOf(m_dt_en.subForHour(c_dt_en)))));
					}
					if (c_dt_bg.before(m_dt_bg)) { //�ͷբҴ��͹���� OT-LESS-BEFORE ---> 14
						this.set("warn14", this.df.format(Double.parseDouble(String.valueOf(m_dt_bg.subForHour(c_dt_bg)))));		
					}		
					if (m_dt_en.before(c_dt_en)) { //�ͷբҴ��ѧ���� OT-LESS-AFTER ---> 15
						this.set("warn15", this.df.format(Double.parseDouble(String.valueOf(c_dt_en.subForHour(m_dt_en)))));		
					}		
				}
			} else {
				if (!m_dt_bg.equals(m_dt_en)) {
					if (m_dt_bg.before(c_dt_bg)) { //�ͷա�͹���� = OT-BEFORE ---> 3
						if (timeTable!=null && (timeTable.getFloat("MINOT_B") < c_dt_bg.subForHour(m_dt_bg))) { //��������硡Ѻ �.�.�ͷ� �ӧҹ��͹���ҵ���ش
							this.set("warn03", this.df.format(Double.parseDouble(String.valueOf(c_dt_bg.subForHour(m_dt_bg)))));						
						}
	    			}
					if (c_dt_en.before(m_dt_en)) { //�ͷ���ѧ���� = OT-AFTER ---> 4
						if (timeTable!=null && (timeTable.getFloat("MIN_OT") < m_dt_en.subForHour(c_dt_en))) { //��������硡Ѻ ���ҷ��ͷ����ҧ���
							this.set("warn04", this.df.format(Double.parseDouble(String.valueOf(m_dt_en.subForHour(c_dt_en)))));
						}
	    			}	    			
					if (this.getString("eventgrp").equals("T")) { //�л��Է�����ͷ��ҵ�ͷ��� ���Ѻ�ͷ��ҤԴ
						if (m_dt_en.before(o_dt_en)) { //�͡��͹���� = OUT-ABSENT ---> 5
		    				//this.set("warn05", o_dt_en.subForHour(m_dt_en));
							this.set("warn05", this.df.format(Double.parseDouble(this.getString("outbefore"))));
		    			}
					} else {
		    			if (m_dt_en.before(c_dt_en)) { //�͡��͹���� = OUT-ABSENT ---> 5
		    				//this.set("warn05", c_dt_en.subForHour(m_dt_en));
		    				this.set("warn05", this.df.format(Double.parseDouble(this.getString("outbefore"))));
		    			}
					}
					
	    			if (c_dt_bg.before(m_dt_bg)) { //��Ҫ�� = IN-ABSENT ---> 6
	    				if (timeTable!=null && (timeTable.getFloat("MAXLATE") < m_dt_bg.subForHour(c_dt_bg))) { //��������硡Ѻ ��������٧�ش	    				
	    					this.set("warn06", this.df.format(Double.parseDouble(String.valueOf(m_dt_bg.subForHour(c_dt_bg)))));	  			
	    				}	    				
	    			}
				}
				if (this.getDouble("lt")>0) { //��� = LATE ---> 2
    				this.set("warn02", this.df.format(this.getDouble("lt"))); 		
    			}
			}
		} catch (Exception e) {}
	}
	
	/* ���ҡ�â��ͷ� �����ǧ����ٴ�ѵ� */
    private double findAPOverTime(String empid, CscCalendar st, CscCalendar en){
    	CscConnection conn = null;
   	   	Statement stmt =null;
        ResultSet resultSet = null;
    
    	double ap_ot = 0d;
    	try {
    			conn = (CscConnection) StaticProperties.myConnection.getConnection(this.userPro.get("dbname"));
    			stmt = conn.createStatement();
    			resultSet = stmt.executeQuery(genFindingAPOTQuery(empid, st, en));
    			
    			while(resultSet.next()){
    				/* ���¡��੾���á�����á ���ж���繡�����ҧ�������㺢��ͷ�����ش */
    				ap_ot = Double.parseDouble(resultSet.getString("TOTAL_TIME"));
    				break;
    			}
    		
    	}catch(Exception e){
    		MyLog.error("!! Error while finding ot document for cal ap_ot process !!" + e);
    	}finally{
			try {
				resultSet.close();
				if(stmt!=null){
					stmt.close();
				}
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}//end try
    	return ap_ot;
    }
    
    /* �ӹdz�� AP OT �¡�����º��º�Ѻ�����š�â��ͷ� */
    private void CalAPOvertime(DbRecord rec){
    	CscCalendar csStart = new CscCalendar();
    	CscCalendar csEnd = new CscCalendar();
    	try {
    		/* �����ѹ��� � �ա�÷ӧҹ�Թ ��. �ӧҹ���� (ac_ot > 0) ����� ap_ot */
    		if(rec.getDouble("ac_ot") > 0){
    			/* ��ͧ�繡зӧҹ ����ѹ��ش ��ҹ�������� �ѹ�� */
    			if(rec.getString("eventgrp").equalsIgnoreCase("H")||rec.getString("eventgrp").equalsIgnoreCase("I")||rec.getString("eventgrp").equalsIgnoreCase("T")){
    				/* �Ҫ�ǧ�ѹ���������� 㹡�ä�����¡�â��ͷ� */
    				csStart = rec.getCscCalendar("m_dt_bg");
    				csStart.setCSCTime(rec.getDouble("m_tm_bg"));
    				
    				/* �Ҫ�ǧ�ѹ�������ش 㹡�ä�����¡�â��ͷ� */
    				csEnd = rec.getCscCalendar("m_dt_en");
    				csEnd.setCSCTime(rec.getDouble("m_tm_en"));
    				
    				double ap_ot = findAPOverTime(rec.getString("employeeid"),csStart,csEnd);
    				if(ap_ot > rec.getDouble("ac_ot")){ /* ��� ��. �ͷ��ͷըҡ�͡��� �ҡ���� ��. ���ͷ� ��ԧ����Ѻ ��. AP_OT ��ҡѺ AC_OT */
    					ap_ot = rec.getDouble("ac_ot");
    				}
    				
    				rec.set("ap_ot", ap_ot); /* ૵��� AP_OT */
    			}
    		}
    	}catch(Exception e){
    		MyLog.error(this,e);
    	}
    }
    
    /* ���ҧ query ����㺢��ͷ� ��������§�Ѻ��ǧ�����ٴ�ѵ� */
    private String genFindingAPOTQuery(String empid, CscCalendar st, CscCalendar en){
    	StringBuffer sql = new StringBuffer();
    	try {
    			sql.append("	select  top 1 edit_date,edit_time,otid,employeeid,start_date,end_date,start_time,end_time,TOTAL_TIME ");
    			sql.append("	from tot    ");
    			sql.append("    where ").append(" EMPLOYEEID = '").append(empid).append("' AND (");
    			sql.append("	( ");
    			sql.append("	( ");
    							/* �ٴ�ѵä����㺢��ͷ� */
    			sql.append("	convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) < CONVERT(datetime, START_DATE + ' ' + replace(START_TIME,'.',':')  ,120)");
    			sql.append("	and ");
    			sql.append("	convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, END_DATE + ' ' + replace(END_TIME,'.',':')  ,120)");
    			sql.append("	) ");
    			sql.append("    or ");
    			sql.append("    (  ");
    							/* ���Ң��ͷ� �������ǧ�����ٴ�ѵ� */
    			sql.append("	convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) >= CONVERT(datetime, START_DATE + ' ' + replace(START_TIME,'.',':')  ,120)");
    			sql.append("	and ");
    			sql.append("	convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) <= CONVERT(datetime, END_DATE + ' ' + replace(END_TIME,'.',':')  ,120)");
    			sql.append("			) ");
    			sql.append("    or ");
    			sql.append("    ( ");
    							/* �ٴ��������ǧ���ͷ� �������ٴ�͡ �ҡ������������ش���ͷ� */
    			sql.append("		( ");
    			sql.append("		convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, START_DATE + ' ' + replace(START_TIME,'.',':')  ,120)");
    			sql.append("		and ");
    			sql.append("		convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) <= CONVERT(datetime, END_DATE + ' ' + replace(END_TIME,'.',':')  ,120)");
    			sql.append("	) ");
    			sql.append("	and convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, END_DATE + ' ' + replace(END_TIME,'.',':')  ,120)");
    			sql.append("	) ");
    			sql.append("	or ");
    			sql.append("	( ");
    							/* �ٴ��������͹��ǧ���ͷ� �������ٴ�͡���������ҧ��â��ͷ� */
    			sql.append("		( ");
    			sql.append("		convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) < CONVERT(datetime, START_DATE + ' ' + replace(START_TIME,'.',':')  ,120)");
    			sql.append("		and ");
    			sql.append("		( ");
    			sql.append("		convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, START_DATE + ' ' + replace(START_TIME,'.',':')  ,120)");
    			sql.append("		and ");
    			sql.append("		convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) <= CONVERT(datetime, START_DATE + ' ' + replace(END_TIME,'.',':')  ,120)");
    			sql.append("		) ");
    			sql.append("	) ");
    			sql.append("  ) ) ");
    			sql.append(") ");
    			sql.append("union ");
    			sql.append("(");
    			sql.append("	select  top 1 t0.EDIT_DATE,t0.EDIT_TIME,t0.otid,t0.EMPLOYEEID,t1.START_DATE,t1.END_DATE,t1.START_TIME,t1.END_TIME,t1.TOTAL_TIME ");
    			sql.append("	from TOT_M_DATE0 t0 left join TOT_M_DATE1 t1 on t0.OTID = t1.OTID  ");
    			sql.append("	where ").append(" EMPLOYEEID = '").append(empid).append("' AND ( ");
    			sql.append("	( ");
    			sql.append("	( ");
    							/* �ٴ�ѵä����㺢��ͷ� */
    			sql.append("	convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) < CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.START_TIME,'.',':')  ,120)");
    			sql.append("	and ");
    			sql.append("	convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, t1.END_DATE + ' ' + replace(t1.END_TIME,'.',':')  ,120)");
    			sql.append("	) ");
    			sql.append("    or ");
    			sql.append("    (  ");
    							/* ���Ң��ͷ� �������ǧ�����ٴ�ѵ� */
    			sql.append("	convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) >= CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.START_TIME,'.',':')  ,120)");
    			sql.append("	and ");
    			sql.append("	convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) <= CONVERT(datetime, t1.END_DATE + ' ' + replace(t1.END_TIME,'.',':')  ,120)");
    			sql.append("			) ");
    			sql.append("    or ");
    			sql.append("    ( ");
    							/* �ٴ��������ǧ���ͷ� �������ٴ�͡ �ҡ������������ش���ͷ� */
    			sql.append("		( ");
    			sql.append("		convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.START_TIME,'.',':')  ,120)");
    			sql.append("		and ");
    			sql.append("		convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) <= CONVERT(datetime, t1.END_DATE + ' ' + replace(t1.END_TIME,'.',':')  ,120)");
    			sql.append("	) ");
    			sql.append("	and convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, t1.END_DATE + ' ' + replace(t1.END_TIME,'.',':')  ,120)");
    			sql.append("	) ");
    			sql.append("	or ");
    			sql.append("	( ");
    							/* �ٴ��������͹��ǧ���ͷ� �������ٴ�͡���������ҧ��â��ͷ� */
    			sql.append("		( ");
    			sql.append("		convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) < CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.START_TIME,'.',':')  ,120)");
    			sql.append("		and ");
    			sql.append("		( ");
    			sql.append("		convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.START_TIME,'.',':')  ,120)");
    			sql.append("		and ");
    			sql.append("		convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) <= CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.END_TIME,'.',':')  ,120)");
    			sql.append("		) ");
    			sql.append("	) ");
    			sql.append("  ) ");
    			sql.append(" ) ) )");
    			sql.append(" union ");
    			sql.append(" ( ");
    			sql.append(" 	select  top 1 t1.EDIT_DATE,t1.EDIT_TIME,t1.LISTID,t1.EMPLOYEEID,t1.START_DATE,t1.END_DATE,t1.START_TIME,t1.END_TIME,t1.TOTAL_TIME ");
    			sql.append(" 	from EMP_CREATE_LIST t1 ");
    			sql.append(" 	where ").append(" EMPLOYEEID = '").append(empid).append("' AND ( ");  
    			sql.append("	( ");
    			sql.append("	( ");
    							/* �ٴ�ѵä����㺢��ͷ� */
    			sql.append("	convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) < CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.START_TIME,'.',':')  ,120)");
    			sql.append("	and ");
    			sql.append("	convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, t1.END_DATE + ' ' + replace(t1.END_TIME,'.',':')  ,120)");
    			sql.append("	) ");
    			sql.append("    or ");
    			sql.append("    (  ");
    							/* ���Ң��ͷ� �������ǧ�����ٴ�ѵ� */
    			sql.append("	convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) >= CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.START_TIME,'.',':')  ,120)");
    			sql.append("	and ");
    			sql.append("	convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) <= CONVERT(datetime, t1.END_DATE + ' ' + replace(t1.END_TIME,'.',':')  ,120)");
    			sql.append("			) ");
    			sql.append("    or ");
    			sql.append("    ( ");
    							/* �ٴ��������ǧ���ͷ� �������ٴ�͡ �ҡ������������ش���ͷ� */
    			sql.append("		( ");
    			sql.append("		convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.START_TIME,'.',':')  ,120)");
    			sql.append("		and ");
    			sql.append("		convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) <= CONVERT(datetime, t1.END_DATE + ' ' + replace(t1.END_TIME,'.',':')  ,120)");
    			sql.append("	) ");
    			sql.append("	and convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, t1.END_DATE + ' ' + replace(t1.END_TIME,'.',':')  ,120)");
    			sql.append("	) ");
    			sql.append("	or ");
    			sql.append("	( ");
    							/* �ٴ��������͹��ǧ���ͷ� �������ٴ�͡���������ҧ��â��ͷ� */
    			sql.append("		( ");
    			sql.append("		convert(datetime,'").append(st.getYYYYMMDDHHMMSS()).append("',120) < CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.START_TIME,'.',':')  ,120)");
    			sql.append("		and ");
    			sql.append("		( ");
    			sql.append("		convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) > CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.START_TIME,'.',':')  ,120)");
    			sql.append("		and ");
    			sql.append("		convert(datetime,'").append(en.getYYYYMMDDHHMMSS()).append("',120) <= CONVERT(datetime, t1.START_DATE + ' ' + replace(t1.END_TIME,'.',':')  ,120)");
    			sql.append("		) ");
    			sql.append("	) ");
    			sql.append("  ) ) ");
    			sql.append(") )   order by edit_date desc, edit_time desc ");
    	}catch(Exception e){
    		MyLog.error(e.getMessage());
    	}
    	return sql.toString();
    }
    
    public String getSwipeRemark(){
		String rtn = "";
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			if(this.getString("source_in").equals("5") || this.getString("source_out").equals("5")){
				conn = (CscConnection) StaticProperties.myConnection.getConnection(this.userPro.get("dbname"));
				stmt = conn.createStatement();
				rs = stmt.executeQuery(getSwRemarkQuery());

				while (rs.next()){
					rtn = rs.getString("remark");
				}
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}finally{
			try {
				if(rs != null) rs.close();
				if(stmt!=null) stmt.close();
				if(conn != null) conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return rtn;
	}
	
	private String getSwRemarkQuery(){
		StringBuffer sb = new StringBuffer();
		try {
			String stdate = "";
			String sttime = "";
			if(this.getString("source_in").equals("5")){
				stdate = this.getString("dateid");
				sttime = this.getString("m_tm_bg");
			}else{
				stdate = this.getString("dateid");
				sttime = this.getString("m_tm_en");
			}
			
			sb.append("select t1.remark");
			sb.append(" from tforgetcard0 t0 left join tforgetcard1 t1 on t0.fscardid = t1.fscardid");
			sb.append(" where t0.employeeid = '").append(this.getString("employeeid")).append("' and");
			sb.append(" t1.forget_date = '").append(stdate).append("' and t1.forget_time = '").append(sttime).append("'");
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return sb.toString();
	}
	
	/* ����Ңͤ��ö��������� */
	public boolean isReqExp1(){
		try {
			setExpValueFromWorkflow();
			if(this.hmExpFromWorkFlow != null || this.hmExpFromWorkFlow.containsKey("req_exp2")){
				if(((String) this.hmExpFromWorkFlow.get("req_exp1")).equals("1")) {
					return true;
				}
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return false;
	}
	
	/* ����Ңͤ����������§��������� */
	public boolean isReqExp2(){
		try {
			setExpValueFromWorkflow();
			if(this.hmExpFromWorkFlow != null || this.hmExpFromWorkFlow.containsKey("req_exp2")){
				if(((String) this.hmExpFromWorkFlow.get("req_exp2")).equals("1")) {
					return true;
				}
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return false;
	}
	
	/* ����Ң��ͷվѡ��������� */
	public boolean isIncludeBreak(){
		try {
			setExpValueFromWorkflow();
			if(this.hmExpFromWorkFlow != null && this.hmExpFromWorkFlow.containsKey("includebreak")){
				if(((String) this.hmExpFromWorkFlow.get("includebreak")).equals("1")) {
					return true;
				}
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return false;
	}
	
	/* �礤��ʶҹТͧ ���ö����� ��Ф����������§ ���¡�â��ͷ������˹�� ������ѹ */
	public void setExpValueFromWorkflow(){
		setExpValueFromTotmdate();
		setExpValueFromTot1();
	}
	
	private void setExpValueFromTot1(){
		CscConnection conn = null;
    	Statement stmt = null;
    	ResultSet rs = null;
    	boolean autoCommit = true;
    	
        try {
        	//if(this.hmExpFromWorkFlow == null){
            	conn = (CscConnection) StaticProperties.myConnection.getConnection(this.userPro.get("dbname"));
    			autoCommit = conn.getAutoCommit();
    			conn.setAutoCommit(false);
    			conn.setTransactionIsolation(conn.TRANSACTION_READ_UNCOMMITTED);

    			StringBuffer sb = new StringBuffer();
    			
    			sb.append("select t1.otid,t1.start_date,t1.end_date,t1.start_time,t1.end_time,t1.req_exp1,t1.req_exp2,includebreak ");
    			sb.append("from tot1 t1 ");
    			sb.append("where t1.otid = '").append(this.getString("docno")).append("' and t1.employeeid = '").append(this.getString("employeeid")).append("'");
    			sb.append("	and convert(datetime, t1.start_date + ' ' + replace(t1.start_time,'.',':'), 120) ");
    			sb.append("	>= ");
    			sb.append("	convert(datetime, '").append(this.getString("c_dt_bg")).append(" ").append(df.format(this.getDouble("c_tm_bg")).replace(".",":")).append(":00', 120)");
    			sb.append("	and convert(datetime, t1.end_date + ' ' + replace(t1.end_time,'.',':'), 120) ");
    			sb.append(" <= "); 
    			sb.append(" convert(datetime, '").append(this.getString("c_dt_en")).append(" ").append(df.format(this.getDouble("c_tm_en")).replace(".",":")).append(":00', 120)");
    		
    			stmt = conn.createStatement();
    			rs = stmt.executeQuery(sb.toString());
    			
    			while(rs.next()){
    				if(this.hmExpFromWorkFlow == null){
    					this.hmExpFromWorkFlow = new HashMap();
    				}
    				
    				if(!rs.getString("req_exp1").equals("")){
    					if( rs.getString("req_exp1").equals("1") ){	/* ����� 1 ������������ͧ૵��� */
    						this.hmExpFromWorkFlow.put("req_exp1", rs.getString("req_exp1"));
    					}else{
    						if(this.hmExpFromWorkFlow == null || !this.hmExpFromWorkFlow.containsKey("req_exp1")){
    							this.hmExpFromWorkFlow.put("req_exp1", "");
    						}
    					}
    				}
    				
    				if(!rs.getString("req_exp2").equals("")){
    					if( rs.getString("req_exp2").equals("1") ){	/* ����� 1 ������������ͧ૵��� */
    						this.hmExpFromWorkFlow.put("req_exp2", rs.getString("req_exp2"));
    					}else{
    						if(this.hmExpFromWorkFlow == null || !this.hmExpFromWorkFlow.containsKey("req_exp2")){
    							this.hmExpFromWorkFlow.put("req_exp2", "");
    						}
    					}
    				}
    				
    				if(!rs.getString("includebreak").equals("")){
    					if( rs.getString("includebreak").equals("1") ){	/* ����� 1 ������������ͧ૵��� */
    						this.hmExpFromWorkFlow.put("includebreak", rs.getString("includebreak"));
    					}else{
    						if(this.hmExpFromWorkFlow == null || !this.hmExpFromWorkFlow.containsKey("includebreak")){
    							this.hmExpFromWorkFlow.put("includebreak", "");
    						}
    					}
    				}
    			}
    			conn.commit();
    			/* set default when empty */
    			if(this.hmExpFromWorkFlow == null){
					this.hmExpFromWorkFlow = new HashMap();
					this.hmExpFromWorkFlow.put("req_exp1", "");
					this.hmExpFromWorkFlow.put("req_exp2", "");
					this.hmExpFromWorkFlow.put("includebreak", "");
				}
        	//}
		}catch(Exception e){
    		MyLog.error(this,e);
   		} finally {
       		try{
       			if(rs != null) rs.close();
       			if(stmt != null) stmt.close();
    	    	if(conn!=null){
    	    		conn.setAutoCommit(autoCommit);
    	    		conn.close();
    	    	}
    	    } catch(Exception e){
        			MyLog.error("!! Error : can't close statement or connection in executeQuery!!",e);
        	}
       	}
	}
	
	/* ��㹡�äӹdz�ٵ��ͷբͧ KSG */
	public void setExpValueFromTotmdate(){
		CscConnection conn = null;
    	Statement stmt = null;
    	ResultSet rs = null;
    	boolean autoCommit = true;
    	
        try {
        	if(this.hmExpFromWorkFlow == null){
            	conn = (CscConnection) StaticProperties.myConnection.getConnection(this.userPro.get("dbname"));
    			autoCommit = conn.getAutoCommit();
    			conn.setAutoCommit(false);
    			conn.setTransactionIsolation(conn.TRANSACTION_READ_UNCOMMITTED);

    			StringBuffer sb = new StringBuffer();
    			
    			sb.append("select t1.otid,t1.start_date,t1.end_date,t1.start_time,t1.end_time,t1.req_exp1,t1.req_exp2,includebreak ");
    			sb.append("from tot_m_date0 t0 left join tot_m_date1 t1 on t0.otid = t1.otid ");
    			//sb.append("where t1.otid = '").append(this.getString("docno")).append("' and t0.employeeid = '").append(this.getString("employeeid")).append("'");
    			sb.append("where t0.employeeid = '").append(this.getString("employeeid")).append("'");
    			sb.append("	and convert(datetime, t1.start_date + ' ' + replace(t1.start_time,'.',':'), 120) ");
    			sb.append("	>= ");
    			sb.append("	convert(datetime, '").append(this.getString("c_dt_bg")).append(" ").append(df.format(this.getDouble("c_tm_bg")).replace(".",":")).append(":00', 120)");
    			sb.append("	and convert(datetime, t1.end_date + ' ' + replace(t1.end_time,'.',':'), 120) ");
    			sb.append(" <= "); 
    			sb.append(" convert(datetime, '").append(this.getString("c_dt_en")).append(" ").append(df.format(this.getDouble("c_tm_en")).replace(".",":")).append(":00', 120)");
    		
    			stmt = conn.createStatement();
    			rs = stmt.executeQuery(sb.toString());
    			
    			while(rs.next()){
    				if(this.hmExpFromWorkFlow == null){
    					this.hmExpFromWorkFlow = new HashMap();
    				}
    				
    				if(!rs.getString("req_exp1").equals("")){
    					if( rs.getString("req_exp1").equals("1") ){	/* ����� 1 ������������ͧ૵��� */
    						this.hmExpFromWorkFlow.put("req_exp1", rs.getString("req_exp1"));
    					}else{
    						if(this.hmExpFromWorkFlow == null || !this.hmExpFromWorkFlow.containsKey("req_exp1")){
    							this.hmExpFromWorkFlow.put("req_exp1", "");
    						}
    					}
    				}
    				
    				if(!rs.getString("req_exp2").equals("")){
    					if( rs.getString("req_exp2").equals("1") ){	/* ����� 1 ������������ͧ૵��� */
    						this.hmExpFromWorkFlow.put("req_exp2", rs.getString("req_exp2"));
    					}else{
    						if(this.hmExpFromWorkFlow == null || !this.hmExpFromWorkFlow.containsKey("req_exp2")){
    							this.hmExpFromWorkFlow.put("req_exp2", "");
    						}
    					}
    				}
    				
    				if(!rs.getString("includebreak").equals("")){
    					if( rs.getString("includebreak").equals("1") ){	/* ����� 1 ������������ͧ૵��� */
    						this.hmExpFromWorkFlow.put("includebreak", rs.getString("includebreak"));
    					}else{
    						if(this.hmExpFromWorkFlow == null || !this.hmExpFromWorkFlow.containsKey("includebreak")){
    							this.hmExpFromWorkFlow.put("includebreak", "");
    						}
    					}
    				}
    			}
    			conn.commit();
    			
    			/* set default when empty */
    			if(this.hmExpFromWorkFlow == null){
					this.hmExpFromWorkFlow = new HashMap();
					this.hmExpFromWorkFlow.put("req_exp1", "");
					this.hmExpFromWorkFlow.put("req_exp2", "");
					this.hmExpFromWorkFlow.put("includebreak", "");
				}
        	}
		}catch(Exception e){
    		MyLog.error(this,e);
   		} finally {
       		try{
       			if(rs != null) rs.close();
       			if(stmt != null) stmt.close();
    	    	if(conn!=null){
    	    		conn.setAutoCommit(autoCommit);
    	    		conn.close();
    	    	}
    	    } catch(Exception e){
        			MyLog.error("!! Error : can't close statement or connection in executeQuery!!",e);
        	}
       	}
	}
	
	/* ��㹡�äӹdz�ٵ��ͷբͧ GPF */
	public boolean isDeductBreak(){
		boolean rtn = false;
		CscConnection conn = null;
    	Statement stmt = null;
    	ResultSet rs = null;
    	boolean autoCommit = true;
    	
        try {
        	conn = (CscConnection) StaticProperties.myConnection.getConnection(this.userPro.get("dbname"));
			autoCommit = conn.getAutoCommit();
			conn.setAutoCommit(false);
			conn.setTransactionIsolation(conn.TRANSACTION_READ_UNCOMMITTED);

			StringBuffer sb = new StringBuffer();
			
			sb.append("select t1.otmpaymentid,t1.start_date,t1.end_date,t1.start_time,t1.end_time,t1.is_break ");
			sb.append("from tot_mpayment1 t1 ");
			sb.append("where t1.otmpaymentid = '").append(this.getString("docno")).append("'");
			sb.append("	and start_date between '").append(this.getString("c_dt_bg")).append("' and ");
			sb.append("	'").append(this.getString("c_dt_bg")).append("'");
		
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sb.toString());
			
			/* Ἱ������� */
			CscCalendar cbg = new CscCalendar(this.getString("c_dt_bg"));
			cbg.setCSCTime(this.getFloat("c_tm_bg"));
			
			/* Ἱ����ش */
			CscCalendar cen = new CscCalendar(this.getString("c_dt_en"));
			cen.setCSCTime(this.getFloat("c_tm_en"));
			
			while(rs.next()){
				/* Ἱ�ͷ�������� */
				CscCalendar obg = new CscCalendar(rs.getString("start_date"));
				obg.setCSCTime(Float.parseFloat(rs.getString("start_time")));
				
				/* Ἱ�ͷ�����ش */
				CscCalendar oen = new CscCalendar(rs.getString("end_date"));
				oen.setCSCTime(Float.parseFloat(rs.getString("end_time")));
				
				if(obg.afterEqualsDateTime(cbg) && oen.beforeEqualsDateTime(oen)){
					if(rs.getString("is_break").equals("1")){
						rtn = true;
					}
				}
			}
			conn.commit();
		}catch(Exception e){
    		MyLog.error(this,e);
   		} finally {
       		try{
       			if(rs != null) rs.close();
       			if(stmt != null) stmt.close();
    	    	if(conn!=null){
    	    		conn.setAutoCommit(autoCommit);
    	    		conn.close();
    	    	}
    	    } catch(Exception e){
        			MyLog.error("!! Error : can't close statement or connection in executeQuery!!",e);
        	}
       	}
   		return rtn ;
	}
	
	/* ��˹���ǧ����������� ����ش���ͷ� ������ config � shift */
	private void setO_TM_Datetime(HashMap shp){
		try {
			String otcount = (String) shp.get("OT_COUNT");
			if(otcount.equals("0")){	/* ������͹��ѵ� �������Ἱ��˹���� */
				/*����ͧ���� �١ set �ҵ�����
				 * if( "'OM','O','B'".indexOf("'"+this.getString("DOCTYPE")+"'") > -1 ){
					this.set("o_dt_bg", this.getString("c_dt_bg"));
					this.set("o_dt_en", this.getString("c_dt_en"));
					this.set("o_tm_bg", this.getString("c_tm_bg"));
					this.set("o_tm_en", this.getString("c_tm_en"));
				}else{
					this.set("o_dt_bg", this.getString("c_dt_bg"));
					this.set("o_dt_en", this.getString("c_dt_en"));
					this.set("o_tm_bg", this.getString("c_tm_bg"));
					this.set("o_tm_en", this.getString("c_tm_en"));
				}*/
			}else if(otcount.equals("1")){	/* ����Ө�ԧ ��������ٴ�ѵ�������  */
				this.set("o_dt_bg", this.getString("m_dt_bg"));
				this.set("o_dt_en", this.getString("m_dt_bg"));
				this.set("o_tm_bg", this.getString("m_tm_bg"));
				this.set("o_tm_en", this.getString("m_tm_en"));
			}else if(otcount.equals("2")){	/* �к��Ѻ��� ������ҷ��շ���ش ������ */
				/* ��ҧҹ���Ἱ���ͷ� */
				CscCalendar cbg = this.getCscCalendar("c_dt_bg");
				cbg.setCSCTime(this.getFloat("c_tm_bg"));
				
				CscCalendar cen = this.getCscCalendar("c_dt_en");
				cen.setCSCTime(this.getFloat("c_tm_en"));
				
				CscCalendar mbg = this.getCscCalendar("m_dt_bg");
				mbg.setCSCTime(this.getFloat("m_tm_bg"));
				
				CscCalendar men = this.getCscCalendar("m_dt_en");
				men.setCSCTime(this.getFloat("m_tm_en"));

				if(cbg.beforeDateTime(mbg)){
					this.set("o_dt_bg", mbg.getYYYYMMDD());
					this.set("o_tm_bg", mbg.getCSCTime());
				}else{
					this.set("o_dt_bg", cbg.getYYYYMMDD());
					this.set("o_tm_bg", cbg.getCSCTime());
				}
				
				/* �͡��͹Ἱ�����ͷ� */
				if(cen.beforeDateTime(men)){
					this.set("o_dt_en", cen.getYYYYMMDD());
					this.set("o_tm_en", cen.getCSCTime());
				}else{
					this.set("o_dt_en", men.getYYYYMMDD());
					this.set("o_tm_en", men.getCSCTime());
				}
			}

		}catch(Exception e){
			MyLog.error(this,e);
		}
	}
	
	/* �Ѻ���������ҧ�ѡ���§ */
	public void FindTimeOnBreak(DbRecord tcur, HashMap shprop, Vector vcswp){
		TimeZone tzIn = new TimeZone();
		TimeZone tzOut = new TimeZone();
		CscCalendar swin = new CscCalendar();
		CscCalendar swout = new CscCalendar() ;
		Vector swd = new Vector();	/* ���ٴ�ѵê�ǧ�ѡ���§ */
		try {
			if(isChkSwipeInOutOnBreak(shprop)){	/* ��ͧ�Ѻ���Ҫ�ǧ�ѡ������� */
				if(isOnCondition()){			/* ��੾�� T , H ��� I ���������ͧ�� */
					genTimeZone(shprop, tzIn, tzOut);	/* ���ҧ timezone ����� ��� �͡ */
					getSwipeData(vcswp, swd, tzIn, tzOut);	/* �֧੾�С���ٴ�ѵ�㹪�ǧ�ѡ���§ */
					swin = findTimeInBreak(swd, tzIn);		/* �Ѻ�ٴ��� */
					swout = findTimeOutBreak(swd, tzOut, swin);	/* �Ѻ�ٴ�͡ */
					setWarningLog(shprop, swin, swout);			/* ��˹�ʶҹ���ѧ�Ѻ���� */
				}
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
	}
	
	/* �Ѻ�ٴ��� */
	private CscCalendar findTimeInBreak(Vector swd, TimeZone tzIn){
		Vector vcin = new Vector();	/* ���ٴ�ѵ�੾�Ъ�ǧ����� */
		Vector vcBeforeBreak = new Vector();	/* �������ٴ�ѵ÷�������͹�ѡ���§ */
		
		CscCalendar swin = null;
		
		boolean found = false;
		try {
			CscCalendar brkin = this.getCscCalendar("dt_breakin");	/* ������Ҿѡ���§ */
			brkin.setCSCTime(this.getFloat("tm_breakin"));
			
			getSwipeData(swd, vcin, tzIn, tzIn);
			
			if(vcin.size() == 1){
				DbRecord db = (DbRecord) vcin.get(0);
				swin = new CscCalendar(db.getString("swipedate"));
				swin.setCSCTime(db.getFloat("swipetime"));
			}else if(vcin.size() > 1){
				/* find first round */
				for(int i=0; i < vcin.size(); i++){	/* */
					DbRecord db = (DbRecord) vcin.get(i);
					CscCalendar cs = new CscCalendar(db.getString("swipedate"));
					cs.setCSCTime(db.getFloat("swipetime"));
					
					if(cs.beforeDateTime(brkin)){	/* �������ٴ�ѵá�͹�ѡ���§ */
						vcBeforeBreak.add(cs);	
					}else{
						swin = new CscCalendar(cs.getYYYYMMDDHHMMSS());	/* ���ش�ѵõ���á㹪�ǧ�ѡ ���������ٴ������� */
						found = true;
						break;
					}
				}
				
				if(!found){	/* ������ٴ�ѵ�㹪�ǧ�ѡ����� �������ٴ�ѵá�͹�ѡ�á�������ش�����᷹ */
					DbRecord db = (DbRecord) vcin.get(vcin.size()-1);
					CscCalendar cs = new CscCalendar(db.getString("swipedate"));
					cs.setCSCTime(db.getFloat("swipetime"));
					
					swin = new CscCalendar(cs.getYYYYMMDDHHMMSS());	
				}
			}else{	/* ������ٴ�ѵ� */
				swin = new CscCalendar("1900-01-01");
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
		
		return swin ;
	}
	
	/* �Ѻ�ٴ��� */
	private CscCalendar findTimeOutBreak(Vector swd, TimeZone tzOut, CscCalendar swin){
		Vector vcout = new Vector();		/* ���ٴ�ѵ�੾�Ъ�ǧ���͡ */
		Vector vcAfterBreak = new Vector();	/* �������ٴ�ѵ÷��������ѧ��ԡ�ѡ���§ */
		
		CscCalendar swout = new CscCalendar("1900-01-01"); 
		
		boolean found = false;
		try {
			CscCalendar brkout = this.getCscCalendar("dt_breakout");	/* ������Ҿѡ���§ */
			brkout.setCSCTime(this.getFloat("tm_breakout"));
			
			/* ���ҧ timezone ����Ѻ���ٴ�ѵâ��͡ ����Ң���������� ���������Ѻ�ٴ�ѵ���ѧ�����ٴ������繵�� */
			if(!swin.equalsDateTime(new CscCalendar("1900-01-01"))){
				CscCalendar bgz = new CscCalendar(swin.getYYYYMMDDHHMMSS());
				bgz.incMinute();
				
				tzOut.setBeginZone(bgz) ;
			}
			
			getSwipeData(swd, vcout, tzOut, tzOut);
			
			if(vcout.size() == 1){
				DbRecord db = (DbRecord) vcout.get(0);
				swout = new CscCalendar(db.getString("swipedate"));
				swout.setCSCTime(db.getFloat("swipetime"));
			}else if(vcout.size() > 1){
				/* find first round */
				for(int i=0; i < vcout.size(); i++){	/* */
					DbRecord db = (DbRecord) vcout.get(i);
					CscCalendar cs = new CscCalendar(db.getString("swipedate"));
					cs.setCSCTime(db.getFloat("swipetime"));
					
					if(cs.beforeEqualsDateTime(brkout)){	/* �������ٴ�ѵá�͹����ش�ѡ���§ */
						vcAfterBreak.add(cs);	
					}else{
						if(vcAfterBreak.size() > 0){	/* �������ٴ��ҷ�������͹����ش�ѡ �������ҹ���繢��͡ */
							DbRecord db1 = (DbRecord) vcAfterBreak.get(vcAfterBreak.size() - 1);
							swout = new CscCalendar(db1.getString("swipedate"));
							swout.setCSCTime(db1.getFloat("swipetime"));
						}else{	/* ����������ٴ��ҷ�������͹����ش�ѡ��� �ѧ��鹨��������ٴ�ѵõ���á��ѧ�ѡ�繢��͡ */
							swout = new CscCalendar(cs.getYYYYMMDDHHMMSS());	/* ���ش�ѵõ���á㹪�ǧ�ѡ ���������ٴ������� */
						}
						break;
					}
				}
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
		
		return swout ;
	}
	
	private void setWarningLog(HashMap shprop, CscCalendar swin, CscCalendar swout){
		try {
			setWarn16(swin);	/* ��ҡ�͹�ѡ���§ */
			setWarn17(swout);	/* �͡��ѧ�ѡ���§ */
			setWarn18(shprop, swin, swout);	/* �ѡ�Թ���ҷ���˹� */
			setWarn19(swin);	/* ����ٴ��� */
			setWarn20(swout);	/* ����ٴ�͡ */
			setWarn21(swin);	/* �ٴ��Ҿѡ */
			setWarn22(swout);	/* �ٴ�͡�ѡ */
			setWarn23(swin, swout);	/* �ӹǹ�ѡ��ԧ */
		}catch(Exception e){
			MyLog.error(this,e);
		}
	}
	
	/* ��ҡ�͹�ѡ���§ */
	private void setWarn16(CscCalendar swin){	
		try {
			CscCalendar brkin = new CscCalendar(this.getString("dt_breakin"));
			brkin.setCSCTime(this.getFloat("tm_breakin"));
			
			if(swin.beforeDateTime(brkin)){
				this.set("warn16", brkin.subForHour(swin));
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
	}
	
	/* �͡��ѧ�ѡ���§ */
	private void setWarn17(CscCalendar swout){	
		try {
			CscCalendar brkout = new CscCalendar(this.getString("dt_breakout"));
			brkout.setCSCTime(this.getFloat("tm_breakout"));
			
			if(swout.afterDateTime(brkout)){
				this.set("warn17", swout.subForHour(brkout));
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
	}
	
	/* �ѡ�Թ���ҷ���˹� */
	private void setWarn18(HashMap shprop, CscCalendar swin, CscCalendar swout){	
		try {
			float brkhour = 0f;
			
			if(shprop.containsKey("BREAKHOUR")){
				brkhour = Float.parseFloat((String) shprop.get("BREAKHOUR"));
			}
			
			float brkused = swout.subForHour(swin);
			
			if(brkused > brkhour){	/* �ѡ�Թ���� */
				CscTime cst = new CscTime();
				cst.add(brkused);
				cst.sub(brkhour);
				
				this.set("warn18", cst.getFloat());
			}
		}catch(Exception e){
			MyLog.error(this,e);
			
		}
	}
	
	/* ����ٴ��Ҿѡ */
	private void setWarn19(CscCalendar swin){	
		try {
			CscCalendar defaultdate = new CscCalendar("1900-01-01");
			
			if(swin == null || swin.equalsDate(defaultdate)){
				this.set("warn19", this.getString("dt_breakin") + " " + this.getString("tm_breakin"));
			}
		}catch(Exception e){
			MyLog.error(this,e);
			
		}
	}
	
	/* ����ٴ�͡�ѡ */
	private void setWarn20(CscCalendar swout){	
		try {
			CscCalendar defaultdate = new CscCalendar("1900-01-01");
			
			if(swout == null || swout.equalsDate(defaultdate)){
				this.set("warn20", this.getString("dt_breakout") + " " + this.getString("tm_breakout"));
			}
		}catch(Exception e){
			MyLog.error(this,e);
			
		}
	}
	
	/* �ٴ��Ҿѡ */
	private void setWarn21(CscCalendar swin){	
		try {
			CscCalendar defaultdate = new CscCalendar("1900-01-01");
			
			if(swin != null && !swin.equalsDate(defaultdate)){
				this.set("warn21", swin.getYYYYMMDDHHMMSS());
			}
		}catch(Exception e){
			MyLog.error(this,e);
			
		}
	}
	
	/* �ٴ�͡�ѡ */
	private void setWarn22(CscCalendar swout){	
		try {
			CscCalendar defaultdate = new CscCalendar("1900-01-01");
			
			if(swout != null && !swout.equalsDate(defaultdate)){
				this.set("warn22", swout.getYYYYMMDDHHMMSS());
			}
		}catch(Exception e){
			MyLog.error(this,e);
			
		}
	}
	
	/* �ӹǹ�ѡ��ԧ  */
	private void setWarn23(CscCalendar swin, CscCalendar swout){	
		try {
			CscCalendar defaultdate = new CscCalendar("1900-01-01");
			
			if(swin != null && !swin.equalsDate(defaultdate) && swout != null && !swout.equalsDate(defaultdate)){
				this.set("warn23", swout.subForHour(swin));
			}else{
				this.set("warn23", "0.00");
			}
		}catch(Exception e){
			MyLog.error(this,e);
			
		}
	}
	
	/* ��ʶҹе�ͧ�Ѻ�ٴ�ѵê�ǧ�ѡ�������  */
	private boolean isChkSwipeInOutOnBreak(HashMap shprop){
		try {
			if(shprop.containsKey("SWIPEONBREAK") && shprop.get("SWIPEONBREAK").equals("1")){
				return true;
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return false;
	}
	
	/* ������� T, H ���� I */
	private boolean isOnCondition(){
		try {
			if(this.getString("eventgrp").equals("T") || this.getString("eventgrp").equals("H") || this.getString("eventgrp").equals("I")){
				return true;
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return false ;
	}
	
	/* ���ҧ timezone */
	private void genTimeZone(HashMap shprop, TimeZone tzIn, TimeZone tzOut){
		try {
			genZoneIn(shprop, tzIn);
			genZoneOut(shprop, tzOut);
		}catch(Exception e){
			MyLog.error(this,e);
		}
	}
	
	/* ���ҧ time zone in (����Ҿѡ��§) */
	private void genZoneIn(HashMap shprop, TimeZone tzIn){
		try {
			float in_hr = Float.parseFloat(getShifPropValue(shprop, "BK_IN_ZONEIN", "0"));
			float out_hr = Float.parseFloat(getShifPropValue(shprop, "BK_IN_ZONEOUT", "0"));
			
			CscCalendar st_bk = this.getCscCalendar("dt_breakin");
			st_bk.setCSCTime(this.getFloat("tm_breakin"));
			
			/* start zone */
			CscCalendar st_zone = new CscCalendar(st_bk.getYYYYMMDDHHMMSS());
			st_zone.decTime(in_hr);
			
			/* end zone */
			CscCalendar en_zone = new CscCalendar(st_bk.getYYYYMMDDHHMMSS());
			en_zone.incTime(out_hr);			
			
			tzIn.setBeginZone(st_zone);
			tzIn.setEndZone(en_zone);			
		}catch(Exception e){
			MyLog.error(this,e);
		}
	}
	
	/* ���ҧ time zone out (���͡�ѡ��§) */	
	private void genZoneOut(HashMap shprop, TimeZone tzOut){
		try {
			float in_hr = Float.parseFloat(getShifPropValue(shprop, "BK_OUT_ZONEIN", "0"));
			float out_hr = Float.parseFloat(getShifPropValue(shprop, "BK_OUT_ZONEOUT", "0"));
			
			CscCalendar en_bk = this.getCscCalendar("dt_breakout");
			en_bk.setCSCTime(this.getFloat("tm_breakout"));
			
			/* start zone */
			CscCalendar st_zone = new CscCalendar(en_bk.getYYYYMMDDHHMMSS());
			st_zone.decTime(in_hr);
			
			/* end zone */
			CscCalendar en_zone = new CscCalendar(en_bk.getYYYYMMDDHHMMSS());
			en_zone.incTime(out_hr);			
			
			tzOut.setBeginZone(st_zone);
			tzOut.setEndZone(en_zone);
		}catch(Exception e){
			MyLog.error(this,e);
		}
	}
	
	private String getShifPropValue(HashMap shprop, String key, String defaultvalue){
		try {
			if(shprop.containsKey(key)){
				return (String) shprop.get(key);
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return defaultvalue;
	}
	
	/* �֧�������ٴ�ѵ�੾�з������㹪�ǧ���ҷ���˹� */
	private void getSwipeData(Vector vcswp, Vector vsw, TimeZone tzIn, TimeZone tzOut){
		try {
			CscCalendar cs = null;
			for(int i=0; i < vcswp.size(); i++){
				DbRecord tm = (DbRecord) vcswp.get(i);
				
				cs = new CscCalendar(tm.getString("swipedate"));
				cs.setCSCTime(tm.getFloat("swipetime"));
				if(cs.afterEqualsDateTime(tzIn.getBeginZone()) && cs.beforeEqualsDateTime(tzOut.getEndZone())){
					vsw.add(tm);
				}
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
	}
	
	public double Tm_To_Dec(double st) {
		String timestring = "";
		try {
			DecimalFormat dc = new DecimalFormat("#0.00");
	        double x1, x2;
	        int i;
	        String st1, st2, x;
	        
	        x = dc.format(st);
	        
	        i = x.indexOf(".");
	        st1 = x.substring(x.indexOf(".") + 1);
	        st2 = x.substring(0, i);
	        
	        x1 = Integer.parseInt(st2);
	        x2 = Double.parseDouble(st1);
	        
	        x2 = (x2 * 100)/60;
	        int y = (int)Math.round(x2);
	        //x2 = Math.round(x2*100)/100.0d;
	        
	        String x2str = Double.toString(x2);
	        timestring = st2 + "." + Integer.toString(y); 
        
		}catch(Exception e){
			MyLog.error(this,e);
			return 0 ;
		}
        return Double.parseDouble(timestring);
    }
	
	/* ��˹������������ ����ش�ͷշ�����㹡й�� */
	public void setOTonDate(TimeZone tz){

		CscConnection conn = null;
    	Statement stmt = null;
    	ResultSet rs = null;
    	boolean autoCommit = true;
    	
        try {
            	conn = (CscConnection) StaticProperties.myConnection.getConnection(this.userPro.get("dbname"));
    			autoCommit = conn.getAutoCommit();
    			conn.setAutoCommit(false);
    			conn.setTransactionIsolation(conn.TRANSACTION_READ_UNCOMMITTED);

    			StringBuffer sb = new StringBuffer();
    			
    			sb.append("select t1.otid,t1.start_date,t1.end_date,t1.start_time,t1.end_time");
    			sb.append(" from tot_m_date0 t0 left join tot_m_date1 t1 on t0.otid = t1.otid ");
    			sb.append(" where t0.employeeid = '").append(this.getString("employeeid")).append("'");
    			sb.append("	and convert(datetime, t1.start_date + ' ' + replace(t1.start_time,'.',':'), 120) ");
    			sb.append("	>= ");
    			sb.append("	convert(datetime, '").append(this.getString("c_dt_bg")).append(" ").append(df.format(this.getDouble("c_tm_bg")).replace(".",":")).append(":00', 120)");
    			sb.append("	and convert(datetime, t1.end_date + ' ' + replace(t1.end_time,'.',':'), 120) ");
    			sb.append(" <= "); 
    			sb.append(" convert(datetime, '").append(this.getString("c_dt_en")).append(" ").append(df.format(this.getDouble("c_tm_en")).replace(".",":")).append(":00', 120)");
    			sb.append(" union ");
    			sb.append("select t1.otid,t1.start_date,t1.end_date,t1.start_time,t1.end_time");
    			sb.append(" from tot1 t1 ");
    			sb.append(" where t1.employeeid = '").append(this.getString("employeeid")).append("'");
    			sb.append("	and convert(datetime, t1.start_date + ' ' + replace(t1.start_time,'.',':'), 120) ");
    			sb.append("	>= ");
    			sb.append("	convert(datetime, '").append(this.getString("c_dt_bg")).append(" ").append(df.format(this.getDouble("c_tm_bg")).replace(".",":")).append(":00', 120)");
    			sb.append("	and convert(datetime, t1.end_date + ' ' + replace(t1.end_time,'.',':'), 120) ");
    			sb.append(" <= "); 
    			sb.append(" convert(datetime, '").append(this.getString("c_dt_en")).append(" ").append(df.format(this.getDouble("c_tm_en")).replace(".",":")).append(":00', 120)");
    			
    			stmt = conn.createStatement();
    			rs = stmt.executeQuery(sb.toString());
    			
    			CscCalendar csst = new CscCalendar();
    			CscCalendar csen = new CscCalendar();
    			int count = 0;
    			
    			/* ��˹���ǧ��ŷ��ͷշ�������ͧ�Ѻ�� 
    			 * �ҡ���ҡ���� 1 ��¡�� �� ���ͷա�͹ ����ͷ���ѧ (�ͤ����) 
    			 * ����������������ͧ�ͷա�͹ �������ش�ͧ�ͷ���ѧ�觡�Ѻ� */
    			while(rs.next()){
    				/* ��¡���á */
    				if(count == 0){
    					csst = new CscCalendar(rs.getString("start_date"));
    					csst.setCSCTime(Float.parseFloat(rs.getString("start_time")));
    				}
    				
					csen = new CscCalendar(rs.getString("end_date"));
					csen.setCSCTime(Float.parseFloat(rs.getString("end_time")));
					
					tz.setBeginZone(csst);	/* ����������ͷ� */
					tz.setEndZone(csen);	/* ��������ش�ͷ� */
    			}
    			conn.commit();
		}catch(Exception e){
    		MyLog.error(this,e);
   		} finally {
       		try{
       			if(rs != null) rs.close();
       			if(stmt != null) stmt.close();
    	    	if(conn!=null){
    	    		conn.setAutoCommit(autoCommit);
    	    		conn.close();
    	    	}
    	    } catch(Exception e){
        			MyLog.error("!! Error : can't close statement or connection in executeQuery!!",e);
        	}
       	}
	
	}
	
	public void setProcLog(TransferTimeLog ttl){
		this.ttl = ttl ;
	}
	
	public TransferTimeLog getProcLog(){
		return this.ttl ;
	}
	
	public MyTimeZone getZoneC() throws Exception{
		String key = "standard_zone_c";
		MyTimeZone result = this.createMyTimeZoneByField(key, "c_dt_bg", "c_tm_bg", "c_dt_en", "c_tm_en");
		return result;
	}
	
	public MyTimeZone getZoneM() throws Exception{
		String key = "standard_zone_m";
		MyTimeZone result = this.createMyTimeZoneByField(key, "m_dt_bg", "m_tm_bg", "m_dt_en", "m_tm_en");
		return result;
	}
	
	public MyTimeZone getZoneSH() throws Exception{
		String key = "standard_zone_sh";
		MyTimeZone result = this.createMyTimeZoneByField(key, "sh_dt_bg", "sh_tm_bg", "sh_dt_en", "sh_tm_en");
		return result;
	}
	
	public MyTimeZone getMyTimeZoneByName(String nameRegis){
		return this.hmZone.get(nameRegis);
	}
	
	public MyTimeZone createMyTimeZoneByField(String nameRegis,String fieldBeginDate , String fieldBeginTime, String fieldEndDate,String fieldEndTime) throws Exception{
		String key = nameRegis;
		MyTimeZone result = null;
		try{
			if(this.hmZone.containsKey(key)){
				result = this.hmZone.get(key);
				if(!result.getBeginZone().getYYYYMMDD().equals(this.getString(fieldBeginDate)) || result.getBeginZone().getCSCTime() != this.getFloat(fieldBeginTime)){
					result.getBeginZone().setCscCalendar(this.getString(fieldBeginDate));
					result.getBeginZone().setCSCTime(this.getFloat(fieldBeginTime));
				}
				if(!result.getEndZone().getYYYYMMDD().equals(this.getString(fieldEndDate)) || result.getEndZone().getCSCTime() != this.getFloat(fieldEndTime)){
					result.getBeginZone().setCscCalendar(this.getString(fieldEndDate));
					result.getBeginZone().setCSCTime(this.getFloat(fieldEndTime));
				}
			}else{
				CscCalendar bg = new CscCalendar(this.getString(fieldBeginDate)) , en = new CscCalendar(this.getString(fieldEndDate));
				bg.setCSCTime(this.getFloat(fieldBeginTime));
				en.setCSCTime(this.getFloat(fieldEndTime));
				result = new MyTimeZone(bg , en);
				this.hmZone.put(key, result);
			}
		}catch(Exception e){
			MyLog.error(this ,this.getUProfile() , e);
		}
		return result;
	}
	
	public MyTimeZone createMyTimeZoneByValue(String nameRegis ,String fieldBeginDate , float fieldBeginTime, String fieldEndDate,float fieldEndTime) throws Exception{
		String key = nameRegis;
		MyTimeZone result = null;
		try{
			if(this.hmZone.containsKey(key)){
				result = this.hmZone.get(key);
				if(!result.getBeginZone().getYYYYMMDD().equals(fieldBeginDate) || result.getBeginZone().getCSCTime() != fieldBeginTime){
					result.getBeginZone().setCscCalendar(fieldBeginDate);
					result.getBeginZone().setCSCTime(fieldBeginTime);
				}
				if(!result.getEndZone().getYYYYMMDD().equals(fieldEndDate) || result.getEndZone().getCSCTime() != fieldEndTime){
					result.getBeginZone().setCscCalendar(fieldEndDate);
					result.getBeginZone().setCSCTime(fieldEndTime);
				}
			}else{
				CscCalendar bg = new CscCalendar(fieldBeginDate) , en = new CscCalendar(fieldEndDate);
				bg.setCSCTime(fieldBeginTime);
				en.setCSCTime(fieldEndTime);
				result = new MyTimeZone(bg , en);
				this.hmZone.put(key, result);
			}
		}catch(Exception e){
			MyLog.error(this ,this.getUProfile() , e);
		}
		return result;
	}
}