Compare commits

..

4 Commits

Author SHA1 Message Date
seb
bea427f3df u 2026-10-17 04:18:43 +02:00
seb
bd16df64a1 u 2026-10-17 04:11:42 +02:00
seb
6df833b362 u 2026-10-17 03:57:36 +02:00
seb
e63abfe2c0 u 2026-10-17 03:47:09 +02:00
12 changed files with 265 additions and 267 deletions

View File

@@ -67,7 +67,7 @@ export function createManifestDraftAutomat({ kind, name }) {
/** @param {Array<object>} lines */
setLines(lines) {
const list = Array.isArray(lines) && lines.length > 0 ? lines : [emptyLine()];
const list = Array.isArray(lines) ? lines : [];
automat.setState({ lines: list });
},
@@ -100,11 +100,11 @@ export function createManifestDraftAutomat({ kind, name }) {
removeLine(key) {
const current = automat.state.lines || [];
const next = current.filter((l) => l.key !== key);
automat.setState({ lines: next.length > 0 ? next : [emptyLine()] });
automat.setState({ lines: next });
},
removeAllLines() {
automat.setState({ lines: [emptyLine()] });
automat.setState({ lines: [] });
},
/** @param {Array<object>} attachments */
@@ -423,7 +423,7 @@ export function createManifestEditAutomat({ kind, name }) {
const partyId = doc.partyId ?? null;
const number = doc.number ?? '';
const externalNumber = doc.externalNumber != null ? String(doc.externalNumber) : '';
const lines = Array.isArray(doc.lines) && doc.lines.length > 0 ? doc.lines : [emptyLine()];
const lines = Array.isArray(doc.lines) ? doc.lines : [];
const attachments = Array.isArray(doc.attachments) ? doc.attachments : [];
const baseline = {
@@ -508,7 +508,7 @@ export function createManifestEditAutomat({ kind, name }) {
const partyId = savedDoc.partyId ?? null;
const number = savedDoc.number ?? automat.state.number;
const externalNumber = savedDoc.externalNumber != null ? String(savedDoc.externalNumber) : '';
const lines = Array.isArray(savedDoc.lines) && savedDoc.lines.length > 0 ? savedDoc.lines : [emptyLine()];
const lines = Array.isArray(savedDoc.lines) ? savedDoc.lines : [];
const attachments = Array.isArray(savedDoc.attachments) ? savedDoc.attachments : automat.state.attachments;
const baseline = {

View File

@@ -136,7 +136,7 @@ export class PriceUnitCorner extends Component {
size="small"
checked={Boolean(hasUnit)}
onChange={(event) => onToggleHasUnit(event.target.checked)}
inputProps={{ 'aria-label': 'Einheit' }}
slotProps={{ input: { 'aria-label': 'Einheit' } }}
/>
<IconButton
type="button"

View File

@@ -21,6 +21,7 @@ import supplierAutomat from '../../automats/supplierAutomat';
import orderAutomat from '../../automats/orderAutomat';
import companyAutomat, { selectCompanyTaxrate } from '../../automats/companyAutomat';
import { netFromGross, grossFromNet, getArticleGross } from '../../utils/price';
import { resolveSalesPrice } from '../../utils/articleDetail';
import {
buildManifestBody,
restoreAttachmentsFromApi,
@@ -81,7 +82,7 @@ class ManifestForm extends PureComponent {
partyId: initialDoc?.partyId ?? null,
number: initialDoc?.number || '',
externalNumber: initialDoc?.externalNumber || '',
lines: initialDoc?.lines?.length > 0 ? initialDoc.lines : [emptyLine()],
lines: Array.isArray(initialDoc?.lines) ? initialDoc.lines : (props.mode === 'create' ? [emptyLine()] : []),
attachments: initialDoc?.attachments || [],
shipments: initialEdit?.shipments || [],
payments: initialEdit?.payments || [],
@@ -119,6 +120,8 @@ class ManifestForm extends PureComponent {
this.handleExternalNumberChange.bind(this);
this.handleLineChange = this.handleLineChange.bind(this);
this.handleSkuBlur = this.handleSkuBlur.bind(this);
this.getCustomerGroupId = this.getCustomerGroupId.bind(this);
this.getOrFetchArticle = this.getOrFetchArticle.bind(this);
this.handleAddLine = this.handleAddLine.bind(this);
this.handleAddArticleLine = this.handleAddArticleLine.bind(this);
this.handleOpenArticleSearchForLine = this.handleOpenArticleSearchForLine.bind(this);
@@ -194,7 +197,7 @@ class ManifestForm extends PureComponent {
date: state.date || '',
partyId: state.partyId,
externalNumber: state.externalNumber || '',
lines: state.lines?.length > 0 ? state.lines : [emptyLine()],
lines: state.lines || [],
attachments: state.attachments || [],
}));
}
@@ -206,7 +209,7 @@ class ManifestForm extends PureComponent {
date: state.date || '',
partyId: state.partyId,
externalNumber: state.externalNumber || '',
lines: state.lines?.length > 0 ? state.lines : [emptyLine()],
lines: state.lines || [],
attachments: state.attachments || [],
shipments: state.shipments || [],
payments: state.payments || [],
@@ -368,8 +371,7 @@ class ManifestForm extends PureComponent {
requireObject(docRes[cfg.docField], cfg.docField);
const doc = docRes[cfg.docField];
const apiLines = requireArray(doc.lines, `${cfg.docField}.lines`);
const lines =
apiLines.length > 0 ? apiLines.map(lineFromApi) : [emptyLine()];
const lines = apiLines.map(lineFromApi);
// Restore attachments if available
const apiFiles = doc.files ?? [];
@@ -453,7 +455,7 @@ class ManifestForm extends PureComponent {
partyId: state.partyId,
number: state.number || '',
externalNumber: state.externalNumber || '',
lines: state.lines?.length > 0 ? state.lines : [emptyLine()],
lines: state.lines || [],
attachments: state.attachments || [],
isDirty: false,
dirtyFields: state.dirtyFields,
@@ -574,48 +576,51 @@ class ManifestForm extends PureComponent {
}));
}
getCustomerGroupId() {
const { partyId, parties } = this.state;
if (!partyId || !Array.isArray(parties)) return null;
const entity = parties.find((p) => String(p.id) === String(partyId));
return entity?.customergroupId ?? null;
}
async getOrFetchArticle(articleOrSku) {
const sku = typeof articleOrSku === 'string' ? articleOrSku : articleOrSku?.sku;
const trimmed = String(sku ?? '').trim();
if (!trimmed) return typeof articleOrSku === 'object' ? articleOrSku : null;
let art = getArticle(trimmed);
if (!art) {
try {
art = await artikelAutomat.actions.loadArticle(trimmed);
} catch {
// fallback
}
}
if (art) return art;
return typeof articleOrSku === 'object' ? articleOrSku : null;
}
async handleSkuBlur(key, sku) {
const trimmed = String(sku ?? '').trim();
if (!trimmed) return;
try {
const art = getArticle(trimmed) || (await artikelAutomat.actions.loadArticle(trimmed));
const art = await this.getOrFetchArticle(trimmed);
if (art && !this._cancelled) {
const normTax = selectCompanyTaxrate() != null ? Number(selectCompanyTaxrate()) : 19;
const customerGroupId = this.getCustomerGroupId();
this.setState((prev) => ({
lines: prev.lines.map((l) => {
if (l.key !== key) return l;
const netVal =
art.price != null
? String(art.price)
: art.vknetto != null
? String(art.vknetto)
: art.net != null
? String(art.net)
: '';
const taxVal =
art.taxrate != null
? String(art.taxrate)
: art.tax != null
? String(art.tax)
: '';
const netNum = parseNum(netVal);
const taxNum = parseNum(taxVal);
const rebateNum = parseNum(l.rebate) ?? 0;
const artGross = getArticleGross(art, taxNum ?? 0);
let grossVal = '';
if (artGross != null && rebateNum === 0) {
grossVal = String(artGross);
} else if (netNum != null) {
grossVal = String(grossFromNet(netNum, taxNum ?? 0, rebateNum));
} else if (artGross != null) {
grossVal = String(Math.round((artGross * (1 - rebateNum / 100) + Number.EPSILON) * 100) / 100);
}
const normTax = selectCompanyTaxrate() != null ? String(selectCompanyTaxrate()) : '19';
const finalTax =
art.taxrate != null
? String(art.taxrate)
: art.tax != null
? String(art.tax)
: l.tax || normTax;
const { net, gross, taxRate } = resolveSalesPrice(art, {
customerGroupId,
defaultTaxRate: normTax,
rebate: rebateNum,
});
const netVal = net != null ? String(net) : '';
const grossVal = gross != null ? String(gross) : '';
const finalTax = taxRate != null ? String(taxRate) : l.tax || String(normTax);
return {
...l,
amount: l.amount || '1',
@@ -624,9 +629,9 @@ class ManifestForm extends PureComponent {
tax: finalTax,
taxrate: finalTax,
rebate: l.rebate || '0',
net: l.net || netVal,
netprice: l.netprice || netVal,
gross: l.gross || grossVal,
net: netVal || l.net,
netprice: netVal || l.netprice,
gross: grossVal || l.gross,
unit: art.unit || l.unit || 'Stück',
};
}),
@@ -641,39 +646,27 @@ class ManifestForm extends PureComponent {
this.setState((prev) => ({ lines: [...prev.lines, emptyLine()] }));
}
handleAddArticleLine(article) {
async handleAddArticleLine(article) {
if (!article) return;
const normTax = selectCompanyTaxrate() != null ? String(selectCompanyTaxrate()) : '19';
const netVal =
article.price != null
? String(article.price)
: article.vknetto != null
? String(article.vknetto)
: article.net != null
? String(article.net)
: '';
const taxVal =
article.taxrate != null
? String(article.taxrate)
: article.tax != null
? String(article.tax)
: normTax;
const netNum = parseNum(netVal);
const taxNum = parseNum(taxVal);
const artGross = getArticleGross(article, taxNum ?? 0);
let grossVal = '';
if (artGross != null) {
grossVal = String(artGross);
} else if (netNum != null) {
const g = Math.round((netNum * (1 + (taxNum ?? 0) / 100) + Number.EPSILON) * 100) / 100;
grossVal = String(g);
}
const fullArticle = (await this.getOrFetchArticle(article)) || article;
const normTax = selectCompanyTaxrate() != null ? Number(selectCompanyTaxrate()) : 19;
const customerGroupId = this.getCustomerGroupId();
const { net, gross, taxRate } = resolveSalesPrice(fullArticle, {
customerGroupId,
defaultTaxRate: normTax,
rebate: 0,
});
const netVal = net != null ? String(net) : '';
const grossVal = gross != null ? String(gross) : '';
const taxVal = taxRate != null ? String(taxRate) : String(normTax);
const newLine = {
key: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
amount: '1',
sku: article.sku || '',
name: article.name || '',
sku: fullArticle.sku || article.sku || '',
name: fullArticle.name || article.name || '',
tax: taxVal,
taxrate: taxVal,
net: netVal,
@@ -681,7 +674,7 @@ class ManifestForm extends PureComponent {
gross: grossVal,
rebate: '0',
pu: '1',
unit: article.unit || 'Stück',
unit: fullArticle.unit || article.unit || 'Stück',
};
this.setState((prev) => {
@@ -706,43 +699,31 @@ class ManifestForm extends PureComponent {
});
}
handleAssignArticleForLine(article, targetLine) {
async handleAssignArticleForLine(article, targetLine) {
if (!article) return;
if (!targetLine) {
this.handleAddArticleLine(article);
await this.handleAddArticleLine(article);
this.setState({
articleSearchDialogOpen: false,
articleSearchLine: null,
});
return;
}
const normTax = selectCompanyTaxrate() != null ? String(selectCompanyTaxrate()) : '19';
const netVal =
article.price != null
? String(article.price)
: article.vknetto != null
? String(article.vknetto)
: article.net != null
? String(article.net)
: '';
const taxVal =
article.taxrate != null
? String(article.taxrate)
: article.tax != null
? String(article.tax)
: normTax;
const netNum = parseNum(netVal);
const taxNum = parseNum(taxVal);
const fullArticle = (await this.getOrFetchArticle(article)) || article;
const normTax = selectCompanyTaxrate() != null ? Number(selectCompanyTaxrate()) : 19;
const customerGroupId = this.getCustomerGroupId();
const rebateNum = parseNum(targetLine.rebate) ?? 0;
const artGross = getArticleGross(article, taxNum ?? 0);
let grossVal = '';
if (artGross != null && rebateNum === 0) {
grossVal = String(artGross);
} else if (netNum != null) {
grossVal = String(grossFromNet(netNum, taxNum ?? 0, rebateNum));
} else if (artGross != null) {
grossVal = String(Math.round((artGross * (1 - rebateNum / 100) + Number.EPSILON) * 100) / 100);
}
const { net, gross, taxRate } = resolveSalesPrice(fullArticle, {
customerGroupId,
defaultTaxRate: normTax,
rebate: rebateNum,
});
const netVal = net != null ? String(net) : '';
const grossVal = gross != null ? String(gross) : '';
const taxVal = taxRate != null ? String(taxRate) : String(normTax);
this.setState((prev) => ({
lines: prev.lines.map((l) => {
@@ -750,15 +731,15 @@ class ManifestForm extends PureComponent {
return {
...l,
amount: l.amount || '1',
sku: article.sku || l.sku,
name: article.name || l.name,
tax: taxVal || l.tax || normTax,
taxrate: taxVal || l.taxrate || normTax,
sku: fullArticle.sku || article.sku || l.sku,
name: fullArticle.name || article.name || l.name,
tax: taxVal || l.tax || String(normTax),
taxrate: taxVal || l.taxrate || String(normTax),
rebate: l.rebate || '0',
net: netVal || l.net,
netprice: netVal || l.netprice,
gross: grossVal || l.gross,
unit: article.unit || l.unit || 'Stück',
unit: fullArticle.unit || article.unit || l.unit || 'Stück',
};
}),
articleSearchDialogOpen: false,
@@ -805,7 +786,7 @@ class ManifestForm extends PureComponent {
}
}
const next = prev.lines.filter((line) => line.key !== key);
return { lines: next.length > 0 ? next : [emptyLine()], isDirty: true };
return { lines: next, isDirty: true };
});
}
@@ -841,10 +822,10 @@ class ManifestForm extends PureComponent {
return null;
}
enqueueSnackbar('Nicht ausgelieferte Positionen wurden entfernt.', { variant: 'info' });
return { lines: remaining.length > 0 ? remaining : [emptyLine()], isDirty: true };
return { lines: remaining, isDirty: true };
}
}
return { lines: [emptyLine()], isDirty: true };
return { lines: [], isDirty: true };
});
}
@@ -1115,7 +1096,7 @@ class ManifestForm extends PureComponent {
if (this.state.saving) return false;
if (mode === 'edit' && docId == null) return false;
const requireAtLeastOne = mode === 'create';
const isEdit = mode === 'edit';
let body;
try {
body = await buildManifestBody(
@@ -1130,8 +1111,10 @@ class ManifestForm extends PureComponent {
{
kind: cfg.kind,
partyField: cfg.partyField,
requireAtLeastOne,
requireAtLeastOne: true,
externalNumber: cfg.externalNumber,
isUpdate: isEdit,
mode,
},
);
} catch (err) {
@@ -1169,8 +1152,7 @@ class ManifestForm extends PureComponent {
number: doc.number ?? '',
externalNumber:
doc.externalNumber != null ? String(doc.externalNumber) : '',
lines:
apiLines.length > 0 ? apiLines.map(lineFromApi) : [emptyLine()],
lines: apiLines.map(lineFromApi),
attachments: this.state.attachments,
};

View File

@@ -584,12 +584,28 @@ class ManifestFormLine extends PureComponent {
const primaryEan = Array.isArray(eans) ? eans[0] : eans;
const vkPrice = primaryPrice(cachedArticle);
const vkNetto = vkPrice?.net;
const vkNetto =
vkPrice?.net != null
? Number(vkPrice.net)
: cachedArticle.net != null
? Number(cachedArticle.net)
: cachedArticle.price != null
? Number(cachedArticle.price)
: null;
const vkTaxRate =
vkPrice?.taxRate ??
vkPrice?.taxrate ??
cachedArticle.taxrate ??
cachedArticle.taxRate ??
selectCompanyTaxrate() ??
19;
const vkBrutto = vkPrice
? priceBrutto(vkPrice) ??
(vkPrice.net != null && vkPrice.taxrate != null
? vkPrice.net * (1 + vkPrice.taxrate / 100)
: null)
(vkNetto != null && vkTaxRate != null
? Math.round((vkNetto * (1 + Number(vkTaxRate) / 100) + Number.EPSILON) * 100) / 100
: null)
: vkNetto != null
? Math.round((vkNetto * (1 + Number(vkTaxRate) / 100) + Number.EPSILON) * 100) / 100
: null;
const suppliers =
@@ -625,7 +641,7 @@ class ManifestFormLine extends PureComponent {
: null;
const hasPriceInfo =
vkNetto != null || vkBrutto != null || ekNetto != null || ekBrutto != null || kind === 'quote';
vkNetto != null || vkBrutto != null || ekNetto != null || ekBrutto != null || kind === 'quote' || kind === 'order';
return (
<Box
@@ -733,7 +749,7 @@ class ManifestFormLine extends PureComponent {
)}
{/* EK Netto, EK Brutto, VK Netto, VK Brutto */}
{!isOrder && hasPriceInfo && (
{hasPriceInfo && (
<Box
sx={{
display: 'flex',
@@ -784,26 +800,28 @@ class ManifestFormLine extends PureComponent {
</Tooltip>
{/* VK Netto */}
{vkNetto != null && (
<Typography
variant="caption"
fontWeight={600}
sx={{ color: 'text.secondary', fontSize: '0.72rem' }}
>
VK Netto: {formatPrice(vkNetto)}
</Typography>
)}
<Typography
variant="caption"
fontWeight={600}
sx={{
color: vkNetto != null ? 'text.secondary' : 'text.disabled',
fontSize: '0.72rem',
}}
>
VK Netto: {vkNetto != null ? formatPrice(vkNetto) : '—'}
</Typography>
{/* VK Brutto */}
{vkBrutto != null && (
<Typography
variant="caption"
fontWeight={600}
sx={{ color: 'primary.dark', fontSize: '0.72rem' }}
>
VK Brutto: {formatPrice(vkBrutto)}
</Typography>
)}
<Typography
variant="caption"
fontWeight={600}
sx={{
color: vkBrutto != null ? 'primary.dark' : 'text.disabled',
fontSize: '0.72rem',
}}
>
VK Brutto: {vkBrutto != null ? formatPrice(vkBrutto) : '—'}
</Typography>
</Box>
)}
</Box>

View File

@@ -9,7 +9,6 @@ import Chip from '@mui/material/Chip';
import UploadFileIcon from '@mui/icons-material/UploadFile';
import PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf';
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
import LocalShippingOutlinedIcon from '@mui/icons-material/LocalShippingOutlined';
import Inventory2OutlinedIcon from '@mui/icons-material/Inventory2Outlined';
import CheckCircleOutlineOutlinedIcon from '@mui/icons-material/CheckCircleOutlineOutlined';
import SingleLineTextEdit from 'dashgui/SingleLineTextEdit';
@@ -251,8 +250,6 @@ class ManifestHeader extends PureComponent {
onRestore,
orderCreating,
onCreateOrder,
onOpenCreateShipment,
deliverDisabled,
actionsColor,
partyError,
docId,
@@ -570,28 +567,6 @@ class ManifestHeader extends PureComponent {
{orderCreating ? 'Wird erstellt…' : 'Bestellung erstellen'}
</Button>
)}
{kind === 'order' && docId != null && onOpenCreateShipment && (
<Button
type="button"
variant="outlined"
color="primary"
startIcon={<LocalShippingOutlinedIcon />}
disabled={saving || pdfCreating || orderCreating || deliverDisabled}
onClick={onOpenCreateShipment}
title={deliverDisabled ? 'Alle Positionen bereits ausgeliefert' : 'Lieferschein erstellen'}
sx={{
whiteSpace: 'nowrap',
height: 40,
width: '100%',
px: 1.5,
boxSizing: 'border-box',
fontWeight: 600,
fontSize: '0.875rem',
}}
>
Liefern
</Button>
)}
{(kind === 'quote' || kind === 'order') && onPdfCreate && docId != null && Boolean(number) && (
<Button
type="button"

View File

@@ -114,8 +114,21 @@ class ManifestLines extends PureComponent {
}
}
return Array.isArray(lines) &&
lines.map((line, index) => {
if (!lines || lines.length === 0) {
return (
<TableRow>
<TableCell
colSpan={columns.length + 1}
align="center"
sx={{ py: 3, color: 'text.secondary', fontSize: '0.82rem' }}
>
Keine Positionen vorhanden
</TableCell>
</TableRow>
);
}
return lines.map((line, index) => {
const lineKey = line.key ?? index;
const rawSku = line.sku != null ? String(line.sku).trim() : '';
const isOnShipment = kind === 'order' && Boolean(rawSku && shippedSkus.has(rawSku.toLowerCase()));

View File

@@ -156,31 +156,7 @@ export class OrderDocumentsTiles extends PureComponent {
);
})}
</Stack>
) : (
<Box
sx={{
p: 1.5,
textAlign: 'center',
bgcolor: 'rgba(255,255,255,0.6)',
borderRadius: 1,
border: '1px dashed',
borderColor: 'divider',
}}
>
<Typography variant="caption" color="text.secondary" sx={{ display: 'block', mb: 1 }}>
Noch keine Lieferscheine erstellt.
</Typography>
<Button
size="small"
variant="contained"
startIcon={<LocalShippingOutlinedIcon />}
onClick={this.props.onOpenCreateShipment || (() => navigate?.('/auftrag/ausliefern'))}
sx={{ textTransform: 'none', fontWeight: 600, fontSize: '0.75rem' }}
>
Lieferschein anlegen
</Button>
</Box>
)}
) : null}
</PanelTile>
);
}
@@ -298,22 +274,7 @@ export class OrderDocumentsTiles extends PureComponent {
);
})}
</Stack>
) : (
<Box
sx={{
p: 1.5,
textAlign: 'center',
bgcolor: 'rgba(255,255,255,0.6)',
borderRadius: 1,
border: '1px dashed',
borderColor: 'divider',
}}
>
<Typography variant="caption" color="text.secondary">
Noch keine Zahlungen erfasst.
</Typography>
</Box>
)}
) : null}
</PanelTile>
);
}

View File

@@ -226,7 +226,7 @@ class OrderRow extends PureComponent {
color="success"
onClick={(e) => e.stopPropagation()}
onChange={(e) => onTogglePaid?.(order, e.target.checked)}
inputProps={{ 'aria-label': `Auftrag ${order.number} bezahlt` }}
slotProps={{ input: { 'aria-label': `Auftrag ${order.number} bezahlt` } }}
sx={{ p: 0.5 }}
/>
</Box>
@@ -238,7 +238,7 @@ class OrderRow extends PureComponent {
color="primary"
onClick={(e) => e.stopPropagation()}
onChange={(e) => onToggleDelivered?.(order, e.target.checked)}
inputProps={{ 'aria-label': `Auftrag ${order.number} geliefert` }}
slotProps={{ input: { 'aria-label': `Auftrag ${order.number} geliefert` } }}
sx={{ p: 0.5 }}
/>
</Box>

View File

@@ -264,7 +264,7 @@ export default class OrderShipmentDialog extends PureComponent {
</Typography>
{orderNumber ? (
<Typography variant="caption" color="text.secondary">
Zu Auftrag / Bestellung: <strong>{orderNumber}</strong>
Zu: <strong>{orderNumber}</strong>
</Typography>
) : null}
</Box>
@@ -307,8 +307,7 @@ export default class OrderShipmentDialog extends PureComponent {
/>
<TextField
size="small"
label="Lieferschein-Nr. / Externe Referenz (optional)"
placeholder="z.B. LS-2026-0042"
label="Referenz"
value={externalNumber}
disabled={saving}
onChange={(e) => this.setState({ externalNumber: e.target.value })}
@@ -316,24 +315,6 @@ export default class OrderShipmentDialog extends PureComponent {
/>
</Stack>
{/* Items selection section */}
<Box sx={{ mb: 1, display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<Typography variant="subtitle2" sx={{ fontWeight: 700 }}>
Zu liefernde Artikel ({selectedCount} von {openItems.length} ausgewählt)
</Typography>
{openItems.length > 0 && (
<Button
size="small"
variant="text"
disabled={saving}
onClick={() => this.handleToggleAll(openItems)}
sx={{ textTransform: 'none', fontWeight: 600, fontSize: '0.8rem' }}
>
{isAllSelected ? 'Auswahl aufheben' : 'Alle offenen auswählen'}
</Button>
)}
</Box>
<TableContainer sx={{ border: '1px solid', borderColor: 'divider', borderRadius: 1 }}>
<Table size="small">
<TableHead sx={{ bgcolor: 'action.hover' }}>
@@ -430,34 +411,17 @@ export default class OrderShipmentDialog extends PureComponent {
</TableContainer>
</DialogContent>
<DialogActions sx={{ p: 2, justifyContent: 'space-between' }}>
<Button variant="outlined" onClick={onClose} disabled={saving}>
Abbrechen
<DialogActions sx={{ p: 2, justifyContent: 'flex-end' }}>
<Button
variant="contained"
color="primary"
disabled={saving || allShipped || selectedCount === 0}
startIcon={saving ? <CircularProgress size={16} color="inherit" /> : <LocalShippingOutlinedIcon />}
onClick={this.handleSubmit}
sx={{ textTransform: 'none', fontWeight: 700 }}
>
{saving ? 'Wird erstellt…' : 'Lieferschein erstellen'}
</Button>
<Stack direction="row" spacing={1.5}>
{!allShipped && openItems.length > 0 && (
<Button
variant="outlined"
color="secondary"
disabled={saving}
onClick={this.handleShipAll}
sx={{ textTransform: 'none', fontWeight: 600 }}
>
Alles liefern
</Button>
)}
<Button
variant="contained"
color="primary"
disabled={saving || allShipped || selectedCount === 0}
startIcon={saving ? <CircularProgress size={16} color="inherit" /> : <LocalShippingOutlinedIcon />}
onClick={this.handleSubmit}
sx={{ textTransform: 'none', fontWeight: 700 }}
>
{saving ? 'Wird erstellt…' : 'Lieferschein erstellen'}
</Button>
</Stack>
</DialogActions>
</AppDialog>
);

View File

@@ -209,9 +209,8 @@ class NewShipmentModal extends PureComponent {
sx={{ width: 180 }}
/>
<TextField
label="Externe Referenz / Lieferschein-Nr."
label="Referenz"
size="small"
placeholder="z.B. LS-2026-99"
value={externalNumber}
onChange={(e) => this.setState({ externalNumber: e.target.value })}
sx={{ flex: 1 }}

View File

@@ -454,12 +454,14 @@ export function collectFilesForUpload(attachments = [], { onlyNew = false } = {}
*/
export async function buildManifestBody(
form,
{ partyField, requireAtLeastOne, externalNumber: useExternalNumber, kind },
{ partyField, requireAtLeastOne, externalNumber: useExternalNumber, kind, isUpdate, mode },
) {
const date = form.date;
if (!date) throw new Error('Datum fehlt.');
const externalNumber = String(form.externalNumber ?? '').trim();
const isEdit = isUpdate != null ? Boolean(isUpdate) : (mode === 'edit' || !requireAtLeastOne);
const shouldRequireLine = requireAtLeastOne !== false;
let body;
if (kind === 'delivery') {
@@ -468,7 +470,7 @@ export async function buildManifestBody(
body = {
externalNumber: externalNumber || null,
date,
lines: buildLines(form.lines, { requireAtLeastOne }),
lines: buildLines(form.lines, { requireAtLeastOne: shouldRequireLine }),
};
} else {
let number = String(form.number ?? '').trim();
@@ -479,7 +481,7 @@ export async function buildManifestBody(
body = {
number,
date,
lines: buildLines(form.lines, { requireAtLeastOne }),
lines: buildLines(form.lines, { requireAtLeastOne: shouldRequireLine }),
};
if (useExternalNumber || form.externalNumber != null) {
body.externalNumber = externalNumber || null;
@@ -490,14 +492,13 @@ export async function buildManifestBody(
if (!Number.isNaN(pid)) {
body[partyField] = pid;
}
} else if (!requireAtLeastOne) {
} else if (isEdit) {
body[partyField] = null;
}
// Add files if attachments exist
if (form.attachments && form.attachments.length > 0) {
const isUpdate = !requireAtLeastOne;
const filesToUpload = collectFilesForUpload(form.attachments, { onlyNew: isUpdate });
const filesToUpload = collectFilesForUpload(form.attachments, { onlyNew: isEdit });
if (filesToUpload.length > 0) {
const formData = new FormData();
body.filesMeta = filesToUpload.map((item) => ({

View File

@@ -2,6 +2,7 @@
import {
formatPriceAmount,
grossFromNet,
netFromGross,
parsePriceInput,
} from './price';
@@ -156,3 +157,87 @@ export function formatPhotoSizeKb(fullSize) {
export function formatPhotoDimensions(fullW, fullH) {
return `${fullW}×${fullH}`;
}
/**
* Resolves the sales price (VK-Preis) and tax rate for an article.
* Inspects `article.prices` (matching optional `customerGroupId`, falling back to base price),
* top-level `article.net` / `article.price` / `article.vknetto`, and calculates gross with optional rebate.
*
* @param {object|null} article
* @param {object} [options]
* @param {number|string|null} [options.customerGroupId]
* @param {number|string} [options.defaultTaxRate=19]
* @param {number|string} [options.rebate=0]
* @returns {{ net: number|null, gross: number|null, taxRate: number|null }}
*/
export function resolveSalesPrice(article, { customerGroupId, defaultTaxRate = 19, rebate = 0 } = {}) {
const normTax = defaultTaxRate != null && Number.isFinite(Number(defaultTaxRate)) ? Number(defaultTaxRate) : 19;
if (!article) {
return { net: null, gross: null, taxRate: normTax };
}
const r = Number.isFinite(Number(rebate)) ? Number(rebate) : 0;
let matchedPrice = null;
if (Array.isArray(article.prices) && article.prices.length > 0) {
if (customerGroupId != null) {
matchedPrice =
article.prices.find(
(p) => String(p.customergroupId) === String(customerGroupId) && (p.minmultiplier === 1 || p.minmultiplier == null)
) ||
article.prices.find((p) => String(p.customergroupId) === String(customerGroupId));
}
if (!matchedPrice) {
matchedPrice = primaryPrice(article);
}
}
let net = null;
let taxRate = null;
let gross = null;
if (matchedPrice) {
if (matchedPrice.net != null && Number.isFinite(Number(matchedPrice.net))) {
net = Number(matchedPrice.net);
}
const rawTax = matchedPrice.taxRate ?? matchedPrice.tax;
if (rawTax != null && Number.isFinite(Number(rawTax))) {
taxRate = Number(rawTax);
}
if (matchedPrice.gross != null && Number.isFinite(Number(matchedPrice.gross))) {
gross = Number(matchedPrice.gross);
} else if (net != null && taxRate != null) {
gross = priceBrutto(matchedPrice);
}
}
if (net == null) {
const rawNet = article.price ?? article.net ?? article.vknetto;
if (rawNet != null && Number.isFinite(Number(rawNet))) {
net = Number(rawNet);
}
}
if (taxRate == null) {
const rawTax = article.taxRate ?? article.taxrate ?? article.tax;
taxRate = rawTax != null && Number.isFinite(Number(rawTax)) ? Number(rawTax) : normTax;
}
if (gross == null && article.gross != null && Number.isFinite(Number(article.gross))) {
gross = Number(article.gross);
}
if (net == null && gross != null && taxRate != null) {
net = netFromGross(gross, taxRate, 0);
}
if (net != null && taxRate != null) {
if (r !== 0) {
gross = grossFromNet(net, taxRate, r);
} else if (gross == null) {
gross = Math.round((net * (1 + taxRate / 100) + Number.EPSILON) * 100) / 100;
}
}
return { net, gross, taxRate };
}