summaryrefslogtreecommitdiff
path: root/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
diff options
context:
space:
mode:
authorMS <ms@taler.net>2021-08-23 03:32:48 -1100
committerMS <ms@taler.net>2021-08-23 03:32:48 -1100
commita5ad795d34402fe8e1f69c4c2edcaab670519853 (patch)
tree1b33249534286a9c620f175611dbb84382221ff5 /sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
parentf780713a659f4d2aa3d81adba1d02101454d3c34 (diff)
downloadlibeufin-a5ad795d34402fe8e1f69c4c2edcaab670519853.tar.gz
libeufin-a5ad795d34402fe8e1f69c4c2edcaab670519853.tar.bz2
libeufin-a5ad795d34402fe8e1f69c4c2edcaab670519853.zip
Fix balance calculation.
Do not search by IBAN, but by bank account name instead.
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt')
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt10
1 files changed, 6 insertions, 4 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
index aac82469..a2e09ee6 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -1,6 +1,7 @@
package tech.libeufin.sandbox
import io.ktor.http.*
+import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.or
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
@@ -27,18 +28,19 @@ fun getAccountFromLabel(accountLabel: String): BankAccountEntity {
}
}
-fun balanceForAccount(iban: String): BigDecimal {
- logger.debug("Calculating balance for account: ${iban}")
+fun balanceForAccount(bankAccount: BankAccountEntity): BigDecimal {
var balance = BigDecimal.ZERO
transaction {
BankAccountTransactionsTable.select {
- BankAccountTransactionsTable.creditorIban eq iban
+ BankAccountTransactionsTable.direction eq "CRDT" and (
+ BankAccountTransactionsTable.account eq bankAccount.id)
}.forEach {
val amount = parseDecimal(it[amount])
balance += amount
}
BankAccountTransactionsTable.select {
- BankAccountTransactionsTable.debtorIban eq iban
+ BankAccountTransactionsTable.direction eq "DBIT" and (
+ BankAccountTransactionsTable.account eq bankAccount.id)
}.forEach {
val amount = parseDecimal(it[amount])
balance -= amount