feat: buttons to set credit & debit as paid
This commit is contained in:
parent
f1974a18e7
commit
56138cd320
1 changed files with 30 additions and 8 deletions
|
@ -85,13 +85,19 @@ public class PeopleView extends Div implements BeforeEnterObserver {
|
||||||
|
|
||||||
grid.addColumn(new ComponentRenderer<>(persona -> {
|
grid.addColumn(new ComponentRenderer<>(persona -> {
|
||||||
if (persona instanceof Person) {
|
if (persona instanceof Person) {
|
||||||
Button markPaidButton = new Button("Mark All Expenses Paid", event -> markExpensesPaid((Person) persona));
|
Button setDebtPaidButton = new Button("Set all debt as paid", event -> setDebtPaid((Person) persona));
|
||||||
markPaidButton.addThemeVariants(ButtonVariant.LUMO_SMALL, ButtonVariant.LUMO_PRIMARY);
|
setDebtPaidButton.addThemeVariants(ButtonVariant.LUMO_SMALL, ButtonVariant.LUMO_PRIMARY);
|
||||||
return markPaidButton;
|
return setDebtPaidButton;
|
||||||
} else {
|
} else return new Span();
|
||||||
return new Span();
|
}));
|
||||||
}
|
|
||||||
})).setHeader("Actions");
|
grid.addColumn(new ComponentRenderer<>(persona -> {
|
||||||
|
if (persona instanceof Person) {
|
||||||
|
Button setCreditPaidButton = new Button("Set all credit as paid", event -> setCreditPaid((Person) persona));
|
||||||
|
setCreditPaidButton.addThemeVariants(ButtonVariant.LUMO_SMALL, ButtonVariant.LUMO_PRIMARY);
|
||||||
|
return setCreditPaidButton;
|
||||||
|
} else return new Span();
|
||||||
|
}));
|
||||||
|
|
||||||
List<Person> people = personService.findAllExcludeUsers();
|
List<Person> people = personService.findAllExcludeUsers();
|
||||||
|
|
||||||
|
@ -255,7 +261,7 @@ public class PeopleView extends Div implements BeforeEnterObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markExpensesPaid(Person person) {
|
private void setDebtPaid(Person person) {
|
||||||
try {
|
try {
|
||||||
List<Expense> expenses = expenseService.findExpensesWherePayer(person).stream().toList();
|
List<Expense> expenses = expenseService.findExpensesWherePayer(person).stream().toList();
|
||||||
for (Expense expense : expenses) {
|
for (Expense expense : expenses) {
|
||||||
|
@ -270,4 +276,20 @@ public class PeopleView extends Div implements BeforeEnterObserver {
|
||||||
n.addThemeVariants(NotificationVariant.LUMO_ERROR);
|
n.addThemeVariants(NotificationVariant.LUMO_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setCreditPaid(Person person) {
|
||||||
|
try {
|
||||||
|
List<Expense> expenses = expenseService.findExpensesWhereBeneficiary(person).stream().toList();
|
||||||
|
for (Expense expense : expenses) {
|
||||||
|
expense.setIsPaid(true);
|
||||||
|
expenseService.update(expense);
|
||||||
|
}
|
||||||
|
Notification.show("All expenses marked as paid for " + person.getFirstName() + " " + person.getLastName());
|
||||||
|
refreshGrid();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Notification n = Notification.show("Error marking expenses as paid: " + e.getMessage());
|
||||||
|
n.setPosition(Position.MIDDLE);
|
||||||
|
n.addThemeVariants(NotificationVariant.LUMO_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue