Simmemployee_statisticleave.java 28.3 KB
Newer Older
TongZuu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
package com.csc.library.databean;

import java.util.HashMap;
import java.util.StringTokenizer;

import std.library.TimeSpan;

import com.csc.library.timeattendance.ManageEmpLeaveStat;
import com.csc.library.utilities.CheckNull;
import com.csc.library.utilities.CscTime;
import com.csc.library.utilities.MyLog;
import com.csc.library.database.DataSet;
import com.csc.library.database.MyHashMap;
import com.csc.library.database.StaticConfig;
import com.csc.library.formula.FormulaString;
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.utilities.CscCalendar;

/*
 * ʴʶԵԡҢͧѡҹ ͡ѧ˹Ҩ
 */
public class Simmemployee_statisticleave extends Memployee_ta {

	private String employeeid="";
	private double hour_d=8;
	private MyHashMap hm_Col = new MyHashMap();
	private String leave_clear = "";
	private String leave_not_clear = "";
	private CscCalendar leaveStart = null;
	private CscCalendar leaveEnd = null;	
	private FormulaString fs = new FormulaString();	
	private CscCalendar c_max = new CscCalendar();
	private String vacationCode = "";
	private ManageEmpLeaveStat mel01 = null;
	private String annType = "";
	
	public int assignField(DataSet rs) {		
		int temp = super.assignField(rs);
		this.hm_Col = new MyHashMap();
		if (this.foundData()) {
			if (this.param!=null && this.param.containsKey("__employeeid")) {
				this.employeeid = (String) this.param.get("__employeeid");
				this.set("employeeid", this.employeeid );
				this.refresh();
			} else this.employeeid = this.getString("employeeid");
				
			this.c_max = new CscCalendar(this.getString("lastleavedate"));
			
			this.hour_d = this.getHour_Day();
			this.selectEvent();		
			
			this.sumTime();
			
			/** current version (27-07-2010) query from tleave_summary only **/
			this.sumLate("tleave_summary");

			this.hm_Col.put("date_begin", this.leaveStart.getYYYYMMDD());
			this.hm_Col.put("date_end", this.leaveEnd.getYYYYMMDD());
		}		
		return temp;
	}
	
	private double getHour_Day() {
		DbInquiry inq1 = null;
		double value = 8;
		try {
			inq1 = new InitialInquiry(this.getUProfile()).getDbInquiry();
			inq1.initMyTable("mtime0", "time0id='"+this.getString("time0")+"'", "");
			inq1.setColumn("time0id,companyid,edesc,tdesc,hour_d");
			
			inq1.refresh();
			while(inq1.next()) {
				value = inq1.getCurrentDbRecord().getDouble("hour_d");  
			}
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
		finally{
			try{
				inq1.closeConnection();
			}catch(Exception e){
				MyLog.error("!! can't close connection in getHour_Day() !!");
			}
		}
		return value;
	}
	
	/* ֧ͿŴ¡ѹ */
	private String getLeaveBranchField(){
		String fld = "";
		try {
			fld = (String) StaticConfig.getConfigCompany(this.userPro, "TALVFD");
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return fld ;
	}
	
	private void selectEvent() {
		DbInquiry inq = null;
		try {
			String limit = "";
			String limit_get = "";
			String vacation0 = "";
			String vacation1 = "";
			FormulaString fs = new FormulaString();
			inq = new InitialInquiry(this.getUProfile()).getDbInquiry();
			inq.setSchemaName(this.getUProfile().getSchemaName());
			
			if(isLeaveLimitByBranch()){
				inq.initMyTable("meventgrp1","daytype!='1' and daytype !='5' and daytype !='6' and daytype !='9' and BRANCHID = (select " + getLeaveBranchField() + " from MEMPLOYEE where EMPLOYEEID = '" +this.getString("employeeid")+ "')","");
			}else{
				inq.initMyTable("meventgrp","daytype!='1' and daytype !='5' and daytype !='6' and daytype !='9'","");
			}
			
			inq.setColumn("*");
			inq.referLangOn();
			inq.refresh();			
			while (inq.next()) {
				 /* Ǩͺ͹䢵ҧ  㹡Ҥ駹 */
	            ManageEmpLeaveStat mels = new ManageEmpLeaveStat(this.userPro, this.getString("employeeid"), inq.getString("eventgrpid"));
				
				if (inq.getString("daytype").equalsIgnoreCase("7")) {
					vacationCode = inq.getString("eventgrpid");
					DbInquiry inqEmp = new InitialInquiry(this.getUProfile()).getDbInquiry();
					inqEmp.initMyTable("memployee_ta", "", "");
					inqEmp.setColumn("employeeid,companyid,vacation0,vacation1,vacation0_get");
					inqEmp.setFilter("employeeid='" + this.employeeid + "'");
					inqEmp.refresh();
					int i=0;
					if (inqEmp.next()) {	
						vacation0 = inqEmp.getString("vacation0");
						vacation1 = inqEmp.getString("vacation1");
						try {						
							/*i = fs.DhmToM(inqEmp.getString("vacation0"), this.hour_d) + fs.DhmToM(inqEmp.getString("vacation1"), this.hour_d);
							limit = fs.MTODhm(i, this.hour_d);
							
							i = fs.DhmToM(inqEmp.getString("vacation0_get"), this.hour_d) + fs.DhmToM(inqEmp.getString("vacation1"), this.hour_d);
							*/
							limit = mels.getLimitLeave(inq.getString("eventgrpid"));
							limit_get = mels.getLimitLeave(inq.getString("eventgrpid"));
						} catch (Exception e) {
							MyLog.error(this, e);

							limit = "00:00:00";
							limit_get = "00:00:00";
						}
					}
					inqEmp.closeConnection(); // close con
				} else {
					/*
					if (inq.getString("limit").length()==1) {
						limit = "0"+inq.getString("limit")+":00:00";
					} else {
						limit = inq.getString("limit")+":00:00";
					}
					*/
					limit = mels.getLimitLeave(inq.getString("eventgrpid"));
					limit_get = "00:00:00";
					vacation0 = "00:00:00";
					vacation1 = "00:00:00";
				}
				
				if (inq.getString("clear_leave").equals("0")) {
					this.leave_not_clear += inq.getString("eventgrpid")+",";
				} else if (inq.getString("clear_leave").equals("1")) {
					this.leave_clear += inq.getString("eventgrpid")+",";
				}
				
				this.hm_Col.put(inq.getString("eventgrpid"), inq.getString("eventgrpid"));
				this.hm_Col.put(inq.getString("eventgrpid") + "_desc", inq.getString("tdesc")); //͡
                this.hm_Col.put(inq.getString("eventgrpid") + "_limit", limit); //Է	
				this.hm_Col.put(inq.getString("eventgrpid") + "_used", "00:00:00"); //ӹǹ
				this.hm_Col.put(inq.getString("eventgrpid") + "_remain", limit); //ӹǹ
				this.hm_Col.put(inq.getString("eventgrpid") + "_count", "0"); //ӹǹ
				this.hm_Col.put(inq.getString("eventgrpid") + "_limit_count", inq.getString("limit_times")); //ӹǹ駷
				this.hm_Col.put(inq.getString("eventgrpid") + "_limit_service", inq.getString("service_year")); //շ
				this.hm_Col.put(inq.getString("eventgrpid") + "_type", inq.getString("daytype")); 
				this.hm_Col.put(inq.getString("eventgrpid") + "_clear", inq.getString("clear_leave"));
				this.hm_Col.put(inq.getString("eventgrpid") + "_hour_d", this.hour_d);
				this.hm_Col.put(inq.getString("eventgrpid") + "_limit_get", limit_get); //Էҷ¡	
				this.hm_Col.put(inq.getString("eventgrpid") + "_vacation0", vacation0);
				this.hm_Col.put(inq.getString("eventgrpid") + "_vacation1", vacation1);
				this.hm_Col.put("date_begin", "");
				this.hm_Col.put("date_end", "");
				this.hm_Col.put("lt_times", "0");
				this.hm_Col.put("lt_hours", "0");
				this.hm_Col.put("lt_hour_fs", "00:00:00");
				this.hm_Col.put("hourwork", this.hour_d);
				this.hm_Col.put(inq.getString("eventgrpid") + "_used0", "00:00:00"); //ӹǹ仡͹ѹҧ
			}
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
		finally{
			try{
				inq.closeConnection();
			}catch(Exception e){
				MyLog.error("!! can't close connection in Simmemployee_statisticleave.selectEvent() !!");
			}
		}
	}
	
	private DbRecord getDefaultAbsent(){
		DbRecord db = null;
		try {
			db = new InitialRecord(this.userPro).getDbRecord("Tabsent_nstda");
			db.setColumn("*");
			db.set("employeeid", this.getString("employeeid"));
			db.set("start_date", new CscCalendar().getYYYYMMDD());
			db.set("end_date", new CscCalendar().getYYYYMMDD());
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return db ;
	}
	
	private void sumTime(){
		HashMap hmLeave = new HashMap();
		try {
			CheckNull chk = new CheckNull();
			String bchfield = chk.chkNullString((String) StaticConfig.getConfigCompany(this.userPro, "TALVFD"),"branch");
			String isbybranch = chk.chkNullString((String) StaticConfig.getConfigCompany(this.userPro, "TALVSET"),"N");
			
			CscCalendar cscLeaveStart = null, cscLeaveEnd=null, cscVacationStart=null, cscVacationEnd=null;
			if (this.param!=null && this.param.containsKey("__date_start") && this.param.containsKey("__date_end")) {
				cscLeaveStart = new CscCalendar((String) this.param.get("__date_start"));
				cscLeaveEnd = new CscCalendar((String) this.param.get("__date_end"));
				cscVacationStart = new CscCalendar((String) this.param.get("__date_start"));
				cscVacationEnd = new CscCalendar((String) this.param.get("__date_end"));
			} else {				
				String startDate = "", endDate="";
				cscLeaveStart = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1001"));
				cscLeaveEnd = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1002"));
				cscVacationStart = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1003"));
				cscVacationEnd = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1004"));
			}
			this.leaveStart = cscLeaveStart;
			this.leaveEnd = cscLeaveEnd;
				
			DbInquiry inq = new InitialInquiry(this.userPro).getDbInquiry((isbybranch.equals("Y"))?"Meventgrp1":"Meventgrp");
			inq.setColumn("*");
			inq.setFilter("branchid = (select " + bchfield + " from memployee where employeeid = '" + this.getString("employeeid") + "')");
			inq.refresh();
			while(inq.next()){
				String lvt = inq.getString("eventgrpid");
				ManageEmpLeaveStat mels = new ManageEmpLeaveStat(userPro, this.getString("employeeid"), lvt);
				mels.setAbsentProp(getDefaultAbsent());
				
				this.hm_Col.put(lvt + "_used", mels.getLeaveUsed(lvt, getDefaultAbsent()));
				this.hm_Col.put(lvt + "_remain", mels.getRemainLeave(lvt));
				this.hm_Col.put(lvt + "_count", mels.getAmountLeaveUsed(lvt));
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
	}
	
	//private void sumTime(String fFilter, String clear) {
	private void sumTime1() {
		DbInquiry inq = null;
		
		try {
			StringBuffer filter = new StringBuffer();
			StringBuffer filter2 = new StringBuffer();
			boolean flag = false;
			CscCalendar cscLeaveStart = null, cscLeaveEnd=null, cscVacationStart=null, cscVacationEnd=null;
			if (this.param!=null && this.param.containsKey("__date_start") && this.param.containsKey("__date_end")) {
				flag = true;
				cscLeaveStart = new CscCalendar((String) this.param.get("__date_start"));
				cscLeaveEnd = new CscCalendar((String) this.param.get("__date_end"));
				cscVacationStart = new CscCalendar((String) this.param.get("__date_start"));
				cscVacationEnd = new CscCalendar((String) this.param.get("__date_end"));
				filter.append("employeeid='").append(this.employeeid).append("' and ");
				filter.append("(dateid between '").append(cscLeaveStart.getYYYYMMDD()).append("' ");
				filter.append("and '"+cscLeaveEnd.getYYYYMMDD()).append("')");
				filter.append("and (doctype='J' or doctype='A' or doctype='S' or doctype='ABSENT') ");
				
				filter2.append("employeeid='").append(this.employeeid).append("' and ");
				filter2.append("(dateid between '").append(cscLeaveStart.getYYYYMMDD()).append("' ");
				filter2.append("and '").append(c_max.getYYYYMMDD()).append("') and lv_type='").append(this.vacationCode).append("' ");
				filter2.append("and (doctype='J' or doctype='A' or doctype='S' or doctype='ABSENT')");
				
				this.leaveStart = cscLeaveStart;
				this.leaveEnd = cscLeaveEnd;
			} else {				
				flag = false;
				String startDate = "", endDate="";
				cscLeaveStart = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1001"));
				cscLeaveEnd = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1002"));
				cscVacationStart = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1003"));
				cscVacationEnd = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "ta1004"));
				
				if (cscLeaveStart.beforeDate(cscVacationStart)) {
					startDate = cscLeaveStart.getYYYYMMDD();					
				} else startDate = cscVacationStart.getYYYYMMDD();
				
				if (cscLeaveEnd.beforeDate(cscVacationEnd)) {
					endDate = cscLeaveEnd.getYYYYMMDD();					
				} else endDate = cscVacationEnd.getYYYYMMDD();
				
				filter.append("employeeid='").append(this.employeeid).append("' ");
				filter.append("and (dateid between '").append(startDate).append("' and '").append(endDate).append("') ");
				filter.append("and (doctype='J' or doctype='A' or doctype='S' or doctype='ABSENT')");
				
				filter2.append("employeeid='").append(this.employeeid).append("' and ");
				filter2.append("(dateid between '").append(startDate).append("' ");
				filter2.append("and '").append(c_max.getYYYYMMDD()).append("') and lv_type='").append(this.vacationCode).append("' ");
				filter2.append("and (doctype='J' or doctype='A' or doctype='S' or doctype='ABSENT')");
				
				this.leaveStart = cscLeaveStart;
				this.leaveEnd = cscLeaveEnd;
			}
			
			/*
			 * աʹ¡
			 */
			CscCalendar c = new CscCalendar();
			int minute_used = 0;
			inq = new InitialInquiry(this.getUProfile()).getDbInquiry();
			inq.initMyTable("tleave_summary", filter2.toString(), "");
			inq.setColumn("*");
			inq.refresh();			
			while (inq.next()) {
				DbRecord rec = inq.getCurrentDbRecord();
				minute_used +=  fs.Tm_To_Min(rec.getDouble("m_lv"));
			}
			inq.closeConnection();
			
			if (minute_used>0) {
				String vacation0 = (String) this.hm_Col.get(this.vacationCode+"_vacation0");
				String vacation1 = (String) this.hm_Col.get(this.vacationCode+"_vacation1");
				//===================== Nuiss Code ===================
				/**
				 * Author  : Nuiss
				 * Date : 29/04/2552
				 * Logic : ત format ͧѹҾѡ͹ ѹеͧ [ѹ:.:ҷ]
				 *  format ѹ
				 */
				String[] arrV0 = vacation0.split(":");
				String[] arrV1= vacation1.split(":");
				if(arrV0.length<3){
					for(int ii=arrV0.length;ii<=3;ii++){
						vacation0+=":00";
					}
				}//end if
				
				if(arrV1.length<3){
					for(int ii=arrV1.length;ii<3;ii++){
						vacation1+=":00";
					}
				}//end if
				//===================== Nuiss Code ===================
				int minute_v0 = fs.DhmToM(vacation0, this.hour_d);
				if (c.after(this.c_max)) {
					if (minute_used < minute_v0) {			
						int i = minute_used + fs.DhmToM(vacation1, this.hour_d);
						String limit = fs.MTODhm(i, this.hour_d);
						this.hm_Col.put(this.vacationCode + "_limit", limit);
					} else {
						int i = fs.DhmToM(vacation0, this.hour_d) + fs.DhmToM(vacation1, this.hour_d);
						String limit = fs.MTODhm(i, this.hour_d);
						this.hm_Col.put(this.vacationCode + "_limit", limit);
					}
				}
			} else {
				if (this.c_max.before(c)) {
					String vacation1 = (String) this.hm_Col.get(this.vacationCode+"_vacation1");
					this.hm_Col.put(this.vacationCode + "_limit", vacation1);
					this.hm_Col.put(this.vacationCode + "_remain", vacation1);
				}
			}
			
			inq = new InitialInquiry(this.getUProfile()).getDbInquiry();
			inq.initMyTable("tleave_summary", filter.toString(), "");
			inq.setColumn("*");
			inq.refresh();			
			while (inq.next()) {
				DbRecord rec = inq.getCurrentDbRecord();
				if (this.hm_Col.containsKey(rec.getString("lv_type"))) {
					String clear_lv = (String) this.hm_Col.get(rec.getString("lv_type")+"_clear");
					String tmp = (String) this.hm_Col.get(rec.getString("lv_type")+"_used");
 					int minute = fs.DhmToM(tmp, this.hour_d) + fs.Tm_To_Min(rec.getDouble("m_lv"));
					String DHM = fs.MTODhm(minute, this.hour_d);
					this.hm_Col.put(rec.getString("lv_type") + "_used", DHM);
					this.hm_Col.put(rec.getString("lv_type") + "_remain", this.getRemainTime(rec.getString("lv_type")));
					
					int count = Integer.parseInt((String) this.hm_Col.get(rec.getString("lv_type")+"_count"));
					count++;
					this.hm_Col.put(inq.getString("lv_type") + "_count", String.valueOf(count));
				}
			}
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
		finally{
			try{
				inq.closeConnection();
			}catch(Exception e){
				MyLog.error("!! can't close connection in Simmemployee_statisticleave.sumTime() !!");
			}
		}
	}
	
	private String getRemainTime(String type) {
		FormulaString fs = new FormulaString();
		String x = this.hm_Col.get(type + "_limit").toString();
		String y = this.hm_Col.get(type + "_used").toString();
		int result = fs.DhmToM(x, this.hour_d) - fs.DhmToM(y, this.hour_d);

		String value = "";
		if (result<0) {
			result = result * -1;
			value = "-"+fs.MTODhm(result, this.hour_d);			
		} else value = fs.MTODhm(result, this.hour_d);
		return value;
	}
	
	public String getString(String fieldName) {
		if(fieldName.equalsIgnoreCase("leave_year")){
			CscCalendar year = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "TA1003"));
			
			return Integer.toString(year.getYear());
		}else if(fieldName.equalsIgnoreCase("last_leavereq")){
			return getLastLeaveRequest();
		}else if (fieldName.equalsIgnoreCase("lastleavedate")) {
			return getLastLeaveDate();
		} else if (fieldName.indexOf("$") > -1) {
			return this.getStringChild(fieldName);
		} else if(fieldName.indexOf("_USED") > -1){
			return getAnnualUsed();
		} else if(fieldName.indexOf("_REMAIN") > -1){ 
			return getAnnualRemain();
		} else {
			return super.getString(fieldName);
		}
	}
	
	private String getAnnualUsed(){
		try {
			if(annType.equals("")){
				DbInquiry inq = new InitialInquiry(this.getUProfile()).getDbInquiry();
				inq.setSchemaName(this.getUProfile().getSchemaName());
				inq.initMyTable("meventgrp1","daytype='7'","");			
				inq.setColumn("*");
				inq.referLangOn();
				inq.refresh();			
				while (inq.next()) {
					annType = inq.getString("eventgrpid");
				}
			}
			
			/* Ǩͺ͹䢵ҧ  㹡Ҥ駹 */
			if(mel01 == null){
				mel01 = new ManageEmpLeaveStat(this.userPro, this.getString("employeeid"), annType);
			}
			
			return mel01.getLeaveUsed(annType);
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return "";
	}
	
	private String getAnnualRemain(){
		try {
			if(annType.equals("")){
				DbInquiry inq = new InitialInquiry(this.getUProfile()).getDbInquiry();
				inq.setSchemaName(this.getUProfile().getSchemaName());
				inq.initMyTable("meventgrp1","daytype='7'","");			
				inq.setColumn("*");
				inq.referLangOn();
				inq.refresh();			
				while (inq.next()) {
					annType = inq.getString("eventgrpid");
				}
			}
			
			/* Ǩͺ͹䢵ҧ  㹡Ҥ駹 */
			if(mel01 == null){
				mel01 = new ManageEmpLeaveStat(this.userPro, this.getString("employeeid"), annType);
			}
			
			return mel01.getRemainLeave(annType);
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return "";
	}
	
	private String getLastLeaveDate(){
		DbInquiry inq = null;
		try {
			inq = new InitialInquiry(this.getUProfile()).getDbInquiry();
			String strWhere = "";
			if(this.getString("vacationcode").equals("")){
				strWhere="vacationid in (select vacationcode from memployee where employeeid ='"+this.getString("employeeid")+"') ";
			}else{
				strWhere ="vacationid='"+this.getString("vacationcode")+"'";
			}
			inq.initMyTable("mvacation0",strWhere , "");
			inq.setColumn("vacationid,companyid,vacation_last");
			inq.refresh();
			while (inq.next()) {
				String d = inq.getString("vacation_last").replace(":", "-");
				if (!d.equals("")) {
					if(d.split("-").length < 3 ){
						CscCalendar styear = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "TA1001"));
						CscCalendar enyear = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "TA1002"));
						
						System.out.print("vacation last > : " + d + "-" + Integer.toString(new CscCalendar().getYear()));
						CscCalendar curlast = new CscCalendar(d + "-" + Integer.toString(new CscCalendar().getYear()));
						
						if(curlast.afterEqualsDate(styear) && curlast.beforeEqualsDate(enyear)){
							return curlast.getDDMMYYYY();
						}else{
							curlast.decYear(1);
							return curlast.getDDMMYYYY();
						}
					}else {
						CscCalendar c = new CscCalendar(d);
						return c.getDDMMYYYY();
					}
				} else return "";					
			}
		} catch (Exception e) {
			MyLog.error(this, e);
		}
		finally{
			try{
				inq.closeConnection();
			}catch(Exception e){
				MyLog.error("!! can't close connection in Simmemployee_statisticleave.getString() !!");
			}
		}
		return "";
	}
	
	/* get last annual leave from tleave_summary */
	private String getLastLeaveRequest(){
		String dateid = "";
		try {
			/* get leave back date 1 year only */
			CscCalendar now = new CscCalendar((String) StaticConfig.getConfigCompany(this.userPro, "TA1003"));
			String filter = "employeeid = '" + this.getString("employeeid") + "' and lv_type in (select eventgrpid from meventgrp1 where daytype = '7') and dateid >= '" + now.getYYYYMMDD() + "'";
			
			DbInquiry inq = new InitialInquiry(this.getUProfile()).getDbInquiry();
			inq.initMyTable("tleave_summary",filter , "");
			inq.setColumn("employeeid,lv_type,dateid");
			inq.setOrderBy("dateid desc");
			inq.refresh();
			while (inq.next()) {
				dateid = inq.getString("dateid");
				break;				
			}

		} catch (Exception e) {
			MyLog.error(this, e);
		}
		finally{
			try{
				inq.closeConnection();
			}catch(Exception e){
				MyLog.error("!! can't close connection in Simmemployee_statisticleave.getString() !!");
			}
		}
		return dateid;
	}

	private String getStringChild(String fieldName) {
		if (fieldName.indexOf("$") > -1) {
			String tName = fieldName.substring(0, fieldName.indexOf("$"));
			String fName = fieldName.substring(fieldName.indexOf("$") + 1, fieldName.length());
			if (this.hm_Col.get(fName) != null) {
				return String.valueOf(this.hm_Col.get(fName));
			}
		}
		return super.getString(fieldName);
	}
	
	private void sumLate(String tableName) {
		//===================== Nuiss Code ================
		/**
		 * Author : Nuiss 
		 * Date : 26/05/2552
		 * Logic : ʴ · ˹Ҩ EMV_TA.jsp
		 * ͧ Retrieve Data ªǧѹǡѹѺ  š
		 * 		    Data  fix  mconfig.configid = ta1001 ,ta1002
		 * Solving  : ҧ Variable ͧѺ Case    кҡ   ǧ˹ ?
		 * 
		 * TA_LATE_ENYEAR : ش [0=ջѨػѹ,-1=͹ 1 ըҡѨغѹ (͹ 2   -2), 1 =  1 ըҡѨغѹ ( 3 ա  3)]
		 * TA_LATE_ENMONTH : ͹ش
		 * TA_LATE_STMONTH : ͹
		 * TA_LATE_STYEAR :  [0=ջѨػѹ,-1=͹ 1  , 1 =  1 ]
		 */
		CscCalendar stDateLate =  this.leaveStart;
		CscCalendar endDateLate =  this.leaveEnd;
		DbInquiry inq = null;
		DbInquiry inqMconfig = null;
		try{
			inqMconfig = new InitialInquiry(this.getUProfile()).getDbInquiry();
			inqMconfig.initMyTable("MCONFIG", "configid like 'TA_LATE_%' ", "configid ASC");
			inqMconfig.setColumn("configid,companyid,tdesc,config_value");
			inqMconfig.refresh();
			// this.leaveStart , this.leaveEnd ͹
			int stMonth =1;int stYear =0;
			int endMonth =12; int endYear =0;
			while (inqMconfig.next()) {
					//TA_LATE_STMONTH
					if(inqMconfig.getString("configid").toUpperCase().equals("TA_LATE_STMONTH")){
						if(inqMconfig.getString("config_value").equals("")||inqMconfig.getString("config_value").equals("0")){
							stMonth=1;
						}else{
							stMonth=Integer.parseInt(inqMconfig.getString("config_value"));
						}//end if 
					}//end if 
					
					//TA_LATE_STYEAR
					if(inqMconfig.getString("configid").toUpperCase().equals("TA_LATE_STYEAR")){
						if(inqMconfig.getString("config_value").equals("")||inqMconfig.getString("config_value").equals("0")){
							stYear=0;
						}else{
							stYear=Integer.parseInt(inqMconfig.getString("config_value"));
						}//end if 
					}//end if 
					
					//TA_LATE_ENMONTH
					if(inqMconfig.getString("configid").toUpperCase().equals("TA_LATE_ENMONTH")){
						if(inqMconfig.getString("config_value").equals("")||inqMconfig.getString("config_value").equals("0")){
							endMonth=1;
						}else{
							endMonth=Integer.parseInt(inqMconfig.getString("config_value"));
						}//end if 
					}//end if 
					
					//TA_LATE_ENYEAR
					if(inqMconfig.getString("configid").toUpperCase().equals("TA_LATE_ENYEAR")){
						if(inqMconfig.getString("config_value").equals("")||inqMconfig.getString("config_value").equals("0")){
							endYear=0;
						}else{
							endYear=Integer.parseInt(inqMconfig.getString("config_value"));
						}//end if 
					}//end if
				}//end while		
			
			//set Calendar
			
			/** original always change startdate and enddate to current year **/
			/** but current version (27-07-2010) follow by company financial year eg. 23/11/yyyy to 22/11/yyyy **/
			/*
			CscCalendar now = new CscCalendar();
			TimeSpan tmsp = new TimeSpan();
			int tmpStYear  = now.getYear()+stYear;
			int tmpEndYear  = now.getYear()+endYear;
			stDateLate = new CscCalendar (tmpStYear,stMonth,1);
			endDateLate = new CscCalendar (tmpEndYear,endMonth,tmsp.getDayInMonth(endMonth, tmpEndYear));
			*/
		}catch(Exception ex){
			MyLog.error("Error in sumLate By Nuiss Code...");
		} finally {//end try
			try{
				inqMconfig.closeConnection();
			}catch(Exception e){
				MyLog.error("---- Error : Simmemployee_statisticleave.sumLate() >> can't close inqMconfig ----");
			}
		}
		
		//===================== Nuiss Code ================
		try {
			String tmp_hr = "0.00";
			String tmp_times = "0.00";
			
			if(!this.hm_Col.containsKey("lt_hours")){
				this.hm_Col.put("lt_hours", "0");
			}
			
			if(!this.hm_Col.containsKey("lt_times")){
				this.hm_Col.put("lt_times", "0");
			}
			tmp_hr = (String) this.hm_Col.get("lt_hours");	
			tmp_times = (String) this.hm_Col.get("lt_times");
			
			CscTime ct = new CscTime(Float.parseFloat(tmp_hr));
			int lt_times = Integer.parseInt(tmp_times);
			
			/** original version query from ttime_current1 and ttime_history1 **/
			/*String filter = "employeeid='"+this.employeeid+"' and lt > 0 and " +
				"(dateid >= '"+stDateLate.getYYYYMMDD()+"' " +
				"and dateid <= '"+endDateLate.getYYYYMMDD()+"') and (eventgrp='T'or eventgrp='J')";*/ 
			
			/** current version query from tleave_summary only **/
			StringBuffer filter = new StringBuffer();
			filter.append("employeeid='").append(this.employeeid).append("' and ");
			filter.append("(dateid >= '").append(stDateLate.getYYYYMMDD()).append("' ");
			filter.append("and dateid <= '").append(endDateLate.getYYYYMMDD()).append("') and doctype='LT'");			
			
			inq = new InitialInquiry(this.getUProfile()).getDbInquiry();
			inq.initMyTable(tableName, filter.toString(), "dateid");
			inq.setColumn("dateid,m_lv");
			inq.refresh();
			while (inq.next()) {
				DbRecord rec = inq.getCurrentDbRecord();
				
				if (rec.getFloat("m_lv")>0) {
					ct.add(rec.getFloat("m_lv"));
					lt_times++;
				}				
			}
			/**
			 * Author : Nuiss
			 * Date : 05/06/2552
			 * Logic : time0 == 05 
			 */
			if(this.getString("time0").equals("05")){
				this.hm_Col.put("lt_times","0");
				this.hm_Col.put("lt_hours","0.00");
				this.hm_Col.put("lt_hour_fs", "00:00:00");
			}else{
				this.hm_Col.put("lt_times", String.valueOf(lt_times));
				this.hm_Col.put("lt_hours", String.valueOf(ct.getFloat()));
				this.hm_Col.put("lt_hour_fs", fs.MTODhm( ((int)ct.getFloat()*60) + (ct.getMinute()), this.hour_d) );
			}//end if 
		} catch (Exception e) {
			MyLog.error(this, e);
		}
		finally{
			try{
				inqMconfig.closeConnection(); 
				inq.closeConnection();
			}catch(Exception e){
				MyLog.error("!! can't close connection in Simmemployee_statisticleave.sumLate() !!");
			}
		}
	}
	
	public boolean isLeaveLimitByBranch(){
		boolean result = false;
		try {
			String stat =  (String) StaticConfig.getConfigCompany(this.userPro, "TALVSET");
			if(stat != null && stat.equals("Y")){
				result = true;
			}
		}catch(Exception e){
			MyLog.error(this,e);
		}
		return result ;
	}
}