This commit is contained in:
seb
2026-10-18 19:32:31 +02:00
parent 199bf869a6
commit 587170ce9b
9 changed files with 184 additions and 29 deletions

View File

@@ -214,6 +214,7 @@ class LieferungNeuPage extends PureComponent {
this.unsubscribe = this.automat.subscribe(this);
this.setState({ ...this.automat.state });
this._initialLines = null;
this._initialDoc = null;
if (this.props.docId != null) {
void this.loadEdit();
} else {
@@ -296,11 +297,21 @@ class LieferungNeuPage extends PureComponent {
if (doc.externalNumber != null) this.automat.actions.setExternalNumber(String(doc.externalNumber));
this.automat.actions.setLineitems(lines);
this._initialLines = lines;
this._initialDoc = {
date: dateInputValue(doc.date),
partyId: doc[cfg.partyField] ?? null,
externalNumber: doc.externalNumber != null ? String(doc.externalNumber) : '',
lines,
attachments: [],
};
// Restore attachments with thumbnails
const apiFiles = doc.files ?? [];
const attachments = await restoreAttachmentsFromApi(apiFiles, this.state.attachments);
this.automat.actions.setAttachments(attachments);
if (this._initialDoc) {
this._initialDoc.attachments = attachments;
}
let ledgerSummary = null;
try {
@@ -1186,6 +1197,14 @@ class LieferungNeuPage extends PureComponent {
const attachments = await restoreAttachmentsFromApi(apiFiles, this.state.attachments);
this.automat.actions.setAttachments(attachments);
this._initialDoc = {
date: dateInputValue(doc.date),
partyId: doc[cfg.partyField] ?? null,
externalNumber: doc.externalNumber != null ? String(doc.externalNumber) : '',
lines,
attachments,
};
enqueueSnackbar(cfg.savedMsg, { variant: 'success' });
this.setState({ saving: false });
}
@@ -1259,6 +1278,27 @@ class LieferungNeuPage extends PureComponent {
}
}
const isEdit = this.props.docId != null;
let isDirty = false;
if (isEdit && this._initialDoc) {
const dateChanged = String(date ?? '').trim() !== String(this._initialDoc.date ?? '').trim();
const partyChanged = (partyId ?? null) !== (this._initialDoc.partyId ?? null);
const extChanged = String(externalNumber ?? '').trim() !== String(this._initialDoc.externalNumber ?? '').trim();
const linesChanged = !areLinesEqual(lines, this._initialDoc.lines);
const currentAtts = attachments || [];
const baseAtts = this._initialDoc.attachments || [];
let attsChanged = currentAtts.length !== baseAtts.length;
if (!attsChanged) {
for (const a of currentAtts) {
if (!a.isPersisted || a.isDirty) {
attsChanged = true;
break;
}
}
}
isDirty = dateChanged || partyChanged || extChanged || linesChanged || attsChanged;
}
return (
<>
<PanelTileGrid>
@@ -1279,6 +1319,7 @@ class LieferungNeuPage extends PureComponent {
onPdfCreate={this.handleCreatePdf}
attachments={attachments}
lines={lines}
isDirty={isDirty}
onPdfUpload={this.handlePdfUpload}
onPdfRescan={this.handlePdfRescan}
onPdfDelete={this.handlePdfDelete}