PRX002_EXCEL.jsp 13.9 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
<!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.*,java.rmi.RemoteException"%>
<%@page import="java.util.*,java.io.*,java.sql.*"%>
<%@ include file="../CHECKPROFILE.jsp" %>
<script src="//code.jquery.com/jquery-1.11.1.js"></script>
<%
	
	response.setHeader("Cache-Control","must-revalidate");
	response.setContentType("application/vnd.ms-excel; UTF-8");
	response.setHeader("Content-Disposition", "inline; filename=" + "export.xls");
	
	DecimalFormat num = new DecimalFormat("#,###");
	DecimalFormat dmfm = new DecimalFormat("#,##0.00");
	CheckNull chk = new CheckNull();
	
	String view = chk.chkNullString(request.getParameter("__view"));
	String export = chk.chkNullString(request.getParameter("__export"));
	String lang = uprofile.get("lang");
	String Payroll_Table = chk.chkNullString(request.getParameter("__payroll_table"),"mempl_taxm");
	String bu2 = chk.chkNullString(request.getParameter("__bu2"));
	String bu2_desc = chk.chkNullString(request.getParameter("__bu2_desc"));
	String salatype = chk.chkNullString(request.getParameter("__salatype0"));
	String salatype_desc = chk.chkNullString(request.getParameter("__salatype0_desc"));
	String gendate = chk.chkNullString(request.getParameter("__gendate"));
	String gendate2 = chk.chkNullString(request.getParameter("__gendate2"));
	String field_amount = Payroll_Table.equals("tpytran1")?"cur_amount":"amount";
	String filter = "1=1 ";
	if(!bu2.equals("")){
		filter += " AND BU2='"+bu2+"' ";
	}
	if(!salatype.equals("")){
		filter += " AND salatype='"+salatype+"' ";
	}
	if(!gendate.equals("") && !gendate2.equals("")){
		filter += " AND gendate between '"+gendate+"' and '"+gendate2+"' ";
	}
	//out.print("<BR><BR><BR><BR><BR><BR>"+filter);
%>

<html ng-app="myHR">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<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('<%=uprofile.get("lang")%>');</script>
<script src="../JS/angular-1.3.15/angular.js"></script>
<script type='text/JavaScript' SRC='../JS/ANGULAR/SCREEN_ANGULAR.js'></script>
<style>
	td{
		padding:2px;
	}
	.tr-column td{
		background-color:#D2CBCB;
	}
	.fetch-row td{
		text-align:right;
	}
	.grand-total td{
		text-align:right;
	}
	td{
		border:1px solid black;
		mso-number-format:\@;
	}
</style>
</head>
<%
String helpReturn="";
if(request.getParameter("__helpReturn")!=null){
	helpReturn=request.getParameter("__helpReturn");
}
String fieldSearch="";
if(request.getParameter("__fieldSearch")!=null){
	fieldSearch=request.getParameter("__fieldSearch");
}
%>
<body leftmargin="0" topmargin="0">
<form name="cscform" method="post" action="PRX001.jsp">
<input type="hidden" name="__cmd" value="">
<input type="hidden" name="__screen" value="PRX001">
<input type="hidden" name="__help" value="">
<input type="hidden" name="__goPage" value="">
<input type="hidden" name="__language" value="<%=uprofile.get("lang")%>">
<input type="hidden" name="__orderBy" value="<%=request.getParameter("__orderBy")%>">
<input type="hidden" name="__helpReturn" value="<%=helpReturn%>">
<input type="hidden" name="__fieldSearch" value="<%=fieldSearch%>"> 
<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="__view" value="<%=request.getParameter("__view")%>">
<input type="hidden" name="__export" value="<%=export%>"> 
<input type="hidden" name="__calendar" value=""> 
<input type="hidden" name="__filter" value="<%//=sql%>"> 
<script language="javascript">getInputFormatDate()</script>
<%	
		String sql ="" ;
		if(Payroll_Table.equalsIgnoreCase("mempl_taxm")){
			sql =	"select bu2."+getDescByLang(lang)+" as bu2desc,cos."+getDescByLang(lang)+" as costdesc,pr.employeeid from mempl_taxm pr "+
					"left join mbu2 bu2 on(bu2.bu2id = pr.bu2) "+
					"left join mcostcenter cos on (cos.costcenterid = pr.costcenter) "+
					"where  "+filter+" "+
					"group by employeeid,bu2."+getDescByLang(lang)+",cos."+getDescByLang(lang)+" ";
		}
		//out.print(sql);
		DataSet ds = new DataSet(sql,uprofile.get("dbname"),"MEMPLOYEE");
		ds.initConnection(uprofile);
%>
<% 
	if(view.equals("1")||export.equals("1")){ 
	ArrayList<Double> arr_income=new ArrayList<Double>();
	ArrayList<Double> arr_deduct=new ArrayList<Double>();
%>
<TABLE >
	<TR class="tr-column"> 
		<TD swlang code="SW000602"><%=(lang.equalsIgnoreCase("tha"))?"รหัสพนักงาน":"Employeeid"%></TD>
		<TD style="min-width:150px;" swlang code="SW000195"><%=(lang.equalsIgnoreCase("tha"))?"ชื่อ":"Name"%></TD>
		<TD swlang code="SW002031"><%=(lang.equalsIgnoreCase("tha"))?"แผนก":"Department"%></TD>
		<TD swlang code="SW011669"><%=(lang.equalsIgnoreCase("tha"))?"ทะเบียนกระจายต้นทุน":"Cost Center"%></TD>
		<%
			Integer count_income = 0;
			String sql2 = "";
			if(Payroll_Table.equalsIgnoreCase("mempl_taxm")){
				sql2 =	"select * from mformula where formulaid in(select DISTINCT(formulaid) from "+Payroll_Table+" where  "+
							" "+filter+" ) and UPPER(formula_type) in ('1','8','D') and tax!='0' order by groupincid";
			}
			DataSet mformula = new DataSet(sql2,uprofile.get("dbname"),"MEMPLOYEE");
			mformula.initConnection(uprofile);
			while(mformula.next()){
				arr_income.add(count_income,0.00);
				count_income++;
		%>
			<TD ><%=mformula.getString(getDescByLang(lang))%></TD>
		<%
			}
		%>
			<TD swlang code="SW011705"><%=(lang.equalsIgnoreCase("tha"))?"รวมรายได้":"Total Income"%></TD>
		<%
			Integer count_deduct = 0;
			String sql3 = "";
			if(Payroll_Table.equalsIgnoreCase("mempl_taxm")){
				sql3 =	"select * from mformula where formulaid in(select DISTINCT(formulaid) from "+Payroll_Table+" where  "+
							" "+filter+" ) and formula_type='2' and tax!='0' and formulaid not in('MPVF','MSOC','TAX') order by groupincid";
			}
			DataSet mformula2 = new DataSet(sql3,uprofile.get("dbname"),"MEMPLOYEE");
			mformula2.initConnection(uprofile);
			while(mformula2.next()){
				arr_deduct.add(count_deduct,0.00);
				count_deduct++;
		%>
			<TD ><%=mformula2.getString(getDescByLang(lang))%></TD>
		<%
			}
		%>
			<TD >MPVF</TD>
			<TD >MSOC</TD>
			<TD >TAX</TD>
			<TD swlang code="SW011703"><%=(lang.equalsIgnoreCase("tha"))?"รวมรายหัก":"Total Deduct"%></TD>
			<TD >CPVF</TD>
			<TD >CSOC</TD>
			<TD >TAXOT</TD>
			<TD swlang code="SW003585"><%=(lang.equalsIgnoreCase("tha"))?"รายได้สุทธิ":"Net Income"%></TD>
    </TR>
<%
	Double grand_income =0.00;
	Double grand_deduct =0.00;
	Double grand_mpvf =0.00;
	Double grand_msoc =0.00;
	Double grand_tax =0.00;
	Double grand_cpvf =0.00;
	Double grand_csoc =0.00;
	Double grand_taxtot =0.00;
	Double grand_net_income =0.00;
	while(ds.next()){
%>
	<TR class="fetch-row"> 
		<TD ><%=ds.getString("employeeid")%></TD>
		<%
			String fullname = "";
			DbInquiry inq_memployee = new InitialInquiry(uprofile).getDbInquiry("Memployee", false);
			inq_memployee.setColumn("*");
			inq_memployee.setFilter("employeeid",ds.getString("employeeid"));
			inq_memployee.refresh();
			if(inq_memployee.next()){
				fullname = inq_memployee.getString("fullname");
			}
		%>
		<TD style="text-align:left;"><%=fullname%></TD>

		<TD ><%=chk.chkNullString(ds.getString("bu2desc"))%></TD>
		<TD ><%=chk.chkNullString(ds.getString("costdesc"))%></TD>
		<%
			int count_for_arr_income = 0;
			Double temp_income = 0.00;
			Double sum_income = 0.00;
			DataSet mformula3 = new DataSet(sql2,uprofile.get("dbname"),"MEMPLOYEE");
			mformula3.initConnection(uprofile);
			while(mformula3.next()){
				Double income= 0.00;
				String sql4 ="select "+field_amount+" from "+Payroll_Table+" where employeeid ='"+ds.getString("employeeid")+"' and formulaid='"+mformula3.getString("formulaid")+"' " ;
				DataSet cur_amount = new DataSet(sql4,uprofile.get("dbname"),"MEMPLOYEE");
				cur_amount.initConnection(uprofile);
				if(cur_amount.next()){
					income = chk.chkNullStringToDouble(new Base64Decoder(cur_amount.getString(field_amount)).processString());
					sum_income += income;
				}else{
					income = 0.00;
				}
				temp_income = arr_income.get(count_for_arr_income);
				temp_income += income;
				arr_income.set(count_for_arr_income,temp_income);
				count_for_arr_income++;
		%>
			<TD ><%=dmfm.format(income)%></TD>
		<%
			}
			grand_income += sum_income;
		%>
			<TD ><%=dmfm.format(sum_income)%></TD>
		<%
			int count_for_arr_deduct = 0;
			Double temp_deduct = 0.00;
			Double sum_deduct = 0.00;
			DataSet mformula4 = new DataSet(sql3,uprofile.get("dbname"),"MEMPLOYEE");
			mformula4.initConnection(uprofile);
			while(mformula4.next()){
				Double deduct= 0.00;
				String sql5 ="select "+field_amount+" from "+Payroll_Table+" where employeeid ='"+ds.getString("employeeid")+"' and formulaid='"+mformula4.getString("formulaid")+"' " ;
				DataSet cur_amount2 = new DataSet(sql5,uprofile.get("dbname"),"MEMPLOYEE");
				cur_amount2.initConnection(uprofile);
				if(cur_amount2.next()){
					deduct = chk.chkNullStringToDouble(new Base64Decoder(cur_amount2.getString(field_amount)).processString());
					sum_deduct += deduct;
				}else{
					deduct = 0.00;
				}
				temp_deduct = arr_deduct.get(count_for_arr_deduct);
				temp_deduct += deduct;
				arr_deduct.set(count_for_arr_deduct,temp_deduct);
				count_for_arr_deduct++;
		%>
			<TD ><%=dmfm.format(deduct)%></TD>
		<%
			}
		%>
		<%
			Double mpvf = 0.00;
			String sql_mpvf ="select "+field_amount+" from "+Payroll_Table+" where employeeid ='"+ds.getString("employeeid")+"' and formulaid='MPVF' " ;
			DataSet ds_mpvf = new DataSet(sql_mpvf,uprofile.get("dbname"),"MEMPLOYEE");
			ds_mpvf.initConnection(uprofile);
			if(ds_mpvf.next()){
				mpvf = chk.chkNullStringToDouble(new Base64Decoder(ds_mpvf.getString(field_amount)).processString());
				sum_deduct += mpvf;
			}
			grand_mpvf += mpvf;
		%>
			<TD ><%=dmfm.format(mpvf)%></TD>
		<%
			Double msoc = 0.00;
			String sql_msoc ="select "+field_amount+" from "+Payroll_Table+" where employeeid ='"+ds.getString("employeeid")+"' and formulaid='MSOC' " ;
			DataSet ds_msoc = new DataSet(sql_msoc,uprofile.get("dbname"),"MEMPLOYEE");
			ds_msoc.initConnection(uprofile);
			if(ds_msoc.next()){
				msoc = chk.chkNullStringToDouble(new Base64Decoder(ds_msoc.getString(field_amount)).processString());
				sum_deduct+=msoc;
			}
			grand_msoc += msoc;
		%>
			<TD ><%=dmfm.format(msoc)%></TD>
		<%
			Double tax = 0.00;
			String sql_tax ="select "+field_amount+" from "+Payroll_Table+" where employeeid ='"+ds.getString("employeeid")+"' and formulaid like '%TAX' " ;
			DataSet ds_tax = new DataSet(sql_tax,uprofile.get("dbname"),"MEMPLOYEE");
			ds_tax.initConnection(uprofile);
			while(ds_tax.next()){
				tax += chk.chkNullStringToDouble(new Base64Decoder(ds_tax.getString(field_amount)).processString());
				sum_deduct += tax;
			}
			grand_tax += tax;
			grand_deduct += sum_deduct;
		%>
			<TD ><%=dmfm.format(tax)%></TD>
			<TD ><%=dmfm.format(sum_deduct)%></TD>
		<%
			Double cpvf = 0.00;
			String sql_cpvf ="select "+field_amount+" from "+Payroll_Table+" where employeeid ='"+ds.getString("employeeid")+"' and formulaid='CPVF' " ;
			DataSet ds_cpvf = new DataSet(sql_cpvf,uprofile.get("dbname"),"MEMPLOYEE");
			ds_cpvf.initConnection(uprofile);
			if(ds_cpvf.next()){
				cpvf = chk.chkNullStringToDouble(new Base64Decoder(ds_cpvf.getString(field_amount)).processString());
			}
			grand_cpvf += cpvf;
		%>
			<TD ><%=dmfm.format(cpvf)%></TD>
		<%
			Double csoc = 0.00;
			String sql_csoc ="select "+field_amount+" from "+Payroll_Table+" where employeeid ='"+ds.getString("employeeid")+"' and formulaid='CSOC' " ;
			DataSet ds_csoc = new DataSet(sql_csoc,uprofile.get("dbname"),"MEMPLOYEE");
			ds_csoc.initConnection(uprofile);
			if(ds_csoc.next()){
				csoc = chk.chkNullStringToDouble(new Base64Decoder(ds_csoc.getString(field_amount)).processString());
			}
			grand_csoc += csoc;
		%>
			<TD ><%=dmfm.format(csoc)%></TD>
		<%
			Double taxtot = 0.00;
			String sql_taxtot ="select "+field_amount+" from "+Payroll_Table+" where employeeid ='"+ds.getString("employeeid")+"' and formulaid like '%TOT' " ;
			DataSet ds_taxtot = new DataSet(sql_taxtot,uprofile.get("dbname"),"MEMPLOYEE");
			ds_taxtot.initConnection(uprofile);
			while(ds_taxtot.next()){
				taxtot += chk.chkNullStringToDouble(new Base64Decoder(ds_taxtot.getString(field_amount)).processString());
			}
			grand_taxtot += taxtot;
		%>
			<TD ><%=dmfm.format(taxtot)%></TD>
		<%
			Double net_income = (sum_income+taxtot)-sum_deduct;
			grand_net_income += net_income;
		%>
			<TD ><%=dmfm.format(net_income)%></TD>			
    </TR>
<%
	}
	ds.closeConnection();
%>
	<TR class="grand-total">
		<TD colspan="4" style="text-align:center;" swlang code="SW010705"><%=(lang.equalsIgnoreCase("tha"))?"รวมทั้งสิ้น":"Grand Total"%></TD>
		<%
			for(int i=0;i<count_income;i++){
		%>
		<TD ><%=dmfm.format(arr_income.get(i))%></TD>
		<%
			}
		%>
		<TD ><%=dmfm.format(grand_income)%></TD>
		<%
			for(int i=0;i<count_deduct;i++){
		%>
		<TD ><%=dmfm.format(arr_deduct.get(i))%></TD>
		<%
			}
		%>
		<TD ><%=dmfm.format(grand_mpvf)%></TD>
		<TD ><%=dmfm.format(grand_msoc)%></TD>
		<TD ><%=dmfm.format(grand_tax)%></TD>
		<TD ><%=dmfm.format(grand_deduct)%></TD>
		<TD ><%=dmfm.format(grand_cpvf)%></TD>
		<TD ><%=dmfm.format(grand_csoc)%></TD>
		<TD ><%=dmfm.format(grand_taxtot)%></TD>
		<TD ><%=dmfm.format(grand_net_income)%></TD>
	</TR>
</TABLE>
<% } %>
<input type="hidden" name="__payroll_table" value="<%=Payroll_Table%>">
</form>
</body>
</html>
<%!
	private String getDescByLang(String lang){
		return (lang.equals("eng"))?"edesc":"tdesc";
	}
%>