This commit is contained in:
2016-07-21 23:37:22 +02:00
parent 05f9b4274c
commit 936e854aad
7 changed files with 110 additions and 59 deletions
@@ -5,6 +5,19 @@ 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();
}
@@ -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();
}
+3 -7
View File
@@ -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),
+1
View File
@@ -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 */
+47 -29
View File
@@ -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++;
@@ -2,26 +2,60 @@
<div class="row">
<table class="importTable">
<tr>
<th>Wertstellung</th>
<th>Typ</th>
<th style="width: 25%;">Text</th>
<th>Betrag</th>
<th style="width: 5%;" class="spacer"></th>
<th style="width: 8%;">Wertstellung</th>
<th style="width: 8%;">Typ</th>
<th style="width: 35%;">Text</th>
<th style="width: 9%;">Betrag</th>
<th class="spacer"></th>
<th>Kategorie</th>
<th>Notiz</th>
<th style="width: 14%;">Kategorie</th>
<th style="width: 14%;">Notiz</th>
<th class="spacer"></th>
<th>Pattern</th>
<th style="width: 5%;">Matcher</th>
</tr>
<tr ng-repeat="line in csv">
<td class="spacer"></td>
<td>{{line[1]}}</td>
<td>{{line[2]}}</td>
<td>{{line[3]}}</td>
<td align="right">{{line[4]}}</td>
<td align="right">{{line[4]}}</td>
<td class="spacer"></td>
<td>{{line.targetCategory}}</td>
<td>
<select
id="categorySelect"
ng-model='line.targetCategory'
size='1'
ng-options="category.name for category in categories track by category._links.self.href"></select>
</td>
<td>{{line.targetDescription}}</td>
<td class="spacer"></td>
<td></td>
<td align="center">{{line.matcherPosition}}</td>
</tr>
</table>
</div>
<div class="row" style="margin-top: 4ex;">
<table class="importTable">
<tr>
<th style="width: 5%;">Position</th>
<th style="width: 8%;">Date Code</th>
<th style="width: 8%;">Type Code</th>
<th style="width: 35%;">Text Code</th>
<th style="width: 9%;">Amount Code</th>
<th class="spacer"></th>
<th style="width: 14%;">Target Category</th>
<th style="width: 14%;">Target Description</th>
<th style="width: 6%;" class="spacer"></th>
</tr>
<tr ng-repeat="matcher in matchers">
<td>{{matcher.position}}</td>
<td>{{matcher.dateMatcherCode}}</td>
<td>{{matcher.typeMatcherCode}}</td>
<td>{{matcher.textMatcherCode}}</td>
<td>{{matcher.amountMatcherCode}}</td>
<td class="spacer"></td>
<td>{{matcher.targetCategory}}</td>
<td>{{matcher.targetDescription}}</td>
<td class="spacer"></td>
</tr>
</table>
</div>
@@ -12,7 +12,7 @@
<div ng-show="lastSubmission" class="lastSubmission col-xs-offset-1 alert alert-info" role="alert">
{{lastSubmission.date | date:'dd.MM.yyyy'}}
<span ng-class="{ 'color-green': lastSubmission.amount > 0, 'color-red': lastSubmission.amount < 0 }">{{lastSubmission.amount}}&nbsp;</span>
<span ng-class="{ 'color-green': lastSubmission.amount.charAt(0) == '+', 'color-red': lastSubmission.amount.charAt(0) == '-' }">{{lastSubmission.amount}}&nbsp;</span>
&nbsp;&nbsp;&nbsp;
<span style='color: red; font-weight: bold;'><a href='' ng-click='deleteLastSubmission()'>löschen</a></span>
</div>