feat(inventory): add spare parts management
This commit is contained in:
parent
abc6e308dd
commit
fb5c2cc26a
43 changed files with 2950 additions and 2 deletions
192
frontend/athena/components/inventory/InventoryItemDialog.tsx
Normal file
192
frontend/athena/components/inventory/InventoryItemDialog.tsx
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import type {
|
||||
InventoryCategory,
|
||||
InventoryItem,
|
||||
InventoryItemPayload,
|
||||
InventoryLocation,
|
||||
InventorySupplier,
|
||||
} from "@/types/inventory";
|
||||
import { centsToEuroInput, emptyItemPayload, euroToCents } from "./inventory-utils";
|
||||
|
||||
type Props = {
|
||||
open: boolean;
|
||||
item: InventoryItem | null;
|
||||
categories: InventoryCategory[];
|
||||
locations: InventoryLocation[];
|
||||
suppliers: InventorySupplier[];
|
||||
pending: boolean;
|
||||
serverError: string;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onSubmit: (payload: InventoryItemPayload) => void;
|
||||
};
|
||||
|
||||
function payloadFromItem(item: InventoryItem | null): InventoryItemPayload {
|
||||
if (!item) {
|
||||
return emptyItemPayload;
|
||||
}
|
||||
return {
|
||||
sku: item.sku,
|
||||
name: item.name,
|
||||
description: item.description,
|
||||
category_id: item.category_id,
|
||||
manufacturer: item.manufacturer,
|
||||
manufacturer_part_number: item.manufacturer_part_number,
|
||||
supplier_id: item.supplier_id,
|
||||
supplier_part_number: item.supplier_part_number,
|
||||
compatible_devices: item.compatible_devices,
|
||||
location_id: item.location_id,
|
||||
quantity_on_hand: item.quantity_on_hand,
|
||||
quantity_reserved: item.quantity_reserved,
|
||||
reorder_level: item.reorder_level,
|
||||
unit: item.unit,
|
||||
purchase_price_cents: item.purchase_price_cents,
|
||||
selling_price_cents: item.selling_price_cents,
|
||||
currency: item.currency,
|
||||
tax_rate_percent: item.tax_rate_percent,
|
||||
notes: item.notes,
|
||||
is_active: item.is_active,
|
||||
};
|
||||
}
|
||||
|
||||
export default function InventoryItemDialog({
|
||||
open,
|
||||
item,
|
||||
categories,
|
||||
locations,
|
||||
suppliers,
|
||||
pending,
|
||||
serverError,
|
||||
onOpenChange,
|
||||
onSubmit,
|
||||
}: Props) {
|
||||
const initialPayload = payloadFromItem(item);
|
||||
const [payload, setPayload] = useState<InventoryItemPayload>(initialPayload);
|
||||
const [purchasePrice, setPurchasePrice] = useState(centsToEuroInput(initialPayload.purchase_price_cents));
|
||||
const [sellingPrice, setSellingPrice] = useState(centsToEuroInput(initialPayload.selling_price_cents));
|
||||
const [clientError, setClientError] = useState("");
|
||||
|
||||
function update<K extends keyof InventoryItemPayload>(key: K, value: InventoryItemPayload[K]) {
|
||||
setPayload((current) => ({ ...current, [key]: value }));
|
||||
}
|
||||
|
||||
function submit() {
|
||||
const purchaseCents = euroToCents(purchasePrice);
|
||||
const sellingCents = euroToCents(sellingPrice);
|
||||
if (!payload.name.trim()) {
|
||||
setClientError("Bitte einen Artikelnamen angeben.");
|
||||
return;
|
||||
}
|
||||
if (payload.quantity_reserved > payload.quantity_on_hand) {
|
||||
setClientError("Reservierter Bestand darf den Lagerbestand nicht überschreiten.");
|
||||
return;
|
||||
}
|
||||
if ((purchasePrice.trim() && purchaseCents === null) || (sellingPrice.trim() && sellingCents === null)) {
|
||||
setClientError("Bitte Preise als Eurobetrag eingeben, z. B. 1,50.");
|
||||
return;
|
||||
}
|
||||
setClientError("");
|
||||
onSubmit({
|
||||
...payload,
|
||||
sku: payload.sku?.trim() || null,
|
||||
name: payload.name.trim(),
|
||||
purchase_price_cents: purchaseCents,
|
||||
selling_price_cents: sellingCents,
|
||||
description: payload.description?.trim() || null,
|
||||
manufacturer: payload.manufacturer?.trim() || null,
|
||||
manufacturer_part_number: payload.manufacturer_part_number?.trim() || null,
|
||||
supplier_part_number: payload.supplier_part_number?.trim() || null,
|
||||
compatible_devices: payload.compatible_devices?.trim() || null,
|
||||
notes: payload.notes?.trim() || null,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-h-[90vh] overflow-y-auto sm:max-w-5xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{item ? "Artikel bearbeiten" : "Artikel anlegen"}</DialogTitle>
|
||||
<DialogDescription>Pflege Stammdaten, Lagerbestand, Preise und Bezugsdaten.</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="grid gap-5">
|
||||
<section className="grid gap-3">
|
||||
<h3 className="font-semibold text-slate-950">Stammdaten</h3>
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
<label className="grid gap-1 text-sm">SKU optional<Input value={payload.sku ?? ""} onChange={(event) => update("sku", event.target.value || null)} placeholder="ET-2026-000001" /></label>
|
||||
<label className="grid gap-1 text-sm md:col-span-2">Name<Input value={payload.name} onChange={(event) => update("name", event.target.value)} /></label>
|
||||
<label className="grid gap-1 text-sm md:col-span-3">Beschreibung<textarea className="min-h-20 rounded-lg border p-2 text-sm" value={payload.description ?? ""} onChange={(event) => update("description", event.target.value || null)} /></label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="grid gap-3">
|
||||
<h3 className="font-semibold text-slate-950">Zuordnung</h3>
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
<label className="grid gap-1 text-sm">Kategorie<select className="h-8 rounded-lg border px-2 text-sm" value={payload.category_id ?? ""} onChange={(event) => update("category_id", event.target.value ? Number(event.target.value) : null)}>
|
||||
<option value="">Keine Kategorie</option>
|
||||
{categories.map((category) => <option key={category.id} value={category.id}>{category.name}</option>)}
|
||||
</select></label>
|
||||
<label className="grid gap-1 text-sm">Lagerort<select className="h-8 rounded-lg border px-2 text-sm" value={payload.location_id ?? ""} onChange={(event) => update("location_id", event.target.value ? Number(event.target.value) : null)}>
|
||||
<option value="">Kein Lagerort</option>
|
||||
{locations.map((location) => <option key={location.id} value={location.id}>{location.name}</option>)}
|
||||
</select></label>
|
||||
<label className="grid gap-1 text-sm">Lieferant<select className="h-8 rounded-lg border px-2 text-sm" value={payload.supplier_id ?? ""} onChange={(event) => update("supplier_id", event.target.value ? Number(event.target.value) : null)}>
|
||||
<option value="">Kein Lieferant</option>
|
||||
{suppliers.map((supplier) => <option key={supplier.id} value={supplier.id}>{supplier.name}</option>)}
|
||||
</select></label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="grid gap-3">
|
||||
<h3 className="font-semibold text-slate-950">Hersteller und Kompatibilität</h3>
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
<label className="grid gap-1 text-sm">Hersteller<Input value={payload.manufacturer ?? ""} onChange={(event) => update("manufacturer", event.target.value || null)} /></label>
|
||||
<label className="grid gap-1 text-sm">Hersteller-Teilenummer<Input value={payload.manufacturer_part_number ?? ""} onChange={(event) => update("manufacturer_part_number", event.target.value || null)} /></label>
|
||||
<label className="grid gap-1 text-sm">Lieferanten-Teilenummer<Input value={payload.supplier_part_number ?? ""} onChange={(event) => update("supplier_part_number", event.target.value || null)} /></label>
|
||||
<label className="grid gap-1 text-sm md:col-span-3">Kompatible Geräte<textarea className="min-h-20 rounded-lg border p-2 text-sm" value={payload.compatible_devices ?? ""} onChange={(event) => update("compatible_devices", event.target.value || null)} /></label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="grid gap-3">
|
||||
<h3 className="font-semibold text-slate-950">Bestand und Preise</h3>
|
||||
<div className="grid gap-3 md:grid-cols-4">
|
||||
<label className="grid gap-1 text-sm">Bestand<Input type="number" min={0} value={payload.quantity_on_hand} onChange={(event) => update("quantity_on_hand", Number(event.target.value))} /></label>
|
||||
<label className="grid gap-1 text-sm">Reserviert<Input type="number" min={0} value={payload.quantity_reserved} onChange={(event) => update("quantity_reserved", Number(event.target.value))} /></label>
|
||||
<label className="grid gap-1 text-sm">Mindestbestand<Input type="number" min={0} value={payload.reorder_level} onChange={(event) => update("reorder_level", Number(event.target.value))} /></label>
|
||||
<label className="grid gap-1 text-sm">Einheit<Input value={payload.unit} onChange={(event) => update("unit", event.target.value)} /></label>
|
||||
<label className="grid gap-1 text-sm">Einkaufspreis €<Input inputMode="decimal" value={purchasePrice} onChange={(event) => setPurchasePrice(event.target.value)} /></label>
|
||||
<label className="grid gap-1 text-sm">Verkaufspreis €<Input inputMode="decimal" value={sellingPrice} onChange={(event) => setSellingPrice(event.target.value)} /></label>
|
||||
<label className="grid gap-1 text-sm">Währung<Input value={payload.currency} onChange={(event) => update("currency", event.target.value.toUpperCase())} /></label>
|
||||
<label className="grid gap-1 text-sm">MwSt. %<Input inputMode="decimal" value={payload.tax_rate_percent} onChange={(event) => update("tax_rate_percent", event.target.value.replace(",", "."))} /></label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="grid gap-3">
|
||||
<h3 className="font-semibold text-slate-950">Notizen</h3>
|
||||
<textarea className="min-h-20 rounded-lg border p-2 text-sm" value={payload.notes ?? ""} onChange={(event) => update("notes", event.target.value || null)} />
|
||||
<label className="flex items-center gap-2 text-sm"><input type="checkbox" checked={payload.is_active} onChange={(event) => update("is_active", event.target.checked)} /> Artikel ist aktiv</label>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{(clientError || serverError) && <p className="text-sm text-red-600">{clientError || serverError}</p>}
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => onOpenChange(false)} disabled={pending}>Abbrechen</Button>
|
||||
<Button type="button" onClick={submit} disabled={pending}>{pending ? "Speichert..." : "Speichern"}</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
148
frontend/athena/components/inventory/MasterDataSection.tsx
Normal file
148
frontend/athena/components/inventory/MasterDataSection.tsx
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Edit, Plus, Trash2 } from "lucide-react";
|
||||
|
||||
import ConfirmDialog from "@/components/common/ConfirmDialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { useToast } from "@/components/common/ToastProvider";
|
||||
import { api } from "@/lib/api";
|
||||
import type { InventoryCategory, InventoryLocation, InventorySupplier } from "@/types/inventory";
|
||||
import { getErrorMessage } from "./inventory-utils";
|
||||
|
||||
type MasterKind = "categories" | "locations" | "suppliers";
|
||||
type MasterEntry = InventoryCategory | InventoryLocation | InventorySupplier;
|
||||
|
||||
type Props = {
|
||||
title: string;
|
||||
kind: MasterKind;
|
||||
entries: MasterEntry[];
|
||||
canManage: boolean;
|
||||
onChanged: () => void;
|
||||
};
|
||||
|
||||
export default function MasterDataSection({ title, kind, entries, canManage, onChanged }: Props) {
|
||||
const { showToast } = useToast();
|
||||
const [editing, setEditing] = useState<MasterEntry | null>(null);
|
||||
const [deleteEntry, setDeleteEntry] = useState<MasterEntry | null>(null);
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [pending, setPending] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
function startCreate() {
|
||||
setEditing({ id: 0, name: "", description: null, created_at: "", updated_at: "" } as MasterEntry);
|
||||
setName("");
|
||||
setDescription("");
|
||||
setError("");
|
||||
}
|
||||
|
||||
function startEdit(entry: MasterEntry) {
|
||||
setEditing(entry);
|
||||
setName(entry.name);
|
||||
setDescription("description" in entry && entry.description ? entry.description : "");
|
||||
setError("");
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!editing) {
|
||||
return;
|
||||
}
|
||||
if (!name.trim()) {
|
||||
setError("Bitte einen Namen angeben.");
|
||||
return;
|
||||
}
|
||||
setPending(true);
|
||||
setError("");
|
||||
const payload = kind === "suppliers"
|
||||
? { name: name.trim(), notes: description.trim() || null }
|
||||
: { name: name.trim(), description: description.trim() || null };
|
||||
try {
|
||||
if (editing.id) {
|
||||
await api.put(`/inventory/${kind}/${editing.id}`, payload);
|
||||
} else {
|
||||
await api.post(`/inventory/${kind}`, payload);
|
||||
}
|
||||
showToast({ type: "success", title: `${title} gespeichert` });
|
||||
setEditing(null);
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
const message = getErrorMessage(err);
|
||||
setError(message);
|
||||
showToast({ type: "error", title: `${title} konnte nicht gespeichert werden`, description: message });
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmDelete() {
|
||||
if (!deleteEntry) {
|
||||
return;
|
||||
}
|
||||
setPending(true);
|
||||
try {
|
||||
await api.delete(`/inventory/${kind}/${deleteEntry.id}`);
|
||||
showToast({ type: "success", title: `${title} gelöscht`, description: deleteEntry.name });
|
||||
setDeleteEntry(null);
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
const message = getErrorMessage(err);
|
||||
showToast({ type: "error", title: `${title} konnte nicht gelöscht werden`, description: message });
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="rounded-lg border bg-white p-5">
|
||||
<div className="mb-4 flex items-center justify-between gap-3">
|
||||
<h2 className="font-semibold text-slate-950">{title}</h2>
|
||||
{canManage && <Button type="button" size="sm" onClick={startCreate}><Plus size={14} />Neu</Button>}
|
||||
</div>
|
||||
|
||||
<div className="divide-y">
|
||||
{entries.length === 0 ? (
|
||||
<p className="py-4 text-sm text-slate-500">Noch keine Einträge vorhanden.</p>
|
||||
) : entries.map((entry) => (
|
||||
<div key={entry.id} className="flex items-center justify-between gap-3 py-3">
|
||||
<div>
|
||||
<p className="font-medium text-slate-950">{entry.name}</p>
|
||||
{"description" in entry && entry.description && <p className="text-sm text-slate-500">{entry.description}</p>}
|
||||
{"notes" in entry && entry.notes && <p className="text-sm text-slate-500">{entry.notes}</p>}
|
||||
</div>
|
||||
{canManage && (
|
||||
<div className="flex gap-2">
|
||||
<Button type="button" variant="ghost" size="icon-sm" onClick={() => startEdit(entry)} title="Bearbeiten"><Edit size={16} /></Button>
|
||||
<Button type="button" variant="destructive" size="icon-sm" onClick={() => setDeleteEntry(entry)} title="Löschen"><Trash2 size={16} /></Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{editing && (
|
||||
<div className="mt-4 grid gap-3 rounded-lg border bg-slate-50 p-4">
|
||||
<Input value={name} placeholder="Name" onChange={(event) => setName(event.target.value)} />
|
||||
<textarea className="min-h-20 rounded-lg border p-2 text-sm" value={description} placeholder={kind === "suppliers" ? "Notizen" : "Beschreibung"} onChange={(event) => setDescription(event.target.value)} />
|
||||
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||
<div className="flex gap-2">
|
||||
<Button type="button" onClick={save} disabled={pending}>{pending ? "Speichert..." : "Speichern"}</Button>
|
||||
<Button type="button" variant="outline" onClick={() => setEditing(null)} disabled={pending}>Abbrechen</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={Boolean(deleteEntry)}
|
||||
title={`${title} löschen`}
|
||||
description="Der Eintrag wird entfernt. Verknüpfte Artikel behalten ihre sonstigen Daten."
|
||||
pending={pending}
|
||||
onOpenChange={(open) => !open && setDeleteEntry(null)}
|
||||
onConfirm={confirmDelete}
|
||||
>
|
||||
{deleteEntry?.name}
|
||||
</ConfirmDialog>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
107
frontend/athena/components/inventory/StockActionDialog.tsx
Normal file
107
frontend/athena/components/inventory/StockActionDialog.tsx
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import type { InventoryItem, InventoryStockPayload } from "@/types/inventory";
|
||||
|
||||
export type StockAction = "adjust" | "reserve" | "release" | "consume";
|
||||
|
||||
type Props = {
|
||||
open: boolean;
|
||||
item: InventoryItem | null;
|
||||
action: StockAction;
|
||||
pending: boolean;
|
||||
serverError: string;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onSubmit: (payload: InventoryStockPayload) => void;
|
||||
};
|
||||
|
||||
const labels: Record<StockAction, { title: string; description: string; reason: string }> = {
|
||||
adjust: {
|
||||
title: "Bestand anpassen",
|
||||
description: "Setzt den physischen Bestand auf den angegebenen Wert.",
|
||||
reason: "Inventurkorrektur",
|
||||
},
|
||||
reserve: {
|
||||
title: "Bestand reservieren",
|
||||
description: "Reserviert verfügbaren Bestand für einen späteren Vorgang.",
|
||||
reason: "Reservierung",
|
||||
},
|
||||
release: {
|
||||
title: "Reservierung aufheben",
|
||||
description: "Gibt reservierten Bestand wieder frei.",
|
||||
reason: "Reservierung aufgehoben",
|
||||
},
|
||||
consume: {
|
||||
title: "Verbrauch buchen",
|
||||
description: "Bucht Bestand als verbraucht aus.",
|
||||
reason: "Verbrauch",
|
||||
},
|
||||
};
|
||||
|
||||
export default function StockActionDialog({ open, item, action, pending, serverError, onOpenChange, onSubmit }: Props) {
|
||||
const [quantity, setQuantity] = useState(action === "adjust" ? item?.quantity_on_hand ?? 0 : 1);
|
||||
const [reason, setReason] = useState(labels[action].reason);
|
||||
const [note, setNote] = useState("");
|
||||
const [clientError, setClientError] = useState("");
|
||||
|
||||
function submit() {
|
||||
if (quantity <= 0 && action !== "adjust") {
|
||||
setClientError("Bitte eine Menge größer 0 angeben.");
|
||||
return;
|
||||
}
|
||||
if (quantity < 0) {
|
||||
setClientError("Bitte keine negative Menge eingeben.");
|
||||
return;
|
||||
}
|
||||
if (!reason.trim()) {
|
||||
setClientError("Bitte einen Grund angeben.");
|
||||
return;
|
||||
}
|
||||
setClientError("");
|
||||
onSubmit({
|
||||
quantity,
|
||||
reason: reason.trim(),
|
||||
note: note.trim() || null,
|
||||
reference_type: null,
|
||||
reference_id: null,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{labels[action].title}</DialogTitle>
|
||||
<DialogDescription>{item ? `${item.sku} · ${item.name}` : labels[action].description}</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="grid gap-3">
|
||||
<p className="rounded-lg border bg-slate-50 p-3 text-sm text-slate-600">
|
||||
Bestand {item?.quantity_on_hand ?? 0} · Reserviert {item?.quantity_reserved ?? 0} · Verfügbar {item?.quantity_available ?? 0}
|
||||
</p>
|
||||
<label className="grid gap-1 text-sm">Menge<Input type="number" min={action === "adjust" ? 0 : 1} value={quantity} onChange={(event) => setQuantity(Number(event.target.value))} /></label>
|
||||
<label className="grid gap-1 text-sm">Grund<Input value={reason} onChange={(event) => setReason(event.target.value)} /></label>
|
||||
<label className="grid gap-1 text-sm">Notiz<textarea className="min-h-20 rounded-lg border p-2 text-sm" value={note} onChange={(event) => setNote(event.target.value)} /></label>
|
||||
</div>
|
||||
|
||||
{(clientError || serverError) && <p className="text-sm text-red-600">{clientError || serverError}</p>}
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => onOpenChange(false)} disabled={pending}>Abbrechen</Button>
|
||||
<Button type="button" onClick={submit} disabled={pending}>{pending ? "Speichert..." : "Buchen"}</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
62
frontend/athena/components/inventory/inventory-utils.ts
Normal file
62
frontend/athena/components/inventory/inventory-utils.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import type { InventoryItemPayload } from "@/types/inventory";
|
||||
|
||||
export function getErrorMessage(error: unknown) {
|
||||
if (typeof error === "object" && error !== null && "response" in error) {
|
||||
const response = (error as { response?: { data?: { detail?: string; message?: string } } }).response;
|
||||
return response?.data?.detail ?? response?.data?.message ?? "Aktion konnte nicht abgeschlossen werden";
|
||||
}
|
||||
return "Aktion konnte nicht abgeschlossen werden";
|
||||
}
|
||||
|
||||
export function formatDate(value: string) {
|
||||
return new Intl.DateTimeFormat("de-DE", { dateStyle: "short", timeStyle: "short" }).format(new Date(value));
|
||||
}
|
||||
|
||||
export function formatMoney(cents: number | null, currency = "EUR") {
|
||||
if (cents === null) {
|
||||
return "Keine Angabe";
|
||||
}
|
||||
return new Intl.NumberFormat("de-DE", { style: "currency", currency }).format(cents / 100);
|
||||
}
|
||||
|
||||
export function euroToCents(value: string) {
|
||||
const normalized = value.trim().replace(",", ".");
|
||||
if (!normalized) {
|
||||
return null;
|
||||
}
|
||||
const amount = Number(normalized);
|
||||
if (!Number.isFinite(amount) || amount < 0) {
|
||||
return null;
|
||||
}
|
||||
return Math.round(amount * 100);
|
||||
}
|
||||
|
||||
export function centsToEuroInput(cents: number | null) {
|
||||
if (cents === null) {
|
||||
return "";
|
||||
}
|
||||
return (cents / 100).toFixed(2).replace(".", ",");
|
||||
}
|
||||
|
||||
export const emptyItemPayload: InventoryItemPayload = {
|
||||
sku: null,
|
||||
name: "",
|
||||
description: null,
|
||||
category_id: null,
|
||||
manufacturer: null,
|
||||
manufacturer_part_number: null,
|
||||
supplier_id: null,
|
||||
supplier_part_number: null,
|
||||
compatible_devices: null,
|
||||
location_id: null,
|
||||
quantity_on_hand: 0,
|
||||
quantity_reserved: 0,
|
||||
reorder_level: 0,
|
||||
unit: "Stk.",
|
||||
purchase_price_cents: null,
|
||||
selling_price_cents: null,
|
||||
currency: "EUR",
|
||||
tax_rate_percent: "19.00",
|
||||
notes: null,
|
||||
is_active: true,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue