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 {
public LanEventProperty getProperty(LanEventPropertyKey property) {
return eventPropertyFacade.find(getCurrentEvent(), property);
}
@Override
public long getPropertyLong(LanEventPropertyKey property)
{
......@@ -201,8 +200,6 @@ public class EventBean implements EventBeanLocal {
}
return ret;
}
@Override
public String getPropertyString(LanEventPropertyKey property)
......@@ -266,4 +263,14 @@ public class EventBean implements EventBeanLocal {
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;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB;
import javax.ejb.EJBAccessException;
import javax.ejb.EJBException;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.imageio.ImageIO;
......@@ -30,15 +31,18 @@ import javax.persistence.PersistenceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.enums.apps.EventPermission;
import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.facade.AccountEventFacade;
import fi.codecrew.moya.facade.ApprovalFacade;
import fi.codecrew.moya.facade.EventFacade;
import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.FeedbackFacade;
import fi.codecrew.moya.facade.GameIDFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.PlaceGroupFacade;
import fi.codecrew.moya.facade.ProductFacade;
import fi.codecrew.moya.facade.RoleFacade;
import fi.codecrew.moya.facade.UserApprovalFacade;
import fi.codecrew.moya.facade.UserFacade;
......@@ -75,6 +79,7 @@ import fi.codecrew.moya.utilities.SearchResult;
UserPermission.S_INVITE_USERS,
UserPermission.S_MODIFY,
SpecialPermission.S_USER,
EventPermission.S_MANAGE_EVENT,
})
public class UserBean implements UserBeanLocal {
......@@ -137,6 +142,10 @@ public class UserBean implements UserBeanLocal {
private ProductPBean productPrivateBean;
@EJB
private AccountEventFacade accountEventFacade;
@EJB
private EventFacade eventfacade;
@EJB
private ProductFacade productFacade;
@Override
@RolesAllowed(UserPermission.S_VIEW_ALL)
......@@ -802,56 +811,78 @@ public class UserBean implements UserBeanLocal {
return ret;
}
/**
* 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.
* </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)
@Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT)
public BigDecimal transferAccountSaldoFromPreviousEvent(List<User> users, LanEvent source)
{
if (source == null || dst == null)
return null;
source = eventUserFacade.reload(source);
dst = eventUserFacade.reload(dst);
if (!source.getEvent().getOrganiser().equals(dst.getEvent().getOrganiser())) {
logger.warn("Can not transfer funds between organisations!");
if (source == null || users == null || users.isEmpty())
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())) {
logger.warn("Can not transfer accountenvets! Users should be the same!!! Source {}, dst {}", source.getUser(), dst.getUser());
return null;
final Calendar time = Calendar.getInstance();
final EventUser seller = permbean.getCurrentUser();
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();
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;
return eventUserFacade.getOtherOrganisationsEventuser(user, event);
}
}
\ No newline at end of file
......@@ -89,10 +89,13 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
}
public EventUser find(User user) {
LanEvent event = eventBean.getCurrentEvent();
EventUser ret;
if ((ret = checkCache(user.getLogin(), event)) == null)
{
return getOtherOrganisationsEventuser(user, eventBean.getCurrentEvent());
}
public EventUser getOtherOrganisationsEventuser(User user, LanEvent event)
{
EventUser ret = null;
if ((ret = checkCache(user.getLogin(), event)) == null) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<EventUser> cq = cb.createQuery(EventUser.class);
Root<EventUser> root = cq.from(EventUser.class);
......
......@@ -12,6 +12,7 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.model.Product_;
......@@ -44,11 +45,15 @@ public class ProductFacade extends IntegerPkGenericFacade<Product> {
}
public List<Product> findProductsByPrice(BigDecimal price) {
return findProductsByPrice(price, eventbean.getCurrentEvent());
}
public List<Product> findProductsByPrice(BigDecimal price, LanEvent event) {
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_.event), eventbean.getCurrentEvent()),
cq.where(cb.equal(root.get(Product_.event), event),
cb.equal(root.get(Product_.price), price));
return getEm().createQuery(cq).getResultList();
......
......@@ -35,7 +35,9 @@ public interface EventBeanLocal {
List<LanEventPrivateProperty> getPrivateProperties();
LanEventPrivateProperty saveOrCreatePrivateProperty(LanEventPrivateProperty privateProperty);
long getPropertyLong(LanEventPropertyKey property);
LanEvent getEventById(Integer id);
}
......@@ -2,6 +2,7 @@ package fi.codecrew.moya.beans;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.List;
import javax.ejb.Local;
......@@ -10,6 +11,7 @@ import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Feedback;
import fi.codecrew.moya.model.GameID;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.User;
......@@ -104,4 +106,23 @@ public interface UserBeanLocal {
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;
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class AccountEvent extends GenericEntity {
private static final long serialVersionUID = 2588419823225148100L;
@Column(name = "cash", nullable = false)
private boolean cash = false;
/**
* What 1 unit of this product costs.
*/
@Column(name = "unit_price", nullable = false, precision = 24, scale = 4)
private BigDecimal unitPrice;
/**
* The units of the product, eg 1.345 (l), 5 (units) 888.32 (g)..
*/
@Column(name = "quantity", nullable = false, precision = 24, scale = 4)
private BigDecimal quantity;
/**
* The time this AccountEvent is created.
*/
@Column(name = "event_time", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Calendar eventTime = Calendar.getInstance();
/**
* Is the product delivered to the user.
*/
@Column(name = "delivered")
@Temporal(TemporalType.TIMESTAMP)
private Calendar delivered;
@Column(name = "delivered_count", nullable = false, precision = 24, scale = 4)
private BigDecimal deliveredCount = new BigDecimal(0);
/**
* If this AccountEvent is a product in foodwace, this field is a reference
* to that foodwave.
*/
@JoinColumn(name = "food_wave_id", referencedColumnName = FoodWave.ID_COLUMN)
@ManyToOne
private FoodWave foodWave;
/**
* The product user has acquired and this this AccountEvent is a reference
* to.
*/
@JoinColumn(name = "product_id", referencedColumnName = Product.ID_COLUMN, nullable = false)
@ManyToOne(optional = false)
private Product product;
/**
* The user that bought the products.
*/
@JoinColumn(name = "eventuser_id", referencedColumnName = EventUser.ID_COLUMN, nullable = false)
@ManyToOne(optional = false)
private EventUser user;
/**
* Who sold the items to the user.
*/
@JoinColumn(name = "seller_eventuser_id", referencedColumnName = EventUser.ID_COLUMN)
@ManyToOne(optional = true)
private EventUser seller;
/**
* What discounts user has for this account event. Some magic is applied to
* calculate these.. :)
*/
@OneToMany(mappedBy = "accountEvent", cascade = CascadeType.ALL)
private List<DiscountInstance> discountInstances = new ArrayList<DiscountInstance>();
/**
* When user has paid a bill a Account event for product "Credit" is created
* and reference to that bill is here..
*/
@OneToOne(mappedBy = "accountEvent")
private Bill bill;
@Lob
private String description;
public BigDecimal getTotal() {
return getQuantity().multiply(getUnitPrice());
}
public AccountEvent() {
}
public AccountEvent(EventUser u, Product prod, BigDecimal unitPrice, BigDecimal quantity, Calendar eventTime) {
this.setUnitPrice(unitPrice);
this.setQuantity(quantity);
this.product = prod;
this.eventTime = eventTime;
this.user = u;
}
public Calendar getEventTime() {
return eventTime;
}
public void setEventTime(Calendar eventTime) {
this.eventTime = eventTime;
}
public Calendar getDelivered() {
return delivered;
}
public void setDelivered(Calendar delivered) {
this.delivered = delivered;
}
public EventUser getUser() {
return user;
}
public void setUser(EventUser usersId) {
this.user = usersId;
}
public List<DiscountInstance> getDiscountInstances() {
return discountInstances;
}
public void setDiscountInstances(List<DiscountInstance> discountInstanceList) {
this.discountInstances = discountInstanceList;
}
public void setFoodWave(FoodWave foodWave) {
this.foodWave = foodWave;
}
public FoodWave getFoodWave() {
return foodWave;
}
public void setProduct(Product product) {
this.product = product;
}
public Product getProduct() {
return product;
}
public void setSeller(EventUser seller) {
this.seller = seller;
}
public EventUser getSeller() {
return seller;
}
public void setBill(Bill bill) {
this.bill = bill;
}
public Bill getBill() {
return bill;
}
public void setUnitPrice(BigDecimal unitPrice) {
this.unitPrice = unitPrice;
}
public BigDecimal getUnitPrice() {
return unitPrice;
}
public void setQuantity(BigDecimal quantity) {
this.quantity = quantity;
}
public BigDecimal getQuantity() {
return quantity;
}
public void setCash(boolean cash) {
this.cash = cash;
}
public boolean isCash() {
return cash;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public BigDecimal getDeliveredCount() {
return deliveredCount;
}
private static final long serialVersionUID = 2588419823225148100L;
@Column(name = "cash", nullable = false)
private boolean cash = false;
/**
* What 1 unit of this product costs.
*/
@Column(name = "unit_price", nullable = false, precision = 24, scale = 4)
private BigDecimal unitPrice;
/**
* The units of the product, eg 1.345 (l), 5 (units) 888.32 (g)..
*/
@Column(name = "quantity", nullable = false, precision = 24, scale = 4)
private BigDecimal quantity;
/**
* The time this AccountEvent is created.
*/
@Column(name = "event_time", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Calendar eventTime = Calendar.getInstance();
/**
* Is the product delivered to the user.
*/
@Column(name = "delivered")
@Temporal(TemporalType.TIMESTAMP)
private Calendar delivered;
@Column(name = "delivered_count", nullable = false, precision = 24, scale = 4)
private BigDecimal deliveredCount = new BigDecimal(0);
/**
* If this AccountEvent is a product in foodwace, this field is a reference
* to that foodwave.
*/
@JoinColumn(name = "food_wave_id", referencedColumnName = FoodWave.ID_COLUMN)
@ManyToOne
private FoodWave foodWave;
/**
* The product user has acquired and this this AccountEvent is a reference
* to.
*/
@JoinColumn(name = "product_id", referencedColumnName = Product.ID_COLUMN, nullable = false)
@ManyToOne(optional = false)
private Product product;
/**
* The user that bought the products.
*/
@JoinColumn(name = "eventuser_id", referencedColumnName = EventUser.ID_COLUMN, nullable = false)
@ManyToOne(optional = false)
private EventUser user;
/**
* Who sold the items to the user.
*/
@JoinColumn(name = "seller_eventuser_id", referencedColumnName = EventUser.ID_COLUMN)
@ManyToOne(optional = true)
private EventUser seller;
/**
* What discounts user has for this account event. Some magic is applied to
* calculate these.. :)
*/
@OneToMany(mappedBy = "accountEvent", cascade = CascadeType.ALL)
private List<DiscountInstance> discountInstances = new ArrayList<DiscountInstance>();
/**
* When user has paid a bill a Account event for product "Credit" is created
* and reference to that bill is here..
*/
@OneToOne(mappedBy = "accountEvent")
private Bill bill;
@Lob
private String description;
public BigDecimal getTotal() {
return getQuantity().multiply(getUnitPrice());
}
public AccountEvent() {
}
public AccountEvent(EventUser u, Product prod, BigDecimal unitPrice, BigDecimal quantity, Calendar eventTime) {
if (!u.getEvent().equals(prod.getEvent())) {
throw new RuntimeException("User and product are not in the same event!");
}
this.setUnitPrice(unitPrice);
this.setQuantity(quantity);
this.product = prod;
this.eventTime = eventTime;
this.user = u;
}
public Calendar getEventTime() {
return eventTime;
}
public void setEventTime(Calendar eventTime) {
this.eventTime = eventTime;
}
public Calendar getDelivered() {
return delivered;
}
public void setDelivered(Calendar delivered) {
this.delivered = delivered;
}
public EventUser getUser() {
return user;
}
public void setUser(EventUser usersId) {
this.user = usersId;
}
public List<DiscountInstance> getDiscountInstances() {
return discountInstances;
}
public void setDiscountInstances(List<DiscountInstance> discountInstanceList) {
this.discountInstances = discountInstanceList;
}
public void setFoodWave(FoodWave foodWave) {
this.foodWave = foodWave;
}
public FoodWave getFoodWave() {
return foodWave;
}
public void setProduct(Product product) {
this.product = product;
}
public Product getProduct() {
return product;
}
public void setSeller(EventUser seller) {
this.seller = seller;
}
public EventUser getSeller() {
return seller;
}
public void setBill(Bill bill) {
this.bill = bill;
}
public Bill getBill() {
return bill;
}
public void setUnitPrice(BigDecimal unitPrice) {
this.unitPrice = unitPrice;
}
public BigDecimal getUnitPrice() {
return unitPrice;
}
public void setQuantity(BigDecimal quantity) {
this.quantity = quantity;
}
public BigDecimal getQuantity() {
return quantity;
}
public void setCash(boolean cash) {
this.cash = cash;
}
public boolean isCash() {
return cash;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public BigDecimal getDeliveredCount() {
return deliveredCount;
}
public void setDeliveredCount(BigDecimal deliveredCount) {
this.deliveredCount = deliveredCount;
}
public void setDeliveredCount(BigDecimal deliveredCount) {
this.deliveredCount = deliveredCount;
}
public boolean isEventDelivered() {
return (delivered != null);
}
public boolean isEventDelivered() {
return (delivered != null);
}
}
......@@ -466,6 +466,9 @@ public class EventUser extends GenericEntity {
if (accountEvents == null) {
accountEvents = new ArrayList<AccountEvent>();
}
if (!this.equals(accountevent.getUser())) {
throw new RuntimeException("Trying to add accountevent for eventuser with different eventuser");
}
accountEvents.add(accountevent);
}
}
......@@ -46,7 +46,7 @@
</p:column>
<p:column sortBy="login" headerText="#{i18n['user.login']}">
<h:outputText value="#{wra.user.login}" />
<h:outputText value="#{user.login}" />
</p:column>
<p:column headerText="#{i18n['user.firstNames']}" sortBy="firstnames">
<h:outputText value="#{user.firstnames}" />
......
......@@ -11,12 +11,13 @@
<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']}">
<h:outputText value="#{(empty wra.user.nick)?'----':wra.user.nick}" />
</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">
<h:outputText value="#{wra.user.firstnames}" />
</p:column>
......
......@@ -16,14 +16,16 @@
}
.hidden {
display: none;
}
#webcamcontainer {
}
.noborderTable tr,.noborderTable td {
border: none;
padding: 0 0 1px 0;
}
#shopItems {
}
......@@ -77,7 +79,6 @@ a.shopItem:active {
background: red;
}
.prime-menu-selected div
{
display:block;
.prime-menu-selected div {
display: block;
}
\ No newline at end of file
......@@ -11,33 +11,27 @@
<h:commandButton action="#{importView.commitImport}" value="#{i18n['userImport.commit']}" />
</h:form>
<h:dataTable id="tbl" border="1" value="#{importView.users}" var="wra">
<h:column>
<p:dataTable id="tbl" border="1" value="#{importView.users}" var="wra">
<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:column>
<h:column>
</p:column>
<p:column headerText="Firstname">
<h:outputText value="#{wra.user.firstnames}" />
</h:column>
<h:column>
</p:column>
<p:column headerText="Lastname">
<h:outputText value="#{wra.user.lastname}" />
</h:column>
<h:column>
<h:outputText value="#{wra.user.email}" />
</h:column>
<h:column>
<h:outputText value="#{wra.user.email}" />
</h:column>
<h:column>
</p:column>
<p:column headerText="Email">
<h:outputText value="#{wra.user.email}" />
</h:column>
<h:column>
<h:outputText value="#{wra.eventuser.id}" />
</h:column>
</h:dataTable>
</p:column>
</p:dataTable>
</ui:define>
</ui:composition>
......
......@@ -2,7 +2,7 @@
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: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>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
......@@ -19,66 +19,48 @@
<ui:define name="content">
<h:outputLabel value="#{i18n['user.accountBalance']}: " for="accountbalance" />
<h:outputText id="accountbalance" value="#{userView.user.accountBalance}" />
<h:dataTable border="1" id="ac" value="#{userView.user.accountEvents}" var="ac">
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.productname']}" />
</f:facet>
<p:dataTable border="1" styleClass="actable" id="ac" value="#{userView.user.accountEvents}" var="ac" rowIndexVar="rowIndex">
<p:column headerText="#{i18n['accountEvent.productname']}">
<p:tooltip for="@(.actable tr[role=row][data-ri=#{rowIndex}])" value="This is row number #{rowIndex}" />
<h:outputText value="#{ac.product.name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.quantity']}" />
</f:facet>
</p:column>
<p:column headerText="#{i18n['accountEvent.quantity']}">
<h:outputText value="#{ac.quantity}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.unitPrice']}" />
</f:facet>
</p:column>
<p:column headerText="#{i18n['accountEvent.unitPrice']}">
<h:outputText value="#{ac.unitPrice}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.total']}" />
</f:facet>
</p:column>
<p:column headerText="#{i18n['accountEvent.total']}">
<h:outputText value="#{ac.total}">
<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.eventTime']}" />
</f:facet>
</p:column>
<p:column headerText="#{i18n['accountEvent.eventTime']}">
<h:outputText value="#{ac.eventTime.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.delivered']}" />
</f:facet>
</p:column>
<p:column headerText="#{i18n['accountEvent.delivered']}">
<h:outputText rendered="#{!empty ac.delivered}" value="#{ac.delivered.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['accountEvent.foodwave']}" />
</f:facet>
</p:column>
<p:column headerText="#{i18n['accountEvent.foodwave']}">
<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']}">
<f:param name="id" value="#{ac.id}" />
</h:link>
</h:column>
</h:dataTable>
</p:column>
</p:dataTable>
</ui:define>
</ui:composition>
</h:body>
......
......@@ -20,19 +20,19 @@
<h:panelGrid columns="3">
<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: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" />
</h:inputText>
</p:inputText>
<h:message for="price" />
<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" />
</h:inputText>
</p:inputText>
<h:message for="quantity" />
<h:outputLabel for="time" value="#{i18n['accountEvent.eventTime']}" />
......@@ -43,14 +43,22 @@
<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}" />
</h:link>
<h:outputText rendered="#{empty accountEventView.accountevent.foodWave}"/>
<h:outputText rendered="#{empty accountEventView.accountevent.foodWave}" />
<h:message for="fw" />
<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}" />
<h:outputText rendered="#{empty accountEventView.accountevent.delivered}" />
<p:calendar rendered="#{!empty accountEventView.accountevent.delivered}" id="delivered" value="#{accountEventView.accountevent.delivered.time}" pattern="#{sessionHandler.datetimeFormat}"
timeZone="#{sessionHandler.timezone}" />
<h:outputText rendered="#{empty accountEventView.accountevent.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:commandButton action="#{accountEventView.save()}" rendered="#{accountEventView.canSave}" value="#{i18n['accountEvent.save']}" />
......
......@@ -19,7 +19,7 @@
<h1>#{i18n['userlist.header']}</h1>
<h:form>
<h:form id="pageform">
<h:panelGrid columns="2">
<h:panelGroup>
......@@ -51,13 +51,14 @@
<h:commandButton value="#{i18n['userlist.search']}" action="#{userSearchView.newSearch()}" />
</h:panelGroup>
<h:panelGroup>
<a style="display: #{((userCartView.isEmpty())?'block':'none')}" onclick="$('#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']}" />
<h:outputText value=" #{userCartView.userCartSize}" />
<h:commandButton action="#{userCartView.clearCart()}" value="#{i18n['usercart.clear']}" />
<br />
<a onclick="$('#pageform\\:usercart').show(); $(this).hide();"><h:outputText value="#{i18n['usercart.showCart']}" /></a>
<p:panelGrid columns="1" id="usercart" styleClass="noborderTable" style="display:none;">
<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 value="#{i18n['usercart.downloadCsv']}">
<p:fileDownload value="#{userCartView.downloadCsv}" />
......@@ -66,7 +67,10 @@
<p:fileDownload value="#{userCartView.userExport}" />
</h:commandButton>
<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:panelGrid>
</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 {
String retStr = "fi_FI";
if (ret != null) {
retStr = ret.toLanguageTag();
logger.info("Got langtag {}", retStr);
}
return retStr;
}
......
......@@ -9,6 +9,7 @@ import java.util.Map;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.ListDataModel;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -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) {
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;
import javax.inject.Named;
import org.primefaces.model.UploadedFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.apps.UserPermission;
......@@ -38,6 +40,7 @@ public class ImportView extends GenericCDIView {
private UploadedFile file;
private ArrayList<ImportWrapper> users;
private Charset UTF8 = Charset.forName("UTF8");
private static final Logger logger = LoggerFactory.getLogger(ImportView.class);
//
// private ArrayList<ImportWrapper> wrapper;
......@@ -50,7 +53,7 @@ public class ImportView extends GenericCDIView {
//
public void initImport() {
if (requirePermissions(UserPermission.MODIFY_ACCOUNTEVENTS)) {
super.beginConversation();
}
}
......@@ -89,6 +92,15 @@ public class ImportView extends GenericCDIView {
return "commitImport";
}
public String commitImport() {
for (ImportWrapper u : users) {
userbean.getEventUser(u.getUser(), true);
}
return "/useradmin/list?faces-redirect=true";
}
public static class ImportWrapper
{
......
......@@ -34,6 +34,8 @@ public class UserCartView extends GenericCDIView {
@Inject
private UserView userview;
@Inject
private CreditTransferView credTransfer;
@Inject
private UserOverviewView userOverviewView;
......@@ -113,6 +115,11 @@ public class UserCartView extends GenericCDIView {
return null;
}
public String transferCredits() {
credTransfer.init(usercart);
return "/useradmin/transferCredits";
}
public String prev() {
--current;
updateCurrent();
......@@ -217,4 +224,12 @@ public class UserCartView extends GenericCDIView {
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!