feat: credit by user calculations
This commit is contained in:
parent
ba686ccdd0
commit
97439065bc
3 changed files with 8 additions and 0 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)))
|
||||
|
|
Loading…
Reference in a new issue