mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-10 04:36:50 +00:00
add total to the booking overview page
This commit is contained in:
parent
b8c83b2d2d
commit
68df2f06a2
4 changed files with 38 additions and 15 deletions
|
|
@ -20,9 +20,16 @@ func NewService(db *gorm.DB) *Service {
|
|||
return &Service{db: db}
|
||||
}
|
||||
|
||||
func (bs Service) All() []*Booking {
|
||||
bookings := make([]*Booking, 0)
|
||||
_ = bs.db.Order("id desc").Find(&bookings)
|
||||
func (bs Service) All() []*Line {
|
||||
bookings := make([]*Line, 0)
|
||||
bs.db.Raw(`
|
||||
select bookings.id, customer_name, "from", "to", platform, sum(price) as total
|
||||
from bookings
|
||||
join items on bookings.id = items.booking_id
|
||||
group by bookings.id
|
||||
order by id desc;
|
||||
`).
|
||||
Scan(&bookings)
|
||||
return bookings
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,14 +22,15 @@ func handleListBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFun
|
|||
return func(c echo.Context) error {
|
||||
bookings := bs.All()
|
||||
|
||||
bvm := u.Map(bookings, func(b *booking.Booking) *views.ListBookingsViewModel {
|
||||
bvm := u.Map(bookings, func(b *booking.Line) *views.ListBookingsViewModel {
|
||||
return &views.ListBookingsViewModel{
|
||||
Id: b.InvoiceNumber(hc),
|
||||
Url: templ.SafeURL(fmt.Sprintf("%s/%d", constants.RouteBooking, b.Id)),
|
||||
From: b.From.Format("2006-01-02"),
|
||||
To: b.To.Format("2006-01-02"),
|
||||
Platform: b.Platform,
|
||||
Name: b.Name,
|
||||
Name: b.CustomerName,
|
||||
Total: strconv.FormatFloat(b.Total, 'f', 2, 64),
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ type ListBookingsViewModel struct {
|
|||
Url templ.SafeURL
|
||||
From string
|
||||
To string
|
||||
Total string
|
||||
Name string
|
||||
Platform string
|
||||
}
|
||||
|
|
@ -36,7 +37,7 @@ templ ListBookings(bookings []*ListBookingsViewModel) {
|
|||
</a>
|
||||
</th>
|
||||
<td>{ b.Name }</td>
|
||||
<td></td>
|
||||
<td>{ b.Total }</td>
|
||||
<td>{ b.From }</td>
|
||||
<td>{ b.To }</td>
|
||||
<td>{ b.Platform }</td>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ type ListBookingsViewModel struct {
|
|||
Url templ.SafeURL
|
||||
From string
|
||||
To string
|
||||
Total string
|
||||
Name string
|
||||
Platform string
|
||||
}
|
||||
|
|
@ -59,7 +60,7 @@ func ListBookings(bookings []*ListBookingsViewModel) templ.Component {
|
|||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(b.Id)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/bookings_list.templ`, Line: 34, Col: 15}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/bookings_list.templ`, Line: 35, Col: 15}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -72,20 +73,20 @@ func ListBookings(bookings []*ListBookingsViewModel) templ.Component {
|
|||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(b.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/bookings_list.templ`, Line: 37, Col: 19}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/bookings_list.templ`, Line: 38, Col: 19}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td></td><td>")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(b.From)
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(b.Total)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/bookings_list.templ`, Line: 39, Col: 19}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/bookings_list.templ`, Line: 39, Col: 20}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -96,9 +97,9 @@ func ListBookings(bookings []*ListBookingsViewModel) templ.Component {
|
|||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(b.To)
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(b.From)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/bookings_list.templ`, Line: 40, Col: 17}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/bookings_list.templ`, Line: 40, Col: 19}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -109,14 +110,27 @@ func ListBookings(bookings []*ListBookingsViewModel) templ.Component {
|
|||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var8 string
|
||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(b.Platform)
|
||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(b.To)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/bookings_list.templ`, Line: 41, Col: 23}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/bookings_list.templ`, Line: 41, Col: 17}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var9 string
|
||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(b.Platform)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/bookings_list.templ`, Line: 42, Col: 23}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td></tr>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
|
|
|
|||
Loading…
Reference in a new issue