// Chromis POS - The New Face of Open Source POS // Copyright (c) (c) 2015-2016 // http://www.chromis.co.uk // // This file is part of Chromis POS // // Chromis POS 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 3 of the License, or // (at your option) any later version. // // Chromis POS 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 Chromis POS. If not, see <http://www.gnu.org/licenses/>. package uk.chromis.pos.printer.javapos; import javax.swing.JComponent; import jpos.FiscalPrinter; import jpos.JposException; import uk.chromis.pos.printer.DeviceFiscalPrinter; import uk.chromis.pos.printer.TicketPrinterException; import uk.chromis.pos.util.RoundUtils; /** * * */ public class DeviceFiscalPrinterJavaPOS extends javax.swing.JPanel implements DeviceFiscalPrinter { private String m_sName; private FiscalPrinter m_fiscal; /** Creates new form DeviceFiscalPrinterJavaPOSPanel * @param sDeviceFiscalPrinterName * @throws uk.chromis.pos.printer.TicketPrinterException */ public DeviceFiscalPrinterJavaPOS(String sDeviceFiscalPrinterName) throws TicketPrinterException { m_sName = sDeviceFiscalPrinterName; m_fiscal = new FiscalPrinter(); try { m_fiscal.open(m_sName); m_fiscal.claim(10000); m_fiscal.setDeviceEnabled(true); // m_printer.setMapMode(POSPrinterConst.PTR_MM_METRIC); // unit = 1/100 mm - i.e. 1 cm = 10 mm = 10 * 100 units m_fiscal.setCheckTotal(false); } catch (JposException e) { throw new TicketPrinterException(e.getMessage(), e); } initComponents(); } /** * * @return */ @Override public String getFiscalName() { return m_sName; } /** * * @return */ @Override public JComponent getFiscalComponent() { return this; } /** * */ @Override public void beginReceipt() { try { m_fiscal.beginFiscalReceipt(true); } catch (JposException e) { } } /** * */ @Override public void endReceipt() { try { m_fiscal.endFiscalReceipt(false); } catch (JposException e) { } } /** * * @param sproduct * @param dprice * @param dunits * @param taxinfo */ @Override public void printLine(String sproduct, double dprice, double dunits, int taxinfo) { try { m_fiscal.printRecItem(sproduct, roundFiscal(dprice * dunits), (int)(dunits * 1000), taxinfo, roundFiscal(dprice), ""); } catch (JposException e) { } } /** * * @param smessage */ @Override public void printMessage(String smessage) { try { m_fiscal.printRecMessage(smessage); } catch (JposException e) { } } /** * * @param sPayment * @param dpaid */ @Override public void printTotal(String sPayment, double dpaid) { try { // el primer valor es el total calculado por la aplicacion. // al poner 0 no se debe chequear: CAPCHECKTOTAL = false. m_fiscal.printRecTotal(0, roundFiscal(dpaid), sPayment); } catch (JposException e) { } } /** * */ @Override public void printZReport() { try { m_fiscal.printZReport(); } catch (JposException e) { } } /** * */ @Override public void printXReport() { try { m_fiscal.printXReport(); } catch (JposException e) { } } @Override public void finalize() throws Throwable { m_fiscal.setDeviceEnabled(false); m_fiscal.release(); m_fiscal.close(); super.finalize(); } private int roundFiscal(double value) { return (int) Math.floor(RoundUtils.round(value) * 10000.0 + 0.5); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jButton1 = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jTextField3 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jTextField5 = new javax.swing.JTextField(); jButton2 = new javax.swing.JButton(); jCheckBox1 = new eu.hansolo.custom.SteelCheckBox(); jCheckBox2 = new eu.hansolo.custom.SteelCheckBox(); jCheckBox3 = new eu.hansolo.custom.SteelCheckBox(); jCheckBox4 = new eu.hansolo.custom.SteelCheckBox(); jCheckBox5 = new eu.hansolo.custom.SteelCheckBox(); setLayout(null); jButton1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jButton1.setText("*X Report"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); add(jButton1); jButton1.setBounds(30, 10, 130, 23); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("*Receipt Title")); jPanel1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jPanel1.setLayout(null); jTextField1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jTextField1.setText("jTextField1"); jPanel1.add(jTextField1); jTextField1.setBounds(20, 30, 260, 25); jTextField2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jTextField2.setText("jTextField2"); jPanel1.add(jTextField2); jTextField2.setBounds(20, 60, 260, 25); jTextField3.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jTextField3.setText("jTextField3"); jPanel1.add(jTextField3); jTextField3.setBounds(20, 90, 260, 25); jTextField4.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jTextField4.setText("jTextField4"); jPanel1.add(jTextField4); jTextField4.setBounds(20, 120, 260, 25); jTextField5.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jTextField5.setText("jTextField5"); jPanel1.add(jTextField5); jTextField5.setBounds(20, 150, 260, 25); jButton2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jButton2.setText("*Z Report"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jPanel1.add(jButton2); jButton2.setBounds(20, 220, 130, 23); jCheckBox1.setText("jCheckBox1"); jPanel1.add(jCheckBox1); jCheckBox1.setBounds(290, 30, 160, 30); jCheckBox2.setText("jCheckBox2"); jPanel1.add(jCheckBox2); jCheckBox2.setBounds(290, 60, 170, 30); jCheckBox3.setText("jCheckBox3"); jPanel1.add(jCheckBox3); jCheckBox3.setBounds(290, 90, 160, 30); jCheckBox4.setText("jCheckBox4"); jPanel1.add(jCheckBox4); jCheckBox4.setBounds(290, 120, 170, 30); jCheckBox5.setText("jCheckBox5"); jPanel1.add(jCheckBox5); jCheckBox5.setBounds(290, 150, 160, 30); add(jPanel1); jPanel1.setBounds(10, 60, 470, 260); }// </editor-fold>//GEN-END:initComponents private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed printZReport(); }//GEN-LAST:event_jButton2ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed printXReport(); }//GEN-LAST:event_jButton1ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private eu.hansolo.custom.SteelCheckBox jCheckBox1; private eu.hansolo.custom.SteelCheckBox jCheckBox2; private eu.hansolo.custom.SteelCheckBox jCheckBox3; private eu.hansolo.custom.SteelCheckBox jCheckBox4; private eu.hansolo.custom.SteelCheckBox jCheckBox5; private javax.swing.JPanel jPanel1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField5; // End of variables declaration//GEN-END:variables }