Esempio n. 1
0
    public Object getValueAt(int rowIndex, int columnIndex) {
      Ticket ticket = (Ticket) rows.get(rowIndex);

      switch (columnIndex) {
        case 0:
          return Integer.valueOf(ticket.getId());

        case 1:
          return Integer.valueOf(ticket.getTableNumber());

        case 2:
          return String.valueOf(ticket.getOwner());

        case 3:
          return ticket.getCreateDate();

        case 4:
          return ticket.getTotalAmount();

        case 5:
          return ticket.getDueAmount();
      }

      return null;
    }
  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 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);
    }
  }
  protected void doCloseOrder() {
    Ticket ticket = getFirstSelectedTicket();

    if (orderServiceExtension.finishOrder(ticket.getId())) {
      updateTicketList();
    }
  }
  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);
  }
Esempio n. 6
0
  @Override
  public void captureAuthAmount(PosTransaction transaction) throws Exception {
    String xml =
        StreamUtils.toString(
            MercuryPayProcessor.class.getResourceAsStream(
                "/com/mercurypay/ws/sdk/mercuryPreAuthCapture.xml")); //$NON-NLS-1$
    Ticket ticket = transaction.getTicket();

    // String merchantId = "118725340908147";
    String laneId = "01"; // $NON-NLS-1$
    String invoiceNo = String.valueOf(ticket.getId());
    String amount = String.valueOf(transaction.getAmount());

    xml = xml.replace($merchantId, CardConfig.getMerchantAccount());
    xml = xml.replace($laneId, laneId);
    xml = xml.replace($invoiceNo, invoiceNo);
    xml = xml.replace($refNo, invoiceNo);
    xml = xml.replace($amount, amount);
    xml = xml.replace($authorizeAmount, amount);
    xml = xml.replace("$gratuity", String.valueOf(transaction.getTipsAmount())); // $NON-NLS-1$
    xml = xml.replace("$recordNo", transaction.getCardTransactionId()); // $NON-NLS-1$
    xml = xml.replace("$authCode", transaction.getCardAuthCode()); // $NON-NLS-1$
    xml =
        xml.replace(
            "$AcqRefData", transaction.getProperty("AcqRefData")); // $NON-NLS-1$ //$NON-NLS-2$

    //		System.out.println(xml);

    MercuryWebRequest mpswr =
        new MercuryWebRequest("https://w1.mercurydev.net/ws/ws.asmx"); // $NON-NLS-1$
    mpswr.addParameter(
        "tran",
        xml); // Set WebServices 'tran' parameter to the XML transaction request //$NON-NLS-1$
    mpswr.addParameter(
        "pw", CardConfig.getMerchantPass()); // Set merchant's WebServices password //$NON-NLS-1$
    mpswr.setWebMethodName(
        "CreditTransaction"); // Set WebServices webmethod to selected type //$NON-NLS-1$
    mpswr.setTimeout(10); // Set request timeout to 10 seconds

    String mpsResponse = mpswr.sendRequest();

    MercuryResponse result = new MercuryResponse(mpsResponse);
    if (!result.isApproved()) {
      throw new PosException("Error authorizing transaction."); // $NON-NLS-1$
    }

    transaction.setCardTransactionId(result.getTransactionId());
    transaction.setCardAuthCode(result.getAuthCode());
  }
Esempio n. 7
0
  private String doPreAuth(Ticket ticket, String cardTrack, double amount)
      throws IOException, Exception {
    String xml =
        StreamUtils.toString(
            MercuryPayProcessor.class.getResourceAsStream(
                "/com/mercurypay/ws/sdk/mercuryAuth.xml")); //$NON-NLS-1$

    String[] strings = cardTrack.split("\\|"); // $NON-NLS-1$

    // String merchantId = "118725340908147";
    String laneId = "01"; // $NON-NLS-1$
    String tranCode = "PreAuth"; // $NON-NLS-1$
    String invoiceNo = String.valueOf(ticket.getId());
    String amountStrng = NumberUtil.formatNumber(amount);
    String encryptedBlock = strings[3];
    String encryptedKey = strings[9];

    xml = xml.replace($merchantId, CardConfig.getMerchantAccount());
    xml = xml.replace($laneId, laneId);
    xml = xml.replace($tranCode, tranCode);
    xml = xml.replace($invoiceNo, invoiceNo);
    xml = xml.replace($refNo, invoiceNo);
    xml = xml.replace($encryptedBlock, encryptedBlock);
    xml = xml.replace($encryptedKey, encryptedKey);
    xml = xml.replace($amount, amountStrng);
    xml = xml.replace($authorizeAmount, amountStrng);

    System.out.println(xml);

    MercuryWebRequest mpswr =
        new MercuryWebRequest("https://w1.mercurydev.net/ws/ws.asmx"); // $NON-NLS-1$
    mpswr.addParameter(
        "tran",
        xml); // Set WebServices 'tran' parameter to the XML transaction request //$NON-NLS-1$
    mpswr.addParameter(
        "pw", CardConfig.getMerchantPass()); // Set merchant's WebServices password //$NON-NLS-1$
    mpswr.setWebMethodName(
        "CreditTransaction"); // Set WebServices webmethod to selected type //$NON-NLS-1$
    mpswr.setTimeout(10); // Set request timeout to 10 seconds

    String mpsResponse = mpswr.sendRequest();
    return mpsResponse;
  }
  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);
    //		}
  }
  private void doGroupSettle() {
    List<Ticket> selectedTickets = getSelectedTickets();
    if (selectedTickets == null) {
      return;
    }

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

    for (int i = 0; i < selectedTickets.size(); i++) {
      Ticket ticket = selectedTickets.get(i);

      Ticket fullTicket = TicketDAO.getInstance().loadFullTicket(ticket.getId());
      ticketsToSettle.add(fullTicket);
    }

    SettleTicketView posDialog = new SettleTicketView();
    posDialog.setTicketsToSettle(ticketsToSettle);
    posDialog.setSize(800, 600);
    posDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    posDialog.open();
  }
  protected void doAssignDriver() {
    try {

      Ticket ticket = getFirstSelectedTicket();

      //			if(ticket == null) {
      //				return;
      //			}

      if (!Ticket.HOME_DELIVERY.equals(ticket.getTicketType())) {
        POSMessageDialog.showError("Driver can be assigned only for Home Delivery");
        return;
      }

      User assignedDriver = ticket.getAssignedDriver();
      if (assignedDriver != null) {
        int option =
            JOptionPane.showOptionDialog(
                Application.getPosWindow(),
                "Driver already assigned. Do you want to reassign?",
                "Confirm",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                null,
                null);

        if (option != JOptionPane.YES_OPTION) {
          return;
        }
      }

      orderServiceExtension.assignDriver(ticket.getId());
    } catch (Exception e) {
      e.printStackTrace();
      POSMessageDialog.showError(e.getMessage());
      LogFactory.getLog(SwitchboardView.class).error(e);
    }
  }
  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);
  }