diff --git a/screenshots/Investments.png b/screenshots/Investments.png index c52de1e..2d3458c 100644 Binary files a/screenshots/Investments.png and b/screenshots/Investments.png differ diff --git a/src/main/java/com/example/FinanceTracker/Controllers/HomeController.java b/src/main/java/com/example/FinanceTracker/Controllers/HomeController.java index 8753c77..b0fd03f 100644 --- a/src/main/java/com/example/FinanceTracker/Controllers/HomeController.java +++ b/src/main/java/com/example/FinanceTracker/Controllers/HomeController.java @@ -16,7 +16,7 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import com.example.FinanceTracker.Components.BootstrapColours; -import com.example.FinanceTracker.Components.PdfManager; +//import com.example.FinanceTracker.Components.PdfManager; import com.example.FinanceTracker.DTOs.GroupedTransaction; import com.example.FinanceTracker.DTOs.Home.OverviewCard; import com.example.FinanceTracker.Models.Transaction; @@ -26,8 +26,8 @@ import com.example.FinanceTracker.Services.TransactionService; @Controller public class HomeController { - @Autowired - private PdfManager pdfManager; +// @Autowired +// private PdfManager pdfManager; @Autowired private TransactionService transactionsService; diff --git a/src/main/java/com/example/FinanceTracker/Controllers/InvestmentsController.java b/src/main/java/com/example/FinanceTracker/Controllers/InvestmentsController.java index 446e3a0..b4581e2 100644 --- a/src/main/java/com/example/FinanceTracker/Controllers/InvestmentsController.java +++ b/src/main/java/com/example/FinanceTracker/Controllers/InvestmentsController.java @@ -2,20 +2,19 @@ package com.example.FinanceTracker.Controllers; import java.math.BigDecimal; import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; - import com.example.FinanceTracker.DTOs.Investments.CurrRate; import com.example.FinanceTracker.DTOs.Investments.Currency; import com.example.FinanceTracker.DTOs.Investments.ExchangeRate; import com.example.FinanceTracker.Services.InvestmentService; +import com.example.FinanceTracker.Services.TransactionService; @Controller public class InvestmentsController { @@ -23,9 +22,15 @@ public class InvestmentsController { @Autowired private InvestmentService investmentService; + @Autowired + private TransactionService transactionService; + @GetMapping("/investments") public String investments(Model model) { + // Heading + model.addAttribute("latestBalance", "Total Invested: " +transactionService.getTotalInvested() + "*"); + // Create Currency Pills List allRates = investmentService.getCurrRates(); model.addAttribute("currRates", allRates); @@ -54,12 +59,21 @@ public class InvestmentsController { return "investments"; } - @GetMapping("/historicalRatesWeekly") - public String showHistoricalRatesWeek(Model model, - @RequestParam("historicalRatesWeekly") boolean historicalRatesWeekly){ + @GetMapping("/historicalRates") + public String getHistoricalRates( + @RequestParam("duration") String durationCode, + @RequestParam("currencyChange") String currencyChange, + Model model) { // historical rates chart - List historicalExchangeRates = investmentService.getHistoricalRates("USD", 3).reversed(); + int duration = 1; + if (durationCode.equals("MONTH")) + duration = 2; + if (durationCode.equals("YEAR")) + duration = 3; + + List historicalExchangeRates = investmentService.getHistoricalRates(currencyChange, duration) + .reversed(); // Get all the rates from the historical Exchange Rates ArrayList historicalRates = new ArrayList<>(); @@ -75,29 +89,4 @@ public class InvestmentsController { return "investments :: HistoricalRatesChart"; } - - @GetMapping("/changeHistoricalCurr") - public String changeHistoricalCurr(Model model, - @RequestParam("currencyChange") String currencyChange){ - - // historical rates chart - List historicalExchangeRates = investmentService.getHistoricalRates(currencyChange, 3).reversed(); - - // Get all the rates from the historical Exchange Rates - ArrayList historicalRates = new ArrayList<>(); - ArrayList historicalRatesLabels = new ArrayList<>(); - for (ExchangeRate exchangeRate : historicalExchangeRates) { - historicalRates.add(exchangeRate.getRate()); - historicalRatesLabels.add(exchangeRate.getCreatedAt().toLocalDate()); - } - - model.addAttribute("historicalRates", historicalRates); - model.addAttribute("labels", historicalRatesLabels); - - return "investments :: HistoricalRatesChart"; - } - - - - } diff --git a/src/main/java/com/example/FinanceTracker/Models/Transaction.java b/src/main/java/com/example/FinanceTracker/Models/Transaction.java index a7a382d..8470297 100644 --- a/src/main/java/com/example/FinanceTracker/Models/Transaction.java +++ b/src/main/java/com/example/FinanceTracker/Models/Transaction.java @@ -32,7 +32,7 @@ public class Transaction { private String description; @Column - private int category; + private String category; @Column private BigDecimal moneyIn; diff --git a/src/main/java/com/example/FinanceTracker/Repo/TransactionRepo.java b/src/main/java/com/example/FinanceTracker/Repo/TransactionRepo.java index fbd4973..567327e 100644 --- a/src/main/java/com/example/FinanceTracker/Repo/TransactionRepo.java +++ b/src/main/java/com/example/FinanceTracker/Repo/TransactionRepo.java @@ -186,4 +186,12 @@ public interface TransactionRepo extends JpaRepository { """, nativeQuery = true) double getSavingRate(); + @Query(value = """ + SELECT SUM(money_out) * -1 + FROM transactions t + JOIN categories c ON t.category = c.id + WHERE c.category_name = 'Investments' + """, nativeQuery = true) + double getTotalInvested(); + } diff --git a/src/main/java/com/example/FinanceTracker/Services/InvestmentService.java b/src/main/java/com/example/FinanceTracker/Services/InvestmentService.java index 0616b38..f85d84b 100644 --- a/src/main/java/com/example/FinanceTracker/Services/InvestmentService.java +++ b/src/main/java/com/example/FinanceTracker/Services/InvestmentService.java @@ -1,6 +1,5 @@ package com.example.FinanceTracker.Services; -import java.math.BigDecimal; import java.time.LocalDate; import java.util.List; @@ -56,10 +55,14 @@ public class InvestmentService { .body(new ParameterizedTypeReference>() { }); - if (exchangeRate.get(0).getRate().compareTo(exchangeRate.get(1).getRate()) > 0) { + int changeFactor = exchangeRate.get(0).getRate().compareTo(exchangeRate.get(1).getRate()); + + if (changeFactor > 0) { return "UP"; - } else { + } else if (changeFactor < 0) { return "DOWN"; + }else { + return "NEUTRAL"; } } diff --git a/src/main/java/com/example/FinanceTracker/Services/TransactionService.java b/src/main/java/com/example/FinanceTracker/Services/TransactionService.java index 280cd0f..5edea40 100644 --- a/src/main/java/com/example/FinanceTracker/Services/TransactionService.java +++ b/src/main/java/com/example/FinanceTracker/Services/TransactionService.java @@ -51,7 +51,7 @@ public class TransactionService { return transactionRepo.searchTransactions(pageable, searchValue); } - public double getLatestBalance(){ + public double getLatestBalance() { return transactionRepo.getLatestBalance(); } @@ -113,7 +113,7 @@ public class TransactionService { return transactionRepo.getTotalFeesByYear(year); } - public double getTotalFees(){ + public double getTotalFees() { return transactionRepo.getTotalFees(); } @@ -121,21 +121,24 @@ public class TransactionService { // Other // ============================================================= - public List getTotals() { return transactionRepo.getTotals(); } - public List getQuarterlyTotals(int year){ + public List getQuarterlyTotals(int year) { return transactionRepo.getQuarterlyTotals(year); } - public double getNetCashflow(){ + public double getNetCashflow() { return transactionRepo.getNetCashflow(); } - public double getSavingRate(){ + public double getSavingRate() { return transactionRepo.getSavingRate(); } + public double getTotalInvested() { + return transactionRepo.getTotalInvested(); + } + } diff --git a/src/main/resources/templates/fragments/investments/curr-badges.html b/src/main/resources/templates/fragments/investments/curr-badges.html index 177a1ca..d847bfb 100644 --- a/src/main/resources/templates/fragments/investments/curr-badges.html +++ b/src/main/resources/templates/fragments/investments/curr-badges.html @@ -1,21 +1,20 @@ - - + - - - - - + \ No newline at end of file diff --git a/src/main/resources/templates/investments.html b/src/main/resources/templates/investments.html index a457157..3236765 100644 --- a/src/main/resources/templates/investments.html +++ b/src/main/resources/templates/investments.html @@ -134,37 +134,43 @@
Historical Rates
-
-
- +
+ + +
+ - + - +
-
-
- + -
+ + +