Commit 48abfe98 by Tuomas Riihimäki

Add possibility to enter product count as a number in user shop.

1 parent fe44ba6d
......@@ -40,13 +40,13 @@
<h:commandButton action="#{productShopView.addMinusOne}" value="#{i18n['productshop.minusOne']}">
<f:ajax render="@form" />
</h:commandButton>
<h:outputText id="cartcount" escape="false" value="&nbsp;&nbsp;#{cart.count}&nbsp;&nbsp;">
<p:inputText size="2" id="cartcount" escape="false" value="#{cart.count}">
<f:ajax render="@form" listener="#{productShopView.countChangeListener}" />
<f:convertNumber maxIntegerDigits="2" minFractionDigits="0" />
</h:outputText>
</p:inputText>
<h:commandButton action="#{productShopView.addOne}" value="#{i18n['productshop.plusOne']}">
<f:ajax render="@form" />
</h:commandButton>
</p:column>
<p:column rendered="#{productShopView.hasLimits}">
<f:facet name="header">
......@@ -57,7 +57,7 @@
</h:outputText>
</p:column>
<p:column>
<h:dataTable border="0" var="disc" value="#{cart.discounts}">
<h:dataTable styleClass="noborderTable" border="0" var="disc" value="#{cart.discounts}">
<p:column>
<h:outputText value="#{disc.shortdesc}" />
</p:column>
......
......@@ -9,6 +9,7 @@ import java.util.Map;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.model.ListDataModel;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -54,8 +55,6 @@ public class ProductShopView extends GenericCDIView {
@EJB
private transient EventBeanLocal eventbean;
public void cashChanged()
{
payInstant = false;
......@@ -81,10 +80,10 @@ public class ProductShopView extends GenericCDIView {
@Inject
private BillEditView billEditView;
@Inject
private ProductShopItemHelper psiHelper;
public ProductShopItemHelper getPsiHelper() {
return psiHelper;
}
......@@ -164,9 +163,17 @@ public class ProductShopView extends GenericCDIView {
}
}
public void countChangeListener(AjaxBehaviorEvent e)
{
ProductShopItem item = shoppingcart.getRowData();
logger.info("Count change from event {}, src {}, from item {}", e, e.getSource(), item.getCount());
psiHelper.setProductShopItemCount(item, item.getCount());
updateCartLimits(item);
}
public String add(Integer count) {
ProductShopItem item = shoppingcart.getRowData();
psiHelper.setProductShopItemCount(item, item.getCount().add(BigDecimal.valueOf(count)));
updateCartLimits(item);
......@@ -223,15 +230,15 @@ public class ProductShopView extends GenericCDIView {
if (l != null) {
hasLimits = true;
}
psiHelper.updateProductShopItemLimit(n,l);
psiHelper.updateProductShopItemLimit(n, l);
}
}
public String removeBought() {
ProductShopItem row = boughtItems.getRowData();
psiHelper.setProductShopItemCount(row, row.getCount().subtract(BigDecimal.ONE));
updateCartLimits(row);
return null;
......@@ -428,8 +435,8 @@ public class ProductShopView extends GenericCDIView {
public String readCode() {
ReaderEvent event = readerView.getReaderEvent();
if(event == null) {
if (event == null) {
return null;
}
......
......@@ -17,49 +17,44 @@ import fi.codecrew.moya.web.helpers.ProductShopItem;
@ConversationScoped
public class ProductShopItemHelper extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = 1L;
@EJB
private DiscountBeanLocal discountBean;
public void setProductShopItemCount(ProductShopItem item, BigDecimal count) {
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);
}
if (count == null || count.compareTo(BigDecimal.ZERO) < 0)
{
count = BigDecimal.ZERO;
}
item.setCount(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);
this.setProductShopItemCount(item, BigDecimal.ZERO);
}
item.setLimit(BigDecimal.ZERO);
return true;
......@@ -68,5 +63,4 @@ public class ProductShopItemHelper extends GenericCDIView {
return false;
}
}
......@@ -47,7 +47,7 @@ public class ProductShopItem {
this.user = user;
this.product = prod;
id = this.product.getId();
setInternalCount(BigDecimal.ZERO);
setCount(BigDecimal.ZERO);
setInternalPrice(BigDecimal.ZERO);
}
......@@ -85,21 +85,26 @@ public class ProductShopItem {
* DO NOT USE THIS.
*
* Use ProductShopIteHelper.setProductShopItemCount instead.
*
* p.s. This still needs to exist because we want to set count from jsf, but
* this value needs to be updated with
* ProductShopIteHelper.setProductShopItemCount
*
* @param count
*/
public void setInternalCount(BigDecimal count) {
public void setCount(BigDecimal count) {
this.count = count;
}
public void setInternalPrice(BigDecimal price) {
this.price = price;
}
public List<Discount> getDiscounts()
{
return discounts;
}
public void setInternalDiscounts(List<Discount> discounts) {
this.discounts = discounts;
}
......@@ -109,7 +114,6 @@ public class ProductShopItem {
return discountValues.get(discId);
}
public BigDecimal getPrice()
{
return price;
......@@ -145,11 +149,11 @@ public class ProductShopItem {
public void setUser(EventUser 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!