From 4862604fdfb2bf74331768d408170abad9957bf2 Mon Sep 17 00:00:00 2001 From: Nirus2000 Date: Tue, 26 Mar 2024 19:03:01 +0100 Subject: [PATCH] Fix UBS AG PDF-Importer Remove FX-Marge (Spread) https://forum.portfolio-performance.info/t/pdf-import-von-ubs-ag/20627/21 and follow... Add notes --- .../pdf/ubsag/UBSAGPDFExtractorTest.java | 40 +++++++++---------- .../pdf/UBSAGBankingAGPDFExtractor.java | 38 +++++++++++------- 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/ubsag/UBSAGPDFExtractorTest.java b/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/ubsag/UBSAGPDFExtractorTest.java index d7168bc0ae..5c21873dfd 100644 --- a/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/ubsag/UBSAGPDFExtractorTest.java +++ b/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/ubsag/UBSAGPDFExtractorTest.java @@ -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)))); @@ -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)))); @@ -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)))); @@ -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)))); @@ -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)))); @@ -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)))); @@ -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)))); @@ -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)))); @@ -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)))); @@ -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)))); @@ -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)))); @@ -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)))); @@ -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 @@ -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(); @@ -890,7 +890,7 @@ public void testDividende02WithSecurityInCHF() } @Test - public void testaddDepotAccountFee01() + public void testDepotAccountFee01() { UBSAGBankingAGPDFExtractor extractor = new UBSAGBankingAGPDFExtractor(new Client()); diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/UBSAGBankingAGPDFExtractor.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/UBSAGBankingAGPDFExtractor.java index e9f235a9ed..96e16276cb 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/UBSAGBankingAGPDFExtractor.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/UBSAGBankingAGPDFExtractor.java @@ -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; @@ -51,11 +52,7 @@ private void addBuySellTransaction() Transaction 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); @@ -351,6 +348,13 @@ private void addBuySellTransaction() checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext()); })) + // @formatter:off + // Auftrags-Nr. 4083256 + // @formatter:on + .section("note").optional() // + .match("^(?Auftrags\\-Nr\\. .*)$") // + .assign((t, v) -> t.setNote(trim(v.get("note")))) + .conclude(ExtractorUtils.fixGrossValueBuySell()) .wrap(t -> { @@ -372,7 +376,7 @@ private void addDividendeTransaction() Transaction pdfTransaction = new Transaction<>(); - Block firstRelevantLine = new Block("^DIVIDENDENZAHLUNG$"); + Block firstRelevantLine = new Block("^.*(Depot|Portfolio)\\-Nr\\..*$"); type.addBlock(firstRelevantLine); firstRelevantLine.set(pdfTransaction); @@ -442,7 +446,6 @@ private void addDividendeTransaction() .section("fxGross", "baseCurrency", "termCurrency", "exchangeRate").optional() // .match("^BRUTTO [\\w]{3} (?[\\.'\\d\\s]+)$") // .match("^UMRECHNUNGSKURS (?[\\w]{3})\\/(?[\\w]{3}) (?[\\.'\\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); @@ -453,6 +456,20 @@ private void addDividendeTransaction() checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext()); }) + // @formatter:off + // Auftrags-Nr. 4083256 + // @formatter:on + .section("note").optional() // + .match("^(?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 (?[\\w]{3}) (?[\\.'\\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); @@ -579,13 +596,6 @@ private > void addFeesSectionsTransaction(T transaction // @formatter:on .section("currency", "fee").optional() // .match("^Externe Geb.hren (?[\\w]{3}) (\\-)?(?[\\.,'\\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 (?[\\w]{3}) (\\-)?(?[\\.,'\\d\\s]+).*$") // .assign((t, v) -> processFeeEntries(t, v, type)); }