Skip to content

Commit

Permalink
Merge pull request #138 from eurofurence/issue-137-accounting-page
Browse files Browse the repository at this point in the history
nick and ev flag in accounting page
  • Loading branch information
Jumpy-Squirrel authored Mar 10, 2024
2 parents b4fe186 + f009107 commit a6f3190
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 17 deletions.
109 changes: 94 additions & 15 deletions src/java/org/eurofurence/regsys/web/forms/AccountingSearchForm.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.eurofurence.regsys.web.forms;

import org.eurofurence.regsys.repositories.attendees.AttendeeSearchCriteria;
import org.eurofurence.regsys.repositories.attendees.AttendeeSearchResultList;
import org.eurofurence.regsys.repositories.attendees.AttendeeService;
import org.eurofurence.regsys.repositories.errors.DownstreamException;
import org.eurofurence.regsys.repositories.errors.DownstreamWebErrorException;
import org.eurofurence.regsys.repositories.payments.PaymentService;
Expand All @@ -17,7 +20,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -33,8 +35,6 @@ public class AccountingSearchForm extends Form {
public static final String PARAM_SEARCH_TYPE = "searchPaymentType";
public static final String PARAM_SEARCH_METHOD = "searchPaymentMethod";

public static final String PARAM_LONG_VERSION = "long";

// ------------ attributes -----------------------

private String searchFrom; // kept as iso - from
Expand All @@ -49,11 +49,26 @@ public class AccountingSearchForm extends Form {
private Map<String,Map<Long,Long>> breakdownCountByAmount;
private Map<String,Long> totalAmounts;

public static class AttendeeInfos {
public String nickname;
public String flags;
public String options;
public String packages;
public String status;
public long totalDues;
public long paymentBalance;
public long currentDues;
public String dueDate;
}

private Map<Long, AttendeeInfos> attendeeInfos = new HashMap<>();

private List<Transaction> found = new ArrayList<>();

// ------------ constructors and initialization -----------------------

private final PaymentService paymentService = new PaymentService();
private final AttendeeService attendeeService = new AttendeeService();

public AccountingSearchForm() {
breakdownCountByAmount = new TreeMap<>();
Expand Down Expand Up @@ -130,18 +145,8 @@ public boolean find() {
boolean result = false;
found = new ArrayList<>();
try {
TransactionResponse response = paymentService.performFindTransactions(null, null, searchFrom, searchTo, getPage().getTokenFromRequest(), getPage().getRequestId());
if (response.payload != null) {
for (Transaction t : response.payload) {
if (searchStatus.contains(t.status) &&
searchTypes.contains(t.transactionType) &&
searchMethods.contains(t.method)) {
if (searchComments.equals("") || t.comment != null && t.comment.contains(searchComments)) {
found.add(t);
}
}
}
}
populateAttendeeInfos();
loadTransactions();
result = true;
count = -1; // first loadNextTransaction() advances to first
} catch (DownstreamWebErrorException e) {
Expand All @@ -153,6 +158,52 @@ public boolean find() {
return result;
}

private void populateAttendeeInfos() {
AttendeeSearchCriteria.AttendeeSearchSingleCriterion criterion = new AttendeeSearchCriteria.AttendeeSearchSingleCriterion();
AttendeeSearchCriteria criteria = new AttendeeSearchCriteria();
criteria.fillFields = Arrays.asList("nickname", "configuration", "balances", "status");
criteria.matchAny.add(criterion); // note: will filter deleted attendees

AttendeeSearchResultList resultList = attendeeService.performFindAttendees(criteria, getPage().getTokenFromRequest(), getPage().getRequestId());
if (resultList != null && resultList.attendees != null) {
resultList.attendees.forEach(sr -> {
AttendeeInfos inf = new AttendeeInfos();
inf.nickname = sr.nickname;
inf.flags = sr.flags;
inf.options = sr.options;
inf.packages = sr.packages;
inf.status = sr.status;
inf.totalDues = valueOrZero(sr.totalDues);
inf.paymentBalance = valueOrZero(sr.paymentBalance);
inf.currentDues = valueOrZero(sr.currentDues);
inf.dueDate = sr.dueDate;
attendeeInfos.put(sr.id, inf);
});
}
}

private void loadTransactions() {
TransactionResponse response = paymentService.performFindTransactions(null, null, searchFrom, searchTo, getPage().getTokenFromRequest(), getPage().getRequestId());
if (response.payload != null) {
for (Transaction t : response.payload) {
if (searchStatus.contains(t.status) &&
searchTypes.contains(t.transactionType) &&
searchMethods.contains(t.method)) {
if (searchComments.equals("") || t.comment != null && t.comment.contains(searchComments)) {
found.add(t);
}
}
}
}
}

private long valueOrZero(Long value) {
if (value == null) {
return 0L;
}
return value.longValue();
}

public boolean loadNextTransaction() {
count++;
if (count < found.size()) {
Expand Down Expand Up @@ -339,6 +390,34 @@ public String getComment() {
return escape(found.get(count).comment);
}

// lookups from attendeeInfos

private AttendeeInfos attInf() {
Long debitorId = found.get(count).debitorId;
if (debitorId != null) {
AttendeeInfos inf = attendeeInfos.get(debitorId);
if (inf == null) {
inf = new AttendeeInfos();
inf.nickname = "(unknown)";
}
return inf;
} else {
AttendeeInfos inf = new AttendeeInfos();
inf.nickname = "(no id)";
return inf;
}
}

public String getAttendeeNickname() {
return escape(attInf().nickname);
}

public boolean attendeeHasFlag(String flag) {
AttendeeInfos inf = attInf();
String flags = "," + inf.flags + ","; // may result in ,null,
return flags.contains("," + flag + ",");
}

// attributes for the amount breakdown (available after all loadNexts only)

public List<Map<String,String>> getDueAmountsBreakdown() {
Expand Down
6 changes: 6 additions & 0 deletions src/tpl/common/pages/accountingList.vm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<TH class="searchlist" ALIGN="left" >$strcolType</TH>
<TH class="searchlist" ALIGN="left" >$strcolMethod</TH>
<TH class="searchlist" ALIGN="left" >$strcolComment</TH>
<TH class="searchlist" ALIGN="left" >$strcolNick</TH>
<TH class="searchlist" ALIGN="left" >$strcolMembership</TH>
</TR>

#foreach($i in [0..10000])## if there are more than this many results, the page will load forever anyway
Expand All @@ -24,6 +26,8 @@
<TD class="searchlist" ALIGN="left">$form.type</TD>
<TD class="searchlist" ALIGN="left">$form.method</TD>
<TD class="searchlist" ALIGN="left">$form.comment</TD>
<TD class="searchlist" ALIGN="left">$form.attendeeNickname</TD>
<TD class="searchlist" ALIGN="left">#if($form.attendeeHasFlag("ev"))X#{end}</TD>
</TR>

#end##
Expand All @@ -39,6 +43,8 @@
<TH class="searchlist" ALIGN="left" ></TH>
<TH class="searchlist" ALIGN="left" ></TH>
<TH class="searchlist" ALIGN="left" ></TH>
<TH class="searchlist" ALIGN="left" ></TH>
<TH class="searchlist" ALIGN="left" ></TH>
</TR>

</TABLE>
Expand Down
2 changes: 1 addition & 1 deletion src/tpl/common/pages/strings/accounting.strings.vm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#set($strcolRealname = "Realname")##
#set($strcolTotal = "Total")##
#set($strcolAttendance = "Attendance")##
#set($strcolMembership = "Membership")##
#set($strcolMembership = "e.V.")##
#set($strcolAmount = "Paid&nbsp;&euro;")##
#set($strcolAmountDue = "Due&nbsp;&euro;")##
#set($strcolDate = "Date")##
Expand Down
2 changes: 1 addition & 1 deletion src/tpl/mmc/pages/strings/accounting.strings.vm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#set($strcolRealname = "Realer&nbsp;Name")##
#set($strcolTotal = "Total")##
#set($strcolAttendance = "Teilnahme")##
#set($strcolMembership = "Vereinsbeitrag")##
#set($strcolMembership = "e.V.")##
#set($strcolAmount = "Betrag")##
#set($strcolAmountDue = "Ford.")##
#set($strcolDate = "Datum")##
Expand Down

0 comments on commit a6f3190

Please sign in to comment.