COBRANCHLIST_EXPORT.jsp 15.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
<!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.*"%>
<% request.setCharacterEncoding("UTF-8"); %>
<jsp:useBean id="COBRANCHLIST_PRE_EXPORT" 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");

	COBRANCHLIST_PRE_EXPORT.setChannel(request,response);
	HelpEntry screen = (HelpEntry) COBRANCHLIST_PRE_EXPORT.process("HelpEntry","MEMPLOYEEHELP");
	
	CheckNull chk = new CheckNull();

	String cmd = chk.chkNullString(request.getParameter("__cmd"));
	String branch = chk.chkNullString(request.getParameter("__branch"));
	String position = chk.chkNullString(request.getParameter("__position"));
	String bu1id = chk.chkNullString(request.getParameter("__bu1"));
	String bu2id = chk.chkNullString(request.getParameter("__bu2"));
	String bu3id = chk.chkNullString(request.getParameter("__bu3"));
	String bu4id = chk.chkNullString(request.getParameter("__bu4"));
	String bu5id = chk.chkNullString(request.getParameter("__bu5"));
	String include_emp = chk.chkNullString(request.getParameter("__include_emp"));
	String branchdesc = chk.chkNullString(request.getParameter("MBRANCH@TDESC"));
	String jobdesc = chk.chkNullString(request.getParameter("MJOBCODE@TDESC"));
	String mbudesc1 = chk.chkNullString(request.getParameter("MBU1@TDESC"));
	String mbudesc2 = chk.chkNullString(request.getParameter("MBU2@TDESC"));
	String mbudesc3 = chk.chkNullString(request.getParameter("MBU3@TDESC"));
	String mbudesc4 = chk.chkNullString(request.getParameter("MBU4@TDESC"));
	String mbudesc5 = chk.chkNullString(request.getParameter("MBU5@TDESC"));
	
	String cf_last_bu = "";
	DbInquiry inqconfig_gohelp = new InitialInquiry(screen.getUProfile()).getDbInquiry("config_gohelp");
	inqconfig_gohelp.setColumn("*");
	inqconfig_gohelp.refresh();
	if(inqconfig_gohelp.next()){
		cf_last_bu = inqconfig_gohelp.getString("last_bu");
	} else {
		cf_last_bu = "BU5";
	}
	inqconfig_gohelp.closeConnection();
	int last_bu_int = Integer.valueOf(cf_last_bu.replaceAll("BU",""));
	
%>
<%!
	private String chkfilter(String str){
		if(!str.equals("")){
			str += " AND ";
		}
		return str;
	}
%>

<html>
<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 language="javascript">setLang('<%=screen.getUProfile().get("lang")%>');</script>
<script language="JavaScript" type="text/JavaScript">

function goHelp(helpName,inputName){
	if (inputName=="__position" ) {
	 	helpReturn="__position:jobcodeid,MJOBCODE@TDESC";
	}else if (inputName=="__branch" ){
		helpReturn="__branch:branchid,MBRANCH@TDESC";
	}else if (inputName=="__bu1" ){
		helpReturn="__bu1:bu1id,MBU1@TDESC";
	}else if (inputName=="__bu2" ){
		helpReturn="__bu2:bu2id,MBU2@TDESC";
	}else if (inputName=="__bu3" ){
		helpReturn="__bu3:bu3id,MBU3@TDESC";
	}else if (inputName=="__bu4" ){
		helpReturn="__bu4:bu4id,MBU4@TDESC";
	}else if (inputName=="__bu5" ){
		helpReturn="__bu5:bu5id,MBU5@TDESC";
	}
	linkHelp_Return(helpName, helpReturn);
}

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

function GoExport(){
	with( document.cscform){
		var include_emp = "";
		if(__include_emp.checked){
			include_emp = __include_emp.value;
		}
		var con = "__branch="+__branch.value+"&__bu1="+__bu1.value+"&__bu2="+__bu2.value+
					"&__bu3="+__bu3.value+"&__bu4="+__bu4.value+"&__bu5="+__bu5.value+
					"&__position="+__position.value+"&__include_emp="+include_emp;
		window.open("COBRANCHLIST_EXPORT.jsp?&"+con);
		window.close();
	}
}

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

</script>
</head>
<style>
	td.rowex {
		background: #3399cc;
		border: #cccccc;
		color: #000000;
		font-weight: bold;
		height: 45px;
	}
</style>

<body leftmargin="0" topmargin="0">
<form name="cscform" method="post" action="COBRANCHLIST_PRE_EXPORT.jsp">


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

<%//=screen.InitialVariable()%>

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

<input type="hidden" name="__cmd" value="">
<input type="hidden" name="__screen" value="COBRANCHLIST_PRE_EXPORT">
<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>

			
<table height="" align="center" cellpadding="0" cellspacing="1" class="maxsize" border="0" width="100%">	
	<tr bgcolor="#3366CC">
		<td colspan=2> 
			<table class="maxsize" border="1" cellpadding="0" cellspacing="1" cols=11 bgcolor="#FFFFFF">
			
				<%
				
				int cols = 2 + last_bu_int;
				if(include_emp.equals("1")){
					cols++;
				}
				
				%>
				<tr>
					<td class="rowex" colspan="<%=cols%>" style="font-size:100%"><b><%=include_emp.equals("1")?"Employee List By Organization":"Organize Structure Report"%></b></td>
				</tr>
			
				<tr>
					<td class="rowex"><div align="center"><b><%=screen.getLabel("branch") %></b></div></td>
					<%if(last_bu_int >= 1) out.println("<td class='rowex'><div align='center'><b>"+screen.getLabel("bu1")+"</b></div></td>"); %>
					<%if(last_bu_int >= 2) out.println("<td class='rowex'><div align='center'><b>"+screen.getLabel("bu2")+"</b></div></td>"); %>
					<%if(last_bu_int >= 3) out.println("<td class='rowex'><div align='center'><b>"+screen.getLabel("bu3")+"</b></div></td>"); %>
					<%if(last_bu_int >= 4) out.println("<td class='rowex'><div align='center'><b>"+screen.getLabel("bu4")+"</b></div></td>"); %>
					<%if(last_bu_int >= 5) out.println("<td class='rowex'><div align='center'><b>"+screen.getLabel("bu5")+"</b></div></td>"); %>
					<td class="rowex"><div align="center"><b><%=screen.getUProfile().get("lang").equalsIgnoreCase("tha")?"ตำแหน่ง":"Position" %></b></div></td>
					<%if(include_emp.equals("1")) out.println("<td class='rowex'><div align='center'><b>"+(screen.getUProfile().get("lang").equalsIgnoreCase("tha")?"รายชื่อพนักงาน":"Employee Name")+"</b></div></td>"); %>
				</tr>
				
				<%
				
				String dbName = screen.getUProfile().getDbName();
				String tableName = "MEMPLOYEE";
				String numbu = String.valueOf(last_bu_int);
				StringBuffer sql_emp = new StringBuffer();
				
				for(int i=1; i<=last_bu_int; i++){
					sql_emp.append("and emp.bu"+i+" = bu"+i+".bu"+i+"id ");
				}
				
				DbInquiry inqbranch = new InitialInquiry(screen.getUProfile()).getDbInquiry("mbranch");
				inqbranch.setColumn("*");
				DbInquiry inqbu1 = new InitialInquiry(screen.getUProfile()).getDbInquiry("mbu1");
				inqbu1.setColumn("*");
				DbInquiry inqbu2 = new InitialInquiry(screen.getUProfile()).getDbInquiry("mbu2");
				inqbu2.setColumn("*");
				DbInquiry inqbu3 = new InitialInquiry(screen.getUProfile()).getDbInquiry("mbu3");
				inqbu3.setColumn("*");
				DbInquiry inqbu4 = new InitialInquiry(screen.getUProfile()).getDbInquiry("mbu4");
				inqbu4.setColumn("*");
				DbInquiry inqbu5 = new InitialInquiry(screen.getUProfile()).getDbInquiry("mbu5");
				inqbu5.setColumn("*");
				DbInquiry inqposition = new InitialInquiry(screen.getUProfile()).getDbInquiry("mposition");
				inqposition.setColumn("*");
				DbInquiry inqemployee = new InitialInquiry(screen.getUProfile()).getDbInquiry("memployee");
				inqemployee.setColumn("*");
				
				String chkbranch = "";
				String chkbu1 = "";
				String chkbu2 = "";
				String chkbu3 = "";
				String chkbu4 = "";
				String chkbu5 = "";
				String chkposition = "";
				String chkemployee = "";
				
				String databranch = "";
				String databu1 = "";
				String databu2 = "";
				String databu3 = "";
				String databu4 = "";
				String databu5 = "";
				String dataposition = "";
				String dataemployee = "";
				
				String filter = " ";
				if(!branch.equals("")){
					filter += "and com.branchid = '"+branch+"' ";
				}
				
				if(!bu1id.equals("")){
					filter += "and bu1.bu1id = '"+bu1id+"' ";
				}
				
				if(!bu2id.equals("")){
					filter += "and bu2.bu2id = '"+bu2id+"' ";
				}
				
				if(!bu3id.equals("")){
					filter += "and bu3.bu3id = '"+bu3id+"' ";
				}
				
				if(!bu4id.equals("")){
					filter += "and bu4.bu4id = '"+bu4id+"' ";
				}
				
				if(!bu5id.equals("")){
					filter += "and bu5.bu5id = '"+bu5id+"' ";
				}
				
				if(!position.equals("")){
					filter += "and pos.positionid = '"+position+"' ";
				}
				
				StringBuffer sql = new StringBuffer();
				sql.append("select com.branchid, bu1.bu1id, bu2.bu2id, bu3.bu3id, bu4.bu4id, bu5.bu5id, pos.positionid, emp.employeeid ");
				sql.append("from ");
				sql.append("mbranch as com ");
				sql.append("left join mbu1 as bu1 on com.branchid = bu1.branchid ");
				sql.append("left join mbu2 as bu2 on bu1.bu1id = bu2.parent ");
				sql.append("left join mbu3 as bu3 on bu2.bu2id = bu3.parent ");
				sql.append("left join mbu4 as bu4 on bu3.bu3id = bu4.parent ");
				sql.append("left join mbu5 as bu5 on bu4.bu4id = bu5.parent ");
				sql.append("left join mposition as pos on pos.bu"+numbu+" = bu"+numbu+".bu"+numbu+"id ");
				sql.append("left join memployee as emp on emp.emp_position = pos.positionid and emp.branch = com.branchid ");
				sql.append(sql_emp.toString());
				sql.append("where 1=1"+filter);
				sql.append("order by com.branchid, bu1.bu1id, bu2.bu2id, bu3.bu3id, bu4.bu4id, bu5.bu5id, pos.positionid, emp.employeeid ");
				
				DataSet ds = new DataSet(sql.toString(), dbName, tableName ); 
				ds.initConnection(screen.getUProfile()); 
				while(ds.next()){
					
					if(!chk.chkNullString(ds.getString("branchid")).equalsIgnoreCase(chkbranch)){
						chkbranch = chk.chkNullString(ds.getString("branchid"));
						inqbranch.setFilter("branchid = '"+chkbranch+"'");
						inqbranch.refresh();
						inqbranch.referLangOn();
						if(inqbranch.next()){
							//databranch = chkbranch + " : " + inqbranch.getString("tdesc");
							databranch = inqbranch.getString("tdesc");
						} else {
							databranch = "";
						}
					} else {
						databranch = "";
					}

					if(!chk.chkNullString(ds.getString("bu1id")).equalsIgnoreCase(chkbu1)){
						chkbu1 = chk.chkNullString(ds.getString("bu1id"));
						inqbu1.setFilter("bu1id = '"+chkbu1+"'");
						inqbu1.refresh();
						inqbu1.referLangOn();
						if(inqbu1.next()){
							//databu1 = chkbu1 + " : " + inqbu1.getString("tdesc");
							databu1 = inqbu1.getString("tdesc");
						} else {
							databu1 = "";
						}
					} else {
						databu1 = "";
					}
					
					if(!chk.chkNullString(ds.getString("bu2id")).equalsIgnoreCase(chkbu2)){
						chkbu2 = chk.chkNullString(ds.getString("bu2id"));
						inqbu2.setFilter("bu2id = '"+chkbu2+"'");
						inqbu2.refresh();
						inqbu2.referLangOn();
						if(inqbu2.next()){
							//databu2 = chkbu2 + " : " + inqbu2.getString("tdesc");
							databu2 = inqbu2.getString("tdesc");
						} else {
							databu2 = "";
						}
					} else {
						databu2 = "";
					}
					
					if(!chk.chkNullString(ds.getString("bu3id")).equalsIgnoreCase(chkbu3)){
						chkbu3 = chk.chkNullString(ds.getString("bu3id"));
						inqbu3.setFilter("bu3id = '"+chkbu3+"'");
						inqbu3.refresh();
						inqbu3.referLangOn();
						if(inqbu3.next()){
							//databu3 = chkbu3 + " : " + inqbu3.getString("tdesc");
							databu3 = inqbu3.getString("tdesc");
						} else {
							databu3 = "";
						}
					} else {
						databu3 = "";
					}
					
					if(!chk.chkNullString(ds.getString("bu4id")).equalsIgnoreCase(chkbu4)){
						chkbu4 = chk.chkNullString(ds.getString("bu4id"));
						inqbu4.setFilter("bu4id = '"+chkbu4+"'");
						inqbu4.refresh();
						inqbu4.referLangOn();
						if(inqbu4.next()){
							//databu4 = chkbu4 + " : " + inqbu4.getString("tdesc");
							databu4 = inqbu4.getString("tdesc");
						} else {
							databu4 = "";
						}
					} else {
						databu4 = "";
					}
					
					if(!chk.chkNullString(ds.getString("bu5id")).equalsIgnoreCase(chkbu5)){
						chkbu5 = chk.chkNullString(ds.getString("bu5id"));
						inqbu5.setFilter("bu5id = '"+chkbu5+"'");
						inqbu5.refresh();
						inqbu5.referLangOn();
						if(inqbu5.next()){
							//databu5 = chkbu5 + " : " + inqbu5.getString("tdesc");
							databu5 = inqbu5.getString("tdesc");
						} else {
							databu5 = "";
						}
					} else {
						databu5 = "";
					}
					
					if(!chk.chkNullString(ds.getString("positionid")).equalsIgnoreCase(chkposition)){
						chkposition = chk.chkNullString(ds.getString("positionid"));
						inqposition.setFilter("positionid = '"+chkposition+"'");
						inqposition.refresh();
						inqposition.referLangOn();
						if(inqposition.next()){
							//dataposition = chkposition + " : " + inqposition.getString("tdesc");
							dataposition = inqposition.getString("tdesc");
						} else {
							dataposition = "";
						}
					} else {
						dataposition = "";
					}
					
					if(!chk.chkNullString(ds.getString("employeeid")).equalsIgnoreCase(chkemployee)){
						chkemployee = chk.chkNullString(ds.getString("employeeid"));
						inqemployee.setFilter("employeeid = '"+chkemployee+"'");
						inqemployee.refresh();
						inqemployee.referLangOn();
						if(inqemployee.next()){
							//dataemployee = inqemployee.getString("employeeid") + " : " + inqemployee.getString("fullname");
							dataemployee = inqemployee.getString("fullname");
						} else {
							dataemployee = "";
						}
					} else {
						dataemployee = "";
					}
					
				%>
				
				<tr>
					<td align="left"><%=databranch%></td>
					<%if(last_bu_int >= 1) out.println("<td align='left'>"+databu1+"</td>"); %>
					<%if(last_bu_int >= 2) out.println("<td align='left'>"+databu2+"</td>"); %>
					<%if(last_bu_int >= 3) out.println("<td align='left'>"+databu3+"</td>"); %>
					<%if(last_bu_int >= 4) out.println("<td align='left'>"+databu4+"</td>"); %>
					<%if(last_bu_int >= 5) out.println("<td align='left'>"+databu5+"</td>"); %>
					<td align="left"><%=dataposition%></td>
					<%if(include_emp.equals("1")) out.println("<td align='left'>"+dataemployee+"</td>"); %>
				</tr>
				
				<%
				
				}
				ds.closeConnection();
				
				inqbranch.closeConnection();
				inqbu1.closeConnection();
				inqbu2.closeConnection();
				inqbu3.closeConnection();
				inqbu4.closeConnection();
				inqbu5.closeConnection();
				inqposition.closeConnection();
				inqemployee.closeConnection();
				
				%>
				
         </table>
	  </td>
	 </tr>
</table>

</form>
</body>
</html>