diff --git a/go.mod b/go.mod index 6563c65..123ec91 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/ncruces/go-strftime v1.0.0 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect github.com/stretchr/testify v1.11.1 // indirect golang.org/x/sys v0.45.0 // indirect golang.org/x/tools v0.44.0 // indirect diff --git a/go.sum b/go.sum index 12a182c..8a692a4 100644 --- a/go.sum +++ b/go.sum @@ -26,6 +26,8 @@ github.com/pquerna/otp v1.5.0 h1:NMMR+WrmaqXU4EzdGJEE1aUUI0AMRzsp96fFFWNPwxs= github.com/pquerna/otp v1.5.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= diff --git a/internal/handler/servis.go b/internal/handler/servis.go index 6fa8bec..2b118d4 100644 --- a/internal/handler/servis.go +++ b/internal/handler/servis.go @@ -1,6 +1,7 @@ package handler import ( + "encoding/base64" "log/slog" "net/http" "strconv" @@ -13,6 +14,7 @@ import ( "ntech/internal/model" "github.com/go-chi/chi/v5" + qrcode "github.com/skip2/go-qrcode" ) // PodaciServisa su podaci za stranicu sa listom servisnih naloga @@ -591,6 +593,7 @@ type PodaciStampeServisa struct { Adresa string Telefon string PIB string + QRKod string // base64 PNG QR koda sa URL-om naloga } // StampaServisa renderuje print-friendly stranicu za servisni nalog @@ -644,6 +647,17 @@ func (h *Handler) StampaServisa(w http.ResponseWriter, r *http.Request) { ukupnoDelovi += d.Ukupno() } + // QR kod sadrži URL naloga — isti host kao što korisnik koristi + scheme := "http" + if r.TLS != nil { + scheme = "https" + } + nalogURL := scheme + "://" + r.Host + "/servis/" + strconv.FormatInt(id, 10) + var qrKod string + if png, err := qrcode.Encode(nalogURL, qrcode.Medium, 160); err == nil { + qrKod = base64.StdEncoding.EncodeToString(png) + } + h.renderujStandalone(w, "servis_stampa", PodaciStampeServisa{ Nalog: *nalog, ServisniDelovi: delovi, @@ -655,6 +669,7 @@ func (h *Handler) StampaServisa(w http.ResponseWriter, r *http.Request) { Adresa: podesavanja["adresa"], Telefon: podesavanja["telefon"], PIB: podesavanja["pib"], + QRKod: qrKod, }) } diff --git a/web/templates/stranice/servis_stampa.html b/web/templates/stranice/servis_stampa.html index ad54739..fdf6953 100644 --- a/web/templates/stranice/servis_stampa.html +++ b/web/templates/stranice/servis_stampa.html @@ -81,9 +81,18 @@