Simmemployee_tadjtime1.java 10 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 269 270 271 272 273 274 275 276 277 278 279 280 281 282
package com.csc.library.databean;

import com.csc.library.utilities.MyLog;
import com.csc.library.formula.FormulaString;
import com.csc.library.database.DataSet;
import com.csc.library.database.MyHashMap;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.InitialInquiry;

import com.csc.library.utilities.CscCalendar;

/**
 * @author xerox
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class Simmemployee_tadjtime1 extends Memployee {
	MyHashMap hm_data = new MyHashMap();
	int count = 0;
	double hr = 0;
	String employeeid;
	
	public int assignField(DataSet rs) {
		int temp = super.assignField(rs);
		this.hm_data.clear();
		employeeid = this.getString("employeeid");
		if (!this.getString("employeeid").trim().equals("")) {
			//	MyLog.debug(this, "employeeid--->>>>>"+this.employeeid);
			//hr=Double.valueOf(this.getString("hour_d")).doubleValue();
			this.getHour_Day();
			this.setEventgrp();
			this.setDaytype();
			this.setSumData();
			this.setSubData();
			//MyLog.debug(this, "hm_eventgrp-->"+this.hm_data);
		}
		return temp;
	}

	public void setEventgrp() {
		MyLog.debug(this, "<<<<<--------setEventgrp--------->>>>>>");
		try {
			String DataEventgrp = "", lang = "ENG";
			if (this.param.containsKey("LANGUAGE")) {
				String codeL = (String) this.param.get("LANGUAGE");
				if (!codeL.trim().equals("")) {
					lang = codeL;
				}
			}
			//MyLog.debug(this, "param_lang---> "+this.param.get("LANGUAGE"));
			//MyLog.debug(this, "lang---> "+lang);
			DbInquiry in2 = new InitialInquiry(this.getUProfile()).getDbInquiry();
			in2.initMyTable("Meventgrp",	"daytype!='1' and daytype !='5' and daytype !='6' and daytype !='9'", "");
			in2.setColumn("eventgrpid,limit,edesc,tdesc");
			in2.refresh();
			while (in2.next()) {
				if (lang.equals("ENG")) {
					this.hm_data.put(in2.getString("eventgrpid"), in2.getString("edesc"));
				} else {
					this.hm_data.put(in2.getString("eventgrpid"), in2.getString("tdesc"));
				}
				this.hm_data.put("id_" + in2.getString("eventgrpid"), in2.getString("eventgrpid"));
				this.hm_data.put("limit_" + in2.getString("eventgrpid"), this.lToL(in2.getString("limit")));
				DataEventgrp += in2.getString("eventgrpid") + ",";
			}
		} catch (Exception e) {
			MyLog.error(this, e);
		}
	}

	public void setDaytype() {
		// MyLog.debug(this, "<-------------------setdayType------------------->");
		try {
			count = 0;
			String codecol = "";
			String data = "0:0:0";
			MyLog.debug(this, "param--->" + this.param);

			codecol = "01";
			MyLog.debug(this, "param--->" + this.param.get("CODEID"));
			if (this.param.containsKey("CODEID")) {
				String code = (String) this.param.get("CODEID");
				if (!code.trim().equals("")) {
					codecol = code;
				}
			}

			DbInquiry in1 = new InitialInquiry(this.getUProfile()).getDbInquiry();
			in1.initMyTable("Mleave_report", "", "");
			in1.setColumn("*");
			in1.setFilter("codeid = '" + codecol + "'");
			in1.refresh();
			in1.next();
			for (int i = 1; i <= 10; i++) {
				if (i == 10) {
					if (!in1.getString("col10").equals("")) {
						count++;
					}
					if (in1.getString("col10").trim().equals("")) {
						continue;
					}
					this.hm_data.put("id_col10", in1.getString("col10"));
					this.hm_data.put("col10", this.hm_data.get(in1.getString("col10")).toString());
					this.hm_data.put("limit_col10", this.hm_data.get("limit_" + in1.getString("col10")).toString());
					this.hm_data.put("lv_col10", data);
					this.hm_data.put("total_col10", data);
					continue;
				}
				if (in1.getString("col0" + i).trim().equals("")) {
					continue;
				}
				if (!in1.getString("col0" + i).equals("")) {
					count++;
				}

				MyLog.debug(this, "Data Inq0" + i + "-->"+ in1.getString("col0" + i));
				this.hm_data.put("id_col0" + i, in1.getString("col0" + i));
				this.hm_data.put("col0" + i, this.hm_data.get(in1.getString("col0" + i)).toString());
				this.hm_data.put("limit_col0" + i, this.hm_data.get("limit_" + in1.getString("col0" + i)).toString());
				this.hm_data.put("lv_col0" + i, data);
				this.hm_data.put("total_col0" + i, data);
			}
		} catch (Exception e) {
			MyLog.error(this, e);

		}
	}

	public void setSumData() {
		//MyLog.debug(this, "<-------------------setSumData------------------->");
		// MyLog.debug(this, "STARTD--->"+this.param.get("STARTD"));
		// MyLog.debug(this, "ENDD--->"+this.param.get("ENDD"));
		try {
			double lt = 0;
			String tlv = "";
			int rec = 0, lv = 0, lv1 = 0, lvSum = 0;
			String startD = "", endD = "", sql = "";
			CscCalendar cs = new CscCalendar();
			FormulaString fs = new FormulaString();
			startD = String.valueOf(cs.getYear()) + "-01-01";
			endD = cs.getYYYYMMDD();

			if (this.param.containsKey("STARTD")) {
				String st = (String) this.param.get("STARTD");
				if (!st.trim().equals("")) {
					CscCalendar csS = new CscCalendar(st);
					startD = csS.getYYYYMMDD();
				}
			}

			if (this.param.containsKey("ENDD")) {
				String en = (String) this.param.get("ENDD");
				if (!en.trim().equals("")) {
					CscCalendar csE = new CscCalendar(en);
					endD = csE.getYYYYMMDD();
				}
			}

			MyLog.debug(this, "date---> " + startD + " <> " + endD);
			CscCalendar cs1 = new CscCalendar(startD);
			CscCalendar cs2 = new CscCalendar(endD);

			sql = "employeeid='" + this.getString("employeeid") + "' "
					+ "and (dateid between '" + startD + "' and '" + endD + "') "
					+ "and (doctype='A' or doctype='S')";
			DbInquiry in1 = new InitialInquiry(this.getUProfile()).getDbInquiry();
			in1.initMyTable("tleave_summary", sql, "employeeid,dateid");
			in1.setColumn("*");
			in1.refresh();
			while (in1.next()) {
				//MyLog.debug(this, "*docdate--->"+in1.getString("docdate"));
				//this.setHourD(in1.getString("docdate"),in1.getString("time0id"));
				//lt += Double.valueOf(in1.getString("lt")).doubleValue();
				for (int i = 1; i <= 10; i++) {
					if (i == 10) {
						if (in1.getString("lv_type").equals(this.hm_data.get("id_col10"))) {
							lv = fs.DhmToM(this.hm_data.get("lv_col10" + i).toString());
							lv += fs.Tm_To_Min(Double.valueOf(in1.getString("m_lv")).doubleValue());
							tlv = fs.MTODhm(lv, hr);
							this.hm_data.put("lv_col10", tlv);
							MyLog.debug(this, "lv_data----> "+ this.hm_data.get("id_col10") + " >"+ this.hm_data.get("lv_col10"));
						}
						continue;
					}
					//  MyLog.debug(this, "id_col"+i+"--->"+this.hm_data.get("id_col0"+i)+"<>"+in1.getString("eventgrp"));
					if (in1.getString("lv_type").equals(this.hm_data.get("id_col0" + i))) {
						//  MyLog.debug(this, "<-------------if-------------->");
						lv = fs.DhmToM(this.hm_data.get("lv_col0" + i).toString());
						lv1 = fs.Tm_To_Min(Double.valueOf(in1.getString("m_lv")).doubleValue());
						lvSum = lv + lv1;
						tlv = fs.MTODhm(lvSum, hr);
						this.hm_data.put("lv_col0" + i, tlv);
						rec += 1;
						//MyLog.debug(this, ">>>>>>>>>>lv_col0"+i+"<<<<<<<<<<<<<  "+tlv+"  hr-> "+hr);
						//MyLog.debug(this, "lv start  --> "+lv+" + "+lv1+" --> "+lvSum);
						//MyLog.debug(this, "lv_data   --> "+this.hm_data.get("lv_col0"+i)+" + "+in1.getString("lv")+" -->"+this.hm_data.get("lv_col0"+i));
					}
				}
				lv = 0;
			}
			startD = cs1.getDD() + "/" + cs1.getMM() + "/"+ String.valueOf(cs1.getYear());
			endD = cs2.getDD() + "/" + cs2.getMM() + "/"+ String.valueOf(cs2.getYear());
			//this.hm_data.put("lt_col",new Double(lt));
			this.hm_data.put("rec_col", new Integer(rec));
			this.hm_data.put("startd", startD);
			this.hm_data.put("endd", endD);
		} catch (Exception e) {
			MyLog.error(this, e);
		}
	}

	public void setSubData() {
		//  MyLog.debug(this, "<-------------------subData------------------->");
		String dhm;
		int sub = 0;
		//  MyLog.debug(this, "count----->"+count);
		FormulaString fs = new FormulaString();
		for (int i = 1; i <= count; i++) {
			if (i == 10) {
				//sub=fs.DhmToM(this.hm_data.get("limit_col10").toString(),hr);
				//sub-=fs.DhmToM(this.hm_data.get("lv_col10").toString(),hr);
				//this.hm_data.put("total_col10",fs.MTODhm(sub,hr));
				dhm = fs.subDhm(this.hm_data.get("limit_col10").toString(),this.hm_data.get("lv_col10").toString(), this.hr);
				this.hm_data.put("total_col10", dhm);
				//MyLog.debug(this, "total_col10--->"+this.hm_data.get("total_col10"));
				continue;
			}
			//sub=fs.DhmToM(this.hm_data.get("limit_col0"+i).toString(),hr);
			//sub-=fs.DhmToM(this.hm_data.get("lv_col0"+i).toString(),hr);
			//this.hm_data.put("total_col0"+i,fs.MTODhm(sub,hr));
			dhm = fs.subDhm(this.hm_data.get("limit_col0" + i).toString(),this.hm_data.get("lv_col0" + i).toString(), this.hr);
			this.hm_data.put("total_col0" + i, dhm);
			//MyLog.debug(this, "total_col0"+i+"--->"+this.hm_data.get("total_col0"+i));

		}
	}

	private String lToL(String a) {
		String dt = "";
		FormulaString fs = new FormulaString();
		if (a.indexOf(":") > -1) {
			dt = fs.MTODhm(fs.DhmToM(a, hr), hr);
		} else {
			dt = a + ":00:00";
		}
		return dt;
	}

	private void getHour_Day() {
		try {
			DbInquiry inq1 = new InitialInquiry(this.getUProfile()).getDbInquiry();
			inq1.initMyTable("mtime0", "", "");
			inq1.setColumn("time0id,companyid,edesc,tdesc,hour_d");
			inq1.refresh();

			DbInquiry inq = new InitialInquiry(this.getUProfile()).getDbInquiry();
			inq.initMyTable("memployee", "", "");
			inq.setColumn("employeeid,companyid,time0");
			inq.setFilter("employeeid='" + this.employeeid + "'");
			inq.putChild(inq1);
			inq.refresh();
			inq.next();
			this.hr = Double.valueOf(inq.getString("mtime0", "hour_d")).doubleValue();
			//	MyLog.debug(this, "hour_d------->>>" + this.hr);
		} catch (Exception e) {
			MyLog.error(this, e);

		}
	}

	public String getString(String field) {
		if (this.hm_data.containsKey(field)) {
			return this.hm_data.get(field).toString();
		} else {
			return super.getString(field);
		}
	}

}