forked from portfolio-performance/portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaaderBankPDFExtractor.java
1027 lines (898 loc) · 48.2 KB
/
BaaderBankPDFExtractor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package name.abuchen.portfolio.datatransfer.pdf;
import static name.abuchen.portfolio.datatransfer.ExtractorUtils.checkAndSetGrossUnit;
import static name.abuchen.portfolio.util.TextUtil.trim;
import java.math.BigDecimal;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import name.abuchen.portfolio.Messages;
import name.abuchen.portfolio.datatransfer.ExtrExchangeRate;
import name.abuchen.portfolio.datatransfer.ExtractorUtils;
import name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block;
import name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType;
import name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction;
import name.abuchen.portfolio.model.AccountTransaction;
import name.abuchen.portfolio.model.BuySellEntry;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.PortfolioTransaction;
import name.abuchen.portfolio.money.Money;
import name.abuchen.portfolio.money.Values;
@SuppressWarnings("nls")
public class BaaderBankPDFExtractor extends AbstractPDFExtractor
{
public BaaderBankPDFExtractor(Client client)
{
super(client);
addBankIdentifier("Baader Bank"); //$NON-NLS-1$
addBuySellTransaction();
addDividendeTransaction();
addAdvanceTaxTransaction();
addTaxAdjustmentTransaction();
addDepotStatementTransaction();
addFeesAssetManagerTransaction();
addDeliveryInOutBoundTransaction();
addTransferOutTransaction();
}
@Override
public String getLabel()
{
return "Baader Bank AG / Scalable Capital Vermögensverwaltung GmbH"; //$NON-NLS-1$
}
private void addBuySellTransaction()
{
DocumentType type = new DocumentType("((Wertpapierabrechnung|Transaction Statement): (Kauf|Verkauf|Purchase|Sale)|Zeichnung|Spitzenregulierung).*");
this.addDocumentTyp(type);
Transaction<BuySellEntry> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.BUY);
return entry;
});
Block firstRelevantLine = new Block("^(Vorgangs\\-Nr|Transaction No)\\.: .*$");
type.addBlock(firstRelevantLine);
firstRelevantLine.set(pdfTransaction);
pdfTransaction
// Is type --> "Verkauf" change from BUY to SELL
.section("type").optional()
.match("^(Wertpapierabrechnung|Transaction Statement): (?<type>(Kauf|Verkauf|Purchase|Sale)).*$")
.assign((t, v) -> {
if ("Verkauf".equals(v.get("type")) || "Sale".equals(v.get("type")))
t.setType(PortfolioTransaction.Type.SELL);
})
// Is type --> "Spitzenregulierung" change from BUY to SELL
.section("type").optional()
.match("^(?<type>Spitzenregulierung).*$")
.assign((t, v) -> {
if ("Spitzenregulierung".equals(v.get("type")))
t.setType(PortfolioTransaction.Type.SELL);
})
// @formatter:off
// Nominale ISIN: IE0032895942 WKN: 911950 Kurs
// STK 2 iShs DL Corp Bond UCITS ETF EUR 104,37
// Registered Shares o.N.
// Kurswert EUR 208,74
// @formatter:on
.section("isin", "wkn", "name", "nameContinued", "currency")
.match("^(Nominale|Quantity) ISIN: (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9]) WKN: (?<wkn>[A-Z0-9]{6}) (Kurs|Bezugspreis|Barabfindung|Price).*$")
.match("^(STK|Units) [\\.,\\d]+ (?<name>.*) (?<currency>[\\w]{3}) .*$")
.match("^(?<nameContinued>.*)$")
.assign((t, v) -> {
if (v.get("nameContinued").endsWith("p.STK"))
v.put("nameContinued", v.get("nameContinued").replace("p.STK", ""));
t.setSecurity(getOrCreateSecurity(v));
})
// @formatter:off
// STK 2 iShs DL Corp Bond UCITS ETF EUR 104,37
// Units 2.734 iShsIII-Core MSCI World U.ETF EUR 73.128
// @formatter:on
.section("local", "shares")
.match("^(?<local>(STK|Units)) (?<shares>[\\.,\\d]+) .*$")
.assign((t, v) -> {
if ("Units".equals(v.get("local")))
t.setShares(asShares(v.get("shares"), "en", "US"));
else
t.setShares(asShares(v.get("shares")));
})
.oneOf(
// @formatter:off
// Handelsdatum Handelsuhrzeit
// 20.03.2017 15:31:10:00
//
// Handelsdatum Handelsuhrzeit
// 11.04.2023 12:31:19:07
// @formatter:on
section -> section
.attributes("date", "time")
.find(".*Handelsdatum Handelsuhrzeit.*")
.match("^(?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) (?<time>[\\d]{2}:[\\d]{2}:[\\d]{2}):.*$")
.assign((t, v) -> t.setDate(asDate(v.get("date"), v.get("time"))))
,
// @formatter:off
// Handels- Handels-
// STK 70 EUR 14,045 GETTEX - MM Munich 24.02.2021 14:49:46:04
//
// Handels- Handels-
// STK 50 EUR 30,79 GETTEX - MM Munich 12.04.2023 09:00:06:185
// @formatter:on
section -> section
.attributes("date", "time")
.find(".*Handels\\- Handels\\-.*")
.match("^.* (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) (?<time>[\\d]{2}:[\\d]{2}:[\\d]{2}):.*$")
.assign((t, v) -> t.setDate(asDate(v.get("date"), v.get("time"))))
,
// @formatter:off
// Details zur Ausführung: Handels- Handels-
// STK 6 EUR 146,34 GETTEX - MM Munich 27.01.2022 16:25:24:39
// @formatter:on
section -> section
.attributes("date", "time")
.find(".*Handels\\- Handels\\-.*")
.match("^.* (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) (?<time>[\\d]{2}:[\\d]{2}:[\\d]{2}):.*$")
.assign((t, v) -> t.setDate(asDate(v.get("date"), v.get("time"))))
,
// @formatter:off
// Einbuchung in Depot yyyyyyyyyy per 09.03.2021
// @formatter:on
section -> section
.attributes("date")
.match("^Einbuchung in Depot .* per (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4})$")
.assign((t, v) -> t.setDate(asDate(v.get("date"))))
,
// @formatter:off
// Ausbuchung aus Depot 11 per 05.05.2020
// @formatter:on
section -> section
.attributes("date")
.match("^Ausbuchung aus Depot .* per (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4})$")
.assign((t, v) -> t.setDate(asDate(v.get("date"))))
,
// @formatter:off
// Trade Date Trade Time
// 2022-02-28 13:48:52:44
// @formatter:on
section -> section
.attributes("date", "time")
.find(".*Trade Date Trade Time.*")
.match("^(?<date>[\\d]{4}\\-[\\d]{2}\\-[\\d]{2}) (?<time>[\\d]{2}:[\\d]{2}:[\\d]{2}):.*$")
.assign((t, v) -> t.setDate(asDate(v.get("date"), v.get("time"))))
,
// @formatter:off
// Quantity Price Execution Venue Trade Date Trade Time
// Units 11 EUR 8.55 GETTEX - MM Munich 2022-04-29 09:32:39:47
// @formatter:on
section -> section
.attributes("date", "time")
.find(".*Trade Date Trade Time.*")
.match("^.* (?<date>[\\d]{4}\\-[\\d]{2}\\-[\\d]{2}) (?<time>[\\d]{2}:[\\d]{2}:[\\d]{2}):.*$")
.assign((t, v) -> t.setDate(asDate(v.get("date"), v.get("time"))))
)
.oneOf(
// @formatter:off
// Zu Lasten Konto 12345004 Valuta: 22.03.2017 EUR 208,95
// Zu Gunsten Konto 12345004 Valuta: 12.05.2017 EUR 75,92
// @formatter:on
section -> section
.attributes("currency", "amount")
.match("^Zu (Gunsten|Lasten) Konto .* (?<currency>[\\w]{3}) (?<amount>[\\.,\\d]+)$")
.assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
})
,
// @formatter:off
// Amount debited to account 1960017000 Value: 2022-03-02 EUR 199.93
// Amount credited to account 1209625007 Value: 2022-07-13 EUR 329.36
// @formatter:on
section -> section
.attributes("currency", "amount")
.match("^Amount (debited|credited) to account [\\d]+ Value: [\\d]{4}\\-[\\d]{2}\\-[\\d]{2} (?<currency>[\\w]{3}) (?<amount>[\\.,\\d]+)$")
.assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
})
)
// @formatter:off
// Kurswert Umrechnungskurs CAD/EUR: 1,4595 EUR 8,85
// @formatter:on
.section("termCurrency", "baseCurrency", "exchangeRate", "currency", "gross").optional()
.match("^Kurswert Umrechnungskurs (?<termCurrency>[\\w]{3})\\/(?<baseCurrency>[\\w]{3}): (?<exchangeRate>[\\.,\\d]+) (?<currency>[\\w]{3}) (?<gross>[\\.,\\d]+)$")
.assign((t, v) -> {
ExtrExchangeRate rate = asExchangeRate(v);
type.getCurrentContext().putType(rate);
Money gross = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("gross")));
Money fxGross = rate.convert(asCurrencyCode(v.get("termCurrency")), gross);
checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext());
})
// @formatter:off
// Vorgangs-Nr.: 184714818
// Transaction No.: 204751222
// @formatter:on
.section("note").optional()
.match("^(?<note>(Vorgangs\\-Nr|Transaction No)\\.: .*)$")
.assign((t, v) -> t.setNote(trim(v.get("note"))))
// @formatter:off
// Verhältnis: 1 : 1
// @formatter:on
.section("note").optional()
.match("^(?<note>Verh.ltnis: .*)$")
.assign((t, v) -> {
if (t.getNote() != null)
t.setNote(t.getNote() + " | " + trim(v.get("note")));
else
t.setNote(trim(v.get("note")));
})
// @formatter:off
// Spitzenregulierung KOPIE
// @formatter:on
.section("note").optional()
.match("^(?<note>Spitzenregulierung).*$")
.assign((t, v) -> {
if (t.getNote() != null)
t.setNote(t.getNote() + " | " + trim(v.get("note")));
else
t.setNote(trim(v.get("note")));
})
.wrap(BuySellEntryItem::new);
addTaxesSectionsTransaction(pdfTransaction, type);
addFeesSectionsTransaction(pdfTransaction, type);
}
private void addDividendeTransaction()
{
DocumentType type = new DocumentType("(Fondsaussch.ttung"
+ "|Ertragsthesaurierung"
+ "|Dividendenabrechnung"
+ "|Aussch.ttung aus"
+ "|Wahldividende"
+ "|Fund Distribution"
+ "|Dividende)");
this.addDocumentTyp(type);
Block block = new Block("^Ex\\-(Tag|Date): .*$");
type.addBlock(block);
Transaction<AccountTransaction> pdfTransaction = new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.DIVIDENDS);
return entry;
});
pdfTransaction
// @formatter:off
// If we have a positive amount and a gross reinvestment,
// there is a tax refund.
// If the amount is negative, then it is taxes.
// @formatter:on
.section("type", "sign").optional()
.match("^Nominale ISIN: .* (?<type>(Aussch.ttung|Thesaurierung brutto))$")
.match("^Zu (?<sign>(Gunsten|Lasten)) Konto [\\d]+ Valuta: [\\d]{2}\\.[\\d]{2}\\.[\\d]{4} [\\w]{3} [\\.,\\d]+$")
.assign((t, v) -> {
if ("Thesaurierung brutto".equals(v.get("type")) && "Gunsten".equals(v.get("sign")))
t.setType(AccountTransaction.Type.TAX_REFUND);
if ("Thesaurierung brutto".equals(v.get("type")) && "Lasten".equals(v.get("sign")))
t.setType(AccountTransaction.Type.TAXES);
})
// @formatter:off
// Dividendenabrechnung STORNO
//
// Fondsausschüttung KOPIE
// STORNO
// @formatter:on
.section("type").optional()
.match("^(Dividendenabrechnung )?(?<type>STORNO)$")
.assign((t, v) -> v.getTransactionContext().put(FAILURE, Messages.MsgErrorOrderCancellationUnsupported))
// @formatter:off
// Nominale ISIN: FR0000130577 WKN: 859386 Ausschüttung
// STK 57 Publicis Groupe S.A. EUR 2,00 p.STK
// Zahlungszeitraum: 17.06.2021 - 30.06.2021
// @formatter:on
.section("isin", "wkn", "name", "name1", "currency")
.match("^(Nominale|Quantity) ISIN: (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9]) WKN: (?<wkn>[A-Z0-9]{6}) .*$")
.match("^(STK|Units) [\\.,\\d]+ (?<name>.*) (?<currency>[\\w]{3}) .*$")
.match("^(?<name1>.*)$")
.assign((t, v) -> {
if (!v.get("name1").startsWith("Zahlungszeitraum")
&& !v.get("name1").startsWith("Payment")
&& !v.get("name1").startsWith("Bruttobetrag"))
v.put("name", v.get("name") + " " + v.get("name1"));
t.setSecurity(getOrCreateSecurity(v));
})
// @formatter:off
// STK 57 Publicis Groupe S.A. EUR 2,00 p.STK
// @formatter:on
.section("local", "shares")
.match("^(?<local>(STK|Units)) (?<shares>[\\.,\\d]+) .*$")
.assign((t, v) -> {
if ("Units".equals(v.get("local")))
t.setShares(asShares(v.get("shares"), "en", "US"));
else
t.setShares(asShares(v.get("shares")));
})
.oneOf(
// @formatter:off
// Zu Gunsten Konto 1111111111 Valuta: 06.07.2021 EUR 68,22
// @formatter:on
section -> section
.attributes("date")
.match("^Zu Gunsten Konto [\\d]+ Valuta: (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) [\\w]{3} [\\.,\\d]+$")
.assign((t, v) -> t.setDateTime(asDate(v.get("date"))))
,
// @formatter:off
// Amount credited to account 1209625007 Value: 2022-02-25 EUR 0.20
// @formatter:on
section -> section
.attributes("date")
.match("^Amount credited to account [\\d]+ Value: (?<date>[\\d]{4}\\-[\\d]{2}\\-[\\d]{2}) [\\w]{3} [\\.,\\d]+$")
.assign((t, v) -> t.setDateTime(asDate(v.get("date"))))
)
.oneOf(
// @formatter:off
// Zu Gunsten Konto 1111111111 Valuta: 06.07.2021 EUR 68,22
// @formatter:on
section -> section
.attributes("currency", "amount")
.match("^Zu Gunsten Konto [\\d]+ Valuta: [\\d]{2}\\.[\\d]{2}\\.[\\d]{4} (?<currency>[\\w]{3}) (?<amount>[\\.,\\d]+)$")
.assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
})
,
// @formatter:off
// Amount credited to account 1209625007 Value: 2022-02-25 EUR 0.20
// @formatter:on
section -> section
.attributes("currency", "amount")
.match("^Amount credited to account [\\d]+ Value: [\\d]{4}\\-[\\d]{2}\\-[\\d]{2} (?<currency>[\\w]{3}) (?<amount>[\\.,\\d]+)$")
.assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
})
)
// @formatter:off
// Umrechnungskurs: EUR/USD 1,1452
// Bruttobetrag USD 3,94
// Bruttobetrag EUR 3,44
// @formatter:on
.section("baseCurrency", "termCurrency", "exchangeRate", "fxGross", "fxCurrency", "gross", "currency").optional()
.match("^(Umrechnungskurs|Exchange Rate): (?<baseCurrency>[\\w]{3})\\/(?<termCurrency>[\\w]{3}) (?<exchangeRate>[\\.,\\d]+)$")
.match("^(Bruttobetrag|Gross Amount) (?<fxCurrency>[\\w]{3}) (?<fxGross>[\\.,\\d]+)$")
.match("^(Bruttobetrag|Gross Amount) (?<currency>[\\w]{3}) (?<gross>[\\.,\\d]+)$")
.assign((t, v) -> {
ExtrExchangeRate rate = asExchangeRate(v);
type.getCurrentContext().putType(rate);
Money gross = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("gross")));
Money fxGross = Money.of(asCurrencyCode(v.get("fxCurrency")), asAmount(v.get("fxGross")));
checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext());
})
// @formatter:off
// Vorgangs-Nr.: 184714818
// Transaction No.: 204751222
// @formatter:on
.section("note").optional()
.match("^(?<note>(Vorgangs\\-Nr|Transaction No)\\.: .*)$")
.assign((t, v) -> t.setNote(trim(v.get("note"))))
.wrap((t, ctx) -> {
// If we have multiple entries in the document, then
// the "noTax" flag must be removed.
type.getCurrentContext().remove("noTax");
TransactionItem item = new TransactionItem(t);
if (ctx.getString(FAILURE) != null)
item.setFailureMessage(ctx.getString(FAILURE));
return item;
});
addTaxesSectionsTransaction(pdfTransaction, type);
addFeesSectionsTransaction(pdfTransaction, type);
block.set(pdfTransaction);
}
private void addAdvanceTaxTransaction()
{
DocumentType type = new DocumentType("Vorabpauschale");
this.addDocumentTyp(type);
Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.TAXES);
return entry;
});
Block firstRelevantLine = new Block("^Ex\\-(Tag|Date): .*$");
type.addBlock(firstRelevantLine);
firstRelevantLine.set(pdfTransaction);
pdfTransaction
// @formatter:off
// Nominale ISIN: IE00BWBXM385 WKN: A14QBZ
// STK 112 SPDR S+P US Con.Sta.Sel.S.UETF
// @formatter:on
.section("isin", "wkn", "name", "name1")
.match("^Nominale ISIN: (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9]) WKN: (?<wkn>[A-Z0-9]{6})$")
.match("^STK [\\.,\\d]+ (?<name>.*)$")
.match("^(?<name1>.*)$")
.assign((t, v) -> {
if (!v.get("name1").startsWith("Zahlungszeitraum"))
v.put("name", v.get("name") + " " + v.get("name1"));
t.setSecurity(getOrCreateSecurity(v));
})
// @formatter:off
// STK 112 SPDR S+P US Con.Sta.Sel.S.UETF
// @formatter:on
.section("shares")
.match("^STK (?<shares>[\\.,\\d]+) .*$")
.assign((t, v) -> t.setShares(asShares(v.get("shares"))))
// @formatter:off
// Zu Lasten Konto 1247201005 Valuta: 04.01.2021 EUR 0,04
// @formatter:on
.section("date", "currency", "amount")
.match("^Zu Lasten Konto [\\d]+ Valuta: (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) (?<currency>[\\w]{3}) (?<amount>[\\.,\\d]+)$")
.assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
t.setDateTime(asDate(v.get("date")));
})
// @formatter:off
// Zahlungszeitraum: 01.01.2020 - 31.12.2020
// @formatter:on
.section("note").optional()
.match("^(?<note>Zahlungszeitraum: .*)$")
.assign((t, v) -> t.setNote(trim(v.get("note"))))
.wrap(TransactionItem::new);
}
private void addTaxAdjustmentTransaction()
{
DocumentType type = new DocumentType("Steuerausgleichsrechnung");
this.addDocumentTyp(type);
Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.TAX_REFUND);
return entry;
});
Block firstRelevantLine = new Block("^.*Seite 1\\/[\\d]$");
type.addBlock(firstRelevantLine);
firstRelevantLine.set(pdfTransaction);
pdfTransaction
// @formatter:off
// Unterschleißheim, 22.06.2017
// 26.06.2020
// @formatter:on
.section("date")
.match("^.*(?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4})$")
.assign((t, v) -> t.setDateTime(asDate(v.get("date"))))
// @formatter:off
// Erstattung EUR 9,01
// @formatter:on
.section("currency", "amount")
.match("^Erstattung (?<currency>[\\w]{3}) (?<amount>[\\.,\\d]+)$")
.assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
})
// @formatter:off
// Vorgangs-Nr.: 184714818
// Transaction No.: 204751222
// @formatter:on
.section("note").optional()
.match("^(?<note>(Vorgangs\\-Nr|Transaction No)\\.: .*)$")
.assign((t, v) -> t.setNote(trim(v.get("note"))))
// @formatter:off
// wir haben für Sie eine Steuerausgleichsrechnung durchgeführt, die der Optimierung der Steuerbelastung
// @formatter:on
.section("note").optional()
.match("^.* (?<note>Steuerausgleichsrechnung) .*$")
.assign((t, v) -> {
if (t.getNote() != null)
t.setNote(t.getNote() + " | " + trim(v.get("note")));
else
t.setNote(trim(v.get("note")));
})
.wrap(TransactionItem::new);
}
private void addDepotStatementTransaction()
{
final DocumentType type = new DocumentType("(Perioden\\-Kontoauszug|Tageskontoauszug|Periodic Account Statement)", (context, lines) -> {
Pattern pCurrency = Pattern.compile("(Perioden\\-Kontoauszug|Tageskontoauszug|Periodic Account Statement): (?<currency>[\\w]{3})(\\-Konto| Account)");
// read the current context here
for (String line : lines)
{
Matcher m = pCurrency.matcher(line);
if (m.matches())
context.put("currency", m.group("currency"));
}
});
this.addDocumentTyp(type);
// @formatter:off
// 12.04.2018 Lastschrift aktiv 12.04.2018 10.000,00
// 11.12.2020 Gutschrift 11.12.2020 20,00
// @formatter:on
Block depositBlock = new Block("^[\\d]{2}\\.[\\d]{2}\\.[\\d]{4} (Lastschrift aktiv|Gutschrift) [\\d]{2}\\.[\\d]{2}\\.[\\d]{4} [\\.,\\d]+$");
type.addBlock(depositBlock);
depositBlock.set(new Transaction<AccountTransaction>()
.subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.DEPOSIT);
return t;
})
.section("note", "date", "amount")
.match("^[\\d]{2}\\.[\\d]{2}\\.[\\d]{4} (?<note>(Lastschrift aktiv|Gutschrift)) (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) (?<amount>[\\.,\\d]+)$")
.assign((t, v) -> {
Map<String, String> context = type.getCurrentContext();
t.setDateTime(asDate(v.get("date")));
t.setCurrencyCode(asCurrencyCode(context.get("currency")));
t.setAmount(asAmount(v.get("amount")));
t.setNote(v.get("note"));
})
.wrap(TransactionItem::new));
// @formatter:off
// 2022-02-02 Credit SEPA 2022-02-02 1,000.00
// 2022-02-03 Direct Debit 2022-02-03 1.00
// @formatter:on
Block depositEnglishBlock = new Block("^[\\d]{4}\\-[\\d]{2}\\-[\\d]{2} (Credit SEPA|Direct Debit) [\\d]{4}\\-[\\d]{2}\\-[\\d]{2} [\\.,\\d]+$");
type.addBlock(depositEnglishBlock);
depositEnglishBlock.set(new Transaction<AccountTransaction>()
.subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.DEPOSIT);
return t;
})
.section("note", "date", "amount")
.match("^[\\d]{4}\\-[\\d]{2}\\-[\\d]{2} (?<note>(Credit SEPA|Direct Debit)) (?<date>[\\d]{4}\\-[\\d]{2}\\-[\\d]{2}) (?<amount>[\\.,\\d]+)$")
.assign((t, v) -> {
Map<String, String> context = type.getCurrentContext();
t.setDateTime(asDate(v.get("date")));
t.setCurrencyCode(asCurrencyCode(context.get("currency")));
t.setAmount(asAmount(v.get("amount")));
t.setNote(v.get("note"));
})
.wrap(TransactionItem::new));
// @formatter:off
// 12.04.2018 Lastschrift aktiv 12.04.2018 10.000,00
// 22.08.2018 SEPA-Ueberweisung 22.08.2018 2.000,00 -
// @formatter:on
Block removalBlock = new Block("^[\\d]{2}\\.[\\d]{2}\\.[\\d]{4} (Lastschrift aktiv|SEPA\\-Ueberweisung) [\\d]{2}\\.[\\d]{2}\\.[\\d]{4} [\\.,\\d]+ \\-$");
type.addBlock(removalBlock);
removalBlock.set(new Transaction<AccountTransaction>()
.subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.REMOVAL);
return t;
})
.section("note", "date", "amount")
.match("^[\\d]{2}\\.[\\d]{2}\\.[\\d]{4} (?<note>(Lastschrift aktiv|SEPA\\-Ueberweisung)) (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) (?<amount>[\\.,\\d]+) \\-$")
.assign((t, v) -> {
Map<String, String> context = type.getCurrentContext();
t.setDateTime(asDate(v.get("date")));
t.setCurrencyCode(asCurrencyCode(context.get("currency")));
t.setAmount(asAmount(v.get("amount")));
t.setNote(v.get("note"));
})
.wrap(TransactionItem::new));
// @formatter:off
// 06.07.2018 Transaktionskostenpauschale o. MwSt. 10.07.2018 2,56 -
// @formatter:on
Block feesBlock = new Block("^[\\d]{2}\\.[\\d]{2}\\.[\\d]{4} Transaktionskostenpauschale o\\. MwSt\\. [\\d]{2}\\.[\\d]{2}\\.[\\d]{4} [\\.,\\d]+ \\-$");
type.addBlock(feesBlock);
feesBlock.set(new Transaction<AccountTransaction>()
.subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.FEES);
return t;
})
.section("note", "date", "amount")
.match("^[\\d]{2}\\.[\\d]{2}\\.[\\d]{4} (?<note>Transaktionskostenpauschale o\\. MwSt\\.) (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) (?<amount>[\\.,\\d]+) \\-$")
.assign((t, v) -> {
Map<String, String> context = type.getCurrentContext();
t.setDateTime(asDate(v.get("date")));
t.setCurrencyCode(asCurrencyCode(context.get("currency")));
t.setAmount(asAmount(v.get("amount")));
t.setNote(v.get("note"));
})
.wrap(TransactionItem::new));
// @formatter:off
// 2022-05-03 Ordergebühr 2022-05-03 0.99 -
// @formatter:on
Block feesEnglishBlock = new Block("^[\\d]{4}\\-[\\d]{2}\\-[\\d]{2} Ordergeb.hr [\\d]{4}\\-[\\d]{2}\\-[\\d]{2} [\\.,\\d]+ \\-$");
type.addBlock(feesEnglishBlock);
feesEnglishBlock.set(new Transaction<AccountTransaction>()
.subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.FEES);
return t;
})
.section("note", "date", "amount")
.match("^[\\d]{4}\\-[\\d]{2}\\-[\\d]{2} (?<note>Ordergeb.hr) (?<date>[\\d]{4}\\-[\\d]{2}\\-[\\d]{2}) (?<amount>[\\.,\\d]+) \\-$")
.assign((t, v) -> {
Map<String, String> context = type.getCurrentContext();
t.setDateTime(asDate(v.get("date")));
t.setCurrencyCode(asCurrencyCode(context.get("currency")));
t.setAmount(asAmount(v.get("amount")));
t.setNote(v.get("note"));
})
.wrap(TransactionItem::new));
}
private void addFeesAssetManagerTransaction()
{
DocumentType type = new DocumentType("Verg.tung des Verm.gensverwalters");
this.addDocumentTyp(type);
Block block = new Block("^Rechnung f.r .*$");
type.addBlock(block);
Transaction<AccountTransaction> pdfTransaction = new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.FEES);
return entry;
});
pdfTransaction
// @formatter:off
// Leistungen Beträge (EUR)
// Rechnungsbetrag 6,48
// @formatter:on
.section("currency", "amount")
.match("^Leistungen Betr.ge \\((?<currency>[\\w]{3})\\)$")
.match("^Rechnungsbetrag *(?<amount>[\\.,\\d]+)$")
.assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
})
// @formatter:off
// Abbuchungsdatum: 02.08.2017
// @formatter:on
.section("date")
.match("^Abbuchungsdatum: (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4})$")
.assign((t, v) -> t.setDateTime(asDate(v.get("date"))))
// @formatter:off
// Abrechnungszeitraum 01.07.2017 - 31.07.2017
// @formatter:on
.section("note").optional()
.match("^(?<note>Abrechnungszeitraum .*)$")
.assign((t, v) -> t.setNote(trim(v.get("note"))))
.wrap(TransactionItem::new);
block.set(pdfTransaction);
}
private void addDeliveryInOutBoundTransaction()
{
DocumentType type = new DocumentType("Kapitalerh.hung gegen Bareinzahlung");
this.addDocumentTyp(type);
Transaction<PortfolioTransaction> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
PortfolioTransaction entry = new PortfolioTransaction();
entry.setType(PortfolioTransaction.Type.DELIVERY_OUTBOUND);
return entry;
});
Block firstRelevantLine = new Block("^(Einbuchung in Depot|Ausbuchung aus Depot) .* per [\\d]{2}\\.[\\d]{2}\\.[\\d]{4}$");
type.addBlock(firstRelevantLine);
firstRelevantLine.set(pdfTransaction);
pdfTransaction
// Is type --> "Einbuchung" change from DELIVERY_OUTBOUND to DELIVERY_INBOUND
.section("type").optional()
.match("^(?<type>Einbuchung) in Depot .* per [\\d]{2}\\.[\\d]{2}\\.[\\d]{4}$")
.assign((t, v) -> {
if ("Einbuchung".equals(v.get("type")))
t.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
})
.oneOf(
// @formatter:off
// Ausbuchung aus Depot yyyyyyyyyy per 09.03.2021
// Nominale ISIN: DE000A3H3MF2 WKN: A3H3MF
// STK 96 Enapter AG
// Inhaber-Bezugsrechte
// @formatter:on
section -> section
.attributes("isin", "wkn", "name", "nameContinued")
.find(".*Ausbuchung aus Depot .* per [\\d]{2}\\.[\\d]{2}\\.[\\d]{4}.*")
.match("^Nominale ISIN: (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9]) WKN: (?<wkn>[A-Z0-9]{6}).*$")
.match("^STK [\\.,\\d]+ (?<name>.*)$")
.match("^(?<nameContinued>.*)$")
.assign((t, v) -> {
t.setSecurity(getOrCreateSecurity(v));
t.setCurrencyCode(asCurrencyCode(t.getSecurity().getCurrencyCode()));
t.setAmount(0L);
})
,
// @formatter:off
// Einbuchung in Depot yyyyyyyyyy per 09.03.2021
// Nominale ISIN: DE000A3H3MG0 WKN: A3H3MG Bezugspreis:
// STK 6 Enapter AG EUR 22,00 p.STK
// junge Inhaber-Aktien o.N.
// @formatter:on
section -> section
.attributes("isin", "wkn", "name", "currency", "nameContinued")
.find(".*Einbuchung in Depot .* per [\\d]{2}\\.[\\d]{2}\\.[\\d]{4}.*")
.match("^Nominale ISIN: (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9]) WKN: (?<wkn>[A-Z0-9]{6}).*$")
.match("^STK [\\.,\\d]+ (?<name>.*) (?<currency>[\\w]{3}) [\\.,\\d]+ .*$")
.match("^(?<nameContinued>.*)$")
.assign((t, v) -> t.setSecurity(getOrCreateSecurity(v)))
)
// @formatter:off
// STK 96 Enapter AG
// @formatter:on
.section("shares")
.match("^STK (?<shares>[\\.,\\d]+) .*$")
.assign((t, v) -> t.setShares(asShares(v.get("shares"))))
// @formatter:off
// Einbuchung in Depot yyyyyyyyyy per 09.03.2021
// Ausbuchung aus Depot yyyyyyyyyy per 09.03.2021
// @formatter:on
.section("date")
.match("^(Einbuchung|Ausbuchung) .* per (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4})$")
.assign((t, v) -> t.setDateTime(asDate(v.get("date"))))
// @formatter:off
// Bezugspreis EUR 132,00
// Bruttobetrag EUR 1.012,00
// @formatter:on
.section("currency", "amount").optional()
.match("^(Bezugspreis|Bruttobetrag) (?<currency>[\\w]{3}) (?<amount>[\\.,\\d]+)$")
.assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
})
// @formatter:off
// Bezugsverhältnis: 16 : 1
// @formatter:on
.section("note").optional()
.match("^(?<note>Bezugsverh.ltnis: .*)$")
.assign((t, v) -> t.setNote(trim(v.get("note"))))
.wrap(TransactionItem::new);
}
private void addTransferOutTransaction()
{
DocumentType type = new DocumentType("Ablauf der Optionsfrist");
this.addDocumentTyp(type);
Transaction<BuySellEntry> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.SELL);
return entry;
});
Block firstRelevantLine = new Block("^Referenz\\-Nr\\.: .*$");
type.addBlock(firstRelevantLine);
firstRelevantLine.set(pdfTransaction);
pdfTransaction
// @formatter:off
// Nominale ISIN: DE000HB2KBG9 WKN: HB2KBG Barabfindung
// STK 6 UniCredit Bank AG EUR 10,00 p.STK
// HVB Inline 18.05.22 BASF 45-70
// @formatter:on
.section("isin", "wkn", "name", "nameContinued", "currency")
.match("^Nominale ISIN: (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9]) WKN: (?<wkn>[A-Z0-9]{6}) Barabfindung$")
.match("^STK [\\.,\\d]+ (?<name>.*) (?<currency>[\\w]{3}) .*$")
.match("^(?<nameContinued>.*)$")
.assign((t, v) -> {
if (v.get("nameContinued").endsWith("p.STK"))
v.put("nameContinued", v.get("nameContinued").replace("p.STK", ""));
t.setSecurity(getOrCreateSecurity(v));
})
// @formatter:off
// STK 6 UniCredit Bank AG EUR 10,00 p.STK
// @formatter:on
.section("shares")
.match("^STK (?<shares>[\\.,\\d]+) .*$")
.assign((t, v) -> t.setShares(asShares(v.get("shares"))))
// @formatter:off
// Ausbuchung aus Depot 1234567001 per 25.05.2022
// @formatter:on
.section("date")
.match("^Ausbuchung .* per (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4})$")
.assign((t, v) -> t.setDate(asDate(v.get("date"))))
// @formatter:off
// Zu Gunsten Konto 1234567005 Valuta: 25.05.2022 EUR 60,00
// @formatter:on
.section("date", "currency", "amount")
.match("^Zu Gunsten Konto [\\d]+ Valuta: (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) (?<currency>[\\w]{3}) (?<amount>[\\.,\\d]+)$")
.assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
})
// @formatter:off
// Ablauf der Optionsfrist
// @formatter:on
.section("note").optional()
.match("^(?<note>Ablauf der Optionsfrist)$")
.assign((t, v) -> t.setNote(trim(v.get("note"))))
.wrap(BuySellEntryItem::new);
addTaxesSectionsTransaction(pdfTransaction, type);
addFeesSectionsTransaction(pdfTransaction, type);
}
private <T extends Transaction<?>> void addTaxesSectionsTransaction(T transaction, DocumentType type)
{
// If we have a gross reinvestment,
// we set a flag and don't book tax below.
transaction
.section("n").optional()
.match("^Ertragsthesaurierung .*$")
.match("Steuerliquidit.t (?<n>.*)")
.assign((t, v) -> type.getCurrentContext().put("noTax", "X"));
transaction
// @formatter:off
// Span. Finanztransaktionssteuer EUR 1,97
// @formatter:on
.section("tax", "currency").optional()
.match("^.* Finanztransaktionssteuer (?<currency>[\\w]{3}) (?<tax>[\\.,\\d]+)$")
.assign((t, v) -> {
if (!"X".equals(type.getCurrentContext().get("noTax")))
processTaxEntries(t, v, type);
})
// @formatter:off
// Kapitalertragsteuer EUR 127,73 -
// @formatter:on
.section("tax", "currency").optional()
.match("^Kapitalertragsteuer (?<currency>[\\w]{3}) (?<tax>[\\.,\\d]+) \\-$")
.assign((t, v) -> {
if (!"X".equals(type.getCurrentContext().get("noTax")))
processTaxEntries(t, v, type);
})
// @formatter:off
// Kirchensteuer EUR 11,49 -
// @formatter:on
.section("tax", "currency").optional()
.match("^Kirchensteuer (?<currency>[\\w]{3}) (?<tax>[\\.,\\d]+) \\-$")
.assign((t, v) -> {
if (!"X".equals(type.getCurrentContext().get("noTax")))
processTaxEntries(t, v, type);
})
// @formatter:off
// Solidaritätszuschlag EUR 7,02 -
// @formatter:on
.section("tax", "currency").optional()
.match("^Solidarit.tszuschlag (?<currency>[\\w]{3}) (?<tax>[\\.,\\d]+) \\-$")
.assign((t, v) -> {
if (!"X".equals(type.getCurrentContext().get("noTax")))
processTaxEntries(t, v, type);
})
// @formatter:off
// Quellensteuer EUR 30,21 -
// US-Quellensteuer EUR 0,17 -
// @formatter:on
.section("withHoldingTax", "currency").optional()
.match("^(US-)?Quellensteuer (?<currency>[\\w]{3}) (?<withHoldingTax>[\\.,\\d]+) \\-$")
.assign((t, v) -> {
if (!"X".equals(type.getCurrentContext().get("noTax")))
processWithHoldingTaxEntries(t, v, "withHoldingTax", type);
});
}
private <T extends Transaction<?>> void addFeesSectionsTransaction(T transaction, DocumentType type)
{
transaction
// @formatter:off
// Provision EUR 0,21
// Provision EUR 0,08 -
// @formatter:on
.section("currency", "fee").optional()
.match("^Provision (?<currency>[\\w]{3}) (?<fee>[\\.,\\d]+)( \\-)?$")
.assign((t, v) -> processFeeEntries(t, v, type))
// @formatter:off
// Gebühren extern ADR EUR 2,00
// @formatter:on
.section("currency", "fee").optional()
.match("^Geb.hren extern ADR (?<currency>[\\w]{3}) (?<fee>[\\.,\\d]+)( \\-)?$")
.assign((t, v) -> processFeeEntries(t, v, type))
// @formatter:off
// Mindermengenzuschlag Finanzen.net EUR 1,00
// @formatter:on
.section("currency", "fee").optional()
.match("^Mindermengenzuschlag .* (?<currency>[\\w]{3}) (?<fee>[\\.,\\d]+)( \\-)?$")
.assign((t, v) -> processFeeEntries(t, v, type));
}
@Override
protected long asAmount(String value)
{
String language = "de"; //$NON-NLS-1$
String country = "DE"; //$NON-NLS-1$
int lastDot = value.lastIndexOf("."); //$NON-NLS-1$
int lastComma = value.lastIndexOf(","); //$NON-NLS-1$
// returns the greater of two int values
if (Math.max(lastDot, lastComma) == lastDot)