From a14fdc5304a9f9651c9aff1680c73ba43a838d71 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sun, 19 Jan 2025 11:48:58 +0100 Subject: [PATCH] feat: show payments in the booking details view --- internal/constant/routes.go | 1 + internal/server/handle_bookings.go | 14 ++- internal/server/routes.go | 2 +- internal/view/item_viewmodel.go | 8 +- internal/view/line_item.templ | 21 +++- internal/view/line_item_templ.go | 180 +++++++++++++++++------------ 6 files changed, 142 insertions(+), 84 deletions(-) diff --git a/internal/constant/routes.go b/internal/constant/routes.go index 1e04076..4165fe2 100644 --- a/internal/constant/routes.go +++ b/internal/constant/routes.go @@ -5,4 +5,5 @@ const ( RouteBooking = "/bookings" RouteReports = "/reports" RouteItem = "/items" + RoutePayment = "/payments" ) diff --git a/internal/server/handle_bookings.go b/internal/server/handle_bookings.go index 8015a43..68c29fc 100644 --- a/internal/server/handle_bookings.go +++ b/internal/server/handle_bookings.go @@ -52,7 +52,7 @@ func handleBookingListPage(bs *booking.Service, hc *config.Host) echo.HandlerFun } } -func handleBookingList(bs *booking.Service, hc *config.Host) echo.HandlerFunc { +func handleBookingList(bs *booking.Service) echo.HandlerFunc { return func(c echo.Context) error { search := c.FormValue("search") @@ -144,9 +144,15 @@ func handleBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFunc { 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, ItemUrl: fmt.Sprintf("%s/%d", constant.RouteItem, i.Id), + Payments: []view.Payment{ + { + Amount: "12.00", + PaymentMethod: "Card", + PaymentUrl: fmt.Sprintf("%s/%d", constant.RoutePayment, b.Id), + }, + }, } }), Total: strconv.FormatFloat(u.Reduce(b.Items, func(i booking.Item, sum float64) float64 { @@ -234,7 +240,6 @@ func handleLineItemForm(bs *booking.Service) echo.HandlerFunc { Item: i.Item, Quantity: strconv.Itoa(i.Quantity), Price: strconv.FormatFloat(i.Price, 'f', 2, 64), - PaymentMethod: i.PaymentMethod, PaymentStatus: i.PaymentStatus, SubTotal: strconv.FormatFloat(i.Price*float64(i.Quantity), 'f', 2, 64), ItemUrl: fmt.Sprintf("%s/%d", constant.RouteItem, i.Id), @@ -290,7 +295,6 @@ func handleCreateItem(bs *booking.Service, hc *config.Host) echo.HandlerFunc { Item: i.Item, Quantity: strconv.Itoa(i.Quantity), Price: strconv.FormatFloat(i.Price, 'f', 2, 64), - PaymentMethod: i.PaymentMethod, PaymentStatus: i.PaymentStatus, SubTotal: strconv.FormatFloat(i.Price*float64(i.Quantity), 'f', 2, 64), ItemUrl: fmt.Sprintf("%s/%d", constant.RouteItem, i.Id), @@ -315,7 +319,6 @@ func handleItemPay(bs *booking.Service) echo.HandlerFunc { Item: i.Item, Quantity: strconv.Itoa(i.Quantity), Price: strconv.FormatFloat(i.Price, 'f', 2, 64), - PaymentMethod: i.PaymentMethod, PaymentStatus: i.PaymentStatus, SubTotal: strconv.FormatFloat(i.Price*float64(i.Quantity), 'f', 2, 64), ItemUrl: fmt.Sprintf("%s/%d", constant.RouteItem, i.Id), @@ -347,7 +350,6 @@ func handleItemUpdate(bs *booking.Service) echo.HandlerFunc { Item: i.Item, Quantity: strconv.Itoa(i.Quantity), Price: strconv.FormatFloat(i.Price, 'f', 2, 64), - PaymentMethod: i.PaymentMethod, PaymentStatus: i.PaymentStatus, SubTotal: strconv.FormatFloat(i.Price*float64(i.Quantity), 'f', 2, 64), ItemUrl: fmt.Sprintf("%s/%d", constant.RouteItem, i.Id), diff --git a/internal/server/routes.go b/internal/server/routes.go index 2f34263..75106d8 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -18,7 +18,7 @@ func (s Server) MountHandlers() { }, })) api.POST("/sync", handleSync(s.bs)) - api.GET("/bookings", handleBookingList(s.bs, s.hc)) + api.GET("/bookings", handleBookingList(s.bs)) private := s.Router.Group("") private.Use(MakeAuthMiddleware(s.as)) diff --git a/internal/view/item_viewmodel.go b/internal/view/item_viewmodel.go index aadea8a..151fb0e 100644 --- a/internal/view/item_viewmodel.go +++ b/internal/view/item_viewmodel.go @@ -6,7 +6,13 @@ type ItemViewModel struct { Quantity string Price string SubTotal string - PaymentMethod string PaymentStatus string ItemUrl string + Payments []Payment +} + +type Payment struct { + Amount string + PaymentMethod string + PaymentUrl string } diff --git a/internal/view/line_item.templ b/internal/view/line_item.templ index 0501f14..263162e 100644 --- a/internal/view/line_item.templ +++ b/internal/view/line_item.templ @@ -5,16 +5,31 @@ templ LineItem(item *ItemViewModel) { { item.Item } { item.Quantity } { item.Price } - { item.PaymentMethod } + – { item.PaymentStatus } { item.SubTotal } if item.PaymentStatus != "Completed" { - + } + if len(item.Payments) >0 { + for _,payment := range item.Payments { + + + + - { payment.Amount } + { payment.PaymentMethod } + + + + + + + } + } } templ LineItemForm(item *ItemViewModel) { @@ -23,7 +38,7 @@ templ LineItemForm(item *ItemViewModel) { - + { item.SubTotal } diff --git a/internal/view/line_item_templ.go b/internal/view/line_item_templ.go index c826bb4..01ec3f8 100644 --- a/internal/view/line_item_templ.go +++ b/internal/view/line_item_templ.go @@ -68,14 +68,14 @@ func LineItem(item *ItemViewModel) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "–") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var5 string - templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(item.PaymentMethod) + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(item.PaymentStatus) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/line_item.templ`, Line: 8, Col: 26} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/line_item.templ`, Line: 9, Col: 26} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -86,67 +86,101 @@ func LineItem(item *ItemViewModel) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var6 string - templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(item.PaymentStatus) + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(item.SubTotal) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/line_item.templ`, Line: 9, Col: 26} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/line_item.templ`, Line: 10, Col: 21} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\" hx-target=\"closest tr\" hx-swap=\"outerHTML\">Edit ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if item.PaymentStatus != "Completed" { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" hx-target=\"closest tr\" hx-swap=\"outerHTML\">Add Payment") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + if len(item.Payments) > 0 { + for _, payment := range item.Payments { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "- ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var9 string + templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(payment.Amount) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/line_item.templ`, Line: 23, Col: 26} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var10 string + templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(payment.PaymentMethod) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/line_item.templ`, Line: 24, Col: 31} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + } return nil }) } @@ -167,103 +201,103 @@ func LineItemForm(item *ItemViewModel) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var10 := templ.GetChildren(ctx) - if templ_7745c5c3_Var10 == nil { - templ_7745c5c3_Var10 = templ.NopComponent + templ_7745c5c3_Var12 := templ.GetChildren(ctx) + if templ_7745c5c3_Var12 == nil { + templ_7745c5c3_Var12 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "\" name=\"price\" form=\"edit-item\">
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "\" name=\"paymentMethod\" form=\"edit-item\">") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var19 string + templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(item.SubTotal) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/line_item.templ`, Line: 43, Col: 22} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }