Add sales-month planning for crops/products and fix today task label format
This commit is contained in:
@@ -210,16 +210,21 @@ func (a *App) handleCreateCrop(w http.ResponseWriter, r *http.Request) {
|
||||
start := mustInt(r.FormValue("sow_start_month"), 0)
|
||||
end := mustInt(r.FormValue("sow_end_month"), 0)
|
||||
grow := mustInt(r.FormValue("grow_months"), 0)
|
||||
bestSaleMonth := mustInt(r.FormValue("best_sale_month"), 0)
|
||||
regrowEnabled := r.FormValue("regrow_enabled") == "on"
|
||||
regrowCycles := mustInt(r.FormValue("regrow_cycles"), 0)
|
||||
if err := validateCropInput(name, start, end, grow, regrowCycles); err != nil {
|
||||
redirectWithMessage(w, r, "/crops", "error", err.Error())
|
||||
return
|
||||
}
|
||||
if bestSaleMonth < 0 || bestSaleMonth > 12 {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Bestpreis-Monat muss 0-12 sein")
|
||||
return
|
||||
}
|
||||
if !regrowEnabled {
|
||||
regrowCycles = 0
|
||||
}
|
||||
if _, err := a.db.Exec(`INSERT INTO crops(name,sow_start_month,sow_end_month,grow_months,regrow_enabled,regrow_cycles) VALUES (?,?,?,?,?,?)`, name, start, end, grow, regrowEnabled, regrowCycles); err != nil {
|
||||
if _, err := a.db.Exec(`INSERT INTO crops(name,sow_start_month,sow_end_month,grow_months,best_sale_month,regrow_enabled,regrow_cycles) VALUES (?,?,?,?,?,?,?)`, name, start, end, grow, bestSaleMonth, regrowEnabled, regrowCycles); err != nil {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Feldfrucht nicht angelegt")
|
||||
return
|
||||
}
|
||||
@@ -240,6 +245,7 @@ func (a *App) handleUpdateCrop(w http.ResponseWriter, r *http.Request) {
|
||||
start := mustInt(r.FormValue("sow_start_month"), 0)
|
||||
end := mustInt(r.FormValue("sow_end_month"), 0)
|
||||
grow := mustInt(r.FormValue("grow_months"), 0)
|
||||
bestSaleMonth := mustInt(r.FormValue("best_sale_month"), 0)
|
||||
regrowEnabled := r.FormValue("regrow_enabled") == "on"
|
||||
regrowCycles := mustInt(r.FormValue("regrow_cycles"), 0)
|
||||
if id <= 0 {
|
||||
@@ -250,10 +256,14 @@ func (a *App) handleUpdateCrop(w http.ResponseWriter, r *http.Request) {
|
||||
redirectWithMessage(w, r, "/crops", "error", err.Error())
|
||||
return
|
||||
}
|
||||
if bestSaleMonth < 0 || bestSaleMonth > 12 {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Bestpreis-Monat muss 0-12 sein")
|
||||
return
|
||||
}
|
||||
if !regrowEnabled {
|
||||
regrowCycles = 0
|
||||
}
|
||||
if _, err := a.db.Exec(`UPDATE crops SET name=?,sow_start_month=?,sow_end_month=?,grow_months=?,regrow_enabled=?,regrow_cycles=? WHERE id=?`, name, start, end, grow, regrowEnabled, regrowCycles, id); err != nil {
|
||||
if _, err := a.db.Exec(`UPDATE crops SET name=?,sow_start_month=?,sow_end_month=?,grow_months=?,best_sale_month=?,regrow_enabled=?,regrow_cycles=? WHERE id=?`, name, start, end, grow, bestSaleMonth, regrowEnabled, regrowCycles, id); err != nil {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Feldfrucht nicht aktualisiert")
|
||||
return
|
||||
}
|
||||
@@ -281,6 +291,72 @@ func (a *App) handleDeleteCrop(w http.ResponseWriter, r *http.Request) {
|
||||
redirectWithMessage(w, r, "/crops", "info", "Feldfrucht gelöscht")
|
||||
}
|
||||
|
||||
func (a *App) handleCreateProduct(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Form ungültig")
|
||||
return
|
||||
}
|
||||
name := strings.TrimSpace(r.FormValue("name"))
|
||||
bestSaleMonth := mustInt(r.FormValue("best_sale_month"), 0)
|
||||
if name == "" || bestSaleMonth < 1 || bestSaleMonth > 12 {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Produktionsgut ungültig")
|
||||
return
|
||||
}
|
||||
if _, err := a.db.Exec(`INSERT INTO products(name,best_sale_month) VALUES (?,?)`, name, bestSaleMonth); err != nil {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Produktionsgut nicht angelegt")
|
||||
return
|
||||
}
|
||||
redirectWithMessage(w, r, "/crops", "info", "Produktionsgut angelegt")
|
||||
}
|
||||
|
||||
func (a *App) handleUpdateProduct(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Form ungültig")
|
||||
return
|
||||
}
|
||||
id := mustInt64(r.FormValue("id"), 0)
|
||||
name := strings.TrimSpace(r.FormValue("name"))
|
||||
bestSaleMonth := mustInt(r.FormValue("best_sale_month"), 0)
|
||||
if id <= 0 || name == "" || bestSaleMonth < 1 || bestSaleMonth > 12 {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Produktionsgut ungültig")
|
||||
return
|
||||
}
|
||||
if _, err := a.db.Exec(`UPDATE products SET name=?,best_sale_month=? WHERE id=?`, name, bestSaleMonth, id); err != nil {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Produktionsgut nicht aktualisiert")
|
||||
return
|
||||
}
|
||||
redirectWithMessage(w, r, "/crops", "info", "Produktionsgut aktualisiert")
|
||||
}
|
||||
|
||||
func (a *App) handleDeleteProduct(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Form ungültig")
|
||||
return
|
||||
}
|
||||
id := mustInt64(r.FormValue("id"), 0)
|
||||
if id <= 0 {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Produktionsgut-ID ungültig")
|
||||
return
|
||||
}
|
||||
if _, err := a.db.Exec(`DELETE FROM products WHERE id=?`, id); err != nil {
|
||||
redirectWithMessage(w, r, "/crops", "error", "Produktionsgut nicht gelöscht")
|
||||
return
|
||||
}
|
||||
redirectWithMessage(w, r, "/crops", "info", "Produktionsgut gelöscht")
|
||||
}
|
||||
|
||||
func (a *App) handleCreatePlan(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
|
||||
Reference in New Issue
Block a user