diff --git a/internal/booking/service.go b/internal/booking/service.go index 7f8f368..374d4b8 100644 --- a/internal/booking/service.go +++ b/internal/booking/service.go @@ -97,16 +97,17 @@ func (bs Service) Update(id int, From time.Time, To time.Time, Name string, Phon return b } -func (bs Service) CreateItem(bookingId int, item config.HostItem, quantity int, paymentMethod string, customerNumber int) (items []*Item) { +func (bs Service) CreateItem(bookingId int, item config.HostItem, quantity int, price float64, paymentMethod string, customerNumber int) (items []*Item) { i := &Item{ BookingId: bookingId, Item: item.Name, Quantity: quantity, - Price: item.Price, + Price: price, PaymentMethod: paymentMethod, } _ = bs.db.Create(i) items = append(items, i) + if item.Taxes != 0.0 { ti := &Item{ BookingId: bookingId, @@ -277,10 +278,11 @@ func (bs Service) ParseFromApi(rawContent string) (*Booking, error) { commissionAmount := extractFloat(`Commission : € (\d+,\d+)`, content) itemName := extractString(`Maison 1 Chambre \((T2|T3) -`, content) externalId := extractString(`Numéro de réservation : \n\s+(\d+)`, content) + standardRate := extractFloat(`Standard Rate\n\s+€ (\d+)`, content) b := bs.Create(*formatDate(arrivalDate), *formatDate(departureDate), customerName, "", customerEmail, "Booking", customerNumber, commissionAmount, &externalId) if item, ok := config.NewHost().Items[itemName]; ok { - bs.CreateItem(b.Id, item, stayLength, "Card", customerNumber) + bs.CreateItem(b.Id, item, stayLength, standardRate, "Card", customerNumber) } return b, nil diff --git a/internal/server/handle_bookings.go b/internal/server/handle_bookings.go index 13f2f82..cc97442 100644 --- a/internal/server/handle_bookings.go +++ b/internal/server/handle_bookings.go @@ -257,7 +257,7 @@ func handleCreateItem(bs *booking.Service, cs *calendar.Service, hc *config.Host return fmt.Errorf("invalid item name %q", ni.Item) } - newItems := bs.CreateItem(b.Id, itm, ni.Quantity, ni.PaymentMethod, b.CustomerNumber) + newItems := bs.CreateItem(b.Id, itm, ni.Quantity, ni.Price, ni.PaymentMethod, b.CustomerNumber) if err = cs.Create( itm.CalendarId,