From de91056094e2ff1478d341ba1570754bb67d3de4 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 13 May 2020 19:52:34 +0200 Subject: [PATCH] Fixed that sheet number may is omitted --- .../fints/transactions/mt940/Mt940Parser.kt | 2 +- .../fints/transactions/Mt940ParserTest.kt | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/fints4k/src/main/kotlin/net/dankito/fints/transactions/mt940/Mt940Parser.kt b/fints4k/src/main/kotlin/net/dankito/fints/transactions/mt940/Mt940Parser.kt index 2efd8cb3..2e5e5638 100644 --- a/fints4k/src/main/kotlin/net/dankito/fints/transactions/mt940/Mt940Parser.kt +++ b/fints4k/src/main/kotlin/net/dankito/fints/transactions/mt940/Mt940Parser.kt @@ -184,7 +184,7 @@ open class Mt940Parser : IMt940Parser { protected open fun parseSheetNumber(statementAndMaySheetNumber: String): Int? { val parts = statementAndMaySheetNumber.split('/') - if (parts.size > 0) { + if (parts.size > 1) { return parts[1].toInt() } diff --git a/fints4k/src/test/kotlin/net/dankito/fints/transactions/Mt940ParserTest.kt b/fints4k/src/test/kotlin/net/dankito/fints/transactions/Mt940ParserTest.kt index c1294d87..a3563738 100644 --- a/fints4k/src/test/kotlin/net/dankito/fints/transactions/Mt940ParserTest.kt +++ b/fints4k/src/test/kotlin/net/dankito/fints/transactions/Mt940ParserTest.kt @@ -68,6 +68,38 @@ class Mt940ParserTest : FinTsTestBase() { AccountStatement1Transaction1OtherPartyBankCode, AccountStatement1Transaction1OtherPartyAccountId) } + @Test + fun accountStatementWithSingleTransaction_SheetNumberOmitted() { + + // given + val amount = BigDecimal("15.00") + val isCredit = false + val bookingDate = Date(120, 4, 11) + + // when + val result = underTest.parseMt940String(AccountStatementWithSingleTransaction_SheetNumberOmitted) + + + // then + assertThat(result).hasSize(1) + + val statement = result.first() + + assertThat(statement.bankCodeBicOrIban).isEqualTo(BankCode) + assertThat(statement.accountIdentifier).isEqualTo(CustomerId) + assertThat(statement.statementNumber).isEqualTo(0) + assertThat(statement.sequenceNumber).isNull() + + assertBalance(statement.openingBalance, true, bookingDate, BigDecimal("0.00")) + assertBalance(statement.closingBalance, isCredit, bookingDate, amount) + + assertThat(statement.transactions).hasSize(1) + + val transaction = statement.transactions.first() + assertTurnover(transaction.turnover, bookingDate, amount, isCredit, null) + assertTransactionDetails(transaction.details, "Ausgabe einer Debitkarte", BankCode, CustomerId) + } + @Test fun accountStatementWithTwoTransactions() { @@ -173,6 +205,19 @@ class Mt940ParserTest : FinTsTestBase() { - """.trimIndent() + private val AccountStatementWithSingleTransaction_SheetNumberOmitted = """ + :20:STARTUMS + :25:$BankCode/$CustomerId + :28C:0 + :60F:C200511EUR0,00 + :61:200511D15,00NMSCNONREF + :86:808?00Entgelt/Auslagen?10907?20Preis bezahlt bis 12.2020 + ?21Jahrespreis?22$AccountHolderName?23Folge-Nr. 0 Verfall 12.23 + ?30$BankCode?31$CustomerId?32Ausgabe einer Debitkarte + :62F:D200511EUR15,00 + - + """.trimIndent() + private fun convertMt940Date(date: Date): String { return Mt940Parser.DateFormat.format(date)