public void updateTicketList() {
    User user = Application.getCurrentUser();

    TicketDAO dao = TicketDAO.getInstance();
    List<Ticket> openTickets;

    boolean showAllOpenTicket = false;
    if (user.getNewUserType() != null) {
      Set<UserPermission> permissions = user.getNewUserType().getPermissions();
      if (permissions != null) {
        for (UserPermission permission : permissions) {
          if (permission.equals(UserPermission.VIEW_ALL_OPEN_TICKET)) {
            showAllOpenTicket = true;
            break;
          }
        }
      }
    }

    if (showAllOpenTicket) {
      openTickets = dao.findOpenTickets();
    } else {
      openTickets = dao.findOpenTicketsForUser(user);
    }
    openTicketList.setTickets(openTickets);

    lblUserName.setText(
        POSConstants.WELCOME
            + " "
            + user.toString()
            + ". "
            + POSConstants.YOU
            + " "
            + POSConstants.HAVE
            + " "
            + openTickets.size()
            + " "
            + POSConstants.TICKETS);
  }
  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();
  }
  public void updateView() {
    User user = Application.getCurrentUser();
    UserType userType = user.getNewUserType();
    if (userType != null) {
      Set<UserPermission> permissions = userType.getPermissions();
      if (permissions != null) {
        btnNewTicket.setEnabled(false);
        btnBackOffice.setEnabled(false);
        btnEditTicket.setEnabled(false);

        if (!"false".equalsIgnoreCase(AppConfig.getFeatureGroupTicketFlag())) {
          btnGroupSettle.setEnabled(false);
        }

        if (!"false".equalsIgnoreCase(AppConfig.getManagerMenuFlag())) {
          btnManager.setEnabled(false);
        }

        if (!"false".equalsIgnoreCase(AppConfig.getFeaturePenarikanFlag())) {
          btnPayout.setEnabled(false);
        }

        btnReopenTicket.setEnabled(false);
        btnSettleTicket.setEnabled(false);

        if (!"false".equalsIgnoreCase(AppConfig.getFeatureSplitTicketFlag())) {
          btnSplitTicket.setEnabled(false);
        }

        btnTakeout.setEnabled(false);
        btnVoidTicket.setEnabled(false);

        for (UserPermission permission : permissions) {
          if (permission.equals(UserPermission.VOID_TICKET)) {
            btnVoidTicket.setEnabled(true);
          } else if (permission.equals(UserPermission.PAY_OUT)) {
            if (!"false".equalsIgnoreCase(AppConfig.getFeaturePenarikanFlag())) {
              btnPayout.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.SETTLE_TICKET)) {
            btnSettleTicket.setEnabled(true);
            if (!"false".equalsIgnoreCase(AppConfig.getFeatureGroupTicketFlag())) {
              btnGroupSettle.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.REOPEN_TICKET)) {
            btnReopenTicket.setEnabled(true);
          } else if (permission.equals(UserPermission.PERFORM_MANAGER_TASK)) {
            if (!"false".equalsIgnoreCase(AppConfig.getManagerMenuFlag())) {
              btnManager.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.SPLIT_TICKET)) {
            if (!"false".equalsIgnoreCase(AppConfig.getFeatureSplitTicketFlag())) {
              btnSplitTicket.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.TAKE_OUT)) {
            btnTakeout.setEnabled(true);
          } else if (permission.equals(UserPermission.VIEW_BACK_OFFICE)) {
            btnBackOffice.setEnabled(true);
          }
          //                    else if (permission.equals(UserPermission.PAY_OUT)) {
          //                        btnPayout.setEnabled(true);
          //                    }
          else if (permission.equals(UserPermission.EDIT_TICKET)) {
            btnEditTicket.setEnabled(true);
          } else if (permission.equals(UserPermission.CREATE_NEW_TICKET)) {
            btnNewTicket.setEnabled(true);
          }
        }
      }
    }

    updateTicketList();
  }