Esempio n. 1
0
  public List<TicketLineInfo> getAffectedLines() {
    List<TicketLineInfo> lines = new ArrayList<TicketLineInfo>();

    int i = ticketlines.getSelectedIndex();
    if (i >= 0) {
      TicketLineInfo line = ticket.getLine(i);

      /* Si el producto seleccionado es axuliar o descuento, no podemos transferirlo */
      if (line.isProductCom() || line.isDiscount()) return lines;

      ticket.removeLine(i);
      ticketlines.removeTicketLine(i);
      lines.add(line);

      /* Comprobamos si la linea corresponde a un producto con productos auxiliares
       * como puede ser un menu o si tiene algun descuento por linea asociado
       */
      if (!line.isProductCom() && !line.isDiscount()) {
        while (i < ticket.getLinesCount()
            && ((line = (TicketLineInfo) ticket.getLine(i)).isProductCom() || line.isDiscount())) {
          lines.add(new TicketLineInfo(line));
          ticket.removeLine(i);
          ticketlines.removeTicketLine(i);
        }
      }
      printTotals();
    }
    return lines;
  }
  private void setActiveTicket(String id) throws BasicException {

    currentTicket = panelticket.getActiveTicket().getId();

    // save current ticket
    //        if (currentTicket != null) {
    //            try {
    //                dataLogicReceipts.insertSharedTicket(currentTicket,
    // panelticket.getActiveTicket());
    //            } catch (BasicException e) {
    //                new MessageInf(e).show(this);
    //            }
    //        }
    // set ticket
    // BEGIN TRANSACTION
    TicketInfo ticket = dataLogicReceipts.getSharedTicket(id);
    if (ticket == null) {
      // Does not exists ???
      throw new BasicException(AppLocal.getIntString("message.noticket"));
    } else {
      dataLogicReceipts.deleteSharedTicket(id);
      currentTicket = id;
      panelticket.setActiveTicket(ticket, null);
      fireTicketSelectionChanged(ticket.getId());
    }
    // END TRANSACTION
  }
  private void m_jEditActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_m_jEditActionPerformed

    m_ticketCopy = m_ticket;
    m_TicketsBagTicketBag.showEdit();
    m_panelticketedit.showCatalog();
    // Indicate that this a ticket in edit mode
    m_ticketCopy.setOldTicket(true);
    m_panelticketedit.setActiveTicket(m_ticket.copyTicket(), null);
  } // GEN-LAST:event_m_jEditActionPerformed
Esempio n. 4
0
  private void btnCustomerActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnCustomerActionPerformed

    JCustomerFinder finder = JCustomerFinder.getCustomerFinder(this, dlCustomers);
    finder.search(ticket.getCustomer());
    finder.setVisible(true);
    ticket.setCustomer(finder.getSelectedCustomer());

    // The ticket name
    m_jTicketId.setText(ticket.getName(ticketext));
  } // GEN-LAST:event_btnCustomerActionPerformed
Esempio n. 5
0
  public final void insertSharedTicket(final String id, final TicketInfo ticket)
      throws BasicException {

    Object[] values = new Object[] {id, ticket.getName(), ticket, ticket.getUser().getId()};
    Datas[] datas = new Datas[] {Datas.STRING, Datas.STRING, Datas.SERIALIZABLE, Datas.STRING};

    new PreparedSentence(
            s,
            "INSERT INTO SHAREDTICKETS (ID, NAME,CONTENT, USERID) VALUES (?, ?, ?, ?)",
            new SerializerWriteBasicExt(datas, new int[] {0, 1, 2, 3}))
        .exec(values);
  }
Esempio n. 6
0
  private void printTotals() {

    if (ticket.getLinesCount() > 0) {
      m_jSubtotalEuros.setText(Formats.CURRENCY.formatValue(new Double(ticket.getSubTotal())));
      m_jTaxesEuros.setText(Formats.CURRENCY.formatValue(new Double(ticket.getTax())));
      m_jTotalEuros.setText(Formats.CURRENCY.formatValue(new Double(ticket.getTotal())));
    } else {
      m_jSubtotalEuros.setText(null);
      m_jTaxesEuros.setText(null);
      m_jTotalEuros.setText(null);
    }
  }
  public void checkout(TicketInfo ticket, String place) throws BasicException {
    appView = AppViewImpl.getInstance();
    DataLogicSales dlSales = appView.getBean(DataLogicSales.class);

    try {
      // reset the payment info
      TaxesLogic taxesLogic = new TaxesLogic(dlSales.getTaxList().list());
      taxesLogic.calculateTaxes(ticket);
      if (ticket.getTotal() >= 0.0) {
        ticket.resetPayments(); // Only reset if is sale
      }

      // assign the payments selected and calculate taxes.
      List<PaymentInfo> payments = new ArrayList<PaymentInfo>();
      payments.add(new PaymentInfoCash(ticket.getTotal(), ticket.getTotalPaid()));
      ticket.setPayments(payments);

      // Asigno los valores definitivos del ticket...
      ticket.setUser(appView.getAppUserView().getUser().getUserInfo()); // El usuario que lo cobra
      ticket.setActiveCash(appView.getActiveCashIndex());
      ticket.setDate(new Date()); // Le pongo la fecha de cobro

      // Save the receipt and assign a receipt number
      try {
        dlSales.saveTicket(ticket, appView.getInventoryLocation());
      } catch (BasicException eData) {
        eData.printStackTrace();
      }

    } catch (TaxesException e) {
      e.printStackTrace();
    }
  }
  private void setActiveTicket(String id) throws BasicException {

    TicketInfo ticket = dlReceipts.getSharedTicket(id);
    if (ticket == null) {
      m_jListTickets.setText("");
      throw new BasicException(AppLocal.getIntString("message.noticket"));
    } else {
      dlReceipts.getPickupId(id);
      Integer pickUp = dlReceipts.getPickupId(id);
      dlReceipts.deleteSharedTicket(id);
      m_sCurrentTicket = id;
      m_panelticket.setActiveTicket(ticket, null);
      ticket.setPickupId(pickUp);
    }
    // END TRANSACTION
  }
Esempio n. 9
0
  private void m_jEditActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_m_jEditActionPerformed

    m_ticketCopy = m_ticket;
    m_TicketsBagTicketBag.showEdit();
    m_panelticketedit.showCatalog();
    m_panelticketedit.setActiveTicket(m_ticket.copyTicket(), null);
  } // GEN-LAST:event_m_jEditActionPerformed
Esempio n. 10
0
  public void setTicket(TicketInfo ticket, Object ticketext) {

    this.ticket = ticket;
    this.ticketext = ticketext;

    // The ticket name
    m_jTicketId.setText(ticket.getName(ticketext));

    ticketlines.clearTicketLines();
    for (int i = 0; i < ticket.getLinesCount(); i++) {
      ticketlines.addTicketLine(ticket.getLine(i));
    }

    if (ticket.getLinesCount() > 0) {
      ticketlines.setSelectedIndex(0);
    }

    printTotals();
  }
Esempio n. 11
0
  private void printTicket() {

    // imprimo m_ticket

    try {
      m_jEdit.setEnabled(
          m_ticket != null
              && (m_ticket.getTicketType() == TicketInfo.RECEIPT_NORMAL
                  || m_ticket.getTicketType() == TicketInfo.RECEIPT_REFUND)
              && m_dlSales.isCashActive(m_ticket.getActiveCash()));
    } catch (BasicException e) {
      m_jEdit.setEnabled(false);
    }
    m_jRefund.setEnabled(m_ticket != null && m_ticket.getTicketType() == TicketInfo.RECEIPT_NORMAL);
    m_jPrint.setEnabled(m_ticket != null);

    // Este deviceticket solo tiene una impresora, la de pantalla
    m_TP.getDevicePrinter("1").reset();

    if (m_ticket == null) {
      m_jTicketId.setText(null);
    } else {
      m_jTicketId.setText(m_ticket.getName());

      try {
        ScriptEngine script = ScriptFactory.getScriptEngine(ScriptFactory.VELOCITY);
        script.put("ticket", m_ticket);
        m_TTP.printTicket(
            script.eval(m_dlSystem.getResourceAsXML("Printer.TicketPreview")).toString());
      } catch (ScriptException e) {
        MessageInf msg =
            new MessageInf(
                MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotprintticket"), e);
        msg.show(this);
      } catch (TicketPrinterException eTP) {
        MessageInf msg =
            new MessageInf(
                MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotprintticket"), eTP);
        msg.show(this);
      }
    }
  }
Esempio n. 12
0
  public final void updateSharedTicket(final String id, final TicketInfo ticket)
      throws BasicException {

    Object[] values = new Object[] {id, ticket.getName(), ticket};
    Datas[] datas = new Datas[] {Datas.STRING, Datas.STRING, Datas.SERIALIZABLE};
    new PreparedSentence(
            s,
            "UPDATE SHAREDTICKETS SET NAME = ?, CONTENT = ? WHERE ID = ?",
            new SerializerWriteBasicExt(datas, new int[] {1, 2, 0}))
        .exec(values);
  }
  private void saveCurrentTicket() {

    if (m_sCurrentTicket != null) {
      try {
        dlReceipts.insertSharedTicket(
            m_sCurrentTicket,
            m_panelticket.getActiveTicket(),
            m_panelticket.getActiveTicket().getPickupId());
        m_jListTickets.setText("*");
        TicketInfo l = dlReceipts.getSharedTicket(m_sCurrentTicket);
        if (l.getLinesCount() == 0) {
          //                      throw new
          // BasicException(AppLocal.getIntString("message.nullticket"));
          //                    }else{
          dlReceipts.deleteSharedTicket(m_sCurrentTicket);
        }
      } catch (BasicException e) {
        new MessageInf(e).show(this);
      }
    }
  }
Esempio n. 14
0
  /**
   * This is the action called from the Struts framework.
   *
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   * @throws java.lang.Exception
   * @return
   */
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    FloorForm inputForm = (FloorForm) form;
    RestaurantManager manager = new RestaurantManager();

    Place place = manager.findPlaceByName(inputForm.getFloorId());

    TicketInfo ticketInfo = manager.findTicket(place.id);

    if (ticketInfo.getUser() == null) {
      ticketInfo.setUser((UserInfo) request.getSession().getAttribute("user"));
    }
    TicketDAO tkdao = new TicketDAO();
    tkdao.updateTicket(place.id, ticketInfo);

    PrintPDA printer = new PrintPDA();
    printer.PrintPDATicket(place.getName(), ticketInfo, place.getName());

    // Obtenemos un Iterador y recorremos la lista.
    List<TicketLineInfo> lst = ticketInfo.getLines();
    ListIterator iter = lst.listIterator();
    int i = 0;
    while (iter.hasNext()) {
      ticketInfo.getLine(i).getProperties().setProperty("sendstatus", "Yes");
      i = i + 1;
      if (i >= lst.size()) break;
    }
    tkdao = new TicketDAO();
    tkdao.updateTicket(place.id, ticketInfo);

    return mapping.findForward(PRINTING);
  }
Esempio n. 15
0
  private void readTicket(int iTicketid, int iTickettype) {
    Integer findTicket = 0;
    try {
      findTicket = m_jTicketEditor.getValueInteger();
    } catch (BasicException e) {
    }

    try {

      TicketInfo ticket =
          (iTicketid == -1)
              ? m_dlSales.loadTicket(iTickettype, findTicket)
              : m_dlSales.loadTicket(iTickettype, iTicketid);

      if (ticket == null) {
        // MessageInf msg = new MessageInf(MessageInf.SGN_WARNING,
        // AppLocal.getIntString("message.notexiststicket"));
        // msg.show(this);
        JFrame frame = new JFrame();
        JOptionPane.showMessageDialog(
            frame,
            AppLocal.getIntString("message.notexiststicket"),
            AppLocal.getIntString("message.notexiststickettitle"),
            JOptionPane.WARNING_MESSAGE);

      } else {
        m_ticket = ticket;
        m_ticketCopy = null; // se asigna al pulsar el boton de editar o devolver

        try {
          taxeslogic.calculateTaxes(m_ticket);
          TicketTaxInfo[] taxlist = m_ticket.getTaxLines();
          //  taxcollection = new ListKeyed<TaxInfo>(taxlist);
        } catch (TaxesException ex) {
        }
        printTicket();
      }

    } catch (BasicException e) {
      MessageInf msg =
          new MessageInf(
              MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotloadticket"), e);
      msg.show(this);
    }

    m_jTicketEditor.reset();
    m_jTicketEditor.activate();
  }
Esempio n. 16
0
  private void m_jRefundActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_m_jRefundActionPerformed

    java.util.List aRefundLines = new ArrayList();

    for (int i = 0; i < m_ticket.getLinesCount(); i++) {
      TicketLineInfo newline = new TicketLineInfo(m_ticket.getLine(i));
      aRefundLines.add(newline);
    }

    m_ticketCopy = null;
    m_TicketsBagTicketBag.showRefund();
    m_panelticketedit.showRefundLines(aRefundLines);

    TicketInfo refundticket = new TicketInfo();
    refundticket.setTicketType(TicketInfo.RECEIPT_REFUND);
    refundticket.setCustomer(m_ticket.getCustomer());
    refundticket.setPayments(m_ticket.getPayments());
    // Indicate that this a ticket in edit mode
    refundticket.setOldTicket(true);
    m_panelticketedit.setActiveTicket(refundticket, null);
  } // GEN-LAST:event_m_jRefundActionPerformed
Esempio n. 17
0
  private void m_jPrintActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_m_jPrintActionPerformed

    if (m_ticket != null) {
      try {
        ScriptEngine script = ScriptFactory.getScriptEngine(ScriptFactory.VELOCITY);
        script.put("ticket", m_ticket);
        script.put("taxes", m_ticket.getTaxLines());
        m_TTP2.printTicket(
            script.eval(m_dlSystem.getResourceAsXML("Printer.TicketPreview")).toString());
      } catch (ScriptException e) {
        JMessageDialog.showMessage(
            this,
            new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("message.cannotprint"), e));
      } catch (TicketPrinterException e) {
        JMessageDialog.showMessage(
            this,
            new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("message.cannotprint"), e));
      }
    }
  } // GEN-LAST:event_m_jPrintActionPerformed
Esempio n. 18
0
  public final TicketInfo loadTicket(final int tickettype, final int ticketid)
      throws BasicException {
    TicketInfo ticket =
        (TicketInfo)
            new PreparedSentence(
                    s,
                    "SELECT T.ID, T.TICKETTYPE, T.TICKETID, R.DATENEW, R.MONEY, R.ATTRIBUTES, P.ID, P.NAME, T.CUSTOMER FROM RECEIPTS R JOIN TICKETS T ON R.ID = T.ID LEFT OUTER JOIN PEOPLE P ON T.PERSON = P.ID WHERE T.TICKETTYPE = ? AND T.TICKETID = ?",
                    SerializerWriteParams.INSTANCE,
                    new SerializerReadClass(TicketInfo.class))
                .find(
                    new DataParams() {
                      public void writeValues() throws BasicException {
                        setInt(1, tickettype);
                        setInt(2, ticketid);
                      }
                    });
    if (ticket != null) {

      String customerid = ticket.getCustomerId();
      ticket.setCustomer(customerid == null ? null : loadCustomerExt(customerid));

      ticket.setLines(
          new PreparedSentence(
                  s,
                  "SELECT L.TICKET, L.LINE, L.PRODUCT, L.ATTRIBUTESETINSTANCE_ID, L.UNITS, L.PRICE, T.ID, T.NAME, T.CATEGORY, T.VALIDFROM, T.CUSTCATEGORY, T.PARENTID, T.RATE, T.RATECASCADE, T.RATEORDER, L.ATTRIBUTES "
                      + "FROM TICKETLINES L, TAXES T WHERE L.TAXID = T.ID AND L.TICKET = ? ORDER BY L.LINE",
                  SerializerWriteString.INSTANCE,
                  new SerializerReadClass(TicketLineInfo.class))
              .list(ticket.getId()));
      ticket.setPayments(
          new PreparedSentence(
                  s,
                  "SELECT PAYMENT, TOTAL, TRANSID FROM PAYMENTS WHERE RECEIPT = ?",
                  SerializerWriteString.INSTANCE,
                  new SerializerReadClass(PaymentInfoTicket.class))
              .list(ticket.getId()));
    }
    return ticket;
  }
Esempio n. 19
0
  public void addAffectedLines(List<TicketLineInfo> lines) {

    int i = ticketlines.getSelectedIndex();
    int e = 0;
    for (e = 0; e < lines.size(); e++, i++) {
      TicketLineInfo line = lines.get(e);
      if (i >= 0
          && ticket.getLine(i).getProduct().getId() != null
          && line.getProduct().getId() != null
          && ticket.getLine(i).getProduct().getId().equals(line.getProduct().getId())
          && ticket.getLine(i).getTaxInfo().getId().equals(line.getTaxInfo().getId())
          && ticket.getLine(i).getPrice() == line.getPrice()) {
        // inc the line
        ticket.getLine(i).setMultiply(ticket.getLine(i).getMultiply() + line.getMultiply());
        ticketlines.setTicketLine(i, ticket.getLine(i));
      } else {
        ticket.addLine(line);
        ticketlines.addTicketLine(line);
      }
    }
    printTotals();
  }
Esempio n. 20
0
  private void btnPayActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnPayActionPerformed

    paymentdialog.setPrintSelected(true);
    // MSL : get total of selected tickets
    double tt = 0;
    for (Object tl : jList1.getSelectedValues()) {

      FindTicketsInfoCustomer sTicket = (FindTicketsInfoCustomer) tl;
      TicketInfo t = new TicketInfo();
      try {
        t = dlsales.loadTicket(0, sTicket.getTicketId());
        tt = tt + t.getTotal(); // - t.getTotalPaid();
      } catch (BasicException e) {

      }
    }
    // -------------

    // if (paymentdialog.showDialog(customerext.getCurdebt(), null)) {
    if (paymentdialog.showDialog(tt, null)) {

      // Save the ticket
      /*TicketInfo ticket = new TicketInfo();
      ticket.setTicketType(TicketInfo.RECEIPT_PAYMENT);

      List<PaymentInfo> payments = paymentdialog.getSelectedPayments();

      double total = 0.0;
      for (PaymentInfo p : payments) {
          total += p.getTotal();
      }

      payments.add(new PaymentInfoTicket(-total, "debtpaid"));

      ticket.setPayments(payments);

      ticket.setUser(app.getAppUserView().getUser().getUserInfo());
      ticket.setActiveCash(app.getActiveCashIndex());
      ticket.setDate(new Date());
      ticket.setCustomer(customerext);

      try {
          dlsales.saveTicket(ticket, app.getInventoryLocation());
      } catch (BasicException eData) {
          MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("message.nosaveticket"), eData);
          msg.show(this);
      }
       *
       */

      // Save the ticket
      TicketInfo ticket = new TicketInfo();
      ticket.setTicketType(TicketInfo.RECEIPT_PAYMENT);

      List<PaymentInfo> payments = paymentdialog.getSelectedPayments();

      double total = 0.0;
      for (PaymentInfo p : payments) {
        total += p.getTotal();
      }
      double reste = total;

      for (Object tl : jList1.getSelectedValues()) {
        FindTicketsInfoCustomer sTicket = (FindTicketsInfoCustomer) tl;
        TicketInfo t = new TicketInfo();

        if (reste > 0) {
          try {
            t = dlsales.loadTicket(0, sTicket.getTicketId());

            payments.add(new PaymentInfoTicket(-t.getTotal(), "debtpaid"));
            reste = total - t.getTotal();

            ticket.setPayments(payments);
            ticket.setUser(app.getAppUserView().getUser().getUserInfo());
            ticket.setActiveCash(app.getActiveCashIndex());
            ticket.setDate(new Date());
            ticket.setCustomer(customerext);
            dlsales.saveTicket(ticket, app.getInventoryLocation());
            new StaticSentence(
                    this.app.getSession(),
                    "UPDATE TICKETS Set STATUS=9 WHERE ID = ?",
                    SerializerWriteString.INSTANCE)
                .exec(t.getId());

            // MSL : break the system : set the receipt with original one
            // TODO : split the amount paid to the ticket values
            /*new StaticSentence(this.app.getSession()
                        , "UPDATE RECEIPTS Set ID=? WHERE ID = ?"
                        , new SerializerWriteBasic(new Datas[] {Datas.STRING, Datas.STRING}))
                        .exec(new Object[] {t.getId(), ticket.getId()});
            */
            new StaticSentence(
                    this.app.getSession(),
                    "UPDATE PAYMENTS Set TICKETID=? WHERE RECEIPT = ?",
                    new SerializerWriteBasic(new Datas[] {Datas.STRING, Datas.STRING}))
                .exec(new Object[] {t.getId(), ticket.getId()});

          } catch (BasicException eData) {
            MessageInf msg =
                new MessageInf(
                    MessageInf.SGN_NOTICE, AppLocal.getIntString("message.nosaveticket"), eData);
            msg.show(this);
          }
        }
      }

      // MSL : no tickets selected
      if ((jList1.getSelectedValues() == null) || (reste > 0)) {

        payments.add(new PaymentInfoTicket(-reste, "debtpaid"));

        ticket.setPayments(payments);

        ticket.setUser(app.getAppUserView().getUser().getUserInfo());
        ticket.setActiveCash(app.getActiveCashIndex());
        ticket.setDate(new Date());
        ticket.setCustomer(customerext);

        try {
          dlsales.saveTicket(ticket, app.getInventoryLocation());
        } catch (BasicException eData) {
          MessageInf msg =
              new MessageInf(
                  MessageInf.SGN_NOTICE, AppLocal.getIntString("message.nosaveticket"), eData);
          msg.show(this);
        }
      }

      // reload customer
      CustomerInfoExt c;
      try {
        c = dlsales.loadCustomerExt(customerext.getId());
        if (c == null) {
          MessageInf msg =
              new MessageInf(
                  MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotfindcustomer"));
          msg.show(this);
        } else {
          editCustomer(c);
        }
      } catch (BasicException ex) {
        c = null;
        MessageInf msg =
            new MessageInf(
                MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotfindcustomer"), ex);
        msg.show(this);
      }

      printTicket(
          paymentdialog.isPrintSelected() ? "Printer.CustomerPaid" : "Printer.CustomerPaid2",
          ticket,
          c);
    }

    editorcard.reset();
    editorcard.activate();
  } // GEN-LAST:event_btnPayActionPerformed
Esempio n. 21
0
  public TicketInfo copyTicket() {
    TicketInfo t = new TicketInfo();

    t.tickettype = tickettype;
    t.m_iTicketId = m_iTicketId;
    t.m_iTicketNCF = m_iTicketNCF; // NCF
    t.m_dDate = m_dDate;
    t.m_sActiveCash = m_sActiveCash;
    t.attributes = (Properties) attributes.clone();
    t.m_User = m_User;
    t.m_Customer = m_Customer;

    t.m_aLines = new ArrayList<TicketLineInfo>();
    for (TicketLineInfo l : m_aLines) {
      t.m_aLines.add(l.copyTicketLine());
    }
    t.refreshLines();

    t.payments = new LinkedList<PaymentInfo>();
    for (PaymentInfo p : payments) {
      t.payments.add(p.copyPayment());
    }

    // taxes are not copied, must be calculated again.

    return t;
  }