Add blocked_date table (migration 5), model, and store CRUD methods. Add management page at /blocked with add/delete functionality. Add nav link 'Terminy zablokowane' with event_busy icon. Pass blocked dates to order form as JSON data attribute. On form submit, if the order has special cakes and the date is blocked, show a confirm() dialog warning the user.
110 lines
1.7 KiB
Go
110 lines
1.7 KiB
Go
package models
|
|
|
|
import (
|
|
"fmt"
|
|
"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 fmt.Sprintf("(%s)", joinParts(parts))
|
|
}
|
|
|
|
func joinParts(parts []string) string {
|
|
out := parts[0]
|
|
for i := 1; i < len(parts); i++ {
|
|
out += ", " + parts[i]
|
|
}
|
|
return out
|
|
}
|
|
|
|
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
|
|
}
|