trying to fix price

This commit is contained in:
bronkuu 2026-06-15 13:34:18 +02:00
parent 7feee7f8a3
commit 8194cea85e
10 changed files with 145 additions and 54 deletions

View file

@ -5,7 +5,7 @@ import "time"
type Cake struct {
Name string
ID int
Price int // increments of 0.01
Price Price // increments of 0.01
Amount int
}
@ -18,18 +18,22 @@ type Order struct {
Date time.Time
Accepted time.Time
Status string
Paid int // increments of 0.01
Paid Price // increments of 0.01
Cakes []Cake
}
func (o *Order) Total() int {
out := o.Paid * (-1)
func (o *Order) Subtotal() Price {
var out Price
for _, e := range o.Cakes {
out += e.Price * e.Amount
out += e.Price * Price(e.Amount)
}
return out
}
func (o *Order) Total() Price {
return o.Subtotal() - o.Paid
}
func (c *Cake) Total() int {
return c.Amount * c.Price
func (c *Cake) Total() Price {
return Price(c.Amount) * c.Price
}