<!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" />
<%
	response.setHeader("Cache-Control","must-revalidate");
	response.setContentType("application/vnd.ms-excel; UTF-8");
	response.setHeader("Content-Disposition", "inline; filename=" + "export.xls");
	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 branchid = chk.chkNullString(request.getParameter("__branchid"));
	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"> -->
<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;
	 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";
	}
	linkHelp_Return(helpName, helpReturn);
}



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



function GoExport(){
	with(document.cscform){
//	alert(__filter.value);
	var param = "MAN002_EXP.jsp?__filter="+__filter.value;
	window.open(param);

//		__export.value = "1";
//		action = "PRU212_EXP.jsp";
//		target = "";
//		submit();
	}
}

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

</script>
</head>
<body leftmargin="0" topmargin="0">
<form name="cscform" method="post" action="MAN002.jsp">
<div align="center">
<table class="large" cellpadding="0"  cellspacing="0"  >
<tr>
    <td colspan=2>
					<table border="1" cellpadding="0" cellspacing="1" align="center" class="largest1" cols=21 bgcolor="#CCCCCC">
						<tr>
							<td align="center" rowspan="3" class="row1" style="vertical-align:middle;"><b>DEPARTMENT</b></td>
							<td align="center" colspan="4" class="row1" style="vertical-align:middle;"><b>BUDGET '<%=cur_year%></b></td>
							<td align="center" colspan="8" class="row1" style="vertical-align:middle;"><b>ACTUAL <%=cur_month%> '<%=cur_year%></b></td>
							<td align="center" colspan="5" class="row1" style="vertical-align:middle;"><b>PAYROLL <%=cur_month%> '<%=cur_year%></b></td>
							<td align="center" rowspan="3" class="row1" style="vertical-align:middle;"><b>SALARY <%=cur_month%> '<%=cur_year%></b></td>
							<td align="center" rowspan="3" class="row1" style="vertical-align:middle;"><b>PAYROLL <%=cur_month%> '<%=cur_year%></b></td>
							<td align="center" rowspan="3" class="row1" style="vertical-align:middle;"><b>DIFF</b></td>
						</tr>
						<tr>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Expats + 1Cons</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Full Time</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Temp</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Total</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Expats + 1Cons</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Other Cos</b></td>
							<td align="center" colspan="4" class="row1" style="vertical-align:middle;"><b>Full Time</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Temp</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Total</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Expats + 1Cons</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Other Cos</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Full Time</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Temp</b></td>
							<td align="center" rowspan="2" class="row1" style="vertical-align:middle;"><b>Total</b></td>
						</tr>
						<tr>
							<td align="center" class="row1" style="vertical-align:middle;"><b><%=pre_month%> '<%=pre_year%></b></td>
							<td align="center" class="row1" style="vertical-align:middle;"><b>In</b></td>
							<td align="center" class="row1" style="vertical-align:middle;"><b>Out</b></td>
							<td align="center" class="row1" style="vertical-align:middle;"><b>No. Emp at present</b></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 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;
    }
%>