iOS (neu, ios/):
- SwiftUI-App: Login (Server + Keychain-Token), Kamera-Scanner (EAN/UPC/Code128),
Einlagern mit mehreren Chargen und eigenem MHD, Auslagern mit Chargenauswahl
oder FEFO, Artikelsuche, Anlegen mit Open-Food-Facts-Vorbefuellung.
- Home-Screen-Shortcuts: Schnellaktionen (langer Druck) und URL-Schema
projectgood://checkin | ://checkout fuer eigene Symbole via Kurzbefehle.
- project.yml (XcodeGen) + README mit Build-Anleitung. NICHT kompiliert - auf
diesem Rechner ist kein Xcode vorhanden.
Import-Modi (wie besprochen sinnvoll):
- add (Standard, nichts loeschen), replace_listed (Bestaende der in der Datei
genannten Produkte ersetzen - fuer Inventur), replace_all (alles ersetzen).
Geleerte Bestaende werden als Korrektur-Bewegung protokolliert; die Oberflaeche
fragt bei den zerstoerenden Modi nach.
Anzeige:
- "Bald ablaufend"/"Abgelaufen" zeigen jetzt das Gebinde ("1 Glas") mit der
Basiseinheit klein darunter (ExpiringItem liefert die Einheiten mit).
- MHD als Zeitspanne mit korrektem Numerus: "in 3 Tagen", "in 1 Woche",
"vor 2 Wochen", dazu heute/morgen/gestern.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
176 lines
6.2 KiB
Swift
176 lines
6.2 KiB
Swift
import SwiftUI
|
|
|
|
struct CheckInView: View {
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
@State private var paused = false
|
|
@State private var status: String?
|
|
@State private var error: String?
|
|
|
|
@State private var product: Product?
|
|
@State private var suggestion: LookupResult.Suggestion?
|
|
@State private var suggestedGroupId: Int?
|
|
@State private var unknownCode: String?
|
|
@State private var manualCodeShown = false
|
|
@State private var manualCode = ""
|
|
@State private var units: [Unit] = []
|
|
@State private var locations: [StorageLocation] = []
|
|
|
|
var body: some View {
|
|
ZStack(alignment: .bottom) {
|
|
ScannerView(onCode: { code in Task { await resolve(code) } }, isPaused: $paused)
|
|
.ignoresSafeArea()
|
|
|
|
VStack(spacing: 10) {
|
|
if let status { banner(status, color: .green) }
|
|
if let error { banner(error, color: .red) }
|
|
|
|
if let suggestion {
|
|
suggestionCard(suggestion)
|
|
} else if let unknownCode {
|
|
unknownCard(unknownCode)
|
|
}
|
|
|
|
HStack(spacing: 10) {
|
|
Button {
|
|
paused = true
|
|
manualCodeShown = true
|
|
} label: {
|
|
Label("EAN manuell", systemImage: "keyboard")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
|
|
NavigationLink {
|
|
ProductFormView(prefillBarcode: nil, groupId: nil) { created in
|
|
product = created
|
|
}
|
|
} label: {
|
|
Label("Artikel anlegen", systemImage: "plus")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.bordered)
|
|
}
|
|
.padding(.horizontal)
|
|
.padding(.bottom, 8)
|
|
}
|
|
.padding(.bottom, 4)
|
|
.background(.ultraThinMaterial.opacity(0.001))
|
|
}
|
|
.navigationTitle("Einlagern")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .topBarLeading) {
|
|
Button("Fertig") { dismiss() }
|
|
}
|
|
}
|
|
.task {
|
|
units = (try? await APIClient.shared.units()) ?? []
|
|
locations = (try? await APIClient.shared.locations()) ?? []
|
|
}
|
|
.alert("EAN eingeben", isPresented: $manualCodeShown) {
|
|
TextField("z.B. 8076809572569", text: $manualCode)
|
|
.keyboardType(.numberPad)
|
|
Button("Suchen") {
|
|
let code = manualCode
|
|
manualCode = ""
|
|
Task { await resolve(code) }
|
|
}
|
|
Button("Abbrechen", role: .cancel) { paused = false }
|
|
}
|
|
.sheet(item: $product) { item in
|
|
NavigationStack {
|
|
CheckInFormView(product: item, units: units, locations: locations) { message in
|
|
status = message
|
|
product = nil
|
|
paused = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Bausteine
|
|
|
|
private func banner(_ text: String, color: Color) -> some View {
|
|
Text(text)
|
|
.font(.callout)
|
|
.padding(10)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.background(color.opacity(0.9))
|
|
.foregroundStyle(.white)
|
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
|
.padding(.horizontal)
|
|
}
|
|
|
|
private func suggestionCard(_ item: LookupResult.Suggestion) -> some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
Text(item.name).font(.headline)
|
|
Text([item.brand, item.quantityText].compactMap { $0 }.joined(separator: " · "))
|
|
.font(.caption).foregroundStyle(.secondary)
|
|
Text("Bei Open Food Facts gefunden, noch nicht im Katalog.")
|
|
.font(.caption2).foregroundStyle(.secondary)
|
|
NavigationLink {
|
|
ProductFormView(prefillBarcode: item.barcode, groupId: suggestedGroupId,
|
|
suggestion: item) { created in
|
|
suggestion = nil
|
|
product = created
|
|
}
|
|
} label: {
|
|
Label("Anlegen & einlagern", systemImage: "plus.circle.fill")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
}
|
|
.padding()
|
|
.background(.thinMaterial)
|
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
|
.padding(.horizontal)
|
|
}
|
|
|
|
private func unknownCard(_ code: String) -> some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
Text("Unbekannter Code \(code)").font(.headline)
|
|
Text("Weder im Katalog noch bei Open Food Facts.")
|
|
.font(.caption).foregroundStyle(.secondary)
|
|
NavigationLink {
|
|
ProductFormView(prefillBarcode: code, groupId: suggestedGroupId) { created in
|
|
unknownCode = nil
|
|
product = created
|
|
}
|
|
} label: {
|
|
Label("Artikel anlegen", systemImage: "plus")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
}
|
|
.padding()
|
|
.background(.thinMaterial)
|
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
|
.padding(.horizontal)
|
|
}
|
|
|
|
// MARK: - Logik
|
|
|
|
private func resolve(_ code: String) async {
|
|
paused = true
|
|
error = nil
|
|
status = nil
|
|
suggestion = nil
|
|
unknownCode = nil
|
|
do {
|
|
let result = try await APIClient.shared.lookup(barcode: code)
|
|
suggestedGroupId = result.groupId
|
|
if let existing = result.existingProduct {
|
|
product = existing
|
|
} else if let hint = result.suggestion {
|
|
suggestion = hint
|
|
} else {
|
|
unknownCode = code
|
|
}
|
|
} catch {
|
|
self.error = error.localizedDescription
|
|
paused = false
|
|
}
|
|
}
|
|
}
|