Skip to content

Commit

Permalink
Fix UBS AG PDF-Importer
Browse files Browse the repository at this point in the history
Remove FX-Marge (Spread)
https://forum.portfolio-performance.info/t/pdf-import-von-ubs-ag/20627/21 and follow...
Add notes
  • Loading branch information
Nirus2000 committed Mar 26, 2024
1 parent 27109f8 commit 4862604
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void testWertpapierKauf02()
assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2017-12-27T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(15)));
assertThat(entry.getSource(), is("Kauf02.txt"));
assertNull(entry.getNote());
assertThat(entry.getNote(), is("Auftrags-Nr. 90586827"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(2213.15))));
Expand Down Expand Up @@ -229,7 +229,7 @@ public void testWertpapierKauf03()
assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2017-12-26T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(100)));
assertThat(entry.getSource(), is("Kauf03.txt"));
assertNull(entry.getNote());
assertThat(entry.getNote(), is("Auftrags-Nr. 90586823"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(3881.75))));
Expand Down Expand Up @@ -275,7 +275,7 @@ public void testWertpapierKauf03WithSecurityInUSD()
assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2017-12-26T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(100)));
assertThat(entry.getSource(), is("Kauf03.txt"));
assertNull(entry.getNote());
assertThat(entry.getNote(), is("Auftrags-Nr. 90586823"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(3881.75))));
Expand Down Expand Up @@ -425,7 +425,7 @@ public void testWertpapierVerkauf02()
assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2021-12-23T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(10)));
assertThat(entry.getSource(), is("Verkauf02.txt"));
assertNull(entry.getNote());
assertThat(entry.getNote(), is("Auftrags-Nr. 155032892"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(3720.18))));
Expand Down Expand Up @@ -469,7 +469,7 @@ public void testWertpapierVerkauf03()
assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2021-08-19T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(39)));
assertThat(entry.getSource(), is("Verkauf03.txt"));
assertNull(entry.getNote());
assertThat(entry.getNote(), is("Auftrags-Nr. 149557039"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(1883.08))));
Expand Down Expand Up @@ -516,7 +516,7 @@ public void testWertpapierVerkauf03WithSecurityInUSD()
assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2021-08-19T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(39)));
assertThat(entry.getSource(), is("Verkauf03.txt"));
assertNull(entry.getNote());
assertThat(entry.getNote(), is("Auftrags-Nr. 149557039"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(1883.08))));
Expand Down Expand Up @@ -570,7 +570,7 @@ public void testWertpapierVerkauf04()
assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2021-05-10T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(1)));
assertThat(entry.getSource(), is("Verkauf04.txt"));
assertNull(entry.getNote());
assertThat(entry.getNote(), is("Auftrags-Nr. 6820800"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(36.90))));
Expand Down Expand Up @@ -614,7 +614,7 @@ public void testWertpapierVerkauf05()
assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2021-04-12T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(73)));
assertThat(entry.getSource(), is("Verkauf05.txt"));
assertNull(entry.getNote());
assertThat(entry.getNote(), is("Auftrags-Nr. 8583497"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(8030.00))));
Expand Down Expand Up @@ -658,7 +658,7 @@ public void testWertpapierVerkauf06()
assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2020-01-04T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(0.167)));
assertThat(entry.getSource(), is("Verkauf06.txt"));
assertNull(entry.getNote());
assertThat(entry.getNote(), is("Auftrags-Nr. 6615705"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(2.63))));
Expand Down Expand Up @@ -705,7 +705,7 @@ public void testWertpapierVerkauf06WithSecurityInCHF()
assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2020-01-04T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(0.167)));
assertThat(entry.getSource(), is("Verkauf06.txt"));
assertNull(entry.getNote());
assertThat(entry.getNote(), is("Auftrags-Nr. 6615705"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(2.63))));
Expand Down Expand Up @@ -754,7 +754,7 @@ public void testDividende01()
assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2021-12-28T00:00")));
assertThat(transaction.getShares(), is(Values.Share.factorize(20)));
assertThat(transaction.getSource(), is("Dividende01.txt"));
assertNull(transaction.getNote());
assertThat(transaction.getNote(), is("Auftrags-Nr. 3256654"));

assertThat(transaction.getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(3.85))));
Expand Down Expand Up @@ -799,7 +799,7 @@ public void testDividende01WithSecurityInCHF()
assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2021-12-28T00:00")));
assertThat(transaction.getShares(), is(Values.Share.factorize(20)));
assertThat(transaction.getSource(), is("Dividende01.txt"));
assertNull(transaction.getNote());
assertThat(transaction.getNote(), is("Auftrags-Nr. 3256654"));

assertThat(transaction.getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(3.85))));
Expand Down Expand Up @@ -843,10 +843,10 @@ public void testDividende02()
assertThat(results, hasItem(dividend( //
hasDate("2023-12-20T00:00"), hasShares(546), //
hasSource("Dividende02.txt"), //
hasNote(null), //
hasAmount("CHF", 155.64), hasGrossValue("CHF", 158.26), //
hasForexGrossValue("EUR", 170.44), //
hasTaxes("CHF", 0.00), hasFees("CHF", 2.62))));
hasNote("Auftrags-Nr. 4083256 | FX-Marge: 2.62 CHF"), //
hasAmount("CHF", 155.64), hasGrossValue("CHF", 155.64), //
hasForexGrossValue("EUR", 167.62), //
hasTaxes("CHF", 0.00), hasFees("CHF", 0.00))));
}

@Test
Expand Down Expand Up @@ -877,9 +877,9 @@ public void testDividende02WithSecurityInCHF()
assertThat(results, hasItem(dividend( //
hasDate("2023-12-20T00:00"), hasShares(546), //
hasSource("Dividende02.txt"), //
hasNote(null), //
hasAmount("CHF", 155.64), hasGrossValue("CHF", 158.26), //
hasTaxes("CHF", 0.00), hasFees("CHF", 2.62), //
hasNote("Auftrags-Nr. 4083256 | FX-Marge: 2.62 CHF"), //
hasAmount("CHF", 155.64), hasGrossValue("CHF", 155.64), //
hasTaxes("CHF", 0.00), hasFees("CHF", 0.00), //
check(tx -> {
CheckCurrenciesAction c = new CheckCurrenciesAction();
Account account = new Account();
Expand All @@ -890,7 +890,7 @@ public void testDividende02WithSecurityInCHF()
}

@Test
public void testaddDepotAccountFee01()
public void testDepotAccountFee01()
{
UBSAGBankingAGPDFExtractor extractor = new UBSAGBankingAGPDFExtractor(new Client());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;

Expand Down Expand Up @@ -51,11 +52,7 @@ private void addBuySellTransaction()

Transaction<BuySellEntry> pdfTransaction = new Transaction<>();

Block firstRelevantLine = new Block("^(Bewertet in: .*" //
+ "|Ihr (Kauf|Verkauf)" //
+ "|R.CKZAHLUNG RESERVEN AUS KAPITALEINLAGEN" //
+ "|FUSION" //
+ "|FRAKTIONS\\-ABRECHNUNG)$");
Block firstRelevantLine = new Block("^.*(Depot|Portfolio)\\-Nr\\..*$");
type.addBlock(firstRelevantLine);
firstRelevantLine.set(pdfTransaction);

Expand Down Expand Up @@ -351,6 +348,13 @@ private void addBuySellTransaction()
checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext());
}))

// @formatter:off
// Auftrags-Nr. 4083256
// @formatter:on
.section("note").optional() //
.match("^(?<note>Auftrags\\-Nr\\. .*)$") //
.assign((t, v) -> t.setNote(trim(v.get("note"))))

.conclude(ExtractorUtils.fixGrossValueBuySell())

.wrap(t -> {
Expand All @@ -372,7 +376,7 @@ private void addDividendeTransaction()

Transaction<AccountTransaction> pdfTransaction = new Transaction<>();

Block firstRelevantLine = new Block("^DIVIDENDENZAHLUNG$");
Block firstRelevantLine = new Block("^.*(Depot|Portfolio)\\-Nr\\..*$");
type.addBlock(firstRelevantLine);
firstRelevantLine.set(pdfTransaction);

Expand Down Expand Up @@ -442,7 +446,6 @@ private void addDividendeTransaction()
.section("fxGross", "baseCurrency", "termCurrency", "exchangeRate").optional() //
.match("^BRUTTO [\\w]{3} (?<fxGross>[\\.'\\d\\s]+)$") //
.match("^UMRECHNUNGSKURS (?<baseCurrency>[\\w]{3})\\/(?<termCurrency>[\\w]{3}) (?<exchangeRate>[\\.'\\d\\s]+)$") //
.match("^GUTSCHRIFT KONTO .* VALUTA [\\d]{2}\\.[\\d]{2}\\.[\\d]{4} [\\w]{3} [\\.'\\d\\s]+$") //
.assign((t, v) -> {
ExtrExchangeRate rate = asExchangeRate(v);
type.getCurrentContext().putType(rate);
Expand All @@ -453,6 +456,20 @@ private void addDividendeTransaction()
checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext());
})

// @formatter:off
// Auftrags-Nr. 4083256
// @formatter:on
.section("note").optional() //
.match("^(?<note>Auftrags\\-Nr\\. .*)$") //
.assign((t, v) -> t.setNote(trim(v.get("note"))))

// @formatter:off
// FX-Marge von CHF 2.62 inbegriffen
// @formatter:on
.section("note1", "note2").optional() //
.match("^FX\\-Marge von (?<note1>[\\w]{3}) (?<note2>[\\.'\\d\\s]+) inbegriffen.*$") //
.assign((t, v) -> t.setNote(concatenate(t.getNote(), v.get("note2") + " " + v.get("note1"), " | FX-Marge: ")))

.conclude(ExtractorUtils.fixGrossValueA())

.wrap(TransactionItem::new);
Expand Down Expand Up @@ -579,13 +596,6 @@ private <T extends Transaction<?>> void addFeesSectionsTransaction(T transaction
// @formatter:on
.section("currency", "fee").optional() //
.match("^Externe Geb.hren (?<currency>[\\w]{3}) (\\-)?(?<fee>[\\.,'\\d\\s]+)$") //
.assign((t, v) -> processFeeEntries(t, v, type))

// @formatter:off
// FX-Marge von CHF 2.62 inbegriffen
// @formatter:on
.section("currency", "fee").optional() //
.match("^FX-Marge von (?<currency>[\\w]{3}) (\\-)?(?<fee>[\\.,'\\d\\s]+).*$") //
.assign((t, v) -> processFeeEntries(t, v, type));
}

Expand Down

0 comments on commit 4862604

Please sign in to comment.