add internal fee and profit

This commit is contained in:
Ruidy 2024-02-26 17:41:28 +01:00
parent 8c9886991e
commit 8ea51da144
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
3 changed files with 56 additions and 12 deletions

View file

@ -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
}

View file

@ -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) {
<th scope="col">To</th>
<th scope="col">Total (€)</th>
<th scope="col">Platform</th>
<th scope="col">Platform Fees</th>
<th scope="col">Platform Fees (€)</th>
<th scope="col">Fees (€)</th>
<th scope="col">Profit (€)</th>
</tr>
</thead>
<tbody>
@ -45,6 +49,8 @@ templ ReportSection(report []*ReportViewModel) {
<td>{ row.Total }</td>
<td>{ row.Platform }</td>
<td>{ row.PlatformFees }</td>
<td>{ row.Fee }</td>
<td>{ row.Profit }</td>
</tr>
}
</tbody>

View file

@ -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
}