Exemplo n.º 1
0
  private void reClockInUser(Calendar currentTime, User user, Shift currentShift) {
    POSMessageDialog.showMessage("You will be clocked out from previous Shift");

    Application application = Application.getInstance();
    AttendenceHistoryDAO attendenceHistoryDAO = new AttendenceHistoryDAO();

    AttendenceHistory attendenceHistory = attendenceHistoryDAO.findHistoryByClockedInTime(user);
    if (attendenceHistory == null) {
      attendenceHistory = new AttendenceHistory();
      Date lastClockInTime = user.getLastClockInTime();
      Calendar c = Calendar.getInstance();
      c.setTime(lastClockInTime);
      attendenceHistory.setClockInTime(lastClockInTime);
      attendenceHistory.setClockInHour(Short.valueOf((short) c.get(Calendar.HOUR)));
      attendenceHistory.setUser(user);
      attendenceHistory.setTerminal(application.getTerminal());
      attendenceHistory.setShift(user.getCurrentShift());
    }

    user.doClockOut(attendenceHistory, currentShift, currentTime);

    user.doClockIn(application.getTerminal(), currentShift, currentTime);
  }
  private void doClockOut() {
    int option =
        JOptionPane.showOptionDialog(
            this,
            POSConstants.CONFIRM_CLOCK_OUT,
            POSConstants.CONFIRM,
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            null,
            null);
    if (option != JOptionPane.YES_OPTION) {
      return;
    }

    User user = Application.getCurrentUser();
    AttendenceHistoryDAO attendenceHistoryDAO = new AttendenceHistoryDAO();
    AttendenceHistory attendenceHistory = attendenceHistoryDAO.findHistoryByClockedInTime(user);
    if (attendenceHistory == null) {
      attendenceHistory = new AttendenceHistory();
      Date lastClockInTime = user.getLastClockInTime();
      Calendar c = Calendar.getInstance();
      c.setTime(lastClockInTime);
      attendenceHistory.setClockInTime(lastClockInTime);
      attendenceHistory.setClockInHour((short) c.get(Calendar.HOUR));
      attendenceHistory.setUser(user);
      attendenceHistory.setTerminal(Application.getInstance().getTerminal());
      attendenceHistory.setShift(user.getCurrentShift());
    }

    Shift shift = user.getCurrentShift();
    Calendar calendar = Calendar.getInstance();

    user.doClockOut(attendenceHistory, shift, calendar);

    Application.getInstance().logout();
  }
Exemplo n.º 3
0
  private void adjustUserShift(User user, Shift currentShift) {
    Application application = Application.getInstance();
    Calendar currentTime = Calendar.getInstance();

    if (user.isClockedIn() != null && user.isClockedIn().booleanValue()) {
      Shift userShift = user.getCurrentShift();
      Date userLastClockInTime = user.getLastClockInTime();
      long elaspedTimeSinceLastLogin =
          Math.abs(currentTime.getTimeInMillis() - userLastClockInTime.getTime());

      if (userShift != null) {
        if (!userShift.equals(currentShift)) {
          reClockInUser(currentTime, user, currentShift);
        } else if (userShift.getShiftLength() != null
            && (elaspedTimeSinceLastLogin >= userShift.getShiftLength())) {
          reClockInUser(currentTime, user, currentShift);
        }
      } else {
        user.doClockIn(application.getTerminal(), currentShift, currentTime);
      }
    } else {
      user.doClockIn(application.getTerminal(), currentShift, currentTime);
    }
  }