-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...io.tests/src/name/abuchen/portfolio/datatransfer/pdf/bigbank/BigbankPDFExtractorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package name.abuchen.portfolio.datatransfer.pdf.bigbank; | ||
|
||
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.deposit; | ||
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasAmount; | ||
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasDate; | ||
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasNote; | ||
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasSource; | ||
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.removal; | ||
import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countAccountTransactions; | ||
import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countBuySell; | ||
import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countSecurities; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.collection.IsEmptyCollection.empty; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import name.abuchen.portfolio.datatransfer.Extractor.Item; | ||
import name.abuchen.portfolio.datatransfer.actions.AssertImportActions; | ||
import name.abuchen.portfolio.datatransfer.pdf.BigbankPDFExtractor; | ||
import name.abuchen.portfolio.datatransfer.pdf.PDFInputFile; | ||
import name.abuchen.portfolio.model.Client; | ||
import name.abuchen.portfolio.money.CurrencyUnit; | ||
|
||
@SuppressWarnings("nls") | ||
public class BigbankPDFExtractorTest | ||
{ | ||
@Test | ||
public void testKontoauszug01() | ||
{ | ||
BigbankPDFExtractor extractor = new BigbankPDFExtractor(new Client()); | ||
|
||
List<Exception> errors = new ArrayList<>(); | ||
|
||
List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Kontoauszug01.txt"), errors); | ||
|
||
assertThat(errors, empty()); | ||
assertThat(countSecurities(results), is(0L)); | ||
assertThat(countBuySell(results), is(0L)); | ||
assertThat(countAccountTransactions(results), is(3L)); | ||
assertThat(results.size(), is(3)); | ||
new AssertImportActions().check(results, CurrencyUnit.EUR); | ||
|
||
// assert transaction | ||
assertThat(results, hasItem(deposit(hasDate("2024-03-20"), hasAmount("EUR", 10.00), // | ||
hasSource("Kontoauszug01.txt"), hasNote(null)))); | ||
|
||
// assert transaction | ||
assertThat(results, hasItem(deposit(hasDate("2024-03-21"), hasAmount("EUR", 1500.00), // | ||
hasSource("Kontoauszug01.txt"), hasNote(null)))); | ||
|
||
// assert transaction | ||
assertThat(results, hasItem(removal(hasDate("2024-03-25"), hasAmount("EUR", 10.00), // | ||
hasSource("Kontoauszug01.txt"), hasNote(null)))); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...hen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/bigbank/Kontoauszug01.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
``` | ||
PDFBox Version: 1.8.17 | ||
Portfolio Performance Version: 0.68.3 | ||
----------------------------------------- | ||
26.03.2024 | ||
tedj yGBqfR MusjIylOz | ||
pnLTPRWhlvLQRQip 06 | ||
2242 PyWc | ||
vBRjZIShrz | ||
Tagesgeldvertrag SD-ATC-55443596 | ||
Kontoauszug von 01.03.2024 bis 25.03.2024 | ||
IBAN: EE123456789101112131 | ||
Anfangssaldo 01.03.2024 0,00 | ||
Datum Gegenkonto Buchung Name Betrag in EUR | ||
20.03.2024 AT123456789101112131 Einzahlung ffIpWotyu dJMdyU +10,00 | ||
21.03.2024 AT123456789101112131 Einzahlung oDkoRVZEb TxDUxE +1 500,00 | ||
25.03.2024 AT123456789101112131 Auszahlung sUBHAKqzf vNNKxT -10,00 | ||
Endsaldo 25.03.2024 1 500,00 | ||
Anfangssaldo 01.03.2024 0,00 | ||
Summe Belastungen -10,00 | ||
Summe Gutschriften +1 510,00 | ||
Endsaldo 25.03.2024 1 500,00 | ||
Dies ist ein automatisch generierter Kontoauszug. | ||
BIGBANK AS Telefon 0810 900 629 | ||
Riia 2, Tartu E-mail [email protected] | ||
51004 Reg. Nr. 10183757 | ||
www.bigbank.at VAT. Nr. EE100041383 | ||
1 / 1 | ||
Powered by TCPDF (www.tcpdf.org) | ||
|
||
``` |
88 changes: 88 additions & 0 deletions
88
name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/BigbankPDFExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package name.abuchen.portfolio.datatransfer.pdf; | ||
|
||
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.Client; | ||
import name.abuchen.portfolio.util.TextUtil; | ||
|
||
@SuppressWarnings("nls") | ||
public class BigbankPDFExtractor extends AbstractPDFExtractor | ||
{ | ||
public BigbankPDFExtractor(Client client) | ||
{ | ||
super(client); | ||
|
||
addBankIdentifier("BIGBANK AS"); | ||
|
||
addAccountStatementTransaction(); | ||
} | ||
|
||
@Override | ||
public String getLabel() | ||
{ | ||
return "Bigbank AS"; | ||
} | ||
|
||
|
||
private void addAccountStatementTransaction() | ||
{ | ||
final DocumentType type = new DocumentType("Kontoauszug", | ||
documentContext -> documentContext | ||
// @formatter:off | ||
// Datum Gegenkonto Buchung Name Betrag in EUR | ||
// @formatter:on | ||
.section("currency") // | ||
.match("^.*Betrag in (?<currency>[\\w]{3}).*$") // | ||
.assign((ctx, v) -> ctx.put("currency", asCurrencyCode(v.get("currency"))))); | ||
|
||
this.addDocumentTyp(type); | ||
|
||
// @formatter:off | ||
// 21.03.2024 AT123456789101112131 Einzahlung oDkoRVZEb TxDUxE +1 500,00 | ||
// @formatter:on | ||
Block depositBlock = new Block("^[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}.*Einzahlung.*\\+[\\d\\s]+\\,[\\d]{2}$"); | ||
type.addBlock(depositBlock); | ||
depositBlock.set(new Transaction<AccountTransaction>() | ||
|
||
.subject(() -> { | ||
AccountTransaction accountTransaction = new AccountTransaction(); | ||
accountTransaction.setType(AccountTransaction.Type.DEPOSIT); | ||
return accountTransaction; | ||
}) | ||
|
||
.section("date", "amount") | ||
.documentContext("currency") | ||
.match("^(?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}).*Einzahlung.*\\+(?<amount>[\\d\\s]+\\,[\\d]{2})$") | ||
.assign((t, v) -> { | ||
t.setDateTime(asDate(v.get("date"))); | ||
t.setAmount(asAmount(TextUtil.stripBlanks(v.get("amount")))); | ||
t.setCurrencyCode(v.get("currency")); | ||
}) | ||
.wrap(TransactionItem::new)); | ||
|
||
// @formatter:off | ||
// 25.03.2024 AT123456789101112131 Auszahlung sUBHAKqzf vNNKxT -10,00 | ||
// @formatter:on | ||
Block removalBlock = new Block("^[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}.*Auszahlung.*\\-[\\d\\s]+,[\\d]{2}.*$"); | ||
type.addBlock(removalBlock); | ||
removalBlock.set(new Transaction<AccountTransaction>() | ||
|
||
.subject(() -> { | ||
AccountTransaction accountTransaction = new AccountTransaction(); | ||
accountTransaction.setType(AccountTransaction.Type.REMOVAL); | ||
return accountTransaction; | ||
}) | ||
|
||
.section("date", "amount") // | ||
.documentContext("currency") | ||
.match("^(?<date>[\\d]{2}\\.[\\d]{2}\\.[\\d]{4}).*Auszahlung.*\\-(?<amount>[\\d\\s]+,[\\d]{2}).*$") | ||
.assign((t, v) -> { | ||
t.setDateTime(asDate(v.get("date"))); | ||
t.setAmount(asAmount(TextUtil.stripBlanks(v.get("amount")))); | ||
t.setCurrencyCode(v.get("currency")); | ||
}) | ||
.wrap(TransactionItem::new)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters