Example #1
0
  public void voidTicket(Ticket ticket) throws Exception {
    Session session = null;
    Transaction tx = null;

    try {
      session = createNewSession();
      tx = session.beginTransaction();

      Terminal terminal = Application.getInstance().getTerminal();

      ticket.setVoided(true);
      ticket.setClosed(true);
      ticket.setClosingDate(new Date());
      ticket.setTerminal(terminal);

      if (ticket.isPaid()) {
        VoidTransaction transaction = new VoidTransaction();
        transaction.setTicket(ticket);
        transaction.setTerminal(terminal);
        transaction.setTransactionTime(new Date());
        transaction.setTransactionType(TransactionType.DEBIT.name());
        transaction.setPaymentType(PaymentType.CASH.name());
        transaction.setAmount(ticket.getPaidAmount());
        transaction.setTerminal(Application.getInstance().getTerminal());
        transaction.setCaptured(true);

        PosTransactionService.adjustTerminalBalance(transaction);

        ticket.addTotransactions(transaction);
      }

      session.update(ticket);
      session.update(terminal);

      session.flush();
      tx.commit();
    } catch (Exception x) {
      try {
        tx.rollback();
      } catch (Exception e) {
      }
      throw x;
    } finally {
      closeSession(session);
    }
  }