diff --git a/index.html b/index.html index a2fef9b..af886df 100644 --- a/index.html +++ b/index.html @@ -1,402 +1,539 @@ - - - - - - Poppe Potthoff - Záznam jízdy služebního vozu - - - - - - - - - - - -
-
-

Záznam jízdy služebního vozu

-

Systém pro evidenci služebních jízd společnosti Poppe + Potthoff

-
-
- - -
-
- -
- -

Nový záznam jízdy

-
- - -
-
-
-
- -
-
- -
- -
-
- -
- -
-
- -
- -
-
-
- -
- -
-
-
- -
- -
- -
-
-
-
- - -

Powered by Mapy.cz

-
- -
- -
-
- -
- -
-
- -
-
- -
-
- -
- -
- km -
-
-
- -
- -
-
- -
- -
- km -
-
-
-
- -
-
-
- Celkem ujetá vzdálenost: - 0 km -
-
- -
- -
- - - - -
-
-
-
- - - - - - + + + + + + Poppe Potthoff - Záznam jízdy služebního vozu + + + + + + + + + + + +
+
+

Záznam jízdy služebního vozu

+

Systém pro evidenci služebních jízd společnosti Poppe + Potthoff

+
+
+ + +
+
+ +
+ +

Nový záznam jízdy

+
+ + +
+
+
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+ +
+
+
+ + +
+
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+ + +
+
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+ +
+
+
+
+ + +

Powered by Mapy.cz

+
+ +
+ +
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+ +
+ km +
+
+
+ +
+ +
+
+ +
+ +
+ km +
+
+
+
+ +
+
+
+ Celkem ujetá vzdálenost: + 0 km +
+
+ Celková doba jízdy: + 0:00 +
+
+ +
+ +
+ + + + +
+
+
+
+ + + + + + \ No newline at end of file diff --git a/main.go b/main.go index f14c1fe..4e42260 100644 --- a/main.go +++ b/main.go @@ -16,8 +16,12 @@ import ( type TripEntry struct { Name string `json:"name"` + Vehicle string `json:"vehicle"` Destination string `json:"destination"` - Date string `json:"date"` + DateStart string `json:"date_start"` + TimeStart string `json:"time_start"` + DateEnd string `json:"date_end"` + TimeEnd string `json:"time_end"` Purpose string `json:"purpose"` KmStart int `json:"km_start"` KmEnd int `json:"km_end"` @@ -104,7 +108,7 @@ func handleSubmit(w http.ResponseWriter, r *http.Request) { return } - if entry.Name == "" || entry.Destination == "" || entry.Date == "" || entry.Purpose == "" { + if entry.Name == "" || entry.Destination == "" || entry.DateStart == "" || entry.DateEnd == "" || entry.Purpose == "" { log.Printf("Chybějící povinná pole: %+v", entry) w.WriteHeader(http.StatusBadRequest) w.Write([]byte(`{"error":"Missing required fields"}`)) @@ -118,20 +122,25 @@ func handleSubmit(w http.ResponseWriter, r *http.Request) { return } - // Formátování data do českého formátu - parsedDate, err := time.Parse("2006-01-02", entry.Date) - if err == nil { - czechMonths := []string{ - "ledna", "února", "března", "dubna", "května", "června", - "července", "srpna", "září", "října", "listopadu", "prosince", - } - monthName := czechMonths[parsedDate.Month()-1] - entry.Date = fmt.Sprintf("%d. %s %d", parsedDate.Day(), monthName, parsedDate.Year()) - } else { - log.Printf("Chyba při parsování data: %v", err) + // Formátování dat do českého formátu + czechMonths := []string{ + "ledna", "února", "března", "dubna", "května", "června", + "července", "srpna", "září", "října", "listopadu", "prosince", } - err = sendEmail(entry) + // Zpracování začátku cesty + parsedDateStart, err := time.Parse("2006-01-02", entry.DateStart) + if err != nil { + log.Printf("Chyba při parsování data začátku: %v", err) + } + + // Zpracování konce cesty + parsedDateEnd, err := time.Parse("2006-01-02", entry.DateEnd) + if err != nil { + log.Printf("Chyba při parsování data konce: %v", err) + } + + err = sendEmail(entry, parsedDateStart, parsedDateEnd, czechMonths) if err != nil { log.Printf("Chyba při odesílání emailu: %v", err) w.WriteHeader(http.StatusInternalServerError) @@ -143,12 +152,12 @@ func handleSubmit(w http.ResponseWriter, r *http.Request) { w.Write([]byte(`{"message":"Záznam byl úspěšně uložen a email odeslán"}`)) } -func sendEmail(entry TripEntry) error { - smtpHost := "mail.pp-kunovice.cz" +func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechMonths []string) error { + smtpHost := "smtp.gmail.com" smtpPort := 465 - sender := "sluzebnicek@pp-kunovice.cz" - password := "7g}qznB5bj" - recipient := "sluzebnicek@pp-kunovice.cz" + sender := "contact.dvorak@gmail.com" + password := "pnhkcsahbwsbpyqj" + recipient := "contact.dvorak@gmail.com" m := gomail.NewMessage() m.SetHeader("From", sender) @@ -158,57 +167,279 @@ func sendEmail(entry TripEntry) error { var htmlContent strings.Builder htmlContent.WriteString(` + + + + Záznam o jízdě služebním autem
-

Záznam o jízdě služebním autem

+
+

Záznam o jízdě služebním autem

+
+
`) - fmt.Fprintf(&htmlContent, `

Řidič: %s

`, entry.Name) - fmt.Fprintf(&htmlContent, `

Kam: %s

`, entry.Destination) - fmt.Fprintf(&htmlContent, `

Datum: %s

`, entry.Date) - fmt.Fprintf(&htmlContent, `

Účel jízdy: %s

`, entry.Purpose) - fmt.Fprintf(&htmlContent, `

Kilometry na začátku: %d km

`, entry.KmStart) - fmt.Fprintf(&htmlContent, `

Kilometry na konci: %d km

`, entry.KmEnd) - fmt.Fprintf(&htmlContent, `

Ujeté kilometry: %d km

`, entry.KmEnd-entry.KmStart) + // Formátování dat a časů pro zobrazení + formattedDateStart := "" + if parsedDateStart.IsZero() == false { + monthNameStart := czechMonths[parsedDateStart.Month()-1] + formattedDateStart = fmt.Sprintf("%d. %s %d", parsedDateStart.Day(), monthNameStart, parsedDateStart.Year()) + } else { + formattedDateStart = entry.DateStart + } + + formattedDateEnd := "" + if !parsedDateEnd.IsZero() { + monthNameEnd := czechMonths[parsedDateEnd.Month()-1] + formattedDateEnd = fmt.Sprintf("%d. %s %d", parsedDateEnd.Day(), monthNameEnd, parsedDateEnd.Year()) + } else { + formattedDateEnd = entry.DateEnd + } + + // Výpočet celkové doby jízdy + startDateTime, startErr := time.Parse("2006-01-02T15:04", fmt.Sprintf("%sT%s", entry.DateStart, entry.TimeStart)) + endDateTime, endErr := time.Parse("2006-01-02T15:04", fmt.Sprintf("%sT%s", entry.DateEnd, entry.TimeEnd)) + + totalDurationStr := "Neznámá" + if startErr == nil && endErr == nil { + diffMs := endDateTime.Sub(startDateTime) + if diffMs >= 0 { + diffDays := int(diffMs.Hours() / 24) + diffHours := int(diffMs.Hours()) % 24 + diffMinutes := int(diffMs.Minutes()) % 60 + + if diffDays > 0 { + dayWord := "dní" + if diffDays == 1 { + dayWord = "den" + } else if diffDays >= 2 && diffDays <= 4 { + dayWord = "dny" + } + totalDurationStr = fmt.Sprintf("%d %s, %d h %d min", diffDays, dayWord, diffHours, diffMinutes) + } else { + totalDurationStr = fmt.Sprintf("%d h %d min", diffHours, diffMinutes) + } + } + } + + // Vypsání informací o řidiči a vozidle + htmlContent.WriteString(`
+
Informace o řidiči a vozidle
+
+
+ Řidič + ` + entry.Name + ` +
+
+ Vozidlo + ` + entry.Vehicle + ` +
+
+
`) + + // Vypsání informací o trase + htmlContent.WriteString(`
+
Informace o trase
+
+
+ Cíl cesty + ` + entry.Destination + ` +
+
+ Účel jízdy + ` + entry.Purpose + ` +
+
+
`) + + // Vypsání informací o času + htmlContent.WriteString(`
+
Časové údaje
+
+
+ Datum a čas odjezdu + ` + formattedDateStart + `, ` + entry.TimeStart + ` +
+
+ Datum a čas příjezdu + ` + formattedDateEnd + `, ` + entry.TimeEnd + ` +
+
+
+ Celková doba jízdy + ` + totalDurationStr + ` +
+
`) + + // Vypsání informací o kilometrech + htmlContent.WriteString(`
+
Stav tachometru
+
+
+ Stav na začátku + ` + fmt.Sprintf("%d km", entry.KmStart) + ` +
+
+ Stav na konci + ` + fmt.Sprintf("%d km", entry.KmEnd) + ` +
+
+
+ Celkem ujeto + ` + fmt.Sprintf("%d km", entry.KmEnd-entry.KmStart) + ` +
+
`) if entry.Coordinates != nil { - fmt.Fprintf(&htmlContent, `

GPS souřadnice: %s, %s

`, entry.Coordinates.Lat, entry.Coordinates.Lng) - fmt.Fprintf(&htmlContent, `

Zobrazit na mapě

`, entry.Coordinates.Lng, entry.Coordinates.Lat) + htmlContent.WriteString(`
+
GPS Souřadnice
+
+
+ Souřadnice + ` + entry.Coordinates.Lat + `, ` + entry.Coordinates.Lng + ` +
+
+ + Zobrazit na mapě + +
`) } htmlContent.WriteString(` +
+