changed to show this month's orders by default

This commit is contained in:
bronku 2025-04-05 12:08:46 +02:00
parent 939665ea02
commit d95d8b996e
2 changed files with 22 additions and 9 deletions

View file

@ -10,13 +10,26 @@ import (
"github.com/Bronku/iroon/internal/models"
)
func monthInterval(y int, m time.Month) (firstDay, lastDay time.Time) {
firstDay = time.Date(y, m, 1, 0, 0, 0, 0, time.UTC)
lastDay = time.Date(y, m+1, 1, 0, 0, 0, -1, time.UTC)
return firstDay, lastDay
}
func (h *Server) orders(_ *http.Request) (any, int, error) {
//r.URL.Query().Get()
orders, err := h.s.GetFilteredOrder("", time.Now(), time.Now().Add(time.Hour*24))
var (
y int
m time.Month
)
y, m, _ = time.Now().Date()
first, last := monthInterval(y, m)
fmt.Println(first, last)
orders, err := h.s.GetFilteredOrder("", first, last)
data := struct {
Today string
First string
Last string
Orders []models.Order
}{Today: time.Now().Format("2006-01-02"), Orders: orders}
}{first.Format("2006-01-02"), last.Format("2006-01-02"), orders}
return data, http.StatusOK, err
}

View file

@ -9,10 +9,10 @@ Orders
<input type="search" name="q" placeholder="Search orders...">
</label>
<label for="from">form</label>
<input type="date" value="{{.Today}}" id="from" name="from">
<label for="from">from</label>
<input type="date" value="{{.First}}" id="from" name="from">
<label for="from">to</label>
<label for="to"></label><input type="date" value="{{.Today}}" id="to" name="to">
<label for="to"></label><input type="date" value="{{.Last}}" id="to" name="to">
<div class="htmx-indicator">
Searching...
@ -48,6 +48,6 @@ Orders
<th>{{.Status}}</th>
<th>{{.Total}}</th>
</tr>
{{end}}</table>
{{end}}
</table>
{{end}}