mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-10 04:36:50 +00:00
add external_id to not duplicate bookings
This commit is contained in:
parent
ba22fa0ffc
commit
c8ab60e07e
3 changed files with 6 additions and 3 deletions
|
|
@ -18,6 +18,7 @@ type Booking struct {
|
|||
PhoneNumber string
|
||||
Email string
|
||||
Platform string
|
||||
ExternalId string `gorm:"uniqueIndex:booking_external_id"`
|
||||
Items []Item
|
||||
Id int
|
||||
CustomerNumber int `gorm:"column:customers"`
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ func (bs Service) All() []*Line {
|
|||
}
|
||||
|
||||
func (bs Service) Create(From time.Time, To time.Time, Name string, PhoneNumber string, Email string, Platform string,
|
||||
CustomerNumber int, PlatformFees float64,
|
||||
CustomerNumber int, PlatformFees float64, externalId string,
|
||||
) *Booking {
|
||||
b := &Booking{
|
||||
Name: Name,
|
||||
|
|
@ -48,6 +48,7 @@ func (bs Service) Create(From time.Time, To time.Time, Name string, PhoneNumber
|
|||
To: To,
|
||||
Platform: Platform,
|
||||
PlatformFees: PlatformFees,
|
||||
ExternalId: externalId,
|
||||
}
|
||||
_ = bs.db.Create(b)
|
||||
return b
|
||||
|
|
@ -244,11 +245,12 @@ func (bs Service) ParseFromApi(rawContent string) (*Booking, error) {
|
|||
customerNumber := extractInt(`Nombre de personnes : \s*\n\s*(\d+)`, content)
|
||||
commissionAmount := extractFloat(`Commission : € (\d+,\d+)`, content)
|
||||
item := 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)
|
||||
|
||||
taxQty := (totalAmount - standardRate*float64(stayLength)) / 1.5
|
||||
|
||||
b := bs.Create(*formatDate(arrivalDate), *formatDate(departureDate), customerName, "", customerEmail, "Booking", customerNumber, commissionAmount)
|
||||
b := bs.Create(*formatDate(arrivalDate), *formatDate(departureDate), customerName, "", customerEmail, "Booking", customerNumber, commissionAmount, externalId)
|
||||
bs.CreateItem(b.Id, item, stayLength, standardRate, "Card")
|
||||
bs.CreateItem(b.Id, "Taxes", int(taxQty), 1.5, "Cash")
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ func handleCreateBooking(bs *booking.Service) echo.HandlerFunc {
|
|||
ts, _ = myTime.ParseFromForm(c.FormValue("to"))
|
||||
nb.To = ts
|
||||
|
||||
b := bs.Create(nb.From, nb.To, nb.Name, nb.PhoneNumber, nb.Email, nb.Platform, nb.CustomerNumber, nb.PlatformFees)
|
||||
b := bs.Create(nb.From, nb.To, nb.Name, nb.PhoneNumber, nb.Email, nb.Platform, nb.CustomerNumber, nb.PlatformFees, "") // TODO: add field in the form
|
||||
return c.Redirect(http.StatusSeeOther, fmt.Sprintf("%s/%d", constant.RouteBooking, b.Id))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue