Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

// JavaScript

// script.linediscount (replaced text resource)


// This script applies UsersInput% Discount for the Item Line value
// Compatible with Category Sales Report
// Added user confirmation dialog and fixed checking of discountrate argument
//
// Maintenance -> Roles -> User -> <class name="button.linediscount"/>
// Maintenance -> Resources -> Ticket.Buttons -> <button key="button.linediscount"
image="img.linediscount" code="script.linediscount"/>
// Maintenance -> Resources -> img.linediscount -> Use custom button image for Line
Discount

import com.openbravo.format.Formats;
import com.openbravo.pos.ticket.TicketLineInfo;
import com.openbravo.pos.ticket.TicketProductInfo;

discountrate = 1 - (sales.getInputValue() / 100.0);

sdiscount = Formats.PERCENT.formatValue((1-discountrate));

index = sales.getSelectedIndex();
if (index >= 0) {
line = ticket.getLine(index);
if (line.getPrice() > 0.0 && sales.getInputValue() > 0.0) {
int reply = JOptionPane.showConfirmDialog(null, "Aplicar descuento a
esta línea?\n" + line.getProductName() + " -" + sdiscount, "Aprobar descuento",
JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION) {
ticket.setLine(index,
new TicketLineInfo(
line.getProductID(),
line.getProductName() + " -" + sdiscount,
line.getProductTaxCategoryID(),
line.getMultiply(),
line.getPrice () * discountrate,
line.getTaxInfo()));
} else if (reply == JOptionPane.NO_OPTION) {
}
} else {
java.awt.Toolkit.getDefaultToolkit().beep();
}
} else {
java.awt.Toolkit.getDefaultToolkit().beep();
}

You might also like