Tforgetcard_nstda.java 6.43 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
package com.csc.library.databean;

import java.text.DecimalFormat;
import java.util.Iterator;

import com.csc.library.timeattendance.DayShift;
import com.csc.library.timeattendance.Shift;
import com.csc.library.timeattendance.TimeZone;
import com.csc.library.timeattendance.WorkingShift;
import com.csc.library.utilities.MyLog;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.DbRecord;
import com.csc.library.session.InitialInquiry;
import com.csc.library.session.InitialRecord;
import com.csc.library.session.RecordCmp;
import com.csc.library.utilities.CscCalendar;

public class Tforgetcard_nstda extends RecordCmp {
	
    private DecimalFormat df = new DecimalFormat("#0.00");
    
	public Tforgetcard_nstda() {
		super("Tforgetcard_nstda", "Tforgetcard_nstda Table");
	}	
	
	protected void postInsertTrigger() throws Exception {
		super.postInsertTrigger();
		if (this.getString("wf_status").equalsIgnoreCase("4") || this.getString("wf_status").equalsIgnoreCase("6")) {
			this.setNewData();
		} else if (this.getString("wf_status").equalsIgnoreCase("8") || this.getString("wf_status").equalsIgnoreCase("9")) {
			this.delOldData();
		}
	}

	protected void postUpdateTrigger() throws Exception {
		super.postUpdateTrigger();
		if (this.getString("wf_status").equalsIgnoreCase("4") || this.getString("wf_status").equalsIgnoreCase("6")) {
			this.setNewData();
		} else if (this.getString("wf_status").equalsIgnoreCase("8") || this.getString("wf_status").equalsIgnoreCase("9")) {
			this.delOldData();
		}
	}
	
	protected void postDeleteTrigger() throws Exception {		
		super.postDeleteTrigger();
		this.delOldData();
	}
	
	private void setNewData() {
		try {		
			String time0id="";
			DbInquiry inq = new InitialInquiry(this.userPro).getDbInquiry();
			inq.setParam(this.param);
			inq.setSchemaName(this.userPro.getSchemaName());
			inq.initMyTable("Memployee", " employeeid='"+this.getString("employeeid")+"'", "");			
			inq.setColumn("employeeid, time0, companyid, status, startdate, resigndate");
			inq.refresh();
			while (inq.next()) {
				time0id = inq.getString("time0");
			}
			
			DbRecord rec = new InitialRecord(this.userPro).getDbRecord("Ttimetemp");
			for (int i=1; i<=10; i++) {
				rec.clearField();
				if (!this.getString("FGDATE"+i).equals("") && 
						!this.getString("FGTIME"+i).equals("") && 
						!this.getString("FGCAUSE"+i).equals("")) {					
					rec.setColumn("*");
					rec.set("COMPANYID", this.getString("COMPANYID"));			
					rec.set("EMPLOYEEID", this.getString("EMPLOYEEID"));		
					rec.set("SWIPEDATE", this.getString("FGDATE"+i));
					rec.set("SWIPETIME", this.getString("FGTIME"+i));
					rec.set("SWIPETYPE", this.getString("FGTYPE"));					
					rec.set("SOURCE", "0");				
					rec.set("TIME0ID", time0id);
					rec.save();
				}				
			}
						
		} catch (Exception e) {
			MyLog.error(this, e);
			
						
		}		
	}
	
	private void delOldData() {	
		try {
			for (int i=1; i<=10; i++) {
				CscCalendar csc = new CscCalendar(this.getString("FORGET_DATE"));
				String filter = " employeeid='"+this.getString("EMPLOYEEID")+"' " +
						"and swipedate='"+csc.getYYYYMMDD()+"' " +
						"and swipetime="+this.getDouble("FORGET_TIME");				
				DbInquiry inq = new InitialInquiry(this.userPro).getDbInquiry();
				inq.setParam(this.param);
				inq.setSchemaName(this.userPro.getSchemaName());
				inq.initMyTable("Ttimetemp", filter , "");			
				inq.setColumn("SWIPEDATE, EMPLOYEEID, SWIPETIME, COMPANYID");
				inq.refresh();
				while (inq.next()) {				
					DbRecord rec = inq.getCurrentDbRecord().cloneRecord(true);
					rec.delete();
				}						
			} 
		} catch (Exception e) {
			MyLog.error(this, e);
		}
	}
	/**
	 * @author PipoXP
	 * @param empCode
	 * @param date
	 * @return start_time (ҷͧӧҹ)
	 */
    public String getWorkingTime(String empCode, String date){
        float start_time = 0;
        try{
            DbInquiry inqEmp = new InitialInquiry(this.getUProfile()).getDbInquiry();
            //inqEmp.setParam(this.param);
            inqEmp.setSchemaName(this.getUProfile().getSchemaName());
            inqEmp.initMyTable("Memployee", "employeeid='"  + empCode + "'", "");
            inqEmp.setColumn("employeeid, time0,companyid, status, startdate, resigndate");
            inqEmp.refresh();
            while (inqEmp.next()) {
                Mtime0 rec = (Mtime0) new InitialRecord(this.getUProfile()).getDbRecord("Mtime0");
                rec.set("time0id", inqEmp.getString("time0"));
                rec.set("companyid", this.getUProfile().get("companyid"));
                rec.search();
    
                CscCalendar cs1 = new CscCalendar(date);
                                    
                rec.setEmpRec(inqEmp.getCurrentDbRecord().cloneRecord(false));
                MyLog.debug(this, ">>>>>> DATE TO PROCESS >>>>>> date="
                                + cs1.getYYYYMMDD());
                WorkingShift ws = rec.genWorkingShift(new CscCalendar(cs1.getYYYYMMDD()), 
                        new CscCalendar(cs1.getYYYYMMDD()), "true");             
                if (!ws.isEmpty()) {
                    ws.setUProfile(this.getUProfile());
                    ws.setEmployeeid(inqEmp.getString("employeeid"));
                    //ws.adjustLeave();
                    ws.overlapChecking();
                    ws.createLink();
                    int i= 0;
                    
                    Iterator it = (Iterator) ws.keySet().iterator(); 
                    if (it.hasNext()) {
                        i++;
                        DayShift ds = (DayShift) ws.get(it.next());
                        int ds_size = ds.size();
                        Iterator it_ds = (Iterator) ds.keySet().iterator();
                        if (it_ds.hasNext()) {
                            Shift sh = (Shift) ds.get((String) it_ds.next());
                            if (sh!=null) {
                                TimeZone tz = sh.getMidDayStop();
                                CscCalendar cs = tz.getBeginZone();
                                start_time = sh.get_c_dt_in().getCSCTime();
                            }
                        }
                    }      
                }
            } //End Check Leave Haft Day
        } catch (Exception e) {
            MyLog.error(this, e);           
        }
        return df.format(start_time);     
    }	
}