From 7d50b12a4fb37cc98484799d5d2364d3f730f586 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Mon, 5 Feb 2024 15:22:26 -0500 Subject: [PATCH] Added functionality for an !exclude tag. --- .../perfin/control/EditAccountController.java | 1 - .../data/impl/JdbcAnalyticsRepository.java | 24 +++++++++++++++++-- .../view/component/module/PieChartModule.java | 11 +++++---- .../help-pages/adding-a-transaction.fxml | 4 ++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/andrewlalis/perfin/control/EditAccountController.java b/src/main/java/com/andrewlalis/perfin/control/EditAccountController.java index 2d97e97..d0761f7 100644 --- a/src/main/java/com/andrewlalis/perfin/control/EditAccountController.java +++ b/src/main/java/com/andrewlalis/perfin/control/EditAccountController.java @@ -58,7 +58,6 @@ public class EditAccountController implements RouteSelectionListener { var numberValid = new ValidationApplier<>(new PredicateValidator() .addTerminalPredicate(s -> s != null && !s.isBlank(), "Account number should not be empty.") .addPredicate(s -> s.length() <= 255, "Account number is too long.") - .addPredicate(s -> s.matches("\\d+"), "Account number should contain only numeric digits.") ).attachToTextField(accountNumberField); var balanceValid = new ValidationApplier<>( diff --git a/src/main/java/com/andrewlalis/perfin/data/impl/JdbcAnalyticsRepository.java b/src/main/java/com/andrewlalis/perfin/data/impl/JdbcAnalyticsRepository.java index 0bb65c4..108888a 100644 --- a/src/main/java/com/andrewlalis/perfin/data/impl/JdbcAnalyticsRepository.java +++ b/src/main/java/com/andrewlalis/perfin/data/impl/JdbcAnalyticsRepository.java @@ -45,7 +45,17 @@ public record JdbcAnalyticsRepository(Connection conn) implements AnalyticsRepos FROM transaction LEFT JOIN transaction_vendor tv ON tv.id = transaction.vendor_id LEFT JOIN account_entry ae ON ae.transaction_id = transaction.id - WHERE transaction.currency = ? AND ae.type = 'CREDIT' AND transaction.timestamp >= ? AND transaction.timestamp <= ? + WHERE + transaction.currency = ? AND + transaction.timestamp >= ? AND + transaction.timestamp <= ? AND + ae.type = 'CREDIT' AND + '!exclude' NOT IN ( + SELECT tt.name + FROM transaction_tag tt + LEFT JOIN transaction_tag_join ttj ON tt.id = ttj.tag_id + WHERE ttj.transaction_id = transaction.id + ) GROUP BY tv.id ORDER BY total DESC""", List.of(currency.getCurrencyCode(), range.start(), range.end()), @@ -75,7 +85,17 @@ public record JdbcAnalyticsRepository(Connection conn) implements AnalyticsRepos FROM transaction LEFT JOIN transaction_category tc ON tc.id = transaction.category_id LEFT JOIN account_entry ae ON ae.transaction_id = transaction.id - WHERE transaction.currency = ? AND ae.type = ? AND transaction.timestamp >= ? AND transaction.timestamp <= ? + WHERE + transaction.currency = ? AND + ae.type = ? AND + transaction.timestamp >= ? AND + transaction.timestamp <= ? AND + '!exclude' NOT IN ( + SELECT tt.name + FROM transaction_tag tt + LEFT JOIN transaction_tag_join ttj ON tt.id = ttj.tag_id + WHERE ttj.transaction_id = transaction.id + ) GROUP BY tc.id ORDER BY total DESC;""", List.of(currency.getCurrencyCode(), type.name(), range.start(), range.end()), diff --git a/src/main/java/com/andrewlalis/perfin/view/component/module/PieChartModule.java b/src/main/java/com/andrewlalis/perfin/view/component/module/PieChartModule.java index babc4cb..20fe260 100644 --- a/src/main/java/com/andrewlalis/perfin/view/component/module/PieChartModule.java +++ b/src/main/java/com/andrewlalis/perfin/view/component/module/PieChartModule.java @@ -11,10 +11,7 @@ import javafx.scene.control.ChoiceBox; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Currency; -import java.util.List; +import java.util.*; import java.util.concurrent.CompletableFuture; /** @@ -39,7 +36,11 @@ public abstract class PieChartModule extends DashboardModule { this.getChildren().add(chart); currencyChoiceBox.valueProperty().addListener((observable, oldValue, newValue) -> { if (newValue != null) { - getChartData(newValue).thenAccept(data -> Platform.runLater(() -> { + getChartData(newValue).exceptionally(throwable -> { + throwable.printStackTrace(System.err); + return Collections.emptyList(); + }) + .thenAccept(data -> Platform.runLater(() -> { chartData.setAll(data); if (!dataColors.isEmpty()) { for (int i = 0; i < dataColors.size(); i++) { diff --git a/src/main/resources/help-pages/adding-a-transaction.fxml b/src/main/resources/help-pages/adding-a-transaction.fxml index 0df9dde..6069ad8 100644 --- a/src/main/resources/help-pages/adding-a-transaction.fxml +++ b/src/main/resources/help-pages/adding-a-transaction.fxml @@ -65,6 +65,10 @@ and earnings. With **tags**, you can add custom text tags to your transaction, sort of like social media's "hashtag" phenomenon. -- + **Pro-tip**: You can add the tag `!exclude` to a transaction to exclude + it from analytics and visuals. This is useful for things like transfers + between your accounts. + -- **Line items** can be used to specify in more detail what was bought or sold in a transaction. For example, you bought a new computer and some accessories at an electronics store. You can record the exact purchase