rounding in virtual decay transaction, pass hold available amount to virtual decay creation

This commit is contained in:
Moriz Wahl 2022-03-31 22:17:36 +02:00
parent 9ed00edc52
commit 681d34b1dc
2 changed files with 13 additions and 4 deletions

View File

@ -201,7 +201,13 @@ export class TransactionResolver {
// The virtual decay is always on the booked amount, not including the generated, not yet booked links,
// since the decay is substantially different when the amount is less
transactions.push(
virtualDecayTransaction(lastTransaction.balance, lastTransaction.balanceDate, now, self),
virtualDecayTransaction(
lastTransaction.balance,
lastTransaction.balanceDate,
now,
self,
sumHoldAvailableAmount,
),
)
// virtual transaction for pending transaction-links sum
if (sumHoldAvailableAmount.greaterThan(0)) {

View File

@ -59,6 +59,7 @@ const virtualDecayTransaction = (
balanceDate: Date,
time: Date = new Date(),
user: User,
holdAvailabeAmount: Decimal,
): Transaction => {
const decay = calculateDecay(balance, balanceDate, time)
// const balance = decay.balance.minus(lastTransaction.balance)
@ -67,10 +68,12 @@ const virtualDecayTransaction = (
userId: -1,
previous: -1,
typeId: TransactionTypeId.DECAY,
amount: decay.decay ? decay.decay : new Decimal(0), // new Decimal(0), // this kinda is wrong, but helps with the frontend query
balance: decay.balance,
amount: decay.decay ? decay.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR) : new Decimal(0), // new Decimal(0), // this kinda is wrong, but helps with the frontend query
balance: decay.balance
.minus(holdAvailabeAmount.toString())
.toDecimalPlaces(2, Decimal.ROUND_DOWN),
balanceDate: time,
decay: decay.decay ? decay.decay : new Decimal(0),
decay: decay.decay ? decay.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR) : new Decimal(0),
decayStart: decay.start,
memo: '',
creationDate: null,