mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +00:00
auto create tax items if the item is taxable
This commit is contained in:
parent
2d8fce7ad2
commit
778254bc61
2 changed files with 23 additions and 13 deletions
|
|
@ -97,15 +97,27 @@ func (bs Service) Update(id int, From time.Time, To time.Time, Name string, Phon
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bs Service) CreateItem(bid int, item string, qty int, price float64, method string) *Item {
|
func (bs Service) CreateItem(bookingId int, item config.HostItem, quantity int, paymentMethod string, customerNumber int) *Item {
|
||||||
i := &Item{
|
i := &Item{
|
||||||
BookingId: bid,
|
BookingId: bookingId,
|
||||||
Item: item,
|
Item: item.Name,
|
||||||
Quantity: qty,
|
Quantity: quantity,
|
||||||
Price: price,
|
Price: item.Price,
|
||||||
PaymentMethod: method,
|
PaymentMethod: paymentMethod,
|
||||||
}
|
}
|
||||||
_ = bs.db.Create(i)
|
_ = bs.db.Create(i)
|
||||||
|
|
||||||
|
if item.Taxes != 0.0 {
|
||||||
|
ti := &Item{
|
||||||
|
BookingId: bookingId,
|
||||||
|
Item: "Taxes",
|
||||||
|
Quantity: quantity * customerNumber,
|
||||||
|
Price: item.Taxes,
|
||||||
|
PaymentMethod: "Cash",
|
||||||
|
}
|
||||||
|
_ = bs.db.Create(ti)
|
||||||
|
}
|
||||||
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -257,20 +269,18 @@ func (bs Service) ParseFromApi(rawContent string) (*Booking, error) {
|
||||||
arrivalDate := extractDate(`Date d'arrivée `, content)
|
arrivalDate := extractDate(`Date d'arrivée `, content)
|
||||||
departureDate := extractDate(`Date de départ `, content)
|
departureDate := extractDate(`Date de départ `, content)
|
||||||
stayLength := extractInt(`Durée de séjour : (\d+) nuits`, content)
|
stayLength := extractInt(`Durée de séjour : (\d+) nuits`, content)
|
||||||
totalAmount := extractFloat(`Montant total € (\d+)`, content)
|
|
||||||
customerName := extractString(`Nom du client : \n\s+([\w\s]+)`, content)
|
customerName := extractString(`Nom du client : \n\s+([\w\s]+)`, content)
|
||||||
customerName = strings.SplitN(customerName, "\n", 2)[0]
|
customerName = strings.SplitN(customerName, "\n", 2)[0]
|
||||||
customerEmail := extractString(`[\w\.\-]+@[\w\.\-]+\.\w+`, content)
|
customerEmail := extractString(`[\w\.\-]+@[\w\.\-]+\.\w+`, content)
|
||||||
customerNumber := extractInt(`Nombre de personnes : \s*\n\s*(\d+)`, content)
|
customerNumber := extractInt(`Nombre de personnes : \s*\n\s*(\d+)`, content)
|
||||||
commissionAmount := extractFloat(`Commission : € (\d+,\d+)`, content)
|
commissionAmount := extractFloat(`Commission : € (\d+,\d+)`, content)
|
||||||
item := extractString(`Maison 1 Chambre \((T2|T3) -`, content)
|
itemName := extractString(`Maison 1 Chambre \((T2|T3) -`, content)
|
||||||
externalId := extractString(`Numéro de réservation : \n\s+(\d+)`, 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, &externalId)
|
b := bs.Create(*formatDate(arrivalDate), *formatDate(departureDate), customerName, "", customerEmail, "Booking", customerNumber, commissionAmount, &externalId)
|
||||||
bs.CreateItem(b.Id, item, stayLength, standardRate, "Card")
|
if item, ok := config.NewHost().Items[itemName]; ok {
|
||||||
bs.CreateItem(b.Id, "Taxes", int(taxQty), 1.5, "Cash")
|
bs.CreateItem(b.Id, item, stayLength, "Card", customerNumber)
|
||||||
|
}
|
||||||
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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, ni.Item, ni.Quantity, ni.Price, ni.PaymentMethod)
|
i := bs.CreateItem(b.Id, itm, ni.Quantity, ni.PaymentMethod, b.CustomerNumber)
|
||||||
|
|
||||||
if err = cs.Create(
|
if err = cs.Create(
|
||||||
itm.CalendarId,
|
itm.CalendarId,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue