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 @@
<f:ajax render="@form" />
</h:commandButton>
<h:inputText size="4" id="cartcount" value="#{cart.count}">
<f:convertNumber maxIntegerDigits="2" minFractionDigits="0" />
<f:convertNumber maxFractionDigits="2" minFractionDigits="0" />
</h:inputText>
<h:commandButton action="#{foodWaveFoodView.addOne}"
value="#{i18n['productshop.plusOne']}">
......
......@@ -40,24 +40,24 @@
<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;">
<f:convertNumber maxIntegerDigits="2" minFractionDigits="0" />
</h:outputText>
<p:inputText size="2" id="cartcount" escape="false" value="#{cart.count}">
<f:ajax render="@form" listener="#{productShopView.countChangeListener}" />
<f:convertNumber maxFractionDigits="2" minFractionDigits="0" />
</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">
<h:outputText value="#{i18n['productshop.limits']}" />
</f:facet>
<h:outputText value="#{cart.limit}">
<f:convertNumber maxIntegerDigits="2" minFractionDigits="0" />
<f:convertNumber maxFractionDigits="2" minFractionDigits="0" />
</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>
......
......@@ -40,35 +40,27 @@
<br />
<p:dataTable id="prods" value="#{productShopView.boughtItems}" var="prods">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['shop.count']}" />
</f:facet>
<p:inplace>
<h:outputText value="#{prods.count}" size="4">
<f:convertNumber minFractionDigits="0" maxFractionDigits="2" />
</h:outputText>
</p:inplace>
<p:column headerText="#{i18n['shop.count']}">
<p:inputText value="#{prods.count}" size="2">
<f:ajax render="@form" listener="#{productShopView.countBoughtChangeListener}" />
<f:convertNumber minFractionDigits="0" maxFractionDigits="2" />
</p:inputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['shop.product']}" />
</f:facet>
<p:column headerText="#{i18n['shop.product']}">
<h:outputText value="#{prods.getProduct().name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['shop.price']}" />
</f:facet>
<p:column headerText="#{i18n['shop.price']}">
<h:outputText value="#{prods.getProduct().price}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" />
</h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['shop.actions']}" />
</f:facet>
<p:column headerText="#{i18n['shop.totalPrice']}">
<h:outputText value="#{prods.price}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" />
</h:outputText>
</p:column>
<p:column headerText="#{i18n['shop.actions']}">
<p:commandButton action="#{productShopView.removeBought()}" update="@form" onerror="location.reload(true);" value="Poista" />
</p:column>
</p:dataTable>
......
......@@ -860,6 +860,7 @@ shop.product = Product
shop.readBarcode = Read
shop.shop = Shop
shop.shoppingcartCommitted = Products bought
shop.toAccountValue = To account
shop.totalPrice = Total
shop.transactionTotal = Transaction total
shop.user = Selling to
......
......@@ -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();
logger.info("Count change from event {}, from item {}", e.getNewValue(), item.getCount());
psiHelper.setProductShopItemCount(item, item.getCount());
updateCartLimits(item);
}
......
......@@ -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!