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