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

import com.csc.library.utilities.MyLog;
import java.util.Vector;

import com.csc.library.process.MyProcess;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.InitialInquiry;
import com.csc.library.timeattendance.WorkingShift;
import com.csc.library.databean.Memployee_worktime;
import com.csc.library.utilities.WriteFile;
import java.util.Iterator;
import com.csc.library.timeattendance.Shift;
import com.csc.library.timeattendance.DayShift;
import com.csc.library.timeattendance.TimeUtility;
import com.csc.library.session.InitialEnvironment;

/*
 * NOT USED 2008/09/01
 */
public class GenWorkTime extends MyProcess {

  public Vector getProcessList() {
    Vector v = new Vector();
    v.addElement("All");
    return v;
  }

  public void process() throws Exception {    
    String filter = "";
    if (this.data.containsKey("__emp1")) {
      if (this.data.containsKey("__emp2")) {
        if (this.data.get("__emp2").toString().trim().equals("")) {
          filter = "employeeid='" + this.data.get("__emp1") + "'";
        } else {
          if (this.data.get("__emp1").toString().equalsIgnoreCase(this.data.get("__emp2").toString())){
            filter = "employeeid='" + this.data.get("__emp1") + "'";
          } else {
            filter = "(employeeid between '" + this.data.get("__emp1") + "' and '" + this.data.get("__emp2") + "')";
          }
        }
      }
      else {
        filter = "employeeid='" + this.data.get("__emp1") + "'";
      }
    }

    String path = new InitialEnvironment("GLOBAL").getValue("DIRUPLOAD-dir");    
    WriteFile wf = new WriteFile(path+this.data.get("__txtname")+".txt");
    DbInquiry inq = new InitialInquiry(this.upf).getDbInquiry();
    inq.setParam(this.data);
    inq.setSchemaName(this.upf.getSchemaName());
    inq.initMyTable("Memployee_worktime", filter, "");
    inq.setColumn("*");
    inq.refresh();
    while (inq.next()) {
      Memployee_worktime rec = (Memployee_worktime) inq.getCurrentDbRecord();
      WorkingShift ws = rec.getWorkingShift();
      this.setDataToFile(ws, wf, rec.getString("employeeid"));
    }
    wf.closeFile();
  }

  private void setDataToFile(WorkingShift ws, WriteFile wf, String employeeid) {
    if (!ws.isEmpty()) {
      TimeUtility tu = new TimeUtility();
      //MyLog.debug(this, "\n<<<<<<<<<<<<<<<<<<<<<<<<<< Display WorkingShift  >>>>>>>>>>>>>>>>>>>>>>>>>>>>");
      for (Iterator IT = ws.keySet().iterator(); IT.hasNext(); ) {
        String key = (String) IT.next();
        DayShift dShift = (DayShift) ws.get(key);
        for (Iterator IT1 = dShift.keySet().iterator(); IT1.hasNext(); ) {
          String key1 = (String) IT1.next();
          Shift sh = (Shift) dShift.get(key1);
          /*MyLog.debug(this, "**** Date=" + key + " **** Time=" + key1 + " **** Shift " +
                             " >>> Begin=" + sh.get_c_dt_in().getCSCTime() +
                             " >>> End=" + sh.get_c_dt_out().getCSCTime() +
                             " >>> Time Code=" + sh.getTimeCode() +
                             " >>> Type=" + sh.getTR_Type().substring(0,1) +
                             " >>> Leave=" + sh.getLv() +
                             " >>> Leave Type=" + sh.getLV_Type());*/
          wf.writeString(this.chkEmployeeLength(employeeid) +
                         key +
                         tu.getTimeFormat(String.valueOf(sh.get_c_dt_in().getCSCTime())) +
                         tu.getTimeFormat(String.valueOf(sh.get_c_dt_out().getCSCTime())) +
                         sh.getTR_Type().substring(0,1) +
                         tu.getTimeFormat(String.valueOf(sh.getLv())) +
                         sh.getLV_Type()+"\n");

        }
        //MyLog.debug(this, "---------------------------------------------------------------------------------------------------------------------------------------------------------");
      }
    }
  }

  private String chkEmployeeLength(String key) {
    //real is 15 but in piswin use 10
    String data = key;
    if (key.length() < 10) {
      int tmp = 10 - key.length();
      for (int i = 0; i < tmp; i++) {
        data = data + " ";
      }
    }
    return data;
  }

}