CalculateEmpVacation_NSTDA.java 10.9 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
package com.csc.library.process;

import java.text.DecimalFormat;
import java.util.StringTokenizer;
import java.util.Vector;

import com.csc.library.database.MyHashMap;
import com.csc.library.database.StaticConfig;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.DbRecord;
import com.csc.library.session.InitialEnvironment;
import com.csc.library.session.InitialInquiry;
import com.csc.library.session.InitialRecord;
import com.csc.library.utilities.CountAge;
import com.csc.library.utilities.CscCalendar;
import com.csc.library.utilities.CscTime;
import com.csc.library.utilities.MyLog;
import com.csc.library.utilities.ReadFile;

/*
 * ѺӹdzԷҾѡ͹ͧѡҹ 
 * Ңѹӡ觻ż ѡҹԷҾѡ͹ѹ
 * ͧ Ƿ 
 */
public class CalculateEmpVacation_NSTDA extends CalulateEmpVacation {

	private CscCalendar sDate = null;
	private CscCalendar eDate = null;
	private DecimalFormat df = new DecimalFormat("00");
	private DecimalFormat df2 = new DecimalFormat("0.0");
	private String max_vacation = "12:00:00";
	
	public Vector getProcessList() {
		Vector v = new Vector();
		try {
			this.alive("Process is Working!!");
			this.setParamData();
			String whereClause = "";
			if (!this.getParamValue("filterProcess").equals("")) {
				whereClause = this.getParamValue("filterProcess");
			}else{
				whereClause = " status in('A','B','S','V','W') " ;
				//=========== for Test ===========
				//whereClause += " and employeeid ='003814' ";
			}//end if 
		 
			DbInquiry inq = new InitialInquiry(this.upf).getDbInquiry();
			inq.setParam(this.data);
			inq.setSchemaName(this.upf.getSchemaName());
			inq.initMyTable("Memployee",whereClause, "employeeid");			
			inq.setColumn("employeeid, runno, emp_position, emp_group, branch, job, bossid, emp_level," +
				"bu1, bu2, bu3, bu4, bu5, costcenter, salatype, currency, salary, emp_every, time0, companyid," + 
				"status, startdate, resigndate, workarea, emp_type");	
			inq.setFatchAll(true);
			inq.refresh();
			while (inq.next()) {
				v.addElement(inq.getCurrentDbRecord().getString("employeeid"));
			}				
			
		} catch (Exception e) {
			MyLog.error(this, e);			
		}
		//v.addElement("All");
		return v;
	}
	
	public void process() throws Exception {
		this.vtFilter = new Vector();
	 	Vector vt = this.processList;
		if (vt==null) {
			vt = this.getProcessList();
		}else{
			this.setParamData();
		}//end if
		
		this.alive("Process is Working!!");
		String errorProcess = "";
		String v0 = ""; //ӹǹѹҾѡ͹¡
		String v1 = ""; //ӹǹѹҾѡ͹չ
		CscCalendar cs = new CscCalendar();
		
		if (this.data.containsKey("companyid")) {
			this.upf.set("companyid", (String) this.data.get("companyid"));
		}
		if (this.data.containsKey("schemaname")) {
			this.upf.setSchemaName((String) this.data.get("schemaname"));
		}
		if (this.data.containsKey("dbname")) {
			this.upf.setDbName((String) this.data.get("dbname"));
		}
		if (this.data.containsKey("appname")) {
			this.upf.set("appname", (String) this.data.get("appname"));
		}
		if (this.data.containsKey("lang")) {
			this.upf.set("lang", (String) this.data.get("lang"));
		}
		if (this.data.containsKey("date")) {
			cs = new CscCalendar((String) this.data.get("date"));
		}
		
		this.vCode = this.getVacationCode();		
		
		try {
			//this.sDate = new CscCalendar("2007-10-01");
			//this.eDate = new CscCalendar("2008-09-30");
			this.sDate = new CscCalendar((String) StaticConfig.getConfigCompany(this.upf, "TA1003"));
			this.eDate = new CscCalendar((String) StaticConfig.getConfigCompany(this.upf, "TA1004"));		
			//================= Nuiss Start Edit 24/11/2551===================
			System.out.println("[Nuiss>>>]ѹ էҳ к Table Mconfig [TA1003] : "+this.sDate.getYYYYMMDD());
			System.out.println("[Nuiss>>>]ѹش էҳ к Table Mconfig [TA1004] : "+this.eDate.getYYYYMMDD());
			//================= Nuiss End Edit ============================
		} catch (Exception e) {
			MyLog.error(this, e);			
		}		
 		
		for (int i=0;i<vt.size() && !this.isCancle();i++) {
 			String id = (String) vt.elementAt(i);
			this.alive("Process is Working!!");
			try {
				DbRecord empRec = new InitialRecord(this.upf).getDbRecord("MEMPLOYEE");
				empRec.setParam(this.data);
				empRec.setColumn("employeeid, companyid, status, emp_type, startdate, firsthiredate, resigndate, " +
						"vacationcode, vacation0, vacation1, time0");
				empRec.set("employeeid",(String) vt.elementAt(i));
				empRec.set("companyidid",this.upf.get("companyid"));

				if (empRec.search()==1) {
 	        		CscCalendar startDate = new CscCalendar(empRec.getString("startdate"));
	        		double empWorkAge = this.getEmpWorkAge(startDate, new CscCalendar()); //Ѻاҹ֧ѹӡ process	        		
    			    if (empWorkAge >= 1 && empWorkAge < 2) {
    			    	if (cs.getMonth()==this.eDate.getMonth() && cs.getDate()==this.eDate.getDate()) { //͹ش¢ͧէҳӡ¡ʹ
	        				double hourWork = this.getHourWork(empRec.getString("time0")); //Ҫ. ÷ӧҹѹ
	        				int m0 = this.util.DhmToM(empRec.getString("vacation0"), hourWork); //ʹ¡
	        				int m1 = this.util.DhmToM(empRec.getString("vacation1"), hourWork); //ԷԷ͹
	        				int m_total = m0+m1;
	        				int use = 0;
	        				CscTime ct = this.getLeaveUsed(empRec.getString("employeeid"), this.sDate, this.eDate, this.vCode); //ʹҷ
	        				use = (ct.getHour()*60)+ct.getMinute();
	        				
	        				String vacation_remain = "00:00:00";
	        				if (use<m_total) {
	        					int max_last = this.util.DhmToM(this.max_vacation, hourWork);
	        					if (max_last <= (m_total-use)) {
	        						vacation_remain = this.util.MTODhm(max_last, hourWork);
	        					} else {
	        						vacation_remain = this.util.MTODhm(m_total-use, hourWork);
	        					}
	        				} else {
	        					vacation_remain = "00:00:00";
	        				}//end if 	
	        				
	        				v1 = "12:00:00";
		        			v0 = vacation_remain;      			
	        			}else{
		              		 /**
		              		  * Author:nuiss
		              		  * Date:25/11/2551
	      	        		  * Logic:ûѴ᷹ 
	      	        		 */
	        				//ҡҧҹԹѹ 1  Է͹   ͹
	        				// nstda ҷӧҹѹ 1  16  
	        				 CountAge count = new CountAge(this.getUProfile().get("lang"));
	        				 String dateDiff = count.getCountAges(startDate,this.eDate,false);
	        				 String datePart[]  = dateDiff.split(":");
	        				 int yearCnt = Integer.valueOf(datePart[0]);
	        				 int monthCnt = Integer.valueOf(datePart[1]);
	        				 int dayCnt = Integer.valueOf(datePart[2]);
	        				 String v1DayCnt ="";
	        				 
	        				 if (yearCnt>1){
	        					 v1DayCnt ="12";
	        				 }else  if (yearCnt<=1){
	    						 if(dayCnt>1){
	    							 monthCnt+=1;
	    						 }//end if 
	    						 v1DayCnt = (String.valueOf(monthCnt).length()==1)? "0"+String.valueOf(monthCnt) :String.valueOf(monthCnt);
	        				 }//end if 
	          				 v0 =this.setVacationFormat(empRec.getString("vacation0"));
	        				 v1 = v1DayCnt+":00:00";
	        			}//end if 
	         		} else if (empWorkAge >= 2) {
	        			if (cs.getMonth()==this.eDate.getMonth() && cs.getDate()==this.eDate.getDate()) { //͹ش¢ͧէҳӡ¡ʹ
	        				double hourWork = this.getHourWork(empRec.getString("time0")); //Ҫ. ÷ӧҹѹ
	        				int m0 = this.util.DhmToM(empRec.getString("vacation0"), hourWork); //ʹ¡
	        				int m1 = this.util.DhmToM(empRec.getString("vacation1"), hourWork); //ԷԷ͹
	        				int m_total = m0+m1;
	        				int use = 0;
	        				CscTime ct = this.getLeaveUsed(empRec.getString("employeeid"), this.sDate, this.eDate, this.vCode); //ʹҷ
	        				use = (ct.getHour()*60)+ct.getMinute();
	        				
	        				String vacation_remain = "00:00:00";
	        				if (use<m_total) {
	        					int max_last = this.util.DhmToM(this.max_vacation, hourWork);
	        					if (max_last <= (m_total-use)) {
	        						vacation_remain = this.util.MTODhm(max_last, hourWork);
	        					} else {
	        						vacation_remain = this.util.MTODhm(m_total-use, hourWork);
	        					}
	        				} else {
	        					vacation_remain = "00:00:00";
	        				}//end if 	
	        				
	        				v1 = "12:00:00";
		        			v0 = vacation_remain;      			
	        			} else {
	        				//ѧ͹ش¢ͧէҳ ͧӹdzʹ
	        				v1 = "12:00:00";
		        			v0 = this.setVacationFormat(empRec.getString("vacation0"));
	        			}//end if 
	        		} else {
	        			//اҹ֧ 1 
	        			v1 = "00:00:00";
	        			v0 = "00:00:00";		
	        		}//end if 
	        		System.out.println("------------------------CalculateEmpVacation_NSTDA--------------------------");
    			    System.out.println("fieldsList is:"+empRec.getArrayFieldList());
	        		System.out.println("Emp Code : "+empRec.getString("employeeid"));
	        		System.out.println("WorkStart Date : "+empRec.getString("startdate")); 
	        		System.out.println("Today Work Age is: : "+empWorkAge);
	        		System.out.println("Vacation0 Before calculate is: "+empRec.getString("vacation0"));
	        		System.out.println("Vacation1 Before calculate is: "+empRec.getString("vacation1"));
	        		System.out.println("Vacation0 After calculate is: "+v0);
	        		System.out.println("Vacation1 After calculate is: "+v1);
	        		System.out.println("------------------------CalculateEmpVacation_NSTDA--------------------------");
	        		
	        		empRec.set("vacation0", v0);
	        		empRec.set("vacation1", v1);
	        		
	        		System.out.print("at class CalculateEmpVacation_NSTDA before Save fields list is : "+empRec.getArrayFieldList());
	        		empRec.save();
				}
	        			              
			} catch (Exception e) {
        		MyLog.error(this, e);     
        		errorProcess += id+",";
        	}
		}
	}
	
	private String setVacationFormat(String strData){
		String correctDataFormat ="";
		if(strData.equals("")){
			correctDataFormat = "00:00:00";
		}else if (strData.split(":").length==3){
			correctDataFormat = strData;
 		}else{
 			String splDay0[] =new String[3] ;
			String splTmpDay0[] = strData.split(":");
			System.arraycopy(splTmpDay0, 0, splDay0, 0,splTmpDay0.length);
		
			for (int ii =0 ;ii<3;ii++){
				if(splDay0[ii]==null){
	 				splDay0[ii]="00";
	 			}//end if 
			}//end if 
			correctDataFormat = splDay0[0]+":"+splDay0[1]+":"+splDay0[2];
		}//end if 
		return correctDataFormat;
	}//end method setVacationFormat
	
}//end class