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