Servis: QR kod na štampanom nalogu
QR kod se generiše server-strano (skip2/go-qrcode) i ugrađuje kao base64 PNG u zaglavlje štampe — skeniranjem se otvara nalog u programu
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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=
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -81,10 +81,19 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="nalog-broj">
|
||||
<div style="display:flex;align-items:flex-start;gap:14px;justify-content:flex-end;">
|
||||
<div>
|
||||
<div class="nalog-naslov">Servisni nalog</div>
|
||||
<div class="nalog-broj-vrednost">{{.Nalog.BrojNaloga}}</div>
|
||||
<div style="margin-top:6px;"><span class="status">{{.Nalog.Status}}</span></div>
|
||||
</div>
|
||||
{{if .QRKod}}
|
||||
<img src="data:image/png;base64,{{.QRKod}}" width="80" height="80"
|
||||
alt="QR {{.Nalog.BrojNaloga}}"
|
||||
style="image-rendering:pixelated;border:1px solid #ddd;border-radius:4px;">
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- datumi i klijent -->
|
||||
|
||||
Reference in New Issue
Block a user