if (customer == null) {
// tables
// check if the sharedticket is the same
TicketInfo ticket = getTicketInfo(m_place);
// check
if (ticket == null && !m_place.hasPeople()) {
// Empty table and checked
// table occupied
ticket = new TicketInfo();
try {
dlReceipts.insertSharedTicket(m_place.getId(), ticket);
} catch (BasicException e) {
new MessageInf(e).show(JTicketsBagRestaurantMap.this); // Glup. But It was empty.
}
m_place.setPeople(true);
setActivePlace(m_place, ticket);
} else if (ticket == null && m_place.hasPeople()) {
// The table is now empty
new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.tableempty")).show(JTicketsBagRestaurantMap.this);
m_place.setPeople(false); // fixed
} else if (ticket != null && !m_place.hasPeople()) {
// The table is now full
new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.tablefull")).show(JTicketsBagRestaurantMap.this);
m_place.setPeople(true);
} else { // both != null
// Full table
// m_place.setPeople(true); // already true
setActivePlace(m_place, ticket);
}
} else {
// receiving customer.
// check if the sharedticket is the same
TicketInfo ticket = getTicketInfo(m_place);
if (ticket == null) {
// receive the customer
// table occupied
ticket = new TicketInfo();
try {
ticket.setCustomer(customer.getId() == null
? null
: dlSales.loadCustomerExt(customer.getId()));
} catch (BasicException e) {
MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotfindcustomer"), e);
msg.show(JTicketsBagRestaurantMap.this);
}
try {
dlReceipts.insertSharedTicket(m_place.getId(), ticket);
} catch (BasicException e) {
new MessageInf(e).show(JTicketsBagRestaurantMap.this); // Glup. But It was empty.
}
m_place.setPeople(true);
m_PlaceClipboard = null;
customer = null;
setActivePlace(m_place, ticket);
} else {
// TODO: msg: The table is now full
new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.tablefull")).show(JTicketsBagRestaurantMap.this);
m_place.setPeople(true);
m_place.getButton().setEnabled(false);
}
}
} else {
// check if the sharedticket is the same
TicketInfo ticketclip = getTicketInfo(m_PlaceClipboard);
if (ticketclip == null) {
new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.tableempty")).show(JTicketsBagRestaurantMap.this);
m_PlaceClipboard.setPeople(false);
m_PlaceClipboard = null;
customer = null;
printState();
} else {
// tenemos que copiar el ticket del clipboard
if (m_PlaceClipboard == m_place) {
// the same button. Canceling.
Place placeclip = m_PlaceClipboard;
m_PlaceClipboard = null;
customer = null;
printState();
setActivePlace(placeclip, ticketclip);
} else if (!m_place.hasPeople()) {
// Moving the receipt to an empty table
TicketInfo ticket = getTicketInfo(m_place);
if (ticket == null) {
try {
dlReceipts.insertSharedTicket(m_place.getId(), ticketclip);
m_place.setPeople(true);
dlReceipts.deleteSharedTicket(m_PlaceClipboard.getId());
m_PlaceClipboard.setPeople(false);
} catch (BasicException e) {
new MessageInf(e).show(JTicketsBagRestaurantMap.this); // Glup. But It was empty.
}
m_PlaceClipboard = null;
customer = null;
printState();
// No hace falta preguntar si estaba bloqueado porque ya lo estaba antes
// activamos el ticket seleccionado
setActivePlace(m_place, ticketclip);
} else {
// Full table
new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.tablefull")).show(JTicketsBagRestaurantMap.this);
m_PlaceClipboard.setPeople(true);
printState();
}
} else {
// Merge the lines with the receipt of the table
TicketInfo ticket = getTicketInfo(m_place);
if (ticket == null) {
// The table is now empty
new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.tableempty")).show(JTicketsBagRestaurantMap.this);
m_place.setPeople(false); // fixed
} else {
//asks if you want to merge tables
if (JOptionPane.showConfirmDialog(JTicketsBagRestaurantMap.this, AppLocal.getIntString("message.mergetablequestion"), AppLocal.getIntString("message.mergetable"), JOptionPane.YES_NO_OPTION)
== JOptionPane.YES_OPTION){
// merge lines ticket
try {
dlReceipts.deleteSharedTicket(m_PlaceClipboard.getId());
m_PlaceClipboard.setPeople(false);
if (ticket.getCustomer() == null) {
ticket.setCustomer(ticketclip.getCustomer());
}
for(TicketLineInfo line : ticketclip.getLines()) {
ticket.addLine(line);
}
dlReceipts.updateSharedTicket(m_place.getId(), ticket);
} catch (BasicException e) {
new MessageInf(e).show(JTicketsBagRestaurantMap.this); // Glup. But It was empty.
}