working on printable PDF Forms
All checks were successful
Tests / Run Go Tests (push) Successful in 30s
All checks were successful
Tests / Run Go Tests (push) Successful in 30s
This commit is contained in:
29
Backend/endpoints/pdf.go
Normal file
29
Backend/endpoints/pdf.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package endpoints
|
||||
|
||||
import (
|
||||
"arbeitszeitmessung/helper"
|
||||
"arbeitszeitmessung/models"
|
||||
"arbeitszeitmessung/templates"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func PDFHandler(w http.ResponseWriter, r *http.Request) {
|
||||
helper.RequiresLogin(Session, w, r)
|
||||
startDate, err := time.Parse("2006-01-02", "2025-08-01")
|
||||
if err != nil {
|
||||
log.Println("Error")
|
||||
}
|
||||
endDate := startDate.AddDate(0, 1, -1)
|
||||
|
||||
user, err := models.GetUserFromSession(Session, r.Context())
|
||||
if err != nil {
|
||||
log.Println("Error getting user!")
|
||||
}
|
||||
|
||||
weeks := models.GetWorkDays(user.CardUID, startDate, endDate)
|
||||
|
||||
log.Printf("Using Dates: %s - %s\n", startDate.String(), endDate.String())
|
||||
templates.PDFReportEmploye(user, weeks, startDate, endDate).Render(r.Context(), w)
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func submitReport(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func showWeeks(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := (*models.User).GetUserFromSession(nil, Session, r.Context())
|
||||
user, err := models.GetUserFromSession(Session, r.Context())
|
||||
if err != nil {
|
||||
log.Println("No user found with the given personal number!")
|
||||
http.Redirect(w, r, "/user/login", http.StatusSeeOther)
|
||||
|
||||
@@ -23,7 +23,7 @@ func TeamPresenceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func teamPresence(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := (*models.User).GetUserFromSession(nil, Session, r.Context())
|
||||
user, err := models.GetUserFromSession(Session, r.Context())
|
||||
if err != nil {
|
||||
log.Println("Error getting user!", err)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func parseTimestamp(r *http.Request, getKey string, fallback string) (time.Time,
|
||||
|
||||
// Returns bookings from DB with similar card uid -> checks for card uid in http query params
|
||||
func getBookings(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := (*models.User).GetUserFromSession(nil, Session, r.Context())
|
||||
user, err := models.GetUserFromSession(Session, r.Context())
|
||||
if err != nil {
|
||||
log.Println("No user found with the given personal number!")
|
||||
http.Redirect(w, r, "/user/login", http.StatusSeeOther)
|
||||
@@ -66,7 +66,7 @@ func getBookings(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
tsTo = tsTo.AddDate(0, 0, 1) // so that today is inside
|
||||
|
||||
workDays := (*models.WorkDay).GetWorkDays(nil, user.CardUID, tsFrom, tsTo)
|
||||
workDays := models.GetWorkDays(user.CardUID, tsFrom, tsTo)
|
||||
sort.Slice(workDays, func(i, j int) bool {
|
||||
return workDays[i].Day.After(workDays[j].Day)
|
||||
})
|
||||
@@ -104,7 +104,7 @@ func updateBooking(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("Error loading location", err)
|
||||
loc = time.Local
|
||||
}
|
||||
user, err := (*models.User).GetUserFromSession(nil, Session, r.Context())
|
||||
user, err := models.GetUserFromSession(Session, r.Context())
|
||||
if err != nil {
|
||||
log.Println("No user found!", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user