u
This commit is contained in:
@@ -26,6 +26,7 @@ import { requireArray, requireDefined, requireObject } from '../../utils/apiShap
|
||||
import { backendErrorFrom } from '../../utils/backendError';
|
||||
import { notifyError } from '../../utils/notify';
|
||||
import {
|
||||
setId,
|
||||
setDeliveryEntities,
|
||||
setDate,
|
||||
setDeliveryEntity,
|
||||
@@ -38,6 +39,7 @@ import {
|
||||
updateLineitem,
|
||||
removeLineitem,
|
||||
resetDelivery,
|
||||
selectDeliveryId,
|
||||
selectDeliveryEntities,
|
||||
selectDeliveryDate,
|
||||
selectDeliveryEntity,
|
||||
@@ -82,6 +84,9 @@ class LieferungNeuPage extends PureComponent {
|
||||
if (this.props.docId != null) {
|
||||
void this.loadEdit();
|
||||
} else {
|
||||
if (this.props.deliveryId != null || this.props.number != null) {
|
||||
this.props.resetDelivery();
|
||||
}
|
||||
void this.loadPartiesOnly();
|
||||
}
|
||||
}
|
||||
@@ -150,6 +155,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
const lines =
|
||||
apiLines.length > 0 ? apiLines.map(lineFromApi) : [emptyLine()];
|
||||
|
||||
this.props.setId(doc.id ?? docId);
|
||||
this.props.setDate(dateInputValue(doc.date));
|
||||
if (doc[cfg.partyField] != null) this.props.setDeliveryEntity(doc[cfg.partyField]);
|
||||
if (doc.number != null) this.props.setNumber(doc.number);
|
||||
@@ -191,10 +197,22 @@ class LieferungNeuPage extends PureComponent {
|
||||
this.props.setExternalNumber(externalNumber);
|
||||
}
|
||||
|
||||
findLineIndex(key) {
|
||||
if (typeof key === 'number' && !Number.isNaN(key)) return key;
|
||||
const lines = this.props.lines;
|
||||
if (Array.isArray(lines)) {
|
||||
const idx = lines.findIndex((l) => l.key === key);
|
||||
if (idx !== -1) return idx;
|
||||
}
|
||||
const n = Number(key);
|
||||
return Number.isInteger(n) ? n : -1;
|
||||
}
|
||||
|
||||
handleLineChange(key, field, value) {
|
||||
const index = typeof key === 'number' ? key : Number(key);
|
||||
const index = this.findLineIndex(key);
|
||||
this.props.updateLineitem({
|
||||
index,
|
||||
key,
|
||||
[field]: value,
|
||||
...(field === 'net' ? { netprice: value } : {}),
|
||||
...(field === 'tax' ? { taxrate: value } : {}),
|
||||
@@ -206,8 +224,8 @@ class LieferungNeuPage extends PureComponent {
|
||||
}
|
||||
|
||||
handleRemoveLine(key) {
|
||||
const index = typeof key === 'number' ? key : Number(key);
|
||||
this.props.removeLineitem(index);
|
||||
const index = this.findLineIndex(key);
|
||||
this.props.removeLineitem(index >= 0 ? index : key);
|
||||
}
|
||||
|
||||
async handlePdfUpload(file) {
|
||||
@@ -268,7 +286,8 @@ class LieferungNeuPage extends PureComponent {
|
||||
? result.items.items
|
||||
: null;
|
||||
const newLines = Array.isArray(rawItems)
|
||||
? rawItems.map((l) => ({
|
||||
? rawItems.map((l, idx) => ({
|
||||
key: l.key ?? `${Date.now()}-${idx}-${Math.random().toString(36).slice(2, 8)}`,
|
||||
name: l.name ?? l.articleName ?? null,
|
||||
sku: l.sku ?? l.liefArtNr ?? '',
|
||||
amount: (l.amount ?? l.count) != null ? String(l.amount ?? l.count) : '',
|
||||
@@ -406,6 +425,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
const apiLines = requireArray(doc.lines, `${cfg.docField}.lines`);
|
||||
const lines = apiLines.length > 0 ? apiLines.map(lineFromApi) : [emptyLine()];
|
||||
|
||||
this.props.setId(doc.id ?? docId);
|
||||
this.props.setDate(dateInputValue(doc.date));
|
||||
if (doc[cfg.partyField] != null) this.props.setDeliveryEntity(doc[cfg.partyField]);
|
||||
if (doc.number != null) this.props.setNumber(doc.number);
|
||||
@@ -532,6 +552,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
deliveryId: selectDeliveryId(state),
|
||||
deliveryEntities: selectDeliveryEntities(state),
|
||||
date: selectDeliveryDate(state),
|
||||
partyId: selectDeliveryEntity(state),
|
||||
@@ -542,6 +563,7 @@ const mapStateToProps = (state) => ({
|
||||
});
|
||||
|
||||
const mapDispatchToProps = {
|
||||
setId,
|
||||
setDeliveryEntities,
|
||||
setDate,
|
||||
setDeliveryEntity,
|
||||
|
||||
Reference in New Issue
Block a user