}//GEN-LAST:event_jButton2ActionPerformed
private void m_jRenduActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jRenduActionPerformed
if (TicketInfo.isWS() && (m_ticket.getStatus() == 0)) {
JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.errorrefund"), AppLocal.getIntString("message.refundnotsynced")));
return;
}
currentCustomer = m_ticket.getCustomer();
double toPay = 0.0;
try {
toPay = currentCustomer.getCurdebt();
} catch (NullPointerException npe) {
}
if (TicketInfo.isWS()) {
//WebService Sync needs remote order ID.
if (m_ticket.getStatus() == 0) {
JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.hastobesynced")));
return;
} else {
toPay = m_ticket.hasToBePaid();
}
} else {
toPay = currentCustomer.getCurdebt();
}
//TODO ROUNDED
long checkPay = Math.round(toPay);
if (checkPay > 0) {
JPaymentSelect paymentdialog;
paymentdialog = JPaymentSelectCustomer.getDialog(this);
paymentdialog.init(m_App);
paymentdialog.setPrintSelected(true);
if (paymentdialog.showDialog(toPay, currentCustomer, null, null)) {
TicketInfo ticket = new TicketInfo();
ticket.setTicketType(TicketInfo.RECEIPT_PAYMENT);
List<PaymentInfo> payments = paymentdialog.getSelectedPayments();
double total = 0.0;
for (PaymentInfo p : payments) {
total += p.getTotal();
m_ticket.getPayments().add(p);
}
payments.add(new PaymentInfoTicket(-total, "debtpaid"));
currentDebt -= total;
ticket.setPayments(payments);
ticket.setUser(m_App.getAppUserView().getUser().getUserInfo());
ticket.setActiveCash(m_App.getActiveCashIndex());
ticket.setDate(new Date());
ticket.setCustomer(currentCustomer);
ticket.setDateReturn(paymentdialog.getrDate());
ticket.setStatus(m_ticket.getStatus());
try {
m_dlSales.saveTicket(ticket, m_App.getInventoryLocation());
} catch (BasicException eData) {
MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("message.nosaveticket"), eData);
msg.show(this);
}
// reload customer
CustomerInfoExt c;
try {
c = m_dlSales.loadCustomerExt(currentCustomer.getId());
if (c == null) {
MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotfindcustomer"));
msg.show(this);
} else {
// editCustomer(c);
}
} catch (BasicException ex) {
c = null;
MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotfindcustomer"), ex);
msg.show(this);
}
m_jRendu.setEnabled(m_ticket != null && (ticket.isPickable()));
if (ticket != null) {
try {
ScriptEngine script = ScriptFactory.getScriptEngine(ScriptFactory.VELOCITY);
script.put("ticket", ticket);
script.put("customer", currentCustomer);
m_TTP2.printTicket(script.eval(m_dlSystem.getResourceAsXML("Printer.CustomerPaid")).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));
}
}
hasDebt();