/
PostbankPDFExtractor.java
835 lines (731 loc) · 50.5 KB
/
PostbankPDFExtractor.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
package name.abuchen.portfolio.datatransfer.pdf;
import static name.abuchen.portfolio.datatransfer.ExtractorUtils.checkAndSetFee;
import static name.abuchen.portfolio.datatransfer.ExtractorUtils.checkAndSetGrossUnit;
import static name.abuchen.portfolio.util.TextUtil.concatenate;
import static name.abuchen.portfolio.util.TextUtil.trim;
import java.math.BigDecimal;
import java.util.function.BiConsumer;
import java.util.regex.Pattern;
import name.abuchen.portfolio.datatransfer.DocumentContext;
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 PostbankPDFExtractor extends AbstractPDFExtractor
{
private static final String IS_JOINT_ACCOUNT = "isJointAccount";
BiConsumer<DocumentContext, String[]> jointAccount = (context, lines) -> {
Pattern pJointAccount = Pattern.compile("Anteilige Berechnungsgrundlage .* \\([\\d]{2},[\\d]{2} %\\).*");
for (String line : lines)
{
if (pJointAccount.matcher(line).matches())
{
context.putBoolean(IS_JOINT_ACCOUNT, true);
break;
}
}
};
public PostbankPDFExtractor(Client client)
{
super(client);
addBankIdentifier("Postbank");
addBuySellTransaction();
addDividendeTransaction();
addAdvanceTaxTransaction();
addDepotStatementTransaction();
}
@Override
public String getLabel()
{
return "Deutsche Postbank AG";
}
private void addBuySellTransaction()
{
DocumentType type = new DocumentType("(Wertpapier )?Abrechnung(:)? "//
+ "(Kauf"
+ "|Kauf von Wertpapieren" //
+ "|Verkauf" //
+ "|Verkauf\\-Festpreisgesch.ft" //
+ "|Ausgabe Investmentfonds" //
+ "|R.cknahme Investmentfonds)", jointAccount);
this.addDocumentTyp(type);
Transaction<BuySellEntry> pdfTransaction = new Transaction<>();
Block firstRelevantLine = new Block("^Postbank(?! \\- ).*$");
type.addBlock(firstRelevantLine);
firstRelevantLine.set(pdfTransaction);
pdfTransaction //
.subject(() -> {
BuySellEntry portfolioTransaction = new BuySellEntry();
portfolioTransaction.setType(PortfolioTransaction.Type.BUY);
return portfolioTransaction;
})
// Is type --> "Verkauf" change from BUY to SELL
.section("type").optional() //
.match("^Wertpapier Abrechnung (?<type>(Kauf|Verkauf|Ausgabe Investmentfonds|R.cknahme Investmentfonds)).*$") //
.assign((t, v) -> {
if ("Verkauf".equals(v.get("type")) || "Rücknahme Investmentfonds".equals(v.get("type")))
t.setType(PortfolioTransaction.Type.SELL);
})
.oneOf( //
// @formatter:off
// Stück 158 XTR.(IE) - MSCI WORLD IE00BJ0KDQ92 (A1XB5U)
// REGISTERED SHARES 1C O.N.
// Ausführungskurs 62,821 EUR
// @formatter:on
section -> section //
.attributes("name", "isin", "wkn", "name1", "currency") //
.match("^St.ck [\\.,\\d]+ (?<name>.*) (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9]) \\((?<wkn>[A-Z0-9]{6})\\)$") //
.match("^(?<name1>.*)$") //
.match("^(Ausf.hrungskurs|Abrech\\.\\-Preis) [\\.,\\d]+ (?<currency>[\\w]{3})$") //
.assign((t, v) -> {
if (!v.get("name1").startsWith("Handels-/Ausführungsplatz"))
v.put("name", trim(v.get("name")) + " " + trim(v.get("name1")));
t.setSecurity(getOrCreateSecurity(v));
}),
// @formatter:off
// 123 4567890 00 DWS ESG TOP ASIEN INHABER-ANTEILE LC 1/1
// WKN 976976 Nominal ST 88
// ISIN DE0009769760 Kurs EUR 196,05
// @formatter:on
section -> section //
.attributes("name", "wkn", "isin", "currency") //
.match("^[\\d]{3} [\\d]+ [\\d]+ (?<name>.*) [\\d]\\/[\\d]$") //
.match("^WKN (?<wkn>[A-Z0-9]{6}) .*$") //
.match("^ISIN (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9]) Kurs (?<currency>[\\w]{3}) [\\.,\\d]+$") //
.assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))))
.oneOf( //
// @formatter:off
// Stück 158 XTR.(IE) - MSCI WORLD IE00BJ0KDQ92 (A1XB5U)
// @formatter:on
section -> section //
.attributes("notation", "shares") //
.match("^(?<notation>(St.ck|[\\w]{3})) (?<shares>[\\.,\\d]+) .* [A-Z]{2}[A-Z0-9]{9}[0-9] \\([A-Z0-9]{6}\\)$") //
.assign((t, v) -> {
// Percentage quotation, workaround for bonds
if (v.get("notation") != null && !"Stück".equalsIgnoreCase(v.get("notation")))
{
BigDecimal shares = asBigDecimal(v.get("shares"));
t.setShares(Values.Share.factorize(shares.doubleValue() / 100));
}
else
{
t.setShares(asShares(v.get("shares")));
}
}),
// @formatter:off
// WKN 976976 Nominal ST 88
// @formatter:on
section -> section //
.attributes("shares") //
.match("^WKN [A-Z0-9]{6} .* ST (?<shares>[\\.,\\d]+)$") //
.assign((t, v) -> t.setShares(asShares(v.get("shares")))))
.oneOf( //
// @formatter:off
// Belegnummer 1481234555 / 987123 Schlusstag 24.07.2023
// @formatter:on
section -> section //
.attributes("date") //
.match("^.*Schlusstag (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4})$") //
.assign((t, v) -> t.setDate(asDate(v.get("date")))),
// @formatter:off
// Schlusstag/-Zeit 04.02.2020 08:00:04
// @formatter:on
section -> section //
.attributes("date", "time") //
.match("^Schlusstag\\/\\-Zeit (?<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
// Den Gegenwert buchen wir mit Valuta 14.01.2020 zu Gunsten des Kontos 012345678
// @formatter:on
section -> section //
.attributes("date") //
.match("^Den Gegenwert buchen wir mit Valuta ([\\s]+)?(?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) .*$") //
.assign((t, v) -> t.setDate(asDate(v.get("date")))))
.oneOf(
// @formatter:off
// Ausmachender Betrag 9.978,18- EUR
// @formatter:on
section -> section //
.attributes("amount", "currency") //
.match("^Ausmachender Betrag (?<amount>[\\.,\\d]+)(\\-)? (?<currency>[\\w]{3})$") //
.assign((t, v) -> {
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}),
// @formatter:off
// Buchung auf Kontonummer 4567890 00 mit Wertstellung 26.07.2023 EUR 17.169,09
// @formatter:on
section -> section //
.attributes("currency", "amount") //
.match("^Buchung auf Kontonummer [\\s\\d]+ mit Wertstellung [\\d]{2}\\.[\\d]{2}\\.[\\d]{4} (?<currency>[\\w]{3}) (?<amount>[\\.,\\d]+)$") //
.assign((t, v) -> {
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}))
// @formatter:off
// Abrech.-Preis 196,00 USD
// Devisenkurs (EUR/USD) 1,06386 vom 12.12.2016
// Kurswert 1.289,64 EUR
// @formatter:on
.section("baseCurrency", "termCurrency", "exchangeRate", "gross").optional() //
.match("^Devisenkurs \\((?<baseCurrency>[\\w]{3})\\/(?<termCurrency>[\\w]{3})\\) (?<exchangeRate>[\\.,\\d]+) .*$") //
.match("^Kurswert (?<gross>[\\.,\\d]+)(\\-)? [\\w]{3}$") //
.assign((t, v) -> {
ExtrExchangeRate rate = asExchangeRate(v);
type.getCurrentContext().putType(rate);
Money gross = Money.of(rate.getBaseCurrency(), asAmount(v.get("gross")));
Money fxGross = rate.convert(rate.getTermCurrency(), gross);
checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext());
})
.optionalOneOf( //
// @formatter:off
// Auftragsnummer 69123/22.01
// @formatter:on
section -> section
.attributes("note")
.match("^.*(?<note>Auftragsnummer [\\d]+\\/[\\.\\d]+)$") //
.assign((t, v) -> t.setNote(trim(v.get("note")))),
// @formatter:off
// Belegnummer 1481234555 / 987123 Schlusstag 24.07.2023
// @formatter:on
section -> section
.attributes("note")
.match("^(?<note>Belegnummer [\\d]+([\\s])?\\/([\\s])?[\\d]+).*$") //
.assign((t, v) -> t.setNote(trim(v.get("note")))))
// @formatter:off
// Limit 43,00 EUR
// @formatter:on
.section("note").optional() //
.match("^(?<note>Limit .*)$") //
.assign((t, v) -> t.setNote(concatenate(t.getNote(), trim(v.get("note")), " | ")))
// @formatter:off
// Barabfindung wegen Fusion
// @formatter:on
.section("note").optional() //
.match("^(?<note>Barabfindung wegen .*)$") //
.assign((t, v) -> t.setNote(concatenate(t.getNote(), trim(v.get("note")), " | ")))
.conclude(ExtractorUtils.fixGrossValueBuySell())
.wrap(BuySellEntryItem::new);
addTaxesSectionsTransaction(pdfTransaction, type);
addFeesSectionsTransaction(pdfTransaction, type);
}
private void addDividendeTransaction()
{
DocumentType type = new DocumentType("(Dividendengutschrift" //
+ "|Aussch.ttung Investmentfonds" //
+ "|Gutschrift von Investmentertr.gen" //
+ "|Ertragsgutschrift" //
+ "|Zinsgutschrift" //
+ "|Kupongutschrift)", jointAccount);
this.addDocumentTyp(type);
Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
Block firstRelevantLine = new Block("^Postbank(?! \\- ).*$");
type.addBlock(firstRelevantLine);
firstRelevantLine.set(pdfTransaction);
pdfTransaction //
.subject(() -> {
AccountTransaction accountTransaction = new AccountTransaction();
accountTransaction.setType(AccountTransaction.Type.DIVIDENDS);
return accountTransaction;
})
.oneOf( //
// @formatter:off
// Stück 12 JOHNSON & JOHNSON SHARES US4781601046 (853260)
// REGISTERED SHARES DL 1
// Zahlbarkeitstag 14.01.2022 Ausschüttung pro St. 1,390000000 USD
// @formatter:on
section -> section //
.attributes("name", "isin", "wkn", "name1", "currency") //
.match("^St.ck [\\.,\\d]+ (?<name>.*) (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9]) \\((?<wkn>[A-Z0-9]{6})\\)$") //
.match("(?<name1>.*)") //
.match("^.* (Aussch.ttung|Dividende|Ertrag) ([\\s]+)?pro (St\\.|St.ck) [\\.,\\d]+ (?<currency>[\\w]{3})$") //
.assign((t, v) -> {
if (!v.get("name1").startsWith("Zahlbarkeitstag"))
v.put("name", trim(v.get("name")) + " " + trim(v.get("name1")));
t.setSecurity(getOrCreateSecurity(v));
}),
// @formatter:off
// EUR 15.000,00 ENEL FINANCE INTL N.V. XS0177089298 (908043)
// EO-MEDIUM-TERM NOTES 2003(23)
// @formatter:on
section -> section //
.attributes("currency", "name", "isin", "wkn", "name1") //
.match("^(?<currency>[\\w]{3}) [\\.,\\d]+ (?<name>.*) (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9]) \\((?<wkn>[A-Z0-9]{6})\\)$") //
.match("(?<name1>.*)") //
.assign((t, v) -> {
if (!v.get("name1").startsWith("Zahlbarkeitstag"))
v.put("name", trim(v.get("name")) + " " + trim(v.get("name1")));
t.setSecurity(getOrCreateSecurity(v));
}),
// @formatter:off
// 16.000,000000 EUR A0JCCZ XS1014610254
// 2,625% VOLKSWAGEN LEASING MTN.V.14 15.1. 24
// @formatter:on
section -> section //
.attributes("currency", "wkn", "isin", "name") //
.match("^[\\.,\\d]+ (?<currency>[\\w]{3}) (?<wkn>[A-Z0-9]{6}) (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9])$") //
.match("^(?<name>.*)$") //
.assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))))
.oneOf( //
// @formatter:off
// Stück 12 JOHNSON & JOHNSON SHARES
// US4781601046 (853260)
// @formatter:on
section -> section //
.attributes("shares") //
.match("^St.ck (?<shares>[\\.,\\d]+) .* [A-Z]{2}[A-Z0-9]{9}[0-9] \\([A-Z0-9]{6}\\)$") //
.assign((t, v) -> t.setShares(asShares(v.get("shares")))),
// @formatter:off
// EUR 15.000,00 ENEL FINANCE INTL N.V.
// XS0177089298 (908043)
section -> section //
.attributes("shares") //
.match("^[\\w]{3} (?<shares>[\\.,\\d]+) .* [A-Z]{2}[A-Z0-9]{9}[0-9] \\([A-Z0-9]{6}\\)$") //
.assign((t, v) -> {
// @formatter:off
// Percentage quotation, workaround for bonds
// @formatter:on
BigDecimal shares = asBigDecimal(v.get("shares"));
t.setShares(Values.Share.factorize(shares.doubleValue() / 100));
}),
// @formatter:off
// 16.000,000000 EUR A0JCCZ XS1014610254
// @formatter:on
section -> section //
.attributes("shares") //
.match("^(?<shares>[\\.,\\d]+) [\\w]{3} [A-Z0-9]{6} [A-Z]{2}[A-Z0-9]{9}[0-9]$") //
.assign((t, v) -> {
// @formatter:off
// Percentage quotation, workaround for bonds
// @formatter:on
BigDecimal shares = asBigDecimal(v.get("shares"));
t.setShares(Values.Share.factorize(shares.doubleValue() / 100));
}))
.oneOf( //
// @formatter:off
// Zahlbarkeitstag 08.04.2021 Ertrag pro Stück 0,60 EUR
// @formatter:on
section -> section //
.attributes("date") //
.match("^Zahlbarkeitstag (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) .*$") //
.assign((t, v) -> t.setDateTime(asDate(v.get("date")))),
// @formatter:off
// Gutschrift mit Wert 16.01.2023 309,23 EUR
// @formatter:on
section -> section //
.attributes("date") //
.match("^Gutschrift mit Wert (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}) .*$") //
.assign((t, v) -> t.setDateTime(asDate(v.get("date")))))
.oneOf( //
// @formatter:off
// Ausmachender Betrag 8,64+ EUR
// @formatter:on
section -> section //
.attributes("amount", "currency") //
.match("^Ausmachender Betrag (?<amount>[\\.,\\d]+)\\+ (?<currency>\\w{3})$") //
.assign((t, v) -> {
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}),
// @formatter:off
// Wir überweisen den Betrag von 309,23 EUR auf Ihr Konto 2222222 00.
// @formatter:on
section -> section //
.attributes("amount", "currency") //
.match("^Wir überweisen den Betrag von (?<amount>[\\.,\\d]+) (?<currency>\\w{3}) .*$") //
.assign((t, v) -> {
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}))
.optionalOneOf( //
// @formatter:off
// Devisenkurs EUR / USD 1,1920
// Dividendengutschrift 12,12 USD 10,17+ EUR
//
// Devisenkurs EUR / USD 0,9997
// Zinsertrag 166,25 USD 166,30+ EUR
// @formatter:on
section -> section //
.attributes("baseCurrency", "termCurrency", "exchangeRate", "fxGross", "gross") //
.match("^Devisenkurs (?<baseCurrency>[\\w]{3}) \\/ (?<termCurrency>[\\w]{3}) ([\\s]+)?(?<exchangeRate>[\\.,\\d]+).*$") //
.match("^(Dividendengutschrift|Aussch.ttung|Zinsertrag) (?<fxGross>[\\.,\\d]+) [\\w]{3} (?<gross>[\\.,\\d]+)\\+ [\\w]{3}.*$") //
.assign((t, v) -> {
ExtrExchangeRate rate = asExchangeRate(v);
type.getCurrentContext().putType(rate);
Money gross = Money.of(rate.getBaseCurrency(), asAmount(v.get("gross")));
Money fxGross = Money.of(rate.getTermCurrency(), asAmount(v.get("fxGross")));
checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext());
}),
// @formatter:off
// Bruttoertrag 312,50 USD 285,83 EUR
// Umrechnungskurs USD zu EUR 1,0933000000
// @formatter:on
section -> section //
.attributes("baseCurrency", "termCurrency", "exchangeRate", "fxGross", "gross") //
.match("^Bruttoertrag (?<fxGross>[\\.,\\d]+) [\\w]{3} (?<gross>[\\.,\\d]+) [\\w]{3}$") //
.match("^Umrechnungskurs (?<termCurrency>[\\w]{3}) zu (?<baseCurrency>[\\w]{3}) (?<exchangeRate>[\\.,\\d]+)$") //
.assign((t, v) -> {
ExtrExchangeRate rate = asExchangeRate(v);
type.getCurrentContext().putType(rate);
Money gross = Money.of(rate.getBaseCurrency(), asAmount(v.get("gross")));
Money fxGross = Money.of(rate.getTermCurrency(), asAmount(v.get("fxGross")));
checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext());
}))
// @formatter:off
// Abrechnungsnr. 12345678999
// @formatter:on
.section("note").optional() //
.match("^.*(?<note>Abrechnungsnr.*)$") //
.assign((t, v) -> t.setNote(trim(v.get("note"))))
.optionalOneOf( //
// @formatter:off
// Devisenkurs EUR / USD 1,1920
// Dividendengutschrift 12,12 USD 10,17+ EUR
//
// Devisenkurs EUR / USD 0,9997
// Zinsertrag 166,25 USD 166,30+ EUR
// @formatter:on
section -> section //
.attributes("note") //
.match("^.* Art der Dividende (?<note>.*)$") //
.assign((t, v) -> t.setNote(concatenate(t.getNote(), trim(v.get("note")), " | "))),
// @formatter:off
// Bruttoertrag 312,50 USD 285,83 EUR
// Umrechnungskurs USD zu EUR 1,0933000000
// @formatter:on
section -> section //
.attributes("note") //
.match("^.* (?<note>Zinsschein .*)$") //
.assign((t, v) -> t.setNote(concatenate(t.getNote(), trim(v.get("note")), " | "))))
.conclude(ExtractorUtils.fixGrossValueA())
.wrap(TransactionItem::new);
addTaxesSectionsTransaction(pdfTransaction, type);
addFeesSectionsTransaction(pdfTransaction, type);
}
private void addAdvanceTaxTransaction()
{
DocumentType type = new DocumentType("Vorabpauschale");
this.addDocumentTyp(type);
Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
Block firstRelevantLine = new Block("^Postbank(?! \\- ).*$");
type.addBlock(firstRelevantLine);
firstRelevantLine.set(pdfTransaction);
pdfTransaction //
.subject(() -> {
AccountTransaction accountTransaction = new AccountTransaction();
accountTransaction.setType(AccountTransaction.Type.TAXES);
return accountTransaction;
})
// @formatter:off
// Stück WKN ISIN
// 88,000000 976976 DE0009769760
// DWS ESG TOP ASIEN INHABER-ANTEILE LC
// Vorabpauschale Jahreswert (p.St.) 3,2556615000 EUR Kalenderjahr 2023
// @formatter:on
.section("wkn", "isin", "name", "currency") //
.find("St.ck WKN ISIN")
.match("^[\\.,\\d]+ (?<wkn>[A-Z0-9]{6}) (?<isin>[A-Z]{2}[A-Z0-9]{9}[0-9])$") //
.match("(?<name>.*)") //
.match("^Vorabpauschale Jahreswert .* [\\.,\\d]+ (?<currency>[\\w]{3}).*$") //
.assign((t, v) -> t.setSecurity(getOrCreateSecurity(v)))
// @formatter:off
// Stück WKN ISIN
// 88,000000 976976 DE0009769760
// @formatter:on
.section("shares") //
.find("St.ck WKN ISIN")
.match("^(?<shares>[\\.,\\d]+) [A-Z0-9]{6} [A-Z]{2}[A-Z0-9]{9}[0-9]$") //
.assign((t, v) -> t.setShares(asShares(v.get("shares"))))
// @formatter:off
// Belastung mit Wert 02.01.2024 26,41 EUR
// @formatter:on
.section("date") //
.match("^Belastung mit Wert (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}).*$") //
.assign((t, v) -> t.setDateTime(asDate(v.get("date"))))
// @formatter:off
// Belastung mit Wert 02.01.2024 26,41 EUR
// @formatter:on
.section("currency", "amount") //
.match("^Belastung mit Wert [\\d]{2}\\.[\\d]{2}\\.[\\d]{4} (?<amount>[\\.,\\d]+) (?<currency>[\\w]{3})$") //
.assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
})
.wrap(TransactionItem::new);
}
private void addDepotStatementTransaction()
{
var currencyAndYear = "^[\\d]{3} (?<year>[\\d]{4}) [\\d] [\\d]+ [A-Z]{2}(?:[\\s]?[0-9]){18,20} (?<baseCurrency>[\\w]{3}) ([\\-|\\+])? [\\.,\\d]+$";
final DocumentType type = new DocumentType("Kontoauszug", new Block(currencyAndYear)
.asRange(section -> section.attributes("baseCurrency", "year").match(currencyAndYear)));
this.addDocumentTyp(type);
// @formatter:off
// 01.08./01.08. D Gut SEPA + 2,70
// 01.08./01.08. Gutschr.SEPA + 600,00
// @formatter:on
Block depositBlock = new Block("^[\\d]{2}\\.[\\d]{2}\\.\\/[\\d]{2}\\.[\\d]{2}\\. (D Gut SEPA|Gutschr\\.SEPA) \\+ [\\.,\\d]+$");
type.addBlock(depositBlock);
depositBlock.set(new Transaction<AccountTransaction>()
.subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.DEPOSIT);
return t;
})
.section("date", "note", "amount").optional() //
.documentRange("baseCurrency", "year") //
.match("^(?<date>[\\d]{2}\\.[\\d]{2}\\.)\\/[\\d]{2}\\.[\\d]{2}\\. (?<note>(D Gut SEPA|Gutschr\\.SEPA)) \\+ (?<amount>[\\.,\\d]+)$") //
.assign((t, v) -> {
t.setDateTime(asDate(v.get("date") + v.get("year")));
t.setCurrencyCode(asCurrencyCode(v.get("baseCurrency")));
t.setAmount(asAmount(v.get("amount")));
// Formatting some notes
if ("D Gut SEPA".equals(v.get("note")))
v.put("note", "Dauerauftrag");
// Formatting some notes
if ("Gutschr.SEPA".equals(v.get("note")))
v.put("note", "SEPA Überweisungsgutschrift");
t.setNote(v.get("note"));
})
.wrap(t -> {
if (t.getCurrencyCode() != null && t.getAmount() != 0)
return new TransactionItem(t);
return null;
}));
// @formatter:off
// 06.08./07.08. SEPA Überw. Einzel - 250,00
// @formatter:on
Block removalBlock = new Block("^[\\d]{2}\\.[\\d]{2}\\.\\/[\\d]{2}\\.[\\d]{2}\\. SEPA Überw\\. Einzel \\- [\\.,\\d]+$");
type.addBlock(removalBlock);
removalBlock.set(new Transaction<AccountTransaction>()
.subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.REMOVAL);
return t;
})
.section("date", "note", "amount").optional() //
.documentRange("baseCurrency", "year") //
.match("^(?<date>[\\d]{2}\\.[\\d]{2}\\.)\\/[\\d]{2}\\.[\\d]{2}\\. (?<note>SEPA Überw\\. Einzel) \\- (?<amount>[\\.,\\d]+)$") //
.assign((t, v) -> {
t.setDateTime(asDate(v.get("date") + v.get("year")));
t.setCurrencyCode(asCurrencyCode(v.get("baseCurrency")));
t.setAmount(asAmount(v.get("amount")));
// Formatting some notes
if ("SEPA Überw. Einzel".equals(v.get("note")))
v.put("note", "SEPA Überweisungslastschrift");
t.setNote(v.get("note"));
})
.wrap(t -> {
if (t.getCurrencyCode() != null && t.getAmount() != 0)
return new TransactionItem(t);
return null;
}));
}
private <T extends Transaction<?>> void addTaxesSectionsTransaction(T transaction, DocumentType type)
{
transaction //
// @formatter:off
// Einbehaltene Quellensteuer 15 % auf 12,12 USD 1,53- EUR
// @formatter:on
.section("withHoldingTax", "currency").optional() //
.match("^Einbehaltene Quellensteuer [\\.,\\d]+([\\s]+)?% .* (?<withHoldingTax>[\\.,\\d]+)\\- (?<currency>[\\w]{3})$") //
.assign((t, v) -> processWithHoldingTaxEntries(t, v, "withHoldingTax", type))
// @formatter:off
// Anrechenbare Quellensteuer 15 % auf 10,17 EUR 1,53 EUR
// @formatter:on
.section("creditableWithHoldingTax", "currency").optional() //
.match("^Anrechenbare Quellensteuer [\\.,\\d]+([\\s]+)?% .* [\\.,\\d]+ [\\w]{3} (?<creditableWithHoldingTax>[\\.,\\d]+) (?<currency>[\\w]{3})$") //
.assign((t, v) -> processWithHoldingTaxEntries(t, v, "creditableWithHoldingTax", type))
// @formatter:off
// Anrechenbare Quellensteuer pro Stück 0,0144878 EUR 0,29 EUR
// @formatter:on
.section("creditableWithHoldingTax", "currency").optional() //
.match("^Anrechenbare Quellensteuer pro St.ck [\\.,\\d]+ [\\w]{3} (?<creditableWithHoldingTax>[\\.,\\d]+) (?<currency>[\\w]{3})$") //
.assign((t, v) -> processWithHoldingTaxEntries(t, v, "creditableWithHoldingTax", type))
// @formatter:off
// Kapitalertragsteuer (Account)
// Kapitalertragsteuer 24,51% auf 0,71 EUR 0,17- EUR
// @formatter:on
.section("tax", "currency").optional() //
.match("^Kapitalertrags(s)?teuer [\\.,\\d]+([\\s]+)?% auf [\\.,\\d]+ [\\w]{3} (?<tax>[\\.,\\d]+)\\- (?<currency>[\\w]{3})$") //
.assign((t, v) -> {
if (!type.getCurrentContext().getBoolean(IS_JOINT_ACCOUNT))
processTaxEntries(t, v, type);
})
// @formatter:off
// Kapitalerstragsteuer (Joint Account)
// Kapitalertragsteuer 25 % auf 50,51 EUR 12,63- EUR
// Kapitalertragsteuer 25 % auf 50,51 EUR 12,63- EUR
// @formatter:on
.section("tax1", "currency1", "tax2", "currency2").optional() //
.match("^Kapitalertrags(s)?teuer [\\.,\\d]+([\\s]+)?% auf [\\.,\\d]+ [\\w]{3} (?<tax1>[\\.,\\d]+)\\- (?<currency1>[\\w]{3})$") //
.match("^Kapitalertrags(s)?teuer [\\.,\\d]+([\\s]+)?% auf [\\.,\\d]+ [\\w]{3} (?<tax2>[\\.,\\d]+)\\- (?<currency2>[\\w]{3})$") //
.assign((t, v) -> {
if (type.getCurrentContext().getBoolean(IS_JOINT_ACCOUNT))
{
// Account 1
v.put("currency", v.get("currency1"));
v.put("tax", v.get("tax1"));
processTaxEntries(t, v, type);
// Account 2
v.put("currency", v.get("currency2"));
v.put("tax", v.get("tax2"));
processTaxEntries(t, v, type);
}
})
// @formatter:off
// Kapitalertragsteuer (KESt) - 105,00 EUR
// Kapitalertragsteuer (KESt) - 78,13 USD - 71,46 EUR
// @formatter:on
.section("tax", "currency").optional() //
.match("^Kapitalertrags(s)?teuer \\(KESt\\).* \\- (?<tax>[\\.,\\d]+) (?<currency>[\\w]{3})$") //
.assign((t, v) -> processTaxEntries(t, v, type))
// @formatter:off
// Solidaritätszuschlag (Account)
// Solidaritätszuschlag auf Kapitalertragsteuer EUR -6,76
// @formatter:on
.section("tax", "currency").optional() //
.match("^Solidarit.tszuschlag [\\.,\\d]+([\\s]+)?% auf [\\.,\\d]+ [\\w]{3} (?<tax>[\\.,\\d]+)\\- (?<currency>[\\w]{3})$") //
.assign((t, v) -> {
if (!type.getCurrentContext().getBoolean(IS_JOINT_ACCOUNT))
processTaxEntries(t, v, type);
})
// @formatter:off
// Solitaritätszuschlag (Joint Account)
// Solidaritätszuschlag 5,5 % auf 12,63 EUR 0,69- EUR
// Solidaritätszuschlag 5,5 % auf 12,63 EUR 0,69- EUR
// @formatter:on
.section("tax1", "currency1", "tax2", "currency2").optional() //
.match("^Solidarit.tszuschlag [\\.,\\d]+([\\s]+)?% auf [\\.,\\d]+ [\\w]{3} (?<tax1>[\\.,\\d]+)\\- (?<currency1>[\\w]{3})$") //
.match("^Solidarit.tszuschlag [\\.,\\d]+([\\s]+)?% auf [\\.,\\d]+ [\\w]{3} (?<tax2>[\\.,\\d]+)\\- (?<currency2>[\\w]{3})$") //
.assign((t, v) -> {
if (type.getCurrentContext().getBoolean(IS_JOINT_ACCOUNT))
{
// Account 1
v.put("currency", v.get("currency1"));
v.put("tax", v.get("tax1"));
processTaxEntries(t, v, type);
// Account 2
v.put("currency", v.get("currency2"));
v.put("tax", v.get("tax2"));
processTaxEntries(t, v, type);
}
})
// @formatter:off
// Solidaritätszuschlag auf KESt - 5,77 EUR
// Solidaritätszuschlag auf KESt - 4,30 USD - 3,93 EUR
// @formatter:on
.section("tax", "currency").optional() //
.match("^Solidarit.tszuschlag auf KESt.* \\- (?<tax>[\\.,\\d]+) (?<currency>[\\w]{3})$") //
.assign((t, v) -> processTaxEntries(t, v, type))
// @formatter:off
// Kirchensteuer (Account)
// Kirchensteuer 8,00% auf 42,45 EUR 3,39- EUR
// @formatter:on
.section("tax", "currency").optional() //
.match("^Kirchensteuer [\\.,\\d]+([\\s]+)?% auf [\\.,\\d]+ [\\w]{3} (?<tax>[\\.,\\d]+)\\- (?<currency>[\\w]{3})$") //
.assign((t, v) -> {
if (!type.getCurrentContext().getBoolean(IS_JOINT_ACCOUNT))
processTaxEntries(t, v, type);
})
// @formatter:off
// Kirchensteuer (Joint Account)
// Kirchensteuer 8,00% auf 42,45 EUR 3,39- EUR
// Kirchensteuer 8,00% auf 42,45 EUR 3,39- EUR
// @formatter:on
.section("tax1", "currency1", "tax2", "currency2").optional() //
.match("^Kirchensteuer [\\.,\\d]+([\\s]+)?% auf [\\.,\\d]+ [\\w]{3} (?<tax1>[\\.,\\d]+)\\- (?<currency1>[\\w]{3})$") //
.match("^Kirchensteuer [\\.,\\d]+([\\s]+)?% auf [\\.,\\d]+ [\\w]{3} (?<tax2>[\\.,\\d]+)\\- (?<currency2>[\\w]{3})$") //
.assign((t, v) -> {
if (type.getCurrentContext().getBoolean(IS_JOINT_ACCOUNT))
{
// Account 1
v.put("currency", v.get("currency1"));
v.put("tax", v.get("tax1"));
processTaxEntries(t, v, type);
// Account 2
v.put("currency", v.get("currency2"));
v.put("tax", v.get("tax2"));
processTaxEntries(t, v, type);
}
})
// @formatter:off
// Kirchensteuer auf KESt - 5,77 EUR
// Kirchensteuer auf KESt - 4,30 USD - 3,93 EUR
// @formatter:on
.section("tax", "currency").optional() //
.match("^Kirchensteuer auf KESt.* \\- (?<tax>[\\.,\\d]+) (?<currency>[\\w]{3})$") //
.assign((t, v) -> processTaxEntries(t, v, type));
}
private <T extends Transaction<?>> void addFeesSectionsTransaction(T transaction, DocumentType type)
{
transaction //
// @formatter:off
// Provision 39,95- EUR
// @formatter:on
.section("fee", "currency").optional() //
.match("^Provision (?<fee>[\\.,\\d]+)\\- (?<currency>[\\w]{3})$") //
.assign((t, v) -> processFeeEntries(t, v, type))
// @formatter:off
// Abwicklungskosten Börse 0,04- EUR
// @formatter:on
.section("fee", "currency").optional() //
.match("^Abwicklungskosten B.rse (?<fee>[\\.,\\d]+)\\- (?<currency>[\\w]{3})$") //
.assign((t, v) -> processFeeEntries(t, v, type))
// @formatter:off
// Transaktionsentgelt Börse 11,82- EUR
// @formatter:on
.section("fee", "currency").optional() //
.match("^Transaktionsentgelt B.rse (?<fee>[\\.,\\d]+)\\- (?<currency>[\\w]{3})$") //
.assign((t, v) -> processFeeEntries(t, v, type))
// @formatter:off
// Übertragungs-/Liefergebühr 0,65- EUR
// @formatter:on
.section("fee", "currency").optional() //
.match("^.bertragungs\\-\\/Liefergeb.hr (?<fee>[\\.,\\d]+)\\- (?<currency>[\\w]{3})$") //
.assign((t, v) -> processFeeEntries(t, v, type))
// @formatter:off
// Fremde Auslagen 16,86- EUR
// @formatter:on
.section("fee", "currency").optional() //
.match("^Fremde Auslagen (?<fee>[\\.,\\d]+)\\- (?<currency>[\\w]{3})$") //
.assign((t, v) -> processFeeEntries(t, v, type))
// @formatter:off
// Ausgabeaufschlag 4,00 %
// Kurswert EUR 17.252,30
// Preisnachlass EUR -82,94
// @formatter:on
.section("percentageFee", "currency", "amount", "discountCurrency", "discount").optional() //
.match("^Ausgabeaufschlag (?<percentageFee>[\\.,\\d]+) %$") //
.match("^Kurswert (?<currency>[\\w]{3}) (?<amount>[\\.,\\d]+)$") //
.match("^Preisnachlass (?<discountCurrency>[\\w]{3}) \\-(?<discount>[\\.,\\d]+)$") //
.assign((t, v) -> {
BigDecimal percentageFee = asBigDecimal(v.get("percentageFee"));
BigDecimal amount = asBigDecimal(v.get("amount"));
Money discount = Money.of(asCurrencyCode(v.get("discountCurrency")), asAmount(v.get("discount")));
if (percentageFee.compareTo(BigDecimal.ZERO) != 0 && discount.isPositive())
{
// @formatter:off
// feeAmount = (amount / (1 + percentageFee / 100)) * (percentageFee / 100)
// @formatter:on
BigDecimal fxFee = amount.divide(percentageFee //
.divide(BigDecimal.valueOf(100)).add(BigDecimal.ONE), Values.MC)
.multiply(percentageFee, Values.MC);
Money fee = Money.of(asCurrencyCode(v.get("currency")), fxFee.setScale(0, Values.MC.getRoundingMode()).longValue());
// @formatter:off
// fee = fee - discount
// @formatter:on
fee = fee.subtract(discount);
checkAndSetFee(fee, t, type.getCurrentContext());
}
});
}
}