Chargen: Packung als massgebliche Einheit, Basiseinheit als Untermenge
Ist eine Packungsgroesse hinterlegt, sind Anzeige UND Bearbeitung der Chargen in Packungen; die Basiseinheit (z.B. Gramm) steht nur noch als Untermenge darunter. Ohne Packungsgroesse bleibt die Produkteinheit massgeblich. Produktkopf nennt ebenfalls zuerst die Packungen. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -205,8 +205,10 @@ export default function ProductForm() {
|
||||
<h1>{isNew ? "Neues Produkt" : form.name || "Produkt"}</h1>
|
||||
{!isNew && product && (
|
||||
<div className="sub">
|
||||
Bestand: {fmt(product.stock / (product.unit_factor || 1))} {product.unit_name}
|
||||
{product.package_size ? ` · ${fmt(product.stock / product.package_size)} Pkg` : ""}
|
||||
Bestand:{" "}
|
||||
{product.package_size
|
||||
? `${fmt(product.stock / product.package_size)} Pkg · ${fmt(product.stock / (product.unit_factor || 1))} ${product.unit_name}`
|
||||
: `${fmt(product.stock / (product.unit_factor || 1))} ${product.unit_name}`}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -311,26 +313,29 @@ function LotsCard({ product, lots, baseShort, warnDays, isAdmin, imageUrl, onCha
|
||||
const [editId, setEditId] = useState(null);
|
||||
const [draft, setDraft] = useState({ quantity: "", best_before: "" });
|
||||
|
||||
const factor = product?.unit_factor || 1;
|
||||
const unitFactor = product?.unit_factor || 1;
|
||||
const unitName = product?.unit_name || baseShort;
|
||||
const pkgSize = product?.package_size || 0;
|
||||
// Zweitangabe: Basiseinheit (falls abweichend) und/oder Packungen.
|
||||
|
||||
// Maßgebliche Einheit: Packung, sobald eine Packungsgröße hinterlegt ist –
|
||||
// sonst die Produkteinheit. Die Basiseinheit ist nur die Untermenge.
|
||||
const primaryFactor = pkgSize > 0 ? pkgSize : unitFactor;
|
||||
const primaryLabel = pkgSize > 0 ? "Pkg" : unitName;
|
||||
|
||||
// Untermenge: Menge in der Basiseinheit (nur wenn sie sich unterscheidet).
|
||||
function secondary(qty) {
|
||||
const parts = [];
|
||||
if (factor !== 1) parts.push(`${fmt(qty)} ${baseShort}`);
|
||||
if (pkgSize > 0) parts.push(`${fmt(qty / pkgSize)} Pkg`);
|
||||
return parts.join(" · ");
|
||||
return primaryFactor !== 1 ? `${fmt(qty)} ${baseShort}` : "";
|
||||
}
|
||||
|
||||
function startEdit(l) {
|
||||
setEditId(l.id);
|
||||
setDraft({ quantity: l.quantity / factor, best_before: l.best_before || "" });
|
||||
setDraft({ quantity: l.quantity / primaryFactor, best_before: l.best_before || "" });
|
||||
}
|
||||
|
||||
async function saveEdit(l) {
|
||||
try {
|
||||
await api.updateLot(l.id, {
|
||||
quantity: Number(draft.quantity) * factor,
|
||||
quantity: Number(draft.quantity) * primaryFactor,
|
||||
best_before: draft.best_before || null,
|
||||
});
|
||||
setEditId(null);
|
||||
@@ -377,11 +382,11 @@ function LotsCard({ product, lots, baseShort, warnDays, isAdmin, imageUrl, onCha
|
||||
<input type="number" step="any" min="0" value={draft.quantity}
|
||||
onChange={(e) => setDraft({ ...draft, quantity: e.target.value })}
|
||||
style={{ maxWidth: 90, marginTop: 0 }} />
|
||||
<span className="muted small">{unitName}</span>
|
||||
<span className="muted small">{primaryLabel}</span>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{fmt(l.quantity / factor)} {unitName}
|
||||
{fmt(l.quantity / primaryFactor)} {primaryLabel}
|
||||
{secondary(l.quantity) && (
|
||||
<div className="muted small">{secondary(l.quantity)}</div>
|
||||
)}
|
||||
@@ -427,8 +432,8 @@ function LotsCard({ product, lots, baseShort, warnDays, isAdmin, imageUrl, onCha
|
||||
</table>
|
||||
</div>
|
||||
<p className="muted small">
|
||||
Mengen in {unitName}
|
||||
{pkgSize > 0 ? `; 1 Packung = ${fmt(pkgSize)} ${baseShort}` : ""}.
|
||||
Mengen in {pkgSize > 0 ? "Packungen" : unitName}
|
||||
{pkgSize > 0 ? ` (1 Packung = ${fmt(pkgSize)} ${baseShort})` : ""}.
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user