Commit 44b92701 by Tuukka Kivilahti

user.getRoles() -> UserBean.findUsersRoles(user)

1 parent df16c9aa
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import java.io.OutputStream; import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
...@@ -27,7 +29,9 @@ import fi.codecrew.moya.facade.EventUserFacade; ...@@ -27,7 +29,9 @@ import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.model.AccountEvent; import fi.codecrew.moya.model.AccountEvent;
import fi.codecrew.moya.model.Bill; import fi.codecrew.moya.model.Bill;
import fi.codecrew.moya.model.BillLine; import fi.codecrew.moya.model.BillLine;
import fi.codecrew.moya.model.Discount;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.FoodWave;
import fi.codecrew.moya.model.LanEvent; import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LanEventPropertyKey; import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.Product; import fi.codecrew.moya.model.Product;
...@@ -68,6 +72,9 @@ public class BillBean implements BillBeanLocal { ...@@ -68,6 +72,9 @@ public class BillBean implements BillBeanLocal {
private EventUserFacade eventUserFacade; private EventUserFacade eventUserFacade;
@EJB @EJB
private ProductPBean productPBean; private ProductPBean productPBean;
@EJB
private DiscountBean discountBean;
/** /**
* Default constructor. * Default constructor.
...@@ -304,5 +311,38 @@ public class BillBean implements BillBeanLocal { ...@@ -304,5 +311,38 @@ public class BillBean implements BillBeanLocal {
bill.markExpired(); bill.markExpired();
return bill; return bill;
} }
@Override
public Bill addProductToBill(Bill bill, Product product, BigDecimal count) {
return this.addProductToBill(bill, product, count, null);
}
@Override
public Bill addProductToBill(Bill bill, Product product, BigDecimal count, FoodWave foodwave) {
// If bill number > 0 bill has been sent and extra privileges are needed
// to modify.
// if (!iscurrent || billnr != null) {
// permbean.fatalPermission(BillPermission.WRITE_ALL,
// "User tried to modify bill ", bill,
// "without sufficient permissions");
// }
if (bill.getBillLines() == null) {
bill.setBillLines(new ArrayList<BillLine>());
}
bill.getBillLines().add(new BillLine(bill, product, count, foodwave));
for (Discount disc : discountBean.getActiveDiscountsByProduct(product, count, bill.getSentDate(), bill.getUser())) {
bill.getBillLines().add(new BillLine(bill, product, disc, count));
}
return bill;
}
} }
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import fi.codecrew.moya.facade.DiscountFacade; import fi.codecrew.moya.facade.DiscountFacade;
import fi.codecrew.moya.facade.EventFacade;
import fi.codecrew.moya.facade.ProductFacade;
import fi.codecrew.moya.beans.DiscountBeanLocal;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.Discount; import fi.codecrew.moya.model.Discount;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.Role;
/** /**
* Session Bean implementation class DiscountBean * Session Bean implementation class DiscountBean
*/ */
@Stateless @Stateless
@LocalBean
public class DiscountBean implements DiscountBeanLocal { public class DiscountBean implements DiscountBeanLocal {
@EJB @EJB
private DiscountFacade discountfacade; private DiscountFacade discountfacade;
@EJB @EJB
private EventBeanLocal eventbean; private UserBean userBean;
@EJB
private ProductFacade productfacade;
@EJB
private EventFacade eventfacade;
public DiscountBean() { public DiscountBean() {
} }
...@@ -36,6 +39,35 @@ public class DiscountBean implements DiscountBeanLocal { ...@@ -36,6 +39,35 @@ public class DiscountBean implements DiscountBeanLocal {
return ret; return ret;
} }
@Override
public List<Discount> getActiveDiscountsByProduct(Product product, BigDecimal quantity, Calendar time, EventUser user) {
ArrayList<Discount> ret = new ArrayList<Discount>();
for (Discount d : product.getDiscounts()) {
if (d.isActive() &&
(d.getValidTo() == null || d.getValidTo().after(time)) &&
(d.getValidFrom() == null || d.getValidFrom().before(time)) &&
(d.getAmountMax().compareTo(BigDecimal.ZERO) == 0 || quantity.compareTo(d.getAmountMax()) <= 0) &&
(d.getAmountMin().compareTo(BigDecimal.ZERO) == 0 || quantity.compareTo(d.getAmountMin()) >= 0)) {
// plaah, there is role, must do stuff
if (d.getRole() != null) {
for (Role role : userBean.localFindUsersRoles(user)) {
if (d.getRole().equals(role)) {
ret.add(d);
}
}
} else {
ret.add(d);
}
}
}
return ret;
}
// @Override // @Override
// public Discount create(String discountdesc) { // public Discount create(String discountdesc) {
// LanEvent ev = eventbean.getCurrentEvent(); // LanEvent ev = eventbean.getCurrentEvent();
......
...@@ -91,6 +91,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -91,6 +91,7 @@ public class ProductBean implements ProductBeanLocal {
private EventBeanLocal eventbean; private EventBeanLocal eventbean;
@EJB @EJB
private BillLineFacade billLineFacade; private BillLineFacade billLineFacade;
@EJB @EJB
private ProductPBean productPBean; private ProductPBean productPBean;
...@@ -99,6 +100,9 @@ public class ProductBean implements ProductBeanLocal { ...@@ -99,6 +100,9 @@ public class ProductBean implements ProductBeanLocal {
@EJB @EJB
private PlaceBean placebean; private PlaceBean placebean;
@EJB
private DiscountBean discountBean;
private static final Logger logger = LoggerFactory.getLogger(ProductBean.class); private static final Logger logger = LoggerFactory.getLogger(ProductBean.class);
...@@ -290,7 +294,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -290,7 +294,7 @@ public class ProductBean implements ProductBeanLocal {
throw new RuntimeException("Some parameter is null!"); throw new RuntimeException("Some parameter is null!");
} }
BigDecimal total = product.getPrice(); BigDecimal total = product.getPrice();
for (Discount d : product.getActiveDiscounts(quantity, date, user)) { for (Discount d : discountBean.getActiveDiscountsByProduct(product, quantity, date, user)) {
total = total.multiply(d.getPercentage()); total = total.multiply(d.getPercentage());
} }
return total.setScale(2, RoundingMode.HALF_UP).multiply(quantity); return total.setScale(2, RoundingMode.HALF_UP).multiply(quantity);
......
...@@ -30,6 +30,9 @@ public class ProductPBean { ...@@ -30,6 +30,9 @@ public class ProductPBean {
@EJB @EJB
private PermissionBean permbean; private PermissionBean permbean;
@EJB
private DiscountBean discountBean;
@EJB @EJB
private AccountEventFacade accounteventfacade; private AccountEventFacade accounteventfacade;
private static final Logger logger = LoggerFactory private static final Logger logger = LoggerFactory
...@@ -73,7 +76,7 @@ public class ProductPBean { ...@@ -73,7 +76,7 @@ public class ProductPBean {
} }
BigDecimal unitPrice = product.getPrice().negate(); BigDecimal unitPrice = product.getPrice().negate();
List<Discount> discounts = product.getActiveDiscounts(quantity, date, user); List<Discount> discounts = discountBean.getActiveDiscountsByProduct(product, quantity, date, user);
for (Discount d : discounts) { for (Discount d : discounts) {
unitPrice = unitPrice.multiply(d.getPercentage()); unitPrice = unitPrice.multiply(d.getPercentage());
} }
......
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import java.io.OutputStream; import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
...@@ -10,6 +11,8 @@ import javax.ejb.Local; ...@@ -10,6 +11,8 @@ import javax.ejb.Local;
import fi.codecrew.moya.bortal.views.BillSummary; import fi.codecrew.moya.bortal.views.BillSummary;
import fi.codecrew.moya.model.Bill; import fi.codecrew.moya.model.Bill;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.FoodWave;
import fi.codecrew.moya.model.Product;
@Local @Local
public interface BillBeanLocal { public interface BillBeanLocal {
...@@ -37,5 +40,9 @@ public interface BillBeanLocal { ...@@ -37,5 +40,9 @@ public interface BillBeanLocal {
List<Bill> find(EventUser user); List<Bill> find(EventUser user);
Bill expireBill(Bill bill); Bill expireBill(Bill bill);
Bill addProductToBill(Bill bill, Product product, BigDecimal count, FoodWave foodwave);
Bill addProductToBill(Bill bill, Product product, BigDecimal count);
} }
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.List;
import javax.ejb.Local; import javax.ejb.Local;
import fi.codecrew.moya.model.Discount; import fi.codecrew.moya.model.Discount;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Product;
@Local @Local
public interface DiscountBeanLocal { public interface DiscountBeanLocal {
Discount save(Discount discount); Discount save(Discount discount);
public List<Discount> getActiveDiscountsByProduct(Product product, BigDecimal quantity, Calendar time, EventUser user);
} }
...@@ -347,28 +347,6 @@ public class Bill extends GenericEntity { ...@@ -347,28 +347,6 @@ public class Bill extends GenericEntity {
return delayIntrest; return delayIntrest;
} }
public void addProduct(Product product, BigDecimal count) {
this.addProduct(product, count, null);
}
public void addProduct(Product product, BigDecimal count, FoodWave foodwave) {
// If bill number > 0 bill has been sent and extra privileges are needed
// to modify.
// if (!iscurrent || billnr != null) {
// permbean.fatalPermission(BillPermission.WRITE_ALL,
// "User tried to modify bill ", bill,
// "without sufficient permissions");
// }
if (this.billLines == null) {
billLines = new ArrayList<BillLine>();
}
this.getBillLines().add(new BillLine(this, product, count, foodwave));
for (Discount disc : product.getActiveDiscounts(count, sentDate, this.getUser())) {
this.getBillLines().add(new BillLine(this, product, disc, count));
}
}
public void setBillNumber(Integer billNumber) { public void setBillNumber(Integer billNumber) {
this.billNumber = billNumber; this.billNumber = billNumber;
} }
......
...@@ -162,34 +162,6 @@ public class Product extends GenericEntity { ...@@ -162,34 +162,6 @@ public class Product extends GenericEntity {
return tot; return tot;
} }
// TODO: alennukset lasketaan täällä. HUOMHUOM!!
// Oikea paikka ois joku kaunis bean, mutta ehkä enskerralla voin
// refactoroida
// tai si sitäseuraavalla -TKjne
public List<Discount> getActiveDiscounts(BigDecimal quantity, Calendar time, EventUser user) {
ArrayList<Discount> ret = new ArrayList<Discount>();
for (Discount d : getDiscounts()) {
if (d.isActive() &&
(d.getValidTo() == null || d.getValidTo().after(time)) &&
(d.getValidFrom() == null || d.getValidFrom().before(time)) &&
(d.getAmountMax().compareTo(BigDecimal.ZERO) == 0 || quantity.compareTo(d.getAmountMax()) <= 0) &&
(d.getAmountMin().compareTo(BigDecimal.ZERO) == 0 || quantity.compareTo(d.getAmountMin()) >= 0)) {
// plaah, there is role, must do magic
if (d.getRole() != null) {
for (Role role : user.getRoles()) {
if (d.getRole().equals(role)) {
ret.add(d);
}
}
} else {
ret.add(d);
}
}
}
return ret;
}
public BigDecimal getInventoryCount() { public BigDecimal getInventoryCount() {
BigDecimal ret = new BigDecimal(0); BigDecimal ret = new BigDecimal(0);
......
...@@ -40,10 +40,9 @@ ...@@ -40,10 +40,9 @@
<h:commandButton action="#{productShopView.addMinusOne}" value="#{i18n['productshop.minusOne']}"> <h:commandButton action="#{productShopView.addMinusOne}" value="#{i18n['productshop.minusOne']}">
<f:ajax render="@form" /> <f:ajax render="@form" />
</h:commandButton> </h:commandButton>
<h:inputText size="4" id="cartcount" value="#{cart.count}"> <h:outputText id="cartcount" escape="false" value="&nbsp;&nbsp;#{cart.count}&nbsp;&nbsp;">
<f:convertNumber maxIntegerDigits="2" minFractionDigits="0" /> <f:convertNumber maxIntegerDigits="2" minFractionDigits="0" />
<f:ajax render="@form" event="valueChange" listener="#{productShopView.updateAllCartLimits()}" /> </h:outputText>
</h:inputText>
<h:commandButton action="#{productShopView.addOne}" value="#{i18n['productshop.plusOne']}"> <h:commandButton action="#{productShopView.addOne}" value="#{i18n['productshop.plusOne']}">
<f:ajax render="@form" /> <f:ajax render="@form" />
</h:commandButton> </h:commandButton>
......
...@@ -23,6 +23,7 @@ import fi.codecrew.moya.model.FoodWave; ...@@ -23,6 +23,7 @@ import fi.codecrew.moya.model.FoodWave;
import fi.codecrew.moya.model.Product; import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.cdiview.user.UserView; import fi.codecrew.moya.web.cdiview.user.UserView;
import fi.codecrew.moya.web.helper.ProductShopItemHelper;
import fi.codecrew.moya.web.helpers.ProductShopItem; import fi.codecrew.moya.web.helpers.ProductShopItem;
@Named @Named
...@@ -36,6 +37,9 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -36,6 +37,9 @@ public class FoodWaveFoodView extends GenericCDIView {
@EJB @EJB
private FoodWaveBeanLocal foodWaveBean; private FoodWaveBeanLocal foodWaveBean;
@Inject
private ProductShopItemHelper psiHelper;
@EJB @EJB
EventBeanLocal eventBean; EventBeanLocal eventBean;
...@@ -99,7 +103,8 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -99,7 +103,8 @@ public class FoodWaveFoodView extends GenericCDIView {
public String add(Integer count) { public String add(Integer count) {
ProductShopItem item = getShoppingcart().getRowData(); ProductShopItem item = getShoppingcart().getRowData();
item.setCount(item.getCount().add(BigDecimal.valueOf(count))); psiHelper.setProductShopItemCount(item, item.getCount().add(BigDecimal.valueOf(count)));
System.out.println("foobar" + item.getCount()); System.out.println("foobar" + item.getCount());
return null; return null;
} }
...@@ -133,7 +138,7 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -133,7 +138,7 @@ public class FoodWaveFoodView extends GenericCDIView {
for (ProductShopItem shopitem : shoppingcart) { for (ProductShopItem shopitem : shoppingcart) {
if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) { if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) {
bill.addProduct(shopitem.getProduct(), shopitem.getCount(), getFoodWave()); billBean.addProductToBill(bill, shopitem.getProduct(), shopitem.getCount(), getFoodWave());
} }
} }
logger.warn("Committing shoppingcart for user {}. Cart prize: {}", userview.getSelectedUser().getWholeName(), bill.getTotalPrice()); logger.warn("Committing shoppingcart for user {}. Cart prize: {}", userview.getSelectedUser().getWholeName(), bill.getTotalPrice());
...@@ -198,4 +203,12 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -198,4 +203,12 @@ public class FoodWaveFoodView extends GenericCDIView {
this.billEditView = billEditView; this.billEditView = billEditView;
} }
public ProductShopItemHelper getPsiHelper() {
return psiHelper;
}
public void setPsiHelper(ProductShopItemHelper psiHelper) {
this.psiHelper = psiHelper;
}
} }
...@@ -31,6 +31,7 @@ import fi.codecrew.moya.web.annotations.SelectedUser; ...@@ -31,6 +31,7 @@ import fi.codecrew.moya.web.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.cdiview.reader.ReaderView; import fi.codecrew.moya.web.cdiview.reader.ReaderView;
import fi.codecrew.moya.web.cdiview.user.UserView; import fi.codecrew.moya.web.cdiview.user.UserView;
import fi.codecrew.moya.web.helper.ProductShopItemHelper;
import fi.codecrew.moya.web.helpers.ProductShopItem; import fi.codecrew.moya.web.helpers.ProductShopItem;
@Named @Named
...@@ -53,6 +54,8 @@ public class ProductShopView extends GenericCDIView { ...@@ -53,6 +54,8 @@ public class ProductShopView extends GenericCDIView {
@EJB @EJB
private transient EventBeanLocal eventbean; private transient EventBeanLocal eventbean;
public void cashChanged() public void cashChanged()
{ {
payInstant = false; payInstant = false;
...@@ -78,6 +81,18 @@ public class ProductShopView extends GenericCDIView { ...@@ -78,6 +81,18 @@ public class ProductShopView extends GenericCDIView {
@Inject @Inject
private BillEditView billEditView; private BillEditView billEditView;
@Inject
private ProductShopItemHelper psiHelper;
public ProductShopItemHelper getPsiHelper() {
return psiHelper;
}
public void setPsiHelper(ProductShopItemHelper psiHelper) {
this.psiHelper = psiHelper;
}
private boolean hasLimits = false; private boolean hasLimits = false;
private boolean blip = false; private boolean blip = false;
private ListDataModel<ProductShopItem> boughtItems; private ListDataModel<ProductShopItem> boughtItems;
...@@ -151,7 +166,8 @@ public class ProductShopView extends GenericCDIView { ...@@ -151,7 +166,8 @@ public class ProductShopView extends GenericCDIView {
public String add(Integer count) { public String add(Integer count) {
ProductShopItem item = shoppingcart.getRowData(); ProductShopItem item = shoppingcart.getRowData();
item.setCount(item.getCount().add(BigDecimal.valueOf(count)));
psiHelper.setProductShopItemCount(item, item.getCount().add(BigDecimal.valueOf(count)));
updateCartLimits(item); updateCartLimits(item);
return null; return null;
...@@ -196,7 +212,7 @@ public class ProductShopView extends GenericCDIView { ...@@ -196,7 +212,7 @@ public class ProductShopView extends GenericCDIView {
// Update the updated cart first // Update the updated cart first
if (item != null) { if (item != null) {
BigDecimal l = limits.get(item.getProduct().getId()); BigDecimal l = limits.get(item.getProduct().getId());
if (item.updateLimit(l)) { if (psiHelper.updateProductShopItemLimit(item, l)) {
updateCartLimits(null); updateCartLimits(null);
return; return;
} }
...@@ -207,14 +223,16 @@ public class ProductShopView extends GenericCDIView { ...@@ -207,14 +223,16 @@ public class ProductShopView extends GenericCDIView {
if (l != null) { if (l != null) {
hasLimits = true; hasLimits = true;
} }
n.updateLimit(l);
psiHelper.updateProductShopItemLimit(n,l);
} }
} }
public String removeBought() { public String removeBought() {
ProductShopItem row = boughtItems.getRowData(); ProductShopItem row = boughtItems.getRowData();
row.setCount(row.getCount().subtract(BigDecimal.ONE));
psiHelper.setProductShopItemCount(row, row.getCount().subtract(BigDecimal.ONE));
updateCartLimits(row); updateCartLimits(row);
return null; return null;
...@@ -284,7 +302,7 @@ public class ProductShopView extends GenericCDIView { ...@@ -284,7 +302,7 @@ public class ProductShopView extends GenericCDIView {
for (ProductShopItem shopitem : shoppingcart) { for (ProductShopItem shopitem : shoppingcart) {
if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) { if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) {
bill.addProduct(shopitem.getProduct(), shopitem.getCount()); billbean.addProductToBill(bill, shopitem.getProduct(), shopitem.getCount());
} }
} }
billbean.createBill(bill); billbean.createBill(bill);
......
package fi.codecrew.moya.web.helper;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.HashMap;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.DiscountBeanLocal;
import fi.codecrew.moya.model.Discount;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.helpers.ProductShopItem;
@Named
@ConversationScoped
public class ProductShopItemHelper extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = 1L;
@EJB
private DiscountBeanLocal discountBean;
public void setProductShopItemCount(ProductShopItem item, BigDecimal count) {
if (count == null || count.compareTo(BigDecimal.ZERO) < 0)
{
count = BigDecimal.ZERO;
}
item.setInternalCount(count);
item.setInternalPrice(item.getProduct().getPrice().abs().multiply(count));
item.setInternalDiscounts(discountBean.getActiveDiscountsByProduct(item.getProduct(),count, Calendar.getInstance(), item.getUser()) );
item.setInternalDiscountValues(new HashMap<Integer, BigDecimal>());
for (Discount d : item.getDiscounts())
{
BigDecimal newprice = item.getPrice().multiply(d.getPercentage());
item.getInternalDiscountValues().put(d.getId(), item.getPrice().subtract(newprice));
item.setInternalPrice(newprice);
}
}
public boolean updateProductShopItemLimit(ProductShopItem item, BigDecimal limitValue) {
if (limitValue != null && limitValue.compareTo(BigDecimal.ZERO) < 0)
{
this.setProductShopItemCount(item, item.getCount().add(limitValue));
if (item.getCount().compareTo(BigDecimal.ZERO) < 0) {
this.setProductShopItemCount(item,BigDecimal.ZERO);
}
item.setLimit(BigDecimal.ZERO);
return true;
}
item.setLimit(limitValue);
return false;
}
}
...@@ -2,8 +2,6 @@ package fi.codecrew.moya.web.helpers; ...@@ -2,8 +2,6 @@ package fi.codecrew.moya.web.helpers;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -25,7 +23,6 @@ public class ProductShopItem { ...@@ -25,7 +23,6 @@ public class ProductShopItem {
private BigDecimal price; private BigDecimal price;
private BigDecimal limit; private BigDecimal limit;
private EventUser user; private EventUser user;
public BigDecimal getCreditPrice() public BigDecimal getCreditPrice()
{ {
...@@ -50,7 +47,8 @@ public class ProductShopItem { ...@@ -50,7 +47,8 @@ public class ProductShopItem {
this.user = user; this.user = user;
this.product = prod; this.product = prod;
id = this.product.getId(); id = this.product.getId();
setCount(BigDecimal.ZERO); setInternalCount(BigDecimal.ZERO);
setInternalPrice(BigDecimal.ZERO);
} }
/** /**
...@@ -83,36 +81,35 @@ public class ProductShopItem { ...@@ -83,36 +81,35 @@ public class ProductShopItem {
return this.product; return this.product;
} }
public void setCount(BigDecimal count) { /**
* DO NOT USE THIS.
if (count == null || count.compareTo(BigDecimal.ZERO) < 0) *
{ * Use ProductShopIteHelper.setProductShopItemCount instead.
count = BigDecimal.ZERO; * @param count
} */
public void setInternalCount(BigDecimal count) {
this.count = count; this.count = count;
price = product.getPrice().abs().multiply(count);
discounts = product.getActiveDiscounts(count, Calendar.getInstance(), user);
discountValues = new HashMap<Integer, BigDecimal>();
for (Discount d : discounts)
{
BigDecimal newprice = price.multiply(d.getPercentage());
discountValues.put(d.getId(), price.subtract(newprice));
price = newprice;
}
} }
public void setInternalPrice(BigDecimal price) {
this.price = price;
}
public List<Discount> getDiscounts() public List<Discount> getDiscounts()
{ {
return discounts; return discounts;
} }
public void setInternalDiscounts(List<Discount> discounts) {
this.discounts = discounts;
}
public BigDecimal getDiscount(Integer discId) public BigDecimal getDiscount(Integer discId)
{ {
return discountValues.get(discId); return discountValues.get(discId);
} }
public BigDecimal getPrice() public BigDecimal getPrice()
{ {
return price; return price;
...@@ -141,22 +138,6 @@ public class ProductShopItem { ...@@ -141,22 +138,6 @@ public class ProductShopItem {
return limit; return limit;
} }
public boolean updateLimit(BigDecimal limitValue) {
if (limitValue != null && limitValue.compareTo(BigDecimal.ZERO) < 0)
{
logger.info("product limit {}, count {}", limitValue, count);
setCount(getCount().add(limitValue));
if (count.compareTo(BigDecimal.ZERO) < 0) {
setCount(BigDecimal.ZERO);
}
limit = BigDecimal.ZERO;
return true;
}
limit = limitValue;
return false;
}
public EventUser getUser() { public EventUser getUser() {
return user; return user;
} }
...@@ -164,4 +145,12 @@ public class ProductShopItem { ...@@ -164,4 +145,12 @@ public class ProductShopItem {
public void setUser(EventUser user) { public void setUser(EventUser user) {
this.user = user; this.user = user;
} }
public Map<Integer, BigDecimal> getInternalDiscountValues() {
return discountValues;
}
public void setInternalDiscountValues(Map<Integer, BigDecimal> discountValues) {
this.discountValues = discountValues;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!