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>
|
<h1>{isNew ? "Neues Produkt" : form.name || "Produkt"}</h1>
|
||||||
{!isNew && product && (
|
{!isNew && product && (
|
||||||
<div className="sub">
|
<div className="sub">
|
||||||
Bestand: {fmt(product.stock / (product.unit_factor || 1))} {product.unit_name}
|
Bestand:{" "}
|
||||||
{product.package_size ? ` · ${fmt(product.stock / product.package_size)} Pkg` : ""}
|
{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>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -311,26 +313,29 @@ function LotsCard({ product, lots, baseShort, warnDays, isAdmin, imageUrl, onCha
|
|||||||
const [editId, setEditId] = useState(null);
|
const [editId, setEditId] = useState(null);
|
||||||
const [draft, setDraft] = useState({ quantity: "", best_before: "" });
|
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 unitName = product?.unit_name || baseShort;
|
||||||
const pkgSize = product?.package_size || 0;
|
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) {
|
function secondary(qty) {
|
||||||
const parts = [];
|
return primaryFactor !== 1 ? `${fmt(qty)} ${baseShort}` : "";
|
||||||
if (factor !== 1) parts.push(`${fmt(qty)} ${baseShort}`);
|
|
||||||
if (pkgSize > 0) parts.push(`${fmt(qty / pkgSize)} Pkg`);
|
|
||||||
return parts.join(" · ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function startEdit(l) {
|
function startEdit(l) {
|
||||||
setEditId(l.id);
|
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) {
|
async function saveEdit(l) {
|
||||||
try {
|
try {
|
||||||
await api.updateLot(l.id, {
|
await api.updateLot(l.id, {
|
||||||
quantity: Number(draft.quantity) * factor,
|
quantity: Number(draft.quantity) * primaryFactor,
|
||||||
best_before: draft.best_before || null,
|
best_before: draft.best_before || null,
|
||||||
});
|
});
|
||||||
setEditId(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}
|
<input type="number" step="any" min="0" value={draft.quantity}
|
||||||
onChange={(e) => setDraft({ ...draft, quantity: e.target.value })}
|
onChange={(e) => setDraft({ ...draft, quantity: e.target.value })}
|
||||||
style={{ maxWidth: 90, marginTop: 0 }} />
|
style={{ maxWidth: 90, marginTop: 0 }} />
|
||||||
<span className="muted small">{unitName}</span>
|
<span className="muted small">{primaryLabel}</span>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{fmt(l.quantity / factor)} {unitName}
|
{fmt(l.quantity / primaryFactor)} {primaryLabel}
|
||||||
{secondary(l.quantity) && (
|
{secondary(l.quantity) && (
|
||||||
<div className="muted small">{secondary(l.quantity)}</div>
|
<div className="muted small">{secondary(l.quantity)}</div>
|
||||||
)}
|
)}
|
||||||
@@ -427,8 +432,8 @@ function LotsCard({ product, lots, baseShort, warnDays, isAdmin, imageUrl, onCha
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<p className="muted small">
|
<p className="muted small">
|
||||||
Mengen in {unitName}
|
Mengen in {pkgSize > 0 ? "Packungen" : unitName}
|
||||||
{pkgSize > 0 ? `; 1 Packung = ${fmt(pkgSize)} ${baseShort}` : ""}.
|
{pkgSize > 0 ? ` (1 Packung = ${fmt(pkgSize)} ${baseShort})` : ""}.
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user