Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify WIR Bank PDF-Importert to support new transaction #2902

Merged
merged 1 commit into from Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,26 @@
PDFBox Version: 1.8.16
-----------------------------------------
Freizügigkeitsstiftung der WIR Bank
Auberg 1
4002 Basel
Internet www.viac.ch
E-Mail info@viac.ch
Telefon 0800 80 40 40
Vertrag XXXXXXXXXXXXXX
Segment XXXXXXXXXXXXXX
Strasse XXXXXXXX
9999 Ort
Basel, 09.06.2022
Börsenabrechnung - Verkauf CSIF Gold
Wir haben für Sie folgenden Auftrag ausgeführt:
Order: Verkauf
0.135 Ant CSIF Gold
ISIN: CH0209106761
Kurs: USD 1'529.17
Betrag USD 205.76
Umrechnungskurs CHF/USD 0.97538 CHF 200.69
Verrechneter Betrag: Valuta 09.06.2022 CHF 200.69
S. E. & O.
Freundliche Grüsse
Freizügigkeitsstiftung der WIR Bank
Anzeige ohne Unterschrift
Expand Up @@ -1462,6 +1462,101 @@ public void testWertpapierVerkauf02()
is(Money.of("CHF", Values.Amount.factorize(0.00))));
}

@Test
public void testWertpapierVerkauf03()
{
Client client = new Client();

WirBankPDFExtractor extractor = new WirBankPDFExtractor(client);

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Verkauf03.txt"), errors);

assertThat(errors, empty());
assertThat(results.size(), is(2));
new AssertImportActions().check(results, "CHF");

// check security
Security security = results.stream().filter(SecurityItem.class::isInstance).findFirst()
.orElseThrow(IllegalArgumentException::new).getSecurity();
assertThat(security.getIsin(), is("CH0209106761"));
assertThat(security.getName(), is("CSIF Gold"));
assertThat(security.getCurrencyCode(), is(CurrencyUnit.USD));

// check buy sell transaction
BuySellEntry entry = (BuySellEntry) results.stream().filter(BuySellEntryItem.class::isInstance).findFirst()
.orElseThrow(IllegalArgumentException::new).getSubject();

assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.SELL));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.SELL));

assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2022-06-09T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(0.135)));
assertThat(entry.getSource(), is("Verkauf03.txt"));
assertNull(entry.getNote());

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(200.69))));
assertThat(entry.getPortfolioTransaction().getGrossValue(),
is(Money.of("CHF", Values.Amount.factorize(200.69))));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX),
is(Money.of("CHF", Values.Amount.factorize(0.00))));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE),
is(Money.of("CHF", Values.Amount.factorize(0.00))));

Unit grossValueUnit = entry.getPortfolioTransaction().getUnit(Unit.Type.GROSS_VALUE)
.orElseThrow(IllegalArgumentException::new);
assertThat(grossValueUnit.getForex(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(205.76))));
}

@Test
public void testWertpapierVerkauf03WithSecurityInCHF()
{
Security security = new Security("CSIF Gold", "CHF");
security.setIsin("CH0209106761");

Client client = new Client();
client.addSecurity(security);

WirBankPDFExtractor extractor = new WirBankPDFExtractor(client);

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Verkauf03.txt"), errors);

assertThat(errors, empty());
assertThat(results.size(), is(1));
new AssertImportActions().check(results, "CHF");

// check buy sell transaction
BuySellEntry entry = (BuySellEntry) results.stream().filter(BuySellEntryItem.class::isInstance).findFirst()
.orElseThrow(IllegalArgumentException::new).getSubject();

assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.SELL));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.SELL));

assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2022-06-09T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(0.135)));
assertThat(entry.getSource(), is("Verkauf03.txt"));
assertNull(entry.getNote());

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(200.69))));
assertThat(entry.getPortfolioTransaction().getGrossValue(),
is(Money.of("CHF", Values.Amount.factorize(200.69))));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX),
is(Money.of("CHF", Values.Amount.factorize(0.00))));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE),
is(Money.of("CHF", Values.Amount.factorize(0.00))));

CheckCurrenciesAction c = new CheckCurrenciesAction();
Account account = new Account();
account.setCurrencyCode("CHF");
Status s = c.process(entry, account, entry.getPortfolio());
assertThat(s, is(Status.OK_STATUS));
}

@Test
public void testSteuerrueckerstattung01()
{
Expand Down
Expand Up @@ -86,7 +86,7 @@ private void addBuySellTransaction()
pdfTransaction
// Is type --> "Verkauf" change from BUY to SELL
.section("type").optional()
.match("^(B.rsenabrechnung|Exchange Settlement) \\- (?<type>(Kauf|Verkauf|Buy|Sell))$")
.match("^(B.rsenabrechnung|Exchange Settlement) \\- (?<type>(Kauf|Verkauf|Buy|Sell)).*$")
.assign((t, v) -> {
if (v.get("type").equals("Verkauf") || v.get("type").equals("Sell"))
t.setType(PortfolioTransaction.Type.SELL);
Expand Down Expand Up @@ -137,6 +137,7 @@ private void addBuySellTransaction()
})

.conclude(PDFExtractorUtils.fixGrossValueBuySell())

.wrap(BuySellEntryItem::new);

addTaxesSectionsTransaction(pdfTransaction, type);
Expand Down