u
This commit is contained in:
@@ -57,6 +57,51 @@ import {
|
||||
YELLOW_BG,
|
||||
} from '../../colors';
|
||||
|
||||
function areLinesEqual(lines1, lines2) {
|
||||
if (!Array.isArray(lines1) || !Array.isArray(lines2)) return false;
|
||||
if (lines1.length !== lines2.length) return false;
|
||||
for (let i = 0; i < lines1.length; i++) {
|
||||
const a = lines1[i] || {};
|
||||
const b = lines2[i] || {};
|
||||
const aSku = String(a.sku ?? '').trim();
|
||||
const bSku = String(b.sku ?? '').trim();
|
||||
if (aSku !== bSku) return false;
|
||||
|
||||
const aName = String(a.name ?? '').trim();
|
||||
const bName = String(b.name ?? '').trim();
|
||||
if (aName !== bName) return false;
|
||||
|
||||
const aAmount = a.amount != null && a.amount !== '' ? Number(a.amount) : null;
|
||||
const bAmount = b.amount != null && b.amount !== '' ? Number(b.amount) : null;
|
||||
if (aAmount !== bAmount) return false;
|
||||
|
||||
const aNet =
|
||||
(a.netprice ?? a.net) != null && (a.netprice ?? a.net) !== ''
|
||||
? Number(a.netprice ?? a.net)
|
||||
: null;
|
||||
const bNet =
|
||||
(b.netprice ?? b.net) != null && (b.netprice ?? b.net) !== ''
|
||||
? Number(b.netprice ?? b.net)
|
||||
: null;
|
||||
if (aNet !== bNet) return false;
|
||||
|
||||
const aTax =
|
||||
(a.taxrate ?? a.tax) != null && (a.taxrate ?? a.tax) !== ''
|
||||
? Number(a.taxrate ?? a.tax)
|
||||
: null;
|
||||
const bTax =
|
||||
(b.taxrate ?? b.tax) != null && (b.taxrate ?? b.tax) !== ''
|
||||
? Number(b.taxrate ?? b.tax)
|
||||
: null;
|
||||
if (aTax !== bTax) return false;
|
||||
|
||||
const aPu = a.pu != null && a.pu !== '' ? Number(a.pu) : 1;
|
||||
const bPu = b.pu != null && b.pu !== '' ? Number(b.pu) : 1;
|
||||
if (aPu !== bPu) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
class LieferungNeuPage extends PureComponent {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@@ -150,6 +195,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
this.automat = getDeliveryEditorAutomat(this.props.docId);
|
||||
this.unsubscribe = this.automat.subscribe(this);
|
||||
this.setState({ ...this.automat.state });
|
||||
this._initialLines = null;
|
||||
if (this.props.docId != null) {
|
||||
void this.loadEdit();
|
||||
} else {
|
||||
@@ -227,6 +273,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
if (doc.number != null) this.automat.actions.setNumber(doc.number);
|
||||
if (doc.externalNumber != null) this.automat.actions.setExternalNumber(String(doc.externalNumber));
|
||||
this.automat.actions.setLineitems(lines);
|
||||
this._initialLines = lines;
|
||||
|
||||
// Restore attachments with thumbnails
|
||||
const apiFiles = doc.files ?? [];
|
||||
@@ -786,9 +833,24 @@ class LieferungNeuPage extends PureComponent {
|
||||
});
|
||||
}
|
||||
|
||||
handlePdfDelete(attachment) {
|
||||
if (!attachment?.id) return;
|
||||
this.automat.actions.removeAttachment(attachment.id);
|
||||
async handlePdfDelete(attachment) {
|
||||
if (!attachment) return;
|
||||
const fileId = attachment.fileId ?? attachment.id;
|
||||
const docId = this.props.docId ?? attachment.manifestId ?? this.state.id;
|
||||
|
||||
this.automat.actions.removeAttachment(attachment.id ?? fileId);
|
||||
if (fileId != null && fileId !== attachment.id) {
|
||||
this.automat.actions.removeAttachment(fileId);
|
||||
}
|
||||
|
||||
if (docId != null && fileId != null && attachment.isPersisted) {
|
||||
try {
|
||||
await deliveryApi.deleteFile(docId, fileId);
|
||||
enqueueSnackbar('Anhang gelöscht.', { variant: 'success' });
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async ensureAttachmentFile(attachment) {
|
||||
@@ -1031,6 +1093,9 @@ class LieferungNeuPage extends PureComponent {
|
||||
if (this.state.saving) return;
|
||||
|
||||
const isCreate = docId == null;
|
||||
const linesModified =
|
||||
isCreate || !this._initialLines || !areLinesEqual(this.state.lines, this._initialLines);
|
||||
|
||||
let body;
|
||||
try {
|
||||
body = await buildManifestBody(
|
||||
@@ -1039,13 +1104,17 @@ class LieferungNeuPage extends PureComponent {
|
||||
externalNumber: this.state.externalNumber ?? '',
|
||||
date: this.state.date ?? '',
|
||||
partyId: this.state.partyId,
|
||||
lines: this.state.lines,
|
||||
lines: linesModified ? this.state.lines : undefined,
|
||||
attachments: this.state.attachments,
|
||||
},
|
||||
{
|
||||
kind: cfg.kind,
|
||||
partyField: cfg.partyField,
|
||||
requireAtLeastOne: isCreate,
|
||||
externalNumber: cfg.externalNumber,
|
||||
isUpdate: !isCreate,
|
||||
mode: isCreate ? 'create' : 'edit',
|
||||
omitLines: !linesModified,
|
||||
},
|
||||
);
|
||||
} catch (err) {
|
||||
@@ -1083,6 +1152,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
if (doc.number != null) this.automat.actions.setNumber(doc.number);
|
||||
if (doc.externalNumber != null) this.automat.actions.setExternalNumber(String(doc.externalNumber));
|
||||
this.automat.actions.setLineitems(lines);
|
||||
this._initialLines = lines;
|
||||
void this.reloadLedgerSummary();
|
||||
|
||||
// Restore attachments with thumbnails
|
||||
|
||||
Reference in New Issue
Block a user