Commit 1a4f03e3 by Tuomas Riihimäki

Added user export and initial accountevent moving

1 parent fe44ba6d
...@@ -30,7 +30,7 @@ public class ProductPBean { ...@@ -30,7 +30,7 @@ public class ProductPBean {
@EJB @EJB
private PermissionBean permbean; private PermissionBean permbean;
@EJB @EJB
private DiscountBean discountBean; private DiscountBean discountBean;
@EJB @EJB
...@@ -100,10 +100,8 @@ public class ProductPBean { ...@@ -100,10 +100,8 @@ public class ProductPBean {
// discountinstancefacade.create(discInst); // discountinstancefacade.create(discInst);
accEventdiscounts.add(new DiscountInstance(ret, d)); accEventdiscounts.add(new DiscountInstance(ret, d));
} }
if (user.getAccountEvents() == null) {
user.setAccountEvents(new ArrayList<AccountEvent>()); user.addAccountevent(ret);
}
user.getAccountEvents().add(ret);
accounteventfacade.create(ret); accounteventfacade.create(ret);
logger.debug("create ac {} for user {}", ret, user.getUser()); logger.debug("create ac {} for user {}", ret, user.getUser());
// flush changes to db. // flush changes to db.
......
...@@ -7,6 +7,7 @@ import java.io.ByteArrayInputStream; ...@@ -7,6 +7,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
...@@ -31,6 +32,7 @@ import org.slf4j.LoggerFactory; ...@@ -31,6 +32,7 @@ import org.slf4j.LoggerFactory;
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.ApprovalFacade; import fi.codecrew.moya.facade.ApprovalFacade;
import fi.codecrew.moya.facade.EventUserFacade; import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.FeedbackFacade; import fi.codecrew.moya.facade.FeedbackFacade;
...@@ -41,6 +43,7 @@ import fi.codecrew.moya.facade.RoleFacade; ...@@ -41,6 +43,7 @@ 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;
import fi.codecrew.moya.facade.UserImageFacade; import fi.codecrew.moya.facade.UserImageFacade;
import fi.codecrew.moya.model.AccountEvent;
import fi.codecrew.moya.model.Approval; import fi.codecrew.moya.model.Approval;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Feedback; import fi.codecrew.moya.model.Feedback;
...@@ -51,6 +54,7 @@ import fi.codecrew.moya.model.LanEvent; ...@@ -51,6 +54,7 @@ import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LanEventPropertyKey; import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceGroup; import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PrintedCard; import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.model.Product;
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;
...@@ -129,6 +133,10 @@ public class UserBean implements UserBeanLocal { ...@@ -129,6 +133,10 @@ public class UserBean implements UserBeanLocal {
private GameIDFacade gameIDFacade; private GameIDFacade gameIDFacade;
@EJB @EJB
private ProductBeanLocal productbean; private ProductBeanLocal productbean;
@EJB
private ProductPBean productPrivateBean;
@EJB
private AccountEventFacade accountEventFacade;
@Override @Override
@RolesAllowed(UserPermission.S_VIEW_ALL) @RolesAllowed(UserPermission.S_VIEW_ALL)
...@@ -791,4 +799,57 @@ public class UserBean implements UserBeanLocal { ...@@ -791,4 +799,57 @@ public class UserBean implements UserBeanLocal {
return ret; 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)
{
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!");
return null;
}
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;
}
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;
}
} }
\ No newline at end of file
...@@ -36,430 +36,436 @@ import fi.codecrew.moya.enums.Gender; ...@@ -36,430 +36,436 @@ import fi.codecrew.moya.enums.Gender;
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS) @OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class EventUser extends GenericEntity { public class EventUser extends GenericEntity {
protected static final String USER_ID_COLUMN = "user_id"; protected static final String USER_ID_COLUMN = "user_id";
protected static final String EVENT_ID_COLUMN = "event_id"; protected static final String EVENT_ID_COLUMN = "event_id";
@ManyToOne(cascade = { PERSIST, MERGE, REFRESH, DETACH }) @ManyToOne(cascade = { PERSIST, MERGE, REFRESH, DETACH })
@JoinColumn(nullable = false, name = USER_ID_COLUMN) @JoinColumn(nullable = false, name = USER_ID_COLUMN)
private User user; private User user;
@ManyToOne @ManyToOne
@JoinColumn(nullable = false, name = EVENT_ID_COLUMN) @JoinColumn(nullable = false, name = EVENT_ID_COLUMN)
private LanEvent event; private LanEvent event;
private static final long serialVersionUID = 6042691271548196815L; private static final long serialVersionUID = 6042691271548196815L;
@OneToMany(mappedBy = "voter") @OneToMany(mappedBy = "voter")
private List<Vote> votes; private List<Vote> votes;
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL) @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<UserNote> notes; private List<UserNote> notes;
@ManyToMany(mappedBy = "users") @ManyToMany(mappedBy = "users")
private List<Role> roles = new ArrayList<Role>(); private List<Role> roles = new ArrayList<Role>();
@OneToMany(mappedBy = "user") @OneToMany(mappedBy = "user")
private List<CompoEntryParticipant> compoEntryParticipants; private List<CompoEntryParticipant> compoEntryParticipants;
@OneToMany(mappedBy = "creator") @OneToMany(mappedBy = "creator")
@OrderBy() @OrderBy()
private List<CompoEntry> compoEntries; private List<CompoEntry> compoEntries;
@OneToMany(mappedBy = "creator", cascade = CascadeType.ALL) @OneToMany(mappedBy = "creator", cascade = CascadeType.ALL)
private List<PlaceGroup> placeGroups = new ArrayList<PlaceGroup>(); private List<PlaceGroup> placeGroups = new ArrayList<PlaceGroup>();
@OneToMany(mappedBy = "user") @OneToMany(mappedBy = "user")
@OrderBy @OrderBy
private List<GroupMembership> groupMemberships; private List<GroupMembership> groupMemberships;
/** /**
* The places this user has registered into. * The places this user has registered into.
*/ */
@OneToMany(mappedBy = "currentUser", fetch = FetchType.LAZY) @OneToMany(mappedBy = "currentUser", fetch = FetchType.LAZY)
@OrderBy() @OrderBy()
private List<Place> currentPlaces; private List<Place> currentPlaces;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user") @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
private List<PrintedCard> printedCards; private List<PrintedCard> printedCards;
@OneToMany(mappedBy = "user") @OneToMany(mappedBy = "user")
@OrderBy() @OrderBy()
private List<AccountEvent> accountEvents; private List<AccountEvent> accountEvents;
@OneToMany(mappedBy = "user") @OneToMany(mappedBy = "user")
@OrderBy() @OrderBy()
private List<Bill> bills; private List<Bill> bills;
@OneToMany(mappedBy = "seller") @OneToMany(mappedBy = "seller")
@OrderBy(AccountEvent.ID_COLUMN) @OrderBy(AccountEvent.ID_COLUMN)
private List<AccountEvent> soldItems; private List<AccountEvent> soldItems;
@OneToMany(mappedBy = "user") @OneToMany(mappedBy = "user")
private List<PollAnswer> pollAnswers; private List<PollAnswer> pollAnswers;
@ManyToOne() @ManyToOne()
@JoinColumn(name = "creator") @JoinColumn(name = "creator")
private EventUser creator; private EventUser creator;
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
@Column(name = "createtime", nullable = false, updatable = false) @Column(name = "createtime", nullable = false, updatable = false)
private Date eventuserCreated; private Date eventuserCreated;
@OneToMany(mappedBy = "eventUser") @OneToMany(mappedBy = "eventUser")
private List<GameID> gameIDs; private List<GameID> gameIDs;
public List<GameID> getGameIDs() { public List<GameID> getGameIDs() {
return gameIDs; return gameIDs;
} }
public void setGameIDs(List<GameID> gameIDs) { public void setGameIDs(List<GameID> gameIDs) {
this.gameIDs = gameIDs; this.gameIDs = gameIDs;
} }
public EventUser getCreator() { public EventUser getCreator() {
return creator; return creator;
} }
public void setCreator(EventUser creator) { public void setCreator(EventUser creator) {
this.creator = creator; this.creator = creator;
} }
public Date getEventuserCreated() { public Date getEventuserCreated() {
return eventuserCreated; return eventuserCreated;
} }
public void setEventuserCreated(Date eventuserCreated) { public void setEventuserCreated(Date eventuserCreated) {
this.eventuserCreated = eventuserCreated; this.eventuserCreated = eventuserCreated;
} }
public EventUser() public EventUser()
{ {
super(); super();
} }
public EventUser(User usr, LanEvent evnt, EventUser usercreator) { public EventUser(User usr, LanEvent evnt, EventUser usercreator) {
super(); super();
this.eventuserCreated = new Date(); this.eventuserCreated = new Date();
this.creator = usercreator; this.creator = usercreator;
this.user = usr; this.user = usr;
this.event = evnt; this.event = evnt;
} }
public User getUser() { public User getUser() {
return user; return user;
} }
public void setUser(User user) { public void setUser(User user) {
this.user = user; this.user = user;
} }
public LanEvent getEvent() { public LanEvent getEvent() {
return event; return event;
} }
public void setEvent(LanEvent event) { public void setEvent(LanEvent event) {
this.event = event; this.event = event;
} }
public List<Vote> getVotes() { public List<Vote> getVotes() {
return votes; return votes;
} }
public void setVotes(List<Vote> votes) { public void setVotes(List<Vote> votes) {
this.votes = votes; this.votes = votes;
} }
public List<UserNote> getNotes() { public List<UserNote> getNotes() {
return notes; return notes;
} }
public void setNotes(List<UserNote> notes) { public void setNotes(List<UserNote> notes) {
this.notes = notes; this.notes = notes;
} }
/** /**
* NOTICE: This returns only manually added roles. If you want to get all * NOTICE: This returns only manually added roles. If you want to get all
* roles from products, places, etc, use * roles from products, places, etc, use
* {@link fi.codecrew.moya.beans.UserBeanLocal#findUsersRoles(EventUser) * {@link fi.codecrew.moya.beans.UserBeanLocal#findUsersRoles(EventUser)
* UserBeanLocal#findUsersRoles(EventUser) } * UserBeanLocal#findUsersRoles(EventUser) }
* *
* @return * @return
*/ */
public List<Role> getRoles() { public List<Role> getRoles() {
return roles; return roles;
} }
public void setRoles(List<Role> roles) { public void setRoles(List<Role> roles) {
this.roles = roles; this.roles = roles;
} }
public List<CompoEntryParticipant> getCompoEntryParticipants() { public List<CompoEntryParticipant> getCompoEntryParticipants() {
return compoEntryParticipants; return compoEntryParticipants;
} }
public void setCompoEntryParticipants(List<CompoEntryParticipant> compoEntryParticipants) { public void setCompoEntryParticipants(List<CompoEntryParticipant> compoEntryParticipants) {
this.compoEntryParticipants = compoEntryParticipants; this.compoEntryParticipants = compoEntryParticipants;
} }
public List<CompoEntry> getCompoEntries() { public List<CompoEntry> getCompoEntries() {
return compoEntries; return compoEntries;
} }
public void setCompoEntries(List<CompoEntry> compoEntries) { public void setCompoEntries(List<CompoEntry> compoEntries) {
this.compoEntries = compoEntries; this.compoEntries = compoEntries;
} }
public List<PlaceGroup> getPlaceGroups() { public List<PlaceGroup> getPlaceGroups() {
return placeGroups; return placeGroups;
} }
public void setPlaceGroups(List<PlaceGroup> placeGroups) { public void setPlaceGroups(List<PlaceGroup> placeGroups) {
this.placeGroups = placeGroups; this.placeGroups = placeGroups;
} }
public List<GroupMembership> getGroupMemberships() { public List<GroupMembership> getGroupMemberships() {
return groupMemberships; return groupMemberships;
} }
public void setGroupMemberships(List<GroupMembership> groupMemberships) { public void setGroupMemberships(List<GroupMembership> groupMemberships) {
this.groupMemberships = groupMemberships; this.groupMemberships = groupMemberships;
} }
public List<Place> getCurrentPlaces() { public List<Place> getCurrentPlaces() {
return currentPlaces; return currentPlaces;
} }
public void setCurrentPlaces(List<Place> currentPlaces) { public void setCurrentPlaces(List<Place> currentPlaces) {
this.currentPlaces = currentPlaces; this.currentPlaces = currentPlaces;
} }
public List<PrintedCard> getPrintedCards() { public List<PrintedCard> getPrintedCards() {
return printedCards; return printedCards;
} }
public void setPrintedCards(List<PrintedCard> printedCards) { public void setPrintedCards(List<PrintedCard> printedCards) {
this.printedCards = printedCards; this.printedCards = printedCards;
} }
public List<AccountEvent> getAccountEvents() { public List<AccountEvent> getAccountEvents() {
return accountEvents; return accountEvents;
} }
public void setAccountEvents(List<AccountEvent> accountEvents) { public void setAccountEvents(List<AccountEvent> accountEvents) {
this.accountEvents = accountEvents; this.accountEvents = accountEvents;
} }
public List<Bill> getBills() { public List<Bill> getBills() {
return bills; return bills;
} }
public void setBills(List<Bill> bills) { public void setBills(List<Bill> bills) {
this.bills = bills; this.bills = bills;
} }
public List<AccountEvent> getSoldItems() { public List<AccountEvent> getSoldItems() {
return soldItems; return soldItems;
} }
public void setSoldItems(List<AccountEvent> soldItems) { public void setSoldItems(List<AccountEvent> soldItems) {
this.soldItems = soldItems; this.soldItems = soldItems;
} }
public List<PollAnswer> getPollAnswers() { public List<PollAnswer> getPollAnswers() {
return pollAnswers; return pollAnswers;
} }
public void setPollAnswers(List<PollAnswer> pollAnswers) { public void setPollAnswers(List<PollAnswer> pollAnswers) {
this.pollAnswers = pollAnswers; this.pollAnswers = pollAnswers;
} }
public void setCreated(Calendar created) { public void setCreated(Calendar created) {
user.setCreated(created); user.setCreated(created);
} }
public boolean getActive() { public boolean getActive() {
return user.getActive(); return user.getActive();
} }
public void setActive(boolean active) { public void setActive(boolean active) {
user.setActive(active); user.setActive(active);
} }
public String getPassword() { public String getPassword() {
return user.getPassword(); return user.getPassword();
} }
public void setPassword(String password) { public void setPassword(String password) {
user.setPassword(password); user.setPassword(password);
} }
public String getWholeName() { public String getWholeName() {
return user.getWholeName(); return user.getWholeName();
} }
public String getLastname() { public String getLastname() {
return user.getLastname(); return user.getLastname();
} }
public void setLastname(String lastname) { public void setLastname(String lastname) {
user.setLastname(lastname); user.setLastname(lastname);
} }
public String getFirstnames() { public String getFirstnames() {
return user.getFirstnames(); return user.getFirstnames();
} }
public void setFirstnames(String firstnames) { public void setFirstnames(String firstnames) {
user.setFirstnames(firstnames); user.setFirstnames(firstnames);
} }
public Date getBirthday() { public Date getBirthday() {
return user.getBirthday(); return user.getBirthday();
} }
public void setBirthday(Date birthday) { public void setBirthday(Date birthday) {
user.setBirthday(birthday); user.setBirthday(birthday);
} }
public String getNick() { public String getNick() {
return user.getNick(); return user.getNick();
} }
public void setNick(String nick) { public void setNick(String nick) {
user.setNick(nick); user.setNick(nick);
} }
public String getEmail() { public String getEmail() {
return user.getEmail(); return user.getEmail();
} }
public void setEmail(String email) { public void setEmail(String email) {
user.setEmail(email); user.setEmail(email);
} }
public String getAddress() { public String getAddress() {
return user.getAddress(); return user.getAddress();
} }
public void setAddress(String address) { public void setAddress(String address) {
user.setAddress(address); user.setAddress(address);
} }
public String getZip() { public String getZip() {
return user.getZip(); return user.getZip();
} }
public void setZip(String zip) { public void setZip(String zip) {
user.setZip(zip); user.setZip(zip);
} }
public String getTown() { public String getTown() {
return user.getTown(); return user.getTown();
} }
public void setTown(String town) { public void setTown(String town) {
user.setTown(town); user.setTown(town);
} }
public String getPhone() { public String getPhone() {
return user.getPhone(); return user.getPhone();
} }
public void setPhone(String phone) {
user.setPhone(phone);
}
public String getLogin() {
return user.getLogin();
}
public void setLogin(String login) {
user.setLogin(login);
}
public List<UserImage> getUserImageList() {
return user.getUserImageList();
}
public void setUserImageList(List<UserImage> userImageList) {
user.setUserImageList(userImageList);
}
public String getConfirmHash() {
return user.getConfirmHash();
}
public void setConfirmHash(String confirmHash) {
user.setConfirmHash(confirmHash);
}
public Calendar getConfirmTime() {
return user.getConfirmTime();
}
public void setConfirmTime(Calendar confirmTime) {
user.setConfirmTime(confirmTime);
}
public void resetPassword(String password) {
user.resetPassword(password);
}
public boolean checkPassword(String plainPassword) {
return user.checkPassword(plainPassword);
}
public boolean isSuperadmin() {
return user.isSuperadmin();
}
public void setPostalTown(String postalTown) {
user.setPostalTown(postalTown);
}
public String getPostalTown() {
return user.getPostalTown();
}
public void setGender(Gender gender) {
user.setGender(gender);
}
public Gender getGender() {
return user.getGender();
}
public void setCurrentImage(UserImage currentImage) {
user.setCurrentImage(currentImage);
}
public UserImage getCurrentImage() {
return user.getCurrentImage();
}
public boolean isAnonymous() {
return user.isAnonymous();
}
public Calendar getCreated() {
return user.getCreated();
}
public BigDecimal getAccountBalance() {
BigDecimal ret = BigDecimal.ZERO;
if (accountEvents != null)
{
for (AccountEvent ac : accountEvents) {
ret = ret.add(ac.getTotal()).setScale(2, RoundingMode.HALF_UP);
}
}
return ret;
}
public String getShortUserDescriptor() {
return user.getShortUserDescriptor();
}
public void setPhone(String phone) {
user.setPhone(phone);
}
public String getLogin() {
return user.getLogin();
}
public void setLogin(String login) {
user.setLogin(login);
}
public List<UserImage> getUserImageList() {
return user.getUserImageList();
}
public void setUserImageList(List<UserImage> userImageList) {
user.setUserImageList(userImageList);
}
public String getConfirmHash() {
return user.getConfirmHash();
}
public void setConfirmHash(String confirmHash) {
user.setConfirmHash(confirmHash);
}
public Calendar getConfirmTime() {
return user.getConfirmTime();
}
public void setConfirmTime(Calendar confirmTime) {
user.setConfirmTime(confirmTime);
}
public void resetPassword(String password) {
user.resetPassword(password);
}
public boolean checkPassword(String plainPassword) {
return user.checkPassword(plainPassword);
}
public boolean isSuperadmin() {
return user.isSuperadmin();
}
public void setPostalTown(String postalTown) {
user.setPostalTown(postalTown);
}
public String getPostalTown() {
return user.getPostalTown();
}
public void setGender(Gender gender) {
user.setGender(gender);
}
public Gender getGender() {
return user.getGender();
}
public void setCurrentImage(UserImage currentImage) {
user.setCurrentImage(currentImage);
}
public UserImage getCurrentImage() {
return user.getCurrentImage();
}
public boolean isAnonymous() {
return user.isAnonymous();
}
public Calendar getCreated() {
return user.getCreated();
}
public BigDecimal getAccountBalance() {
BigDecimal ret = BigDecimal.ZERO;
if (accountEvents != null)
{
for (AccountEvent ac : accountEvents) {
ret = ret.add(ac.getTotal()).setScale(2, RoundingMode.HALF_UP);
}
}
return ret;
}
public String getShortUserDescriptor() {
return user.getShortUserDescriptor();
}
public void addAccountevent(AccountEvent accountevent) {
if (accountEvents == null) {
accountEvents = new ArrayList<AccountEvent>();
}
accountEvents.add(accountevent);
}
} }
...@@ -62,6 +62,9 @@ ...@@ -62,6 +62,9 @@
<h:commandButton value="#{i18n['usercart.downloadCsv']}"> <h:commandButton value="#{i18n['usercart.downloadCsv']}">
<p:fileDownload value="#{userCartView.downloadCsv}" /> <p:fileDownload value="#{userCartView.downloadCsv}" />
</h:commandButton> </h:commandButton>
<h:commandButton value="#{i18n['usercart.downloadExport']}">
<p:fileDownload value="#{userCartView.userExport}" />
</h:commandButton>
<h:commandButton action="#{userCartView.showOverview}" value="#{i18n['usercart.showoverview']}" /> <h:commandButton action="#{userCartView.showOverview}" value="#{i18n['usercart.showoverview']}" />
</div> </div>
</h:panelGroup> </h:panelGroup>
......
...@@ -54,8 +54,6 @@ public class ProductShopView extends GenericCDIView { ...@@ -54,8 +54,6 @@ public class ProductShopView extends GenericCDIView {
@EJB @EJB
private transient EventBeanLocal eventbean; private transient EventBeanLocal eventbean;
public void cashChanged() public void cashChanged()
{ {
payInstant = false; payInstant = false;
...@@ -81,10 +79,10 @@ public class ProductShopView extends GenericCDIView { ...@@ -81,10 +79,10 @@ public class ProductShopView extends GenericCDIView {
@Inject @Inject
private BillEditView billEditView; private BillEditView billEditView;
@Inject @Inject
private ProductShopItemHelper psiHelper; private ProductShopItemHelper psiHelper;
public ProductShopItemHelper getPsiHelper() { public ProductShopItemHelper getPsiHelper() {
return psiHelper; return psiHelper;
} }
...@@ -166,7 +164,7 @@ public class ProductShopView extends GenericCDIView { ...@@ -166,7 +164,7 @@ public class ProductShopView extends GenericCDIView {
public String add(Integer count) { public String add(Integer count) {
ProductShopItem item = shoppingcart.getRowData(); ProductShopItem item = shoppingcart.getRowData();
psiHelper.setProductShopItemCount(item, item.getCount().add(BigDecimal.valueOf(count))); psiHelper.setProductShopItemCount(item, item.getCount().add(BigDecimal.valueOf(count)));
updateCartLimits(item); updateCartLimits(item);
...@@ -223,15 +221,15 @@ public class ProductShopView extends GenericCDIView { ...@@ -223,15 +221,15 @@ public class ProductShopView extends GenericCDIView {
if (l != null) { if (l != null) {
hasLimits = true; hasLimits = true;
} }
psiHelper.updateProductShopItemLimit(n,l); psiHelper.updateProductShopItemLimit(n, l);
} }
} }
public String removeBought() { public String removeBought() {
ProductShopItem row = boughtItems.getRowData(); ProductShopItem row = boughtItems.getRowData();
psiHelper.setProductShopItemCount(row, row.getCount().subtract(BigDecimal.ONE)); psiHelper.setProductShopItemCount(row, row.getCount().subtract(BigDecimal.ONE));
updateCartLimits(row); updateCartLimits(row);
return null; return null;
...@@ -428,8 +426,8 @@ public class ProductShopView extends GenericCDIView { ...@@ -428,8 +426,8 @@ public class ProductShopView extends GenericCDIView {
public String readCode() { public String readCode() {
ReaderEvent event = readerView.getReaderEvent(); ReaderEvent event = readerView.getReaderEvent();
if(event == null) { if (event == null) {
return null; return null;
} }
......
...@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory; ...@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership; import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named @Named
...@@ -41,6 +42,23 @@ public class UserCartView extends GenericCDIView { ...@@ -41,6 +42,23 @@ public class UserCartView extends GenericCDIView {
private SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd"); private SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
public StreamedContent getUserExport()
{
StringBuilder sb = new StringBuilder();
DefaultStreamedContent ret = null;
if (usercart.size() > 0) {
LanEvent event = usercart.get(0).getEvent();
for (EventUser uc : usercart) {
sb.append(uc.getUser().getId()).append(";");
}
ret = new DefaultStreamedContent(new ByteArrayInputStream(sb.toString().getBytes(UTF8)));
ret.setContentType("text/csv");
ret.setName(event.getName() + "userexport.dat");
}
return ret;
}
public StreamedContent getDownloadCsv() { public StreamedContent getDownloadCsv() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
...@@ -56,7 +74,7 @@ public class UserCartView extends GenericCDIView { ...@@ -56,7 +74,7 @@ public class UserCartView extends GenericCDIView {
sb.append("Zip").append(CSV_SEPARATOR); sb.append("Zip").append(CSV_SEPARATOR);
sb.append("City").append(CSV_SEPARATOR); sb.append("City").append(CSV_SEPARATOR);
sb.append("Places").append(CSV_SEPARATOR); sb.append("Places").append(CSV_SEPARATOR);
sb.append("\n"); sb.append("\n");
for (EventUser uc : usercart) for (EventUser uc : usercart)
{ {
......
...@@ -39,7 +39,6 @@ import fi.codecrew.moya.model.Role; ...@@ -39,7 +39,6 @@ import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.model.UserImage; import fi.codecrew.moya.model.UserImage;
import fi.codecrew.moya.util.MassPrintResult; import fi.codecrew.moya.util.MassPrintResult;
import fi.codecrew.moya.utilities.jsf.MessageHelper;
import fi.codecrew.moya.web.annotations.LoggedIn; import fi.codecrew.moya.web.annotations.LoggedIn;
import fi.codecrew.moya.web.annotations.SelectedUser; import fi.codecrew.moya.web.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
...@@ -277,7 +276,8 @@ public class UserView extends GenericCDIView { ...@@ -277,7 +276,8 @@ public class UserView extends GenericCDIView {
canSave = getCurrentUser().equals(user) || permbean.hasPermission(UserPermission.MODIFY); canSave = getCurrentUser().equals(user) || permbean.hasPermission(UserPermission.MODIFY);
this.beginConversation(); this.beginConversation();
logger.debug("Accountevents for user {}", user.getAccountEvents().size()); if (user.getAccountEvents() != null)
logger.debug("Accountevents for user {}", user.getAccountEvents().size());
} }
...@@ -351,23 +351,22 @@ public class UserView extends GenericCDIView { ...@@ -351,23 +351,22 @@ public class UserView extends GenericCDIView {
public String attachCodeToCard() { public String attachCodeToCard() {
return attachCodeToCard(readerView.getReaderEvent()); return attachCodeToCard(readerView.getReaderEvent());
} }
public String attachCodeToCard(ReaderEvent event ) {
public String attachCodeToCard(ReaderEvent event) {
if(event == null)
if (event == null)
return null; return null;
// already attached // already attached
if (event.getPrintedCard() != null) { if (event.getPrintedCard() != null) {
super.addFaceMessage("usercard.alreadyassociated"); super.addFaceMessage("usercard.alreadyassociated");
return null; return null;
} }
// still there, we can get real card and update it's barcodes // still there, we can get real card and update it's barcodes
PrintedCard card = cardBean.checkPrintedCard(user); PrintedCard card = cardBean.checkPrintedCard(user);
readerbean.assocCodeToCard(event , card); readerbean.assocCodeToCard(event, card);
return null; return null;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!