mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
add card only revenue
This commit is contained in:
parent
55ee7f8638
commit
b8c83b2d2d
4 changed files with 70 additions and 29 deletions
|
|
@ -62,11 +62,12 @@ func (bs Service) CreateItem(bid int, item string, qty int, price float64, metho
|
|||
}
|
||||
|
||||
type Report struct {
|
||||
Lines []*Line
|
||||
Total float64
|
||||
PlatformFees float64
|
||||
Fee float64
|
||||
Profit float64
|
||||
Lines []*Line
|
||||
CardTotal float64
|
||||
}
|
||||
|
||||
type Line struct {
|
||||
|
|
@ -109,25 +110,38 @@ func (bs Service) BuildReport(period string, month, year int) *Report {
|
|||
endDate = time.Date(year, time.December, 31, 0, 0, 0, 0, time.UTC)
|
||||
}
|
||||
|
||||
bs.db.
|
||||
Raw(`
|
||||
select id, customer_name, "from", "to", platform, total, platform_fees
|
||||
from (select sum(price*quantity) 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")).
|
||||
bs.db.Raw(`
|
||||
select id, customer_name, "from", "to", platform, total, platform_fees
|
||||
from (select sum(price*quantity) 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(&lines)
|
||||
|
||||
cardTotal := 0.0
|
||||
bs.db.Raw(`
|
||||
select sum(total)
|
||||
from (select sum(price * quantity) as total
|
||||
from bookings
|
||||
join items on bookings.id = items.booking_id
|
||||
where "from" between ? and ?
|
||||
and payment_method = 'Card'
|
||||
group by booking_id);
|
||||
`,
|
||||
startDate.Format("2006-01-02"), endDate.Format("2006-01-02")).
|
||||
Scan(&cardTotal)
|
||||
|
||||
return &Report{
|
||||
Total: u.Reduce(lines, func(l *Line, sum float64) float64 { return sum + l.Total }, 0.0),
|
||||
PlatformFees: u.Reduce(lines, func(l *Line, sum float64) float64 { return sum + l.PlatformFees }, 0.0),
|
||||
Fee: u.Reduce(lines, func(l *Line, sum float64) float64 { return sum + l.Fee() }, 0.0),
|
||||
Profit: u.Reduce(lines, func(l *Line, sum float64) float64 { return sum + l.Profit() }, 0.0),
|
||||
Lines: lines,
|
||||
CardTotal: cardTotal,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ func handleComputeReport(bs *booking.Service, hc *config.Host) echo.HandlerFunc
|
|||
PlatformFees: strconv.FormatFloat(r.PlatformFees, 'f', 2, 64),
|
||||
Fee: strconv.FormatFloat(r.Fee, 'f', 2, 64),
|
||||
Profit: strconv.FormatFloat(r.Profit, 'f', 2, 64),
|
||||
CardTotal: strconv.FormatFloat(r.CardTotal, 'f', 2, 64),
|
||||
Lines: u.Map(r.Lines, func(l *booking.Line) *views.ReportLine {
|
||||
return &views.ReportLine{
|
||||
Id: l.InvoiceNumber(hc),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package views
|
|||
|
||||
type ReportViewModel struct {
|
||||
Total string
|
||||
CardTotal string
|
||||
PlatformFees string
|
||||
Fee string
|
||||
Profit string
|
||||
|
|
@ -36,7 +37,7 @@ templ ReportSection(report *ReportViewModel) {
|
|||
<th scope="col">Name</th>
|
||||
<th scope="col">From</th>
|
||||
<th scope="col">To</th>
|
||||
<th scope="col">Total (€)</th>
|
||||
<th scope="col">Revenue (€)</th>
|
||||
<th scope="col">Platform</th>
|
||||
<th scope="col">Platform Fees (€)</th>
|
||||
<th scope="col">Fees (€)</th>
|
||||
|
|
@ -74,6 +75,17 @@ templ ReportSection(report *ReportViewModel) {
|
|||
<td>{ report.Fee }</td>
|
||||
<td>{ report.Profit }</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td scope="row"></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>Card-only: </td>
|
||||
<td>{ report.CardTotal }</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import "bytes"
|
|||
|
||||
type ReportViewModel struct {
|
||||
Total string
|
||||
CardTotal string
|
||||
PlatformFees string
|
||||
Fee string
|
||||
Profit string
|
||||
|
|
@ -44,7 +45,7 @@ func ReportSection(report *ReportViewModel) templ.Component {
|
|||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
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><div class=\"overflow-auto\"><table class=\"striped\"><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><th scope=\"col\">Fees (€)</th><th scope=\"col\">Profit (€)</th></tr></thead> <tbody>")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"grid\"><h2>Your report </h2><div><button class=\"outline\">Create PDF</button></div></div><div class=\"overflow-auto\"><table class=\"striped\"><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\">Revenue (€)</th><th scope=\"col\">Platform</th><th scope=\"col\">Platform Fees (€)</th><th scope=\"col\">Fees (€)</th><th scope=\"col\">Profit (€)</th></tr></thead> <tbody>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
|
@ -65,7 +66,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: 50, Col: 16}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 51, Col: 16}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -78,7 +79,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: 53, Col: 28}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 54, Col: 28}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -91,7 +92,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: 54, Col: 20}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 55, Col: 20}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -104,7 +105,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: 55, Col: 18}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 56, Col: 18}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -117,7 +118,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: 56, Col: 21}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 57, Col: 21}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -130,7 +131,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: 57, Col: 24}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 58, Col: 24}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -143,7 +144,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: 58, Col: 28}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 59, Col: 28}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -156,7 +157,7 @@ func ReportSection(report *ReportViewModel) templ.Component {
|
|||
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: 59, Col: 19}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 60, Col: 19}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -169,7 +170,7 @@ func ReportSection(report *ReportViewModel) templ.Component {
|
|||
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: 60, Col: 22}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 61, Col: 22}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -187,7 +188,7 @@ func ReportSection(report *ReportViewModel) templ.Component {
|
|||
var templ_7745c5c3_Var12 string
|
||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(report.Total)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 70, Col: 23}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 71, Col: 23}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -200,7 +201,7 @@ func ReportSection(report *ReportViewModel) templ.Component {
|
|||
var templ_7745c5c3_Var13 string
|
||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(report.PlatformFees)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 72, Col: 30}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 73, Col: 30}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -213,7 +214,7 @@ func ReportSection(report *ReportViewModel) templ.Component {
|
|||
var templ_7745c5c3_Var14 string
|
||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(report.Fee)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 73, Col: 21}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 74, Col: 21}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
|
@ -226,13 +227,26 @@ func ReportSection(report *ReportViewModel) templ.Component {
|
|||
var templ_7745c5c3_Var15 string
|
||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(report.Profit)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 74, Col: 24}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 75, Col: 24}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td></tr></tfoot></table></div>")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td></tr><tr><td scope=\"row\"></td><td></td><td></td><td>Card-only: </td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var16 string
|
||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(report.CardTotal)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 82, Col: 27}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td></td><td></td><td></td><td></td></tr></tfoot></table></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue