Search in sources :

Example 1 with JposException

use of jpos.JposException in project JavaForFun by gumartinm.

the class KeyBoardDeviceLinux method enable.

/**
 * Not thread-safe.!!!!!
 *
 * NO OLVIDAR try/finally PARA DEJAR EL DISPOSITIVO CORRECTAMENTE
 *
 * @throws JposException
 * @throws RejectedExecutionException
 *             if this task cannot be accepted for execution. CUIDADO
 *             RUNTIME NO OLVIDAR try/finally PARA DEJAR BIEN EL DISPOSITIVO
 */
@Override
public synchronized void enable() throws JposException {
    if (this.isEnabled) {
        return;
    }
    if (this.deviceName == null) {
        throw new JposException(JposConst.JPOSERR, "There is not an assigned device", new NullPointerException("The deviceName field has null value"));
    }
    // está o no muerto?
    if (!this.thread.isAlive()) {
        try {
            this.device = new DataInputStream(Channels.newInputStream(new FileInputStream(this.deviceName).getChannel()));
        } catch (FileNotFoundException e) {
            throw new JposException(JposConst.JPOS_E_NOHARDWARE, "Device not found.", e);
        }
        Runnable task = new Runnable() {

            @Override
            public void run() {
                // Hidden pointer: KeyBoardDeviceLinux.this.runBatchTask();
                runBatchTask();
            }
        };
        this.thread = new Thread(task, "KeyBoardDeviceLinux-Thread");
        this.thread.setUncaughtExceptionHandler(new DriverHWUncaughtExceptionHandler());
        this.thread.start();
        this.isEnabled = true;
    }
}
Also used : JposException(jpos.JposException) FileNotFoundException(java.io.FileNotFoundException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream)

Example 2 with JposException

use of jpos.JposException in project lar_361 by comitsrl.

the class ManejadorAbstractoDeImpresion method imprimir.

public boolean imprimir() throws JposException {
    boolean resultado = false;
    boolean sigue = true;
    while (sigue) {
        try {
            log.config("Abriendo e inicializando dispositivo...");
            // Esta instancia de impresora ya está inicializada
            printer = ImpresoraPOS.getInstance().getPrinter();
            if (printer.getCoverOpen()) {
                final String msg = "Cubierta abierta";
                log.config(msg);
                throw new JposException(1, msg);
            }
            if (printer.getRecEmpty() == true) {
                final String msg = "Impresora sin papel";
                log.config(msg);
                throw new JposException(2, msg);
            }
            // Paso genérico delegado a la subclase concreta
            imprimirDocumento();
            resultado = true;
            sigue = false;
        } catch (JposException e) {
            final String msg = "Error en Impresi\u00f3n JPOS";
            log.log(Level.SEVERE, msg, e);
            throw new JposException(3, msg);
        }
        // FIXME - @emmie, revisar
        if ((!resultado) && (1 == JOptionPane.showConfirmDialog(null, "¿ Reintentar ?", "Error al imprimir documento.", 0))) {
            sigue = false;
        }
    }
    return resultado;
}
Also used : JposException(jpos.JposException)

Example 3 with JposException

use of jpos.JposException in project lar_361 by comitsrl.

the class PosBasePanel method init.

/**
 *	Initialize Panel
 *  @param WindowNo window
 *  @param frame parent frame
 */
public void init(int WindowNo, FormFrame frame) {
    m_frame = frame;
    m_frame.setJMenuBar(null);
    if (debug)
        m_frame.setPreferredSize(new Dimension(1024, 768));
    else {
        m_frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
        m_frame.setResizable(false);
    }
    m_SalesRep_ID = Env.getAD_User_ID(m_ctx);
    log.info("init - SalesRep_ID=" + m_SalesRep_ID);
    m_WindowNo = WindowNo;
    // 
    try {
        if (!dynInit()) {
            dispose();
            frame.dispose();
            return;
        }
        m_frame.getContentPane().add(this, BorderLayout.CENTER);
    } catch (Exception e) {
        log.log(Level.SEVERE, "init", e);
    }
    log.config("PosPanel.init - " + getPreferredSize());
    if (p_pos.getAutoLogoutDelay() > 0 && logoutTimer == null) {
        logoutTimer = new javax.swing.Timer(1000, new ActionListener() {

            PointerInfo pi = null;

            long lastMouseMove = System.currentTimeMillis();

            long lastKeyboardEvent = System.currentTimeMillis();

            @Override
            public void actionPerformed(ActionEvent e) {
                long now = e.getWhen();
                PointerInfo newPi = MouseInfo.getPointerInfo();
                // mouse moved
                if (newPi != null && pi != null && !pi.getLocation().equals(newPi.getLocation())) {
                    lastMouseMove = now;
                }
                pi = newPi;
                lastKeyboardEvent = m_focusMgr.getLastWhen();
                if (p_pos.getAutoLogoutDelay() * 1000 < now - Math.max(lastKeyboardEvent, lastMouseMove)) {
                // new PosLogin(this);
                }
            }
        });
        logoutTimer.start();
    }
    m_focusMgr.start();
    // @emmie - Se intenta inicializar la impresora POS "PRT100FC"
    try {
        if (p_pos.get_ValueAsBoolean("IsJavaPOS")) {
            ManejadorAbstractoDeImpresion.ImpresoraPOS.getInstance();
            log.info("Impresora POS inicializada OK");
        }
    } catch (JposException e) {
        final String msg = String.format("No se pudo inicializar impresora POS: %s", e.getMessage());
        log.severe(msg);
        ADialog.error(getWindowNo(), this, msg);
    }
}
Also used : PointerInfo(java.awt.PointerInfo) ActionListener(java.awt.event.ActionListener) DialogActionListener(ar.com.ergio.print.fiscal.view.AInfoFiscalPrinter.DialogActionListener) JposException(jpos.JposException) ActionEvent(java.awt.event.ActionEvent) Dimension(java.awt.Dimension) JposException(jpos.JposException)

Example 4 with JposException

use of jpos.JposException in project lar_361 by comitsrl.

the class PosSubPanel method printTicket.

// actionPerformed
/**
 * 	Print Ticket
 *  @author Comunidad de Desarrollo OpenXpertya
 *  *Basado en Codigo Original Modificado, Revisado y Optimizado de:
 *  *Copyright (c) ConSerTi
 */
public void printTicket() {
    if (p_posPanel.m_order == null)
        return;
    final MOrder order = p_posPanel.m_order;
    boolean isFiscal = false;
    boolean isElectronic = false;
    boolean isJavaPOS = p_pos.get_ValueAsBoolean("IsJavaPOS");
    int reportType = 0;
    int documentId = 0;
    String impresoraFactura = "";
    if (order != null) {
        if (p_pos.get_ValueAsBoolean("IsShipment")) {
            // /// Procesa Remitos /////
            final MInOut shipment = p_posPanel.m_order.getShipments()[0];
            int C_DocType_ID = shipment.getC_DocType_ID();
            isFiscal = LAR_Utils.isFiscalDocType(C_DocType_ID);
            /* if (isFiscal)
		        {
		            // Impresión fiscal del de remito generado
		            if (!p_posPanel.printFiscalTicket(shipment))
		            {
		                log.log(Level.SEVERE, "Error in Fiscal Printing Ticket");
		                return;
		            }
		        } */
            if (!isFiscal) {
                reportType = ReportEngine.SHIPMENT;
                documentId = order.getC_Order_ID();
            }
        } else {
            // /// Procesa Facturas /////
            final MInvoice invoice = p_posPanel.m_order.getInvoices()[0];
            int C_DocType_ID = invoice.getC_DocType_ID();
            isFiscal = LAR_Utils.isFiscalDocType(C_DocType_ID);
            isElectronic = MDocType.isElectronicDocType(C_DocType_ID);
            /* @fchiappano se comenta codigo de impresión fiscal

                // Si DocType es fiscal se utiliza el controlador fiscal
                if (isFiscal && !isElectronic)
                {
                    // Impresión fiscal de factura
                    if (!p_posPanel.printFiscalTicket(invoice))
                    {
                        log.log(Level.SEVERE, "Error en impresi\u00f3n de factura fiscal");
                        return;
                    }
                } */
            if (isJavaPOS) {
                try {
                    // @fchiappano Imprimir ticket de envio a domicilio.
                    if (p_posPanel.m_order.get_ValueAsBoolean("ImprimirEnvio")) {
                        final ImprimeTicketEnvio ticketEnvio = new ImprimeTicketEnvio(order);
                        ticketEnvio.imprimir();
                    }
                } catch (final JposException e) {
                    log.log(Level.SEVERE, "Error al imprimir v\u00eda Java POS", e);
                }
            }
            if (!isFiscal) {
                reportType = ReportEngine.INVOICE;
                documentId = invoice.getC_Invoice_ID();
                if (isElectronic) {
                    ReportCtl.startDocumentPrint(reportType, null, documentId, null, Env.getWindowNo(this), true, impresoraFactura);
                } else
                    // @fchiappano Si no es ni electronica ni JavaPos, se imprime de forma tradicional
                    ReportCtl.startDocumentPrint(reportType, documentId, null, Env.getWindowNo(this), false);
            }
        }
        // if (isShipment)
        p_posPanel.newOrder();
        p_posPanel.stopGlassPane();
    }
// if (order != null)
}
Also used : MInOut(org.compiere.model.MInOut) MOrder(org.compiere.model.MOrder) JposException(jpos.JposException) MInvoice(org.compiere.model.MInvoice) ImprimeTicketEnvio(ar.com.comit.print.javapos.ImprimeTicketEnvio)

Example 5 with JposException

use of jpos.JposException in project openpos-framework by JumpMind.

the class EscpServiceInstanceFactory method createInstance.

@SuppressWarnings({ "unchecked", "rawtypes" })
public JposServiceInstance createInstance(String s, JposEntry jposentry) throws JposException {
    if (!jposentry.hasPropertyWithName("serviceClass")) {
        throw new JposException(JposConst.JPOS_E_NOSERVICE, "The JposEntry does not contain the 'serviceClass' property");
    }
    try {
        String s1 = (String) jposentry.getPropertyValue("serviceClass");
        Class class1 = Class.forName(s1);
        Constructor constructor = class1.getConstructor(new Class[0]);
        JposServiceInstance instance = (JposServiceInstance) constructor.newInstance(new Object[0]);
        Iterator i = jposentry.getProps();
        while (i.hasNext()) {
            JposEntry.Prop prop = (JposEntry.Prop) i.next();
            if (!ignoreProperty(prop.getName())) {
                try {
                    Field field = class1.getDeclaredField(prop.getName());
                    Class<?> type = field.getType();
                    Object value = prop.getValue();
                    if (type == int.class) {
                        value = new Integer(prop.getValueAsString());
                    }
                    field.setAccessible(true);
                    field.set(instance, value);
                } catch (NoSuchFieldException e) {
                    logger.warn("No such property: " + prop.getName() + " exists on " + class1.getSimpleName());
                } catch (Exception e) {
                    logger.error("", e);
                }
            }
        }
        if (instance instanceof IOpenposPrinter) {
            configureOpenposPrinter((IOpenposPrinter) instance, jposentry);
        }
        return instance;
    } catch (Exception ex) {
        throw new PrintException(String.format("Failed to create '%s' (%s)", s, ex.toString()), ex);
    }
}
Also used : JposException(jpos.JposException) JposServiceInstance(jpos.loader.JposServiceInstance) Constructor(java.lang.reflect.Constructor) JposException(jpos.JposException) Field(java.lang.reflect.Field) JposEntry(jpos.config.JposEntry) Iterator(java.util.Iterator)

Aggregations

JposException (jpos.JposException)13 IOException (java.io.IOException)3 JposServiceInstance (jpos.loader.JposServiceInstance)3 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 Constructor (java.lang.reflect.Constructor)2 Field (java.lang.reflect.Field)2 Iterator (java.util.Iterator)2 JposEntry (jpos.config.JposEntry)2 ImprimeTicketEnvio (ar.com.comit.print.javapos.ImprimeTicketEnvio)1 DialogActionListener (ar.com.ergio.print.fiscal.view.AInfoFiscalPrinter.DialogActionListener)1 BaseKeyBoardDriver (de.javapos.example.hardware.BaseKeyBoardDriver)1 JposEventQueueImpl (de.javapos.example.queue.JposEventQueueImpl)1 Dimension (java.awt.Dimension)1 PointerInfo (java.awt.PointerInfo)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1