private void onOK() { try { if (!updateModel()) return; ShiftDAO dao = new ShiftDAO(); if (shift.getId() == null && dao.exists(shift.getName())) { POSMessageDialog.showError(this, com.floreantpos.POSConstants.SHIFT_NAME_ALREADY_EXISTS); return; } dao.saveOrUpdate(shift); setCanceled(false); dispose(); } catch (Exception e) { POSMessageDialog.showError(this, com.floreantpos.POSConstants.ERROR_SAVING_SHIFT_STATE, e); } }
public boolean updateModel() { if (!calculateShifts()) return false; if (shift == null) { shift = new Shift(); } shift.setName(tfShiftName.getText()); shift.setStartTime(shiftStart); shift.setEndTime(shiftEnd); Calendar c = Calendar.getInstance(); c.setTime(shiftStart); long length = Math.abs(shiftStart.getTime() - shiftEnd.getTime()); shift.setShiftLength(Long.valueOf(length)); return true; }
public void updateView() { if (shift == null) { return; } tfShiftName.setText(shift.getName()); Date startTime = shift.getStartTime(); Date endTime = shift.getEndTime(); Calendar c = Calendar.getInstance(); c.setTime(startTime); startHour.setSelectedIndex(c.get(Calendar.HOUR) - 1); startMin.setSelectedIndex(c.get(Calendar.MINUTE)); startAmPm.setSelectedIndex(c.get(Calendar.AM_PM) == Calendar.AM ? 0 : 1); c.setTime(endTime); endHour.setSelectedIndex(c.get(Calendar.HOUR) - 1); endMin.setSelectedIndex(c.get(Calendar.MINUTE)); endAmPm.setSelectedIndex(c.get(Calendar.AM_PM) == Calendar.AM ? 0 : 1); }
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); } }
public static Shift getCurrentShift() { Calendar calendar = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.HOUR, calendar2.get(Calendar.HOUR)); calendar.set(Calendar.MINUTE, calendar2.get(Calendar.MINUTE)); calendar.set(Calendar.AM_PM, calendar2.get(Calendar.AM_PM)); Date currentTime = calendar.getTime(); ShiftDAO shiftDAO = new ShiftDAO(); List<Shift> shifts = shiftDAO.findAll(); for (Shift shift : shifts) { Date startTime = new Date(shift.getStartTime().getTime()); Date endTime = new Date(shift.getEndTime().getTime()); if (currentTime.after(startTime) && currentTime.before(endTime)) { return shift; } } calendar.add(Calendar.DATE, 1); currentTime = calendar.getTime(); for (Shift shift : shifts) { Date startTime = new Date(shift.getStartTime().getTime()); Date endTime = new Date(shift.getEndTime().getTime()); if (currentTime.after(startTime) && currentTime.before(endTime)) { return shift; } } return null; }