proper handling of currency values
This commit is contained in:
parent
060eb86c59
commit
a24c5e2c89
4 changed files with 36 additions and 17 deletions
|
|
@ -19,7 +19,7 @@ import scala.util.Success
|
||||||
|
|
||||||
object DexieDB {
|
object DexieDB {
|
||||||
|
|
||||||
private val schemaVersion = 1.1
|
private val schemaVersion = 1.3
|
||||||
|
|
||||||
private val dexieDB: Dexie = new Dexie.^("fahrtenbuch")
|
private val dexieDB: Dexie = new Dexie.^("fahrtenbuch")
|
||||||
dexieDB
|
dexieDB
|
||||||
|
|
|
||||||
|
|
@ -111,13 +111,21 @@ class EntryComponent(
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
tr(
|
tr(
|
||||||
td(new Date(entry.date.payload).toISOString()),
|
td(new Date(entry.date.payload).toDateString()),
|
||||||
td(entry.driver.payload),
|
td(entry.driver.payload),
|
||||||
td(entry.startKm.payload),
|
td(
|
||||||
td(entry.endKm.payload),
|
entry.startKm.payload
|
||||||
|
.setScale(0, BigDecimal.RoundingMode.HALF_UP)
|
||||||
|
.toString()
|
||||||
|
),
|
||||||
|
td(
|
||||||
|
entry.endKm.payload
|
||||||
|
.setScale(0, BigDecimal.RoundingMode.HALF_UP)
|
||||||
|
.toString()
|
||||||
|
),
|
||||||
td(entry.animal.payload),
|
td(entry.animal.payload),
|
||||||
td(s"${entry.costWear}€"),
|
td(s"${entry.costWear.setScale(2, BigDecimal.RoundingMode.HALF_UP)}€"),
|
||||||
td(s"${entry.costTotal}€"),
|
td(s"${entry.costTotal.setScale(2, BigDecimal.RoundingMode.HALF_UP)}€"),
|
||||||
td(if entry.paid.payload then "Ja" else "Nein"),
|
td(if entry.paid.payload then "Ja" else "Nein"),
|
||||||
td(
|
td(
|
||||||
button(
|
button(
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,9 @@ class NewEntryInput(showNewEntryField: Var[Boolean]):
|
||||||
onClick --> {
|
onClick --> {
|
||||||
val id = EntryId.gen()
|
val id = EntryId.gen()
|
||||||
val driver = LastWriterWins.now(newEntryDriver.ref.value)
|
val driver = LastWriterWins.now(newEntryDriver.ref.value)
|
||||||
val startKm = LastWriterWins.now(newEntryStartKm.ref.value.toDouble)
|
val startKm =
|
||||||
val endKm = LastWriterWins.now(newEntryEndKm.ref.value.toDouble)
|
LastWriterWins.now(BigDecimal(newEntryStartKm.ref.value))
|
||||||
|
val endKm = LastWriterWins.now(BigDecimal(newEntryEndKm.ref.value))
|
||||||
val animal = LastWriterWins.now(newEntryAnimal.ref.value)
|
val animal = LastWriterWins.now(newEntryAnimal.ref.value)
|
||||||
val paid = LastWriterWins.now(newEntryPaid.ref.checked)
|
val paid = LastWriterWins.now(newEntryPaid.ref.checked)
|
||||||
entryEditBus.emit(
|
entryEditBus.emit(
|
||||||
|
|
|
||||||
|
|
@ -26,27 +26,37 @@ object EntryId:
|
||||||
|
|
||||||
case class Entry(
|
case class Entry(
|
||||||
id: EntryId,
|
id: EntryId,
|
||||||
startKm: LastWriterWins[Double],
|
startKm: LastWriterWins[BigDecimal],
|
||||||
endKm: LastWriterWins[Double],
|
endKm: LastWriterWins[BigDecimal],
|
||||||
animal: LastWriterWins[String],
|
animal: LastWriterWins[String],
|
||||||
paid: LastWriterWins[Boolean],
|
paid: LastWriterWins[Boolean],
|
||||||
driver: LastWriterWins[String],
|
driver: LastWriterWins[String],
|
||||||
date: LastWriterWins[Double]
|
date: LastWriterWins[Double],
|
||||||
|
gasPricePerKm: LastWriterWins[BigDecimal] = LastWriterWins.now(0.13),
|
||||||
|
wearPricePerKm: LastWriterWins[BigDecimal] = LastWriterWins.now(0.05)
|
||||||
) derives NativeConverter:
|
) derives NativeConverter:
|
||||||
val distance = endKm.payload - startKm.payload
|
val distance = endKm.payload - startKm.payload
|
||||||
|
|
||||||
// 13 cent pro km, 5 cent Abnutzung
|
// initial 13 cent pro km, 5 cent Abnutzung
|
||||||
def costGas: Double = distance * 0.13
|
def costGas: BigDecimal = distance * gasPricePerKm.payload
|
||||||
def costWear: Double = distance * 0.05
|
def costWear: BigDecimal = distance * wearPricePerKm.payload
|
||||||
def costTotal: Double = costGas + costWear
|
def costTotal: BigDecimal = costGas + costWear
|
||||||
|
|
||||||
object Entry:
|
object Entry:
|
||||||
given Lattice[Entry] = Lattice.derived
|
given Lattice[Entry] = Lattice.derived
|
||||||
|
|
||||||
|
given NativeConverter[BigDecimal] with {
|
||||||
|
extension (a: BigDecimal)
|
||||||
|
override def toNative: js.Any =
|
||||||
|
a.toString()
|
||||||
|
override def fromNative(ps: ParseState): BigDecimal =
|
||||||
|
BigDecimal(ps.json.asInstanceOf[String])
|
||||||
|
}
|
||||||
|
|
||||||
def apply(
|
def apply(
|
||||||
id: EntryId,
|
id: EntryId,
|
||||||
startKm: LastWriterWins[Double],
|
startKm: LastWriterWins[BigDecimal],
|
||||||
endKm: LastWriterWins[Double],
|
endKm: LastWriterWins[BigDecimal],
|
||||||
animal: LastWriterWins[String],
|
animal: LastWriterWins[String],
|
||||||
paid: LastWriterWins[Boolean],
|
paid: LastWriterWins[Boolean],
|
||||||
driver: LastWriterWins[String]
|
driver: LastWriterWins[String]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue