Commit adef6888 by Tuomas Riihimäki

Merge branch 'master' of codecrew.fi:bortal

2 parents 01ddfb13 0f1ab868
...@@ -356,4 +356,12 @@ public class ProductBean implements ProductBeanLocal { ...@@ -356,4 +356,12 @@ public class ProductBean implements ProductBeanLocal {
public AccountEvent createAccountEvent(Product product, BigDecimal quantity, EventUser user) { public AccountEvent createAccountEvent(Product product, BigDecimal quantity, EventUser user) {
return createAccountEvent(product, quantity, user, Calendar.getInstance()); return createAccountEvent(product, quantity, user, Calendar.getInstance());
} }
@Override
//@RolesAllowed(ShopPermission.S_LIST_ALL_PRODUCTS)
public Product findByBarcode(String barcode) {
return productFacade.findProductByBarcode(barcode);
}
} }
...@@ -489,4 +489,11 @@ public class UserBean implements UserBeanLocal { ...@@ -489,4 +489,11 @@ public class UserBean implements UserBeanLocal {
} }
} @Override
@RolesAllowed(UserPermission.S_VIEW_ALL)
public EventUser getUserByBarcode(String barcode) {
EventUser user = eventUserFacade.findByBarcode(barcode);
return user;
}
}
\ No newline at end of file
...@@ -12,6 +12,8 @@ import javax.persistence.criteria.Root; ...@@ -12,6 +12,8 @@ import javax.persistence.criteria.Root;
import fi.insomnia.bortal.beans.EventBeanLocal; import fi.insomnia.bortal.beans.EventBeanLocal;
import fi.insomnia.bortal.model.EventUser; import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.EventUser_; import fi.insomnia.bortal.model.EventUser_;
import fi.insomnia.bortal.model.PrintedCard;
import fi.insomnia.bortal.model.PrintedCard_;
import fi.insomnia.bortal.model.User; import fi.insomnia.bortal.model.User;
import fi.insomnia.bortal.model.User_; import fi.insomnia.bortal.model.User_;
...@@ -40,7 +42,7 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -40,7 +42,7 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
return getSingleNullableResult(getEm().createQuery(cq)); return getSingleNullableResult(getEm().createQuery(cq));
} }
public EventUser find(User user) { public EventUser find(User user) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<EventUser> cq = cb.createQuery(EventUser.class); CriteriaQuery<EventUser> cq = cb.createQuery(EventUser.class);
...@@ -62,5 +64,18 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -62,5 +64,18 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
eventBean.getCurrentEvent())); eventBean.getCurrentEvent()));
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
public EventUser findByBarcode(String barcode) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<EventUser> cq = cb.createQuery(EventUser.class);
Root<PrintedCard> root = cq.from(PrintedCard.class);
cq.select(root.get(PrintedCard_.user));
cq.where(
cb.equal(root.get(PrintedCard_.barcode), barcode),
cb.equal(root.get(PrintedCard_.event), eventBean.getCurrentEvent())
);
return getSingleNullableResult(getEm().createQuery(cq));
}
} }
...@@ -65,5 +65,18 @@ public class ProductFacade extends IntegerPkGenericFacade<Product> { ...@@ -65,5 +65,18 @@ public class ProductFacade extends IntegerPkGenericFacade<Product> {
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
public Product findProductByBarcode(String barcode) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Product> cq = cb.createQuery(Product.class);
Root<Product> root = cq.from(Product.class);
cq.where(
cb.equal(root.get(Product_.barcode), barcode)
);
return super.getSingleNullableResult(getEm().createQuery(cq));
}
} }
...@@ -36,7 +36,9 @@ public interface ProductBeanLocal { ...@@ -36,7 +36,9 @@ public interface ProductBeanLocal {
// List<Discount> getActiveDiscounts(Product product, BigDecimal quantity); // List<Discount> getActiveDiscounts(Product product, BigDecimal quantity);
Product findById(int parseInt); Product findById(int parseInt);
Product findByBarcode(String barcode);
List<Product> findForStaffshop(); List<Product> findForStaffshop();
Discount findDiscount(Integer discountid); Discount findDiscount(Integer discountid);
......
...@@ -65,5 +65,7 @@ public interface UserBeanLocal { ...@@ -65,5 +65,7 @@ public interface UserBeanLocal {
EventUser getEventUser(User user); EventUser getEventUser(User user);
EventUser validateUser(String username, String password); EventUser validateUser(String username, String password);
EventUser getUserByBarcode(String barcode);
} }
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:shop="http://java.sun.com/jsf/composite/cditools/shop" xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<f:metadata>
<f:event type="preRenderView" listener="#{barcodeView.initView}" />
</f:metadata>
<ui:define name="content">
<h:form>
<h:inputText name="barcode" value="#{barcodeView.barcode}" />
<h:commandButton action="#{barcodeView.readBarcode}" value="#{i18n['barcodeReader.readBarcode']}"/>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:products="http://java.sun.com/jsf/composite/cditools/products" xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:c="http://java.sun.com/jsp/jstl/core"> xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:products="http://java.sun.com/jsf/composite/cditools/products"
xmlns:p="http://primefaces.org/ui"
xmlns:users="http://java.sun.com/jsf/composite/cditools/user"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition
template="/layout/#{sessionHandler.layout}/template.xhtml">
<f:metadata> <f:metadata>
<f:viewParam name="userid" value="#{userView.userid}" /> <f:viewParam name="userid" value="#{userView.userid}" />
<f:event type="preRenderView" listener="#{userView.initView}" /> <f:event type="preRenderView" listener="#{userView.initView}" />
<f:event type="preRenderView" listener="#{productShopView.initShopView}" /> <f:event type="preRenderView"
listener="#{productShopView.initShopView}" />
</f:metadata> </f:metadata>
<ui:define name="title"> <ui:define name="title">
...@@ -18,40 +26,74 @@ ...@@ -18,40 +26,74 @@
<ui:define name="content"> <ui:define name="content">
<h:form id="shoppingcartform"> <h:form id="shoppingcartform">
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<h:outputLabel value="#{i18n['shop.accountBalance']}" />
<h:outputText value="#{productShopView.accountBalance}">
<f:convertNumber />
</h:outputText>
<h:outputLabel value="#{i18n['shop.totalPrice']}" />
<h:outputText value="#{productShopView.totalPrice}">
<f:convertNumber />
</h:outputText>
<h:outputLabel value="#{i18n['shop.cash']}" />
<h:inputText value="#{productShopView.cash}">
<f:ajax render="@form" event="valueChange" />
<f:convertNumber />
</h:inputText>
</h:panelGrid> <h:panelGrid columns="2">
<h:outputLabel value="#{i18n['shop.accountBalance']}" />
<h:outputText value="#{productShopView.accountBalance}">
<f:convertNumber />
</h:outputText>
<h:outputLabel value="#{i18n['shop.totalPrice']}" />
<h:outputText value="#{productShopView.totalPrice}">
<f:convertNumber />
</h:outputText>
<h:outputLabel value="#{i18n['shop.cash']}" />
<h:inputText value="#{productShopView.cash}">
<f:ajax render="@form" event="valueChange" />
<f:convertNumber />
</h:inputText>
</h:panelGrid>
<h:panelGroup>
<h:outputLabel value="#{i18n['shop.readBarcode']}" />
<h:inputText id="barcode" value="#{productShopView.barcode}" />
<h:commandButton action="#{productShopView.readBarcode}"
onclick="blip(); return true;"
value="#{i18n['productShopView.readBarcode']}">
<f:ajax render="@form" onevent="barcodeReadEvent" execute="@form" />
</h:commandButton>
</h:panelGroup>
</h:panelGrid>
<h:outputText value="#{i18n['product.shopInstant']}" /> <h:outputText value="#{i18n['product.shopInstant']}" />
<h:selectBooleanCheckbox value="#{productShopView.payInstant}"> <h:selectBooleanCheckbox value="#{productShopView.payInstant}">
<f:ajax render="@form" execute="@form" /> <f:ajax render="@form" execute="@form" />
</h:selectBooleanCheckbox> </h:selectBooleanCheckbox>
<products:shop commitaction="#{productShopView.commitShoppingCart()}" items="#{productShopView.shoppingcart}" commitValue="#{i18n['productshop.commit']}" /> <products:shop
commitaction="#{productShopView.commitShoppingCart()}"
items="#{productShopView.shoppingcart}"
commitValue="#{i18n['productshop.commit']}" />
</h:form> </h:form>
<script>
var blipSnd = new Audio(
"#{request.contextPath}/resources/media/blip.mp3")
$(function() {
$("#shoppingcartform\\:barcode").focus();
})
function blip() {
blipSnd.play();
}
function barcodeReadEvent(data) {
if (data.status == "success") {
$("#shoppingcartform\\:barcode").focus();
}
}
</script>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
</html> </html>
\ No newline at end of file
...@@ -75,9 +75,9 @@ placegroupview.toptext = \ ...@@ -75,9 +75,9 @@ placegroupview.toptext = \
poll.edit = edit poll.edit = edit
product.providedRole = Tuote tarjoaa roolin product.providedRole = Tuote tarjoaa roolin
product.returnProductEdit = Palaa tuotteeseen: product.returnProductEdit = Palaa tuotteeseen:
product.saved = Tuote tallennettu product.saved = Tuote tallennettu
productshop.minusOne = -1 productshop.minusOne = -1
productshop.minusTen = -10 productshop.minusTen = -10
......
...@@ -231,6 +231,8 @@ mapView.errorWhenReservingPlace = Error when reserving place! ...@@ -231,6 +231,8 @@ mapView.errorWhenReservingPlace = Error when reserving place!
mapView.errorWhileBuyingPlaces = Error when buying places. Please try again. If error reoccurs please contact organizers. mapView.errorWhileBuyingPlaces = Error when buying places. Please try again. If error reoccurs please contact organizers.
mapView.notEnoughCreditsToReserve = You don't have enough credits to reserve this place. mapView.notEnoughCreditsToReserve = You don't have enough credits to reserve this place.
mapedit.save = Save
nasty.user = Go away! nasty.user = Go away!
org.hibernate.validator.constraints.Email.message = not a well-formed email address org.hibernate.validator.constraints.Email.message = not a well-formed email address
...@@ -379,26 +381,28 @@ poll.end = Close poll ...@@ -379,26 +381,28 @@ poll.end = Close poll
poll.name = Poll name poll.name = Poll name
poll.save = Send answers poll.save = Send answers
product.barcode = Barcode product.barcode = Barcode
product.billed = Billed product.billed = Billed
product.boughtTotal = Products billed product.boughtTotal = Products billed
product.cart.count = To shoppingcart product.cart.count = To shoppingcart
product.cashed = Cashpaid product.cashed = Cashpaid
product.color = Color in UI product.color = Color in UI
product.create = Create product product.create = Create product
product.createDiscount = Add volumediscount product.createDiscount = Add volumediscount
product.edit = edit product.edit = edit
product.name = Name of product product.name = Name of product
product.paid = Paid product.paid = Paid
product.prepaid = Prepaid product.prepaid = Prepaid
product.prepaidInstant = Created when prepaid is paid product.prepaidInstant = Created when prepaid is paid
product.price = Price of product product.price = Price of product
product.save = Save product.save = Save
product.shopInstant = Create automatic cashpayment product.shopInstant = Create automatic cashpayment
product.sort = Sort nr product.sort = Sort nr
product.totalPrice = Total product.totalPrice = Total
product.unitName = Unit name product.unitName = Unit name
product.vat = VAT product.vat = VAT
productShopView.readBarcode = Read
products.save = Save products.save = Save
...@@ -447,6 +451,7 @@ sendPicture.header = S ...@@ -447,6 +451,7 @@ sendPicture.header = S
shop.accountBalance = Account balance shop.accountBalance = Account balance
shop.cash = Cash deposit shop.cash = Cash deposit
shop.readBarcode = Read viivakoodi
shop.totalPrice = Price of products shop.totalPrice = Price of products
shop.user = Selling to shop.user = Selling to
......
...@@ -238,6 +238,8 @@ mapView.errorWhenReservingPlace = Paikkaa varatessa tapahtui virhe. ...@@ -238,6 +238,8 @@ mapView.errorWhenReservingPlace = Paikkaa varatessa tapahtui virhe.
mapView.errorWhileBuyingPlaces = Virhe paikkojen ostossa. Ole hyv\u00E4 ja yrit\u00E4 uudelleen. Jos virhe toistuu ota yhteytt\u00E4 j\u00E4rjest\u00E4jiin. mapView.errorWhileBuyingPlaces = Virhe paikkojen ostossa. Ole hyv\u00E4 ja yrit\u00E4 uudelleen. Jos virhe toistuu ota yhteytt\u00E4 j\u00E4rjest\u00E4jiin.
mapView.notEnoughCreditsToReserve = Sinulla ei ole riitt\u00E4v\u00E4sti suoritettuja konepaikkamaksuja t\u00E4m\u00E4n paikan varaamiseen. mapView.notEnoughCreditsToReserve = Sinulla ei ole riitt\u00E4v\u00E4sti suoritettuja konepaikkamaksuja t\u00E4m\u00E4n paikan varaamiseen.
mapedit.save = Tallenna
menu.index = Etusivu menu.index = Etusivu
menu.place.placemap = Paikkakartta menu.place.placemap = Paikkakartta
menu.poll.index = Kyselyt menu.poll.index = Kyselyt
...@@ -368,26 +370,28 @@ poll.end = Sulje kysely ...@@ -368,26 +370,28 @@ poll.end = Sulje kysely
poll.name = Kyselyn nimi poll.name = Kyselyn nimi
poll.save = L\u00E4het\u00E4 vastauksesi poll.save = L\u00E4het\u00E4 vastauksesi
product.barcode = Viivakoodi product.barcode = Viivakoodi
product.billed = Laskutettu product.billed = Laskutettu
product.boughtTotal = Tuotteita laskutettu product.boughtTotal = Tuotteita laskutettu
product.cart.count = Ostoskoriin product.cart.count = Ostoskoriin
product.cashed = Ostettu k\u00E4teisell\u00E4 product.cashed = Ostettu k\u00E4teisell\u00E4
product.color = V\u00E4ri k\u00E4ytt\u00F6liittym\u00E4ss\u00E4 product.color = V\u00E4ri k\u00E4ytt\u00F6liittym\u00E4ss\u00E4
product.create = Luo tuote product.create = Luo tuote
product.createDiscount = Lis\u00E4\u00E4 m\u00E4\u00E4r\u00E4alennus product.createDiscount = Lis\u00E4\u00E4 m\u00E4\u00E4r\u00E4alennus
product.edit = Muokkaa product.edit = Muokkaa
product.name = Tuotteen nimi product.name = Tuotteen nimi
product.paid = Maksettu product.paid = Maksettu
product.prepaid = Prepaid product.prepaid = Prepaid
product.prepaidInstant = Luodaan kun prepaid maksetaan product.prepaidInstant = Luodaan kun prepaid maksetaan
product.price = Tuotteen hinta product.price = Tuotteen hinta
product.save = Tallenna product.save = Tallenna
product.shopInstant = Luo k\u00E4teismaksu tuotteille product.shopInstant = Luo k\u00E4teismaksu tuotteille
product.sort = J\u00E4rjestys luku product.sort = J\u00E4rjestys luku
product.totalPrice = Summa product.totalPrice = Summa
product.unitName = Tuoteyksikk\u00F6 product.unitName = Tuoteyksikk\u00F6
product.vat = ALV product.vat = ALV
productShopView.readBarcode = Lue
products.save = Tallenna products.save = Tallenna
...@@ -434,6 +438,7 @@ sendPicture.header = L\u00E4het\u00E4 kuva ...@@ -434,6 +438,7 @@ sendPicture.header = L\u00E4het\u00E4 kuva
shop.accountBalance = Tilin saldo shop.accountBalance = Tilin saldo
shop.cash = K\u00E4teispano shop.cash = K\u00E4teispano
shop.readBarcode = Lue viivakoodi
shop.totalPrice = Tuotteiden hinta shop.totalPrice = Tuotteiden hinta
shop.user = Myyd\u00E4\u00E4n shop.user = Myyd\u00E4\u00E4n
......
package fi.insomnia.bortal.web.cdiview.shop;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.UserBeanLocal;
import fi.insomnia.bortal.enums.apps.UserPermission;
import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.web.cdiview.GenericCDIView;
import fi.insomnia.bortal.web.cdiview.user.UserView;
@Named
@ConversationScoped
public class BarcodeView extends GenericCDIView {
private String barcode;
private static final Logger logger = LoggerFactory
.getLogger(BarcodeView.class);
@Inject
private UserView userView;
@Inject
private ProductShopView productShopView;
@EJB
private UserBeanLocal userBean;
public String getBarcode() {
return barcode;
}
public void initView() {
super.requirePermissions(UserPermission.VIEW_ALL);
}
public void setBarcode(String barcode) {
this.barcode = barcode;
}
public String readBarcode() {
EventUser user = userBean.getUserByBarcode(barcode);
userView.setUser(user);
if (user == null) {
super.addFaceMessage("barcodeView.userNotFound", barcode);
logger.info("User not found by barcode: {}", barcode);
return null;
}
productShopView.initShopView();
super.beginConversation();
logger.info("Recieved Barcode: {}", barcode);
return "/shop/shopToUser";
}
public UserView getUserView() {
return userView;
}
public void setUserView(UserView userView) {
this.userView = userView;
}
public ProductShopView getProductShopView() {
return productShopView;
}
public void setProductShopView(ProductShopView productShopView) {
this.productShopView = productShopView;
}
}
...@@ -29,7 +29,8 @@ import fi.insomnia.bortal.web.helpers.ProductShopItem; ...@@ -29,7 +29,8 @@ import fi.insomnia.bortal.web.helpers.ProductShopItem;
@ConversationScoped @ConversationScoped
public class ProductShopView extends GenericCDIView { public class ProductShopView extends GenericCDIView {
private static final Logger logger = LoggerFactory.getLogger(ProductShopView.class); private static final Logger logger = LoggerFactory
.getLogger(ProductShopView.class);
/** /**
* *
*/ */
...@@ -50,6 +51,7 @@ public class ProductShopView extends GenericCDIView { ...@@ -50,6 +51,7 @@ public class ProductShopView extends GenericCDIView {
private boolean payInstant; private boolean payInstant;
private BigDecimal cash = BigDecimal.ZERO; private BigDecimal cash = BigDecimal.ZERO;
private String barcode;
private transient ListDataModel<ProductShopItem> shoppingcart; private transient ListDataModel<ProductShopItem> shoppingcart;
@Inject @Inject
...@@ -58,11 +60,14 @@ public class ProductShopView extends GenericCDIView { ...@@ -58,11 +60,14 @@ public class ProductShopView extends GenericCDIView {
@Inject @Inject
private BillEditView billEditView; private BillEditView billEditView;
private boolean hasLimits = false; private boolean hasLimits = false;
private boolean blip = false;
public void initBillView()
{ public void initBillView() {
if (requirePermissions(ShopPermission.LIST_USERPRODUCTS) && shoppingcart == null) { if (requirePermissions(ShopPermission.LIST_USERPRODUCTS)
shoppingcart = new ListDataModel<ProductShopItem>(ProductShopItem.productList(productBean.listUserShoppableProducts())); && shoppingcart == null) {
shoppingcart = new ListDataModel<ProductShopItem>(
ProductShopItem.productList(productBean
.listUserShoppableProducts()));
updateCartLimits(); updateCartLimits();
logger.debug("Initialized billing shoppingcart to {}", shoppingcart); logger.debug("Initialized billing shoppingcart to {}", shoppingcart);
this.beginConversation(); this.beginConversation();
...@@ -72,17 +77,18 @@ public class ProductShopView extends GenericCDIView { ...@@ -72,17 +77,18 @@ public class ProductShopView extends GenericCDIView {
public void initShopView() { public void initShopView() {
if (requirePermissions(ShopPermission.SHOP_TO_OTHERS) && shoppingcart == null) { if (requirePermissions(ShopPermission.SHOP_TO_OTHERS)
shoppingcart = new ListDataModel<ProductShopItem>(ProductShopItem.productGTList(productBean.findForStaffshop())); && shoppingcart == null) {
shoppingcart = new ListDataModel<ProductShopItem>(
ProductShopItem.productGTList(productBean
.findForStaffshop()));
updateCartLimits(); updateCartLimits();
logger.debug("Initialized shoppingcart to {}", shoppingcart); logger.debug("Initialized shoppingcart to {}", shoppingcart);
this.beginConversation(); this.beginConversation();
} }
} }
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))); item.setCount(item.getCount().add(BigDecimal.valueOf(count)));
...@@ -94,15 +100,14 @@ public class ProductShopView extends GenericCDIView { ...@@ -94,15 +100,14 @@ public class ProductShopView extends GenericCDIView {
public void updateCartLimits() { public void updateCartLimits() {
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(prodCounts, user); HashMap<Integer, BigDecimal> limits = productBean.getProductLimit(
prodCounts, user);
for (ProductShopItem n : shoppingcart) for (ProductShopItem n : shoppingcart) {
{
BigDecimal l = limits.get(n.getProduct().getId()); BigDecimal l = limits.get(n.getProduct().getId());
if (l != null) { if (l != null) {
hasLimits = true; hasLimits = true;
...@@ -111,22 +116,19 @@ public class ProductShopView extends GenericCDIView { ...@@ -111,22 +116,19 @@ public class ProductShopView extends GenericCDIView {
} }
} }
public BigDecimal getAccountBalance() public BigDecimal getAccountBalance() {
{
BigDecimal ret = user.getAccountBalance(); BigDecimal ret = user.getAccountBalance();
ret = ret.add(getCash()); ret = ret.add(getCash());
ret = ret.subtract(getTotalPrice()); ret = ret.subtract(getTotalPrice());
logger.info("User accountbalance {}, cash{}, total {}. retBalance {}", new Object[] { logger.info("User accountbalance {}, cash{}, total {}. retBalance {}",
user.getAccountBalance(), getCash(), getTotalPrice(), ret new Object[] { user.getAccountBalance(), getCash(),
}); getTotalPrice(), ret });
return ret; return ret;
} }
public BigDecimal getTotalPrice() public BigDecimal getTotalPrice() {
{
BigDecimal ret = BigDecimal.ZERO; BigDecimal ret = BigDecimal.ZERO;
for (ProductShopItem cart : shoppingcart) for (ProductShopItem cart : shoppingcart) {
{
ret = ret.add(cart.getPrice()); ret = ret.add(cart.getPrice());
} }
return ret; return ret;
...@@ -159,22 +161,21 @@ public class ProductShopView extends GenericCDIView { ...@@ -159,22 +161,21 @@ public class ProductShopView extends GenericCDIView {
} }
public String commitShoppingCart() public String commitShoppingCart() {
{
EventUser retuser = null; EventUser retuser = null;
for (ProductShopItem shopitem : shoppingcart) { for (ProductShopItem shopitem : shoppingcart) {
if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) { if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) {
retuser = productBean.createAccountEvent(shopitem.getProduct(), shopitem.getCount(), user).getUser(); retuser = productBean.createAccountEvent(shopitem.getProduct(),
shopitem.getCount(), user).getUser();
} }
} }
if (cash != null && cash.compareTo(BigDecimal.ZERO) != 0) if (cash != null && cash.compareTo(BigDecimal.ZERO) != 0) {
{
Product credProd = productBean.findCreditProduct(); Product credProd = productBean.findCreditProduct();
retuser = productBean.createAccountEvent(credProd, cash, user).getUser(); retuser = productBean.createAccountEvent(credProd, cash, user)
.getUser();
} }
if (user != null) if (user != null) {
{
user = retuser; user = retuser;
} }
shoppingcart = null; shoppingcart = null;
...@@ -209,8 +210,7 @@ public class ProductShopView extends GenericCDIView { ...@@ -209,8 +210,7 @@ public class ProductShopView extends GenericCDIView {
} }
public void setPayInstant(boolean payInstant) { public void setPayInstant(boolean payInstant) {
if (payInstant) if (payInstant) {
{
getCash(); getCash();
} }
this.payInstant = payInstant; this.payInstant = payInstant;
...@@ -250,4 +250,35 @@ public class ProductShopView extends GenericCDIView { ...@@ -250,4 +250,35 @@ public class ProductShopView extends GenericCDIView {
public void setHasLimits(boolean hasLimits) { public void setHasLimits(boolean hasLimits) {
this.hasLimits = hasLimits; this.hasLimits = hasLimits;
} }
public String getBarcode() {
return barcode;
}
public void setBarcode(String barcode) {
this.barcode = barcode;
}
public void readBarcode() {
Product product = productBean.findByBarcode(this.barcode);
this.blip = false;
for (ProductShopItem a : shoppingcart) {
if (a.getProduct().equals(product)) {
a.setCount(a.getCount().add(BigDecimal.ONE));
setBlip(true);
break;
}
}
this.barcode = null;
logger.debug("barcode read");
}
public boolean isBlip() {
return blip;
}
public void setBlip(boolean blip) {
this.blip = blip;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!