Mbranch_absentot.java 10.5 KB
Newer Older
TongZuu 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
package com.csc.library.databean;

import java.text.DecimalFormat;

import com.csc.library.database.MyHashMap;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.DbRecord;
import com.csc.library.session.InitialInquiry;
import com.csc.library.utilities.CscCalendar;
import com.csc.library.utilities.CscTime;
import com.csc.library.utilities.MyLog;

public class Mbranch_absentot extends Mbranch {

	private DbInquiry inqTimeC = null;
	private DbInquiry inqTimeH = null;
	private DbInquiry inqEmp = null;
	private MyHashMap hmEmp = new MyHashMap();
	private DecimalFormat df = new DecimalFormat("###,###,###,##0.00");
	
	private double workingDay_1 = 0;
	private double leaveDay_1 = 0;
	private CscTime workingHour_1 = new CscTime(0);
	private CscTime ot_1 = new CscTime(0);
	private double emp_1 = 0;
	private double workingDay_2 = 0;
	private double leaveDay_2 = 0;
	private CscTime workingHour_2 = new CscTime(0);
	private CscTime ot_2 = new CscTime(0);	
	private double emp_2 = 0;
	
	public boolean foundData() {
		boolean flag = super.foundData();
		workingDay_1 = 0;
		leaveDay_1 = 0;
		ot_1 = new CscTime(0);
		workingHour_1 = new CscTime(0);
		emp_1 = 0;
		
		workingDay_2 = 0;
		leaveDay_2 = 0;
		ot_2 = new CscTime(0);
		workingHour_2 = new CscTime(0);
		emp_2 = 0;
				
		if (flag==true) { 			
			this.setDataCurrent();
			this.setDataHistory();
		}
		return flag;
	}
	
	private void setDataValue(DbRecord rec) {
		try {
			String cost_type = this.getEmpCostType(rec.getString("employeeid"));
			float hour_s = rec.getFloat("hour_s");
				
			if (rec.getString("eventgrp").equals("T") || rec.getString("eventgrp").equals("J")) { //ѹӧҹ
				float hour_d = rec.getFloat("hour_d");
				if (hour_d>0 && hour_s>0 && hour_s/hour_d <= 0.5) {
					if (cost_type.equals("1")) { 
						workingDay_1 += 0.5;
						workingHour_1.add(hour_s/hour_d);
					} else if (cost_type.equals("2")) { 
						workingDay_2 += 0.5;
						workingHour_2.add(hour_s/hour_d);
					} 
				} else if (hour_d>0 && hour_s>0 && hour_s/hour_d > 0.5) {
					if (cost_type.equals("1")) { 
						workingDay_1 += 1;
						workingHour_1.add(hour_s);
					} else if (cost_type.equals("2")) { 
						workingDay_2 += 1;
						workingHour_2.add(hour_s);
					} 
				} else if (hour_d==0 && hour_s>0) {
					if (cost_type.equals("1")) { 
						workingDay_1 += 1;
						workingHour_1.add(hour_s);
					} else if (cost_type.equals("2")) { 
						workingDay_2 += 1;
						workingHour_2.add(hour_s);
					} 
				}
			}
			
			if (rec.getString("doctype").equals("A") || rec.getString("doctype").equals("S")) { //
				float lv = rec.getFloat("m_lv");
				if (lv>0 && hour_s>0 && hour_s/lv <= 0.5) {
					if (cost_type.equals("1")) { 
						leaveDay_1 += 0.5;
					} else if (cost_type.equals("2")) { 
						leaveDay_2 += 0.5;
					} 
				} else if (lv>0 && hour_s>0 && hour_s/lv > 0.5) {
					if (cost_type.equals("1")) { 
						leaveDay_1 += 1;
					} else if (cost_type.equals("2")) { 
						leaveDay_2 += 1;
					} 
				} 
			}
			
			if (rec.getFloat("ac_ot")>0) {
				if (cost_type.equals("1")) { 
					ot_1.add(rec.getFloat("ac_ot"));
				} else if (cost_type.equals("2")) { 
					ot_2.add(rec.getFloat("ac_ot"));
				} 
			}
		} catch (Exception e) {
			MyLog.error(this, e);
		}
	}
	
	private void setDataCurrent() {
		// cscStart = new CscCalendar("2007-01-01");
		//CscCalendar cscEnd = new CscCalendar("2007-12-01");
		CscCalendar cscStart = new CscCalendar((String) this.param.get("STARTDATE"));
		CscCalendar cscEnd = new CscCalendar((String) this.param.get("ENDDATE"));
		
		try {
			if (this.inqTimeC==null) {
				this.inqTimeC = new InitialInquiry(this.userPro).getDbInquiry();			
				this.inqTimeC.setSchemaName(this.userPro.getSchemaName());						
				this.inqTimeC.initMyTable("Ttime_current1", "", "employeeid, dateid, sequence");
				this.inqTimeC.setColumn("*");
			}
			this.inqTimeC.setFilter("branch='"+this.getString("branchid")+"' and (dateid between '"+cscStart.getYYYYMMDD()+"' and '"+cscEnd.getYYYYMMDD()+"')");
			this.inqTimeC.refresh();
			while (this.inqTimeC.next()) {
				DbRecord rec = this.inqTimeC.getCurrentDbRecord();
				this.setDataValue(rec);
			}
		} catch (Exception e) {
			MyLog.error(this, e);
		}
	}  
	
	private void setDataHistory() {
		// cscStart = new CscCalendar("2007-01-01");
		//CscCalendar cscEnd = new CscCalendar("2007-12-01");
		CscCalendar cscStart = new CscCalendar((String) this.param.get("STARTDATE"));
		CscCalendar cscEnd = new CscCalendar((String) this.param.get("ENDDATE"));
		
		try {
			if (this.inqTimeH==null) {
				this.inqTimeH = new InitialInquiry(this.userPro).getDbInquiry();			
				this.inqTimeH.setSchemaName(this.userPro.getSchemaName());						
				this.inqTimeH.initMyTable("Ttime_history1", "", "employeeid, dateid, sequence");
				this.inqTimeH.setColumn("*");
			}
			this.inqTimeH.setFilter("branch='"+this.getString("branchid")+"' and (dateid between '"+cscStart.getYYYYMMDD()+"' and '"+cscEnd.getYYYYMMDD()+"')");
			this.inqTimeH.refresh();
			while (this.inqTimeH.next()) {
				DbRecord rec = this.inqTimeH.getCurrentDbRecord();
				this.setDataValue(rec);
			}
		} catch (Exception e) {
			MyLog.error(this, e);
		}
	}  
	
	private String getEmpCostType(String employeeid) {
		if (this.hmEmp.containsKey(employeeid)) {
			return this.hmEmp.getString(employeeid);
		} else {
			try {
				if (this.inqEmp==null) {
					this.inqEmp = new InitialInquiry(this.userPro).getDbInquiry();			
					this.inqEmp.setSchemaName(this.userPro.getSchemaName());						
					this.inqEmp.initMyTable("Memployee", "", "employeeid");
					this.inqEmp.setColumn("employeeid, companyid, emp_level, cost_type");
				}
				this.inqEmp.setFilter("employeeid='"+employeeid+"'");
				this.inqEmp.refresh();
				if (this.inqEmp.next()) {
					this.hmEmp.put(employeeid, this.inqEmp.getString("cost_type"));
					if (this.inqEmp.getString("cost_type").equals("1")) {
						emp_1++;
					} else if (this.inqEmp.getString("cost_type").equals("2")) {
						emp_2++;
					}
					return this.inqEmp.getString("cost_type");
				}
			} catch (Exception e) {
				MyLog.error(this, e);
			}
		}
		return "";
	}
	
	public String getString(String fieldName) {		
		String value = "";
		if (fieldName.toLowerCase().indexOf("workingday_1") >= 0) {
			value = df.format(this.workingDay_1);
		} else if (fieldName.toLowerCase().indexOf("workingday_2") >= 0) {
			value = df.format(this.workingDay_2);
		} else if (fieldName.toLowerCase().indexOf("leaveday_1") >= 0) {
			value = df.format(this.leaveDay_1);
		} else if (fieldName.toLowerCase().indexOf("leaveday_2") >= 0) {
			value = df.format(this.leaveDay_2);
		} else if (fieldName.toLowerCase().indexOf("ot_1") >= 0) {
			value = df.format(Double.parseDouble(String.valueOf(this.ot_1.getFloat())));
		} else if (fieldName.toLowerCase().indexOf("ot_2") >= 0) {
			value = df.format(Double.parseDouble(String.valueOf(this.ot_2.getFloat())));
		} else if (fieldName.toLowerCase().indexOf("workinghour_1") >= 0) {
			value = df.format(Double.parseDouble(String.valueOf(this.workingHour_1.getFloat())));
		} else if (fieldName.toLowerCase().indexOf("workinghour_2") >= 0) {
			value = df.format(Double.parseDouble(String.valueOf(this.workingHour_2.getFloat())));
		} else if (fieldName.toLowerCase().indexOf("emp_1") >= 0) {
			value = df.format(this.emp_1);
		} else if (fieldName.toLowerCase().indexOf("emp_2") >= 0) {
			value = df.format(this.emp_2);
		} else if (fieldName.toLowerCase().indexOf("attday_1") >= 0) {			
			value = df.format(this.workingDay_1 - this.leaveDay_1);
		} else if (fieldName.toLowerCase().indexOf("attday_2") >= 0) {			
			value = df.format(this.workingDay_2 - this.leaveDay_2);
		} else if (fieldName.toLowerCase().indexOf("leaverate_1") >= 0) {	
			if (this.workingDay_1==0) {
				value = "0.00";
			} else value = df.format((this.leaveDay_1/this.workingDay_1)*100);
		} else if (fieldName.toLowerCase().indexOf("leaverate_2") >= 0) {				
			if (this.workingDay_2==0) {
				value = "0.00";
			} else value = df.format((this.leaveDay_2/this.workingDay_2)*100);
		} else if (fieldName.toLowerCase().indexOf("otrate_1") >= 0) {			
			if (this.workingHour_1.getFloat()==0) {
				value = "0.00";
			} else value = df.format(Double.parseDouble(String.valueOf((this.ot_1.getFloat()/this.workingHour_1.getFloat())*100)));
		} else if (fieldName.toLowerCase().indexOf("otrate_2") >= 0) {			
			if (this.workingHour_2.getFloat()==0) {
				value = "0.00";
			} else value = df.format(Double.parseDouble(String.valueOf((this.ot_2.getFloat()/this.workingHour_2.getFloat())*100)));
		} else if (fieldName.toLowerCase().indexOf("otamt_1") >= 0) {
			value = df.format(Double.parseDouble(String.valueOf(this.ot_1.getFloat())));
		} else if (fieldName.toLowerCase().indexOf("otamt_2") >= 0) {
			value = df.format(Double.parseDouble(String.valueOf(this.ot_2.getFloat())));
		} 
		
		else if (fieldName.toLowerCase().indexOf("workingday_total") >= 0) {
			value = df.format(this.workingDay_1 + this.workingDay_2);
		} else if (fieldName.toLowerCase().indexOf("leaveday_total") >= 0) {
			value = df.format(this.leaveDay_1 + this.leaveDay_2);
		} else if (fieldName.toLowerCase().indexOf("ot_total") >= 0) {
			value = df.format(Double.parseDouble(String.valueOf(this.ot_1.getFloat() + this.ot_2.getFloat())));
		} else if (fieldName.toLowerCase().indexOf("workinghour_total") >= 0) {
			value = df.format(Double.parseDouble(String.valueOf(this.workingHour_1.getFloat() + this.workingHour_2.getFloat())));
		} else if (fieldName.toLowerCase().indexOf("attday_total") >= 0) {
			value = df.format((this.workingDay_1 - this.leaveDay_1) + (this.workingDay_2 - this.leaveDay_2));
		} else if (fieldName.toLowerCase().indexOf("emp_total") >= 0) {
			value = df.format(this.emp_1 + this.emp_2);
		} else if (fieldName.toLowerCase().indexOf("leaverate_total") >= 0) {
			value = df.format(Double.parseDouble(this.getString("leaverate_1")) + Double.parseDouble(this.getString("leaverate_2")));
		} else if (fieldName.toLowerCase().indexOf("otrate_total") >= 0) {
			value = df.format(Double.parseDouble(this.getString("otrate_1")) + Double.parseDouble(this.getString("otrate_2")));
		} else if (fieldName.toLowerCase().indexOf("otamt_total") >= 0) {
			value = df.format(Double.parseDouble(String.valueOf(this.ot_1.getFloat() + this.ot_2.getFloat())));
		} else {
			return super.getString(fieldName);
		}
		
		if (value.equals("")) {
			return "0.00";
		} else return value;
	}

}