Ejemplo n.º 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);
    }
  }
  public void settleTicket(Ticket ticket, PosTransaction transaction) throws Exception {
    Application application = Application.getInstance();
    User currentUser = Application.getCurrentUser();
    Terminal terminal = application.refreshAndGetTerminal();

    Session session = null;
    Transaction tx = null;

    GenericDAO dao = new GenericDAO();

    try {
      Date currentDate = new Date();

      session = dao.createNewSession();
      tx = session.beginTransaction();

      ticket.setVoided(false);
      ticket.setDrawerResetted(false);
      ticket.setTerminal(terminal);
      ticket.setPaidAmount(ticket.getPaidAmount() + transaction.getAmount());

      ticket.calculatePrice();

      if (ticket.getDueAmount() == 0.0) {
        ticket.setPaid(true);
        closeTicketIfApplicable(ticket, currentDate);
      } else {
        ticket.setPaid(false);
        ticket.setClosed(false);
      }

      transaction.setTransactionType(TransactionType.CREDIT.name());
      // transaction.setPaymentType(transaction.getPaymentType());
      transaction.setTerminal(terminal);
      transaction.setUser(currentUser);
      transaction.setTransactionTime(currentDate);

      ticket.addTotransactions(transaction);

      if (ticket.getType() == OrderType.BAR_TAB) {
        ticket.removeProperty(Ticket.PROPERTY_PAYMENT_METHOD);
        ticket.removeProperty(Ticket.PROPERTY_CARD_NAME);
        ticket.removeProperty(Ticket.PROPERTY_CARD_TRANSACTION_ID);
        ticket.removeProperty(Ticket.PROPERTY_CARD_TRACKS);
        ticket.removeProperty(Ticket.PROPERTY_CARD_READER);
        ticket.removeProperty(Ticket.PROPERTY_ADVANCE_PAYMENT);
        ticket.removeProperty(Ticket.PROPERTY_CARD_NUMBER);
        ticket.removeProperty(Ticket.PROPERTY_CARD_EXP_YEAR);
        ticket.removeProperty(Ticket.PROPERTY_CARD_EXP_MONTH);
        ticket.removeProperty(Ticket.PROPERTY_CARD_AUTH_CODE);
      }

      adjustTerminalBalance(transaction);

      session.update(terminal);
      // session.saveOrUpdate(ticket);
      TicketDAO.getInstance().saveOrUpdate(ticket, session);

      //				User assignedDriver = ticket.getAssignedDriver();
      //				if(assignedDriver != null) {
      //					assignedDriver.setAvailableForDelivery(true);
      //					UserDAO.getInstance().saveOrUpdate(assignedDriver, session);
      //				}

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

    //			SETTLE ACTION
    String actionMessage =
        com.floreantpos.POSConstants.RECEIPT_REPORT_TICKET_NO_LABEL
            + ":"
            + ticket.getId(); // $NON-NLS-1$
    actionMessage +=
        ";"
            + com.floreantpos.POSConstants.TOTAL
            + ":"
            + NumberUtil.formatNumber(ticket.getTotalAmount()); // $NON-NLS-1$ //$NON-NLS-2$
    ActionHistoryDAO.getInstance()
        .saveHistory(Application.getCurrentUser(), ActionHistory.SETTLE_CHECK, actionMessage);
  }