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 Swissquote Bank PDF-Importer to support new transaction #3327

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,29 @@
PDF author: 'Registered to: SWISQUOT'
PDFBox Version: 1.8.16
-----------------------------------------
TRANSAKTIONSBELEG
Kunde: 1234567 - TRADING
IBAN: CH431213484123183435
Herrn Max Mustermann
Musterstraße 1
DE-12345 Musterstadt
Gland, 28.10.2020
Börsentransaktion: Kauf Unsere Referenz: 206871550
Gemäss Ihrem Kaufauftrag vom 28.10.2020 haben wir folgende Transaktionen vorgenommen:
Titel Ort der Ausführung
Vanguard All World ETF Dist ISIN: IE00B3RBWM25 SIX Swiss Exchange
NKN: 18575459
Anzahl Preis Betrag
25 83.49 CHF 2'087.25
Total CHF 2'087.25
Kommission Swissquote Bank AG CHF 9.85
Abgabe (Eidg. Stempelsteuer) CHF 3.15
Börsengebühren CHF 2.00
Zu Ihren Lasten CHF 2'102.25
Betrag belastet auf Kontonummer 123456701, Valutadatum 30.10.2020
Dieser Transaktionsbeleg sowie die aufgeführte Transaktion unterliegen unseren Allgemeinen Geschäftsbedingungen und Depotreglement.
Vielen Dank für Ihren Auftrag.
Formular ohne Unterschrift S.E. & O.
Swissquote Bank AG, 33 chemin de la Crétaux, CH-1196 Gland
Customer Care : 0848 25 88 88 (Aus dem Ausland +41 44 825 88 88)
MwSt n° CHE-116.310.079
Expand Up @@ -223,6 +223,52 @@ public void testWertpapierKauf03WithSecurityInCHF()
assertThat(s, is(Status.OK_STATUS));
}

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

SwissquotePDFExtractor extractor = new SwissquotePDFExtractor(client);

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

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Kauf04.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("IE00B3RBWM25"));
assertNull(security.getWkn());
assertNull(security.getTickerSymbol());
assertThat(security.getName(), is("Vanguard All World ETF Dist"));
assertThat(security.getCurrencyCode(), is("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.BUY));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.BUY));

assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2020-10-30T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(25)));
assertThat(entry.getSource(), is("Kauf04.txt"));
assertThat(entry.getNote(), is("Referenz: 206871550"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of("CHF", Values.Amount.factorize(2102.25))));
assertThat(entry.getPortfolioTransaction().getGrossValue(),
is(Money.of("CHF", Values.Amount.factorize(2087.25))));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX),
is(Money.of("CHF", Values.Amount.factorize(3.15))));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE),
is(Money.of("CHF", Values.Amount.factorize(9.85 + 2.00))));
}

@Test
public void testWertpapierVerkauf01()
{
Expand Down
Expand Up @@ -24,7 +24,7 @@ public SwissquotePDFExtractor(Client client)
{
super(client);

addBankIdentifier("Swissquote Bank AG, 33 chemin de la Crétaux, CH-1196 Gland"); //$NON-NLS-1$
addBankIdentifier("Swissquote Bank AG"); //$NON-NLS-1$

addBuySellTransaction();
addDividendsTransaction();
Expand Down Expand Up @@ -86,7 +86,7 @@ private void addBuySellTransaction()
.match("^Betrag (belastet|gutgeschrieben) (auf|auf Ihrer) Kontonummer .*, Valutadatum (?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4})$")
.assign((t, v) -> t.setDate(asDate(v.get("date"))))

// // @formatter:off
// @formatter:off
// Zu Ihren Lasten USD 2'900.60
// Zu Ihren Gunsten CHF 8'198.70
// @formatter:on
Expand All @@ -105,8 +105,7 @@ private void addBuySellTransaction()
.section("fxCurrency", "fxGross", "exchangeRate", "currency", "gross").optional()
.match("^Total (?<fxCurrency>[\\w]{3}) (?<fxGross>[\\.'\\d]+)$")
.match("^Wechselkurs (?<exchangeRate>[\\.'\\d]+)$")
.match("^(?<currency>[\\w]{3}) (?<gross>[\\.'\\d]+)$")
.assign((t, v) -> {
.match("^(?<currency>[\\w]{3}) (?<gross>[\\.'\\d]+)$").assign((t, v) -> {
BigDecimal exchangeRate = asExchangeRate(v.get("exchangeRate"));
if (t.getPortfolioTransaction().getCurrencyCode().contentEquals(asCurrencyCode(v.get("fxCurrency"))))
{
Expand All @@ -130,7 +129,7 @@ private void addBuySellTransaction()
}
catch (IllegalArgumentException e)
{
exchangeRate = BigDecimal.valueOf(((double) gross.getAmount()) / fxGross.getAmount());
exchangeRate = BigDecimal.valueOf(((double) gross.getAmount()) / fxGross.getAmount());
type.getCurrentContext().put("exchangeRate", exchangeRate.toPlainString());

t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.GROSS_VALUE, gross, fxGross, exchangeRate));
Expand Down Expand Up @@ -158,12 +157,11 @@ private void addDividendsTransaction()

Block block = new Block("^(Dividende|Kapitalgewinn) Unsere Referenz:.*$");
type.addBlock(block);
Transaction<AccountTransaction> pdfTransaction = new Transaction<AccountTransaction>()
.subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.DIVIDENDS);
return entry;
});
Transaction<AccountTransaction> pdfTransaction = new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.DIVIDENDS);
return entry;
});

pdfTransaction
// @formatter:off
Expand Down