Setzt den Backend-Umbau in beiden Oberflaechen um. Die Genauigkeit gilt jeweils fuer den ganzen Einlager-Vorgang und nicht je Charge: Auf einer Packung steht entweder ein Tagesdatum oder nur Monat/Jahr, gemischt kommt das nicht vor. Vorbelegt wird sie aus dem Produkt, laesst sich aber im Vorgang umstellen. Web-UI: Umschalter im Kopf der Chargenliste; das Eingabefeld wechselt zwischen type="date" und type="month". Im Produktformular gibt es das neue Feld "MHD-Angabe" neben der Gebinde-Bezeichnung. Anzeige laeuft ueber den Settings-Context, damit das eingestellte Datumsformat erhalten bleibt und Monatsangaben ueberall als "09/2026" erscheinen (Auslagern, Uebersicht, Chargentabelle). Die Abgelaufen-Warnung prueft bei Monatsangaben gegen den Monatsletzten - sonst haette eine Packung schon am Monatsersten als abgelaufen gegolten. iOS: Auswahl "Tagesdatum / nur Monat/Jahr" im Einlagern-Formular und beim Anlegen eines Artikels. SwiftUI hat keinen DatePicker ohne Tag, deshalb ein eigener MonthYearPicker aus zwei Auswahlfeldern; die Jahresliste reicht zwei Jahre zurueck (bereits abgelaufene Ware) und fuenfzehn nach vorn (Konserven). Die Chargenauswahl beim Auslagern zeigt Monatsangaben ebenfalls ohne Tag. Getestet: Web-Build (vite) und iOS-Geraetebuild laufen fehlerfrei durch, die App ist auf dem iPhone installiert. Das Verhalten in der Oberflaeche ist noch nicht von Hand durchgeklickt. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
229 lines
7.9 KiB
Swift
229 lines
7.9 KiB
Swift
import SwiftUI
|
|
|
|
struct CheckOutView: View {
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
@State private var paused = false
|
|
@State private var torchOn = false
|
|
@State private var status: String?
|
|
@State private var error: String?
|
|
@State private var product: Product?
|
|
@State private var units: [Unit] = []
|
|
@State private var manualCodeShown = false
|
|
@State private var manualCode = ""
|
|
@State private var searchShown = false
|
|
|
|
var body: some View {
|
|
ZStack(alignment: .bottom) {
|
|
ScannerView(onCode: { code in Task { await resolve(code) } },
|
|
isPaused: $paused, torchOn: $torchOn)
|
|
.ignoresSafeArea()
|
|
|
|
VStack(spacing: 10) {
|
|
if let status { banner(status, color: .green) }
|
|
if let error { banner(error, color: .red) }
|
|
|
|
HStack(spacing: 10) {
|
|
Button {
|
|
paused = true
|
|
searchShown = true
|
|
} label: {
|
|
Label("Artikel suchen", systemImage: "magnifyingglass")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
|
|
Button {
|
|
paused = true
|
|
manualCodeShown = true
|
|
} label: {
|
|
Label("EAN manuell", systemImage: "keyboard")
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.bordered)
|
|
}
|
|
.padding(.horizontal)
|
|
.padding(.bottom, 8)
|
|
}
|
|
}
|
|
.navigationTitle("Auslagern")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .topBarLeading) { Button("Fertig") { dismiss() } }
|
|
ToolbarItem(placement: .topBarTrailing) { TorchButton(isOn: $torchOn) }
|
|
}
|
|
.task { units = (try? await APIClient.shared.units()) ?? [] }
|
|
.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(isPresented: $searchShown) {
|
|
NavigationStack {
|
|
ProductSearchView { picked in
|
|
searchShown = false
|
|
product = picked
|
|
}
|
|
}
|
|
}
|
|
.sheet(item: $product) { item in
|
|
NavigationStack {
|
|
CheckOutFormView(product: item, units: units) { message in
|
|
status = message
|
|
product = nil
|
|
paused = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 resolve(_ code: String) async {
|
|
paused = true
|
|
error = nil
|
|
status = nil
|
|
do {
|
|
let result = try await APIClient.shared.lookup(barcode: code)
|
|
if let existing = result.existingProduct {
|
|
product = existing
|
|
} else {
|
|
error = "Kein bekanntes Produkt zu diesem Code im Lager."
|
|
paused = false
|
|
}
|
|
} catch {
|
|
self.error = error.localizedDescription
|
|
paused = false
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Auslagern: Menge, Einheit und optional eine bestimmte Charge (sonst FEFO).
|
|
struct CheckOutFormView: View {
|
|
let product: Product
|
|
let units: [Unit]
|
|
var onDone: (String) -> Void
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
@State private var quantity = "1"
|
|
@State private var unit = ""
|
|
@State private var lots: [Lot] = []
|
|
@State private var lotId: Int?
|
|
@State private var busy = false
|
|
@State private var error: String?
|
|
|
|
private var unitOptions: [String] {
|
|
var options = units.filter { $0.kind == product.kind }.map(\.name)
|
|
if let size = product.packageSize, size > 0 {
|
|
options.append(product.packageLabel ?? "Packung")
|
|
}
|
|
return options
|
|
}
|
|
|
|
var body: some View {
|
|
Form {
|
|
Section {
|
|
VStack(alignment: .leading) {
|
|
Text(product.name).font(.headline)
|
|
Text("Verfügbar: \(format(product.stockInArticleUnits)) \(product.articleUnitLabel)")
|
|
.font(.caption).foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
|
|
Section("Charge") {
|
|
Picker("Charge", selection: $lotId) {
|
|
Text("Automatisch (zuerst ablaufende)").tag(Int?.none)
|
|
ForEach(lots) { lot in
|
|
Text(label(for: lot)).tag(Int?.some(lot.id))
|
|
}
|
|
}
|
|
}
|
|
|
|
Section("Menge") {
|
|
HStack {
|
|
Text("Menge")
|
|
Spacer(minLength: 12)
|
|
TextField("Menge", text: $quantity)
|
|
.keyboardType(.decimalPad)
|
|
.multilineTextAlignment(.trailing)
|
|
.frame(maxWidth: 110)
|
|
}
|
|
Picker("Einheit", selection: $unit) {
|
|
ForEach(unitOptions, id: \.self) { Text($0).tag($0) }
|
|
}
|
|
}
|
|
|
|
if let error {
|
|
Section { Text(error).foregroundStyle(.red).font(.callout) }
|
|
}
|
|
|
|
Section {
|
|
Button(busy ? "Speichern…" : "Auslagern") { Task { await submit() } }
|
|
.disabled(busy)
|
|
}
|
|
}
|
|
.navigationTitle("Auslagern")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .topBarLeading) { Button("Abbrechen") { dismiss() } }
|
|
}
|
|
.task {
|
|
unit = (product.packageSize ?? 0) > 0 ? (product.packageLabel ?? "Packung") : product.unitName
|
|
lots = (try? await APIClient.shared.lots(productId: product.id)) ?? []
|
|
}
|
|
}
|
|
|
|
private func label(for lot: Lot) -> String {
|
|
let amount = format(lot.quantity / product.articleUnitFactor)
|
|
return "\(bestBeforeText(lot)) · \(amount) \(product.articleUnitLabel)"
|
|
}
|
|
|
|
/// Monatsangaben ohne Tag zeigen: "09/2026" statt "2026-09-30".
|
|
private func bestBeforeText(_ lot: Lot) -> String {
|
|
guard let raw = lot.bestBefore else { return "ohne MHD" }
|
|
guard lot.bestBeforePrecision == "month" else { return raw }
|
|
let parts = raw.split(separator: "-")
|
|
guard parts.count >= 2 else { return raw }
|
|
return "\(parts[1])/\(parts[0])"
|
|
}
|
|
|
|
private func format(_ value: Double) -> String {
|
|
value == value.rounded() ? String(Int(value)) : String(format: "%.2f", value)
|
|
}
|
|
|
|
private func submit() async {
|
|
error = nil
|
|
guard let amount = Double(quantity.replacingOccurrences(of: ",", with: ".")), amount > 0 else {
|
|
error = "Bitte eine Menge größer 0 angeben."
|
|
return
|
|
}
|
|
busy = true
|
|
defer { busy = false }
|
|
do {
|
|
let response = try await APIClient.shared.checkOut(
|
|
CheckOutRequest(productId: product.id, quantity: amount, unit: unit, lotId: lotId)
|
|
)
|
|
let total = response.productStock / product.articleUnitFactor
|
|
onDone("Ausgelagert. Neuer Bestand: \(format(total)) \(product.articleUnitLabel)")
|
|
dismiss()
|
|
} catch {
|
|
self.error = error.localizedDescription
|
|
}
|
|
}
|
|
}
|