cake-order-tracker/models/data.go
2026-06-15 20:00:04 +02:00

102 lines
1.6 KiB
Go

package models
import (
"strings"
"time"
)
type Tag struct {
ID int
Name string
}
type Cake struct {
Name string
ID int
Price Price // increments of 0.01
Amount int
Tags []Tag
}
type SpecialCake struct {
ID int
OrderID int
Name string
Price Price
Size string
Shape string
Flavour string
Notes string
Tags []Tag
}
func (s SpecialCake) Detail() string {
parts := make([]string, 0, 4)
if s.Size != "" {
parts = append(parts, s.Size)
}
if s.Flavour != "" {
parts = append(parts, s.Flavour)
}
if s.Shape == "square" {
parts = append(parts, "kwadrat")
} else if s.Shape == "round" {
parts = append(parts, "okrągły")
}
if s.Notes != "" {
parts = append(parts, "notatka: "+s.Notes)
}
if len(parts) == 0 {
return ""
}
return "(" + strings.Join(parts, ", ") + ")"
}
type Order struct {
ID int
Name string
Surname string
Phone string
Location string
Date time.Time
Accepted time.Time
Status string
Paid Price // increments of 0.01
Cakes []Cake
SpecialCakes []SpecialCake
}
func (o *Order) Subtotal() Price {
var out Price
for _, e := range o.Cakes {
out += e.Price * Price(e.Amount)
}
for _, s := range o.SpecialCakes {
out += s.Price
}
return out
}
func (o *Order) Total() Price {
return o.Subtotal() - o.Paid
}
func (c *Cake) Total() Price {
return Price(c.Amount) * c.Price
}
type OrderCounts struct {
Active int
DueToday int
}
type CakeCount struct {
ID int
Name string
Amount int
}
type BlockedDate struct {
ID int
Date string
}