Commit e977367c by Tuukka Kivilahti

bug hunted from barcodes

1 parent 6d11ea6b
...@@ -38,13 +38,11 @@ ...@@ -38,13 +38,11 @@
<h:outputLabel value="#{i18n['shop.barcode']}" /> <h:outputLabel value="#{i18n['shop.barcode']}" />
<h:inputText id="barcode" value="#{productShopView.barcode}" /> <h:inputText id="barcode" value="#{productShopView.barcode}" />
<h:commandButton action="#{productShopView.readBarcode}" onclick="blip(); return true;" value="#{i18n['shop.readBarcode']}"> <h:commandButton action="#{productShopView.readBarcode}" value="#{i18n['shop.readBarcode']}">
<f:ajax render="@form" onevent="barcodeReadEvent" execute="@form" /> <f:ajax render="@form" onevent="barcodeReadEvent" execute="@form" />
</h:commandButton> </h:commandButton>
<br /> <br />
<p:dataTable id="prods" value="#{productShopView.boughtItems}" var="prods"> <p:dataTable id="prods" value="#{productShopView.boughtItems}" var="prods">
<p:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['shop.count']}" /> <h:outputText value="#{i18n['shop.count']}" />
...@@ -138,6 +136,8 @@ ...@@ -138,6 +136,8 @@
function calc() { function calc() {
$("#returnval").val($("#inputval").val() - $(".inputval").text().replace(",",".")); $("#returnval").val($("#inputval").val() - $(".inputval").text().replace(",","."));
} }
function barcodeReadEvent(data) { function barcodeReadEvent(data) {
if (data.status == "success") { if (data.status == "success") {
......
...@@ -140,7 +140,7 @@ public class ProductShopView extends GenericCDIView { ...@@ -140,7 +140,7 @@ public class ProductShopView extends GenericCDIView {
Map<Integer, BigDecimal> prodCounts = new HashMap<Integer, BigDecimal>(); Map<Integer, BigDecimal> prodCounts = new HashMap<Integer, BigDecimal>();
for (ProductShopItem sc : shoppingcart) { for (ProductShopItem sc : shoppingcart) {
prodCounts.put(sc.getProduct().getId(), sc.getCount()); prodCounts.put(sc.getProduct().getId(), sc.getCount());
} }
HashMap<Integer, BigDecimal> limits = productBean.getProductLimit( HashMap<Integer, BigDecimal> limits = productBean.getProductLimit(
...@@ -365,16 +365,25 @@ public class ProductShopView extends GenericCDIView { ...@@ -365,16 +365,25 @@ public class ProductShopView extends GenericCDIView {
public String readBarcode() { public String readBarcode() {
Product product = productBean.findByBarcode(this.barcode); Product product = productBean.findByBarcode(this.barcode);
this.blip = false; this.blip = false;
// find product index, set index and add one
// I don't know why this does not work if you just loop over and change the product count
int n = 0;
for (ProductShopItem a : shoppingcart) { for (ProductShopItem a : shoppingcart) {
if (a.getProduct().equals(product)) { if (a.getProduct().equals(product))
a.setCount(a.getCount().add(BigDecimal.ONE)); {
//a.setCount(a.getCount().add(BigDecimal.ONE));
//updateCartLimits(null);
shoppingcart.setRowIndex(n);
this.addOne();
setBlip(true); setBlip(true);
break; break;
} }
n++;
} }
this.barcode = null; this.barcode = null;
logger.debug("barcode read"); logger.debug("barcode read");
return null; return "success";
} }
public boolean isBlip() { public boolean isBlip() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!