add linking between internal and external orders

This commit is contained in:
Matthias Hochmeister
2026-03-27 12:28:25 +01:00
parent 90f691d607
commit eb82fe29b7

View File

@@ -116,7 +116,7 @@ export default function AusruestungsanfrageZuBestellung() {
// ── Derived: progress ── // ── Derived: progress ──
const assignedCount = positionen.filter(p => assignments[p.id] != null).length; const assignedCount = positionen.filter(p => assignments[p.id] != null).length;
const allAssigned = positionen.length > 0 && assignedCount === positionen.length; const skippedCount = positionen.length - assignedCount;
// ── Mutations ── // ── Mutations ──
const createOrdersMut = useMutation({ const createOrdersMut = useMutation({
@@ -154,8 +154,10 @@ export default function AusruestungsanfrageZuBestellung() {
}); });
// ── Handlers ── // ── Handlers ──
const canSubmit = vendorGroups.length > 0 && !createOrdersMut.isPending;
const handleSubmit = () => { const handleSubmit = () => {
if (!allAssigned) return; if (!canSubmit) return;
const orders = vendorGroups.map(g => ({ const orders = vendorGroups.map(g => ({
lieferant_id: g.lieferantId, lieferant_id: g.lieferantId,
bezeichnung: orderNames[g.lieferantId] || `Anfrage ${g.lieferantName}`, bezeichnung: orderNames[g.lieferantId] || `Anfrage ${g.lieferantName}`,
@@ -225,8 +227,8 @@ export default function AusruestungsanfrageZuBestellung() {
</Box> </Box>
<Chip <Chip
label={`${assignedCount} / ${positionen.length} zugewiesen`} label={`${assignedCount} / ${positionen.length} zugewiesen`}
color={allAssigned ? 'success' : 'default'} color={assignedCount > 0 ? 'primary' : 'default'}
variant={allAssigned ? 'filled' : 'outlined'} variant="outlined"
/> />
</Box> </Box>
@@ -235,7 +237,7 @@ export default function AusruestungsanfrageZuBestellung() {
variant="determinate" variant="determinate"
value={positionen.length > 0 ? (assignedCount / positionen.length) * 100 : 0} value={positionen.length > 0 ? (assignedCount / positionen.length) * 100 : 0}
sx={{ mb: 3, borderRadius: 2, height: 6 }} sx={{ mb: 3, borderRadius: 2, height: 6 }}
color={allAssigned ? 'success' : 'primary'} color="primary"
/> />
{/* ── Items table ── */} {/* ── Items table ── */}
@@ -258,7 +260,7 @@ export default function AusruestungsanfrageZuBestellung() {
? vendors.find(v => v.id === assignment.lieferantId) ?? null ? vendors.find(v => v.id === assignment.lieferantId) ?? null
: null; : null;
return ( return (
<TableRow key={pos.id} sx={assignment ? {} : { bgcolor: 'warning.light', opacity: 0.85 }}> <TableRow key={pos.id}>
<TableCell> <TableCell>
<Typography variant="body2" fontWeight={500}>{pos.bezeichnung}</Typography> <Typography variant="body2" fontWeight={500}>{pos.bezeichnung}</Typography>
{pos.notizen && ( {pos.notizen && (
@@ -355,16 +357,21 @@ export default function AusruestungsanfrageZuBestellung() {
{/* ── Bottom action bar ── */} {/* ── Bottom action bar ── */}
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2, justifyContent: 'flex-end' }}> <Box sx={{ display: 'flex', alignItems: 'center', gap: 2, justifyContent: 'flex-end' }}>
{!allAssigned && positionen.length > 0 && ( {skippedCount > 0 && assignedCount > 0 && (
<Alert severity="warning" sx={{ flex: 1, py: 0.5 }}> <Alert severity="info" sx={{ flex: 1, py: 0.5 }}>
{positionen.length - assignedCount} Artikel {positionen.length - assignedCount === 1 ? 'hat' : 'haben'} noch keinen Lieferanten. {skippedCount} Artikel {skippedCount === 1 ? 'ist' : 'sind'} auf Lager und {skippedCount === 1 ? 'wird' : 'werden'} nicht bestellt.
</Alert>
)}
{assignedCount === 0 && positionen.length > 0 && (
<Alert severity="info" sx={{ flex: 1, py: 0.5 }}>
Mindestens einem Artikel einen Lieferanten zuweisen, um Bestellungen zu erstellen.
</Alert> </Alert>
)} )}
<Button <Button
variant="contained" variant="contained"
size="large" size="large"
startIcon={<ShoppingCartIcon />} startIcon={<ShoppingCartIcon />}
disabled={!allAssigned || createOrdersMut.isPending} disabled={!canSubmit}
onClick={handleSubmit} onClick={handleSubmit}
> >
{createOrdersMut.isPending ? 'Erstelle…' : `${vendorGroups.length || ''} Bestellung${vendorGroups.length !== 1 ? 'en' : ''} erstellen`} {createOrdersMut.isPending ? 'Erstelle…' : `${vendorGroups.length || ''} Bestellung${vendorGroups.length !== 1 ? 'en' : ''} erstellen`}