diff --git a/constants/items.go b/constants/items.go index 28f0c57..1b05c52 100644 --- a/constants/items.go +++ b/constants/items.go @@ -1,3 +1,3 @@ package constants -var Items = []string{"T2", "T3", "Airport", "Port"} +var Items = []string{"T2", "T3", "Airport", "Port", "Taxes"} diff --git a/internal/domains/booking/models.go b/internal/domains/booking/models.go index 189dacd..93a0de5 100644 --- a/internal/domains/booking/models.go +++ b/internal/domains/booking/models.go @@ -11,7 +11,7 @@ type Booking struct { Id int Name string `gorm:"column:customer_name"` PhoneNumber string - CustomerNumber string `gorm:"column:customers"` + CustomerNumber int `gorm:"column:customers"` Email string From time.Time To time.Time diff --git a/internal/server/handlers.go b/internal/server/handlers.go index e387645..d5844db 100644 --- a/internal/server/handlers.go +++ b/internal/server/handlers.go @@ -60,7 +60,7 @@ func (s Server) handleCreateBooking() echo.HandlerFunc { type NewBooking struct { Name string `form:"name"` PhoneNumber string `form:"phone_number"` - CustomerNumber string `form:"customer_number"` + CustomerNumber int `form:"customer_number"` Email string `form:"email"` From time.Time `json:"from"` To time.Time `from:"to"` @@ -104,7 +104,35 @@ func (s Server) handleBookingPage() echo.HandlerFunc { b := &booking.Booking{Id: id} s.db.Preload("Items").First(b) - component := views.BookingById(b, constants.Items, constants.Platforms, constants.PaymentMethods) + bvm := &views.BookingViewModel{ + Id: fmt.Sprintf("%04s", strconv.Itoa(b.Id)), + Name: b.Name, + PhoneNumber: b.PhoneNumber, + CustomerNumber: strconv.Itoa(b.CustomerNumber), + Email: b.Email, + From: b.From.Format("2006-01-02"), + To: b.To.Format("2006-01-02"), + Platform: b.Platform, + PlatformFees: strconv.FormatFloat(b.PlatformFees, 'f', 2, 64), + Url: templ.EscapeString(fmt.Sprintf("%s/%d/items", constants.RouteBooking, b.Id)), + Items: u.Map(b.Items, func(i booking.Item) views.ItemViewModel { + return views.ItemViewModel{ + Item: i.Item, + Quantity: strconv.Itoa(i.Quantity), + Price: strconv.FormatFloat(i.Price, 'f', 2, 64), + SubTotal: strconv.FormatFloat(i.Price*float64(i.Quantity), 'f', 2, 64), + PaymentMethod: i.PaymentMethod, + PaymentStatus: i.PaymentStatus, + } + }), + Total: strconv.FormatFloat(u.Reduce(b.Items, func(i booking.Item, sum float64) float64 { + return sum + i.Price*float64(i.Quantity) + }, 0.0), 'f', 2, 64), + Platforms: constants.Platforms, + ItemList: constants.Items, + PaymentMethods: constants.PaymentMethods, + } + component := views.BookingById(bvm) return s.renderTempl(c, http.StatusOK, component) } } diff --git a/internal/views/booking_by_id.templ b/internal/views/booking_by_id.templ index efbb1ed..3b66686 100644 --- a/internal/views/booking_by_id.templ +++ b/internal/views/booking_by_id.templ @@ -1,17 +1,37 @@ package views -import ( - "fmt" - "strconv" +type BookingViewModel struct { + Id string + Name string + PhoneNumber string + CustomerNumber string + Email string + From string + To string + Platform string + Platforms []string + PlatformFees string + Items []ItemViewModel + ItemList []string + PaymentMethods []string + Url string + Total string +} - "github.com/rjNemo/rentease/internal/domains/booking" -) +type ItemViewModel struct { + Item string + Quantity string + Price string + SubTotal string + PaymentMethod string + PaymentStatus string +} -templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []string) { +templ BookingById(booking *BookingViewModel) { @BaseLayout() {
-

Booking ID VFNI#{ fmt.Sprintf("%04s", strconv.Itoa(booking.Id)) }

+

Booking ID VFNI#{ booking.Id }

Manage a booking

@@ -21,12 +41,12 @@ templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []s
@@ -42,11 +62,11 @@ templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []s
@@ -54,14 +74,14 @@ templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []s Platform
@@ -74,9 +94,10 @@ templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []s # Item Quantity - Price + Price (€) Payment Method Payment Status + Sub-total (€) @@ -84,23 +105,33 @@ templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []s { item.Item } - { strconv.Itoa(item.Quantity) } - { strconv.FormatFloat(item.Price, 'f', 2, 64) } + { item.Quantity } + { item.Price } { item.PaymentMethod } { item.PaymentStatus } + { item.SubTotal } } + + + + + + + + { booking.Total } +
Add line - +
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }