Renamed ReferenceReferenceNumberCode to RelatedReferenceNumberCode and simplified splitting statementAndMaySequenceNumber and accountIdentification

This commit is contained in:
dankito 2020-05-21 18:02:43 +02:00
parent 4cf2fc0973
commit 55fc0ca266
1 changed files with 8 additions and 41 deletions

View File

@ -31,7 +31,7 @@ open class Mt940Parser : IMt940Parser {
val TransactionReferenceNumberCode = "20" val TransactionReferenceNumberCode = "20"
val ReferenceReferenceNumberCode = "21" val RelatedReferenceNumberCode = "21"
val AccountIdentificationCode = "25" val AccountIdentificationCode = "25"
@ -147,18 +147,18 @@ open class Mt940Parser : IMt940Parser {
} }
protected open fun parseAccountStatement(fieldsByCode: List<Pair<String, String>>): AccountStatement? { protected open fun parseAccountStatement(fieldsByCode: List<Pair<String, String>>): AccountStatement? {
val statementAndMaySequenceNumber = getFieldValue(fieldsByCode, StatementNumberCode) val statementAndMaySequenceNumber = getFieldValue(fieldsByCode, StatementNumberCode).split('/')
val accountIdentification = getFieldValue(fieldsByCode, AccountIdentificationCode) val accountIdentification = getFieldValue(fieldsByCode, AccountIdentificationCode).split('/')
val openingBalancePair = fieldsByCode.first { it.first.startsWith(OpeningBalanceCode) } val openingBalancePair = fieldsByCode.first { it.first.startsWith(OpeningBalanceCode) }
val closingBalancePair = fieldsByCode.first { it.first.startsWith(ClosingBalanceCode) } val closingBalancePair = fieldsByCode.first { it.first.startsWith(ClosingBalanceCode) }
return AccountStatement( return AccountStatement(
getFieldValue(fieldsByCode, TransactionReferenceNumberCode), getFieldValue(fieldsByCode, TransactionReferenceNumberCode),
getOptionalFieldValue(fieldsByCode, ReferenceReferenceNumberCode), getOptionalFieldValue(fieldsByCode, RelatedReferenceNumberCode),
parseBankCodeSwiftCodeOrIban(accountIdentification), accountIdentification[0],
parseAccountNumber(accountIdentification), if (accountIdentification.size > 1) accountIdentification[1] else null,
parseStatementNumber(statementAndMaySequenceNumber), statementAndMaySequenceNumber[0].toInt(),
parseSheetNumber(statementAndMaySequenceNumber), if (statementAndMaySequenceNumber.size > 1) statementAndMaySequenceNumber[1].toInt() else null,
parseBalance(openingBalancePair.first, openingBalancePair.second), parseBalance(openingBalancePair.first, openingBalancePair.second),
parseAccountStatementTransactions(fieldsByCode), parseAccountStatementTransactions(fieldsByCode),
parseBalance(closingBalancePair.first, closingBalancePair.second) parseBalance(closingBalancePair.first, closingBalancePair.second)
@ -173,39 +173,6 @@ open class Mt940Parser : IMt940Parser {
return fieldsByCode.firstOrNull { it.first == code }?.second return fieldsByCode.firstOrNull { it.first == code }?.second
} }
protected open fun parseBankCodeSwiftCodeOrIban(accountIdentification: String): String {
val parts = accountIdentification.split('/')
return parts[0]
}
protected open fun parseAccountNumber(accountIdentification: String): String? {
val parts = accountIdentification.split('/')
if (parts.size > 0) {
return parts[1]
}
return null
}
protected open fun parseStatementNumber(statementAndMaySheetNumber: String): Int {
val parts = statementAndMaySheetNumber.split('/')
// val isSupported = statementNumber != "00000"
return parts[0].toInt()
}
protected open fun parseSheetNumber(statementAndMaySheetNumber: String): Int? {
val parts = statementAndMaySheetNumber.split('/')
if (parts.size > 1) {
return parts[1].toInt()
}
return null
}
protected open fun parseBalance(code: String, fieldValue: String): Balance { protected open fun parseBalance(code: String, fieldValue: String): Balance {
val isIntermediate = code.endsWith("M") val isIntermediate = code.endsWith("M")