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 {
PORTAL_EMAIL_ADDRESS(Type.TEXT, "intra@streamparty.org"),
PORTAL_EMAIL_NAME(Type.TEXT, "Streamparty intranet"),
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 {
TEXT, DATE, DATA
TEXT, DATE, DATA, BOOL
};
private final String defaultvalue;
......@@ -27,6 +28,10 @@ public enum LanEventPropertyKey {
return Type.DATA.equals(type);
}
public boolean isBoolean() {
return Type.DATA.equals(type);
}
private LanEventPropertyKey(Type t, String def)
{
this.type = t;
......
......@@ -80,7 +80,7 @@
</ui:fragment>
<div id="left">
<ui:insert name="title" />
<h:messages globalOnly="true" />
<p:messages />
<ui:repeat var="cont1" value="#{menuView.getPagecontent('top')}">
<h:outputText value="#{cont1.content}" escape="false" />
</ui:repeat>
......
package fi.insomnia.bortal.web.cdiview.shop;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
......@@ -20,6 +22,8 @@ import fi.insomnia.bortal.beans.ProductBeanLocal;
import fi.insomnia.bortal.enums.apps.ShopPermission;
import fi.insomnia.bortal.model.Bill;
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.web.annotations.SelectedUser;
import fi.insomnia.bortal.web.cdiview.GenericCDIView;
......@@ -44,11 +48,16 @@ public class ProductShopView extends GenericCDIView {
@EJB
private transient EventBeanLocal eventbean;
public void cashChanged()
{
payInstant = false;
}
@Inject
@SelectedUser
private EventUser user;
private boolean payInstant;
private boolean payInstant = true;
private BigDecimal cash = BigDecimal.ZERO;
private String barcode;
......@@ -61,7 +70,9 @@ public class ProductShopView extends GenericCDIView {
private BillEditView billEditView;
private boolean hasLimits = false;
private boolean blip = false;
private ListDataModel<ProductShopItem> boughtItems;
@EJB
public void initBillView() {
if (requirePermissions(ShopPermission.LIST_USERPRODUCTS)
&& shoppingcart == null) {
......@@ -77,13 +88,16 @@ 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(null);
logger.debug("Initialized shoppingcart to {}", shoppingcart);
LanEventProperty cashdefault = eventbean.getProperty(LanEventPropertyKey.SHOP_DEFAULT_CASH);
if (cashdefault == null || cashdefault.isBooleanValue())
{
payInstant = true;
}
this.beginConversation();
}
}
......@@ -96,29 +110,36 @@ public class ProductShopView extends GenericCDIView {
return null;
}
public String addOne()
{
public String addOne() {
return add(1);
}
public String addMinusOne()
{
public String addMinusOne() {
return add(-1);
}
public String addTen()
{
public String addTen() {
return add(10);
}
public String addMinusTen()
{
public String addMinusTen() {
return add(-10);
}
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>();
for (ProductShopItem sc : shoppingcart) {
prodCounts.put(sc.getProduct().getId(), sc.getCount());
......@@ -152,7 +173,17 @@ public class ProductShopView extends GenericCDIView {
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();
ret = ret.add(getCash());
ret = ret.subtract(getTotalPrice());
......@@ -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() {
EventUser retuser = null;
for (ProductShopItem shopitem : shoppingcart) {
......@@ -274,6 +317,9 @@ public class ProductShopView extends GenericCDIView {
}
public void setCash(BigDecimal cash) {
if (cash == null) {
payInstant = true;
}
this.cash = cash;
}
......@@ -316,4 +362,12 @@ public class ProductShopView extends GenericCDIView {
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!