Commit 4fb7141b by Tuukka Kivilahti

Merge branch 'shopCountAsValue' into 'master'

Shop Count As Value

Kaupan lukumääräarvojen syöttäminen myös numerona.
Korjattu myös bugi jossa ei voinut ostaa kuin 99 tuotetta.

Kattonut @tkfftk
2 parents 9e7b0f57 6ff1be2d
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
<f:ajax render="@form" /> <f:ajax render="@form" />
</h:commandButton> </h:commandButton>
<h:inputText size="4" id="cartcount" value="#{cart.count}"> <h:inputText size="4" id="cartcount" value="#{cart.count}">
<f:convertNumber maxIntegerDigits="2" minFractionDigits="0" /> <f:convertNumber maxFractionDigits="2" minFractionDigits="0" />
</h:inputText> </h:inputText>
<h:commandButton action="#{foodWaveFoodView.addOne}" <h:commandButton action="#{foodWaveFoodView.addOne}"
value="#{i18n['productshop.plusOne']}"> value="#{i18n['productshop.plusOne']}">
......
...@@ -40,24 +40,24 @@ ...@@ -40,24 +40,24 @@
<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:outputText id="cartcount" escape="false" value="&nbsp;&nbsp;#{cart.count}&nbsp;&nbsp;"> <p:inputText size="2" id="cartcount" escape="false" value="#{cart.count}">
<f:convertNumber maxIntegerDigits="2" minFractionDigits="0" /> <f:ajax render="@form" listener="#{productShopView.countChangeListener}" />
</h:outputText> <f:convertNumber maxFractionDigits="2" minFractionDigits="0" />
</p: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>
</p:column> </p:column>
<p:column rendered="#{productShopView.hasLimits}"> <p:column rendered="#{productShopView.hasLimits}">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['productshop.limits']}" /> <h:outputText value="#{i18n['productshop.limits']}" />
</f:facet> </f:facet>
<h:outputText value="#{cart.limit}"> <h:outputText value="#{cart.limit}">
<f:convertNumber maxIntegerDigits="2" minFractionDigits="0" /> <f:convertNumber maxFractionDigits="2" minFractionDigits="0" />
</h:outputText> </h:outputText>
</p:column> </p:column>
<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> <p:column>
<h:outputText value="#{disc.shortdesc}" /> <h:outputText value="#{disc.shortdesc}" />
</p:column> </p:column>
......
...@@ -40,35 +40,27 @@ ...@@ -40,35 +40,27 @@
<br /> <br />
<p:dataTable id="prods" value="#{productShopView.boughtItems}" var="prods"> <p:dataTable id="prods" value="#{productShopView.boughtItems}" var="prods">
<p:column> <p:column headerText="#{i18n['shop.count']}">
<f:facet name="header"> <p:inputText value="#{prods.count}" size="2">
<h:outputText value="#{i18n['shop.count']}" /> <f:ajax render="@form" listener="#{productShopView.countBoughtChangeListener}" />
</f:facet> <f:convertNumber minFractionDigits="0" maxFractionDigits="2" />
<p:inplace> </p:inputText>
<h:outputText value="#{prods.count}" size="4">
<f:convertNumber minFractionDigits="0" maxFractionDigits="2" />
</h:outputText>
</p:inplace>
</p:column> </p:column>
<p:column> <p:column headerText="#{i18n['shop.product']}">
<f:facet name="header">
<h:outputText value="#{i18n['shop.product']}" />
</f:facet>
<h:outputText value="#{prods.getProduct().name}" /> <h:outputText value="#{prods.getProduct().name}" />
</p:column> </p:column>
<p:column> <p:column headerText="#{i18n['shop.price']}">
<f:facet name="header">
<h:outputText value="#{i18n['shop.price']}" />
</f:facet>
<h:outputText value="#{prods.getProduct().price}"> <h:outputText value="#{prods.getProduct().price}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" /> <f:convertNumber maxFractionDigits="2" minFractionDigits="2" />
</h:outputText> </h:outputText>
</p:column> </p:column>
<p:column> <p:column headerText="#{i18n['shop.totalPrice']}">
<f:facet name="header"> <h:outputText value="#{prods.price}">
<h:outputText value="#{i18n['shop.actions']}" /> <f:convertNumber maxFractionDigits="2" minFractionDigits="2" />
</f:facet> </h:outputText>
</p:column>
<p:column headerText="#{i18n['shop.actions']}">
<p:commandButton action="#{productShopView.removeBought()}" update="@form" onerror="location.reload(true);" value="Poista" /> <p:commandButton action="#{productShopView.removeBought()}" update="@form" onerror="location.reload(true);" value="Poista" />
</p:column> </p:column>
</p:dataTable> </p:dataTable>
......
...@@ -860,6 +860,7 @@ shop.product = Product ...@@ -860,6 +860,7 @@ shop.product = Product
shop.readBarcode = Read shop.readBarcode = Read
shop.shop = Shop shop.shop = Shop
shop.shoppingcartCommitted = Products bought shop.shoppingcartCommitted = Products bought
shop.toAccountValue = To account
shop.totalPrice = Total shop.totalPrice = Total
shop.transactionTotal = Transaction total shop.transactionTotal = Transaction total
shop.user = Selling to shop.user = Selling to
......
...@@ -163,11 +163,16 @@ public class ProductShopView extends GenericCDIView { ...@@ -163,11 +163,16 @@ public class ProductShopView extends GenericCDIView {
} }
} }
public void countChangeListener(ValueChangeEvent e) public void countBoughtChangeListener()
{ {
ProductShopItem item = boughtItems.getRowData();
psiHelper.setProductShopItemCount(item, item.getCount());
updateCartLimits(item);
}
public void countChangeListener()
{
ProductShopItem item = shoppingcart.getRowData(); ProductShopItem item = shoppingcart.getRowData();
logger.info("Count change from event {}, from item {}", e.getNewValue(), item.getCount());
psiHelper.setProductShopItemCount(item, item.getCount()); psiHelper.setProductShopItemCount(item, item.getCount());
updateCartLimits(item); updateCartLimits(item);
} }
......
...@@ -17,49 +17,44 @@ import fi.codecrew.moya.web.helpers.ProductShopItem; ...@@ -17,49 +17,44 @@ import fi.codecrew.moya.web.helpers.ProductShopItem;
@ConversationScoped @ConversationScoped
public class ProductShopItemHelper extends GenericCDIView { public class ProductShopItemHelper extends GenericCDIView {
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@EJB @EJB
private DiscountBeanLocal discountBean; 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)
{
if (count == null || count.compareTo(BigDecimal.ZERO) < 0) count = BigDecimal.ZERO;
{ }
count = BigDecimal.ZERO; item.setCount(count);
}
item.setInternalCount(count); item.setInternalPrice(item.getProduct().getPrice().abs().multiply(count));
item.setInternalPrice(item.getProduct().getPrice().abs().multiply(count)); item.setInternalDiscounts(discountBean.getActiveDiscountsByProduct(item.getProduct(), count, Calendar.getInstance(), item.getUser()));
item.setInternalDiscounts(discountBean.getActiveDiscountsByProduct(item.getProduct(),count, Calendar.getInstance(), item.getUser()) ); item.setInternalDiscountValues(new HashMap<Integer, BigDecimal>());
item.setInternalDiscountValues(new HashMap<Integer, BigDecimal>()); for (Discount d : item.getDiscounts())
{
for (Discount d : item.getDiscounts()) BigDecimal newprice = item.getPrice().multiply(d.getPercentage());
{ item.getInternalDiscountValues().put(d.getId(), item.getPrice().subtract(newprice));
BigDecimal newprice = item.getPrice().multiply(d.getPercentage()); item.setInternalPrice(newprice);
item.getInternalDiscountValues().put(d.getId(), item.getPrice().subtract(newprice)); }
item.setInternalPrice(newprice);
}
} }
public boolean updateProductShopItemLimit(ProductShopItem item, BigDecimal limitValue) { public boolean updateProductShopItemLimit(ProductShopItem item, BigDecimal limitValue) {
if (limitValue != null && limitValue.compareTo(BigDecimal.ZERO) < 0) if (limitValue != null && limitValue.compareTo(BigDecimal.ZERO) < 0)
{ {
this.setProductShopItemCount(item, item.getCount().add(limitValue)); this.setProductShopItemCount(item, item.getCount().add(limitValue));
if (item.getCount().compareTo(BigDecimal.ZERO) < 0) { if (item.getCount().compareTo(BigDecimal.ZERO) < 0) {
this.setProductShopItemCount(item,BigDecimal.ZERO); this.setProductShopItemCount(item, BigDecimal.ZERO);
} }
item.setLimit(BigDecimal.ZERO); item.setLimit(BigDecimal.ZERO);
return true; return true;
...@@ -68,5 +63,4 @@ public class ProductShopItemHelper extends GenericCDIView { ...@@ -68,5 +63,4 @@ public class ProductShopItemHelper extends GenericCDIView {
return false; return false;
} }
} }
...@@ -47,7 +47,7 @@ public class ProductShopItem { ...@@ -47,7 +47,7 @@ public class ProductShopItem {
this.user = user; this.user = user;
this.product = prod; this.product = prod;
id = this.product.getId(); id = this.product.getId();
setInternalCount(BigDecimal.ZERO); setCount(BigDecimal.ZERO);
setInternalPrice(BigDecimal.ZERO); setInternalPrice(BigDecimal.ZERO);
} }
...@@ -85,21 +85,26 @@ public class ProductShopItem { ...@@ -85,21 +85,26 @@ public class ProductShopItem {
* DO NOT USE THIS. * DO NOT USE THIS.
* *
* Use ProductShopIteHelper.setProductShopItemCount instead. * 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 * @param count
*/ */
public void setInternalCount(BigDecimal count) { public void setCount(BigDecimal count) {
this.count = count; this.count = count;
} }
public void setInternalPrice(BigDecimal price) { public void setInternalPrice(BigDecimal price) {
this.price = price; this.price = price;
} }
public List<Discount> getDiscounts() public List<Discount> getDiscounts()
{ {
return discounts; return discounts;
} }
public void setInternalDiscounts(List<Discount> discounts) { public void setInternalDiscounts(List<Discount> discounts) {
this.discounts = discounts; this.discounts = discounts;
} }
...@@ -109,7 +114,6 @@ public class ProductShopItem { ...@@ -109,7 +114,6 @@ public class ProductShopItem {
return discountValues.get(discId); return discountValues.get(discId);
} }
public BigDecimal getPrice() public BigDecimal getPrice()
{ {
return price; return price;
...@@ -145,11 +149,11 @@ public class ProductShopItem { ...@@ -145,11 +149,11 @@ public class ProductShopItem {
public void setUser(EventUser user) { public void setUser(EventUser user) {
this.user = user; this.user = user;
} }
public Map<Integer, BigDecimal> getInternalDiscountValues() { public Map<Integer, BigDecimal> getInternalDiscountValues() {
return discountValues; return discountValues;
} }
public void setInternalDiscountValues(Map<Integer, BigDecimal> discountValues) { public void setInternalDiscountValues(Map<Integer, BigDecimal> discountValues) {
this.discountValues = 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!