public void refundTicket(Ticket ticket, final double refundAmount) throws Exception { User currentUser = Application.getCurrentUser(); Terminal terminal = ticket.getTerminal(); Session session = null; Transaction tx = null; GenericDAO dao = new GenericDAO(); try { Double currentBalance = terminal.getCurrentBalance(); Double totalPrice = ticket.getTotalAmount(); double newBalance = currentBalance - totalPrice; terminal.setCurrentBalance(newBalance); // double refundAmount = ticket.getPaidAmount(); // if(ticket.getGratuity() != null) { // refundAmount -= ticket.getGratuity().getAmount(); // } RefundTransaction posTransaction = new RefundTransaction(); posTransaction.setTicket(ticket); posTransaction.setPaymentType(PaymentType.CASH.name()); posTransaction.setTransactionType(TransactionType.DEBIT.name()); posTransaction.setAmount(refundAmount); posTransaction.setTerminal(terminal); posTransaction.setUser(currentUser); posTransaction.setTransactionTime(new Date()); ticket.setVoided(false); ticket.setRefunded(true); ticket.setClosed(true); ticket.setDrawerResetted(false); ticket.setClosingDate(new Date()); ticket.addTotransactions(posTransaction); session = dao.getSession(); tx = session.beginTransaction(); dao.saveOrUpdate(ticket, session); tx.commit(); // String title = "- REFUND RECEIPT -"; // String data = "Ticket #" + ticket.getId() + ", amount " + refundAmount + " was refunded."; ReceiptPrintService.printRefundTicket(ticket, posTransaction); } catch (Exception e) { try { tx.rollback(); } catch (Exception x) { } throw e; } finally { dao.closeSession(session); } }
public static void adjustTerminalBalance(PosTransaction transaction) { Terminal terminal = transaction.getTerminal(); if (transaction instanceof CashTransaction) { double currentBalance = terminal.getCurrentBalance(); double newBalance = currentBalance + transaction.getAmount(); terminal.setCurrentBalance(newBalance); } else if (transaction instanceof GiftCertificateTransaction) { double currentBalance = terminal.getCurrentBalance(); double newBalance = currentBalance - transaction.getGiftCertCashBackAmount(); terminal.setCurrentBalance(newBalance); } else if (transaction instanceof VoidTransaction) { double currentBalance = terminal.getCurrentBalance(); double newBalance = currentBalance - transaction.getAmount(); terminal.setCurrentBalance(newBalance); } }