This commit is contained in:
seb
2026-10-17 04:39:37 +02:00
parent bea427f3df
commit cb2f6ad37f
2 changed files with 45 additions and 3 deletions

View File

@@ -40,6 +40,24 @@ function computeShippedBySku(shipments) {
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.
* Calls POST /api/order/:id/shipment.
@@ -228,6 +246,7 @@ export default class OrderShipmentDialog extends PureComponent {
render() {
const { open, onClose, orderNumber, lines = [], shipments = [] } = this.props;
const { date, externalNumber, lineAmounts, selectedSkus, saving, error } = this.state;
const nextShipmentNumber = getNextShipmentNumber(orderNumber, shipments);
const shippedBySku = computeShippedBySku(shipments);
const activeLines = lines.filter((l) => Boolean(l.sku));
@@ -293,7 +312,7 @@ export default class OrderShipmentDialog extends PureComponent {
</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 }}>
<TextField
size="small"
@@ -303,7 +322,19 @@ export default class OrderShipmentDialog extends PureComponent {
disabled={saving}
onChange={(e) => this.setState({ date: e.target.value })}
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
size="small"

View File

@@ -31,6 +31,7 @@ import { notifyError } from '../../utils/notify';
import { getMaxDocumentNumber } from '../../utils/documentNumber';
import withNavigate from '../withNavigate';
import ShipmentDetailDialog from './ShipmentDetailDialog';
import { getNextShipmentNumber } from './OrderShipmentDialog';
import {
formatDate,
loadParties,
@@ -206,8 +207,18 @@ class NewShipmentModal extends PureComponent {
value={date}
onChange={(e) => this.setState({ date: e.target.value })}
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
label="Referenz"
size="small"