[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Camt: coordinating PRCD and CLBD balan
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Camt: coordinating PRCD and CLBD balances. |
Date: |
Tue, 24 Aug 2021 12:55:55 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new d2fdce4 Camt: coordinating PRCD and CLBD balances.
d2fdce4 is described below
commit d2fdce416c4d8abf74e293501a701fa45bfbb9ee
Author: MS <ms@taler.net>
AuthorDate: Mon Aug 23 23:54:21 2021 -1100
Camt: coordinating PRCD and CLBD balances.
---
.../tech/libeufin/sandbox/EbicsProtocolBackend.kt | 19 +++++++++++-----
.../kotlin/tech/libeufin/sandbox/bankAccount.kt | 26 ++++++++++++++++++++--
2 files changed, 38 insertions(+), 7 deletions(-)
diff --git
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index 9c17085..1c5482d 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -43,6 +43,7 @@ import tech.libeufin.util.ebics_hev.HEVResponse
import tech.libeufin.util.ebics_hev.SystemReturnCodeType
import tech.libeufin.util.ebics_s001.SignatureTypes
import tech.libeufin.util.ebics_s001.UserSignatureData
+import java.math.BigDecimal
import java.security.interfaces.RSAPrivateCrtKey
import java.security.interfaces.RSAPublicKey
import java.time.Instant
@@ -212,6 +213,7 @@ fun buildCamtString(type: Int, subscriberIban: String,
history: List<RawPayment>
val now = LocalDateTime.now()
val dashedDate = now.toDashedDate()
val zonedDateTime = now.toZonedString()
+ val balance = balanceForAccount(history)
return constructXml(indent = true) {
root("Document") {
attribute("xmlns",
"urn:iso:std:iso:20022:tech:xsd:camt.0${type}.001.02")
@@ -286,11 +288,9 @@ fun buildCamtString(type: Int, subscriberIban: String,
history: List<RawPayment>
}
element("Amt") {
attribute("Ccy", "EUR")
- text(Amount(0).toPlainString())
+ text("0")
}
element("CdtDbtInd") {
- // a temporary value to get the camt to validate.
- // Should be fixed along #6269
text("CRDT")
}
element("Dt/Dt") {
@@ -309,12 +309,21 @@ fun buildCamtString(type: Int, subscriberIban: String,
history: List<RawPayment>
attribute("Ccy", "EUR")
// FIXME: the balance computation still not
working properly
//text(balanceForAccount(subscriberIban).toString())
- text("0")
+ if (balance < BigDecimal.ZERO) {
+ text(balance.abs().toPlainString())
+ } else {
+ text(balance.toPlainString())
+ }
+
}
element("CdtDbtInd") {
// a temporary value to get the camt to validate.
// Should be fixed along #6269
- text("DBIT")
+ if (balance < BigDecimal.ZERO) {
+ text("DBIT")
+ } else {
+ text("CRDT")
+ }
}
element("Dt/Dt") {
text(dashedDate)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
index cafe2ea..18748ef 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -27,6 +27,27 @@ fun getAccountFromLabel(accountLabel: String):
BankAccountEntity {
account
}
}
+// Mainly useful inside the CAMT generator.
+fun balanceForAccount(history: List<RawPayment>): BigDecimal {
+ var ret = BigDecimal.ZERO
+ history.forEach direction@ {
+ if (it.direction == "CRDT") {
+ val amount = parseDecimal(it.amount)
+ ret += amount
+ return@direction
+ }
+ if (it.direction == "DBIT") {
+ val amount = parseDecimal(it.amount)
+ ret -= amount
+ return@direction
+ }
+ throw SandboxError(
+ HttpStatusCode.InternalServerError,
+ "A payment direction was found neither CRDT not DBIT"
+ )
+ }
+ return ret
+}
fun balanceForAccount(bankAccount: BankAccountEntity): BigDecimal {
var balance = BigDecimal.ZERO
@@ -66,8 +87,7 @@ fun historyForAccount(bankAccount: BankAccountEntity):
List<RawPayment> {
FIXME: add the following condition too:
and (BankAccountTransactionsTable.date.between(start.millis,
end.millis))
*/
- BankAccountTransactionsTable.select {
BankAccountTransactionsTable.account eq bankAccount.id }
- }.forEach {
+ BankAccountTransactionsTable.select {
BankAccountTransactionsTable.account eq bankAccount.id }.forEach {
history.add(
RawPayment(
subject = it[BankAccountTransactionsTable.subject],
@@ -88,6 +108,8 @@ fun historyForAccount(bankAccount: BankAccountEntity):
List<RawPayment> {
pmtInfId = it[BankAccountTransactionsTable.pmtInfId]
)
)
+
}
+ }
return history
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Camt: coordinating PRCD and CLBD balances.,
gnunet <=