u
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user