From b1f69a2aee8a080fbbc4397291e9c2eb25c62aee Mon Sep 17 00:00:00 2001 From: MK13 Date: Wed, 18 May 2022 20:50:15 +0200 Subject: [PATCH] #29 Projected cash flow --- .../financer/controller/ReportController.java | 15 ++-- .../ConfigProjectedCashFlowForPeriodForm.java | 9 -- ...ctedCashFlowForPeriodTransactionsForm.java | 83 ++++++++++++------- .../main/resources/i18n/message.properties | 3 - .../resources/i18n/message_de_DE.properties | 3 - .../src/main/resources/static/css/main.css | 4 + .../configureProjectedCashFlowForPeriod.html | 10 --- ...rojectedCashFlowForPeriodTransactions.html | 47 +++++++---- 8 files changed, 91 insertions(+), 83 deletions(-) diff --git a/financer-web-client/src/main/java/de/financer/controller/ReportController.java b/financer-web-client/src/main/java/de/financer/controller/ReportController.java index 2d68150..7cfb6cc 100644 --- a/financer-web-client/src/main/java/de/financer/controller/ReportController.java +++ b/financer-web-client/src/main/java/de/financer/controller/ReportController.java @@ -169,18 +169,15 @@ public class ReportController { ConfigProjectedCashFlowForPeriodTransactionsForm formTransactions = new ConfigProjectedCashFlowForPeriodTransactionsForm(incomeTransactions, expenseTransactions, - form.isByAccount(), ControllerUtils.parseDate(this.financerConfig, form.getFromDate()), + ControllerUtils.parseDate(this.financerConfig, form.getFromDate()), ControllerUtils.parseDate(this.financerConfig, form.getToDate())); - if(form.isByAccount()) { - final ResponseEntity> response = new GetAllAccountsTemplate().exchange(this.financerConfig); + final ResponseEntity> response = new GetAllAccountsTemplate().exchange(this.financerConfig); - decorateAccounts(ControllerUtils.filterAndSortAccounts(response.getBody(), false, LIABILITY, EXPENSE)) - .forEach(formTransactions::addAccountContainer); - } - else { - // TODO by account group - } + decorateAccounts(ControllerUtils.filterAndSortAccounts(response.getBody(), false, LIABILITY, EXPENSE)) + .stream().filter(ad -> ad.getAccountGroup() != null) + .collect(Collectors.groupingBy(ad -> ad.getAccountGroup().getName())) + .forEach(formTransactions::addAccountGroupAccountList); formTransactions.refresh(); diff --git a/financer-web-client/src/main/java/de/financer/form/ConfigProjectedCashFlowForPeriodForm.java b/financer-web-client/src/main/java/de/financer/form/ConfigProjectedCashFlowForPeriodForm.java index ddc9ebc..2487ce1 100644 --- a/financer-web-client/src/main/java/de/financer/form/ConfigProjectedCashFlowForPeriodForm.java +++ b/financer-web-client/src/main/java/de/financer/form/ConfigProjectedCashFlowForPeriodForm.java @@ -3,7 +3,6 @@ package de.financer.form; public class ConfigProjectedCashFlowForPeriodForm { private String fromDate; private String toDate; - private boolean byAccount; public String getFromDate() { return fromDate; @@ -20,12 +19,4 @@ public class ConfigProjectedCashFlowForPeriodForm { public void setToDate(String toDate) { this.toDate = toDate; } - - public boolean isByAccount() { - return byAccount; - } - - public void setByAccount(boolean byAccount) { - this.byAccount = byAccount; - } } diff --git a/financer-web-client/src/main/java/de/financer/form/ConfigProjectedCashFlowForPeriodTransactionsForm.java b/financer-web-client/src/main/java/de/financer/form/ConfigProjectedCashFlowForPeriodTransactionsForm.java index 6da0673..24ad0e5 100644 --- a/financer-web-client/src/main/java/de/financer/form/ConfigProjectedCashFlowForPeriodTransactionsForm.java +++ b/financer-web-client/src/main/java/de/financer/form/ConfigProjectedCashFlowForPeriodTransactionsForm.java @@ -5,12 +5,40 @@ import de.financer.model.Account; import de.financer.model.RecurringTransaction; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; public class ConfigProjectedCashFlowForPeriodTransactionsForm { + public static class AccountGroupAccountContainer { + private String accountGroup; + private List accounts; + + public AccountGroupAccountContainer() { + + } + + public AccountGroupAccountContainer(String accountGroup, List accounts) { + this.accountGroup = accountGroup; + this.accounts = accounts; + } + + public String getAccountGroup() { + return accountGroup; + } + + public void setAccountGroup(String accountGroup) { + this.accountGroup = accountGroup; + } + + public List getAccounts() { + return accounts; + } + + public void setAccounts(List accounts) { + this.accounts = accounts; + } + } + public static class AccountContainer { private Account account; private long spending; @@ -25,7 +53,7 @@ public class ConfigProjectedCashFlowForPeriodTransactionsForm { this.spending = spending; this.averageSpending = averageSpending; - if(this.spending == 0 && this.averageSpending != 0) { + if (this.spending == 0 && this.averageSpending != 0) { this.spending = this.averageSpending; } } @@ -57,11 +85,10 @@ public class ConfigProjectedCashFlowForPeriodTransactionsForm { private List incomeTransactions; private List expenseTransactions; - private List accountContainers; + private List accountGroupAccountContainers; private long incomeSum; private long expenseSum; private long cashFlow; - private boolean byAccount; private long accountSum; private LocalDate fromDate; private LocalDate toDate; @@ -69,17 +96,16 @@ public class ConfigProjectedCashFlowForPeriodTransactionsForm { public ConfigProjectedCashFlowForPeriodTransactionsForm() { this.incomeTransactions = new ArrayList<>(); this.expenseTransactions = new ArrayList<>(); - this.accountContainers = new ArrayList<>(); + this.accountGroupAccountContainers = new ArrayList<>(); } public ConfigProjectedCashFlowForPeriodTransactionsForm(List incomeTransactions, List expenseTransactions, - boolean byAccount, LocalDate fromDate, LocalDate toDate + LocalDate fromDate, LocalDate toDate ) { this.incomeTransactions = incomeTransactions; this.expenseTransactions = expenseTransactions; - this.accountContainers = new ArrayList<>(); - this.byAccount = byAccount; + this.accountGroupAccountContainers = new ArrayList<>(); this.fromDate = fromDate; this.toDate = toDate; @@ -92,14 +118,11 @@ public class ConfigProjectedCashFlowForPeriodTransactionsForm { this.expenseSum = expenseTransactions.stream().mapToLong(RecurringTransaction::getAmount).sum(); this.cashFlow = this.incomeSum - this.expenseSum; - if(this.byAccount) { - this.accountSum = this.accountContainers.stream().filter(ac -> ac.spending != 0).mapToLong(AccountContainer::getSpending).sum(); + this.accountSum = this.accountGroupAccountContainers.stream().map(AccountGroupAccountContainer::getAccounts) + .flatMap(List::stream).filter(ac -> ac.spending != 0) + .mapToLong(AccountContainer::getSpending).sum(); - this.cashFlow = this.cashFlow - this.accountSum; - } - else { - // TODO account group calc - } + this.cashFlow = this.cashFlow - this.accountSum; } public List getIncomeTransactions() { @@ -118,16 +141,20 @@ public class ConfigProjectedCashFlowForPeriodTransactionsForm { this.expenseTransactions = expenseTransactions; } - public List getAccountContainers() { - return accountContainers; + public List getAccountGroupAccountContainers() { + return accountGroupAccountContainers; } - public void setAccountContainers(List accountContainers) { - this.accountContainers = accountContainers; + public void setAccountGroupAccountContainers(List accountGroupAccountContainers) { + this.accountGroupAccountContainers = accountGroupAccountContainers; } - public void addAccountContainer(AccountDecorator account) { - this.accountContainers.add(new AccountContainer(account.getAccount(), account.getSpendingCurrentExpensePeriod(), account.getAverageSpendingExpensePeriod())); + public void addAccountGroupAccountList(String accountGroup, List accounts) { + this.accountGroupAccountContainers.add(new AccountGroupAccountContainer(accountGroup, accounts.stream() + .map(ad -> new AccountContainer(ad.getAccount(), + ad.getSpendingCurrentExpensePeriod(), + ad.getAverageSpendingExpensePeriod())) + .collect(Collectors.toList()))); } public long getIncomeSum() { @@ -150,14 +177,6 @@ public class ConfigProjectedCashFlowForPeriodTransactionsForm { return cashFlow; } - public boolean isByAccount() { - return byAccount; - } - - public void setByAccount(boolean byAccount) { - this.byAccount = byAccount; - } - public long getAccountSum() { return accountSum; } diff --git a/financer-web-client/src/main/resources/i18n/message.properties b/financer-web-client/src/main/resources/i18n/message.properties index 21a0f32..349957a 100644 --- a/financer-web-client/src/main/resources/i18n/message.properties +++ b/financer-web-client/src/main/resources/i18n/message.properties @@ -219,9 +219,6 @@ financer.chart-config-account-expenses-for-period.submit=Generate financer.report-config-projected-cashflow-for-period.title=Configure projected cash flow report financer.report-config-projected-cashflow-for-period.label.from-date=From date\: financer.report-config-projected-cashflow-for-period.label.to-date=To date\: -financer.report-config-projected-cashflow-for-period.label.account-or-account-group-summary=By account or account group -financer.report-config-projected-cashflow-for-period.label.by-account=Account -financer.report-config-projected-cashflow-for-period.label.by-account-group=Account group financer.report-config-projected-cashflow-for-period.submit=Next step financer.report-select.title=Select a report to generate diff --git a/financer-web-client/src/main/resources/i18n/message_de_DE.properties b/financer-web-client/src/main/resources/i18n/message_de_DE.properties index caa45be..e8b64e6 100644 --- a/financer-web-client/src/main/resources/i18n/message_de_DE.properties +++ b/financer-web-client/src/main/resources/i18n/message_de_DE.properties @@ -219,9 +219,6 @@ financer.chart-config-account-expenses-for-period.submit=Erzeugen financer.report-config-projected-cashflow-for-period.title=Konfigurieren von prognostizierter Cashflow Bericht financer.report-config-projected-cashflow-for-period.label.from-date=Von Datum\: financer.report-config-projected-cashflow-for-period.label.to-date=Bis Datum\: -financer.report-config-projected-cashflow-for-period.label.account-or-account-group-summary=Konto oder Kontogruppe -financer.report-config-projected-cashflow-for-period.label.by-account=Konto -financer.report-config-projected-cashflow-for-period.label.by-account-group=Kontogruppe financer.report-config-projected-cashflow-for-period.submit=N\u00E4chster Schritt financer.report-select.title=Einen Bericht zum Erzeugen ausw\u00E4hlen diff --git a/financer-web-client/src/main/resources/static/css/main.css b/financer-web-client/src/main/resources/static/css/main.css index 9933f1e..229b866 100644 --- a/financer-web-client/src/main/resources/static/css/main.css +++ b/financer-web-client/src/main/resources/static/css/main.css @@ -429,6 +429,10 @@ input[type=submit] { padding-left: 1em !important; } +.projected-cashflow-account { + padding-left: 2em !important; +} + .projected-cashflow-sum > * { font-weight: bolder; padding-top: 1em !important; diff --git a/financer-web-client/src/main/resources/templates/report/configureProjectedCashFlowForPeriod.html b/financer-web-client/src/main/resources/templates/report/configureProjectedCashFlowForPeriod.html index 90a2519..c12e644 100644 --- a/financer-web-client/src/main/resources/templates/report/configureProjectedCashFlowForPeriod.html +++ b/financer-web-client/src/main/resources/templates/report/configureProjectedCashFlowForPeriod.html @@ -19,16 +19,6 @@