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 {
public AccountEvent createAccountEvent(Product product, BigDecimal quantity, EventUser user) {
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 {
}
@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;
import fi.insomnia.bortal.beans.EventBeanLocal;
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_;
......@@ -63,4 +65,17 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
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));
}
}
......@@ -66,4 +66,17 @@ public class ProductFacade extends IntegerPkGenericFacade<Product> {
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));
}
}
......@@ -37,6 +37,8 @@ public interface ProductBeanLocal {
Product findById(int parseInt);
Product findByBarcode(String barcode);
List<Product> findForStaffshop();
Discount findDiscount(Integer discountid);
......
......@@ -66,4 +66,6 @@ public interface UserBeanLocal {
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
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: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">
<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: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>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:composition
template="/layout/#{sessionHandler.layout}/template.xhtml">
<f:metadata>
<f:viewParam name="userid" value="#{userView.userid}" />
<f:event type="preRenderView" listener="#{userView.initView}" />
<f:event type="preRenderView" listener="#{productShopView.initShopView}" />
<f:event type="preRenderView"
listener="#{productShopView.initShopView}" />
</f:metadata>
<ui:define name="title">
......@@ -18,12 +26,12 @@
<ui:define name="content">
<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 />
......@@ -41,17 +49,51 @@
</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:selectBooleanCheckbox value="#{productShopView.payInstant}">
<f:ajax render="@form" execute="@form" />
</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>
<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:composition>
</h:body>
</html>
\ No newline at end of file
......@@ -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.notEnoughCreditsToReserve = You don't have enough credits to reserve this place.
mapedit.save = Save
nasty.user = Go away!
org.hibernate.validator.constraints.Email.message = not a well-formed email address
......@@ -400,6 +402,8 @@ product.totalPrice = Total
product.unitName = Unit name
product.vat = VAT
productShopView.readBarcode = Read
products.save = Save
productshop.billCreated = Bill created
......@@ -447,6 +451,7 @@ sendPicture.header = S
shop.accountBalance = Account balance
shop.cash = Cash deposit
shop.readBarcode = Read viivakoodi
shop.totalPrice = Price of products
shop.user = Selling to
......
......@@ -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.notEnoughCreditsToReserve = Sinulla ei ole riitt\u00E4v\u00E4sti suoritettuja konepaikkamaksuja t\u00E4m\u00E4n paikan varaamiseen.
mapedit.save = Tallenna
menu.index = Etusivu
menu.place.placemap = Paikkakartta
menu.poll.index = Kyselyt
......@@ -389,6 +391,8 @@ product.totalPrice = Summa
product.unitName = Tuoteyksikk\u00F6
product.vat = ALV
productShopView.readBarcode = Lue
products.save = Tallenna
productshop.billCreated = Lasku luotu
......@@ -434,6 +438,7 @@ sendPicture.header = L\u00E4het\u00E4 kuva
shop.accountBalance = Tilin saldo
shop.cash = K\u00E4teispano
shop.readBarcode = Lue viivakoodi
shop.totalPrice = Tuotteiden hinta
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;
@ConversationScoped
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 {
private boolean payInstant;
private BigDecimal cash = BigDecimal.ZERO;
private String barcode;
private transient ListDataModel<ProductShopItem> shoppingcart;
@Inject
......@@ -58,11 +60,14 @@ public class ProductShopView extends GenericCDIView {
@Inject
private BillEditView billEditView;
private boolean hasLimits = false;
public void initBillView()
{
if (requirePermissions(ShopPermission.LIST_USERPRODUCTS) && shoppingcart == null) {
shoppingcart = new ListDataModel<ProductShopItem>(ProductShopItem.productList(productBean.listUserShoppableProducts()));
private boolean blip = false;
public void initBillView() {
if (requirePermissions(ShopPermission.LIST_USERPRODUCTS)
&& shoppingcart == null) {
shoppingcart = new ListDataModel<ProductShopItem>(
ProductShopItem.productList(productBean
.listUserShoppableProducts()));
updateCartLimits();
logger.debug("Initialized billing shoppingcart to {}", shoppingcart);
this.beginConversation();
......@@ -72,17 +77,18 @@ public class ProductShopView extends GenericCDIView {
public void initShopView() {
if (requirePermissions(ShopPermission.SHOP_TO_OTHERS) && shoppingcart == null) {
shoppingcart = new ListDataModel<ProductShopItem>(ProductShopItem.productGTList(productBean.findForStaffshop()));
if (requirePermissions(ShopPermission.SHOP_TO_OTHERS)
&& shoppingcart == null) {
shoppingcart = new ListDataModel<ProductShopItem>(
ProductShopItem.productGTList(productBean
.findForStaffshop()));
updateCartLimits();
logger.debug("Initialized shoppingcart to {}", shoppingcart);
this.beginConversation();
}
}
public String add(Integer count)
{
public String add(Integer count) {
ProductShopItem item = shoppingcart.getRowData();
item.setCount(item.getCount().add(BigDecimal.valueOf(count)));
......@@ -94,15 +100,14 @@ public class ProductShopView extends GenericCDIView {
public void updateCartLimits() {
Map<Integer, BigDecimal> prodCounts = new HashMap<Integer, BigDecimal>();
for (ProductShopItem sc : shoppingcart)
{
for (ProductShopItem sc : shoppingcart) {
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());
if (l != null) {
hasLimits = true;
......@@ -111,22 +116,19 @@ public class ProductShopView extends GenericCDIView {
}
}
public BigDecimal getAccountBalance()
{
public BigDecimal getAccountBalance() {
BigDecimal ret = user.getAccountBalance();
ret = ret.add(getCash());
ret = ret.subtract(getTotalPrice());
logger.info("User accountbalance {}, cash{}, total {}. retBalance {}", new Object[] {
user.getAccountBalance(), getCash(), getTotalPrice(), ret
});
logger.info("User accountbalance {}, cash{}, total {}. retBalance {}",
new Object[] { user.getAccountBalance(), getCash(),
getTotalPrice(), ret });
return ret;
}
public BigDecimal getTotalPrice()
{
public BigDecimal getTotalPrice() {
BigDecimal ret = BigDecimal.ZERO;
for (ProductShopItem cart : shoppingcart)
{
for (ProductShopItem cart : shoppingcart) {
ret = ret.add(cart.getPrice());
}
return ret;
......@@ -159,22 +161,21 @@ public class ProductShopView extends GenericCDIView {
}
public String commitShoppingCart()
{
public String commitShoppingCart() {
EventUser retuser = null;
for (ProductShopItem shopitem : shoppingcart) {
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();
retuser = productBean.createAccountEvent(credProd, cash, user).getUser();
retuser = productBean.createAccountEvent(credProd, cash, user)
.getUser();
}
if (user != null)
{
if (user != null) {
user = retuser;
}
shoppingcart = null;
......@@ -209,8 +210,7 @@ public class ProductShopView extends GenericCDIView {
}
public void setPayInstant(boolean payInstant) {
if (payInstant)
{
if (payInstant) {
getCash();
}
this.payInstant = payInstant;
......@@ -250,4 +250,35 @@ public class ProductShopView extends GenericCDIView {
public void setHasLimits(boolean 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!