Add current expenses to the overview
The period start is configurable.
This commit is contained in:
@@ -13,6 +13,7 @@ public class FinancerConfig {
|
||||
private String serverUrl;
|
||||
private String dateFormat;
|
||||
private String version;
|
||||
private Integer monthPeriodStartDay;
|
||||
|
||||
public String getServerUrl() {
|
||||
return serverUrl;
|
||||
@@ -37,4 +38,20 @@ public class FinancerConfig {
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
// The same property exists on the server, look there for documentation
|
||||
public Integer getMonthPeriodStartDay() {
|
||||
return monthPeriodStartDay;
|
||||
}
|
||||
|
||||
public void setMonthPeriodStartDay(Integer monthPeriodStartDay) {
|
||||
if (monthPeriodStartDay == null) {
|
||||
throw new IllegalArgumentException("Parameter 'financer.monthPeriodStartDay' is not set!");
|
||||
}
|
||||
else if (monthPeriodStartDay < 1 || monthPeriodStartDay > 28) {
|
||||
throw new IllegalArgumentException("Parameter 'financer.monthPeriodStartDay' is out of range! Valid range from 1-28");
|
||||
}
|
||||
|
||||
this.monthPeriodStartDay = monthPeriodStartDay;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@@ -33,12 +34,18 @@ public class AccountController {
|
||||
final ResponseEntity<Iterable<RecurringTransaction>> rtAllActRes = new GetAllActiveRecurringTransactionsTemplate()
|
||||
.exchange(this.financerConfig);
|
||||
final ResponseEntity<Long> currentAssets = new GetCurrentAssetsTemplate().exchange(this.financerConfig);
|
||||
final ResponseEntity<Long> currentExpenses = new GetExpensesCurrentPeriodTemplate().exchange(this.financerConfig);
|
||||
final boolean showClosedBoolean = BooleanUtils.toBoolean(showClosed);
|
||||
final LocalDate periodStart = LocalDate.now().withDayOfMonth(this.financerConfig.getMonthPeriodStartDay());
|
||||
final LocalDate periodEnd = periodStart.plusMonths(1);
|
||||
|
||||
model.addAttribute("accounts", ControllerUtils.filterAndSortAccounts(response.getBody(), showClosedBoolean));
|
||||
model.addAttribute("rtDueTodayCount", IterableUtils.size(rtDtRes.getBody()));
|
||||
model.addAttribute("rtAllActiveCount", IterableUtils.size(rtAllActRes.getBody()));
|
||||
model.addAttribute("currentAssets", currentAssets.getBody());
|
||||
model.addAttribute("currentExpenses", currentExpenses.getBody());
|
||||
model.addAttribute("periodStart", ControllerUtils.formatDate(this.financerConfig, periodStart));
|
||||
model.addAttribute("periodEnd", ControllerUtils.formatDate(this.financerConfig, periodEnd));
|
||||
model.addAttribute("showClosed", showClosedBoolean);
|
||||
ControllerUtils.addVersionAttribute(model, this.financerConfig);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ public enum Function {
|
||||
TR_GET_ALL_FOR_ACCOUNT("transactions/getAllForAccount"),
|
||||
TR_CREATE_TRANSACTION("transactions/createTransaction"),
|
||||
TR_DELETE_TRANSACTION("transactions/deleteTransaction"),
|
||||
TR_EXPENSES_CURRENT_PERIOD("transactions/getExpensesCurrentPeriod"),
|
||||
|
||||
RT_GET_ALL("recurringTransactions/getAll"),
|
||||
RT_GET_ALL_ACTIVE("recurringTransactions/getAllActive"),
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package de.financer.controller.template;
|
||||
|
||||
import de.financer.config.FinancerConfig;
|
||||
import de.financer.controller.Function;
|
||||
import de.financer.util.ControllerUtils;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
public class GetExpensesCurrentPeriodTemplate {
|
||||
public ResponseEntity<Long> exchange(FinancerConfig financerConfig) {
|
||||
return new FinancerRestTemplate<Long>().exchange(ControllerUtils
|
||||
.buildUrl(financerConfig, Function.TR_EXPENSES_CURRENT_PERIOD), new ParameterizedTypeReference<Long>() {
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,10 @@ public class ControllerUtils {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static String formatDate(FinancerConfig financerConfig, LocalDate date) {
|
||||
return date.format(DateTimeFormatter.ofPattern(financerConfig.getDateFormat()));
|
||||
}
|
||||
|
||||
public static String formatDate(FinancerConfig financerConfig, String dateFromForm) {
|
||||
if (StringUtils.isEmpty(dateFromForm)) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user