diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/InstituteSegmentId.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/InstituteSegmentId.kt index 2f8d808b..93a929d5 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/InstituteSegmentId.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/InstituteSegmentId.kt @@ -37,6 +37,8 @@ enum class InstituteSegmentId(override val id: String) : ISegmentId { Balance("HISAL"), - AccountTransactionsMt940("HIKAZ") + AccountTransactionsMt940("HIKAZ"), + + AccountTransactionsMt940Parameters(AccountTransactionsMt940.id + "S") } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt index 658a7078..bf71990f 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt @@ -112,7 +112,9 @@ open class ResponseParser( InstituteSegmentId.ChangeTanMediaParameters.id -> parseChangeTanMediaParameters(segment, segmentId, dataElementGroups) InstituteSegmentId.Balance.id -> parseBalanceSegment(segment, dataElementGroups) + InstituteSegmentId.AccountTransactionsMt940.id -> parseMt940AccountTransactions(segment, dataElementGroups) + InstituteSegmentId.AccountTransactionsMt940Parameters.id -> parseMt940AccountTransactionsParameters(segment, segmentId, dataElementGroups) else -> { if (JobParametersSegmentRegex.matches(segmentId)) { @@ -657,6 +659,19 @@ open class ResponseParser( return ReceivedAccountTransactions(bookedTransactionsString, unbookedTransactionsString, segment) } + protected open fun parseMt940AccountTransactionsParameters(segment: String, segmentId: String, dataElementGroups: List): RetrieveAccountTransactionsInMt940Parameters { + val jobParameters = parseJobParameters(segment, segmentId, dataElementGroups) + + val transactionsParameterIndex = if (jobParameters.segmentVersion >= 6) 4 else 3 + val dataElements = getDataElements(dataElementGroups[transactionsParameterIndex]) + + val countDaysForWhichTransactionsAreKept = parseInt(dataElements[0]) + val settingCountEntriesAllowed = parseBoolean(dataElements[1]) + val settingAllAccountAllowed = if (dataElements.size > 2) parseBoolean(dataElements[2]) else false + + return RetrieveAccountTransactionsInMt940Parameters(jobParameters, countDaysForWhichTransactionsAreKept, settingCountEntriesAllowed, settingAllAccountAllowed) + } + protected open fun parseBankDetails(dataElementsGroup: String): Kreditinstitutskennung { val detailsStrings = getDataElements(dataElementsGroup) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/RetrieveAccountTransactionsInMt940Parameters.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/RetrieveAccountTransactionsInMt940Parameters.kt new file mode 100644 index 00000000..2af9bc70 --- /dev/null +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/RetrieveAccountTransactionsInMt940Parameters.kt @@ -0,0 +1,13 @@ +package net.dankito.banking.fints.response.segments + + +open class RetrieveAccountTransactionsInMt940Parameters( + parameters: JobParameters, + open val countDaysForWhichTransactionsAreKept: Int, + open val settingCountEntriesAllowed: Boolean, + open val settingAllAccountAllowed: Boolean +) : JobParameters(parameters) { + + internal constructor() : this(JobParameters(), -1, false, false) // for object deserializers + +} \ No newline at end of file diff --git a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt index f9ca0fd3..d7d7c4e9 100644 --- a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt +++ b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt @@ -1043,6 +1043,47 @@ class ResponseParserTest : FinTsTestBase() { } + @Test + fun parseAccountTransactionsMt940Parameters_Version4() { + + // given + val countDaysForWhichTransactionsAreKept = 90 + + // when + val result = underTest.parse("HIKAZS:21:4:4+20+1+$countDaysForWhichTransactionsAreKept:N'") + + // then + assertSuccessfullyParsedSegment(result, InstituteSegmentId.AccountTransactionsMt940Parameters, 21, 4, 4) + + result.getFirstSegmentById(InstituteSegmentId.AccountTransactionsMt940Parameters)?.let { segment -> + expect(segment.countDaysForWhichTransactionsAreKept).toBe(countDaysForWhichTransactionsAreKept) + expect(segment.settingCountEntriesAllowed).isFalse() + expect(segment.settingAllAccountAllowed).isFalse() + } + ?: run { fail("No segment of type AccountTransactionsMt940Parameters found in ${result.receivedSegments}") } + } + + @Test + fun parseAccountTransactionsMt940Parameters_Version6() { + + // given + val countDaysForWhichTransactionsAreKept = 90 + + // when + val result = underTest.parse("HIKAZS:23:6:4+20+1+1+$countDaysForWhichTransactionsAreKept:N:N'") + + // then + assertSuccessfullyParsedSegment(result, InstituteSegmentId.AccountTransactionsMt940Parameters, 23, 6, 4) + + result.getFirstSegmentById(InstituteSegmentId.AccountTransactionsMt940Parameters)?.let { segment -> + expect(segment.countDaysForWhichTransactionsAreKept).toBe(countDaysForWhichTransactionsAreKept) + expect(segment.settingCountEntriesAllowed).isFalse() + expect(segment.settingAllAccountAllowed).isFalse() + } + ?: run { fail("No segment of type AccountTransactionsMt940Parameters found in ${result.receivedSegments}") } + } + + private fun assertSuccessfullyParsedSegment(result: Response, segmentId: ISegmentId, segmentNumber: Int, segmentVersion: Int, referenceSegmentNumber: Int? = null) {