feat: credit by user calculations

This commit is contained in:
Filippo Ferrari 2024-06-04 13:35:16 +01:00
parent ba686ccdd0
commit 97439065bc
3 changed files with 8 additions and 0 deletions

View file

@ -29,6 +29,9 @@ public class ExpenseService {
return repository.findDebtorsExpensesByPersonId(person.getId());
}
public Collection<Expense> findCreditByUser(final Person person) {
return repository.findCreditorsExpensesByPersonId(person.getId());
}
public List<Expense> findAll() {return repository.findAll();}
public Expense update(Expense entity) {

View file

@ -54,4 +54,8 @@ public class PersonService {
public BigDecimal calculateDebt(final Person person){
return this.expenseService.findDebtByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add);
}
public BigDecimal calculateCredit(final Person person) {
return this.expenseService.findCreditByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add);
}
}

View file

@ -70,6 +70,7 @@ public class PeopleView extends Div implements BeforeEnterObserver {
grid.addColumn(Person::getLastName).setHeader("Last Name").setSortable(true);
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.getColumns().forEach(col -> col.setAutoWidth(true));
grid.setItems(query -> personService.list(
PageRequest.of(query.getPage(), query.getPageSize(), VaadinSpringDataHelpers.toSpringDataSort(query)))