Compare commits
No commits in common. "8e5ba1bb2b7c5642211a605ad5752620af7aabdf" and "23b9e09aab7ba55f434eabda914b1dde911f10ae" have entirely different histories.
8e5ba1bb2b
...
23b9e09aab
4 changed files with 12 additions and 25 deletions
|
@ -21,11 +21,5 @@ public interface ExpenseRepository extends JpaRepository<Expense, Long>, JpaSpec
|
|||
@Query("SELECT e FROM Expense e WHERE YEAR(e.date) = :year")
|
||||
List<Expense> findAllByYear(@Param("year") int year);
|
||||
|
||||
@Query("SELECT e FROM Expense e JOIN e.creditors c WHERE c.id = :personId AND e.isResolved = false")
|
||||
Set<Expense> findUnpaidCreditorsExpensesByPersonId(@Param("personId") Long personId);
|
||||
|
||||
@Query("SELECT e FROM Expense e JOIN e.debtors d WHERE d.id = :personId AND e.isResolved = false")
|
||||
Set<Expense> findUnpaidDebtorsExpensesByPersonId(@Param("personId") Long personId);
|
||||
|
||||
boolean existsByIdAndIsResolvedTrue(Long id);
|
||||
}
|
|
@ -32,14 +32,6 @@ public class ExpenseService {
|
|||
public Collection<Expense> findCreditByUser(final Person person) {
|
||||
return repository.findCreditorsExpensesByPersonId(person.getId());
|
||||
}
|
||||
|
||||
public Collection<Expense> findUnpaidDebtByUser(final Person person) {
|
||||
return repository.findUnpaidDebtorsExpensesByPersonId(person.getId());
|
||||
}
|
||||
|
||||
public Collection<Expense> findUnpaidCreditByUser(final Person person) {
|
||||
return repository.findUnpaidCreditorsExpensesByPersonId(person.getId());
|
||||
}
|
||||
public List<Expense> findAll() {return repository.findAll();}
|
||||
|
||||
public void update(Expense entity) {
|
||||
|
|
|
@ -60,8 +60,8 @@ public class PersonService {
|
|||
}
|
||||
|
||||
public BigDecimal calculateNetBalance(final Person person) {
|
||||
final var credit = this.expenseService.findUnpaidCreditByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
final var debit = this.expenseService.findUnpaidDebtByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
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.subtract(debit);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.vaadin.flow.component.textfield.TextField;
|
|||
import com.vaadin.flow.data.binder.BeanValidationBinder;
|
||||
import com.vaadin.flow.data.binder.ValidationException;
|
||||
import com.vaadin.flow.data.renderer.ComponentRenderer;
|
||||
import com.vaadin.flow.data.renderer.LitRenderer;
|
||||
import com.vaadin.flow.router.*;
|
||||
import com.vaadin.flow.spring.data.VaadinSpringDataHelpers;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
@ -67,7 +68,6 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
|
|||
private ComboBox<Category> category;
|
||||
private TextArea description;
|
||||
private Checkbox isPeriodic;
|
||||
private Checkbox isResolved;
|
||||
private ComboBox<PeriodUnit> periodUnit;
|
||||
private TextField periodInterval;
|
||||
private DatePicker date;
|
||||
|
@ -124,7 +124,6 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
|
|||
|
||||
// We set initial value of isPeriodic to true and show period fields
|
||||
isPeriodic.setValue(false);
|
||||
isResolved.setValue(false);
|
||||
periodUnit.setVisible(false);
|
||||
periodInterval.setVisible(false);
|
||||
|
||||
|
@ -233,6 +232,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
|
|||
category.setItems(categoryService.findAll());
|
||||
category.setItemLabelGenerator(Category::getName);
|
||||
description = new TextArea("Description");
|
||||
isPeriodic = new Checkbox("Is Periodic");
|
||||
periodUnit = new ComboBox<>("Period Unit");
|
||||
periodUnit.setItems(PeriodUnit.values());
|
||||
periodInterval = new TextField("Period Interval");
|
||||
|
@ -246,14 +246,15 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
|
|||
debtors.setItems(personService.findAll());
|
||||
debtors.setItemLabelGenerator(Person::getFirstName);
|
||||
date = new DatePicker("Date");
|
||||
LitRenderer<Expense> isPeriodicRenderer = LitRenderer.<Expense>of(
|
||||
"<vaadin-icon icon='vaadin:${item.icon}' style='width: var(--lumo-icon-size-s); height: var(--lumo-icon-size-s); color: ${item.color};'></vaadin-icon>")
|
||||
.withProperty("icon", important -> important.getIsPeriodic() ? "check" : "minus").withProperty("color",
|
||||
important -> important.getIsPeriodic()
|
||||
? "var(--lumo-primary-text-color)"
|
||||
: "var(--lumo-disabled-text-color)");
|
||||
|
||||
// Horizontal layout for checkboxes
|
||||
HorizontalLayout checkboxLayout = new HorizontalLayout();
|
||||
isPeriodic = new Checkbox("Is Periodic");
|
||||
isResolved = new Checkbox("Paid");
|
||||
checkboxLayout.add(isPeriodic, isResolved);
|
||||
|
||||
formLayout.add(name, cost, category, description, checkboxLayout, periodUnit, periodInterval, date, creditors, debtors, event);
|
||||
formLayout.add(name, cost, category, description, isPeriodic, periodUnit, periodInterval, date, creditors, debtors, event);
|
||||
grid.addColumn(isPeriodicRenderer).setHeader("Periodic").setAutoWidth(true);
|
||||
editorDiv.add(formLayout);
|
||||
createButtonLayout(editorLayoutDiv);
|
||||
|
||||
|
|
Loading…
Reference in a new issue