fix numeric types and view model

This commit is contained in:
Ruidy 2024-02-13 21:58:58 +01:00
parent 7a4674cd14
commit 8f15fd4cfd
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
7 changed files with 201 additions and 96 deletions

View file

@ -1,3 +1,3 @@
package constants package constants
var Items = []string{"T2", "T3", "Airport", "Port"} var Items = []string{"T2", "T3", "Airport", "Port", "Taxes"}

View file

@ -11,7 +11,7 @@ type Booking struct {
Id int Id int
Name string `gorm:"column:customer_name"` Name string `gorm:"column:customer_name"`
PhoneNumber string PhoneNumber string
CustomerNumber string `gorm:"column:customers"` CustomerNumber int `gorm:"column:customers"`
Email string Email string
From time.Time From time.Time
To time.Time To time.Time

View file

@ -60,7 +60,7 @@ func (s Server) handleCreateBooking() echo.HandlerFunc {
type NewBooking struct { type NewBooking struct {
Name string `form:"name"` Name string `form:"name"`
PhoneNumber string `form:"phone_number"` PhoneNumber string `form:"phone_number"`
CustomerNumber string `form:"customer_number"` CustomerNumber int `form:"customer_number"`
Email string `form:"email"` Email string `form:"email"`
From time.Time `json:"from"` From time.Time `json:"from"`
To time.Time `from:"to"` To time.Time `from:"to"`
@ -104,7 +104,35 @@ func (s Server) handleBookingPage() echo.HandlerFunc {
b := &booking.Booking{Id: id} b := &booking.Booking{Id: id}
s.db.Preload("Items").First(b) s.db.Preload("Items").First(b)
component := views.BookingById(b, constants.Items, constants.Platforms, constants.PaymentMethods) bvm := &views.BookingViewModel{
Id: fmt.Sprintf("%04s", strconv.Itoa(b.Id)),
Name: b.Name,
PhoneNumber: b.PhoneNumber,
CustomerNumber: strconv.Itoa(b.CustomerNumber),
Email: b.Email,
From: b.From.Format("2006-01-02"),
To: b.To.Format("2006-01-02"),
Platform: b.Platform,
PlatformFees: strconv.FormatFloat(b.PlatformFees, 'f', 2, 64),
Url: templ.EscapeString(fmt.Sprintf("%s/%d/items", constants.RouteBooking, b.Id)),
Items: u.Map(b.Items, func(i booking.Item) views.ItemViewModel {
return views.ItemViewModel{
Item: i.Item,
Quantity: strconv.Itoa(i.Quantity),
Price: strconv.FormatFloat(i.Price, 'f', 2, 64),
SubTotal: strconv.FormatFloat(i.Price*float64(i.Quantity), 'f', 2, 64),
PaymentMethod: i.PaymentMethod,
PaymentStatus: i.PaymentStatus,
}
}),
Total: strconv.FormatFloat(u.Reduce(b.Items, func(i booking.Item, sum float64) float64 {
return sum + i.Price*float64(i.Quantity)
}, 0.0), 'f', 2, 64),
Platforms: constants.Platforms,
ItemList: constants.Items,
PaymentMethods: constants.PaymentMethods,
}
component := views.BookingById(bvm)
return s.renderTempl(c, http.StatusOK, component) return s.renderTempl(c, http.StatusOK, component)
} }
} }

View file

@ -1,17 +1,37 @@
package views package views
import ( type BookingViewModel struct {
"fmt" Id string
"strconv" Name string
PhoneNumber string
CustomerNumber string
Email string
From string
To string
Platform string
Platforms []string
PlatformFees string
Items []ItemViewModel
ItemList []string
PaymentMethods []string
Url string
Total string
}
"github.com/rjNemo/rentease/internal/domains/booking" type ItemViewModel struct {
) Item string
Quantity string
Price string
SubTotal string
PaymentMethod string
PaymentStatus string
}
templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []string) { templ BookingById(booking *BookingViewModel) {
@BaseLayout() { @BaseLayout() {
<div class="grid"> <div class="grid">
<hgroup> <hgroup>
<h1>Booking ID VFNI#{ fmt.Sprintf("%04s", strconv.Itoa(booking.Id)) } </h1> <h1>Booking ID VFNI#{ booking.Id } </h1>
<h2>Manage a booking </h2> <h2>Manage a booking </h2>
</hgroup> </hgroup>
<div> <div>
@ -21,12 +41,12 @@ templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []s
<form method="POST"> <form method="POST">
<div class="grid"> <div class="grid">
<label for="name"> <label for="name">
Customer full name Customer name
<input type="text" id="name" name="name" value={ booking.Name } required autofocus/> <input type="text" id="name" name="name" value={ booking.Name } required autofocus/>
</label> </label>
<label for="phone_number"> <label for="phone_number">
Phone number Phone number
<input type="text" id="phone_number" name="phone_number" value={ booking.PhoneNumber }/> <input type="tel" id="phone_number" name="phone_number" value={ booking.PhoneNumber }/>
</label> </label>
</div> </div>
<div class="grid"> <div class="grid">
@ -42,11 +62,11 @@ templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []s
<div class="grid"> <div class="grid">
<label for="from"> <label for="from">
From From
<input type="date" id="from" name="from" value={ booking.From.Format("2006-01-02") }/> <input type="date" id="from" name="from" value={ booking.From }/>
</label> </label>
<label for="to"> <label for="to">
To To
<input type="date" id="to" name="to" value={ booking.To.Format("2006-01-02") }/> <input type="date" id="to" name="to" value={ booking.To }/>
</label> </label>
</div> </div>
<div class="grid"> <div class="grid">
@ -54,14 +74,14 @@ templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []s
Platform Platform
<select id="platform" name="platform"> <select id="platform" name="platform">
<option value={ booking.Platform } selected>{ booking.Platform } </option> <option value={ booking.Platform } selected>{ booking.Platform } </option>
for _, platform := range platforms { for _, platform := range booking.Platforms {
<option value={ platform }>{ platform } </option> <option value={ platform }>{ platform } </option>
} }
</select> </select>
</label> </label>
<label for="platform_fees"> <label for="platform_fees">
Fees Fees
<input type="number" id="platform_fees" name="platform_fees" value={ strconv.FormatFloat(booking.PlatformFees, 'f', 2, 64) }/> <input type="number" id="platform_fees" inputmode="decimal" step="0.01" name="platform_fees" value={ booking.PlatformFees }/>
</label> </label>
</div> </div>
<button type="submit">Update</button> <button type="submit">Update</button>
@ -74,9 +94,10 @@ templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []s
<th scope="col">#</th> <th scope="col">#</th>
<th scope="col">Item</th> <th scope="col">Item</th>
<th scope="col">Quantity</th> <th scope="col">Quantity</th>
<th scope="col">Price</th> <th scope="col">Price (€)</th>
<th scope="col">Payment Method</th> <th scope="col">Payment Method</th>
<th scope="col">Payment Status</th> <th scope="col">Payment Status</th>
<th scope="col">Sub-total (€)</th>
</tr> </tr>
</thead> </thead>
<tbody id="line-items"> <tbody id="line-items">
@ -84,23 +105,33 @@ templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []s
<tr> <tr>
<th scope="row"></th> <th scope="row"></th>
<td>{ item.Item }</td> <td>{ item.Item }</td>
<td>{ strconv.Itoa(item.Quantity) }</td> <td>{ item.Quantity }</td>
<td>{ strconv.FormatFloat(item.Price, 'f', 2, 64) }</td> <td>{ item.Price }</td>
<td>{ item.PaymentMethod }</td> <td>{ item.PaymentMethod }</td>
<td>{ item.PaymentStatus }</td> <td>{ item.PaymentStatus }</td>
<td>{ item.SubTotal }</td>
</tr> </tr>
} }
</tbody> </tbody>
<tfoot>
<th scope="col"></th>
<th scope="col"></th>
<th scope="col"></th>
<th scope="col"></th>
<th scope="col"></th>
<th scope="col"></th>
<th scope="col">{ booking.Total }</th>
</tfoot>
</table> </table>
</figure> </figure>
<details> <details>
<summary role="button" class="secondary">Add line </summary> <summary role="button" class="secondary">Add line </summary>
<form hx-post={ fmt.Sprintf("/bookings/%d/items", booking.Id) } hx-target="#line-items" hx-swap="afterend"> <form hx-post={ booking.Url } hx-target="#line-items" hx-swap="afterend" hx-on::after-request=" if(event.detail.successful) this.reset()">
<article> <article>
<label for="new-line-item"> <label for="new-line-item">
Item Item
<select name="item" id="new-line-item"> <select name="item" id="new-line-item">
for _, item := range items { for _, item := range booking.ItemList {
<option value={ item }>{ item } </option> <option value={ item }>{ item } </option>
} }
</select> </select>
@ -111,12 +142,12 @@ templ BookingById(booking *booking.Booking, items, platforms, paymentMethods []s
</label> </label>
<label for="new-line-price"> <label for="new-line-price">
Price Price
<input type="number" name="price" id="new-line-price"/> <input type="number" name="price" inputmode="decimal" step="0.01" id="new-line-price"/>
</label> </label>
<label for="new-line-method"> <label for="new-line-method">
Payment Method Payment Method
<select name="method" id="new-line-method"> <select name="method" id="new-line-method">
for _, paymentMethod := range paymentMethods { for _, paymentMethod := range booking.PaymentMethods {
<option value={ paymentMethod }>{ paymentMethod } </option> <option value={ paymentMethod }>{ paymentMethod } </option>
} }
</select> </select>

View file

@ -10,14 +10,34 @@ import "context"
import "io" import "io"
import "bytes" import "bytes"
import ( type BookingViewModel struct {
"fmt" Id string
"strconv" Name string
PhoneNumber string
CustomerNumber string
Email string
From string
To string
Platform string
Platforms []string
PlatformFees string
Items []ItemViewModel
ItemList []string
PaymentMethods []string
Url string
Total string
}
"github.com/rjNemo/rentease/internal/domains/booking" type ItemViewModel struct {
) Item string
Quantity string
Price string
SubTotal string
PaymentMethod string
PaymentStatus string
}
func BookingById(booking *booking.Booking, items, platforms, paymentMethods []string) templ.Component { func BookingById(booking *BookingViewModel) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
@ -36,20 +56,20 @@ func BookingById(booking *booking.Booking, items, platforms, paymentMethods []st
templ_7745c5c3_Buffer = templ.GetBuffer() templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"grid\"><hgroup><h1>Booking ID VFNI#") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var3 string var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%04s", strconv.Itoa(booking.Id))) templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Id)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 13, Col: 71} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 33, Col: 36}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h1><h2>Manage a booking </h2></hgroup><div><button class=\"outline\">Create PDF</button></div></div><form method=\"POST\"><div class=\"grid\"><label for=\"name\">Customer full name <input type=\"text\" id=\"name\" name=\"name\" value=\"") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -57,7 +77,7 @@ func BookingById(booking *booking.Booking, items, platforms, paymentMethods []st
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" required autofocus></label> <label for=\"phone_number\">Phone number <input type=\"text\" id=\"phone_number\" name=\"phone_number\" value=\"") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -65,7 +85,7 @@ func BookingById(booking *booking.Booking, items, platforms, paymentMethods []st
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></label></div><div class=\"grid\"><label for=\"customer_number\">Customer number <input type=\"number\" id=\"customer_number\" name=\"customer_number\" required value=\"") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -73,7 +93,7 @@ func BookingById(booking *booking.Booking, items, platforms, paymentMethods []st
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></label> <label for=\"email\">Email <input type=\"email\" id=\"email\" name=\"email\" value=\"") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -81,23 +101,23 @@ func BookingById(booking *booking.Booking, items, platforms, paymentMethods []st
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></label></div><div class=\"grid\"><label for=\"from\">From <input type=\"date\" id=\"from\" name=\"from\" value=\"") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(booking.From.Format("2006-01-02"))) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(booking.From))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></label> <label for=\"to\">To <input type=\"date\" id=\"to\" name=\"to\" value=\"") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 7)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(booking.To.Format("2006-01-02"))) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(booking.To))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></label></div><div class=\"grid\"><label for=\"platform\">Platform <select id=\"platform\" name=\"platform\"><option value=\"") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 8)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -105,25 +125,25 @@ func BookingById(booking *booking.Booking, items, platforms, paymentMethods []st
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" selected>") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 9)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var4 string var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Platform) templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Platform)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 55, Col: 68} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 75, Col: 68}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option> ") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 10)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for _, platform := range platforms { for _, platform := range booking.Platforms {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 11)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -131,121 +151,147 @@ func BookingById(booking *booking.Booking, items, platforms, paymentMethods []st
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 12)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var5 string var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(platform) templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(platform)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 57, Col: 44} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 77, Col: 44}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option>") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 13)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label> <label for=\"platform_fees\">Fees <input type=\"number\" id=\"platform_fees\" name=\"platform_fees\" value=\"") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 14)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(strconv.FormatFloat(booking.PlatformFees, 'f', 2, 64))) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(booking.PlatformFees))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></label></div><button type=\"submit\">Update</button></form><h3>Line Items </h3><figure><table role=\"grid\"><thead><tr><th scope=\"col\">#</th><th scope=\"col\">Item</th><th scope=\"col\">Quantity</th><th scope=\"col\">Price</th><th scope=\"col\">Payment Method</th><th scope=\"col\">Payment Status</th></tr></thead> <tbody id=\"line-items\">") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 15)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for _, item := range booking.Items { for _, item := range booking.Items {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr><th scope=\"row\"></th><td>") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 16)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var6 string var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(item.Item) templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(item.Item)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 85, Col: 22} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 106, Col: 22}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 17)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var7 string var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(item.Quantity)) templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(item.Quantity)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 86, Col: 40} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 107, Col: 26}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 18)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var8 string var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.FormatFloat(item.Price, 'f', 2, 64)) templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(item.Price)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 87, Col: 56} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 108, Col: 23}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 19)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var9 string var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(item.PaymentMethod) templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(item.PaymentMethod)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 88, Col: 31} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 109, Col: 31}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 20)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var10 string var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(item.PaymentStatus) templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(item.PaymentStatus)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 89, Col: 31} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 110, Col: 31}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td></tr>") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 21)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(item.SubTotal)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 111, Col: 26}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 22)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</tbody></table></figure><details><summary role=\"button\" class=\"secondary\">Add line </summary><form hx-post=\"") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 23)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(fmt.Sprintf("/bookings/%d/items", booking.Id))) var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Total)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 122, Col: 36}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-target=\"#line-items\" hx-swap=\"afterend\"><article><label for=\"new-line-item\">Item <select name=\"item\" id=\"new-line-item\">") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 24)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for _, item := range items { _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(booking.Url))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"") if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 25)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, item := range booking.ItemList {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 26)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -253,30 +299,30 @@ func BookingById(booking *booking.Booking, items, platforms, paymentMethods []st
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 27)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var11 string var templ_7745c5c3_Var13 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(item) templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(item)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 103, Col: 37} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 134, Col: 37}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option>") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 28)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label> <label for=\"new-line-quantity\">Quantity <input type=\"number\" name=\"quantity\" id=\"new-line-quantity\"></label> <label for=\"new-line-price\">Price <input type=\"number\" name=\"price\" id=\"new-line-price\"></label> <label for=\"new-line-method\">Payment Method <select name=\"method\" id=\"new-line-method\">") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 29)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for _, paymentMethod := range paymentMethods { for _, paymentMethod := range booking.PaymentMethods {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 30)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -284,25 +330,25 @@ func BookingById(booking *booking.Booking, items, platforms, paymentMethods []st
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 31)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var12 string var templ_7745c5c3_Var14 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(paymentMethod) templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(paymentMethod)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 119, Col: 55} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/booking_by_id.templ`, Line: 150, Col: 55}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option>") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 32)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label> <button type=\"submit\">Add</button></article></form></details>") templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 33)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }

View file

@ -9,32 +9,32 @@ templ NewBooking(platforms []string) {
<form method="POST"> <form method="POST">
<div class="grid"> <div class="grid">
<label for="name"> <label for="name">
Customer full name Customer name
<input type="text" id="name" name="name" placeholder="John Doe" required autofocus/> <input type="text" id="name" name="name" placeholder="John Doe" required autofocus/>
</label> </label>
<label for="phone_number"> <label for="phone_number">
Phone number Phone number
<input type="text" id="phone_number" name="phone_number" placeholder="06 12 34 56 78"/> <input type="tel" id="phone_number" name="phone_number" placeholder="06 12 34 56 78"/>
</label> </label>
</div> </div>
<div class="grid"> <div class="grid">
<label for="customer_number"> <label for="customer_number">
Customer number Customer number
<input type="number" id="customer_number" name="customer_number" required/> <input type="number" inputmode="numeric" id="customer_number" name="customer_number" placeholder="1" required/>
</label> </label>
<label for="email"> <label for="email">
Email Email
<input type="text" id="email" name="email" placeholder="john@doe.com"/> <input type="email" id="email" name="email" placeholder="john@doe.com"/>
</label> </label>
</div> </div>
<div class="grid"> <div class="grid">
<label for="from"> <label for="from">
From From
<input type="date" id="from" name="from"/> <input type="date" id="from" name="from" required/>
</label> </label>
<label for="to"> <label for="to">
To To
<input type="date" id="to" name="to"/> <input type="date" id="to" name="to" required/>
</label> </label>
</div> </div>
<div class="grid"> <div class="grid">
@ -48,7 +48,7 @@ templ NewBooking(platforms []string) {
</label> </label>
<label for="platform_fees"> <label for="platform_fees">
Fees Fees
<input type="number" id="platform_fees" name="platform_fees"/> <input type="number" inputmode="decimal" step="0.01" id="platform_fees" name="platform_fees" placeholder="0"/>
</label> </label>
</div> </div>
<button type="submit">Submit</button> <button type="submit">Submit</button>

View file

@ -29,7 +29,7 @@ func NewBooking(platforms []string) templ.Component {
templ_7745c5c3_Buffer = templ.GetBuffer() templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<hgroup><h1>New Booking </h1><h2>Create a new booking </h2></hgroup><form method=\"POST\"><div class=\"grid\"><label for=\"name\">Customer full name <input type=\"text\" id=\"name\" name=\"name\" placeholder=\"John Doe\" required autofocus></label> <label for=\"phone_number\">Phone number <input type=\"text\" id=\"phone_number\" name=\"phone_number\" placeholder=\"06 12 34 56 78\"></label></div><div class=\"grid\"><label for=\"customer_number\">Customer number <input type=\"number\" id=\"customer_number\" name=\"customer_number\" required></label> <label for=\"email\">Email <input type=\"text\" id=\"email\" name=\"email\" placeholder=\"john@doe.com\"></label></div><div class=\"grid\"><label for=\"from\">From <input type=\"date\" id=\"from\" name=\"from\"></label> <label for=\"to\">To <input type=\"date\" id=\"to\" name=\"to\"></label></div><div class=\"grid\"><label for=\"platform\">Platform <select id=\"platform\" name=\"platform\">") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<hgroup><h1>New Booking </h1><h2>Create a new booking </h2></hgroup><form method=\"POST\"><div class=\"grid\"><label for=\"name\">Customer name <input type=\"text\" id=\"name\" name=\"name\" placeholder=\"John Doe\" required autofocus></label> <label for=\"phone_number\">Phone number <input type=\"tel\" id=\"phone_number\" name=\"phone_number\" placeholder=\"06 12 34 56 78\"></label></div><div class=\"grid\"><label for=\"customer_number\">Customer number <input type=\"number\" inputmode=\"numeric\" id=\"customer_number\" name=\"customer_number\" placeholder=\"1\" required></label> <label for=\"email\">Email <input type=\"email\" id=\"email\" name=\"email\" placeholder=\"john@doe.com\"></label></div><div class=\"grid\"><label for=\"from\">From <input type=\"date\" id=\"from\" name=\"from\" required></label> <label for=\"to\">To <input type=\"date\" id=\"to\" name=\"to\" required></label></div><div class=\"grid\"><label for=\"platform\">Platform <select id=\"platform\" name=\"platform\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -60,7 +60,7 @@ func NewBooking(platforms []string) templ.Component {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label> <label for=\"platform_fees\">Fees <input type=\"number\" id=\"platform_fees\" name=\"platform_fees\"></label></div><button type=\"submit\">Submit</button></form>") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label> <label for=\"platform_fees\">Fees <input type=\"number\" inputmode=\"decimal\" step=\"0.01\" id=\"platform_fees\" name=\"platform_fees\" placeholder=\"0\"></label></div><button type=\"submit\">Submit</button></form>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }