From 936e854aad3a1115ddb739e95d3f81b6ab2755b9 Mon Sep 17 00:00:00 2001 From: Tilman Liero Date: Thu, 21 Jul 2016 23:37:22 +0200 Subject: [PATCH] Matchers --- .../domain/MatcherProjection.java | 15 +++- .../transactions/repository/FullMatcher.java | 11 --- src/main/resources/data-h2.sql | 10 +-- src/main/resources/static/css/app.css | 1 + src/main/resources/static/js/controllers.js | 76 ++++++++++++------- .../static/partials/import-list.html | 54 ++++++++++--- .../static/partials/transaction-list.html | 2 +- 7 files changed, 110 insertions(+), 59 deletions(-) delete mode 100644 src/main/java/de/tilman/transactions/repository/FullMatcher.java diff --git a/src/main/java/de/tilman/transactions/domain/MatcherProjection.java b/src/main/java/de/tilman/transactions/domain/MatcherProjection.java index b0c1fa1..c46bc32 100644 --- a/src/main/java/de/tilman/transactions/domain/MatcherProjection.java +++ b/src/main/java/de/tilman/transactions/domain/MatcherProjection.java @@ -4,7 +4,20 @@ import org.springframework.data.rest.core.config.Projection; @Projection(name = "full", types = Matcher.class) public interface MatcherProjection { - + + Long getId(); + + Account getAccount(); + + Integer getPosition(); + + String getTypeMatcherCode(); + String getDateMatcherCode(); + String getTextMatcherCode(); + String getAmountMatcherCode(); + Category getTargetCategory(); + String getTargetDescription(); + } diff --git a/src/main/java/de/tilman/transactions/repository/FullMatcher.java b/src/main/java/de/tilman/transactions/repository/FullMatcher.java deleted file mode 100644 index ff96410..0000000 --- a/src/main/java/de/tilman/transactions/repository/FullMatcher.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.tilman.transactions.repository; - -import org.springframework.data.rest.core.config.Projection; - -import de.tilman.transactions.domain.Category; -import de.tilman.transactions.domain.Matcher; - -@Projection(name = "fullMatchers", types = Matcher.class) -public interface FullMatcher { - Category getCategory(); -} diff --git a/src/main/resources/data-h2.sql b/src/main/resources/data-h2.sql index 4647cf7..5307ff1 100644 --- a/src/main/resources/data-h2.sql +++ b/src/main/resources/data-h2.sql @@ -12,13 +12,9 @@ INSERT INTO Category (id, name, account_id, position) VALUES INSERT INTO Account_User (account_id, user_id) VALUES (1, 1), (1, 2), (1, 3), (2, 1); INSERT INTO Matcher (id, account_id, position, type_matcher_code, date_matcher_code, text_matcher_code, amount_matcher_code, target_category_id, target_description) VALUES - (NULL, 1, 1, null, null, 'return /\bnone\b/.test(x)', 'return (x == -40)', 4, 'Sparplan (in Rücklage)'), - (NULL, 1, 1, null, null, 'return /\bLIDL\b/.test(x)', null, 1, 'Lidl'); - ---INSERT INTO Pattern (id, account_id, position, type_pattern, date_pattern, text_pattern, amount_pattern, target_category_id, target_description) VALUES --- (NULL, 1, 1, '', '', '*.LIDL*.', '', 1, 'Lidl'), --- (NULL, 1, 1, null, null, '*.Buchungstext: none*.', -40.0, 4, '(in Rücklage)'), --- (NULL, 1, 1, 'Kontoübertrag', null, 'Auftraggeber: Tilman Liero Kto/IBAN: DE44200411330649163305*.', null, 4, '(Entnahme aus Rücklagen)'); + (NULL, 1, 2, null, null, 'return /\bnone\b/.test(x)', 'return (x == -40)', 4, 'Sparplan (in Rücklage)'), + (NULL, 1, 1, null, null, 'return /\bLIDL\b/.test(x)', null, 1, 'Lidl'), + (NULL, 1, 3, null, null, 'return /\bNETTO\b/.test(x)', null, 1, 'Netto'); INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, 1280.81, 1, 2, '2016-04-01 14:14:14', 'Gehalt', null), diff --git a/src/main/resources/static/css/app.css b/src/main/resources/static/css/app.css index e5ef541..03171f5 100644 --- a/src/main/resources/static/css/app.css +++ b/src/main/resources/static/css/app.css @@ -84,6 +84,7 @@ label { .importTable .spacer { background-color: transparent; border: none; + width: 1%; } /* for angular-ui, see https://angular-ui.github.io/bootstrap/#/getting_started */ diff --git a/src/main/resources/static/js/controllers.js b/src/main/resources/static/js/controllers.js index 66a8c3a..bca161d 100644 --- a/src/main/resources/static/js/controllers.js +++ b/src/main/resources/static/js/controllers.js @@ -177,6 +177,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$routePara $scope.waitingForSubmission = false; $scope.refreshList(); $scope.lastSubmission = newTransaction; + $scope.lastSubmission.amount = numberToAmount(newTransaction.amount); }); } } @@ -415,52 +416,69 @@ transactionControllers.controller('ImportListCtrl', [ '$scope', '$resource', '$l $scope.categories = ImportService.getCategories(); $scope.csv = Papa.parse(ImportService.getCSV()).data; - var matcherData = $resource('/matchers/search/listForAccount', { accountId: $scope.account.id }).get(); + var matcherData = $resource('/matchers/search/listForAccount', { projection: 'full', accountId: $scope.account.id }).get(); matcherData.$promise.then(function(data) { - - // XXX - console.log(matcherData); - - matcherData = matcherData._embedded.matchers; - var matchers = new Array(matcherData.length); + $scope.matchers = new Array(matcherData.length); - for (i = 0; i < matchers.length; i++) { - matchers[i] = {}; + for (i = 0; i < $scope.matchers.length; i++) { + $scope.matchers[i] = {}; - if (matcherData[i].dateMatcherCode != null) - matchers[i].dateMatcher = new Function('x', matcherData[i].dateMatcherCode); - if (matcherData[i].typeMatcherCode != null) - matchers[i].typeMatcher = new Function('x', matcherData[i].typeMatcherCode); - if (matcherData[i].textMatcherCode != null) - matchers[i].textMatcher = new Function('x', matcherData[i].textMatcherCode); - if (matcherData[i].amountMatcherCode != null) - matchers[i].amountMatcher = new Function('x', matcherData[i].amountMatcherCode); + $scope.matchers[i].id = matcherData[i].id; + $scope.matchers[i].position = matcherData[i].position; + + if (matcherData[i].dateMatcherCode != null) { + $scope.matchers[i].dateMatcher = new Function('x', matcherData[i].dateMatcherCode); + $scope.matchers[i].dateMatcherCode = matcherData[i].dateMatcherCode; + } + + if (matcherData[i].typeMatcherCode != null) { + $scope.matchers[i].typeMatcher = new Function('x', matcherData[i].typeMatcherCode); + $scope.matchers[i].typeMatcherCode = matcherData[i].typeMatcherCode; + } + + if (matcherData[i].textMatcherCode != null) { + $scope.matchers[i].textMatcher = new Function('x', matcherData[i].textMatcherCode); + $scope.matchers[i].textMatcherCode = matcherData[i].textMatcherCode; + } + + if (matcherData[i].amountMatcherCode != null) { + $scope.matchers[i].amountMatcher = new Function('x', matcherData[i].amountMatcherCode); + $scope.matchers[i].amountMatcherCode = matcherData[i].amountMatcherCode; + } + + $scope.matchers[i].targetDescription = matcherData[i].targetDescription; + $scope.matchers[i].targetCategory = matcherData[i].targetCategory; - matchers[i].targetDescription = matcherData[i].targetDescription; } // XXX - console.log(matchers); + console.log(matcherData); + console.log($scope.matchers); for (i = 0; i < $scope.csv.length; i++) { var matched = false; var j = 0; - while (!matched && j < matchers.length) { + while (!matched && j < $scope.matchers.length) { var match = true; - if (match && matchers[j].dateMatcher) - match = matchers[j].dateMatcher($scope.csv[i][1]); - if (match && matchers[j].typeMatcher) - match = matchers[j].typeMatcher($scope.csv[i][2]); - if (match && matchers[j].textMatcher) - match = matchers[j].textMatcher($scope.csv[i][3]); - if (match && matchers[j].amountMatcher) - match = matchers[j].amountMatcher(amountToNumber($scope.csv[i][4])); + if (match && $scope.matchers[j].dateMatcher) + match = $scope.matchers[j].dateMatcher($scope.csv[i][1]); + if (match && $scope.matchers[j].typeMatcher) + match = $scope.matchers[j].typeMatcher($scope.csv[i][2]); + if (match && $scope.matchers[j].textMatcher) + match = $scope.matchers[j].textMatcher($scope.csv[i][3]); + if (match && $scope.matchers[j].amountMatcher) + match = $scope.matchers[j].amountMatcher(amountToNumber($scope.csv[i][4])); if (match) { - $scope.csv[i].targetDescription = matchers[j].targetDescription; + $scope.csv[i].targetDescription = $scope.matchers[j].targetDescription; + $scope.csv[i].matcherPosition = $scope.matchers[j].position; + for (k = 0; k < $scope.categories.length; k++) { + if ($scope.categories[k].name == $scope.matchers[j].targetCategory.name) + $scope.csv[i].targetCategory = $scope.categories[k]; + } } j++; diff --git a/src/main/resources/static/partials/import-list.html b/src/main/resources/static/partials/import-list.html index d2a5d9d..6a0e645 100644 --- a/src/main/resources/static/partials/import-list.html +++ b/src/main/resources/static/partials/import-list.html @@ -2,26 +2,60 @@
- - - - + + + + + - - + + - + + - + - + - + + +
WertstellungTypTextBetragWertstellungTypTextBetrag KategorieNotizKategorieNotiz PatternMatcher
{{line[1]}} {{line[2]}} {{line[3]}}{{line[4]}}{{line[4]}} € {{line.targetCategory}} + + {{line.targetDescription}} {{line.matcherPosition}}
+
+
+ + + + + + + + + + + + + + + + + + + + + +
PositionDate CodeType CodeText CodeAmount CodeTarget CategoryTarget Description
{{matcher.position}}{{matcher.dateMatcherCode}}{{matcher.typeMatcherCode}}{{matcher.textMatcherCode}}{{matcher.amountMatcherCode}}{{matcher.targetCategory}}{{matcher.targetDescription}}
diff --git a/src/main/resources/static/partials/transaction-list.html b/src/main/resources/static/partials/transaction-list.html index b928d30..83b1b34 100644 --- a/src/main/resources/static/partials/transaction-list.html +++ b/src/main/resources/static/partials/transaction-list.html @@ -12,7 +12,7 @@