OI-HOLIDAY.jsp 17.4 KB
Newer Older
Thitichaipun Wutthisak 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
<!DOCTYPE html>
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ page import="com.csc.library.system.*,com.csc.library.utilities.*"%>
<%@ page import="com.csc.library.entry.*,com.csc.library.database.*,com.csc.library.session.*"  %>
<%@ page import="java.util.*"  %>
<%@page import="com.csc.library.timeattendance.DayShift,com.csc.library.timeattendance.Shift"  %>
<%@page import="com.csc.library.timeattendance.WorkingShift,com.csc.library.report.ReportUDF"  %>
<%@page import="java.text.DecimalFormat,java.util.*,com.csc.library.databean.*;"  %>

<%@ include file="../CHECKPROFILE.jsp" %>
<% request.setCharacterEncoding("UTF-8"); %>
<jsp:useBean id="EMV" class="com.csc.library.system.Task" scope="page" />
<jsp:setProperty name="EMV" property="appname" value="empview" />
<jsp:useBean id="TA" class="com.csc.library.system.Task" scope="page" />
<jsp:setProperty name="TA" property="appname" value="empview" />
<%
	EMV.setChannel(request, response);
	TA.setChannel(request,response);
	UIManager screenTA = (UIManager)TA.process("SingleEntry","TAU147");
	HelpEntry screen = (HelpEntry)EMV.process("HelpEntry", "OI-HOLIDAYHELP");
	if(screen==null){
		return;
	}

	ReportUDF rp=new ReportUDF();
	CscCalendar cs=new CscCalendar();

	String lang = screen.getUProfile().get("lang");
	String subQuery = "select holidaycode from mtime0 where time0id='" +screen.getUProfile().get("time0id") +"' and companyid='"+screen.getUProfile().get("companyid") +"'";
	CscCalendar calendar = new CscCalendar();
	CscCalendar lastcalen = new CscCalendar();
	CscCalendar nextcalen = new CscCalendar();
	lastcalen.decYear(5);
	nextcalen.incYear(1);
	int lastmon = lastcalen.getMonth()+1;
	int nextmon = nextcalen.getMonth()+1;
	//screen.getInquiry().setFilter("hdate", calendar.getEngYYYY()+"-%","","like");
	//screen.getInquiry().setFilter("holidayid", subQuery, "" ,"in");
	screen.getInquiry().setFilter("holidayid = ("+subQuery+") AND (hdate >= '"+lastcalen.getYear()+"-"+lastmon+"-01' AND hdate <= '"+nextcalen.getYear()+"-"+nextmon+"-31')");
	screen.getInquiry().refresh();
	CheckNull chk = new CheckNull();

	HtmlCalendar htmlCal = new HtmlCalendar();

	//htmlCal.setLanguage(HtmlCalendar.THAI);
	htmlCal.setLanguage(screen.getUProfile().get("lang"));
	htmlCal.setHeader("MMMM");
	htmlCal.setWeekEnd(1);
	htmlCal.setWeekEnd(7);

	while(screen.nextRec()){
		screen.inq.referLangOn();
		htmlCal.setHoliday(screen.getInquiry().getString("hdate") , screen.getString("edesc"));
 		screen.referLangOff();
   }

	HashMap hm =new HashMap();
	DbRecord dbrec = new InitialRecord(screen.getUProfile()).getDbRecord("memployee");
	dbrec.set("employeeid",screen.getUProfile().get("employeeid"));
	dbrec.set("companyid",screen.getUProfile().get("companyid"));
	dbrec.setColumn("*");
	dbrec.search();
	if (dbrec.recCount()>0){

		Mtime0 rec = (Mtime0)new InitialRecord(screen.getUProfile()).getDbRecord("Mtime0");
		rec.setColumn("*");
		rec.set("time0id",dbrec.getString("time0"));
		rec.search();
		if (!rec.getString("time0id").equalsIgnoreCase("")){
			CscCalendar cs1 = new CscCalendar("01-01-"+cs.getYear());
			CscCalendar cs2 = new CscCalendar("31-12-"+cs.getYear());
			// cs1.incYear(1);
			cs2.incYear(1);
			rec.setEmpRec(dbrec);
			try{
				WorkingShift ws = rec.genWorkingShift(new CscCalendar(cs1.getYYYYMMDD()),new CscCalendar(cs2.getYYYYMMDD()),"true");
				ws.setUProfile(screen.getUProfile());
				ws.meargeWithShiftTrans(dbrec, new CscCalendar(cs1.getYYYYMMDD()), new CscCalendar(cs2.getYYYYMMDD()));
				if (!ws.isEmpty()){
					// out.print(">>" + ws);
					ws.setUProfile(screen.getUProfile());
					ws.setEmprec(dbrec);
					ws.setEmployeeid(screen.getUProfile().get("employeeid"));
					ws.setEmpTimeCode(dbrec.getString("time0"));
					ws.adjust();
					ws.createLink();
					hm.put("ws", ws);
				}
			}catch(Exception ex){

			}
		}
	}

	WorkingShift pws = (WorkingShift)hm.get("ws");
	/*try{
		for (Iterator IT = pws.keySet().iterator();IT.hasNext();){
			String key = (String)IT.next();
			DayShift dShift = (DayShift) pws.get(key);
			for (Iterator IT1 = dShift.keySet().iterator(); IT1.hasNext();){
				String key1 = (String)IT1.next();
				Shift sh = (Shift)dShift.get(key1);

				if (sh.getEventGroup().equalsIgnoreCase("H")){
					out.println(sh.getShiftDate().getYYYYMMDD());
				}

			}
		}
	}catch(Exception ex){
		out.println("error");
	}*/

%>
<%!
	private String getLongDate(UProfile upf, String date){
    	CscCalendar c = null;
        try{
            c=new CscCalendar(date);
        }catch(Exception ex){
			MyLog.error(this, ex);
            c=new CscCalendar();
        }
        if(upf.get("lang").toString().equalsIgnoreCase("ENG")){
            return c.getEngLongMonth()+", "+c.getDate();
        }else{
        	return c.getDate()+" "+c.getThaiLongMonth();
        }
    }

	private String truncate(String msg, int limit) {
		String pad = "...";
		String saparator = " ";
		if(msg.length() <= limit){
			return msg;
		}
		msg = msg.substring(0, limit);

		int breakpoint = msg.lastIndexOf( saparator );
		if( breakpoint >0) {
			msg = msg.substring(0, breakpoint);
		}
	 	return msg +pad;
	}
%>

<%
	char[] cyear;
	if("eng".equalsIgnoreCase(screen.getUProfile().get("lang"))) {
		cyear = calendar.getEngYYYY().toCharArray();
	} else {
		cyear = calendar.getThaiYYYY().toCharArray();
	}
%>
<html ng-app="myHR" xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Employee View</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<style>
			.eventhover{
			    display: none;
			    position: fixed;
			    width: 20%;
			    height: auto;
			    background-color: #fdfdfd;
			    top: 120%;
			    z-index: 100;
			    border-radius: 4px;
			   /* border: 1px solid #fff;*/
			    box-shadow: 1px 1px 2px 2px #B3B3B3;
			    line-height:200%;
			    font-size:16px;
			    padding-left:20px;
			    padding-right:20px;
			    /*right:5%;*/
			    text-align:center;
			}

			.fc-event-container:hover .eventhover{
				 display: block;
			}

			.darkbg{
				position:fixed;
				display:none;
				width:100%;
				height:100%;
				background:black;
				z-index:20;
				opacity:0.5;
				top:0%;
			}
			.full-calendar{
				padding-bottom: 2% !important;
			}
			.statuscalendar{
				display:block;
				float:right;
				width:64%;
				margin-bottom:30px;
			}
			.blockcolor{
				width:20px;
				height:20px;
				display:block;
				float:left;
			}
			.dayoffcolor{
				background :#feff1a;
			}
			.holidaycolor{
				background :#ff0000;
			}
			.mytxt{
				display:block;
				float:left;
				width:24%;
				padding-left:10px;
				text-align:left;
			}
			.container{
					width:100% !important;
			}
			@media screen and (max-width: 1333px){
				.eventhover{
					 font-size:14px;
				}
				.mytxt{
					width:22% !important;
				}

			}
			@media screen and (max-width: 1330px){
				.mytxt{
					width:22% !important;
				}

			}
		</style>
	</head>
	<body>
		<div class="bg-com"></div>
		<jsp:include page="EMV_HEADMENU.jsp" flush="true" />

		<script type="text/javascript">

			setLang("<%=screen.getUProfile().get("lang")%>");
			var swap = new swaplang();
            var titlename = swap.swap2String("SW002193");
            var evwidth = parseInt($("body").width())*0.2;
			setPageTitle(titlename);

			$("document").ready(function(){
				var nowdate=new Date();
				var nowlang='<%=screen.getUProfile().get("lang")%>';
				var tmp_month,tmp_year,tmp_date,varkey,detailkey,totalev=[],mypointer,tmp_date_month;
				var headname="";
				var myholiday="";
				var weekdayoff="";
				var myhollist="",mylang="";
				var beyear=nowdate.getFullYear()-5;
				var mydayOff="";
				var mypublicholiday="";
				setCalendarLang(nowlang);

				if (nowlang=="eng"){
					headname="Yearly Calendar";
					mylang="en";
					mydayOff="Day Off";
					mypublicholiday="Public Holiday";
				} else {
					headname="ปฏิทินประจำปี";
					mylang="th";
					mydayOff="วันหยุดประจำสัปดาห์";
					mypublicholiday="วันหยุดนักขัตฤกษ์";
				}

				for (beyear;beyear<=nowdate.getFullYear()+5 ; beyear++){
					for (incmonth=1;incmonth<=12 ;incmonth++){
						if (incmonth<=9){
							tmp_month="0"+incmonth;
						}else {
							tmp_month=incmonth;
						}
						myholiday=myholiday+',"ho'+beyear+tmp_month+'":[]';
						weekdayoff=weekdayoff+',"ho'+beyear+tmp_month+'":[]';
					}
				}

				myholiday=JSON.parse("{"+myholiday.substring(1)+"}");
				weekdayoff=JSON.parse("{"+weekdayoff.substring(1)+"}");

				<%
					MyHashMap holiday = htmlCal.getHoliday();
					for ( Iterator it = holiday.getKeySortIterator(); it.hasNext(); ){
						String key = it.next().toString();
				%>
						varkey="<%=key%>";
						detailkey="<%=holiday.get(key)%>";
						console.log(varkey, detailkey);

						tmp_date="ho"+getYearFYYYYMMDD(varkey)+getMonthFYYYYMMDD(varkey);
						myholiday[tmp_date].push({
							date_event:varkey,
							date_detail:detailkey,
							colorev :'#ff0000',
							txtcolor : '#fff',
							date_status : "holiday"
						});
				<%
					}

					try{
						for (Iterator IT = pws.keySet().iterator();IT.hasNext();){
							String key = (String)IT.next();
							DayShift dShift = (DayShift) pws.get(key);
							for (Iterator IT1 = dShift.keySet().iterator(); IT1.hasNext();){
								String key1 = (String)IT1.next();
								Shift sh = (Shift)dShift.get(key1);

								if (sh.getEventGroup().equalsIgnoreCase("H")){
				%>
									varkey="<%=sh.getShiftDate().getYYYYMMDD()%>";
									detailkey=mydayOff;

									tmp_date="ho"+getYearFYYYYMMDD(varkey)+getMonthFYYYYMMDD(varkey);
									weekdayoff[tmp_date].push({
										date_event:varkey,
										date_detail:detailkey,
										colorev : '#feff1a',
										txtcolor : '#202020',
									});
				<%
								}

							}
						}
					}catch(Exception ex){
						out.println("error");
					}
				%>
				for (mypointer in myholiday){
					for (tmp_month in myholiday[mypointer]){
						totalev.push({
							title:myholiday[mypointer][tmp_month].date_detail,
							start:myholiday[mypointer][tmp_month].date_event,
							end:myholiday[mypointer][tmp_month].date_event,
							color : myholiday[mypointer][tmp_month].colorev,
							textColor : myholiday[mypointer][tmp_month].txtcolor
						});
					}
				}

				for (mypointer in weekdayoff){
					for (tmp_month in weekdayoff[mypointer]){
						totalev.push({
							title:weekdayoff[mypointer][tmp_month].date_detail,
							start:weekdayoff[mypointer][tmp_month].date_event,
							end:weekdayoff[mypointer][tmp_month].date_event,
							color:weekdayoff[mypointer][tmp_month].colorev,
							textColor:weekdayoff[mypointer][tmp_month].txtcolor
						});
					}
				}

				$("#mycalendar").fullCalendar({
					header: {
						left: 'prev,next today',
						center: 'title',
						right: 'month,year'
					},
					yearColumns: 3,
					defaultView: 'year',
					eventLimit:true,
					events: totalev,
					lang: mylang
				});

				$("h3.center-detail").html(headname+" "+nowdate.getFullYear());
				$(".fc-center h2").html(headname+" "+nowdate.getFullYear());

				tmp_year=nowdate.getFullYear();
				tmp_month=getMonthAndCon(nowdate);

				$.setDateFromSelect=function(paramMonth,paramYear){
					tmp_month=paramMonth;
					tmp_year=paramYear;
				}


				$.getListMonth=function(param_incdec){
					tmp_date=tmp_year+"-"+tmp_month+"-01";

					console.log(tmp_date);

					nowdate = new Date(tmp_date);
					nowdate.setMonth(nowdate.getMonth()+param_incdec);

					tmp_year=nowdate.getFullYear();
					tmp_month=getMonthAndCon(nowdate);

					myhollist="";
					tmp_date_month="ho"+tmp_year+tmp_month;

					for(incmonth=1;incmonth<=12;incmonth++){
						myhollist+="<div class='body-event'><div class='class-title'>"+getMonthFullName(incmonth)+"</div>";
						if (incmonth<=9){
							tmp_date="ho"+tmp_year+"0"+incmonth;
						}else{
							tmp_date="ho"+tmp_year+incmonth;
						}
						if (tmp_date==tmp_date_month){
							for (mypointer in myholiday[tmp_date]){

								myhollist+="<div class='listof-body-event'><span class='highlight'>"+getDayFYYYYMMDD(myholiday[tmp_date][mypointer].date_event)+" - "+myholiday[tmp_date][mypointer].date_detail+"</span></div>";
							}
						}else{
							for (mypointer in myholiday[tmp_date]){

								myhollist+="<div class='listof-body-event'>"+getDayFYYYYMMDD(myholiday[tmp_date][mypointer].date_event)+" - "+myholiday[tmp_date][mypointer].date_detail+"</div>";
							}
						}

						myhollist+="</div>";

					}
					$(".class-list").html(myhollist);
				}

				$.getListYear=function(param_incdec){

					tmp_date=tmp_year+"-"+tmp_month+"-01";

					nowdate = new Date(tmp_date);
					nowdate.setFullYear(nowdate.getFullYear()+param_incdec);

					tmp_year=nowdate.getFullYear();

					myhollist="";
					for (incmonth=1;incmonth<=12;incmonth++){
						myhollist+="<div class='body-event'><div class='class-title'>"+getMonthFullName(incmonth)+"</div>";

						if (incmonth<=9){
							tmp_date="ho"+tmp_year+"0"+incmonth;
						}else{
							tmp_date="ho"+tmp_year+incmonth;
						}

						for (mypointer in myholiday[tmp_date]){
							myhollist+="<div class='listof-body-event'>"+getDayFYYYYMMDD(myholiday[tmp_date][mypointer].date_event)+" - "+myholiday[tmp_date][mypointer].date_detail+"</div>";
						}

						myhollist+="</div>";
					}

					$(".class-list").html(myhollist);
				}

				$.getListYear(0);


				$(".fc-month-button").click(function(){
					$.resizeHover();

					$.getListMonth(0);
				});

				$(".fc-year-button").click(function(){
					$.unResizeHover();

					$("h3.center-detail").html(headname+" "+tmp_year);
					$(".fc-center h2").html(headname+" "+tmp_year);
				});

				$(".fc-prev-button").click(function(){

					if ($(".fc-month-button").hasClass("fc-state-active")){
						$.getListMonth(-1);
					}else if ($(".fc-year-button").hasClass("fc-state-active")){
						tmp_month="01";
						$.getListYear(-1);
						$("h3.center-detail").html(headname+" "+tmp_year);
						$(".fc-center h2").html(headname+" "+tmp_year);
					}

				});

				$(".fc-next-button").click(function(){

					if ($(".fc-month-button").hasClass("fc-state-active")){
						$.getListMonth(1);
					}else if ($(".fc-year-button").hasClass("fc-state-active")){
						tmp_month="01";
						$.getListYear(1);
						$("h3.center-detail").html(headname+" "+tmp_year);
						$(".fc-center h2").html(headname+" "+tmp_year);
					}
				});

				$(".fc-today-button").click(function(){


					nowdate = new Date();

					tmp_month=getMonthAndCon(nowdate);
					tmp_year=nowdate.getFullYear();
					console.log(tmp_year);
					$("h3.center-detail").html(headname+" "+nowdate.getFullYear());
					$(".fc-center h2").html(headname+" "+nowdate.getFullYear());
					setTimeout($.getListMonth(0),1000);
				});

				$.resizeHover = function (){
					//$(".eventhover").css("width","40%");
				}

				$.unResizeHover = function(){
					//$(".eventhover").css("width","90%");
				}
				$(".fc-toolbar").append("<div class=\"statuscalendar\"><div class=\"blockcolor dayoffcolor\"></div><span class=\"mytxt\">"+mydayOff+"</span><div class=\"blockcolor holidaycolor\"></div><span class=\"mytxt\">"+mypublicholiday+"</span></div>");
			});

			window.onmousemove = function(ev){
				var x = ev.clientX;
				var y = ev.clientY;
				//var evwidth = $(".eventhover").width();
				var nowbodywidth = $("body").width()-$(".list-event").width()-100;

				$(".eventhover").css("top",y+20);
				if ((evwidth+x)>=nowbodywidth){
					$(".eventhover").css("left",x-evwidth);
				}else{
					$(".eventhover").css("left",x-40);
				}
			}


			function showHover(myId){
				var mystr = $("#"+myId).find(".fc-title").html();

				console.log($("#"+myId).find(".fc-event").css("background-color"));
				var bgcolor=$("#"+myId).find(".fc-event").css("background-color");
				var txtcolor=$("#"+myId).find(".fc-event").css("color")
				$("#"+myId).find(".eventhover").css("background-color",bgcolor);
				$("#"+myId).find(".eventhover").css("color",txtcolor);
				$("#"+myId).find(".eventhover").html(mystr);
				//$("#"+myId).find(".eventhover").css("display","block");
			}

			function disableHover(){
				//$(".eventhover").css("display","none");
			}

			function selectMonth(thismonth,thisyear){
				$.resizeHover();
				var tmpMonth
				thismonth++;

				if (thismonth<=9){
					tmpMonth="0"+thismonth;
				} else {
					tmpMonth=thismonth;
				}

				tmpYear=thisyear;
				$.setDateFromSelect(tmpMonth,tmpYear);
				$.getListMonth(0);
			}
		</script>

		<section>
			<div class="container csc-content" style="width:100% !important">
				<form class="form-horizontal" name="cscform" method="post" action="?">
					<!-- BEGIN CSC INITIAL ZONE -->
					<%=screen.InitialVariable()%>
					<!-- END CSC INITIAL ZONE -->
					<input type="hidden" name="__cmd" value="">
					<input type="hidden" name="__screen" value="OI_HOLIDAY">
					<input type="hidden" name="__language" value ="<%=screen.getUProfile().get("lang")%>">

					<div class="csc-block-white">
						<div class="list-event">
							<div class="list-block-event">
								<h3 class="center-detail"></h3>
								<div class="class-list">
								</div>
							</div>
						</div>

						<div id="mycalendar" class="full-calendar"></div>
						<!-- <div class="statuscalendar">
							<div class="blockcolor dayoffcolor"></div><span class="mytxt">Day Off</span>
							<div class="blockcolor holidaycolor"></div><span class="mytxt">Holiday</span>
						</div> -->
					</div><!-- end csc-block-white -->
				</form>
			</div>
			<a href="#top" id="top-button">
				<i class="fa fa-angle-up"></i>
				<div class="top-word">Back to top</div>
			</a>
		</section>
		<jsp:include page="FOOTER.jsp" flush="true" />
	</body>
</html>