diff --git a/src/main/java/com/application/munera/data/Expense.java b/src/main/java/com/application/munera/data/Expense.java index c2269d0..1d1ff13 100644 --- a/src/main/java/com/application/munera/data/Expense.java +++ b/src/main/java/com/application/munera/data/Expense.java @@ -34,11 +34,11 @@ public class Expense { @Column(name = "Description") private String description; - @Column(name = "PeriodicExpense", nullable = false) + @Column(name = "Periodic", nullable = false) private Boolean isPeriodic; @Enumerated(EnumType.ORDINAL) - @Column(name = "PeriodUnit") + @Column(name = "Period") private PeriodUnit periodUnit; @Column(name = "PeriodInterval") @@ -62,7 +62,7 @@ public class Expense { private Boolean isPaid = false; @Enumerated(EnumType.STRING) - @Column(name = "expenseType", nullable = false) + @Column(name = "type", nullable = false) private ExpenseType expenseType; @Column(name = "userId", nullable = false) diff --git a/src/main/java/com/application/munera/services/ExpenseService.java b/src/main/java/com/application/munera/services/ExpenseService.java index d031ce3..21ff86a 100644 --- a/src/main/java/com/application/munera/services/ExpenseService.java +++ b/src/main/java/com/application/munera/services/ExpenseService.java @@ -121,15 +121,6 @@ public class ExpenseService { return this.expenseRepository.findByUserIdOrderByDateDesc(userId); } - /** - * Finds expenses by year excluding those marked as credit and paid. - * @param year the year for which to find expenses - * @return the list of expenses found - */ - public List findExpensesByYearExcludingCreditPaid(int year) { - return expenseRepository.findByYearAndFilterCreditPaid(year, ExpenseType.CREDIT); - } - /** * Checks if an expense has been paid. * @param expense the expense to check diff --git a/src/main/java/com/application/munera/views/dashboard/DashboardView.java b/src/main/java/com/application/munera/views/dashboard/DashboardView.java index 93d06ca..a20074a 100644 --- a/src/main/java/com/application/munera/views/dashboard/DashboardView.java +++ b/src/main/java/com/application/munera/views/dashboard/DashboardView.java @@ -32,12 +32,14 @@ public class DashboardView extends Div { private final PersonService personService; private final UserService userService; private final User loggedUser; + private final Person loggedPerson; public DashboardView(final ExpenseService expenseService, final PersonService personService, UserService userService) { this.expenseService = expenseService; this.personService = personService; this.userService = userService; loggedUser = userService.getLoggedInUser(); + loggedPerson = personService.getLoggedInPerson(); addClassName("highcharts-view"); // Optional CSS class for styling VerticalLayout mainLayout = new VerticalLayout(); @@ -100,19 +102,18 @@ public class DashboardView extends Div { String barChartJs = generateBarChartScript(); String pieChartJs = generatePieChartScript(); - String bottomLeftChartJs = generateNegativeColumnChartScript(); - String bottomRightChartJs = generateExpensesOverTimeByCategoryScript(); + String negativeColumnChartJs = generateNegativeColumnChartScript(); + String expensesOverTimeByCategoryChart = generateExpensesOverTimeByCategoryScript(); // Execute the JavaScript to initialize the charts getElement().executeJs(barChartJs); getElement().executeJs(pieChartJs); - getElement().executeJs(bottomLeftChartJs); - getElement().executeJs(bottomRightChartJs); + getElement().executeJs(negativeColumnChartJs); + getElement().executeJs(expensesOverTimeByCategoryChart); } private String generateBarChartScript() { - final var loggedInPerson = this.personService.getLoggedInPerson(); - List expenses = expenseService.fetchExpensesForDashboard(loggedInPerson, Year.now()); + List expenses = expenseService.fetchExpensesForDashboard(loggedPerson, Year.now()); // Prepare data for Highcharts Map monthlyData = new LinkedHashMap<>(); @@ -157,7 +158,7 @@ public class DashboardView extends Div { } private String generatePieChartScript() { - List expenses = expenseService.findExpensesByYearExcludingCreditPaid(Year.now().getValue()); + List expenses = expenseService.fetchExpensesForDashboard(loggedPerson, Year.now()); // Group expenses by category name and sum their costs Map categoryData = expenses.stream() @@ -275,7 +276,7 @@ public class DashboardView extends Div { } private String generateExpensesOverTimeByCategoryScript() { - List expenses = expenseService.findExpensesByYearExcludingCreditPaid(Year.now().getValue()); + List expenses = expenseService.fetchExpensesForDashboard(loggedPerson, Year.now()); // Group expenses by category and by month Map> categoryMonthlyData = new LinkedHashMap<>();