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); } }
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); }