diff --git a/internal/booking/service.go b/internal/booking/service.go index b47b6a3..6a271be 100644 --- a/internal/booking/service.go +++ b/internal/booking/service.go @@ -92,6 +92,12 @@ func (bs Service) PayItem(id int) *Item { return i } +func (bs Service) OneItem(id int) *Item { + i := &Item{Id: id} + bs.db.First(i) + return i +} + type Report struct { Lines []*Line Total float64 diff --git a/internal/server/handle_bookings.go b/internal/server/handle_bookings.go index aac07ac..52fd01a 100644 --- a/internal/server/handle_bookings.go +++ b/internal/server/handle_bookings.go @@ -167,6 +167,28 @@ func handleUpdateBooking(bs *booking.Service, hc *config.Host) echo.HandlerFunc } } +func handleLineItemForm(bs *booking.Service) echo.HandlerFunc { + return func(c echo.Context) error { + idStr := c.Param("id") + id, err := strconv.Atoi(idStr) + if err != nil { + return err + } + i := bs.OneItem(id) + form := view.LineItemForm(&view.ItemViewModel{ + Id: strconv.Itoa(i.Id), + 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), + }) + return renderTempl(c, http.StatusOK, form) + } +} + func handleCreateItem(bs *booking.Service) echo.HandlerFunc { return func(c echo.Context) error { bookingIdStr := c.Param("id") diff --git a/internal/server/routes.go b/internal/server/routes.go index e839fa8..76deae7 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -12,6 +12,7 @@ func (s Server) MountHandlers() { s.Router.PUT("/bookings/:id", handleUpdateBooking(s.bs, s.hc)) s.Router.POST("/bookings/:id/items", handleCreateItem(s.bs)) s.Router.POST("/items/:id", handlePayItem(s.bs)) + s.Router.GET("/items/:id", handleLineItemForm(s.bs)) s.Router.GET("/bookings/pdf/:id", handleCreateInvoicePdf(s.bs, s.ps, s.hc)) s.Router.GET("/reports", handleReportsPage()) s.Router.GET("/reports/do", handleComputeReport(s.bs, s.hc)) diff --git a/internal/view/line_item.templ b/internal/view/line_item.templ index 5fcd793..0ddd280 100644 --- a/internal/view/line_item.templ +++ b/internal/view/line_item.templ @@ -9,10 +9,26 @@ templ LineItem(item *ItemViewModel) {