fixing totalDiscount
This commit is contained in:
@@ -36,15 +36,16 @@ if (index >= 0) {
|
|||||||
sdiscount = Formats.PERCENT.formatValue((discountrate));
|
sdiscount = Formats.PERCENT.formatValue((discountrate));
|
||||||
for (int number= 0; number < ticket.getLinesCount(); number++) {
|
for (int number= 0; number < ticket.getLinesCount(); number++) {
|
||||||
line = ticket.getLine(number);
|
line = ticket.getLine(number);
|
||||||
ticket.setLine(number,
|
TicketLineInfo ticketLineInfo = new TicketLineInfo(
|
||||||
new TicketLineInfo(
|
line.getProductID(),
|
||||||
line.getProductID(),
|
line.getProductName() + " - Item Discount @ " + sdiscount,
|
||||||
line.getProductName() + " - Item Discount @ " + sdiscount,
|
line.getProductTaxCategoryID(),
|
||||||
line.getProductTaxCategoryID(),
|
line.getProductPrinter(),
|
||||||
line.getProductPrinter(),
|
line.getMultiply(),
|
||||||
line.getMultiply(),
|
line.getNewPrice() - (double)Math.abs(line.getNewPrice() * discountrate * 100) /100,
|
||||||
line.getNewPrice() - (double)Math.abs(line.getNewPrice() * discountrate * 100) /100,
|
line.getTaxInfo());
|
||||||
line.getTaxInfo()));
|
ticketLineInfo.setTicketUpdated("ticket.updated", "true");
|
||||||
|
ticket.setLine(number,ticketLineInfo);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
java.awt.Toolkit.getDefaultToolkit().beep();
|
java.awt.Toolkit.getDefaultToolkit().beep();
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package com.unicenta.pos.ticket;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class TicketLineInfoTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldSendOrderDiscountToPrinter(){
|
||||||
|
|
||||||
|
String json = getText("src/test/resources/TicketLineInfo.json");
|
||||||
|
assert json != null;
|
||||||
|
TicketLineInfo ticketLineInfo = new Gson().fromJson(json, TicketLineInfo.class);
|
||||||
|
assert ticketLineInfo != null;
|
||||||
|
sendOrderScript(ticketLineInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldSendItemDiscountToPrinter() {
|
||||||
|
String json = getText("src/test/resources/TicketLineInfoOrderDiscount.json");
|
||||||
|
assert json != null;
|
||||||
|
TicketLineInfo ticketLineInfo = new Gson().fromJson(json, TicketLineInfo.class);
|
||||||
|
assert ticketLineInfo != null;
|
||||||
|
sendOrderScript(ticketLineInfo);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendOrderScript(TicketLineInfo line) {
|
||||||
|
boolean printedP1 = false;
|
||||||
|
boolean printedP2 = false;
|
||||||
|
boolean printedP3 = false;
|
||||||
|
boolean printedP4 = false;
|
||||||
|
boolean printedP5 = false;
|
||||||
|
boolean printedP6 = false;
|
||||||
|
|
||||||
|
if (line.getProperty("product.printer")!=null && line.getProperty("ticket.updated")!=null) {
|
||||||
|
|
||||||
|
if (line.getProperty("product.printer").equals("1")) {
|
||||||
|
System.out.print("getting property: ");
|
||||||
|
System.out.println(line.getProperty("ticket.updated").equals("true"));
|
||||||
|
if((printedP1 == false)) {
|
||||||
|
//sales.printTicket("Printer.Ticket.P1");
|
||||||
|
printedP1 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.getProperty("product.printer").equals("2")) {
|
||||||
|
if((printedP2 == false) && line.getProperty("ticket.updated").equals("true")){
|
||||||
|
//sales.printTicket("Printer.Ticket.P2");
|
||||||
|
printedP2 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (line.getProperty("product.printer").equals("3")) {
|
||||||
|
if((printedP3 == false) && line.getProperty("ticket.updated").equals("true")){
|
||||||
|
//sales.printTicket("Printer.Ticket.P3");
|
||||||
|
printedP3 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.getProperty("product.printer").equals("4")) {
|
||||||
|
if((printedP4 == false) && line.getProperty("ticket.updated").equals("true")){
|
||||||
|
//sales.printTicket("Printer.Ticket.P4");
|
||||||
|
printedP4 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (line.getProperty("product.printer").equals("5")) {
|
||||||
|
if((printedP5 == false) && line.getProperty("ticket.updated").equals("true")){
|
||||||
|
//sales.printTicket("Printer.Ticket.P5");
|
||||||
|
printedP5 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.getProperty("product.printer").equals("6")) {
|
||||||
|
if((printedP6 == false) && line.getProperty("ticket.updated").equals("true")){
|
||||||
|
//sales.printTicket("Printer.Ticket.P6");
|
||||||
|
printedP6 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getText(String path) {
|
||||||
|
try {
|
||||||
|
return new String(Files.readAllBytes(Paths.get(path)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"m_sTicket": "8c5bfd03-f4f8-4a3f-b216-57f194e1cda6",
|
||||||
|
"m_iLine": 0,
|
||||||
|
"multiply": 1.0,
|
||||||
|
"price": 8.333333333333334,
|
||||||
|
"tax":
|
||||||
|
{
|
||||||
|
"id": "001",
|
||||||
|
"name": "Tax Standard",
|
||||||
|
"taxcategoryid": "001",
|
||||||
|
"rate": 0.2,
|
||||||
|
"cascade": false
|
||||||
|
},
|
||||||
|
"attributes":
|
||||||
|
{
|
||||||
|
"product.printer": "1",
|
||||||
|
"product.warranty": "false",
|
||||||
|
"product.reference": "123",
|
||||||
|
"product.com": "false",
|
||||||
|
"product.verpatrib": "false",
|
||||||
|
"ticket.updated": "true",
|
||||||
|
"product.name": "Burger",
|
||||||
|
"product.service": "false",
|
||||||
|
"product.categoryid": "000",
|
||||||
|
"product.taxcategoryid": "001",
|
||||||
|
"product.memodate": "1900-01-01 00:00:01",
|
||||||
|
"product.code": "123",
|
||||||
|
"product.vprice": "false",
|
||||||
|
"product.texttip": "",
|
||||||
|
"product.constant": "false"
|
||||||
|
},
|
||||||
|
"productid": "fc33fa54-3af1-486b-85e7-9838160053ea",
|
||||||
|
"updated": false,
|
||||||
|
"newprice": 10.0
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"m_sTicket": "5ff16e4c-0df9-4002-bc54-cc60fce92de2",
|
||||||
|
"m_iLine": 0,
|
||||||
|
"multiply": 1.0,
|
||||||
|
"price": 7.333333333333334,
|
||||||
|
"tax":
|
||||||
|
{
|
||||||
|
"id": "001",
|
||||||
|
"name": "Tax Standard",
|
||||||
|
"taxcategoryid": "001",
|
||||||
|
"rate": 0.2,
|
||||||
|
"cascade": false
|
||||||
|
},
|
||||||
|
"attributes":
|
||||||
|
{
|
||||||
|
"product.taxcategoryid": "001",
|
||||||
|
"product.printer": "1",
|
||||||
|
"product.name": "Burger - Item Discount @ 12%"
|
||||||
|
},
|
||||||
|
"productid": "fc33fa54-3af1-486b-85e7-9838160053ea",
|
||||||
|
"updated": false,
|
||||||
|
"newprice": 0.0
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user