private void doSplitTicket() {
    try {
      Ticket selectedTicket = getFirstSelectedTicket();

      if (selectedTicket == null) {
        return;
      }

      if (!selectedTicket.getTotalAmount().equals(selectedTicket.getDueAmount())) {
        POSMessageDialog.showMessage(POSConstants.PARTIAL_PAID_VOID_ERROR);
        return;
      }

      // initialize the ticket.
      Ticket ticket = TicketDAO.getInstance().loadFullTicket(selectedTicket.getId());

      SplitTicketDialog dialog = new SplitTicketDialog();
      dialog.setTicket(ticket);
      dialog.open();

      updateView();
    } catch (Exception e) {
      POSMessageDialog.showError(POSConstants.ERROR_MESSAGE, e);
    }
  }
  private void doVoidTicket() {
    try {
      Ticket selectedTicket = getFirstSelectedTicket();

      if (selectedTicket == null) {
        return;
      }

      if (!selectedTicket.getTotalAmount().equals(selectedTicket.getDueAmount())) {
        POSMessageDialog.showMessage(POSConstants.PARTIAL_PAID_VOID_ERROR);
        return;
      }

      Ticket ticketToVoid = TicketDAO.getInstance().loadFullTicket(selectedTicket.getId());

      VoidTicketDialog voidTicketDialog = new VoidTicketDialog(Application.getPosWindow(), true);
      voidTicketDialog.setTicket(ticketToVoid);
      voidTicketDialog.open();

      if (!voidTicketDialog.isCanceled()) {
        updateView();
      }
    } catch (Exception e) {
      POSMessageDialog.showError(POSConstants.ERROR_MESSAGE, e);
    }
  }
  private List<Ticket> getSelectedTickets() {
    List<Ticket> selectedTickets = openTicketList.getSelectedTickets();

    if (selectedTickets.size() == 0) {
      POSMessageDialog.showMessage("Silahkan pilih sedikitnya satu tiket");
      return null;
    }

    return selectedTickets;
  }
  private Ticket getFirstSelectedTicket() {
    List<Ticket> selectedTickets = openTicketList.getSelectedTickets();

    if (selectedTickets.size() == 0 || selectedTickets.size() > 1) {
      POSMessageDialog.showMessage("Silahkan pilih tiket");
      return null;
    }

    return selectedTickets.get(0);
  }
  private void editTicket(Ticket ticket) {
    if (ticket.isPaid()) {
      POSMessageDialog.showMessage("Tiket yang sudah terbayar tidak dapat diedit lagi");
      return;
    }

    Ticket ticketToEdit = TicketDAO.getInstance().loadFullTicket(ticket.getId());
    OrderView.getInstance().setCurrentTicket(ticketToEdit);

    RootView.getInstance().showView(OrderView.VIEW_NAME);
  }
  private void doEditTicket() {
    List<Ticket> selectedTickets = openTicketList.getSelectedTickets();
    if (selectedTickets.size() == 0 || selectedTickets.size() > 1) {
      POSMessageDialog.showMessage(POSConstants.SELECT_ONE_TICKET_TO_EDIT);
      return;
    }

    Ticket ticket = selectedTickets.get(0);

    editTicket(ticket);
  }
  private void doSettleTicket() {
    try {

      List<Ticket> selectedTickets = openTicketList.getSelectedTickets();
      if (selectedTickets.size() == 0 || selectedTickets.size() > 1) {
        POSMessageDialog.showMessage(POSConstants.SELECT_ONE_TICKET_TO_SETTLE);
        return;
      }

      Ticket ticket = selectedTickets.get(0);

      new SettleTicketAction(ticket.getId()).execute();

      updateTicketList();

    } catch (Exception e) {
      POSMessageDialog.showError(POSConstants.ERROR_MESSAGE, e);
    }
  }
  private void doShowOrderInfo() {
    try {
      List<Ticket> selectedTickets = openTicketList.getSelectedTickets();
      if (selectedTickets.size() == 0) {
        POSMessageDialog.showMessage(POSConstants.SELECT_ONE_TICKET_TO_PRINT);
        return;
      }

      List<Ticket> ticketsToShow = new ArrayList<Ticket>();

      for (int i = 0; i < selectedTickets.size(); i++) {
        Ticket ticket = selectedTickets.get(i);
        ticketsToShow.add(TicketDAO.getInstance().loadFullTicket(ticket.getId()));
      }

      OrderInfoView view = new OrderInfoView(ticketsToShow);
      OrderInfoDialog dialog = new OrderInfoDialog(view);
      dialog.setSize(400, 600);
      dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
      dialog.setLocationRelativeTo(Application.getPosWindow());
      dialog.setVisible(true);

    } catch (Exception e) {
      e.printStackTrace();
    }

    //		Ticket ticket = selectedTickets.get(0);
    //		try {
    //			ticket = TicketDAO.getInstance().initializeTicket(ticket);
    //			ticket.calculateDefaultGratutity();
    //
    //			PosPrintService.printTicket(ticket, 0);
    //
    //			// PRINT ACTION
    //			String actionMessage = "CHK#" + ":" + ticket.getId();
    //			ActionHistoryDAO.getInstance().saveHistory(Application.getCurrentUser(),
    // ActionHistory.PRINT_CHECK, actionMessage);
    //		} catch (Exception e) {
    //			POSMessageDialog.showError(this, e.getMessage(), e);
    //		}
  }