Commit c41cb319 by Tuomas Riihimäki

Bill discounts are calculated wrong.

Discount should be stacked, but multiple discount BillLines were generated
all from the original full price.
1 parent 25472c7f
...@@ -369,9 +369,11 @@ public class BillBean implements BillBeanLocal { ...@@ -369,9 +369,11 @@ public class BillBean implements BillBeanLocal {
} }
bill.getBillLines().add(new BillLine(bill, product, count, foodwave, additionalDescription)); bill.getBillLines().add(new BillLine(bill, product, count, foodwave, additionalDescription));
BigDecimal discountPrice = product.getPrice();
for (Discount disc : discountBean.getActiveDiscountsByProduct(product, count, bill.getSentDate(), bill.getUser())) { for (Discount disc : discountBean.getActiveDiscountsByProduct(product, count, bill.getSentDate(), bill.getUser())) {
bill.getBillLines().add(new BillLine(bill, product, disc, count)); BillLine line = new BillLine(bill, product, disc,discountPrice, count);
discountPrice = discountPrice.subtract(line.getUnitPrice());
bill.getBillLines().add(line);
} }
return bill; return bill;
......
...@@ -157,10 +157,10 @@ public class BillLine extends GenericEntity { ...@@ -157,10 +157,10 @@ public class BillLine extends GenericEntity {
* @param disc * @param disc
* @param count * @param count
*/ */
public BillLine(Bill bill2, Product product, Discount disc, BigDecimal count) { public BillLine(Bill bill2, Product product, Discount disc, BigDecimal price, BigDecimal count) {
super(); super();
this.bill = bill2; this.bill = bill2;
BigDecimal unitPrice = product.getPrice().subtract(product.getPrice().multiply(disc.getPercentage())).negate().setScale(Bill.BILL_PRICE_SCALE, RoundingMode.HALF_UP); BigDecimal unitPrice = price.subtract(price.multiply(disc.getPercentage())).negate().setScale(Bill.BILL_PRICE_SCALE, RoundingMode.HALF_UP);
this.name = disc.getShortdesc(); this.name = disc.getShortdesc();
this.unitName = product.getUnitName(); this.unitName = product.getUnitName();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!