Commit 71611071 by Tuomas Riihimäki

Merge branch 'bill_expire_from_hours_tos_minutes' into 'master'

Bill expire from hours to minutes

See merge request !433
2 parents d3f8f960 5a98ba61
...@@ -647,6 +647,10 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -647,6 +647,10 @@ public class BootstrapBean implements BootstrapBeanLocal {
dbUpdates.add(new String[]{ dbUpdates.add(new String[]{
"UPDATE place_slots SET used = now() WHERE used is null AND product_id in (SELECT product_id FROM product_productflags WHERE productflags = 'CREATE_NEW_PLACE_WHEN_BOUGHT')" "UPDATE place_slots SET used = now() WHERE used is null AND product_id in (SELECT product_id FROM product_productflags WHERE productflags = 'CREATE_NEW_PLACE_WHEN_BOUGHT')"
}); });
dbUpdates.add(new String[] {
"UPDATE event_properties SET long_value = (long_value * 60), key = 'BILL_EXPIRE_MINS' WHERE key = 'BILL_EXPIRE_HOURS'"
});
} }
......
...@@ -225,7 +225,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -225,7 +225,7 @@ public class ProductBean implements ProductBeanLocal {
ret.put(prod.getId(), BigDecimal.valueOf(freeCount)); ret.put(prod.getId(), BigDecimal.valueOf(freeCount));
} else { } else {
BigDecimal lim = getPrivateProductLimit(prod, user, prodCounts, userroles); BigDecimal lim = getPrivateProductLimit(prod, user, userroles);
ret.put(prod.getId(), lim); ret.put(prod.getId(), lim);
// logger.info("Added product limit {} to {}", lim, prod); // logger.info("Added product limit {} to {}", lim, prod);
...@@ -288,19 +288,19 @@ public class ProductBean implements ProductBeanLocal { ...@@ -288,19 +288,19 @@ public class ProductBean implements ProductBeanLocal {
{ {
product = productFacade.reload(product); product = productFacade.reload(product);
HashSet<Role> userroles = new HashSet<Role>(userbean.findUsersRoles(user)); HashSet<Role> userroles = new HashSet<Role>(userbean.findUsersRoles(user));
return getPrivateProductLimit(product, user, prodCounts, userroles); return getPrivateProductLimit(product, user, userroles);
} }
/** /**
* Returns available products to be bought for the user. * Returns available products to be bought for the user.
*
* *
* @param product * @param product
* @param user * @param user
* @param prodCounts
* @param userroles * @param userroles
* @return Number of buyable products * @return Number of buyable products
*/ */
private BigDecimal getPrivateProductLimit(Product product, EventUser user, Map<Integer, BigDecimal> prodCounts, Set<Role> userroles) private BigDecimal getPrivateProductLimit(Product product, EventUser user, Set<Role> userroles)
{ {
BigDecimal ret = null; BigDecimal ret = null;
if (product != null && product.getProductLimits() != null) if (product != null && product.getProductLimits() != null)
...@@ -308,13 +308,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -308,13 +308,7 @@ public class ProductBean implements ProductBeanLocal {
for (ProductLimitation limit : product.getProductLimits()) for (ProductLimitation limit : product.getProductLimits())
{ {
BigDecimal currentCount = BigDecimal.ZERO;
for (Product p : limit.getProducts())
{
currentCount = currentCount.add(prodCounts.get(p.getId()));
}
// logger.info("Got limit {} for product {}", limit, product);
if (limit.getMatchingRoles() != null && !limit.getMatchingRoles().isEmpty()) if (limit.getMatchingRoles() != null && !limit.getMatchingRoles().isEmpty())
{ {
boolean roleMatched = false; boolean roleMatched = false;
...@@ -330,8 +324,6 @@ public class ProductBean implements ProductBeanLocal { ...@@ -330,8 +324,6 @@ public class ProductBean implements ProductBeanLocal {
} }
} }
BigDecimal count = currentCount;
switch (limit.getType()) switch (limit.getType())
{ {
case GLOBAL_BILLED: { case GLOBAL_BILLED: {
...@@ -340,8 +332,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -340,8 +332,7 @@ public class ProductBean implements ProductBeanLocal {
BillSummary globBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent()); BillSummary globBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent());
globBillTot = globBillTot.add(globBilledSummary.getActive()); globBillTot = globBillTot.add(globBilledSummary.getActive());
} }
count = count.add(globBillTot); ret = limit.getUpperLimit().subtract(globBillTot);
ret = limit.getUpperLimit().subtract(count);
break; break;
} }
case GLOBAL_BILL_PAID: case GLOBAL_BILL_PAID:
...@@ -350,22 +341,21 @@ public class ProductBean implements ProductBeanLocal { ...@@ -350,22 +341,21 @@ public class ProductBean implements ProductBeanLocal {
BillSummary billPaidSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent()); BillSummary billPaidSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent());
globBillPaid = globBillPaid.add(billPaidSummary.getPaid()); globBillPaid = globBillPaid.add(billPaidSummary.getPaid());
} }
count = count.add(globBillPaid); ret = limit.getUpperLimit().subtract(globBillPaid);
ret = limit.getUpperLimit().subtract(count);
break; break;
case GLOBAL_ACCOUNTEVENTS: case GLOBAL_ACCOUNTEVENTS:
BigDecimal globalProductCount = accounteventfacade.getProductCount(limit.getProducts()); BigDecimal globalProductCount = accounteventfacade.getProductCount(limit.getProducts());
if (globalProductCount != null) { if (globalProductCount == null) {
count = count.add(globalProductCount); globalProductCount = BigDecimal.ZERO;
} }
ret = limit.getUpperLimit().subtract(count); ret = limit.getUpperLimit().subtract(globalProductCount);
break; break;
case USER_ACCOUNTEVENTS: case USER_ACCOUNTEVENTS:
BigDecimal userProductCount = accounteventfacade.getProductCount(limit.getProducts(), user); BigDecimal userProductCount = accounteventfacade.getProductCount(limit.getProducts(), user);
if (userProductCount != null) { if (userProductCount == null) {
count = count.add(userProductCount); userProductCount = BigDecimal.ZERO;
} }
ret = limit.getUpperLimit().subtract(count); ret = limit.getUpperLimit().subtract(userProductCount);
break; break;
case USER_BILLED: case USER_BILLED:
BigDecimal userBillTot = BigDecimal.ZERO; BigDecimal userBillTot = BigDecimal.ZERO;
...@@ -373,8 +363,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -373,8 +363,7 @@ public class ProductBean implements ProductBeanLocal {
BillSummary userBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user); BillSummary userBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user);
userBillTot = userBillTot.add(userBilledSummary.getActive()); userBillTot = userBillTot.add(userBilledSummary.getActive());
} }
count = count.add(userBillTot); ret = limit.getUpperLimit().subtract(userBillTot);
ret = limit.getUpperLimit().subtract(count);
break; break;
case USER_BILL_PAID: case USER_BILL_PAID:
BigDecimal userBillPaid = BigDecimal.ZERO; BigDecimal userBillPaid = BigDecimal.ZERO;
...@@ -382,8 +371,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -382,8 +371,7 @@ public class ProductBean implements ProductBeanLocal {
BillSummary userPaidSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user); BillSummary userPaidSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user);
userBillPaid = userBillPaid.add(userPaidSummary.getPaid()); userBillPaid = userBillPaid.add(userPaidSummary.getPaid());
} }
count = count.add(userBillPaid); ret = limit.getUpperLimit().subtract(userBillPaid);
ret = limit.getUpperLimit().subtract(count);
break; break;
default: default:
......
...@@ -254,8 +254,8 @@ public class Bill extends GenericEntity { ...@@ -254,8 +254,8 @@ public class Bill extends GenericEntity {
this.event = event; this.event = event;
} }
public Bill(LanEvent event, EventUser user, long expireTimeHours) { public Bill(LanEvent event, EventUser user, long expireTimeMins) {
this(event, user, new Date(System.currentTimeMillis() + (expireTimeHours * 60 * 60 * 1000))); this(event, user, new Date(System.currentTimeMillis() + (expireTimeMins * 60 * 1000)));
} }
public Bill(LanEvent event, long expireTimeHours) { public Bill(LanEvent event, long expireTimeHours) {
......
...@@ -36,7 +36,7 @@ public enum LanEventPropertyKey { ...@@ -36,7 +36,7 @@ public enum LanEventPropertyKey {
GATHER_OTHER_BILL_INFO(Type.BOOL), GATHER_OTHER_BILL_INFO(Type.BOOL),
GATHER_SHIRT_SIZE(Type.BOOL), GATHER_SHIRT_SIZE(Type.BOOL),
ALLOW_BILLING(Type.BOOL), ALLOW_BILLING(Type.BOOL),
BILL_EXPIRE_HOURS(Type.LONG, 1l), BILL_EXPIRE_MINS(Type.LONG, 30l),
TEMPLATE_PROPERTY1(Type.TEXT), TEMPLATE_PROPERTY1(Type.TEXT),
TEMPLATE_PROPERTY2(Type.TEXT), TEMPLATE_PROPERTY2(Type.TEXT),
TEMPLATE_PROPERTY3(Type.TEXT), TEMPLATE_PROPERTY3(Type.TEXT),
......
...@@ -150,7 +150,7 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -150,7 +150,7 @@ public class FoodWaveFoodView extends GenericCDIView {
* @return * @return
*/ */
public Bill createBillFromShoppingcart() { public Bill createBillFromShoppingcart() {
Bill bill = new Bill(eventBean.getCurrentEvent(), userview.getSelectedUser(), eventBean.getPropertyLong(LanEventPropertyKey.BILL_EXPIRE_HOURS)); Bill bill = new Bill(eventBean.getCurrentEvent(), userview.getSelectedUser(), eventBean.getPropertyLong(LanEventPropertyKey.BILL_EXPIRE_MINS));
bill.setOurReference(eventBean.getCurrentEvent().getName()); bill.setOurReference(eventBean.getCurrentEvent().getName());
for (ProductShopItem shopitem : shoppingcart) { for (ProductShopItem shopitem : shoppingcart) {
......
...@@ -351,7 +351,7 @@ public class ProductShopView extends GenericCDIView { ...@@ -351,7 +351,7 @@ public class ProductShopView extends GenericCDIView {
return null; return null;
} }
Bill bill = new Bill(eventbean.getCurrentEvent(), userView.getSelectedUser(), eventbean.getPropertyLong(LanEventPropertyKey.BILL_EXPIRE_HOURS)); Bill bill = new Bill(eventbean.getCurrentEvent(), userView.getSelectedUser(), eventbean.getPropertyLong(LanEventPropertyKey.BILL_EXPIRE_MINS));
bill.setNotes(otherInfo); bill.setNotes(otherInfo);
bill.setOurReference(eventbean.getCurrentEvent().getName()); bill.setOurReference(eventbean.getCurrentEvent().getName());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!