From 04586832fa2ecc9269e0d7dda8e6947cad6f1cbc Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sat, 1 Jun 2024 20:21:24 +0200 Subject: [PATCH] add cancel flag on booking --- internal/booking/models.go | 4 +- internal/booking/service.go | 1 + internal/server/handle_bookings.go | 3 + internal/view/booking_by_id.templ | 8 +- internal/view/booking_by_id_templ.go | 179 +++++++++++++++------------ internal/view/bookings_list.templ | 1 + internal/view/bookings_list_templ.go | 13 +- 7 files changed, 124 insertions(+), 85 deletions(-) diff --git a/internal/booking/models.go b/internal/booking/models.go index 2bc33b9..dcbbed2 100644 --- a/internal/booking/models.go +++ b/internal/booking/models.go @@ -5,8 +5,9 @@ import ( "strconv" "time" - "github.com/rjNemo/rentease/config" "gorm.io/gorm" + + "github.com/rjNemo/rentease/config" ) type Booking struct { @@ -21,6 +22,7 @@ type Booking struct { 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 { diff --git a/internal/booking/service.go b/internal/booking/service.go index 2ee113b..6998ae8 100644 --- a/internal/booking/service.go +++ b/internal/booking/service.go @@ -128,6 +128,7 @@ type Line struct { Id int Total float64 PlatformFees float64 + Canceled bool } func (l Line) InvoiceNumber(hc *config.Host) string { diff --git a/internal/server/handle_bookings.go b/internal/server/handle_bookings.go index 250b4cb..2a34013 100644 --- a/internal/server/handle_bookings.go +++ b/internal/server/handle_bookings.go @@ -31,6 +31,7 @@ func handleListBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFun Platform: b.Platform, Name: b.CustomerName, Total: strconv.FormatFloat(b.Total, 'f', 2, 64), + Canceled: b.Canceled, } }) @@ -93,6 +94,7 @@ func handleBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFunc { From: b.From.Format(time.DateOnly), To: b.To.Format(time.DateOnly), Platform: b.Platform, + Canceled: b.Canceled, PlatformFees: strconv.FormatFloat(b.PlatformFees, 'f', 2, 64), Url: templ.EscapeString(fmt.Sprintf("%s/%d", constant.RouteBooking, b.Id)), PdfUrl: templ.SafeURL(fmt.Sprintf("%s/pdf/%d", constant.RouteBooking, b.Id)), @@ -155,6 +157,7 @@ func handleUpdateBooking(bs *booking.Service, hc *config.Host) echo.HandlerFunc Email: b.Email, From: b.From.Format(time.DateOnly), To: b.To.Format(time.DateOnly), + Canceled: b.Canceled, Platform: b.Platform, Platforms: hc.Platforms, PlatformFees: strconv.FormatFloat(b.PlatformFees, 'f', 2, 64), diff --git a/internal/view/booking_by_id.templ b/internal/view/booking_by_id.templ index 84cd259..c0e6363 100644 --- a/internal/view/booking_by_id.templ +++ b/internal/view/booking_by_id.templ @@ -11,6 +11,7 @@ type BookingViewModel struct { PhoneNumber string CustomerNumber string Email string + Canceled bool From string To string Platform string @@ -43,9 +44,14 @@ templ BookingById(booking *BookingViewModel) {

{ booking.Id }

- Create PDF + Create PDF + if booking.Canceled { + Canceled + } else { + Cancel + }
diff --git a/internal/view/booking_by_id_templ.go b/internal/view/booking_by_id_templ.go index f6dd412..04c21bc 100644 --- a/internal/view/booking_by_id_templ.go +++ b/internal/view/booking_by_id_templ.go @@ -21,6 +21,7 @@ type BookingViewModel struct { PhoneNumber string CustomerNumber string Email string + Canceled bool From string To string Platform string @@ -71,7 +72,7 @@ func BookingById(booking *BookingViewModel) templ.Component { var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_by_id.templ`, Line: 42, Col: 22} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_by_id.templ`, Line: 43, Col: 22} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -84,13 +85,13 @@ func BookingById(booking *BookingViewModel) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Id) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_by_id.templ`, Line: 43, Col: 20} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_by_id.templ`, Line: 44, Col: 20} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Create PDF
Create PDF ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var6 string - templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Url) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_by_id.templ`, Line: 52, Col: 29} + if booking.Canceled { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Canceled") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Cancel") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("