MAN002.jsp 31.3 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 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="com.csc.library.entry.*,com.csc.library.system.*,com.csc.library.session.*,com.csc.library.utilities.*,java.text.DecimalFormat,com.csc.library.database.*"%>
<%@ page import="java.util.*,java.io.*,java.sql.*,com.csc.library.components.*"%>

<jsp:useBean id="MAN002" class="com.csc.library.system.Task" scope="page" />
<%
	MAN002.setChannel(request,response);
	HelpEntry screen = (HelpEntry) MAN002.process("HelpEntry","MJOBCODEHELP");
	CheckNull chk = new CheckNull();
	CscCalendar cal = new CscCalendar();

	String cmd = chk.chkNullString(request.getParameter("__cmd"));
	String budid = chk.chkNullString(request.getParameter("__manid"));
	String budtdesc = chk.chkNullString(request.getParameter("MMANPOWER_BUD@TDESC"));
	String branchid = chk.chkNullString(request.getParameter("__branchid"));
	String branchtdesc = chk.chkNullString(request.getParameter("MBRANCH@TDESC"));
	String period_year = chk.chkNullString(request.getParameter("__period_year"),String.valueOf(cal.getYear()));
	String period_month = chk.chkNullString(request.getParameter("__period_month"),cal.getMM());
	String period = chk.chkNullString(request.getParameter("__period"),"tpytran1");
	String groupby = chk.chkNullString(request.getParameter("__groupby"),"bu1");

	String sql = "";
	String payroll_field = "cur_amount";
	if(period.equalsIgnoreCase("mempl_taxm")){
		payroll_field = "amount";
	}
	String butable = "m" + groupby;
	String buid = groupby + "id";
	CscCalendar period_cal_date = new CscCalendar(period_year + "-" + period_month + "-01");
	String period_date = String.valueOf(period_cal_date.getYear()) + "-" + period_cal_date.getMM();
	String cur_year = period_cal_date.getEngYY();
	String cur_month = period_cal_date.getEngShortMonth();
	period_cal_date.decMonth();
	String before_period_date = String.valueOf(period_cal_date.getYear()) + "-" + period_cal_date.getMM();
	String pre_year = period_cal_date.getEngYY();
	String pre_month = period_cal_date.getEngShortMonth();
%>

<html ng-app="myHR">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css">
<link href="../CSS/bootstrap.css" rel="stylesheet"  type="text/css">
<link href="../CSS/bootstrap_csc_backend.css" rel="stylesheet"  type="text/css">
<script type="text/javascript" src="../JS/jquery-2.1.3.min.js"></script>
<script type='text/javascript' src="../JS/bootstrap.js"></script>
<script language="JavaScript" src="../JS/SCREEN.js"></script>
<SCRIPT TYPE='text/JavaScript' SRC='../JS/DATEINPUT.js'></SCRIPT>
<SCRIPT TYPE='text/JavaScript' SRC='../JS/VIEWCALENDAR.js'></SCRIPT>
<script type="text/javascript" src="../JS/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="../JS/angular-1.3.15/angular.js"></script>
<script type="text/javascript" src="../JS/ANGULAR/SCREEN_ANGULAR.js"></script>
<script language="javascript">setLang('<%=screen.getUProfile().get("lang")%>');</script>
<script language="JavaScript" type="text/JavaScript">
function goHelp(helpName,inputName){
	var helpReturn;
	var fixCon = "";
	if(inputName=="__bu1" ){
		helpReturn="__bu1:bu1id,__bu1_desc:tdesc";
	}else if(inputName=="__bu2" ){
		helpReturn="__bu2:bu2id,__bu2_desc:tdesc";
	}else if(inputName=="__bu3" ){
		helpReturn="__bu3:bu3id,__bu3_desc:tdesc";
	}else if(inputName=="__bu4" ){
		helpReturn="__bu4:bu4id,__bu4_desc:tdesc";
	}else if(inputName=="__bu5" ){
		helpReturn="__bu5:bu5id,__bu5_desc:tdesc";
	}else if(inputName=="__employeeid" ){
		helpReturn="__employeeid:employeeid,__employeeid_desc:fullname";
	}else if(inputName=="__shift" ){
		helpReturn="__shift:time0id,__shift_desc:tdesc";
	}else if(inputName=="__salatype" ){
		helpReturn="__salatype:codeid,__salatype_desc:tdesc";
	}else if(inputName=="__emp_type" ){
		helpReturn="__emp_type:codeid,__emp_type_desc:tdesc";
	}else if(inputName=="__manid" ){
		fixcon = "active = '1'";
		helpReturn="__manid:budid,MMANPOWER_BUD@TDESC";
	}else if(inputName=="__branchid" ){
		helpReturn="__branchid:branchid,MBRANCH@TDESC";
	}
	linkHelp_Return(helpName, helpReturn, fixCon);
}

function back(unit){
	with(window.opener.document.cscform){
	        locateId.value =unit;
	}
	window.close();
}

function GoExport(){
	with(document.cscform){
		var param = "MAN002_EXP.jsp?__filter="+__filter.value+"&__period_year="+__period_year.value+"&__period_month="+__period_month.value+"&__period="+__period.value+"&__groupby="+__groupby.value+"&__manid="+__manid.value+"&__branchid="+__branchid.value;
		window.open(param);
	}
}

function GoProcess(){
	with( document.cscform){
		__cmd.value = "search"
		submit();
	}
}

</script>
</head>
<body leftmargin="0" topmargin="0">
<form name="cscform" method="post" action="MAN002.jsp">

<!----------BEGIN CSC INITIAL ZONE ------------------------>

<%=screen.InitialVariable()%>

<!----------END CSC INITIAL ZONE -------------------------->

<input type="hidden" name="__cmd" value="">
<input type="hidden" name="__screen" value="MAN002">
<input type="hidden" name="__help" value="">
<input type="hidden" name="__goPage" value="">
<input type="hidden" name="__language" value="<%=screen.getUProfile().get("lang")%>">
<input type="hidden" name="__orderBy" value="<%=request.getParameter("__orderBy")%>">
<input type="hidden" name="__helpName" value="<%=request.getParameter("__helpName")%>">
<input type="hidden" name="__pageCall" value="<%=request.getParameter("__screen")%>">
<input type="hidden" name="__fixCon" value="<%=request.getParameter("__fixCon")%>">
<input type="hidden" name="__export" value="">
<input type="hidden" name="__calendar" value="">
<input type="hidden" name="__filter" value="">
<script language="javascript">getInputFormatDate()</script>

<br>
<div align="center">
<table class="large" cellpadding="0"  cellspacing="0"  >
<tr>
	<td colspan=2 class="header">MAN002, Report Excel Report Reconcile&nbsp;</td>
</tr>
<tr>
    <td colspan=2>

		<table border="0" cellpadding="0" cellspacing="0" align="center" class="inframe">
			<tr>
				<td colspan=2 class="blankspace"></td>
			</tr>
			<tr>
				<td width="30%" align="right"><%=screen.getUProfile().get("lang").equalsIgnoreCase("tha")?"รหัสงบประมาณกำลังคน":"Manpower Budget ID"%></td>
				<td>
					<input type="text" name="__manid" size="10" value="<%=budid%>"/>
					<a href="javascript:goHelp('MMANPOWER_BUDHELP','__manid')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('__manid_Image2','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="Help" name="__manid_Image2" border="0" align="absmiddle"></a>
					<input type="Text" name="MMANPOWER_BUD@TDESC" size="50" maxlength="100" value="<%=budtdesc%>" readonly="">
				</td>
			</tr>
			<tr>
				<td width="30%" align="right"><%=screen.getUProfile().get("lang").equalsIgnoreCase("tha")?"บริษัท":"Branch ID"%></td>
				<td>
					<input type="text" name="__branchid" size="10" value="<%=branchid%>"/>
					<a href="javascript:goHelp('MBRANCHHELP','__branchid')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('__branchid_Image2','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="Help" name="__branchid_Image2" border="0" align="absmiddle"></a>
					<input type="Text" name="MBRANCH@TDESC" size="50" maxlength="100" value="<%=branchtdesc%>" readonly="">
				</td>
			</tr>
			<tr>
				<td align="right"><%=screen.getUProfile().get("lang").equalsIgnoreCase("tha")?"งวด":"Period"%></td>
				<td>
					<select name="__period">
						<option value="tpytran1" <%if(period.equals("tpytran1")){%>selected<%}%>><%=screen.getUProfile().get("lang").equalsIgnoreCase("tha")?"ปัจจุบัน":"Current"%></option>
						<option value="mempl_taxm" <%if(period.equals("mempl_taxm")){%>selected<%}%>><%=screen.getUProfile().get("lang").equalsIgnoreCase("tha")?"ก่อนหน้า":"Previous"%></option>
					</select>
					&emsp;
					<%=screen.getUProfile().get("lang").equalsIgnoreCase("tha")?"เดือน":"Month"%>
					<%
					ListBox listboxMonth = new ListBox();
					listboxMonth.setUProfile(screen.getUProfile());
					listboxMonth.setName("period_month");
					listboxMonth.setValidCode("MONTHCODE");
					listboxMonth.setChecked(period_month);
					listboxMonth.setDisable("false");
					out.print(listboxMonth.process());
					%>
					&emsp;
					<%=screen.getUProfile().get("lang").equalsIgnoreCase("tha")?"ปี":"Year"%>
					<select name="__period_year">
						<%
						CscCalendar period_cal = new CscCalendar();
						for(int cyear=1; cyear<=5; cyear++){
							if(cyear != 1){
								period_cal.decYear(1);
							}
							String syear = String.valueOf( period_cal.getYear() );
							%>
							<option value="<%=syear%>" <%if(period_year.equals(syear)){%>selected<%}%>><%=syear%></option>
							<%
						}
						%>
					</select>
				</td>
			</tr>
			<tr>
				<td align="right"><span swlang code="SW000122">Group By</span></td>
				<td>
					<select name="__groupby">
						<option value="bu1" <%if(groupby.equals("bu1")){%>selected<%}%>><%=screen.getLabel("bu1")%></option>
						<option value="bu2" <%if(groupby.equals("bu2")){%>selected<%}%>><%=screen.getLabel("bu2")%></option>
						<option value="bu3" <%if(groupby.equals("bu3")){%>selected<%}%>><%=screen.getLabel("bu3")%></option>
						<option value="bu4" <%if(groupby.equals("bu4")){%>selected<%}%>><%=screen.getLabel("bu4")%></option>
						<option value="bu5" <%if(groupby.equals("bu5")){%>selected<%}%>><%=screen.getLabel("bu5")%></option>
					</select>
				</td>
			</tr>

			<tr>
				<td  class="buttonline" colspan="7"><div align="center">
					<button type="button" class="btn btn-primary width100" swlang code="SW003537" onClick="GoProcess();">SEARCH</button>
				</div>
				</td>
			</tr>
		<% if(cmd.equalsIgnoreCase("SEARCH")) { %>
			<tr>
				<td colspan=2 class="blankspace"></td>
			</tr>
			<tr>
				<td colspan=2>

					<table border="1" cellpadding="0" cellspacing="1" align="center" class="largest1 tablewithborder" cols=21 bgcolor="#CCCCCC">
						<tr>
							<td align="center" rowspan="3" class="row1">DEPARTMENT</td>
							<td align="center" colspan="4" class="row1">BUDGET '<%=cur_year%></td>
							<td align="center" colspan="8" class="row1">ACTUAL <%=cur_month%> '<%=cur_year%></td>
							<td align="center" colspan="5" class="row1">PAYROLL <%=cur_month%> '<%=cur_year%></td>
							<td align="center" rowspan="3" class="row1">SALARY<BR><%=cur_month%> '<%=cur_year%></td>
							<td align="center" rowspan="3" class="row1">PAYROLL<BR><%=cur_month%> '<%=cur_year%></td>
							<td align="center" rowspan="3" class="row1">DIFF</td>
						</tr>
						<tr>
							<td align="center" rowspan="2" class="row1">Expats<BR>+<BR>1Cons</td>
							<td align="center" rowspan="2" class="row1">Full<BR>Time</td>
							<td align="center" rowspan="2" class="row1">Temp</td>
							<td align="center" rowspan="2" class="row1">Total</td>
							<td align="center" rowspan="2" class="row1">Expats<BR>+<BR>1Cons</td>
							<td align="center" rowspan="2" class="row1">Other<BR>Cos</td>
							<td align="center" colspan="4" class="row1">Full<BR>Time</td>
							<td align="center" rowspan="2" class="row1">Temp</td>
							<td align="center" rowspan="2" class="row1">Total</td>
							<td align="center" rowspan="2" class="row1">Expats<BR>+<BR>1Cons</td>
							<td align="center" rowspan="2" class="row1">Other<BR>Cos</td>
							<td align="center" rowspan="2" class="row1">Full<BR>Time</td>
							<td align="center" rowspan="2" class="row1">Temp</td>
							<td align="center" rowspan="2" class="row1">Total</td>
						</tr>
						<tr>
							<td align="center" class="row1"><%=pre_month%><BR>'<%=pre_year%></td>
							<td align="center" class="row1">In</td>
							<td align="center" class="row1">Out</td>
							<td align="center" class="row1">No. Emp<BR>at present</td>
						</tr>

						<%
							int budget_expat_con = 0;
							int budget_fulltime = 0;
							int budget_temp = 0;
							int actual_expat_con = 0;
							int actual_orther_cos = 0;
							int actual_fulltime_before_cur = 0;
							int actual_fulltime_in = 0;
							int actual_fulltime_out = 0;
							int actual_fulltime_cur = 0;
							int actual_temp = 0;
							int payroll_expat_con = 0;
							int payroll_other_cos = 0;
							int payroll_fulltime = 0;
							int payroll_temp = 0;
							double salary_emp = 0.0;
							double salary_payroll = 0.0;

							int subtotal_budget_expat_con = 0;
							int subtotal_budget_fulltime = 0;
							int subtotal_budget_temp = 0;
							int subtotal_actual_expat_con = 0;
							int subtotal_actual_orther_cos = 0;
							int subtotal_actual_fulltime_before_cur = 0;
							int subtotal_actual_fulltime_in = 0;
							int subtotal_actual_fulltime_out = 0;
							int subtotal_actual_fulltime_cur = 0;
							int subtotal_actual_temp = 0;
							int subtotal_payroll_expat_con = 0;
							int subtotal_payroll_other_cos = 0;
							int subtotal_payroll_fulltime = 0;
							int subtotal_payroll_temp = 0;
							double subtotal_salary_emp = 0.0;
							double subtotal_salary_payroll = 0.0;

							int total_budget_expat_con = 0;
							int total_budget_fulltime = 0;
							int total_budget_temp = 0;
							int total_actual_expat_con = 0;
							int total_actual_orther_cos = 0;
							int total_actual_fulltime_before_cur = 0;
							int total_actual_fulltime_in = 0;
							int total_actual_fulltime_out = 0;
							int total_actual_fulltime_cur = 0;
							int total_actual_temp = 0;
							int total_payroll_expat_con = 0;
							int total_payroll_other_cos = 0;
							int total_payroll_fulltime = 0;
							int total_payroll_temp = 0;
							double total_salary_emp = 0.0;
							double total_salary_payroll = 0.0;

							DbInquiry budgetinq = new InitialInquiry(screen.getUProfile()).getDbInquiry("manpower_bud_data");
							budgetinq.setColumn("*");
							budgetinq.referLangOn();

							DbInquiry actualinq = new InitialInquiry(screen.getUProfile()).getDbInquiry("memployee");
							actualinq.setColumn("employeeid,salary,alien");
							actualinq.referLangOn();

							DbInquiry payrollinq = new InitialInquiry(screen.getUProfile()).getDbInquiry(period);
							payrollinq.setColumn("*");
							payrollinq.referLangOn();

							DbInquiry buinq = new InitialInquiry(screen.getUProfile()).getDbInquiry(butable);
							buinq.setColumn("*");
							buinq.referLangOn();
							buinq.setFilter(buid + " in (select "+groupby+" from mjobcode where status = '1')");
							buinq.setOrderBy(buid);
							buinq.refresh();
							while(buinq.next()){
								subtotal_budget_expat_con = 0;
								subtotal_budget_fulltime = 0;
								subtotal_budget_temp = 0;
								subtotal_actual_expat_con = 0;
								subtotal_actual_orther_cos = 0;
								subtotal_actual_fulltime_before_cur = 0;
								subtotal_actual_fulltime_in = 0;
								subtotal_actual_fulltime_out = 0;
								subtotal_actual_fulltime_cur = 0;
								subtotal_actual_temp = 0;
								subtotal_payroll_expat_con = 0;
								subtotal_payroll_other_cos = 0;
								subtotal_payroll_fulltime = 0;
								subtotal_payroll_temp = 0;
								subtotal_salary_emp = 0.0;
								subtotal_salary_payroll = 0.0;
						%>

						<tr>
							<td colspan="21"><b><%=buinq.getString("tdesc")%></b></td>
						</tr>

						<%
								String branchfilter = "";
								if(!branchid.equalsIgnoreCase("")) {
									branchfilter = " and branchid = '"+branchid+"'";
								}

								screen.getInquiry().setFilter(groupby+" = '"+buinq.getString(buid)+"' and status = '1'"+branchfilter);
								screen.getInquiry().setOrderBy("jobcodeid");
								screen.getInquiry().refresh();
								screen.referLangOn();
								while(screen.nextRec()){
									budget_expat_con = 0;
									budget_fulltime = 0;
									budget_temp = 0;
									actual_expat_con = 0;
									actual_orther_cos = 0;
									actual_fulltime_before_cur = 0;
									actual_fulltime_in = 0;
									actual_fulltime_out = 0;
									actual_fulltime_cur = 0;
									actual_temp = 0;
									payroll_expat_con = 0;
									payroll_other_cos = 0;
									payroll_fulltime = 0;
									payroll_temp = 0;
									salary_emp = 0.0;
									salary_payroll = 0.0;

									// ----------------------------------- Start Budget -----------------------------------------
									//budgetinq.setFilter("budid in (select budid from mmanpower_bud where substring(start_date,1,4) = '"+period_year+"') and jobid = '"+screen.getString("jobcodeid")+"'");
									budgetinq.setFilter("budid = '"+budid+"' and jobid = '"+screen.getString("jobcodeid")+"'");
									budgetinq.refresh();
									while(budgetinq.next()){
										budget_expat_con += chk.chkNullStringToInt(budgetinq.getString("expat_head"));
										budget_expat_con += chk.chkNullStringToInt(budgetinq.getString("consult_head"));
										budget_fulltime += chk.chkNullStringToInt(budgetinq.getString("per_head"));
										budget_temp += chk.chkNullStringToInt(budgetinq.getString("temp_head"));
										salary_emp += chk.chkNullStringToDouble(budgetinq.getString("per_sal"));
										salary_emp += chk.chkNullStringToDouble(budgetinq.getString("temp_sal"));
										salary_emp += chk.chkNullStringToDouble(budgetinq.getString("expat_sal"));
										salary_emp += chk.chkNullStringToDouble(budgetinq.getString("consult_sal"));
									}
									// ----------------------------------- End Budget -----------------------------------------

									// ----------------------------------- Start Actual -----------------------------------------
									sql = "select count(DISTINCT employeeid) as querydata from memployee "
										+ "where (job = '"+screen.getString("jobcodeid")+"' and substring(startdate,1,7) <= '"+before_period_date+"' and status in (select statuscode from mempl_status where statustype = 'A') and emp_type in (select codeid from memployment_type where type in ('3','4'))) or (job = '"+screen.getString("jobcodeid")+"' and substring(endworkdate,1,7) = '"+period_date+"' and status in (select statuscode from mempl_status where statustype = 'C') and emp_type in (select codeid from memployment_type where type in ('3','4')))";
									actual_expat_con = chk.chkNullStringToInt( getQueryData(sql, screen.getUProfile(), "querydata") );

									sql = "select count(DISTINCT employeeid) as querydata from memployee "
										+ "where (job = '"+screen.getString("jobcodeid")+"' and substring(startdate,1,7) <= '"+before_period_date+"' and status in (select statuscode from mempl_status where statustype = 'A') and isnull(alien, '0') <> '1' and emp_type in (select codeid from memployment_type where type = '1')) or (job = '"+screen.getString("jobcodeid")+"' and substring(endworkdate,1,7) >= '"+period_date+"' and status in (select statuscode from mempl_status where statustype = 'C') and isnull(alien, '0') <> '1' and emp_type in (select codeid from memployment_type where type = '1'))";
									actual_fulltime_before_cur = chk.chkNullStringToInt( getQueryData(sql, screen.getUProfile(), "querydata") );

									sql = "select count(DISTINCT employeeid) as querydata from memployee "
										+ "where job = '"+screen.getString("jobcodeid")+"' and substring(startdate,1,7) = '"+period_date+"' and status in (select statuscode from mempl_status where statustype = 'A') and isnull(alien, '0') <> '1' and emp_type in (select codeid from memployment_type where type = '1')";
									actual_fulltime_in = chk.chkNullStringToInt( getQueryData(sql, screen.getUProfile(), "querydata") );

									sql = "select count(DISTINCT employeeid) as querydata from memployee "
										+ "where job = '"+screen.getString("jobcodeid")+"' and substring(endworkdate,1,7) = '"+period_date+"' and status in (select statuscode from mempl_status where statustype = 'C') and isnull(alien, '0') <> '1' and emp_type in (select codeid from memployment_type where type = '1')";
									actual_fulltime_out = chk.chkNullStringToInt( getQueryData(sql, screen.getUProfile(), "querydata") );

									actualinq.setFilter("job = '"+screen.getString("jobcodeid")+"' and ((substring(startdate,1,7) <= '"+period_date+"' and status in (select statuscode from mempl_status where statustype = 'A')) or (substring(endworkdate,1,7) > '"+period_date+"' and status in (select statuscode from mempl_status where statustype = 'C'))) and emp_type in (select codeid from memployment_type where type = '1')");
									actualinq.refresh();
									while(actualinq.next()){
										if(actualinq.getString("alien").equals("1")){
											actual_expat_con++;
										} else {
											actual_fulltime_cur++;
											//salary_emp += chk.chkNullStringToDouble(actualinq.getString("salary"));
										}
									}

									sql = "select count(DISTINCT employeeid) as querydata from memployee "
										+ "where job = '"+screen.getString("jobcodeid")+"' and substring(startdate,1,7) <= '"+period_date+"' and status in (select statuscode from mempl_status where statustype = 'A') and isnull(alien, '0') <> '1' and emp_type in (select codeid from memployment_type where type = '2')";
									actual_temp = chk.chkNullStringToInt( getQueryData(sql, screen.getUProfile(), "querydata") );
									// ----------------------------------- End Actual --------------------------------------------

									// ----------------------------------- Start Payroll -----------------------------------------
									sql = "select count(DISTINCT employeeid) as querydata from "+period+" "
										+ "where substring(gendate,1,7) = '"+period_date+"' and employeeid in (select employeeid from memployee where job = '"+screen.getString("jobcodeid")+"' and emp_type in (select codeid from memployment_type where type in ('3','4')) )";
									payroll_expat_con = chk.chkNullStringToInt( getQueryData(sql, screen.getUProfile(), "querydata") );

									sql = "select count(DISTINCT employeeid) as querydata from "+period+" "
										+ "where substring(gendate,1,7) = '"+period_date+"' and employeeid in (select employeeid from memployee where isnull(alien, '0') <> '1' and job = '"+screen.getString("jobcodeid")+"' and emp_type in (select codeid from memployment_type where type = '1') )";
									payroll_fulltime = chk.chkNullStringToInt( getQueryData(sql, screen.getUProfile(), "querydata") );

									payrollinq.setFilter("substring(gendate,1,7) = '"+period_date+"' and formulaid in (select formulaid from mformula where groupincid = '1' and formula_type = '1' and tax40 = '1' and basicinc = '1') and employeeid in (select employeeid from memployee where isnull(alien, '0') <> '1' and job = '"+screen.getString("jobcodeid")+"' and emp_type in (select codeid from memployment_type where type = '1') )");
									payrollinq.refresh();
									while(payrollinq.next()){
										salary_payroll += chk.chkNullStringToDouble(payrollinq.getString(payroll_field));
									}

									sql = "select count(DISTINCT employeeid) as querydata from "+period+" "
										+ "where substring(gendate,1,7) = '"+period_date+"' and employeeid in (select employeeid from memployee where isnull(alien, '0') <> '1' and job = '"+screen.getString("jobcodeid")+"' and emp_type in (select codeid from memployment_type where type = '2') )";
									payroll_temp = chk.chkNullStringToInt( getQueryData(sql, screen.getUProfile(), "querydata") );
									// ----------------------------------- End Payroll -------------------------------------------

									total_budget_expat_con += budget_expat_con;
									total_budget_fulltime += budget_fulltime;
									total_budget_temp += budget_temp;
									total_actual_expat_con += actual_expat_con;
									total_actual_orther_cos += actual_orther_cos;
									total_actual_fulltime_before_cur += actual_fulltime_before_cur;
									total_actual_fulltime_in += actual_fulltime_in;
									total_actual_fulltime_out += actual_fulltime_out;
									total_actual_fulltime_cur += actual_fulltime_cur;
									total_actual_temp += actual_temp;
									total_payroll_expat_con += payroll_expat_con;
									total_payroll_other_cos += payroll_other_cos;
									total_payroll_fulltime += payroll_fulltime;
									total_payroll_temp += payroll_temp;
									total_salary_emp += salary_emp;
									total_salary_payroll += salary_payroll;

									subtotal_budget_expat_con += budget_expat_con;
									subtotal_budget_fulltime += budget_fulltime;
									subtotal_budget_temp += budget_temp;
									subtotal_actual_expat_con += actual_expat_con;
									subtotal_actual_orther_cos += actual_orther_cos;
									subtotal_actual_fulltime_before_cur += actual_fulltime_before_cur;
									subtotal_actual_fulltime_in += actual_fulltime_in;
									subtotal_actual_fulltime_out += actual_fulltime_out;
									subtotal_actual_fulltime_cur += actual_fulltime_cur;
									subtotal_actual_temp += actual_temp;
									subtotal_payroll_expat_con += payroll_expat_con;
									subtotal_payroll_other_cos += payroll_other_cos;
									subtotal_payroll_fulltime += payroll_fulltime;
									subtotal_payroll_temp += payroll_temp;
									subtotal_salary_emp += salary_emp;
									subtotal_salary_payroll += salary_payroll;
						%>

						<tr>
							<td nowrap align="left"><%=screen.getDataLabel("tdesc")%></td>
							<td nowrap align="center"><%=budget_expat_con%></td>
							<td nowrap align="center"><%=budget_fulltime%></td>
							<td nowrap align="center"><%=budget_temp%></td>
							<td nowrap align="center"><%=budget_expat_con + budget_fulltime + budget_temp%></td>
							<td nowrap align="center"><%=actual_expat_con%></td>
							<td nowrap align="center"><%=actual_orther_cos%></td>
							<td nowrap align="center"><%=actual_fulltime_before_cur%></td>
							<td nowrap align="center"><%=actual_fulltime_in%></td>
							<td nowrap align="center"><%=actual_fulltime_out%></td>
							<td nowrap align="center"><%=actual_fulltime_cur%></td>
							<td nowrap align="center"><%=actual_temp%></td>
							<td nowrap align="center"><%=actual_expat_con + actual_orther_cos + actual_fulltime_cur + actual_temp%></td>
							<td nowrap align="center"><%=payroll_expat_con%></td>
							<td nowrap align="center"><%=payroll_other_cos%></td>
							<td nowrap align="center"><%=payroll_fulltime%></td>
							<td nowrap align="center"><%=payroll_temp%></td>
							<td nowrap align="center"><%=payroll_expat_con + payroll_other_cos + payroll_fulltime + payroll_temp%></td>
							<td nowrap align="right"><%=setDecimalFormat(salary_emp)%></td>
							<td nowrap align="right"><%=setDecimalFormat(salary_payroll)%></td>
							<td nowrap align="right"><%=setDecimalFormat(salary_emp - salary_payroll)%></td>
						</tr>

						<%
								}
						%>

						<tr>
							<td nowrap align="left"><b>Total <%=buinq.getString("tdesc")%></b></td>
							<td nowrap align="center"><b><%=subtotal_budget_expat_con%></b></td>
							<td nowrap align="center"><b><%=subtotal_budget_fulltime%></b></td>
							<td nowrap align="center"><b><%=subtotal_budget_temp%></b></td>
							<td nowrap align="center"><b><%=subtotal_budget_expat_con + subtotal_budget_fulltime + subtotal_budget_temp%></b></td>
							<td nowrap align="center"><b><%=subtotal_actual_expat_con%></b></td>
							<td nowrap align="center"><b><%=subtotal_actual_orther_cos%></b></td>
							<td nowrap align="center"><b><%=subtotal_actual_fulltime_before_cur%></b></td>
							<td nowrap align="center"><b><%=subtotal_actual_fulltime_in%></b></td>
							<td nowrap align="center"><b><%=subtotal_actual_fulltime_out%></b></td>
							<td nowrap align="center"><b><%=subtotal_actual_fulltime_cur%></b></td>
							<td nowrap align="center"><b><%=subtotal_actual_temp%></b></td>
							<td nowrap align="center"><b><%=subtotal_actual_expat_con + subtotal_actual_orther_cos + subtotal_actual_fulltime_cur + subtotal_actual_temp%></b></td>
							<td nowrap align="center"><b><%=subtotal_payroll_expat_con%></b></td>
							<td nowrap align="center"><b><%=subtotal_payroll_other_cos%></b></td>
							<td nowrap align="center"><b><%=subtotal_payroll_fulltime%></b></td>
							<td nowrap align="center"><b><%=subtotal_payroll_temp%></b></td>
							<td nowrap align="center"><b><%=subtotal_payroll_expat_con + subtotal_payroll_other_cos + subtotal_payroll_fulltime + subtotal_payroll_temp%></b></td>
							<td nowrap align="right"><b><%=setDecimalFormat(subtotal_salary_emp)%></b></td>
							<td nowrap align="right"><b><%=setDecimalFormat(subtotal_salary_payroll)%></b></td>
							<td nowrap align="right"><b><%=setDecimalFormat(subtotal_salary_emp - subtotal_salary_payroll)%></b></td>
						</tr>

						<%
							}
							actualinq.closeConnection();
							payrollinq.closeConnection();
						%>

						<tr>
							<td nowrap align="center"><b>Grand Total</b></td>
							<td nowrap align="center"><b><%=total_budget_expat_con%></b></td>
							<td nowrap align="center"><b><%=total_budget_fulltime%></b></td>
							<td nowrap align="center"><b><%=total_budget_temp%></b></td>
							<td nowrap align="center"><b><%=total_budget_expat_con + total_budget_fulltime + total_budget_temp%></b></td>
							<td nowrap align="center"><b><%=total_actual_expat_con%></b></td>
							<td nowrap align="center"><b><%=total_actual_orther_cos%></b></td>
							<td nowrap align="center"><b><%=total_actual_fulltime_before_cur%></b></td>
							<td nowrap align="center"><b><%=total_actual_fulltime_in%></b></td>
							<td nowrap align="center"><b><%=total_actual_fulltime_out%></b></td>
							<td nowrap align="center"><b><%=total_actual_fulltime_cur%></b></td>
							<td nowrap align="center"><b><%=total_actual_temp%></b></td>
							<td nowrap align="center"><b><%=total_actual_expat_con + total_actual_orther_cos + total_actual_fulltime_cur + total_actual_temp%></b></td>
							<td nowrap align="center"><b><%=total_payroll_expat_con%></b></td>
							<td nowrap align="center"><b><%=total_payroll_other_cos%></b></td>
							<td nowrap align="center"><b><%=total_payroll_fulltime%></b></td>
							<td nowrap align="center"><b><%=total_payroll_temp%></b></td>
							<td nowrap align="center"><b><%=total_payroll_expat_con + total_payroll_other_cos + total_payroll_fulltime + total_payroll_temp%></b></td>
							<td nowrap align="right"><b><%=setDecimalFormat(total_salary_emp)%></b></td>
							<td nowrap align="right"><b><%=setDecimalFormat(total_salary_payroll)%></b></td>
							<td nowrap align="right"><b><%=setDecimalFormat(total_salary_emp - total_salary_payroll)%></b></td>
						</tr>

					</table>

				</td>
			</tr>
			<tr>
				<td colspan=2 class="blankspace"></td>
			</tr>
			<tr>
				<td colspan=2>
					<table class="maxsize" align="center" cellpadding="0" cellspacing="0" class="large">

						<tr>
							<td  class="buttonline" colspan="7"><div align="center">
								<button type="button" class="btn btn-primary width100" swlang code="SW013178" onClick="GoExport();">EXPORT</button>
							</div>
							</td>
						</tr>
					</table>
				</td>
		    </tr>
		<% } %>
		</table>

	</td>
</tr>
<tr>
	<td colspan=2 class="blankspace"></td>
</tr>
<tr bordercolor="0069B3">
	<td colspan=2 class="bottom"></td>
</tr>
</table>
</div>
</form>
</body>
</html>
<%!
	private String setDecimalFormat(Double salary){
		DecimalFormat df = new DecimalFormat("###,##0.00");
		if(salary != 0.0){
			return df.format(salary);
		} else {
			return "-&nbsp;&nbsp;";
		}
	}

	private String getQueryData(String sql ,UProfile up,String fieldreturn){
    	String result = "";
		DataSet ds = null;

		try {

			ds = new DataSet(sql, up.get("dbname"), "");
			ds.setFetchAll(false);
			ds.initConnection(up);
			if (ds.next()) {
				result = ds.getString(fieldreturn);
			}

		} catch (Exception e) {
			MyLog.error(up, e);
		} finally {
			if(ds != null) {
				try {
					ds.closeConnection();
				} catch (Exception e) { /* Ignore Error*/ }
			}
		}

		return result;
    }
%>