private void printTicket(String resname, TicketInfo ticket, CustomerInfoExt customer) {

    String resource = dlsystem.getResourceAsXML(resname);
    if (resource == null) {
      MessageInf msg =
          new MessageInf(
              MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotprintticket"));
      msg.show(this);
    } else {
      try {
        ScriptEngine script = ScriptFactory.getScriptEngine(ScriptFactory.VELOCITY);
        script.put("ticket", ticket);
        script.put("customer", customer);
        ttp.printTicket(script.eval(resource).toString());
      } catch (ScriptException e) {
        MessageInf msg =
            new MessageInf(
                MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotprintticket"), e);
        msg.show(this);
      } catch (TicketPrinterException e) {
        MessageInf msg =
            new MessageInf(
                MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotprintticket"), e);
        msg.show(this);
      }
    }
  }
  /** Creates new form JPrincipalApp */
  public JPrincipalApp(JRootApp appview, AppUser appuser) {

    m_appview = appview;
    m_appuser = appuser;

    m_dlSystem =
        (DataLogicSystem) m_appview.getBean("com.openbravo.pos.forms.DataLogicSystemCreate");

    // Cargamos los permisos del usuario
    m_appuser.fillPermissions(m_dlSystem);

    m_principalnotificator = new JPrincipalNotificator();

    m_actionfirst = null;
    m_jLastView = null;
    m_aPreparedViews = new HashMap<String, JPanelView>();
    m_aCreatedViews = new HashMap<String, JPanelView>();

    initComponents();

    // m_jPanelTitle.setUI(new GradientUI());
    m_jPanelTitle.setBorder(RoundedBorder.createGradientBorder());
    m_jPanelTitle.setVisible(false);

    // Anado el panel nulo
    m_jPanelContainer.add(new JPanel(), "<NULL>");
    showView("<NULL>");

    try {

      ScriptMenu menu = new ScriptMenu();

      ScriptEngine eng = ScriptFactory.getScriptEngine(ScriptFactory.BEANSHELL);
      eng.put("menu", menu);
      eng.eval(m_dlSystem.getResourceAsText("Menu.Root"));

      m_jPanelLeft.setViewportView(menu.getTaskPane());
    } catch (ScriptException e) {
      e.printStackTrace();
      // Error Message
    }
  }
  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);
      }
    }
  }
  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);
        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
  private void printPayments(String report) {

    String sresource = m_dlSystem.getResourceAsXML(report);
    if (sresource == null) {
      MessageInf msg =
          new MessageInf(
              MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotprintticket"));
      msg.show(this);
    } else {
      try {
        ScriptEngine script = ScriptFactory.getScriptEngine(ScriptFactory.VELOCITY);
        script.put("payments", m_PaymentsToClose);
        m_TTP.printTicket(script.eval(sresource).toString());
        // JG 16 May 2012 use multicatch
      } catch (ScriptException | TicketPrinterException e) {
        MessageInf msg =
            new MessageInf(
                MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotprintticket"), e);
        msg.show(this);
      }
    }
  }