Commit 7a8c9d73 by Tuomas Riihimäki

Shoppia

Conflicts:
	code/LanBortalWeb/WebContent/resources/cditools/user/create.xhtml
	code/LanBortalWeb/WebContent/shop/shopToUser.xhtml
	code/LanBortalWeb/src/fi/insomnia/bortal/web/cdiview/shop/ProductShopView.java
1 parent 6ccbd31f
...@@ -7,9 +7,10 @@ public enum LanEventPropertyKey { ...@@ -7,9 +7,10 @@ public enum LanEventPropertyKey {
PORTAL_EMAIL_ADDRESS(Type.TEXT, "intra@streamparty.org"), PORTAL_EMAIL_ADDRESS(Type.TEXT, "intra@streamparty.org"),
PORTAL_EMAIL_NAME(Type.TEXT, "Streamparty intranet"), PORTAL_EMAIL_NAME(Type.TEXT, "Streamparty intranet"),
ADMIN_MAIL(Type.TEXT, "intra@streamparty.org"), ADMIN_MAIL(Type.TEXT, "intra@streamparty.org"),
EVENT_LAYOUT(Type.TEXT, "template1"), ; EVENT_LAYOUT(Type.TEXT, "template1"),
SHOP_DEFAULT_CASH(Type.BOOL, null), ;
private enum Type { private enum Type {
TEXT, DATE, DATA TEXT, DATE, DATA, BOOL
}; };
private final String defaultvalue; private final String defaultvalue;
...@@ -27,6 +28,10 @@ public enum LanEventPropertyKey { ...@@ -27,6 +28,10 @@ public enum LanEventPropertyKey {
return Type.DATA.equals(type); return Type.DATA.equals(type);
} }
public boolean isBoolean() {
return Type.DATA.equals(type);
}
private LanEventPropertyKey(Type t, String def) private LanEventPropertyKey(Type t, String def)
{ {
this.type = t; this.type = t;
......
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
</ui:fragment> </ui:fragment>
<div id="left"> <div id="left">
<ui:insert name="title" /> <ui:insert name="title" />
<h:messages globalOnly="true" /> <p:messages />
<ui:repeat var="cont1" value="#{menuView.getPagecontent('top')}"> <ui:repeat var="cont1" value="#{menuView.getPagecontent('top')}">
<h:outputText value="#{cont1.content}" escape="false" /> <h:outputText value="#{cont1.content}" escape="false" />
</ui:repeat> </ui:repeat>
......
package fi.insomnia.bortal.web.cdiview.shop; package fi.insomnia.bortal.web.cdiview.shop;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.ejb.EJB; import javax.ejb.EJB;
...@@ -20,6 +22,8 @@ import fi.insomnia.bortal.beans.ProductBeanLocal; ...@@ -20,6 +22,8 @@ import fi.insomnia.bortal.beans.ProductBeanLocal;
import fi.insomnia.bortal.enums.apps.ShopPermission; import fi.insomnia.bortal.enums.apps.ShopPermission;
import fi.insomnia.bortal.model.Bill; import fi.insomnia.bortal.model.Bill;
import fi.insomnia.bortal.model.EventUser; import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.LanEventProperty;
import fi.insomnia.bortal.model.LanEventPropertyKey;
import fi.insomnia.bortal.model.Product; import fi.insomnia.bortal.model.Product;
import fi.insomnia.bortal.web.annotations.SelectedUser; import fi.insomnia.bortal.web.annotations.SelectedUser;
import fi.insomnia.bortal.web.cdiview.GenericCDIView; import fi.insomnia.bortal.web.cdiview.GenericCDIView;
...@@ -44,11 +48,16 @@ public class ProductShopView extends GenericCDIView { ...@@ -44,11 +48,16 @@ public class ProductShopView extends GenericCDIView {
@EJB @EJB
private transient EventBeanLocal eventbean; private transient EventBeanLocal eventbean;
public void cashChanged()
{
payInstant = false;
}
@Inject @Inject
@SelectedUser @SelectedUser
private EventUser user; private EventUser user;
private boolean payInstant; private boolean payInstant = true;
private BigDecimal cash = BigDecimal.ZERO; private BigDecimal cash = BigDecimal.ZERO;
private String barcode; private String barcode;
...@@ -61,7 +70,9 @@ public class ProductShopView extends GenericCDIView { ...@@ -61,7 +70,9 @@ public class ProductShopView extends GenericCDIView {
private BillEditView billEditView; private BillEditView billEditView;
private boolean hasLimits = false; private boolean hasLimits = false;
private boolean blip = false; private boolean blip = false;
private ListDataModel<ProductShopItem> boughtItems;
@EJB
public void initBillView() { public void initBillView() {
if (requirePermissions(ShopPermission.LIST_USERPRODUCTS) if (requirePermissions(ShopPermission.LIST_USERPRODUCTS)
&& shoppingcart == null) { && shoppingcart == null) {
...@@ -77,13 +88,16 @@ public class ProductShopView extends GenericCDIView { ...@@ -77,13 +88,16 @@ public class ProductShopView extends GenericCDIView {
public void initShopView() { public void initShopView() {
if (requirePermissions(ShopPermission.SHOP_TO_OTHERS) if (requirePermissions(ShopPermission.SHOP_TO_OTHERS) && shoppingcart == null) {
&& shoppingcart == null) { shoppingcart = new ListDataModel<ProductShopItem>(ProductShopItem.productGTList(productBean.findForStaffshop()));
shoppingcart = new ListDataModel<ProductShopItem>(
ProductShopItem.productGTList(productBean
.findForStaffshop()));
updateCartLimits(null); updateCartLimits(null);
logger.debug("Initialized shoppingcart to {}", shoppingcart);
LanEventProperty cashdefault = eventbean.getProperty(LanEventPropertyKey.SHOP_DEFAULT_CASH);
if (cashdefault == null || cashdefault.isBooleanValue())
{
payInstant = true;
}
this.beginConversation(); this.beginConversation();
} }
} }
...@@ -96,29 +110,36 @@ public class ProductShopView extends GenericCDIView { ...@@ -96,29 +110,36 @@ public class ProductShopView extends GenericCDIView {
return null; return null;
} }
public String addOne() public String addOne() {
{
return add(1); return add(1);
} }
public String addMinusOne() public String addMinusOne() {
{
return add(-1); return add(-1);
} }
public String addTen() public String addTen() {
{
return add(10); return add(10);
} }
public String addMinusTen() public String addMinusTen() {
{
return add(-10); return add(-10);
} }
public void updateCartLimits(ProductShopItem item) { public void updateCartLimits(ProductShopItem item) {
if (boughtItems == null) {
boughtItems = new ListDataModel<ProductShopItem>(new ArrayList<ProductShopItem>());
}
@SuppressWarnings("unchecked")
List<ProductShopItem> listdata = (List<ProductShopItem>) boughtItems.getWrappedData();
if (item != null && !listdata.contains(item)) {
listdata.add(item);
}
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());
...@@ -152,7 +173,17 @@ public class ProductShopView extends GenericCDIView { ...@@ -152,7 +173,17 @@ public class ProductShopView extends GenericCDIView {
updateCartLimits(null); updateCartLimits(null);
} }
public BigDecimal getAccountBalance() { public BigDecimal getTransactionTotal()
{
BigDecimal ret = getCartPrice().subtract(getAccountCredits());
if (BigDecimal.ZERO.compareTo(ret) > 0)
{
ret = BigDecimal.ZERO;
}
return ret;
}
public BigDecimal getBalanceAfterTransaction() {
BigDecimal ret = user.getAccountBalance(); BigDecimal ret = user.getAccountBalance();
ret = ret.add(getCash()); ret = ret.add(getCash());
ret = ret.subtract(getTotalPrice()); ret = ret.subtract(getTotalPrice());
...@@ -197,6 +228,18 @@ public class ProductShopView extends GenericCDIView { ...@@ -197,6 +228,18 @@ public class ProductShopView extends GenericCDIView {
} }
public String buyCashback() {
logger.info("buying cash {}", cash);
commitShoppingCart();
return null;
}
public String buyCredit() {
commitShoppingCart();
return null;
}
public String commitShoppingCart() { public String commitShoppingCart() {
EventUser retuser = null; EventUser retuser = null;
for (ProductShopItem shopitem : shoppingcart) { for (ProductShopItem shopitem : shoppingcart) {
...@@ -274,6 +317,9 @@ public class ProductShopView extends GenericCDIView { ...@@ -274,6 +317,9 @@ public class ProductShopView extends GenericCDIView {
} }
public void setCash(BigDecimal cash) { public void setCash(BigDecimal cash) {
if (cash == null) {
payInstant = true;
}
this.cash = cash; this.cash = cash;
} }
...@@ -316,4 +362,12 @@ public class ProductShopView extends GenericCDIView { ...@@ -316,4 +362,12 @@ public class ProductShopView extends GenericCDIView {
this.blip = blip; this.blip = blip;
} }
public ListDataModel<ProductShopItem> getBoughtItems() {
return boughtItems;
}
public void setBoughtItems(ListDataModel<ProductShopItem> boughtItems) {
this.boughtItems = boughtItems;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!