Commit fc521ebe by Tuomas Riihimäki

Arg... Pitäisi tehdä yksi asia kerrallaan.

  * Tehty loppuun credittisiirto tapahtumasta toiseen.
  * Fiksailtu ja uudelleenkirjoitettu osittain käyttäjien listaus
(paginointi ja sorttaus primefacesin päälle)
  * Pieniä viilauksia tilitapahtuman esittämiseen.
  * Ei luoda ihan automaattisesti uutta käyttäjää tapahtumaan.
1 parent 3a29778b
...@@ -187,8 +187,7 @@ public class EventBean implements EventBeanLocal { ...@@ -187,8 +187,7 @@ public class EventBean implements EventBeanLocal {
public LanEventProperty getProperty(LanEventPropertyKey property) { public LanEventProperty getProperty(LanEventPropertyKey property) {
return eventPropertyFacade.find(getCurrentEvent(), property); return eventPropertyFacade.find(getCurrentEvent(), property);
} }
@Override @Override
public long getPropertyLong(LanEventPropertyKey property) public long getPropertyLong(LanEventPropertyKey property)
{ {
...@@ -201,8 +200,6 @@ public class EventBean implements EventBeanLocal { ...@@ -201,8 +200,6 @@ public class EventBean implements EventBeanLocal {
} }
return ret; return ret;
} }
@Override @Override
public String getPropertyString(LanEventPropertyKey property) public String getPropertyString(LanEventPropertyKey property)
...@@ -266,4 +263,14 @@ public class EventBean implements EventBeanLocal { ...@@ -266,4 +263,14 @@ public class EventBean implements EventBeanLocal {
return ret; return ret;
} }
/**
* If you want this event, user getCurrentEvent() This method should be used
* only in special cases...
*/
@Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT)
public LanEvent getEventById(Integer id) {
return eventFacade.find(id);
}
} }
...@@ -21,6 +21,7 @@ import javax.annotation.security.PermitAll; ...@@ -21,6 +21,7 @@ import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.EJBAccessException; import javax.ejb.EJBAccessException;
import javax.ejb.EJBException;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
...@@ -30,15 +31,18 @@ import javax.persistence.PersistenceContext; ...@@ -30,15 +31,18 @@ import javax.persistence.PersistenceContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.enums.apps.EventPermission;
import fi.codecrew.moya.enums.apps.SpecialPermission; import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.enums.apps.UserPermission; import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.facade.AccountEventFacade; import fi.codecrew.moya.facade.AccountEventFacade;
import fi.codecrew.moya.facade.ApprovalFacade; import fi.codecrew.moya.facade.ApprovalFacade;
import fi.codecrew.moya.facade.EventFacade;
import fi.codecrew.moya.facade.EventUserFacade; import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.FeedbackFacade; import fi.codecrew.moya.facade.FeedbackFacade;
import fi.codecrew.moya.facade.GameIDFacade; import fi.codecrew.moya.facade.GameIDFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade; import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.PlaceGroupFacade; import fi.codecrew.moya.facade.PlaceGroupFacade;
import fi.codecrew.moya.facade.ProductFacade;
import fi.codecrew.moya.facade.RoleFacade; import fi.codecrew.moya.facade.RoleFacade;
import fi.codecrew.moya.facade.UserApprovalFacade; import fi.codecrew.moya.facade.UserApprovalFacade;
import fi.codecrew.moya.facade.UserFacade; import fi.codecrew.moya.facade.UserFacade;
...@@ -75,6 +79,7 @@ import fi.codecrew.moya.utilities.SearchResult; ...@@ -75,6 +79,7 @@ import fi.codecrew.moya.utilities.SearchResult;
UserPermission.S_INVITE_USERS, UserPermission.S_INVITE_USERS,
UserPermission.S_MODIFY, UserPermission.S_MODIFY,
SpecialPermission.S_USER, SpecialPermission.S_USER,
EventPermission.S_MANAGE_EVENT,
}) })
public class UserBean implements UserBeanLocal { public class UserBean implements UserBeanLocal {
...@@ -137,6 +142,10 @@ public class UserBean implements UserBeanLocal { ...@@ -137,6 +142,10 @@ public class UserBean implements UserBeanLocal {
private ProductPBean productPrivateBean; private ProductPBean productPrivateBean;
@EJB @EJB
private AccountEventFacade accountEventFacade; private AccountEventFacade accountEventFacade;
@EJB
private EventFacade eventfacade;
@EJB
private ProductFacade productFacade;
@Override @Override
@RolesAllowed(UserPermission.S_VIEW_ALL) @RolesAllowed(UserPermission.S_VIEW_ALL)
...@@ -802,56 +811,78 @@ public class UserBean implements UserBeanLocal { ...@@ -802,56 +811,78 @@ public class UserBean implements UserBeanLocal {
return ret; return ret;
} }
/** @Override
* Transfers account saldo from previous event. Creates negative @RolesAllowed(EventPermission.S_MANAGE_EVENT)
* accountevent for source user and positive for dst user. There are few public BigDecimal transferAccountSaldoFromPreviousEvent(List<User> users, LanEvent source)
* requirements.
* <ul>
* <li>User must be the same.
* <li>Organisation must be the same.
* </ul>
*
* @param source
* @param dst
* @return Saldo transferred. Zero if no transfer was made, Null if there
* was error..
*/
public BigDecimal transferAccountSaldoFromPreviousEvent(EventUser source, EventUser dst)
{ {
if (source == null || dst == null)
return null;
source = eventUserFacade.reload(source);
dst = eventUserFacade.reload(dst);
if (!source.getEvent().getOrganiser().equals(dst.getEvent().getOrganiser())) { if (source == null || users == null || users.isEmpty())
logger.warn("Can not transfer funds between organisations!");
return null; return null;
source = eventfacade.reload(source);
LanEvent destination = eventBean.getCurrentEvent();
if (!source.getOrganiser().equals(destination.getOrganiser())) {
throw new EJBException("Trying to move credits between organisations!");
} }
if (!source.getUser().equals(dst.getUser())) { final Calendar time = Calendar.getInstance();
logger.warn("Can not transfer accountenvets! Users should be the same!!! Source {}, dst {}", source.getUser(), dst.getUser()); final EventUser seller = permbean.getCurrentUser();
return null;
final Product dstCredprod = productbean.findCreditProduct();
final Product srcCredprod = productFacade.findProductsByPrice(BigDecimal.ONE.negate(), source).get(0);
if (!srcCredprod.getPrice().equals(dstCredprod.getPrice())) {
throw new RuntimeException("Credit prices do not match!");
}
final BigDecimal creditPrice = srcCredprod.getPrice().negate();
BigDecimal dstTotal = BigDecimal.ZERO;
for (User user : users)
{
EventUser dstUser = eventUserFacade.find(user);
EventUser srcUser = eventUserFacade.getOtherOrganisationsEventuser(dstUser.getUser(), source);
// If source user does not exist, skip over.
if (srcUser == null) {
continue;
}
BigDecimal srcBalance = srcUser.getAccountBalance();
if (srcBalance.compareTo(BigDecimal.ZERO) == 0) {
continue;
}
BigDecimal count = srcBalance.divide(creditPrice);
if (count.compareTo(BigDecimal.ZERO) < 0) {
throw new EJBException("All users should have positive balance!. User with id: " + dstUser.getUser().getId() + " has negative balance!");
}
// Negative accountevent for source user
AccountEvent srcacc = new AccountEvent(srcUser, srcCredprod, creditPrice, count.negate(), time);
srcacc.setDescription("Credits transferred to: '" + destination.getName() + "'");
srcacc.setSeller(seller);
srcUser.addAccountevent(srcacc);
accountEventFacade.create(srcacc);
AccountEvent dstacc = new AccountEvent(dstUser, dstCredprod, creditPrice, count, time);
dstacc.setDescription("Credits transferred from: '" + source.getName() + "'");
dstacc.setSeller(seller);
dstUser.addAccountevent(dstacc);
accountEventFacade.create(dstacc);
logger.info("Transferred {} credits with price {} for user {} from {} to {}", count, creditPrice, srcUser.getUser(), srcUser, dstUser);
dstTotal = dstTotal.add(dstacc.getTotal());
}
return dstTotal;
}
@Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT)
public EventUser getOtherEventsEventuser(User user, LanEvent event) {
event = eventfacade.reload(event);
if (!eventBean.getCurrentEvent().getOrganiser().equals(event.getOrganiser())) {
throw new EJBAccessException("event must be organised by the organisation as this event.");
} }
Calendar time = Calendar.getInstance(); return eventUserFacade.getOtherOrganisationsEventuser(user, event);
EventUser seller = permbean.getCurrentUser();
Product credprod = productbean.findCreditProduct();
BigDecimal price = credprod.getPrice().negate();
BigDecimal srcBalance = source.getAccountBalance();
// This should always
BigDecimal count = srcBalance.divide(price);
AccountEvent srcacc = new AccountEvent(source, credprod, price, count.negate(), time);
srcacc.setDescription("Credits transferred to: '" + dst.getEvent().getName() + "'");
srcacc.setSeller(seller);
source.addAccountevent(srcacc);
accountEventFacade.create(srcacc);
AccountEvent dstacc = new AccountEvent(source, credprod, price, count, time);
dstacc.setDescription("Credits transferred from: '" + source.getEvent().getName() + "'");
dstacc.setSeller(seller);
dst.addAccountevent(dstacc);
accountEventFacade.create(dstacc);
return srcBalance;
} }
} }
\ No newline at end of file
...@@ -89,10 +89,13 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -89,10 +89,13 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
} }
public EventUser find(User user) { public EventUser find(User user) {
LanEvent event = eventBean.getCurrentEvent(); return getOtherOrganisationsEventuser(user, eventBean.getCurrentEvent());
EventUser ret; }
if ((ret = checkCache(user.getLogin(), event)) == null)
{ public EventUser getOtherOrganisationsEventuser(User user, LanEvent event)
{
EventUser ret = null;
if ((ret = checkCache(user.getLogin(), event)) == null) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<EventUser> cq = cb.createQuery(EventUser.class); CriteriaQuery<EventUser> cq = cb.createQuery(EventUser.class);
Root<EventUser> root = cq.from(EventUser.class); Root<EventUser> root = cq.from(EventUser.class);
......
...@@ -12,6 +12,7 @@ import javax.persistence.criteria.CriteriaQuery; ...@@ -12,6 +12,7 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Product; import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag; import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.model.Product_; import fi.codecrew.moya.model.Product_;
...@@ -44,11 +45,15 @@ public class ProductFacade extends IntegerPkGenericFacade<Product> { ...@@ -44,11 +45,15 @@ public class ProductFacade extends IntegerPkGenericFacade<Product> {
} }
public List<Product> findProductsByPrice(BigDecimal price) { public List<Product> findProductsByPrice(BigDecimal price) {
return findProductsByPrice(price, eventbean.getCurrentEvent());
}
public List<Product> findProductsByPrice(BigDecimal price, LanEvent event) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Product> cq = cb.createQuery(Product.class); CriteriaQuery<Product> cq = cb.createQuery(Product.class);
Root<Product> root = cq.from(Product.class); Root<Product> root = cq.from(Product.class);
cq.where(cb.equal(root.get(Product_.event), eventbean.getCurrentEvent()), cq.where(cb.equal(root.get(Product_.event), event),
cb.equal(root.get(Product_.price), price)); cb.equal(root.get(Product_.price), price));
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
......
...@@ -35,7 +35,9 @@ public interface EventBeanLocal { ...@@ -35,7 +35,9 @@ public interface EventBeanLocal {
List<LanEventPrivateProperty> getPrivateProperties(); List<LanEventPrivateProperty> getPrivateProperties();
LanEventPrivateProperty saveOrCreatePrivateProperty(LanEventPrivateProperty privateProperty); LanEventPrivateProperty saveOrCreatePrivateProperty(LanEventPrivateProperty privateProperty);
long getPropertyLong(LanEventPropertyKey property); long getPropertyLong(LanEventPropertyKey property);
LanEvent getEventById(Integer id);
} }
...@@ -2,6 +2,7 @@ package fi.codecrew.moya.beans; ...@@ -2,6 +2,7 @@ package fi.codecrew.moya.beans;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import javax.ejb.Local; import javax.ejb.Local;
...@@ -10,6 +11,7 @@ import fi.codecrew.moya.model.EventUser; ...@@ -10,6 +11,7 @@ import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Feedback; import fi.codecrew.moya.model.Feedback;
import fi.codecrew.moya.model.GameID; import fi.codecrew.moya.model.GameID;
import fi.codecrew.moya.model.GroupMembership; import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Role; import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.TournamentGame; import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
...@@ -104,4 +106,23 @@ public interface UserBeanLocal { ...@@ -104,4 +106,23 @@ public interface UserBeanLocal {
boolean isUserInRole(EventUser user, Integer roleId); boolean isUserInRole(EventUser user, Integer roleId);
EventUser getOtherEventsEventuser(User user, LanEvent event);
/**
* Transfers account saldo from previous event. Creates negative
* accountevent for source user and positive for dst user. There are few
* requirements.
* <ul>
* <li>User must be the same.
* <li>Organisation must be the same.
* <li>All users should have positive or zero balance on source event.
* </ul>
*
* @param source
* @param dst
* @return Saldo transferred. Zero if no transfer was made, Null if there
* was error..
*/
BigDecimal transferAccountSaldoFromPreviousEvent(List<User> dstEventuser, LanEvent source);
} }
...@@ -30,208 +30,211 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -30,208 +30,211 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS) @OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class AccountEvent extends GenericEntity { public class AccountEvent extends GenericEntity {
private static final long serialVersionUID = 2588419823225148100L; private static final long serialVersionUID = 2588419823225148100L;
@Column(name = "cash", nullable = false) @Column(name = "cash", nullable = false)
private boolean cash = false; private boolean cash = false;
/** /**
* What 1 unit of this product costs. * What 1 unit of this product costs.
*/ */
@Column(name = "unit_price", nullable = false, precision = 24, scale = 4) @Column(name = "unit_price", nullable = false, precision = 24, scale = 4)
private BigDecimal unitPrice; private BigDecimal unitPrice;
/** /**
* The units of the product, eg 1.345 (l), 5 (units) 888.32 (g).. * The units of the product, eg 1.345 (l), 5 (units) 888.32 (g)..
*/ */
@Column(name = "quantity", nullable = false, precision = 24, scale = 4) @Column(name = "quantity", nullable = false, precision = 24, scale = 4)
private BigDecimal quantity; private BigDecimal quantity;
/** /**
* The time this AccountEvent is created. * The time this AccountEvent is created.
*/ */
@Column(name = "event_time", nullable = false) @Column(name = "event_time", nullable = false)
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar eventTime = Calendar.getInstance(); private Calendar eventTime = Calendar.getInstance();
/** /**
* Is the product delivered to the user. * Is the product delivered to the user.
*/ */
@Column(name = "delivered") @Column(name = "delivered")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar delivered; private Calendar delivered;
@Column(name = "delivered_count", nullable = false, precision = 24, scale = 4) @Column(name = "delivered_count", nullable = false, precision = 24, scale = 4)
private BigDecimal deliveredCount = new BigDecimal(0); private BigDecimal deliveredCount = new BigDecimal(0);
/** /**
* If this AccountEvent is a product in foodwace, this field is a reference * If this AccountEvent is a product in foodwace, this field is a reference
* to that foodwave. * to that foodwave.
*/ */
@JoinColumn(name = "food_wave_id", referencedColumnName = FoodWave.ID_COLUMN) @JoinColumn(name = "food_wave_id", referencedColumnName = FoodWave.ID_COLUMN)
@ManyToOne @ManyToOne
private FoodWave foodWave; private FoodWave foodWave;
/** /**
* The product user has acquired and this this AccountEvent is a reference * The product user has acquired and this this AccountEvent is a reference
* to. * to.
*/ */
@JoinColumn(name = "product_id", referencedColumnName = Product.ID_COLUMN, nullable = false) @JoinColumn(name = "product_id", referencedColumnName = Product.ID_COLUMN, nullable = false)
@ManyToOne(optional = false) @ManyToOne(optional = false)
private Product product; private Product product;
/** /**
* The user that bought the products. * The user that bought the products.
*/ */
@JoinColumn(name = "eventuser_id", referencedColumnName = EventUser.ID_COLUMN, nullable = false) @JoinColumn(name = "eventuser_id", referencedColumnName = EventUser.ID_COLUMN, nullable = false)
@ManyToOne(optional = false) @ManyToOne(optional = false)
private EventUser user; private EventUser user;
/** /**
* Who sold the items to the user. * Who sold the items to the user.
*/ */
@JoinColumn(name = "seller_eventuser_id", referencedColumnName = EventUser.ID_COLUMN) @JoinColumn(name = "seller_eventuser_id", referencedColumnName = EventUser.ID_COLUMN)
@ManyToOne(optional = true) @ManyToOne(optional = true)
private EventUser seller; private EventUser seller;
/** /**
* What discounts user has for this account event. Some magic is applied to * What discounts user has for this account event. Some magic is applied to
* calculate these.. :) * calculate these.. :)
*/ */
@OneToMany(mappedBy = "accountEvent", cascade = CascadeType.ALL) @OneToMany(mappedBy = "accountEvent", cascade = CascadeType.ALL)
private List<DiscountInstance> discountInstances = new ArrayList<DiscountInstance>(); private List<DiscountInstance> discountInstances = new ArrayList<DiscountInstance>();
/** /**
* When user has paid a bill a Account event for product "Credit" is created * When user has paid a bill a Account event for product "Credit" is created
* and reference to that bill is here.. * and reference to that bill is here..
*/ */
@OneToOne(mappedBy = "accountEvent") @OneToOne(mappedBy = "accountEvent")
private Bill bill; private Bill bill;
@Lob @Lob
private String description; private String description;
public BigDecimal getTotal() { public BigDecimal getTotal() {
return getQuantity().multiply(getUnitPrice()); return getQuantity().multiply(getUnitPrice());
} }
public AccountEvent() { public AccountEvent() {
} }
public AccountEvent(EventUser u, Product prod, BigDecimal unitPrice, BigDecimal quantity, Calendar eventTime) { public AccountEvent(EventUser u, Product prod, BigDecimal unitPrice, BigDecimal quantity, Calendar eventTime) {
this.setUnitPrice(unitPrice); if (!u.getEvent().equals(prod.getEvent())) {
this.setQuantity(quantity); throw new RuntimeException("User and product are not in the same event!");
this.product = prod; }
this.eventTime = eventTime; this.setUnitPrice(unitPrice);
this.user = u; this.setQuantity(quantity);
} this.product = prod;
this.eventTime = eventTime;
public Calendar getEventTime() { this.user = u;
return eventTime; }
}
public Calendar getEventTime() {
public void setEventTime(Calendar eventTime) { return eventTime;
this.eventTime = eventTime; }
}
public void setEventTime(Calendar eventTime) {
public Calendar getDelivered() { this.eventTime = eventTime;
return delivered; }
}
public Calendar getDelivered() {
public void setDelivered(Calendar delivered) { return delivered;
this.delivered = delivered; }
}
public void setDelivered(Calendar delivered) {
public EventUser getUser() { this.delivered = delivered;
return user; }
}
public EventUser getUser() {
public void setUser(EventUser usersId) { return user;
this.user = usersId; }
}
public void setUser(EventUser usersId) {
public List<DiscountInstance> getDiscountInstances() { this.user = usersId;
return discountInstances; }
}
public List<DiscountInstance> getDiscountInstances() {
public void setDiscountInstances(List<DiscountInstance> discountInstanceList) { return discountInstances;
this.discountInstances = discountInstanceList; }
}
public void setDiscountInstances(List<DiscountInstance> discountInstanceList) {
public void setFoodWave(FoodWave foodWave) { this.discountInstances = discountInstanceList;
this.foodWave = foodWave; }
}
public void setFoodWave(FoodWave foodWave) {
public FoodWave getFoodWave() { this.foodWave = foodWave;
return foodWave; }
}
public FoodWave getFoodWave() {
public void setProduct(Product product) { return foodWave;
this.product = product; }
}
public void setProduct(Product product) {
public Product getProduct() { this.product = product;
return product; }
}
public Product getProduct() {
public void setSeller(EventUser seller) { return product;
this.seller = seller; }
}
public void setSeller(EventUser seller) {
public EventUser getSeller() { this.seller = seller;
return seller; }
}
public EventUser getSeller() {
public void setBill(Bill bill) { return seller;
this.bill = bill; }
}
public void setBill(Bill bill) {
public Bill getBill() { this.bill = bill;
return bill; }
}
public Bill getBill() {
public void setUnitPrice(BigDecimal unitPrice) { return bill;
this.unitPrice = unitPrice; }
}
public void setUnitPrice(BigDecimal unitPrice) {
public BigDecimal getUnitPrice() { this.unitPrice = unitPrice;
return unitPrice; }
}
public BigDecimal getUnitPrice() {
public void setQuantity(BigDecimal quantity) { return unitPrice;
this.quantity = quantity; }
}
public void setQuantity(BigDecimal quantity) {
public BigDecimal getQuantity() { this.quantity = quantity;
return quantity; }
}
public BigDecimal getQuantity() {
public void setCash(boolean cash) { return quantity;
this.cash = cash; }
}
public void setCash(boolean cash) {
public boolean isCash() { this.cash = cash;
return cash; }
}
public boolean isCash() {
public String getDescription() { return cash;
return description; }
}
public String getDescription() {
public void setDescription(String description) { return description;
this.description = description; }
}
public void setDescription(String description) {
public BigDecimal getDeliveredCount() { this.description = description;
return deliveredCount; }
}
public BigDecimal getDeliveredCount() {
return deliveredCount;
}
public void setDeliveredCount(BigDecimal deliveredCount) { public void setDeliveredCount(BigDecimal deliveredCount) {
this.deliveredCount = deliveredCount; this.deliveredCount = deliveredCount;
} }
public boolean isEventDelivered() { public boolean isEventDelivered() {
return (delivered != null); return (delivered != null);
} }
} }
...@@ -466,6 +466,9 @@ public class EventUser extends GenericEntity { ...@@ -466,6 +466,9 @@ public class EventUser extends GenericEntity {
if (accountEvents == null) { if (accountEvents == null) {
accountEvents = new ArrayList<AccountEvent>(); accountEvents = new ArrayList<AccountEvent>();
} }
if (!this.equals(accountevent.getUser())) {
throw new RuntimeException("Trying to add accountevent for eventuser with different eventuser");
}
accountEvents.add(accountevent); accountEvents.add(accountevent);
} }
} }
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
</p:column> </p:column>
<p:column sortBy="login" headerText="#{i18n['user.login']}"> <p:column sortBy="login" headerText="#{i18n['user.login']}">
<h:outputText value="#{wra.user.login}" /> <h:outputText value="#{user.login}" />
</p:column> </p:column>
<p:column headerText="#{i18n['user.firstNames']}" sortBy="firstnames"> <p:column headerText="#{i18n['user.firstNames']}" sortBy="firstnames">
<h:outputText value="#{user.firstnames}" /> <h:outputText value="#{user.firstnames}" />
......
...@@ -11,12 +11,13 @@ ...@@ -11,12 +11,13 @@
<p:dataTable id="user" value="#{userSearchView.userModel}" rows="20" var="wra" paginator="true" lazy="true"> <p:dataTable id="user" value="#{userSearchView.userModel}" rows="20" var="wra" paginator="true" lazy="true">
<p:column sortBy="login" headerText="#{i18n['user.login']}">
<h:outputText value="#{wra.user.login}" />
</p:column>
<p:column sortBy="nick" headerText="#{i18n['user.nick']}"> <p:column sortBy="nick" headerText="#{i18n['user.nick']}">
<h:outputText value="#{(empty wra.user.nick)?'----':wra.user.nick}" /> <h:outputText value="#{(empty wra.user.nick)?'----':wra.user.nick}" />
</p:column> </p:column>
<p:column sortBy="login" headerText="#{i18n['user.login']}">
<h:outputText value="#{wra.user.login}" />
</p:column>
<p:column headerText="#{i18n['user.firstNames']}" sortBy="firstnames"> <p:column headerText="#{i18n['user.firstNames']}" sortBy="firstnames">
<h:outputText value="#{wra.user.firstnames}" /> <h:outputText value="#{wra.user.firstnames}" />
</p:column> </p:column>
......
...@@ -16,14 +16,16 @@ ...@@ -16,14 +16,16 @@
} }
.hidden {
display: none;
}
#webcamcontainer { #webcamcontainer {
} }
.noborderTable tr,.noborderTable td {
border: none;
padding: 0 0 1px 0;
}
#shopItems { #shopItems {
} }
...@@ -77,7 +79,6 @@ a.shopItem:active { ...@@ -77,7 +79,6 @@ a.shopItem:active {
background: red; background: red;
} }
.prime-menu-selected div .prime-menu-selected div {
{ display: block;
display:block;
} }
\ No newline at end of file
...@@ -11,33 +11,27 @@ ...@@ -11,33 +11,27 @@
<h:commandButton action="#{importView.commitImport}" value="#{i18n['userImport.commit']}" /> <h:commandButton action="#{importView.commitImport}" value="#{i18n['userImport.commit']}" />
</h:form> </h:form>
<h:dataTable id="tbl" border="1" value="#{importView.users}" var="wra"> <p:dataTable id="tbl" border="1" value="#{importView.users}" var="wra">
<h:column>
<p:column headerText="User id">
<h:outputText value="#{wra.user.id}" />
</p:column>
<p:column headerText="Eventuser id">
<h:outputText value="#{wra.eventuser.id}" />
</p:column>
<p:column headerText="Login">
<h:outputText value="#{wra.user.login}" /> <h:outputText value="#{wra.user.login}" />
</h:column> </p:column>
<h:column> <p:column headerText="Firstname">
<h:outputText value="#{wra.user.firstnames}" /> <h:outputText value="#{wra.user.firstnames}" />
</h:column> </p:column>
<h:column> <p:column headerText="Lastname">
<h:outputText value="#{wra.user.lastname}" /> <h:outputText value="#{wra.user.lastname}" />
</h:column> </p:column>
<h:column> <p:column headerText="Email">
<h:outputText value="#{wra.user.email}" />
</h:column>
<h:column>
<h:outputText value="#{wra.user.email}" />
</h:column>
<h:column>
<h:outputText value="#{wra.user.email}" /> <h:outputText value="#{wra.user.email}" />
</h:column> </p:column>
<h:column> </p:dataTable>
<h:outputText value="#{wra.eventuser.id}" />
</h:column>
</h:dataTable>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
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:users="http://java.sun.com/jsf/composite/cditools/user" <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:users="http://java.sun.com/jsf/composite/cditools/user"
xmlns:f="http://java.sun.com/jsf/core"> xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui">
<h:body> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<f:metadata> <f:metadata>
...@@ -19,66 +19,48 @@ ...@@ -19,66 +19,48 @@
<ui:define name="content"> <ui:define name="content">
<h:outputLabel value="#{i18n['user.accountBalance']}: " for="accountbalance" /> <h:outputLabel value="#{i18n['user.accountBalance']}: " for="accountbalance" />
<h:outputText id="accountbalance" value="#{userView.user.accountBalance}" /> <h:outputText id="accountbalance" value="#{userView.user.accountBalance}" />
<h:dataTable border="1" id="ac" value="#{userView.user.accountEvents}" var="ac">
<h:column> <p:dataTable border="1" styleClass="actable" id="ac" value="#{userView.user.accountEvents}" var="ac" rowIndexVar="rowIndex">
<f:facet name="header"> <p:column headerText="#{i18n['accountEvent.productname']}">
<h:outputText value="#{i18n['accountEvent.productname']}" /> <p:tooltip for="@(.actable tr[role=row][data-ri=#{rowIndex}])" value="This is row number #{rowIndex}" />
</f:facet>
<h:outputText value="#{ac.product.name}" /> <h:outputText value="#{ac.product.name}" />
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.quantity']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.quantity']}" />
</f:facet>
<h:outputText value="#{ac.quantity}"> <h:outputText value="#{ac.quantity}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" /> <f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText> </h:outputText>
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.unitPrice']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.unitPrice']}" />
</f:facet>
<h:outputText value="#{ac.unitPrice}"> <h:outputText value="#{ac.unitPrice}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" /> <f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText> </h:outputText>
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.total']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.total']}" />
</f:facet>
<h:outputText value="#{ac.total}"> <h:outputText value="#{ac.total}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" /> <f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText> </h:outputText>
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.eventTime']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.eventTime']}" />
</f:facet>
<h:outputText value="#{ac.eventTime.time}"> <h:outputText value="#{ac.eventTime.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" /> <f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText> </h:outputText>
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.delivered']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.delivered']}" />
</f:facet>
<h:outputText rendered="#{!empty ac.delivered}" value="#{ac.delivered.time}"> <h:outputText rendered="#{!empty ac.delivered}" value="#{ac.delivered.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" /> <f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText> </h:outputText>
</h:column> </p:column>
<h:column> <p:column headerText="#{i18n['accountEvent.foodwave']}">
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.foodwave']}" />
</f:facet>
<h:outputText rendered="#{!empty ac.foodWave}" value="#{ac.foodWave.name}" /> <h:outputText rendered="#{!empty ac.foodWave}" value="#{ac.foodWave.name}" />
</h:column> </p:column>
<h:column> <p:column>
<h:link outcome="/useradmin/editAccountevent" value="#{i18n['accountEvent.edit']}"> <h:link outcome="/useradmin/editAccountevent" value="#{i18n['accountEvent.edit']}">
<f:param name="id" value="#{ac.id}" /> <f:param name="id" value="#{ac.id}" />
</h:link> </h:link>
</h:column> </p:column>
</h:dataTable> </p:dataTable>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -20,19 +20,19 @@ ...@@ -20,19 +20,19 @@
<h:panelGrid columns="3"> <h:panelGrid columns="3">
<h:outputLabel for="user" value="#{i18n['accountEvent.user']}" /> <h:outputLabel for="user" value="#{i18n['accountEvent.user']}" />
<h:outputText id="user" value="#{accountEventView.accountevent.user.user.id} / #{accountEventView.accountevent.user.user.wholeName}" /> <h:outputText id="user" value="#{accountEventView.accountevent.user.user.id} / #{accountEventView.accountevent.user.user.nick} /#{accountEventView.accountevent.user.user.wholeName}" />
<h:message for="user" /> <h:message for="user" />
<h:outputLabel for="price" value="#{i18n['accountEvent.price']}" /> <h:outputLabel for="price" value="#{i18n['accountEvent.price']}" />
<h:inputText id="price" value="#{accountEventView.accountevent.unitPrice}"> <p:inputText id="price" value="#{accountEventView.accountevent.unitPrice}">
<f:convertNumber minFractionDigits="0" maxFractionDigits="4" /> <f:convertNumber minFractionDigits="0" maxFractionDigits="4" />
</h:inputText> </p:inputText>
<h:message for="price" /> <h:message for="price" />
<h:outputLabel for="quantity" value="#{i18n['accountEvent.quantity']}" /> <h:outputLabel for="quantity" value="#{i18n['accountEvent.quantity']}" />
<h:inputText id="quantity" value="#{accountEventView.accountevent.quantity}"> <p:inputText id="quantity" value="#{accountEventView.accountevent.quantity}">
<f:convertNumber minFractionDigits="0" maxFractionDigits="4" /> <f:convertNumber minFractionDigits="0" maxFractionDigits="4" />
</h:inputText> </p:inputText>
<h:message for="quantity" /> <h:message for="quantity" />
<h:outputLabel for="time" value="#{i18n['accountEvent.eventTime']}" /> <h:outputLabel for="time" value="#{i18n['accountEvent.eventTime']}" />
...@@ -43,14 +43,22 @@ ...@@ -43,14 +43,22 @@
<h:link id="fw" rendered="#{!empty accountEventView.accountevent.foodWave}" value="#{accountEventView.accountevent.foodWave.name}" outcome="/foodmanager/listOrders"> <h:link id="fw" rendered="#{!empty accountEventView.accountevent.foodWave}" value="#{accountEventView.accountevent.foodWave.name}" outcome="/foodmanager/listOrders">
<f:param name="foodwaveid" value="#{accountEventView.accountevent.foodWave.id}" /> <f:param name="foodwaveid" value="#{accountEventView.accountevent.foodWave.id}" />
</h:link> </h:link>
<h:outputText rendered="#{empty accountEventView.accountevent.foodWave}"/> <h:outputText rendered="#{empty accountEventView.accountevent.foodWave}" />
<h:message for="fw" /> <h:message for="fw" />
<h:outputLabel for="delivered" value="#{i18n['accountEvent.delivered']}" /> <h:outputLabel for="delivered" value="#{i18n['accountEvent.delivered']}" />
<p:calendar rendered="#{!empty accountEventView.accountevent.delivered}" id="delivered" value="#{accountEventView.accountevent.delivered.time}" pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" /> <p:calendar rendered="#{!empty accountEventView.accountevent.delivered}" id="delivered" value="#{accountEventView.accountevent.delivered.time}" pattern="#{sessionHandler.datetimeFormat}"
<h:outputText rendered="#{empty accountEventView.accountevent.delivered}" /> timeZone="#{sessionHandler.timezone}" />
<h:outputText rendered="#{empty accountEventView.accountevent.delivered}" />
<h:message for="delivered" /> <h:message for="delivered" />
<h:outputLabel for="seller" value="#{i18n['accountEvent.seller']}" />
<h:outputText id="seller" value="#{accountEventView.accountevent.seller.user.nick} / #{accountEventView.accountevent.seller.user.wholeName}" />
<h:message for="seller" />
<p:outputLabel for="description" value="#{i18n['accountEvent.description']}" />
<p:inputTextarea id="description" cols="30" rows="5" value="#{accountEventView.accountevent.description}" />
<p:message for="description" />
</h:panelGrid> </h:panelGrid>
<h:commandButton action="#{accountEventView.save()}" rendered="#{accountEventView.canSave}" value="#{i18n['accountEvent.save']}" /> <h:commandButton action="#{accountEventView.save()}" rendered="#{accountEventView.canSave}" value="#{i18n['accountEvent.save']}" />
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<h1>#{i18n['userlist.header']}</h1> <h1>#{i18n['userlist.header']}</h1>
<h:form> <h:form id="pageform">
<h:panelGrid columns="2"> <h:panelGrid columns="2">
<h:panelGroup> <h:panelGroup>
...@@ -51,13 +51,14 @@ ...@@ -51,13 +51,14 @@
<h:commandButton value="#{i18n['userlist.search']}" action="#{userSearchView.newSearch()}" /> <h:commandButton value="#{i18n['userlist.search']}" action="#{userSearchView.newSearch()}" />
</h:panelGroup> </h:panelGroup>
<h:panelGroup> <h:panelGroup>
<a style="display: #{((userCartView.isEmpty())?'block':'none')}" onclick="$('#usercart').show(); $(this).hide();"><h:outputText value="#{i18n['usercart.showCart']}" /></a> <a onclick="$('#pageform\\:usercart').show(); $(this).hide();"><h:outputText value="#{i18n['usercart.showCart']}" /></a>
<div id="usercart" style="display: #{((userCartView.isEmpty())?'none':'block')}">
<h:outputText value="#{i18n['usercart.cartsize']}" /> <p:panelGrid columns="1" id="usercart" styleClass="noborderTable" style="display:none;">
<h:outputText value=" #{userCartView.userCartSize}" />
<h:commandButton action="#{userCartView.clearCart()}" value="#{i18n['usercart.clear']}" />
<br />
<h:commandButton actionListener="#{userSearchView.addToCart}" value="#{i18n['usercart.addSearchedUsers']}" /> <h:commandButton actionListener="#{userSearchView.addToCart}" value="#{i18n['usercart.addSearchedUsers']}" />
<h:panelGroup>
<h:outputText value="#{i18n['usercart.cartsize']} #{userCartView.userCartSize}" />
<h:commandButton action="#{userCartView.clearCart()}" value="#{i18n['usercart.clear']}" />
</h:panelGroup>
<h:commandButton action="#{userCartView.traverse}" value="#{i18n['usercart.traverse']}" /> <h:commandButton action="#{userCartView.traverse}" value="#{i18n['usercart.traverse']}" />
<h:commandButton value="#{i18n['usercart.downloadCsv']}"> <h:commandButton value="#{i18n['usercart.downloadCsv']}">
<p:fileDownload value="#{userCartView.downloadCsv}" /> <p:fileDownload value="#{userCartView.downloadCsv}" />
...@@ -66,7 +67,10 @@ ...@@ -66,7 +67,10 @@
<p:fileDownload value="#{userCartView.userExport}" /> <p:fileDownload value="#{userCartView.userExport}" />
</h:commandButton> </h:commandButton>
<h:commandButton action="#{userCartView.showOverview}" value="#{i18n['usercart.showoverview']}" /> <h:commandButton action="#{userCartView.showOverview}" value="#{i18n['usercart.showoverview']}" />
</div>
<h:commandButton rendered="#{creditTransferView.transferPermissions}" action="#{userCartView.transferCredits}" value="#{i18n['usercart.transferCredits']}" />
</p:panelGrid>
</h:panelGroup> </h:panelGroup>
</h:panelGrid> </h:panelGrid>
</h:form> </h:form>
......
<!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:tools="http://java.sun.com/jsf/composite/cditools" xmlns:account="http://java.sun.com/jsf/composite/cditools/account" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<!-- f:event type="preRenderView" listener="#{userCartView.initView}" />
-->
</f:metadata>
<ui:define name="title">
<h1>#{i18n['user.creditTransfer.title']}</h1>
</ui:define>
<ui:define name="content">
<h:form>
<h:outputText value="#{i18n['creditTransferView.selectEvent']}" />
<p:selectOneMenu value="#{creditTransferView.sourceEvent}" converter="#{lanEventConverter}">
<f:selectItem itemLabel="---" />
<f:selectItems value="#{creditTransferView.events}" var="ev" itemLabel="#{ev.name}" />
</p:selectOneMenu>
<h:commandButton action="#{creditTransferView.selectEvent}" value="#{i18n['creditTransfer.selectEvent']}" />
</h:form>
<h:outputText value="#{i18n['creditTransfer.totalCredits']} #{creditTransferView.totalCredits}" />
<h:form>
<h:commandButton value="#{i18n['creditTransferView.commitTransfer']}" action="#{creditTransferView.commitTransfer}" />
<p:dataTable value="#{creditTransferView.users}" var="wrap">
<p:column headerText="#{i18n['user.nick']}">
<h:outputText value="#{wrap.user.user.nick}" />
</p:column>
<p:column headerText="#{i18n['creditTransfer.dstEventuserId']}">
<h:outputText value="#{wrap.user.id}" />
</p:column>
<p:column headerText="#{i18n['creditTransfer.srcEventuserId']}">
<h:outputText value="#{wrap.sourceEventuser.id}" />
</p:column>
<p:column headerText="#{i18n['creditTransfer.credits']}">
<h:outputText value="#{wrap.credits}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -64,7 +64,6 @@ public class SessionHandler { ...@@ -64,7 +64,6 @@ public class SessionHandler {
String retStr = "fi_FI"; String retStr = "fi_FI";
if (ret != null) { if (ret != null) {
retStr = ret.toLanguageTag(); retStr = ret.toLanguageTag();
logger.info("Got langtag {}", retStr);
} }
return retStr; return retStr;
} }
......
...@@ -9,6 +9,7 @@ import java.util.Map; ...@@ -9,6 +9,7 @@ import java.util.Map;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.ListDataModel; import javax.faces.model.ListDataModel;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
...@@ -162,6 +163,15 @@ public class ProductShopView extends GenericCDIView { ...@@ -162,6 +163,15 @@ public class ProductShopView extends GenericCDIView {
} }
} }
public void countChangeListener(ValueChangeEvent e)
{
ProductShopItem item = shoppingcart.getRowData();
logger.info("Count change from event {}, from item {}", e.getNewValue(), item.getCount());
psiHelper.setProductShopItemCount(item, item.getCount());
updateCartLimits(item);
}
public String add(Integer count) { public String add(Integer count) {
ProductShopItem item = shoppingcart.getRowData(); ProductShopItem item = shoppingcart.getRowData();
......
package fi.codecrew.moya.web.cdiview.user;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.apps.EventPermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class CreditTransferView extends GenericCDIView {
private static final long serialVersionUID = -4254396884077758765L;
private List<EventUserWrapper> users;
@EJB
private UserBeanLocal userbean;
@EJB
private EventBeanLocal eventbean;
private List<LanEvent> events;
private LanEvent sourceEvent;
private BigDecimal totalCredits;
private BigDecimal totalTransferred;
public void init(List<EventUser> users) {
ArrayList<EventUserWrapper> wrap = new ArrayList<EventUserWrapper>();
for (EventUser u : users) {
wrap.add(new EventUserWrapper(u));
}
this.users = wrap;
events = eventbean.getCurrentEvent().getOrganiser().getEvents();
}
public String selectEvent() {
BigDecimal total = BigDecimal.ZERO;
if (sourceEvent != null && !eventbean.getCurrentEvent().equals(sourceEvent))
{
for (EventUserWrapper u : users) {
u.setSourceEventuser(userbean.getOtherEventsEventuser(u.getUser().getUser(), sourceEvent));
if (u.getSourceEventuser() != null) {
u.setCredits(u.getSourceEventuser().getAccountBalance());
total = total.add(u.getCredits());
} else {
u.setCredits(BigDecimal.ZERO);
}
}
}
this.totalCredits = total;
return null;
}
public String commitTransfer() {
List<User> transfer = new ArrayList<User>();
for (EventUserWrapper u : users) {
transfer.add(u.getUser().getUser());
}
totalTransferred = userbean.transferAccountSaldoFromPreviousEvent(transfer, sourceEvent);
users = null;
return null;
}
public boolean isTransferPermissions() {
return super.hasPermission(EventPermission.MANAGE_EVENT);
}
public List<LanEvent> getEvents() {
return events;
}
public void setEvents(List<LanEvent> events) {
this.events = events;
}
public LanEvent getSourceEvent() {
return sourceEvent;
}
public void setSourceEvent(LanEvent sourceEvent) {
this.sourceEvent = sourceEvent;
}
public List<EventUserWrapper> getUsers() {
return users;
}
public void setUsers(List<EventUserWrapper> users) {
this.users = users;
}
public BigDecimal getTotalCredits() {
return totalCredits;
}
public void setTotalCredits(BigDecimal totalCredits) {
this.totalCredits = totalCredits;
}
public BigDecimal getTotalTransferred() {
return totalTransferred;
}
public void setTotalTransferred(BigDecimal totalTransferred) {
this.totalTransferred = totalTransferred;
}
public static class EventUserWrapper {
private final EventUser user;
private BigDecimal credits = BigDecimal.ZERO;
private EventUser sourceEventuser;
private EventUserWrapper(EventUser u) {
super();
this.user = u;
}
public EventUser getUser() {
return user;
}
public BigDecimal getCredits() {
return credits;
}
public void setCredits(BigDecimal credits) {
this.credits = credits;
}
public EventUser getSourceEventuser() {
return sourceEventuser;
}
public void setSourceEventuser(EventUser sourceEventuser) {
this.sourceEventuser = sourceEventuser;
}
}
}
...@@ -9,6 +9,8 @@ import javax.enterprise.context.ConversationScoped; ...@@ -9,6 +9,8 @@ import javax.enterprise.context.ConversationScoped;
import javax.inject.Named; import javax.inject.Named;
import org.primefaces.model.UploadedFile; import org.primefaces.model.UploadedFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.UserBeanLocal; import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.apps.UserPermission; import fi.codecrew.moya.enums.apps.UserPermission;
...@@ -38,6 +40,7 @@ public class ImportView extends GenericCDIView { ...@@ -38,6 +40,7 @@ public class ImportView extends GenericCDIView {
private UploadedFile file; private UploadedFile file;
private ArrayList<ImportWrapper> users; private ArrayList<ImportWrapper> users;
private Charset UTF8 = Charset.forName("UTF8"); private Charset UTF8 = Charset.forName("UTF8");
private static final Logger logger = LoggerFactory.getLogger(ImportView.class);
// //
// private ArrayList<ImportWrapper> wrapper; // private ArrayList<ImportWrapper> wrapper;
...@@ -50,7 +53,7 @@ public class ImportView extends GenericCDIView { ...@@ -50,7 +53,7 @@ public class ImportView extends GenericCDIView {
// //
public void initImport() { public void initImport() {
if (requirePermissions(UserPermission.MODIFY_ACCOUNTEVENTS)) { if (requirePermissions(UserPermission.MODIFY_ACCOUNTEVENTS)) {
super.beginConversation();
} }
} }
...@@ -89,6 +92,15 @@ public class ImportView extends GenericCDIView { ...@@ -89,6 +92,15 @@ public class ImportView extends GenericCDIView {
return "commitImport"; return "commitImport";
} }
public String commitImport() {
for (ImportWrapper u : users) {
userbean.getEventUser(u.getUser(), true);
}
return "/useradmin/list?faces-redirect=true";
}
public static class ImportWrapper public static class ImportWrapper
{ {
......
...@@ -34,6 +34,8 @@ public class UserCartView extends GenericCDIView { ...@@ -34,6 +34,8 @@ public class UserCartView extends GenericCDIView {
@Inject @Inject
private UserView userview; private UserView userview;
@Inject
private CreditTransferView credTransfer;
@Inject @Inject
private UserOverviewView userOverviewView; private UserOverviewView userOverviewView;
...@@ -113,6 +115,11 @@ public class UserCartView extends GenericCDIView { ...@@ -113,6 +115,11 @@ public class UserCartView extends GenericCDIView {
return null; return null;
} }
public String transferCredits() {
credTransfer.init(usercart);
return "/useradmin/transferCredits";
}
public String prev() { public String prev() {
--current; --current;
updateCurrent(); updateCurrent();
...@@ -217,4 +224,12 @@ public class UserCartView extends GenericCDIView { ...@@ -217,4 +224,12 @@ public class UserCartView extends GenericCDIView {
this.current = current; this.current = current;
} }
public CreditTransferView getCredTransfer() {
return credTransfer;
}
public void setCredTransfer(CreditTransferView credTransfer) {
this.credTransfer = credTransfer;
}
} }
package fi.codecrew.moya.web.converter;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.utilities.jsf.GenericIntegerEntityConverter;
@Named
@RequestScoped
public class LanEventConverter extends GenericIntegerEntityConverter<LanEvent> {
@EJB
private EventBeanLocal eventbean;
@Override
protected LanEvent find(Integer id) {
return eventbean.getEventById(id);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!