compute report part 1

This commit is contained in:
Ruidy 2024-02-12 14:48:28 +01:00
parent 37ecf522ea
commit 6bdecd33f5
No known key found for this signature in database
GPG key ID: E00F51288CB857CC

View file

@ -106,7 +106,6 @@ func (s Server) handleBookingPage() echo.HandlerFunc {
component := views.BookingById(b, constants.Items, constants.Platforms, constants.PaymentMethods)
return s.renderTempl(c, http.StatusOK, component)
}
}
@ -166,7 +165,7 @@ func (s Server) handleReportsPage() echo.HandlerFunc {
func (s Server) handleComputeReport() echo.HandlerFunc {
return func(c echo.Context) error {
period := c.QueryParam("period")
period := c.FormValue("period")
if !u.Contains([]string{"month", "year"}, period) {
return &echo.HTTPError{
Code: http.StatusBadRequest,
@ -174,7 +173,7 @@ func (s Server) handleComputeReport() echo.HandlerFunc {
}
}
monthStr := c.QueryParam("month")
monthStr := c.FormValue("month")
month, err := strconv.Atoi(monthStr)
if err != nil || month < 1 || month > 12 {
return &echo.HTTPError{
@ -183,7 +182,7 @@ func (s Server) handleComputeReport() echo.HandlerFunc {
}
}
yearStr := c.QueryParam("year")
yearStr := c.FormValue("year")
year, err := strconv.Atoi(yearStr)
if err != nil {
return &echo.HTTPError{
@ -191,13 +190,24 @@ func (s Server) handleComputeReport() echo.HandlerFunc {
Message: fmt.Sprintf("%q is not a valid year", year),
}
}
// TODO: compute report view model
// fetch bookings with From started this month, or year
bs := make([]*booking.Booking, 0)
var startDate time.Time
var endDate time.Time
if period == "month" {
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)
}
_ = 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())
}
}
func (s Server) handleCreateInvoicePdf() echo.HandlerFunc {
return func(c echo.Context) error {
return func(_ echo.Context) error {
data := struct {
Context map[string]any `json:"context"`
Path string `json:"path"`