display multiple items

This commit is contained in:
Ruidy 2024-08-26 21:14:37 +02:00
parent cb2c6d9464
commit 0a0e819133
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
2 changed files with 19 additions and 14 deletions

View file

@ -97,7 +97,7 @@ func (bs Service) Update(id int, From time.Time, To time.Time, Name string, Phon
return b return b
} }
func (bs Service) CreateItem(bookingId int, item config.HostItem, quantity int, paymentMethod string, customerNumber int) *Item { func (bs Service) CreateItem(bookingId int, item config.HostItem, quantity int, paymentMethod string, customerNumber int) (items []*Item) {
i := &Item{ i := &Item{
BookingId: bookingId, BookingId: bookingId,
Item: item.Name, Item: item.Name,
@ -106,7 +106,7 @@ func (bs Service) CreateItem(bookingId int, item config.HostItem, quantity int,
PaymentMethod: paymentMethod, PaymentMethod: paymentMethod,
} }
_ = bs.db.Create(i) _ = bs.db.Create(i)
items = append(items, i)
if item.Taxes != 0.0 { if item.Taxes != 0.0 {
ti := &Item{ ti := &Item{
BookingId: bookingId, BookingId: bookingId,
@ -116,9 +116,10 @@ func (bs Service) CreateItem(bookingId int, item config.HostItem, quantity int,
PaymentMethod: "Cash", PaymentMethod: "Cash",
} }
_ = bs.db.Create(ti) _ = bs.db.Create(ti)
items = append(items, ti)
} }
return i return items
} }
func (bs Service) PayItem(id int) *Item { func (bs Service) PayItem(id int) *Item {

View file

@ -257,7 +257,7 @@ func handleCreateItem(bs *booking.Service, cs *calendar.Service, hc *config.Host
return fmt.Errorf("invalid item name %q", ni.Item) return fmt.Errorf("invalid item name %q", ni.Item)
} }
i := bs.CreateItem(b.Id, itm, ni.Quantity, ni.PaymentMethod, b.CustomerNumber) newItems := bs.CreateItem(b.Id, itm, ni.Quantity, ni.PaymentMethod, b.CustomerNumber)
if err = cs.Create( if err = cs.Create(
itm.CalendarId, itm.CalendarId,
@ -269,16 +269,20 @@ func handleCreateItem(bs *booking.Service, cs *calendar.Service, hc *config.Host
captureError(c, err) captureError(c, err)
} }
return renderTempl(c, http.StatusCreated, view.LineItem(&view.ItemViewModel{ for _, i := range newItems {
Id: strconv.Itoa(i.Id), renderTempl(c, http.StatusCreated, view.LineItem(&view.ItemViewModel{
Item: i.Item, Id: strconv.Itoa(i.Id),
Quantity: strconv.Itoa(i.Quantity), Item: i.Item,
Price: strconv.FormatFloat(i.Price, 'f', 2, 64), Quantity: strconv.Itoa(i.Quantity),
PaymentMethod: i.PaymentMethod, Price: strconv.FormatFloat(i.Price, 'f', 2, 64),
PaymentStatus: i.PaymentStatus, PaymentMethod: i.PaymentMethod,
SubTotal: strconv.FormatFloat(i.Price*float64(i.Quantity), 'f', 2, 64), PaymentStatus: i.PaymentStatus,
ItemUrl: fmt.Sprintf("%s/%d", constant.RouteItem, i.Id), SubTotal: strconv.FormatFloat(i.Price*float64(i.Quantity), 'f', 2, 64),
})) ItemUrl: fmt.Sprintf("%s/%d", constant.RouteItem, i.Id),
}))
}
return nil
} }
} }