📄 jpanelticket.java
字号:
// Tina POS is a point of sales application designed for touch screens.// Copyright (C) 2005 Adrian Romero Corchado.// http://sourceforge.net/projects/tinapos//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USApackage net.adrianromero.tpv.panelsales;import java.util.*;import javax.swing.*;import java.awt.*;import net.adrianromero.data.gui.ComboBoxValModel;import net.adrianromero.data.gui.MessageInf;import net.adrianromero.tpv.ticket.*;import net.adrianromero.tpv.printer.*;import net.adrianromero.tpv.forms.JPanelView;import net.adrianromero.tpv.forms.AppView;import net.adrianromero.tpv.forms.AppLocal;import net.adrianromero.tpv.forms.UserView;import net.adrianromero.tpv.panels.JProductFinder;import net.adrianromero.tpv.scale.ScaleException;import net.adrianromero.tpv.payment.JPaymentSelect;import net.adrianromero.format.Formats;import net.adrianromero.basic.BasicException;import net.adrianromero.data.loader.SentenceList;import net.adrianromero.scripting.ScriptEngine;import net.adrianromero.scripting.ScriptException;import net.adrianromero.scripting.ScriptFactory;import net.adrianromero.tpv.forms.DataLogicSystem;import net.adrianromero.tpv.forms.SentenceContainer;public abstract class JPanelTicket extends JPanel implements JPanelView, TicketsEditor { // Variable numerica private final static int NUMBERZERO = 0; private final static int NUMBERVALID = 1; private final static int NUMBER_INPUTZERO = 0; private final static int NUMBER_INPUTZERODEC = 1; private final static int NUMBER_INPUTINT = 2; private final static int NUMBER_INPUTDEC = 3; private final static int NUMBER_PORZERO = 4; private final static int NUMBER_PORZERODEC = 5; private final static int NUMBER_PORINT = 6; private final static int NUMBER_PORDEC = 7; protected JTicketLines m_ticketlines; // private Template m_tempLine; private TicketParser m_TTP; protected TicketInfo m_oTicket; protected Object m_oTicketExt; // Estas tres variables forman el estado... private int m_iNumberStatus; private int m_iNumberStatusInput; private int m_iNumberStatusPor; private StringBuffer m_sBarcode; private JTicketsBag m_ticketsbag; private UserView m_User; private SentenceList m_senttax; private ComboBoxValModel m_TaxModel; protected JPanelButtons m_jbtnconfig; protected AppView m_App; /** Creates new form JTicketView */ public JPanelTicket(AppView oApp, UserView oUser) { m_App = oApp; m_User = oUser; initComponents (); // borramos el boton de bascula si no hay bascula conectada if (!m_App.getDeviceScale().existsScale()) { m_jbtnScale.setVisible(false); } m_ticketsbag = getJTicketsBag(); m_jPanelBag.add(m_ticketsbag.getBagComponent(), BorderLayout.CENTER); add(m_ticketsbag.getNullComponent(), "null"); m_ticketlines = new JTicketLines(oApp); m_jPanelCentral.add(m_ticketlines, java.awt.BorderLayout.CENTER); m_TTP = new TicketParser(m_App.getDeviceTicket(), m_App.lookupDataLogic(DataLogicSystem.class)); // Los botones configurables... m_jbtnconfig = new JPanelButtons("Ticket.Buttons", new ScriptObject()); m_jButtonsExt.add(m_jbtnconfig); // El panel de los productos o de las lineas... m_jPanContainer.add(getSouthComponent(), BorderLayout.SOUTH); // El modelo de impuestos m_senttax = m_App.lookupDataLogic(SentenceContainer.class).getTaxList(); m_TaxModel = new ComboBoxValModel(); // ponemos a cero el estado stateToZero(); // inicializamos m_oTicket = null; m_oTicketExt = null; } protected abstract JTicketsBag getJTicketsBag(); protected abstract Component getSouthComponent(); public JComponent getComponent() { return this; } public void activate() throws BasicException { m_ticketsbag.activate(); // impuestos incluidos seleccionado ? m_jaddtax.setSelected(m_jbtnconfig.isTaxesIncluded()); // Inicializamos el combo de los impuestos. m_TaxModel = new ComboBoxValModel(m_senttax.list()); m_jTax.setModel(m_TaxModel); if (m_jbtnconfig.getTaxesID() == null) { if (m_jTax.getItemCount() > 0) { m_jTax.setSelectedIndex(0); } } else { m_TaxModel.setSelectedKey(m_jbtnconfig.getTaxesID()); } } public boolean deactivate() { return m_ticketsbag.deactivate(); } public void setActiveTicket(TicketInfo oTicket, Object oTicketExt) { m_oTicket = oTicket; m_oTicketExt = oTicketExt; CardLayout cl = (CardLayout)(getLayout()); if (m_oTicket == null) { m_jTicketId.setText(null); m_ticketlines.clearTicketLines(); m_jSubtotalEuros.setText(null); m_jTaxesEuros.setText(null); m_jTotalEuros.setText(null); stateToZero(); // Muestro el panel de nulos. cl.show(this, "null"); } else { // Reasigno los valores previos del ticket. Al grabar se volveran a asignar... m_oTicket.setUser(m_User.getUser().getName()); // El usuario que lo cobra m_oTicket.setActiveCash(m_App.getActiveCashIndex()); m_oTicket.setDate(new Date()); // Le pongo la fecha de cobro // La fecha y numero del ticket //m_jID.setText(String.valueOf(m_oTicket.getID())); //m_jDate.setText(m_oDateFormat.format(oTicket.getDate())); m_jTicketId.setText(String.valueOf(m_oTicket.getId())); // Limpiamos todas las filas y anadimos las del ticket actual m_ticketlines.clearTicketLines(); for (int i = 0; i < m_oTicket.getLinesCount(); i++) { m_ticketlines.addTicketLine(m_oTicket.getLine(i)); } printPartialTotals(); stateToZero(); // Muestro el panel de tickets. cl.show(this, "ticket"); // activo el tecleador... m_jKeyFactory.setText(null); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { m_jKeyFactory.requestFocus(); } }); } } public TicketInfo getActiveTicket() { return m_oTicket; } private void printPartialTotals(){ if (m_oTicket.getLinesCount() == 0) { m_jSubtotalEuros.setText(null); m_jTaxesEuros.setText(null); m_jTotalEuros.setText(null); } else { m_jSubtotalEuros.setText(Formats.CURRENCY.formatValue(new Double(m_oTicket.getSubTotal()))); m_jTaxesEuros.setText(Formats.CURRENCY.formatValue(new Double(m_oTicket.getTax()))); m_jTotalEuros.setText(Formats.CURRENCY.formatValue(new Double(m_oTicket.getTotal()))); } } private void paintTicketLine(int index, TicketLineInfo oLine){ m_ticketlines.setTicketLine(index, oLine); m_ticketlines.setSelectedIndex(index); visorTicketLine(oLine); // Y al visor tambien... printPartialTotals(); stateToZero(); } private void addTicketLine(ProductInfoExt oProduct, double dMul, double dPrice) { addTicketLine(new TicketLineInfo(oProduct, dMul, dPrice)); } protected void addTicketLine(TicketLineInfo oLine) { if (oLine.isProductCom()) { // Comentario entonces donde se pueda int i = m_ticketlines.getSelectedIndex(); // me salto el primer producto normal... if (i >= 0 && !m_oTicket.getLine(i).isProductCom()) { i++; } // me salto todos los productos auxiliares... while (i >= 0 && i < m_oTicket.getLinesCount() && m_oTicket.getLine(i).isProductCom()) { i++; } if (i >= 0) { m_oTicket.insertLine(i, oLine); m_ticketlines.insertTicketLine(i, oLine); // Pintamos la linea en la vista... } else { Toolkit.getDefaultToolkit().beep(); } } else { // Producto normal, entonces al final m_oTicket.addLine(oLine); m_ticketlines.addTicketLine(oLine); // Pintamos la linea en la vista... } visorTicketLine(oLine); printPartialTotals(); stateToZero(); } private void removeTicketLine(int i){ if (m_oTicket.getLine(i).isProductCom()) { // Es un producto auxiliar, lo borro y santas pascuas. m_oTicket.removeLine(i); m_ticketlines.removeTicketLine(i); } else { // Es un producto normal, lo borro. m_oTicket.removeLine(i); m_ticketlines.removeTicketLine(i); // Y todos lo auxiliaries que hubiera debajo. while(i < m_oTicket.getLinesCount() && m_oTicket.getLine(i).isProductCom()) { m_oTicket.removeLine(i); m_ticketlines.removeTicketLine(i); } } visorTicketLine(null); // borro el visor printPartialTotals(); // pinto los totales parciales... stateToZero(); // Pongo a cero } private ProductInfoExt getInputProduct() { ProductInfoExt oProduct = new ProductInfoExt(); // Es un ticket oProduct.setReference(null); oProduct.setCode(null); oProduct.setName(""); oProduct.setPriceSell(includeTaxes(getInputValue())); oProduct.setTaxInfo((TaxInfo) m_TaxModel.getSelectedItem()); return oProduct; } private double includeTaxes(double dValue) { if (m_jaddtax.isSelected()) { TaxInfo tax = (TaxInfo) m_TaxModel.getSelectedItem(); double dTaxRate = tax == null ? 0.0 : tax.getRate(); return dValue / (1.0 + dTaxRate); } else { return dValue; } } private double getInputValue() { try { return Double.parseDouble(m_jPrice.getText());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -