diff --git a/internal/server/handle_reports.go b/internal/server/handle_reports.go
index e3ecbc1..e52cceb 100644
--- a/internal/server/handle_reports.go
+++ b/internal/server/handle_reports.go
@@ -2,7 +2,6 @@ package server
import (
"fmt"
- "log"
"net/http"
"strconv"
"time"
@@ -69,16 +68,18 @@ func handleComputeReport(bs *booking.Service, hc *config.Host) echo.HandlerFunc
res := bs.BuildReport(period, month, year)
reportVm := u.Map(res, func(r *booking.Line) *views.ReportViewModel {
- log.Printf("%+v", r)
+ fee := computeFee(r)
return &views.ReportViewModel{
Id: r.InvoiceNumber(hc),
- Url: templ.SafeURL(fmt.Sprintf("%s/%s", constants.RouteBooking, r.Id)),
+ Url: templ.SafeURL(fmt.Sprintf("%s/%d", 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),
+ Fee: strconv.FormatFloat(fee, 'f', 2, 64),
+ Profit: strconv.FormatFloat(r.Total-r.PlatformFees-fee, 'f', 2, 64),
// TODO: add NemoImmo part and compute the profit
}
})
@@ -86,3 +87,12 @@ func handleComputeReport(bs *booking.Service, hc *config.Host) echo.HandlerFunc
return renderTempl(c, http.StatusOK, views.ReportSection(reportVm))
}
}
+
+func computeFee(r *booking.Line) (f float64) {
+ if r.Platform == "Other" {
+ f = r.Total * 5 / 100
+ } else {
+ f = r.Total * 10 / 100
+ }
+ return f
+}
diff --git a/internal/views/report_section.templ b/internal/views/report_section.templ
index 0612a0f..bdf2cc9 100644
--- a/internal/views/report_section.templ
+++ b/internal/views/report_section.templ
@@ -9,6 +9,8 @@ type ReportViewModel struct {
To string
Platform string
PlatformFees string
+ Fee string
+ Profit string
}
templ ReportSection(report []*ReportViewModel) {
@@ -28,7 +30,9 @@ templ ReportSection(report []*ReportViewModel) {
To |
Total (€) |
Platform |
- Platform Fees |
+ Platform Fees (€) |
+ Fees (€) |
+ Profit (€) |
@@ -45,6 +49,8 @@ templ ReportSection(report []*ReportViewModel) {
{ row.Total } |
{ row.Platform } |
{ row.PlatformFees } |
+ { row.Fee } |
+ { row.Profit } |
}
diff --git a/internal/views/report_section_templ.go b/internal/views/report_section_templ.go
index 74a628f..22241aa 100644
--- a/internal/views/report_section_templ.go
+++ b/internal/views/report_section_templ.go
@@ -19,6 +19,8 @@ type ReportViewModel struct {
To string
Platform string
PlatformFees string
+ Fee string
+ Profit string
}
func ReportSection(report []*ReportViewModel) templ.Component {
@@ -55,7 +57,7 @@ func ReportSection(report []*ReportViewModel) templ.Component {
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}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 42, Col: 16}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
@@ -68,7 +70,7 @@ func ReportSection(report []*ReportViewModel) templ.Component {
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}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 45, Col: 28}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
@@ -81,7 +83,7 @@ func ReportSection(report []*ReportViewModel) templ.Component {
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}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 46, Col: 20}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
@@ -94,7 +96,7 @@ func ReportSection(report []*ReportViewModel) templ.Component {
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}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 47, Col: 18}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
@@ -107,7 +109,7 @@ func ReportSection(report []*ReportViewModel) templ.Component {
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}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 48, Col: 21}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
@@ -120,7 +122,7 @@ func ReportSection(report []*ReportViewModel) templ.Component {
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}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 49, Col: 24}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
@@ -133,7 +135,7 @@ func ReportSection(report []*ReportViewModel) templ.Component {
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}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 50, Col: 28}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
@@ -143,8 +145,34 @@ func ReportSection(report []*ReportViewModel) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
+ var templ_7745c5c3_Var10 string
+ templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(row.Fee)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 51, Col: 19}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 11)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var11 string
+ templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(row.Profit)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 52, Col: 22}
+ }
+ _, 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, 12)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 11)
+ templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 13)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}