diff --git a/src/main/java/com/application/munera/services/PersonService.java b/src/main/java/com/application/munera/services/PersonService.java index 097840a..be2685e 100644 --- a/src/main/java/com/application/munera/services/PersonService.java +++ b/src/main/java/com/application/munera/services/PersonService.java @@ -58,4 +58,10 @@ public class PersonService { public BigDecimal calculateCredit(final Person person) { return this.expenseService.findCreditByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add); } + + public BigDecimal calculateTotalExpenses(final Person person) { + final var credit = this.expenseService.findCreditByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add); + final var debit = this.expenseService.findDebtByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add); + return credit.add(debit); + } } diff --git a/src/main/java/com/application/munera/views/expenses/CategoriesView.java b/src/main/java/com/application/munera/views/expenses/CategoriesView.java index 7b82b3c..f7ba8e3 100644 --- a/src/main/java/com/application/munera/views/expenses/CategoriesView.java +++ b/src/main/java/com/application/munera/views/expenses/CategoriesView.java @@ -196,6 +196,5 @@ public class CategoriesView extends Div implements BeforeEnterObserver { private void populateForm(Category value) { this.category = value; binder.readBean(this.category); - } } diff --git a/src/main/java/com/application/munera/views/expenses/ExpensesView.java b/src/main/java/com/application/munera/views/expenses/ExpensesView.java index 251acb9..8f6c1ee 100644 --- a/src/main/java/com/application/munera/views/expenses/ExpensesView.java +++ b/src/main/java/com/application/munera/views/expenses/ExpensesView.java @@ -87,9 +87,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver { // Configure Grid grid.addColumn(Expense::getName).setHeader("Name").setSortable(true); grid.addColumn(Expense::getCost).setHeader("Amount").setSortable(true); - grid.addColumn(expenseCategory -> expenseCategory.getCategory().getName()) - .setHeader("Category") - .setSortable(true); + grid.addColumn(expenseCategory -> expenseCategory.getCategory().getName()).setHeader("Category").setSortable(true); grid.addColumn(Expense::getPeriodInterval).setHeader("Period Interval").setSortable(true); grid.addColumn(Expense::getPeriodUnit).setHeader("Period Unit").setSortable(true); grid.addColumn(Expense::getDate).setHeader("Date").setSortable(true); diff --git a/src/main/java/com/application/munera/views/expenses/PeopleView.java b/src/main/java/com/application/munera/views/expenses/PeopleView.java index 9ca9255..8ceb100 100644 --- a/src/main/java/com/application/munera/views/expenses/PeopleView.java +++ b/src/main/java/com/application/munera/views/expenses/PeopleView.java @@ -71,6 +71,7 @@ public class PeopleView extends Div implements BeforeEnterObserver { grid.addColumn(Person::getEmail).setHeader("Email").setSortable(true); grid.addColumn(personService::calculateDebt).setHeader("Debt").setSortable(true); grid.addColumn(personService::calculateCredit).setHeader("Credit").setSortable(true); + grid.addColumn(personService::calculateTotalExpenses).setHeader("Total Expenses value").setSortable(true); grid.getColumns().forEach(col -> col.setAutoWidth(true)); grid.setItems(query -> personService.list( PageRequest.of(query.getPage(), query.getPageSize(), VaadinSpringDataHelpers.toSpringDataSort(query)))