mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
package booking
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"time"
|
|
|
|
u "github.com/rjNemo/underscore"
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/rjNemo/rentease/internal/config"
|
|
)
|
|
|
|
type Booking struct {
|
|
From time.Time
|
|
To time.Time
|
|
gorm.Model
|
|
Name string `gorm:"column:customer_name"`
|
|
PhoneNumber string
|
|
Email string
|
|
Platform string
|
|
ExternalId *string `gorm:"uniqueIndex:booking_external_id"`
|
|
Items []Item
|
|
Id int
|
|
CustomerNumber int `gorm:"column:customers"`
|
|
PlatformFees float64 `gorm:"type:decimal(10,2)"`
|
|
Canceled bool `gorm:"default:false"`
|
|
}
|
|
|
|
func (b Booking) InvoiceNumber(hc *config.Host) string {
|
|
return fmt.Sprintf("%s%04s", hc.InvoicePrefix, strconv.Itoa(b.Id+hc.CustomerSeed))
|
|
}
|
|
|
|
func (b Booking) Serialize(hc *config.Host) map[string]any {
|
|
return map[string]any{
|
|
"host": map[string]any{
|
|
"name": hc.Name,
|
|
"address": hc.Address,
|
|
"zip": hc.ZipCode,
|
|
"city": hc.City,
|
|
"phone": hc.PhoneNumber,
|
|
"email": hc.Email,
|
|
},
|
|
"id": b.InvoiceNumber(hc),
|
|
"name": b.Name,
|
|
"phone_number": b.PhoneNumber,
|
|
"customers_number": b.CustomerNumber,
|
|
"platform": b.Platform,
|
|
"from": b.From.Format("02/01/2006"),
|
|
"to": b.To.Format("02/01/2006"),
|
|
"lines": u.Map(b.Items, func(i Item) map[string]any {
|
|
return map[string]any{
|
|
"name": i.Item,
|
|
"quantity": i.Quantity,
|
|
"price": i.Price,
|
|
"total": i.Price * float64(i.Quantity),
|
|
}
|
|
}),
|
|
"total": strconv.FormatFloat(u.Reduce(b.Items, func(i Item, sum float64) float64 {
|
|
return sum + i.Price*float64(i.Quantity)
|
|
}, 0.0), 'f', 2, 64),
|
|
}
|
|
}
|
|
|
|
type BookingRequest struct {
|
|
gorm.Model
|
|
From time.Time
|
|
To time.Time
|
|
PhoneNumber *string
|
|
Email *string
|
|
BookingId *int
|
|
CustomerName string
|
|
ItemType string
|
|
Message string
|
|
Status string
|
|
CustomerNumber int
|
|
}
|
|
|
|
type Item struct {
|
|
gorm.Model
|
|
Item string
|
|
PaymentMethod string
|
|
PaymentStatus string `gorm:"default:Pending"`
|
|
Id int
|
|
BookingId int
|
|
Quantity int
|
|
Price float64 `gorm:"type:decimal(10,2)"`
|
|
}
|