Compare commits

..

2 Commits

Author SHA1 Message Date
seb
b3051953b0 u 2026-10-17 04:51:09 +02:00
seb
cb2f6ad37f u 2026-10-17 04:39:37 +02:00
3 changed files with 86 additions and 76 deletions

View File

@@ -40,6 +40,24 @@ function computeShippedBySku(shipments) {
return map; return map;
} }
// MARK: helper to determine next shipment number preview
export function getNextShipmentNumber(orderNumber, shipments = []) {
if (!orderNumber) return '–';
let maxIdx = 0;
for (const s of shipments || []) {
const num = String(s.number ?? '').trim();
const match = num.match(/-L-(\d+)$/i) || num.match(/-(\d+)$/);
if (match) {
const parsed = parseInt(match[1], 10);
if (!Number.isNaN(parsed) && parsed > maxIdx) {
maxIdx = parsed;
}
}
}
const nextIdx = maxIdx > 0 ? maxIdx + 1 : ((shipments?.length || 0) + 1);
return `${orderNumber}-L-${nextIdx}`;
}
/** /**
* Dialog for selecting items and quantities to create a shipment from a sales order. * Dialog for selecting items and quantities to create a shipment from a sales order.
* Calls POST /api/order/:id/shipment. * Calls POST /api/order/:id/shipment.
@@ -228,6 +246,7 @@ export default class OrderShipmentDialog extends PureComponent {
render() { render() {
const { open, onClose, orderNumber, lines = [], shipments = [] } = this.props; const { open, onClose, orderNumber, lines = [], shipments = [] } = this.props;
const { date, externalNumber, lineAmounts, selectedSkus, saving, error } = this.state; const { date, externalNumber, lineAmounts, selectedSkus, saving, error } = this.state;
const nextShipmentNumber = getNextShipmentNumber(orderNumber, shipments);
const shippedBySku = computeShippedBySku(shipments); const shippedBySku = computeShippedBySku(shipments);
const activeLines = lines.filter((l) => Boolean(l.sku)); const activeLines = lines.filter((l) => Boolean(l.sku));
@@ -293,7 +312,7 @@ export default class OrderShipmentDialog extends PureComponent {
</Alert> </Alert>
)} )}
{/* Header controls: date and external reference */} {/* Header controls: date, preview shipment number, and external reference */}
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={2} sx={{ mb: 2.5 }}> <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2} sx={{ mb: 2.5 }}>
<TextField <TextField
size="small" size="small"
@@ -303,7 +322,19 @@ export default class OrderShipmentDialog extends PureComponent {
disabled={saving} disabled={saving}
onChange={(e) => this.setState({ date: e.target.value })} onChange={(e) => this.setState({ date: e.target.value })}
slotProps={{ inputLabel: { shrink: true } }} slotProps={{ inputLabel: { shrink: true } }}
sx={{ minWidth: 170 }} sx={{ minWidth: 160 }}
/>
<TextField
size="small"
label="Lieferschein-Nr."
value={nextShipmentNumber}
disabled
slotProps={{
input: {
readOnly: true,
},
}}
sx={{ minWidth: 190 }}
/> />
<TextField <TextField
size="small" size="small"

View File

@@ -24,8 +24,6 @@ import AddIcon from '@mui/icons-material/Add';
import DeleteOutlinedIcon from '@mui/icons-material/DeleteOutlined'; import DeleteOutlinedIcon from '@mui/icons-material/DeleteOutlined';
import CheckCircleOutlineOutlinedIcon from '@mui/icons-material/CheckCircleOutlineOutlined'; import CheckCircleOutlineOutlinedIcon from '@mui/icons-material/CheckCircleOutlineOutlined';
import ContentCopyIcon from '@mui/icons-material/ContentCopy'; import ContentCopyIcon from '@mui/icons-material/ContentCopy';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import Inventory2Icon from '@mui/icons-material/Inventory2';
import { enqueueSnackbar } from 'notistack'; import { enqueueSnackbar } from 'notistack';
import AppDialog from '../AppDialog'; import AppDialog from '../AppDialog';
import { shipment as shipmentApi, shipping as shippingApi } from '../../api'; import { shipment as shipmentApi, shipping as shippingApi } from '../../api';
@@ -174,7 +172,6 @@ export default class ShipmentDetailDialog extends PureComponent {
this.handleDeletePackage = this.handleDeletePackage.bind(this); this.handleDeletePackage = this.handleDeletePackage.bind(this);
this.handleMarkPackageShipped = this.handleMarkPackageShipped.bind(this); this.handleMarkPackageShipped = this.handleMarkPackageShipped.bind(this);
this.handleStateChange = this.handleStateChange.bind(this); this.handleStateChange = this.handleStateChange.bind(this);
this.handleNavigateFull = this.handleNavigateFull.bind(this);
} }
componentDidMount() { componentDidMount() {
@@ -260,7 +257,7 @@ export default class ShipmentDetailDialog extends PureComponent {
this.setState((prev) => ({ this.setState((prev) => ({
shipment: { ...prev.shipment, state: newState }, shipment: { ...prev.shipment, state: newState },
})); }));
const label = newState === 'delivered' ? 'Geliefert' : newState === 'returned' ? 'Retoure' : 'Neu'; const label = newState === 'delivered' ? 'Versendet' : newState === 'returned' ? 'Retoure' : 'Neu';
enqueueSnackbar(`Lieferstatus geändert: ${label}`, { variant: 'success' }); enqueueSnackbar(`Lieferstatus geändert: ${label}`, { variant: 'success' });
await Promise.all([ await Promise.all([
orderAutomat.actions.reload(), orderAutomat.actions.reload(),
@@ -274,14 +271,6 @@ export default class ShipmentDetailDialog extends PureComponent {
} }
} }
handleNavigateFull() {
const { shipment, onClose, onNavigate } = this.props;
onClose?.();
if (onNavigate && shipment?.id) {
onNavigate(`/auftrag/ausliefern?shipmentId=${shipment.id}`);
}
}
render() { render() {
const { open, onClose } = this.props; const { open, onClose } = this.props;
const { shipment, loading, error, addPackageDialogOpen, busyAction } = this.state; const { shipment, loading, error, addPackageDialogOpen, busyAction } = this.state;
@@ -290,7 +279,6 @@ export default class ShipmentDetailDialog extends PureComponent {
const shLines = Array.isArray(shipment.lines) ? shipment.lines : []; const shLines = Array.isArray(shipment.lines) ? shipment.lines : [];
const shPackages = Array.isArray(shipment.shippings) ? shipment.shippings : []; const shPackages = Array.isArray(shipment.shippings) ? shipment.shippings : [];
const hasShippedPackages = shPackages.some((p) => p.state === 'shipped');
return ( return (
<AppDialog open={open} onClose={onClose} maxWidth="md" fullWidth> <AppDialog open={open} onClose={onClose} maxWidth="md" fullWidth>
@@ -298,46 +286,23 @@ export default class ShipmentDetailDialog extends PureComponent {
<Stack direction="row" spacing={1.5} sx={{ alignItems: 'center' }}> <Stack direction="row" spacing={1.5} sx={{ alignItems: 'center' }}>
<LocalShippingIcon color="primary" sx={{ fontSize: 28 }} /> <LocalShippingIcon color="primary" sx={{ fontSize: 28 }} />
<Box> <Box>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}> <Typography variant="h6" sx={{ fontWeight: 700, lineHeight: 1.2 }}>
<Typography variant="h6" sx={{ fontWeight: 700, lineHeight: 1.2 }}> {shipment.number || 'Lieferschein'}
{shipment.number || 'Lieferschein'} </Typography>
</Typography>
<Chip
size="small"
color={hasShippedPackages ? 'success' : 'default'}
label={hasShippedPackages ? 'Im Versand' : 'Bereitstellung'}
sx={{ fontWeight: 600, height: 20, fontSize: '0.7rem' }}
/>
</Box>
<Typography variant="caption" color="text.secondary"> <Typography variant="caption" color="text.secondary">
{shipment.date ? `Datum: ${formatDate(shipment.date)}` : ''} {shipment.date ? `Datum: ${formatDate(shipment.date)}` : ''}
{shipment.externalNumber ? ` • Ref: ${shipment.externalNumber}` : ''} {shipment.externalNumber ? ` • Ref: ${shipment.externalNumber}` : ''}
</Typography> </Typography>
</Box> </Box>
</Stack> </Stack>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5 }}> <IconButton
<TextField aria-label="close"
select onClick={onClose}
size="small" size="small"
label="Lieferstatus" sx={{ color: (theme) => theme.palette.grey[500] }}
value={shipment.state || 'new'} >
onChange={(e) => this.handleStateChange(e.target.value)} <CloseIcon />
disabled={busyAction} </IconButton>
sx={{ minWidth: 130 }}
>
<MenuItem value="new">Neu</MenuItem>
<MenuItem value="delivered">Geliefert</MenuItem>
<MenuItem value="returned">Retoure</MenuItem>
</TextField>
<IconButton
aria-label="close"
onClick={onClose}
size="small"
sx={{ color: (theme) => theme.palette.grey[500] }}
>
<CloseIcon />
</IconButton>
</Box>
</DialogTitle> </DialogTitle>
<DialogContent dividers sx={{ p: 2.5, display: 'flex', flexDirection: 'column', gap: 2.5 }}> <DialogContent dividers sx={{ p: 2.5, display: 'flex', flexDirection: 'column', gap: 2.5 }}>
@@ -349,9 +314,6 @@ export default class ShipmentDetailDialog extends PureComponent {
{/* Shipped Article Positions */} {/* Shipped Article Positions */}
<Box> <Box>
<Typography variant="subtitle2" sx={{ fontWeight: 700, mb: 1 }}>
Gelieferte Artikel-Positionen ({shLines.length})
</Typography>
<TableContainer sx={{ border: '1px solid', borderColor: 'divider', borderRadius: 1.5, bgcolor: WHITE }}> <TableContainer sx={{ border: '1px solid', borderColor: 'divider', borderRadius: 1.5, bgcolor: WHITE }}>
<Table size="small"> <Table size="small">
<TableHead sx={{ bgcolor: SURFACE_RAISED }}> <TableHead sx={{ bgcolor: SURFACE_RAISED }}>
@@ -386,10 +348,7 @@ export default class ShipmentDetailDialog extends PureComponent {
{/* Shipping Packages / Tracking */} {/* Shipping Packages / Tracking */}
<Box> <Box>
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', mb: 1 }}> <Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'flex-end', mb: shPackages.length > 0 ? 1 : 0 }}>
<Typography variant="subtitle2" sx={{ fontWeight: 700 }}>
Pakete & Sendungsverfolgung ({shPackages.length})
</Typography>
<Button <Button
size="small" size="small"
variant="outlined" variant="outlined"
@@ -402,14 +361,7 @@ export default class ShipmentDetailDialog extends PureComponent {
</Button> </Button>
</Box> </Box>
{shPackages.length === 0 ? ( {shPackages.length > 0 ? (
<Box sx={{ p: 2.5, textAlign: 'center', bgcolor: WHITE, borderRadius: 1.5, border: '1px dashed', borderColor: 'divider' }}>
<Inventory2Icon sx={{ color: 'text.secondary', fontSize: 28, mb: 0.5 }} />
<Typography variant="body2" color="text.secondary">
Noch keine Pakete erfasst.
</Typography>
</Box>
) : (
<Stack spacing={1}> <Stack spacing={1}>
{shPackages.map((pkg) => { {shPackages.map((pkg) => {
const isShipped = pkg.state === 'shipped'; const isShipped = pkg.state === 'shipped';
@@ -493,25 +445,41 @@ export default class ShipmentDetailDialog extends PureComponent {
); );
})} })}
</Stack> </Stack>
)} ) : null}
</Box> </Box>
</DialogContent> </DialogContent>
<DialogActions sx={{ p: 2, justifyContent: 'space-between' }}> <DialogActions sx={{ p: 2, justifyContent: 'flex-end' }}>
<Button variant="outlined" onClick={onClose}> {(!shipment.state || shipment.state === 'new') && (
Schließen
</Button>
{this.props.onNavigate && (
<Button <Button
variant="contained" variant="contained"
startIcon={<OpenInNewIcon />} color="primary"
onClick={this.handleNavigateFull} disabled={busyAction}
sx={{ textTransform: 'none', fontWeight: 600 }} onClick={() => this.handleStateChange('delivered')}
sx={{ textTransform: 'none', fontWeight: 700 }}
> >
In Auslieferungen öffnen {busyAction ? 'Wird versendet…' : 'Versenden'}
</Button> </Button>
)} )}
{shipment.state === 'delivered' && (
<Button
variant="contained"
color="warning"
disabled={busyAction}
onClick={() => this.handleStateChange('returned')}
sx={{ textTransform: 'none', fontWeight: 700 }}
>
{busyAction ? 'Wird gebucht…' : 'Retoure'}
</Button>
)}
{shipment.state === 'returned' && (
<Chip
label="Retoure"
color="error"
variant="outlined"
sx={{ fontWeight: 700, height: 28, fontSize: '0.8rem' }}
/>
)}
</DialogActions> </DialogActions>
{addPackageDialogOpen && ( {addPackageDialogOpen && (

View File

@@ -31,6 +31,7 @@ import { notifyError } from '../../utils/notify';
import { getMaxDocumentNumber } from '../../utils/documentNumber'; import { getMaxDocumentNumber } from '../../utils/documentNumber';
import withNavigate from '../withNavigate'; import withNavigate from '../withNavigate';
import ShipmentDetailDialog from './ShipmentDetailDialog'; import ShipmentDetailDialog from './ShipmentDetailDialog';
import { getNextShipmentNumber } from './OrderShipmentDialog';
import { import {
formatDate, formatDate,
loadParties, loadParties,
@@ -206,8 +207,18 @@ class NewShipmentModal extends PureComponent {
value={date} value={date}
onChange={(e) => this.setState({ date: e.target.value })} onChange={(e) => this.setState({ date: e.target.value })}
InputLabelProps={{ shrink: true }} InputLabelProps={{ shrink: true }}
sx={{ width: 180 }} sx={{ width: 170 }}
/> />
{currentOrder ? (
<TextField
label="Lieferschein-Nr."
size="small"
value={getNextShipmentNumber(currentOrder.number, currentOrder.shipments)}
disabled
slotProps={{ input: { readOnly: true } }}
sx={{ width: 190 }}
/>
) : null}
<TextField <TextField
label="Referenz" label="Referenz"
size="small" size="small"