// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2013 uniCenta & previous Openbravo POS works
// http://www.unicenta.net/unicentaopos
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS 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.
//
// uniCenta oPOS 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 uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.openbravo.pos.sales.restaurant;
import bsh.Interpreter;
import bsh.EvalError;
import com.openbravo.data.gui.JMessageDialog;
import com.openbravo.data.gui.ListKeyed;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.loader.SentenceList;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppView;
import com.openbravo.pos.forms.DataLogicSystem;
import com.openbravo.pos.forms.JRootApp;
import com.openbravo.pos.printer.DeviceTicket;
import com.openbravo.pos.printer.TicketParser;
import com.openbravo.pos.printer.TicketPrinterException;
import com.openbravo.pos.sales.JPanelTicket;
import com.openbravo.pos.sales.TaxesLogic;
import com.openbravo.pos.scripting.ScriptEngine;
import com.openbravo.pos.scripting.ScriptException;
import com.openbravo.pos.scripting.ScriptFactory;
import com.openbravo.pos.ticket.TicketInfo;
import com.openbravo.pos.ticket.TicketLineInfo;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
public class JTicketsBagRestaurant extends javax.swing.JPanel {
private AppView m_App;
private JTicketsBagRestaurantMap m_restaurant;
private List<TicketLineInfo> m_aLines;
private TicketLineInfo line;
private TicketInfo ticket;
private Object ticketExt;
private DataLogicSystem m_dlSystem = null;
private DeviceTicket m_TP;
private TicketParser m_TTP2;
private RestaurantDBUtils restDB;
private DataLogicSystem dlSystem = null;
private TicketParser m_TTP;
private SentenceList senttax;
private ListKeyed taxcollection;
private TaxesLogic taxeslogic;
private Interpreter i;
/** Creates new form JTicketsBagRestaurantMap */
public JTicketsBagRestaurant(AppView app, JTicketsBagRestaurantMap restaurant) {
super();
m_App = app;
m_restaurant = restaurant;
initComponents();
// Added by JDL for kitchen printer
ticketExt = null;
restDB = new RestaurantDBUtils(m_App);
m_dlSystem = (DataLogicSystem) m_App.getBean("com.openbravo.pos.forms.DataLogicSystem");
m_TP = new DeviceTicket();
m_TTP2 = new TicketParser(m_App.getDeviceTicket(), m_dlSystem);
// j_btnKitchenPrt.setVisible(m_App.getAppUserView().getUser().hasPermission("sales.PrintKitchen"));
j_btnKitchenPrt.setVisible(false);
}
public void activate() {
// Authorization
m_jDelTicket.setEnabled(m_App.getAppUserView().getUser().hasPermission("com.openbravo.pos.sales.JPanelTicketEdits"));
}
public void printTicket(String resource) {
printTicket(resource, ticket, m_restaurant.getTable());
}
private void printTicket(String sresourcename, TicketInfo ticket, String table) {
if (ticket != null) {
try {
ScriptEngine script = ScriptFactory.getScriptEngine(ScriptFactory.VELOCITY);
script.put("ticket", ticket);
script.put("place",m_restaurant.getTableName());
m_TTP2.printTicket(script.eval(m_dlSystem.getResourceAsXML(sresourcename)).toString());
} catch ( ScriptException | TicketPrinterException e) {
JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("message.cannotprint"), e));
}
}
}
/** 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() {
m_jDelTicket = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
j_btnKitchenPrt = new javax.swing.JButton();
setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
setMinimumSize(new java.awt.Dimension(250, 50));
setPreferredSize(new java.awt.Dimension(250, 50));
setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
m_jDelTicket.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/sale_delete.png"))); // NOI18N
m_jDelTicket.setToolTipText("Delete Current Order");
m_jDelTicket.setFocusPainted(false);
m_jDelTicket.setFocusable(false);
m_jDelTicket.setMargin(new java.awt.Insets(0, 4, 0, 4));
m_jDelTicket.setMaximumSize(new java.awt.Dimension(50, 40));
m_jDelTicket.setMinimumSize(new java.awt.Dimension(50, 40));
m_jDelTicket.setPreferredSize(new java.awt.Dimension(50, 40));
m_jDelTicket.setRequestFocusEnabled(false);
m_jDelTicket.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
m_jDelTicketActionPerformed(evt);
}
});
add(m_jDelTicket);
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/movetable.png"))); // NOI18N
jButton2.setToolTipText("Move Table");
jButton2.setFocusPainted(false);
jButton2.setFocusable(false);
jButton2.setMargin(new java.awt.Insets(0, 4, 0, 4));
jButton2.setMaximumSize(new java.awt.Dimension(50, 40));
jButton2.setMinimumSize(new java.awt.Dimension(50, 40));
jButton2.setPreferredSize(new java.awt.Dimension(50, 40));
jButton2.setRequestFocusEnabled(false);
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
add(jButton2);
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/tables.png"))); // NOI18N
jButton1.setToolTipText("Go to Table Plan");
jButton1.setFocusPainted(false);
jButton1.setFocusable(false);
jButton1.setMargin(new java.awt.Insets(0, 4, 0, 4));
jButton1.setMaximumSize(new java.awt.Dimension(50, 40));
jButton1.setMinimumSize(new java.awt.Dimension(50, 40));
jButton1.setPreferredSize(new java.awt.Dimension(50, 40));
jButton1.setRequestFocusEnabled(false);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
add(jButton1);
j_btnKitchenPrt.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/printer24.png"))); // NOI18N
j_btnKitchenPrt.setToolTipText("Send to Kichen Printer");
j_btnKitchenPrt.setMargin(new java.awt.Insets(0, 4, 0, 4));
j_btnKitchenPrt.setMaximumSize(new java.awt.Dimension(50, 40));
j_btnKitchenPrt.setMinimumSize(new java.awt.Dimension(50, 40));
j_btnKitchenPrt.setPreferredSize(new java.awt.Dimension(50, 40));
j_btnKitchenPrt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
j_btnKitchenPrtActionPerformed(evt);
}
});
add(j_btnKitchenPrt);
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
restDB.setTableMovedFlag(m_restaurant.getTable());
m_restaurant.moveTicket();
}//GEN-LAST:event_jButton2ActionPerformed
@SuppressWarnings("empty-statement")
private void m_jDelTicketActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jDelTicketActionPerformed
int res = JOptionPane.showConfirmDialog(this, AppLocal.getIntString("message.wannadelete"), AppLocal.getIntString("title.editor"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (res == JOptionPane.YES_OPTION) {
restDB.clearCustomerNameInTableById(m_restaurant.getTable()); ;
restDB.clearWaiterNameInTableById(m_restaurant.getTable());
restDB.clearTicketIdInTableById(m_restaurant.getTable());
m_restaurant.deleteTicket();
}
}//GEN-LAST:event_m_jDelTicketActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
m_restaurant.newTicket();
}//GEN-LAST:event_jButton1ActionPerformed
@SuppressWarnings("empty-statement")
private void j_btnKitchenPrtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_j_btnKitchenPrtActionPerformed
// This replaces the code from the buttons script
ticket = m_restaurant.getActiveTicket();
String rScript = (m_dlSystem.getResourceAsText("script.SendOrder"));
Interpreter i = new Interpreter();
try {
i.set("ticket", ticket);
i.set("place",m_restaurant.getTableName());
i.set("user", m_App.getAppUserView().getUser());
i.set("sales", this);
Object result = i.eval(rScript);
} catch (EvalError ex) {
Logger.getLogger(JPanelTicket.class.getName()).log(Level.SEVERE, null, ex);
}
// Autologoff after sales
String autoLogoff = (m_App.getProperties().getProperty("till.autoLogoff"));
String autoLogoffRestaurant =(m_App.getProperties().getProperty("till.autoLogoffrestaurant"));
if (autoLogoff != null){
if (autoLogoff.equals("true")){
// check how far to logoof to ie tables or application
if (autoLogoffRestaurant == null){
((JRootApp)m_App).closeAppView();
}else if (autoLogoffRestaurant.equals("true")){
m_restaurant.newTicket();
}else{
((JRootApp)m_App).closeAppView();
}
}
}
}//GEN-LAST:event_j_btnKitchenPrtActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton j_btnKitchenPrt;
private javax.swing.JButton m_jDelTicket;
// End of variables declaration//GEN-END:variables
}