import { useEffect, useState } from "react"; import { api } from "../api"; import Icon from "../components/Icon"; import ShoppingNeedText from "../components/ShoppingNeedText"; import { anzahlWort } from "../units"; export default function ShoppingList() { const [items, setItems] = useState([]); const [groups, setGroups] = useState([]); const [byLocation, setByLocation] = useState([]); const [checked, setChecked] = useState({}); const [error, setError] = useState(null); useEffect(() => { Promise.all([api.shoppingList(), api.groupShoppingList(), api.shoppingByLocation()]) .then(([p, g, l]) => { setItems(p); setGroups(g); setByLocation(l); }) .catch((e) => setError(e.message)); }, []); const empty = items.length === 0 && groups.length === 0; function toggle(key, val) { setChecked((c) => ({ ...c, [key]: val })); } return (

Einkaufsliste

Produkte und Gruppen unter ihrem Mindestbestand
{error &&
{error}
} {byLocation.length > 0 && (
Überall (egal wo)
)}
{empty ? (
Alle Mindestbestände erreicht.
) : ( )}
{byLocation.map((loc) => (
Bedarf: {loc.location_name}
    {loc.groups.map((it) => { const key = `l${loc.location_id}g${it.group_id}`; return (
  • ); })} {loc.products.map((it) => { const key = `l${loc.location_id}p${it.product_id}`; return (
  • ); })}
))}

Das Abhaken hilft beim Einkaufen und wird (noch) nicht dauerhaft gespeichert.

Bedarfe sind gegeneinander verrechnet: Was du für einen Lagerort oder eine Untergruppe kaufst, deckt „Überall“ bzw. die Obergruppe mit ab. Hängt dieselbe Untergruppe unter zwei Obergruppen, die einander nicht enthalten (Grillwurst unter Wurst und unter Grillgut), stehen beide Bedarfe getrennt da — ein Kauf kann dann beide decken. Ein eigener Mindestbestand auf der gemeinsamen Untergruppe verrechnet auch das.

); }