CreditTransferView.java
3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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;
}
}
}