mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +00:00
basic report
This commit is contained in:
parent
68e7d540b5
commit
7a4674cd14
3 changed files with 193 additions and 21 deletions
|
|
@ -191,18 +191,54 @@ func (s Server) handleComputeReport() echo.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: compute report view model
|
type Result struct {
|
||||||
// fetch bookings with From started this month, or year
|
Id string
|
||||||
bs := make([]*booking.Booking, 0)
|
Total float64
|
||||||
|
CustomerName string
|
||||||
|
From time.Time
|
||||||
|
To time.Time
|
||||||
|
Platform string
|
||||||
|
PlatformFees float64
|
||||||
|
}
|
||||||
|
res := make([]*Result, 0)
|
||||||
var startDate time.Time
|
var startDate time.Time
|
||||||
var endDate time.Time
|
var endDate time.Time
|
||||||
|
|
||||||
if period == "month" {
|
if period == "month" {
|
||||||
startDate = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.UTC)
|
startDate = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.UTC)
|
||||||
endDate = time.Date(year, time.Month(month), 31, 0, 0, 0, 0, time.UTC)
|
endDate = time.Date(year, time.Month(month), 31, 0, 0, 0, 0, time.UTC)
|
||||||
|
} else {
|
||||||
|
startDate = time.Date(year, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||||
|
endDate = time.Date(year, time.December, 31, 0, 0, 0, 0, time.UTC)
|
||||||
}
|
}
|
||||||
_ = s.db.Where("\"from\" BETWEEN ? AND ?", startDate.Format("2006-01-02"), endDate.Format("2006-01-02")).Find(&bs)
|
|
||||||
|
|
||||||
return s.renderTempl(c, http.StatusOK, views.ReportSection())
|
s.db.
|
||||||
|
Raw(`
|
||||||
|
select id, customer_name, "from", "to", platform, total, platform_fees
|
||||||
|
from (select sum(price) as total, booking_id
|
||||||
|
from bookings
|
||||||
|
join items on bookings.id = items.booking_id
|
||||||
|
where "from" between ? and ?
|
||||||
|
group by booking_id) as sbi,
|
||||||
|
(select * from bookings) as b
|
||||||
|
where sbi.booking_id = b.id;
|
||||||
|
`,
|
||||||
|
startDate.Format("2006-01-02"), endDate.Format("2006-01-02")).
|
||||||
|
Scan(&res)
|
||||||
|
|
||||||
|
reportVm := u.Map(res, func(r *Result) *views.ReportViewModel {
|
||||||
|
return &views.ReportViewModel{
|
||||||
|
Id: r.Id,
|
||||||
|
Url: templ.SafeURL(fmt.Sprintf("%s/%s", constants.RouteBooking, r.Id)),
|
||||||
|
Total: strconv.FormatFloat(r.Total, 'f', 2, 64),
|
||||||
|
CustomerName: r.CustomerName,
|
||||||
|
From: r.From.Format("2006-01-02"),
|
||||||
|
To: r.To.Format("2006-01-02"),
|
||||||
|
Platform: r.Platform,
|
||||||
|
PlatformFees: strconv.FormatFloat(r.PlatformFees, 'f', 2, 64),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return s.renderTempl(c, http.StatusOK, views.ReportSection(reportVm))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,17 @@
|
||||||
package views
|
package views
|
||||||
|
|
||||||
templ ReportSection() {
|
type ReportViewModel struct {
|
||||||
|
Id string
|
||||||
|
Url templ.SafeURL
|
||||||
|
Total string
|
||||||
|
CustomerName string
|
||||||
|
From string
|
||||||
|
To string
|
||||||
|
Platform string
|
||||||
|
PlatformFees string
|
||||||
|
}
|
||||||
|
|
||||||
|
templ ReportSection(report []*ReportViewModel) {
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<h2>Your report </h2>
|
<h2>Your report </h2>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -13,25 +24,29 @@ templ ReportSection() {
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">ID</th>
|
<th scope="col">ID</th>
|
||||||
<th scope="col">Name</th>
|
<th scope="col">Name</th>
|
||||||
<th scope="col">Total (€)</th>
|
|
||||||
<th scope="col">From</th>
|
<th scope="col">From</th>
|
||||||
<th scope="col">To</th>
|
<th scope="col">To</th>
|
||||||
|
<th scope="col">Total (€)</th>
|
||||||
<th scope="col">Platform</th>
|
<th scope="col">Platform</th>
|
||||||
|
<th scope="col">Platform Fees</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
for _, row := range report {
|
||||||
<th scope="row">
|
<tr>
|
||||||
<a href="fjkslafj">
|
<th scope="row">
|
||||||
12
|
<a href={ row.Url }>
|
||||||
</a>
|
{ row.Id }
|
||||||
</th>
|
</a>
|
||||||
<td>joe</td>
|
</th>
|
||||||
<td></td>
|
<td>{ row.CustomerName }</td>
|
||||||
<td>fgsdkjf</td>
|
<td>{ row.From }</td>
|
||||||
<td>jjxlkvj</td>
|
<td>{ row.To }</td>
|
||||||
<td>jjxlkvj</td>
|
<td>{ row.Total }</td>
|
||||||
</tr>
|
<td>{ row.Platform }</td>
|
||||||
|
<td>{ row.PlatformFees }</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</figure>
|
</figure>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,18 @@ import "context"
|
||||||
import "io"
|
import "io"
|
||||||
import "bytes"
|
import "bytes"
|
||||||
|
|
||||||
func ReportSection() templ.Component {
|
type ReportViewModel struct {
|
||||||
|
Id string
|
||||||
|
Url templ.SafeURL
|
||||||
|
Total string
|
||||||
|
CustomerName string
|
||||||
|
From string
|
||||||
|
To string
|
||||||
|
Platform string
|
||||||
|
PlatformFees string
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReportSection(report []*ReportViewModel) 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 {
|
||||||
|
|
@ -23,7 +34,117 @@ func ReportSection() templ.Component {
|
||||||
templ_7745c5c3_Var1 = templ.NopComponent
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
}
|
}
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"grid\"><h2>Your report </h2><div><button class=\"outline\">Create PDF</button></div></div><figure><table role=\"grid\"><thead><tr><th scope=\"col\">ID</th><th scope=\"col\">Name</th><th scope=\"col\">Total (€)</th><th scope=\"col\">From</th><th scope=\"col\">To</th><th scope=\"col\">Platform</th></tr></thead> <tbody><tr><th scope=\"row\"><a href=\"fjkslafj\">12</a></th><td>joe</td><td></td><td>fgsdkjf</td><td>jjxlkvj</td><td>jjxlkvj</td></tr></tbody></table></figure>")
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"grid\"><h2>Your report </h2><div><button class=\"outline\">Create PDF</button></div></div><figure><table role=\"grid\"><thead><tr><th scope=\"col\">ID</th><th scope=\"col\">Name</th><th scope=\"col\">From</th><th scope=\"col\">To</th><th scope=\"col\">Total (€)</th><th scope=\"col\">Platform</th><th scope=\"col\">Platform Fees</th></tr></thead> <tbody>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, row := range report {
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr><th scope=\"row\"><a href=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var2 templ.SafeURL = row.Url
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var2)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var3 string
|
||||||
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(row.Id)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 38, Col: 16}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></th><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var4 string
|
||||||
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(row.CustomerName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 41, Col: 28}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||||
|
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_Var5 string
|
||||||
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(row.From)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 42, Col: 20}
|
||||||
|
}
|
||||||
|
_, 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>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var6 string
|
||||||
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(row.To)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 43, Col: 18}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
|
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_Var7 string
|
||||||
|
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(row.Total)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 44, Col: 21}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||||
|
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_Var8 string
|
||||||
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(row.Platform)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 45, Col: 24}
|
||||||
|
}
|
||||||
|
_, 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(row.PlatformFees)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 46, Col: 28}
|
||||||
|
}
|
||||||
|
_, 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</tbody></table></figure>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue