Magacin — forma puna širina, responsive popravke
This commit is contained in:
@@ -57,6 +57,15 @@ func main() {
|
||||
r.Get("/podesavanja", h.Podesavanja)
|
||||
r.Post("/podesavanja/sacuvaj", h.SacuvajPodesavanja)
|
||||
r.Get("/tema/{tema}", h.PromeniTemu)
|
||||
r.Get("/magacin", h.Magacin)
|
||||
r.Get("/magacin/novi", h.NoviArtikal)
|
||||
r.Post("/magacin/novi", h.SacuvajArtikal)
|
||||
r.Get("/magacin/izmeni/{id}", h.IzmeniArtikal)
|
||||
r.Post("/magacin/izmeni/{id}", h.SacuvajIzmenuArtikla)
|
||||
r.Get("/magacin/obrisi/{id}", h.ObrisiArtikal)
|
||||
r.Get("/magacin/kategorije", h.Kategorije)
|
||||
r.Post("/magacin/kategorije/dodaj", h.DodajKategoriju)
|
||||
r.Get("/magacin/kategorije/obrisi/{id}", h.ObrisiKategoriju)
|
||||
|
||||
log.Printf("NTech pokrenut na portu %s", port)
|
||||
err = http.ListenAndServe(":"+port, r)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"ntech/internal/model"
|
||||
)
|
||||
|
||||
// ArtikalRepository definiše operacije nad artiklima
|
||||
type ArtikalRepository interface {
|
||||
Lista(ctx context.Context, filter ArtikalFilter) ([]model.ArtikalSaKategorijom, error)
|
||||
DohvatiID(ctx context.Context, id int64) (*model.Artikal, error)
|
||||
Kreiraj(ctx context.Context, a *model.Artikal) (int64, error)
|
||||
Izmeni(ctx context.Context, a *model.Artikal) error
|
||||
Obrisi(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
// KategorijaRepository definiše operacije nad kategorijama
|
||||
type KategorijaRepository interface {
|
||||
Lista(ctx context.Context) ([]model.Kategorija, error)
|
||||
Kreiraj(ctx context.Context, k *model.Kategorija) (int64, error)
|
||||
}
|
||||
|
||||
// ArtikalFilter definiše parametre za filtriranje liste artikala
|
||||
type ArtikalFilter struct {
|
||||
Pretraga string
|
||||
KategorijaID *int64
|
||||
SamoKriticni bool
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"ntech/internal/db"
|
||||
"ntech/internal/model"
|
||||
)
|
||||
|
||||
// ArtikalRepo je SQLite implementacija ArtikalRepository interfejsa
|
||||
type ArtikalRepo struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
// NoviArtikalRepo kreira novi ArtikalRepo
|
||||
func NoviArtikalRepo(db *sql.DB) *ArtikalRepo {
|
||||
return &ArtikalRepo{db: db}
|
||||
}
|
||||
|
||||
// Lista vraća listu artikala sa opcionalnim filterima
|
||||
func (r *ArtikalRepo) Lista(ctx context.Context, filter db.ArtikalFilter) ([]model.ArtikalSaKategorijom, error) {
|
||||
upit := `
|
||||
SELECT
|
||||
a.id, a.kategorija_id, a.naziv, a.opis,
|
||||
a.kolicina, a.kolicina_min, a.lokacija,
|
||||
a.nabavna_cena, a.prodajna_cena, a.napomena, a.datum_unosa,
|
||||
COALESCE(k.naziv, '') as kategorija_naziv
|
||||
FROM artikli a
|
||||
LEFT JOIN kategorije k ON a.kategorija_id = k.id
|
||||
WHERE 1=1`
|
||||
|
||||
args := []any{}
|
||||
|
||||
if filter.Pretraga != "" {
|
||||
upit += " AND a.naziv LIKE ?"
|
||||
args = append(args, "%"+filter.Pretraga+"%")
|
||||
}
|
||||
|
||||
if filter.KategorijaID != nil {
|
||||
upit += " AND a.kategorija_id = ?"
|
||||
args = append(args, *filter.KategorijaID)
|
||||
}
|
||||
|
||||
if filter.SamoKriticni {
|
||||
upit += " AND a.kolicina <= a.kolicina_min"
|
||||
}
|
||||
|
||||
upit += " ORDER BY a.naziv ASC"
|
||||
|
||||
redovi, err := r.db.QueryContext(ctx, upit, args...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ntech: ArtikalRepo.Lista: %w", err)
|
||||
}
|
||||
defer redovi.Close()
|
||||
|
||||
var rezultat []model.ArtikalSaKategorijom
|
||||
for redovi.Next() {
|
||||
var a model.ArtikalSaKategorijom
|
||||
var kategorijaID sql.NullInt64
|
||||
|
||||
err := redovi.Scan(
|
||||
&a.ID, &kategorijaID, &a.Naziv, &a.Opis,
|
||||
&a.Kolicina, &a.KolicinMin, &a.Lokacija,
|
||||
&a.NabavnaCena, &a.ProdajnaCena, &a.Napomena, &a.DatumUnosa,
|
||||
&a.KategorijaNaziv,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ntech: ArtikalRepo.Lista: scan: %w", err)
|
||||
}
|
||||
|
||||
if kategorijaID.Valid {
|
||||
a.KategorijaID = &kategorijaID.Int64
|
||||
}
|
||||
|
||||
a.KriticnaZaliha = a.Kolicina <= a.KolicinMin
|
||||
|
||||
rezultat = append(rezultat, a)
|
||||
}
|
||||
|
||||
return rezultat, nil
|
||||
}
|
||||
|
||||
// DohvatiID vraća jedan artikal po ID-u
|
||||
func (r *ArtikalRepo) DohvatiID(ctx context.Context, id int64) (*model.Artikal, error) {
|
||||
var a model.Artikal
|
||||
var kategorijaID sql.NullInt64
|
||||
|
||||
err := r.db.QueryRowContext(ctx, `
|
||||
SELECT id, kategorija_id, naziv, opis, kolicina, kolicina_min,
|
||||
lokacija, nabavna_cena, prodajna_cena, napomena, datum_unosa
|
||||
FROM artikli WHERE id = ?`, id).Scan(
|
||||
&a.ID, &kategorijaID, &a.Naziv, &a.Opis,
|
||||
&a.Kolicina, &a.KolicinMin, &a.Lokacija,
|
||||
&a.NabavnaCena, &a.ProdajnaCena, &a.Napomena, &a.DatumUnosa,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ntech: ArtikalRepo.DohvatiID: %w", err)
|
||||
}
|
||||
|
||||
if kategorijaID.Valid {
|
||||
a.KategorijaID = &kategorijaID.Int64
|
||||
}
|
||||
|
||||
return &a, nil
|
||||
}
|
||||
|
||||
// Kreiraj dodaje novi artikal u bazu
|
||||
func (r *ArtikalRepo) Kreiraj(ctx context.Context, a *model.Artikal) (int64, error) {
|
||||
rezultat, err := r.db.ExecContext(ctx, `
|
||||
INSERT INTO artikli
|
||||
(kategorija_id, naziv, opis, kolicina, kolicina_min, lokacija,
|
||||
nabavna_cena, prodajna_cena, napomena)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
a.KategorijaID, a.Naziv, a.Opis, a.Kolicina, a.KolicinMin,
|
||||
a.Lokacija, a.NabavnaCena, a.ProdajnaCena, a.Napomena,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("ntech: ArtikalRepo.Kreiraj: %w", err)
|
||||
}
|
||||
|
||||
id, err := rezultat.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("ntech: ArtikalRepo.Kreiraj: last insert id: %w", err)
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// Izmeni ažurira postojeći artikal
|
||||
func (r *ArtikalRepo) Izmeni(ctx context.Context, a *model.Artikal) error {
|
||||
_, err := r.db.ExecContext(ctx, `
|
||||
UPDATE artikli SET
|
||||
kategorija_id = ?, naziv = ?, opis = ?, kolicina = ?,
|
||||
kolicina_min = ?, lokacija = ?, nabavna_cena = ?,
|
||||
prodajna_cena = ?, napomena = ?
|
||||
WHERE id = ?`,
|
||||
a.KategorijaID, a.Naziv, a.Opis, a.Kolicina,
|
||||
a.KolicinMin, a.Lokacija, a.NabavnaCena,
|
||||
a.ProdajnaCena, a.Napomena, a.ID,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ntech: ArtikalRepo.Izmeni: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Obrisi briše artikal po ID-u
|
||||
func (r *ArtikalRepo) Obrisi(ctx context.Context, id int64) error {
|
||||
_, err := r.db.ExecContext(ctx, "DELETE FROM artikli WHERE id = ?", id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ntech: ArtikalRepo.Obrisi: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"ntech/internal/model"
|
||||
)
|
||||
|
||||
// KategorijaRepo je SQLite implementacija KategorijaRepository interfejsa
|
||||
type KategorijaRepo struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
// NovaKategorijaRepo kreira novi KategorijaRepo
|
||||
func NovaKategorijaRepo(db *sql.DB) *KategorijaRepo {
|
||||
return &KategorijaRepo{db: db}
|
||||
}
|
||||
|
||||
// Lista vraća sve kategorije
|
||||
func (r *KategorijaRepo) Lista(ctx context.Context) ([]model.Kategorija, error) {
|
||||
redovi, err := r.db.QueryContext(ctx, "SELECT id, naziv, opis FROM kategorije ORDER BY naziv ASC")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ntech: KategorijaRepo.Lista: %w", err)
|
||||
}
|
||||
defer redovi.Close()
|
||||
|
||||
var rezultat []model.Kategorija
|
||||
for redovi.Next() {
|
||||
var k model.Kategorija
|
||||
var opis sql.NullString
|
||||
if err := redovi.Scan(&k.ID, &k.Naziv, &opis); err != nil {
|
||||
return nil, fmt.Errorf("ntech: KategorijaRepo.Lista: scan: %w", err)
|
||||
}
|
||||
if opis.Valid {
|
||||
k.Opis = opis.String
|
||||
}
|
||||
rezultat = append(rezultat, k)
|
||||
}
|
||||
|
||||
return rezultat, nil
|
||||
}
|
||||
|
||||
// Kreiraj dodaje novu kategoriju
|
||||
func (r *KategorijaRepo) Kreiraj(ctx context.Context, k *model.Kategorija) (int64, error) {
|
||||
rezultat, err := r.db.ExecContext(ctx,
|
||||
"INSERT INTO kategorije (naziv, opis) VALUES (?, ?)",
|
||||
k.Naziv, k.Opis,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("ntech: KategorijaRepo.Kreiraj: %w", err)
|
||||
}
|
||||
|
||||
id, err := rezultat.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("ntech: KategorijaRepo.Kreiraj: last insert id: %w", err)
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
@@ -1,13 +1,24 @@
|
||||
package handler
|
||||
|
||||
import "database/sql"
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"ntech/internal/db"
|
||||
"ntech/internal/db/sqlite"
|
||||
)
|
||||
|
||||
// Handler drži zavisnosti koje su potrebne svim handlerima
|
||||
type Handler struct {
|
||||
DB *sql.DB
|
||||
Artikli db.ArtikalRepository
|
||||
KategorijeRepo db.KategorijaRepository
|
||||
}
|
||||
|
||||
// Novi kreira novi Handler sa datom bazom
|
||||
func Novi(db *sql.DB) *Handler {
|
||||
return &Handler{DB: db}
|
||||
func Novi(baza *sql.DB) *Handler {
|
||||
return &Handler{
|
||||
DB: baza,
|
||||
Artikli: sqlite.NoviArtikalRepo(baza),
|
||||
KategorijeRepo: sqlite.NovaKategorijaRepo(baza),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"ntech/internal/db/sqlite"
|
||||
"ntech/internal/model"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
// PodaciKategorija su podaci za stranicu kategorija
|
||||
type PodaciKategorija struct {
|
||||
model.PodaciStranice
|
||||
Kategorije []model.Kategorija
|
||||
Sacuvano bool
|
||||
Obrisana bool
|
||||
}
|
||||
|
||||
// Kategorije renderuje listu kategorija
|
||||
func (h *Handler) Kategorije(w http.ResponseWriter, r *http.Request) {
|
||||
podesavanja, err := sqlite.DohvatiSvaPodesavanja(r.Context(), h.DB)
|
||||
if err != nil {
|
||||
http.Error(w, "Greška pri učitavanju podešavanja", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
kategorije, err := h.KategorijeRepo.Lista(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, "Greška pri učitavanju kategorija", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
podaci := PodaciKategorija{
|
||||
PodaciStranice: model.PodaciStranice{
|
||||
Stranica: "magacin",
|
||||
NaslovStranice: "Kategorije",
|
||||
Tema: podesavanja["tema"],
|
||||
NazivFirme: podesavanja["naziv_firme"],
|
||||
Podnazlov: podesavanja["podnazlov"],
|
||||
LogoTip: podesavanja["logo_tip"],
|
||||
LogoPutanja: podesavanja["logo_putanja"],
|
||||
Korisnik: "Admin",
|
||||
},
|
||||
Kategorije: kategorije,
|
||||
Sacuvano: r.URL.Query().Get("sacuvano") == "1",
|
||||
Obrisana: r.URL.Query().Get("obrisana") == "1",
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles(
|
||||
"web/templates/teme/podrazumevana/base.html",
|
||||
"web/templates/komponente/sidebar.html",
|
||||
"web/templates/komponente/topbar.html",
|
||||
"web/templates/stranice/kategorije.html",
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("greška pri učitavanju šablona: %v", err)
|
||||
http.Error(w, "Greška pri učitavanju stranice", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err := tmpl.ExecuteTemplate(w, "base", podaci); err != nil {
|
||||
log.Printf("greška pri renderovanju: %v", err)
|
||||
http.Error(w, "Greška pri prikazu stranice", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// DodajKategoriju prima POST i čuva novu kategoriju
|
||||
func (h *Handler) DodajKategoriju(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "Greška pri čitanju forme", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
naziv := r.FormValue("naziv")
|
||||
if naziv == "" {
|
||||
http.Redirect(w, r, "/magacin/kategorije", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
k := &model.Kategorija{
|
||||
Naziv: naziv,
|
||||
Opis: r.FormValue("opis"),
|
||||
}
|
||||
|
||||
if _, err := h.KategorijeRepo.Kreiraj(r.Context(), k); err != nil {
|
||||
http.Error(w, "Greška pri čuvanju kategorije", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/magacin/kategorije?sacuvano=1", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// ObrisiKategoriju briše kategoriju po ID-u
|
||||
func (h *Handler) ObrisiKategoriju(w http.ResponseWriter, r *http.Request) {
|
||||
idStr := chi.URLParam(r, "id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "Neispravan ID kategorije", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := h.DB.ExecContext(r.Context(), "DELETE FROM kategorije WHERE id = ?", id); err != nil {
|
||||
http.Error(w, "Greška pri brisanju kategorije", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/magacin/kategorije?obrisana=1", http.StatusSeeOther)
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"ntech/internal/db"
|
||||
"ntech/internal/db/sqlite"
|
||||
"ntech/internal/model"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
// PodaciMagacina su podaci za stranicu magacina
|
||||
type PodaciMagacina struct {
|
||||
model.PodaciStranice
|
||||
Artikli []model.ArtikalSaKategorijom
|
||||
Kategorije []model.Kategorija
|
||||
Filter db.ArtikalFilter
|
||||
KategorijaIDStr string
|
||||
Sacuvano bool
|
||||
Obrisan bool
|
||||
}
|
||||
|
||||
// Magacin renderuje listu artikala
|
||||
func (h *Handler) Magacin(w http.ResponseWriter, r *http.Request) {
|
||||
podesavanja, err := sqlite.DohvatiSvaPodesavanja(r.Context(), h.DB)
|
||||
if err != nil {
|
||||
http.Error(w, "Greška pri učitavanju podešavanja", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
filter := db.ArtikalFilter{
|
||||
Pretraga: r.URL.Query().Get("pretraga"),
|
||||
SamoKriticni: r.URL.Query().Get("kriticni") == "1",
|
||||
}
|
||||
|
||||
katIDStr := ""
|
||||
if katID := r.URL.Query().Get("kategorija"); katID != "" {
|
||||
id, err := strconv.ParseInt(katID, 10, 64)
|
||||
if err == nil {
|
||||
filter.KategorijaID = &id
|
||||
katIDStr = katID
|
||||
}
|
||||
}
|
||||
|
||||
artikli, err := h.Artikli.Lista(r.Context(), filter)
|
||||
if err != nil {
|
||||
http.Error(w, "Greška pri učitavanju artikala", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
kategorije, err := h.KategorijeRepo.Lista(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, "Greška pri učitavanju kategorija", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
podaci := PodaciMagacina{
|
||||
PodaciStranice: model.PodaciStranice{
|
||||
Stranica: "magacin",
|
||||
NaslovStranice: "Magacin",
|
||||
Tema: podesavanja["tema"],
|
||||
NazivFirme: podesavanja["naziv_firme"],
|
||||
Podnazlov: podesavanja["podnazlov"],
|
||||
LogoTip: podesavanja["logo_tip"],
|
||||
LogoPutanja: podesavanja["logo_putanja"],
|
||||
Korisnik: "Admin",
|
||||
},
|
||||
Artikli: artikli,
|
||||
Kategorije: kategorije,
|
||||
Filter: filter,
|
||||
KategorijaIDStr: katIDStr,
|
||||
Sacuvano: r.URL.Query().Get("sacuvano") == "1",
|
||||
Obrisan: r.URL.Query().Get("obrisan") == "1",
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles(
|
||||
"web/templates/teme/podrazumevana/base.html",
|
||||
"web/templates/komponente/sidebar.html",
|
||||
"web/templates/komponente/topbar.html",
|
||||
"web/templates/stranice/magacin.html",
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("greška pri učitavanju šablona: %v", err)
|
||||
http.Error(w, "Greška pri učitavanju stranice", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err := tmpl.ExecuteTemplate(w, "base", podaci); err != nil {
|
||||
log.Printf("greška pri renderovanju: %v", err)
|
||||
http.Error(w, "Greška pri prikazu stranice", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// ObrisiArtikal briše artikal po ID-u
|
||||
func (h *Handler) ObrisiArtikal(w http.ResponseWriter, r *http.Request) {
|
||||
idStr := chi.URLParam(r, "id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "Neispravan ID artikla", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.Artikli.Obrisi(r.Context(), id); err != nil {
|
||||
http.Error(w, "Greška pri brisanju artikla", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/magacin?obrisan=1", http.StatusSeeOther)
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"ntech/internal/db/sqlite"
|
||||
"ntech/internal/model"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
// PodaciFormeArtikla su podaci za formu novog/izmenjenog artikla
|
||||
type PodaciFormeArtikla struct {
|
||||
model.PodaciStranice
|
||||
Artikal model.Artikal
|
||||
Kategorije []model.Kategorija
|
||||
KategorijaIDStr string
|
||||
Greska string
|
||||
Izmena bool
|
||||
}
|
||||
|
||||
// NoviArtikal prikazuje formu za unos novog artikla
|
||||
func (h *Handler) NoviArtikal(w http.ResponseWriter, r *http.Request) {
|
||||
podesavanja, err := sqlite.DohvatiSvaPodesavanja(r.Context(), h.DB)
|
||||
if err != nil {
|
||||
http.Error(w, "Greška pri učitavanju podešavanja", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
kategorije, err := h.KategorijeRepo.Lista(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, "Greška pri učitavanju kategorija", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
podaci := PodaciFormeArtikla{
|
||||
PodaciStranice: model.PodaciStranice{
|
||||
Stranica: "magacin",
|
||||
NaslovStranice: "Novi artikal",
|
||||
Tema: podesavanja["tema"],
|
||||
NazivFirme: podesavanja["naziv_firme"],
|
||||
Podnazlov: podesavanja["podnazlov"],
|
||||
LogoTip: podesavanja["logo_tip"],
|
||||
LogoPutanja: podesavanja["logo_putanja"],
|
||||
Korisnik: "Admin",
|
||||
},
|
||||
Kategorije: kategorije,
|
||||
Izmena: false,
|
||||
}
|
||||
|
||||
renderujFormuArtikla(w, podaci)
|
||||
}
|
||||
|
||||
// SacuvajArtikal prima POST formu i čuva novi artikal
|
||||
func (h *Handler) SacuvajArtikal(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "Greška pri čitanju forme", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
artikal, greska := parseFormuArtikla(r)
|
||||
if greska != "" {
|
||||
podesavanja, _ := sqlite.DohvatiSvaPodesavanja(r.Context(), h.DB)
|
||||
kategorije, _ := h.KategorijeRepo.Lista(r.Context())
|
||||
katIDStr := ""
|
||||
if artikal.KategorijaID != nil {
|
||||
katIDStr = strconv.FormatInt(*artikal.KategorijaID, 10)
|
||||
}
|
||||
renderujFormuArtikla(w, PodaciFormeArtikla{
|
||||
PodaciStranice: model.PodaciStranice{
|
||||
Stranica: "magacin",
|
||||
NaslovStranice: "Novi artikal",
|
||||
Tema: podesavanja["tema"],
|
||||
NazivFirme: podesavanja["naziv_firme"],
|
||||
Podnazlov: podesavanja["podnazlov"],
|
||||
LogoTip: podesavanja["logo_tip"],
|
||||
LogoPutanja: podesavanja["logo_putanja"],
|
||||
Korisnik: "Admin",
|
||||
},
|
||||
Artikal: artikal,
|
||||
Kategorije: kategorije,
|
||||
KategorijaIDStr: katIDStr,
|
||||
Greska: greska,
|
||||
Izmena: false,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := h.Artikli.Kreiraj(r.Context(), &artikal); err != nil {
|
||||
http.Error(w, "Greška pri čuvanju artikla", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/magacin?sacuvano=1", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// IzmeniArtikal prikazuje formu za izmenu postojećeg artikla
|
||||
func (h *Handler) IzmeniArtikal(w http.ResponseWriter, r *http.Request) {
|
||||
idStr := chi.URLParam(r, "id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "Neispravan ID artikla", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
artikal, err := h.Artikli.DohvatiID(r.Context(), id)
|
||||
if err != nil {
|
||||
http.Error(w, "Artikal nije pronađen", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
podesavanja, err := sqlite.DohvatiSvaPodesavanja(r.Context(), h.DB)
|
||||
if err != nil {
|
||||
http.Error(w, "Greška pri učitavanju podešavanja", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
kategorije, err := h.KategorijeRepo.Lista(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, "Greška pri učitavanju kategorija", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
katIDStr := ""
|
||||
if artikal.KategorijaID != nil {
|
||||
katIDStr = strconv.FormatInt(*artikal.KategorijaID, 10)
|
||||
}
|
||||
|
||||
podaci := PodaciFormeArtikla{
|
||||
PodaciStranice: model.PodaciStranice{
|
||||
Stranica: "magacin",
|
||||
NaslovStranice: "Izmeni artikal",
|
||||
Tema: podesavanja["tema"],
|
||||
NazivFirme: podesavanja["naziv_firme"],
|
||||
Podnazlov: podesavanja["podnazlov"],
|
||||
LogoTip: podesavanja["logo_tip"],
|
||||
LogoPutanja: podesavanja["logo_putanja"],
|
||||
Korisnik: "Admin",
|
||||
},
|
||||
Artikal: *artikal,
|
||||
Kategorije: kategorije,
|
||||
KategorijaIDStr: katIDStr,
|
||||
Izmena: true,
|
||||
}
|
||||
|
||||
renderujFormuArtikla(w, podaci)
|
||||
}
|
||||
|
||||
// SacuvajIzmenuArtikla prima POST formu i čuva izmenu artikla
|
||||
func (h *Handler) SacuvajIzmenuArtikla(w http.ResponseWriter, r *http.Request) {
|
||||
idStr := chi.URLParam(r, "id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "Neispravan ID artikla", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "Greška pri čitanju forme", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
artikal, greska := parseFormuArtikla(r)
|
||||
if greska != "" {
|
||||
podesavanja, _ := sqlite.DohvatiSvaPodesavanja(r.Context(), h.DB)
|
||||
kategorije, _ := h.KategorijeRepo.Lista(r.Context())
|
||||
artikal.ID = id
|
||||
katIDStr := ""
|
||||
if artikal.KategorijaID != nil {
|
||||
katIDStr = strconv.FormatInt(*artikal.KategorijaID, 10)
|
||||
}
|
||||
renderujFormuArtikla(w, PodaciFormeArtikla{
|
||||
PodaciStranice: model.PodaciStranice{
|
||||
Stranica: "magacin",
|
||||
NaslovStranice: "Izmeni artikal",
|
||||
Tema: podesavanja["tema"],
|
||||
NazivFirme: podesavanja["naziv_firme"],
|
||||
Podnazlov: podesavanja["podnazlov"],
|
||||
LogoTip: podesavanja["logo_tip"],
|
||||
LogoPutanja: podesavanja["logo_putanja"],
|
||||
Korisnik: "Admin",
|
||||
},
|
||||
Artikal: artikal,
|
||||
Kategorije: kategorije,
|
||||
KategorijaIDStr: katIDStr,
|
||||
Greska: greska,
|
||||
Izmena: true,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
artikal.ID = id
|
||||
if err := h.Artikli.Izmeni(r.Context(), &artikal); err != nil {
|
||||
http.Error(w, "Greška pri čuvanju izmene", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/magacin?sacuvano=1", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// parseFormuArtikla čita polja iz forme i vraća artikal i eventualnu grešku
|
||||
func parseFormuArtikla(r *http.Request) (model.Artikal, string) {
|
||||
naziv := r.FormValue("naziv")
|
||||
if naziv == "" {
|
||||
return model.Artikal{}, "Naziv artikla je obavezan."
|
||||
}
|
||||
|
||||
var artikal model.Artikal
|
||||
artikal.Naziv = naziv
|
||||
artikal.Opis = r.FormValue("opis")
|
||||
artikal.Lokacija = r.FormValue("lokacija")
|
||||
artikal.Napomena = r.FormValue("napomena")
|
||||
|
||||
if k := r.FormValue("kolicina"); k != "" {
|
||||
v, err := strconv.Atoi(k)
|
||||
if err != nil || v < 0 {
|
||||
return artikal, "Količina mora biti pozitivan broj."
|
||||
}
|
||||
artikal.Kolicina = v
|
||||
}
|
||||
|
||||
if k := r.FormValue("kolicina_min"); k != "" {
|
||||
v, err := strconv.Atoi(k)
|
||||
if err != nil || v < 0 {
|
||||
return artikal, "Minimalna količina mora biti pozitivan broj."
|
||||
}
|
||||
artikal.KolicinMin = v
|
||||
}
|
||||
|
||||
if c := r.FormValue("nabavna_cena"); c != "" {
|
||||
v, err := strconv.ParseFloat(c, 64)
|
||||
if err != nil || v < 0 {
|
||||
return artikal, "Nabavna cena mora biti pozitivan broj."
|
||||
}
|
||||
artikal.NabavnaCena = v
|
||||
}
|
||||
|
||||
if c := r.FormValue("prodajna_cena"); c != "" {
|
||||
v, err := strconv.ParseFloat(c, 64)
|
||||
if err != nil || v < 0 {
|
||||
return artikal, "Prodajna cena mora biti pozitivan broj."
|
||||
}
|
||||
artikal.ProdajnaCena = v
|
||||
}
|
||||
|
||||
if katID := r.FormValue("kategorija_id"); katID != "" {
|
||||
id, err := strconv.ParseInt(katID, 10, 64)
|
||||
if err == nil {
|
||||
artikal.KategorijaID = &id
|
||||
}
|
||||
}
|
||||
|
||||
return artikal, ""
|
||||
}
|
||||
|
||||
// renderujFormuArtikla renderuje HTML formu za artikal
|
||||
func renderujFormuArtikla(w http.ResponseWriter, podaci PodaciFormeArtikla) {
|
||||
tmpl, err := template.ParseFiles(
|
||||
"web/templates/teme/podrazumevana/base.html",
|
||||
"web/templates/komponente/sidebar.html",
|
||||
"web/templates/komponente/topbar.html",
|
||||
"web/templates/stranice/magacin_forma.html",
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("greška pri učitavanju šablona: %v", err)
|
||||
http.Error(w, "Greška pri učitavanju stranice", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err := tmpl.ExecuteTemplate(w, "base", podaci); err != nil {
|
||||
log.Printf("greška pri renderovanju: %v", err)
|
||||
http.Error(w, "Greška pri prikazu stranice", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Artikal predstavlja jedan artikal u magacinu
|
||||
type Artikal struct {
|
||||
ID int64
|
||||
KategorijaID *int64
|
||||
Naziv string
|
||||
Opis string
|
||||
Kolicina int
|
||||
KolicinMin int
|
||||
Lokacija string
|
||||
NabavnaCena float64
|
||||
ProdajnaCena float64
|
||||
Napomena string
|
||||
DatumUnosa time.Time
|
||||
}
|
||||
|
||||
// Kategorija predstavlja kategoriju artikala
|
||||
type Kategorija struct {
|
||||
ID int64
|
||||
Naziv string
|
||||
Opis string
|
||||
}
|
||||
|
||||
// ArtikalSaKategorijom je artikal sa nazivom kategorije — za prikaz u tabeli
|
||||
type ArtikalSaKategorijom struct {
|
||||
Artikal
|
||||
KategorijaNaziv string
|
||||
KriticnaZaliha bool // true ako je kolicina <= kolicina_min
|
||||
}
|
||||
@@ -393,3 +393,54 @@ select:focus {
|
||||
.tema-krug-aktivan {
|
||||
border-color: var(--tekst-glavni) !important;
|
||||
}
|
||||
|
||||
/* forme — responsive */
|
||||
@media (max-width: 768px) {
|
||||
.forma-grid-2 {
|
||||
grid-template-columns: 1fr !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* gornja traka magacina — responsive */
|
||||
.magacin-traka {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.magacin-traka form {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.magacin-traka {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.magacin-traka form {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.magacin-traka a {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
/* dodatna korekcija magacin trake */
|
||||
@media (max-width: 768px) {
|
||||
.magacin-traka form input,
|
||||
.magacin-traka form select,
|
||||
.magacin-traka form button,
|
||||
.magacin-traka form label {
|
||||
width: 100%;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "naslov"}}Kategorije — NTech{{end}}
|
||||
|
||||
{{define "sadrzaj"}}
|
||||
<div style="display:flex;flex-direction:column;gap:16px;">
|
||||
|
||||
{{if .Sacuvano}}
|
||||
<div class="poruka-uspeh">Kategorija je uspešno sačuvana.</div>
|
||||
{{end}}
|
||||
{{if .Obrisana}}
|
||||
<div class="poruka-uspeh">Kategorija je uspešno obrisana.</div>
|
||||
{{end}}
|
||||
|
||||
<!-- nazad dugme -->
|
||||
<a href="/magacin" style="display:inline-flex;align-items:center;gap:6px;font-size:13px;color:var(--tekst-sporedni);text-decoration:none;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
|
||||
Nazad na magacin
|
||||
</a>
|
||||
|
||||
<!-- forma za novu kategoriju -->
|
||||
<div class="kartica">
|
||||
<div style="margin-bottom:16px;padding-bottom:12px;border-bottom:0.5px solid var(--ivica);">
|
||||
<span style="font-size:15px;font-weight:500;color:var(--tekst-glavni);">Nova kategorija</span>
|
||||
</div>
|
||||
<form method="POST" action="/magacin/kategorije/dodaj">
|
||||
<div style="display:flex;flex-direction:column;gap:12px;">
|
||||
<div>
|
||||
<label style="font-size:13px;color:var(--tekst-sporedni);display:block;margin-bottom:6px;">
|
||||
Naziv <span style="color:#dc2626;">*</span>
|
||||
</label>
|
||||
<input type="text" name="naziv" placeholder="npr. Memorija, Diskovi, Kablovi..."
|
||||
style="width:100%;">
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:13px;color:var(--tekst-sporedni);display:block;margin-bottom:6px;">Opis</label>
|
||||
<input type="text" name="opis" placeholder="Kratak opis kategorije..."
|
||||
style="width:100%;">
|
||||
</div>
|
||||
<div style="display:flex;justify-content:flex-end;">
|
||||
<button type="submit"
|
||||
style="padding:8px 20px;background:var(--sb-akcent);color:#fff;border:none;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer;">
|
||||
Dodaj kategoriju
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- lista kategorija -->
|
||||
<div class="kartica" style="padding:0;overflow:hidden;">
|
||||
<div style="padding:14px 16px;border-bottom:0.5px solid var(--ivica);">
|
||||
<span style="font-size:14px;font-weight:500;color:var(--tekst-glavni);">Postojeće kategorije</span>
|
||||
</div>
|
||||
{{range .Kategorije}}
|
||||
<div style="display:flex;align-items:center;gap:12px;padding:12px 16px;border-bottom:0.5px solid var(--ivica);">
|
||||
<div style="flex:1;">
|
||||
<div style="font-size:14px;color:var(--tekst-glavni);">{{.Naziv}}</div>
|
||||
{{if .Opis}}
|
||||
<div style="font-size:12px;color:var(--tekst-sporedni);margin-top:2px;">{{.Opis}}</div>
|
||||
{{end}}
|
||||
</div>
|
||||
<a href="/magacin/kategorije/obrisi/{{.ID}}"
|
||||
onclick="return confirm('Da li ste sigurni da želite da obrišete ovu kategoriju?')"
|
||||
style="padding:4px 10px;background:#dc2626;color:#fff;border-radius:6px;font-size:12px;text-decoration:none;white-space:nowrap;">
|
||||
Obriši
|
||||
</a>
|
||||
</div>
|
||||
{{else}}
|
||||
<div style="padding:24px;text-align:center;font-size:14px;color:var(--tekst-sporedni);">
|
||||
Nema kategorija. Dodaj prvu kategoriju iznad.
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{{end}}
|
||||
@@ -0,0 +1,111 @@
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "naslov"}}Magacin — NTech{{end}}
|
||||
|
||||
{{define "sadrzaj"}}
|
||||
<div style="display:flex;flex-direction:column;gap:16px;">
|
||||
|
||||
{{if .Sacuvano}}
|
||||
<div class="poruka-uspeh">Artikal je uspešno sačuvan.</div>
|
||||
{{end}}
|
||||
{{if .Obrisan}}
|
||||
<div class="poruka-uspeh">Artikal je uspešno obrisan.</div>
|
||||
{{end}}
|
||||
|
||||
<!-- dugmad -->
|
||||
<div style="display:flex;gap:10px;flex-wrap:wrap;">
|
||||
<a href="/magacin/novi"
|
||||
style="padding:8px 16px;background:var(--sb-akcent);color:#fff;border-radius:8px;font-size:14px;font-weight:500;text-decoration:none;white-space:nowrap;">
|
||||
+ Novi artikal
|
||||
</a>
|
||||
<a href="/magacin/kategorije"
|
||||
style="padding:8px 16px;background:var(--sb-aktivan);color:#fff;border-radius:8px;font-size:14px;font-weight:500;text-decoration:none;white-space:nowrap;">
|
||||
Kategorije
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- pretraga i filteri -->
|
||||
<form method="GET" action="/magacin" style="display:flex;flex-direction:column;gap:10px;">
|
||||
<input type="text" name="pretraga" value="{{.Filter.Pretraga}}"
|
||||
placeholder="Pretraži artikle..."
|
||||
style="width:100%;">
|
||||
<div style="display:flex;gap:10px;flex-wrap:wrap;align-items:center;">
|
||||
<select name="kategorija" style="flex:1;min-width:140px;">
|
||||
<option value="">Sve kategorije</option>
|
||||
{{range .Kategorije}}
|
||||
<option value="{{.ID}}" {{if eq (printf "%d" .ID) $.KategorijaIDStr}}selected{{end}}>{{.Naziv}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
<label style="display:inline-flex;align-items:center;gap:6px;font-size:13px;color:var(--tekst-sporedni);cursor:pointer;padding:8px 12px;border:0.5px solid var(--ivica);border-radius:8px;background:var(--kartica);white-space:nowrap;">
|
||||
<input type="checkbox" name="kriticni" value="1" {{if .Filter.SamoKriticni}}checked{{end}}>
|
||||
Samo kritični
|
||||
</label>
|
||||
<button type="submit"
|
||||
style="padding:8px 16px;background:var(--sb-aktivan);color:#fff;border:none;border-radius:8px;font-size:14px;cursor:pointer;white-space:nowrap;">
|
||||
Traži
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- tabela artikala -->
|
||||
<div class="kartica" style="padding:0;overflow:hidden;">
|
||||
<div style="overflow-x:auto;">
|
||||
<table style="width:100%;border-collapse:collapse;">
|
||||
<thead>
|
||||
<tr style="border-bottom:0.5px solid var(--ivica);">
|
||||
<th style="padding:12px 16px;text-align:left;font-size:12px;font-weight:500;color:var(--tekst-sporedni);">Naziv</th>
|
||||
<th style="padding:12px 16px;text-align:left;font-size:12px;font-weight:500;color:var(--tekst-sporedni);">Kategorija</th>
|
||||
<th style="padding:12px 16px;text-align:center;font-size:12px;font-weight:500;color:var(--tekst-sporedni);">Količina</th>
|
||||
<th style="padding:12px 16px;text-align:right;font-size:12px;font-weight:500;color:var(--tekst-sporedni);">Nabavna</th>
|
||||
<th style="padding:12px 16px;text-align:right;font-size:12px;font-weight:500;color:var(--tekst-sporedni);">Prodajna</th>
|
||||
<th style="padding:12px 16px;text-align:left;font-size:12px;font-weight:500;color:var(--tekst-sporedni);">Lokacija</th>
|
||||
<th style="padding:12px 16px;text-align:center;font-size:12px;font-weight:500;color:var(--tekst-sporedni);">Akcije</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range .Artikli}}
|
||||
<tr style="border-bottom:0.5px solid var(--ivica);transition:background 0.15s;"
|
||||
onmouseover="this.style.background='var(--pozadina)'"
|
||||
onmouseout="this.style.background=''">
|
||||
<td style="padding:12px 16px;font-size:14px;color:var(--tekst-glavni);">{{.Naziv}}</td>
|
||||
<td style="padding:12px 16px;font-size:13px;color:var(--tekst-sporedni);">
|
||||
{{if .KategorijaNaziv}}{{.KategorijaNaziv}}{{else}}—{{end}}
|
||||
</td>
|
||||
<td style="padding:12px 16px;text-align:center;">
|
||||
<span style="font-size:14px;font-weight:500;color:{{if .KriticnaZaliha}}#dc2626{{else}}#16a34a{{end}};">
|
||||
{{.Kolicina}}
|
||||
</span>
|
||||
</td>
|
||||
<td style="padding:12px 16px;text-align:right;font-size:13px;color:var(--tekst-sporedni);">{{printf "%.0f" .NabavnaCena}} din</td>
|
||||
<td style="padding:12px 16px;text-align:right;font-size:14px;color:var(--tekst-glavni);">{{printf "%.0f" .ProdajnaCena}} din</td>
|
||||
<td style="padding:12px 16px;font-size:13px;color:var(--tekst-sporedni);">
|
||||
{{if .Lokacija}}{{.Lokacija}}{{else}}—{{end}}
|
||||
</td>
|
||||
<td style="padding:12px 16px;text-align:center;">
|
||||
<div style="display:flex;align-items:center;justify-content:center;gap:8px;">
|
||||
<a href="/magacin/izmeni/{{.ID}}"
|
||||
style="padding:4px 10px;background:var(--sb-aktivan);color:#fff;border-radius:6px;font-size:12px;text-decoration:none;">
|
||||
Izmeni
|
||||
</a>
|
||||
<a href="/magacin/obrisi/{{.ID}}"
|
||||
onclick="return confirm('Da li ste sigurni da želite da obrišete ovaj artikal?')"
|
||||
style="padding:4px 10px;background:#dc2626;color:#fff;border-radius:6px;font-size:12px;text-decoration:none;">
|
||||
Obriši
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{{else}}
|
||||
<tr>
|
||||
<td colspan="7" style="padding:32px;text-align:center;font-size:14px;color:var(--tekst-sporedni);">
|
||||
Nema artikala. <a href="/magacin/novi" style="color:var(--sb-akcent);">Dodaj prvi artikal.</a>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{{end}}
|
||||
@@ -0,0 +1,115 @@
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "naslov"}}{{if .Izmena}}Izmeni artikal{{else}}Novi artikal{{end}} — NTech{{end}}
|
||||
|
||||
{{define "sadrzaj"}}
|
||||
<div style="width:100%;">
|
||||
|
||||
<!-- nazad dugme -->
|
||||
<a href="/magacin" style="display:inline-flex;align-items:center;gap:6px;font-size:13px;color:var(--tekst-sporedni);text-decoration:none;margin-bottom:20px;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
|
||||
Nazad na magacin
|
||||
</a>
|
||||
|
||||
<div class="kartica">
|
||||
<div style="margin-bottom:20px;padding-bottom:14px;border-bottom:0.5px solid var(--ivica);">
|
||||
<span style="font-size:16px;font-weight:500;color:var(--tekst-glavni);">
|
||||
{{if .Izmena}}Izmeni artikal{{else}}Novi artikal{{end}}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{{if .Greska}}
|
||||
<div style="background:var(--kartica);border:0.5px solid #dc2626;border-radius:8px;padding:10px 14px;margin-bottom:16px;font-size:13px;color:#dc2626;">
|
||||
{{.Greska}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
<form method="POST" action="{{if .Izmena}}/magacin/izmeni/{{.Artikal.ID}}{{else}}/magacin/novi{{end}}">
|
||||
<div style="display:flex;flex-direction:column;gap:14px;">
|
||||
|
||||
<!-- naziv -->
|
||||
<div>
|
||||
<label style="font-size:13px;color:var(--tekst-sporedni);display:block;margin-bottom:6px;">
|
||||
Naziv <span style="color:#dc2626;">*</span>
|
||||
</label>
|
||||
<input type="text" name="naziv" value="{{.Artikal.Naziv}}"
|
||||
placeholder="npr. RAM DDR4 8GB Kingston"
|
||||
style="width:100%;">
|
||||
</div>
|
||||
|
||||
<!-- kategorija -->
|
||||
<div>
|
||||
<label style="font-size:13px;color:var(--tekst-sporedni);display:block;margin-bottom:6px;">Kategorija</label>
|
||||
<select name="kategorija_id" style="width:100%;">
|
||||
<option value="">— bez kategorije —</option>
|
||||
{{range .Kategorije}}
|
||||
<option value="{{.ID}}" {{if eq (printf "%d" .ID) $.KategorijaIDStr}}selected{{end}}>{{.Naziv}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- opis -->
|
||||
<div>
|
||||
<label style="font-size:13px;color:var(--tekst-sporedni);display:block;margin-bottom:6px;">Opis</label>
|
||||
<textarea name="opis" rows="2"
|
||||
placeholder="Kratak opis artikla..."
|
||||
style="width:100%;resize:vertical;">{{.Artikal.Opis}}</textarea>
|
||||
</div>
|
||||
|
||||
<!-- količina i minimum -->
|
||||
<div class="forma-grid-2" style="display:grid;grid-template-columns:1fr 1fr;gap:12px;">
|
||||
<div>
|
||||
<label style="font-size:13px;color:var(--tekst-sporedni);display:block;margin-bottom:6px;">Količina na stanju</label>
|
||||
<input type="number" name="kolicina" value="{{.Artikal.Kolicina}}" min="0" style="width:100%;">
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:13px;color:var(--tekst-sporedni);display:block;margin-bottom:6px;">Minimalna količina</label>
|
||||
<input type="number" name="kolicina_min" value="{{.Artikal.KolicinMin}}" min="0" style="width:100%;">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- cene -->
|
||||
<div class="forma-grid-2" style="display:grid;grid-template-columns:1fr 1fr;gap:12px;">
|
||||
<div>
|
||||
<label style="font-size:13px;color:var(--tekst-sporedni);display:block;margin-bottom:6px;">Nabavna cena (din)</label>
|
||||
<input type="number" name="nabavna_cena" value="{{.Artikal.NabavnaCena}}" min="0" step="0.01" style="width:100%;">
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:13px;color:var(--tekst-sporedni);display:block;margin-bottom:6px;">Prodajna cena (din)</label>
|
||||
<input type="number" name="prodajna_cena" value="{{.Artikal.ProdajnaCena}}" min="0" step="0.01" style="width:100%;">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- lokacija -->
|
||||
<div>
|
||||
<label style="font-size:13px;color:var(--tekst-sporedni);display:block;margin-bottom:6px;">Lokacija u magacinu</label>
|
||||
<input type="text" name="lokacija" value="{{.Artikal.Lokacija}}"
|
||||
placeholder="npr. Polica A3, Kutija 2..."
|
||||
style="width:100%;">
|
||||
</div>
|
||||
|
||||
<!-- napomena -->
|
||||
<div>
|
||||
<label style="font-size:13px;color:var(--tekst-sporedni);display:block;margin-bottom:6px;">Napomena</label>
|
||||
<textarea name="napomena" rows="2"
|
||||
placeholder="Interna napomena..."
|
||||
style="width:100%;resize:vertical;">{{.Artikal.Napomena}}</textarea>
|
||||
</div>
|
||||
|
||||
<!-- dugmad -->
|
||||
<div style="display:flex;justify-content:flex-end;gap:10px;margin-top:6px;">
|
||||
<a href="/magacin"
|
||||
style="padding:9px 20px;border:0.5px solid var(--ivica);border-radius:8px;font-size:14px;color:var(--tekst-sporedni);text-decoration:none;">
|
||||
Odustani
|
||||
</a>
|
||||
<button type="submit"
|
||||
style="padding:9px 20px;background:var(--sb-akcent);color:#fff;border:none;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer;">
|
||||
{{if .Izmena}}Sačuvaj izmene{{else}}Dodaj artikal{{end}}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
@@ -3,7 +3,7 @@
|
||||
{{define "naslov"}}Podešavanja — NTech{{end}}
|
||||
|
||||
{{define "sadrzaj"}}
|
||||
<div style="max-width:720px;">
|
||||
<div style="width:100%;max-width:100%;">
|
||||
|
||||
{{if .Sacuvano}}
|
||||
<div class="poruka-uspeh">
|
||||
|
||||
Reference in New Issue
Block a user