u
This commit is contained in:
@@ -77,12 +77,19 @@ function parseNum(value) {
|
|||||||
* @returns {DeliveryLine} Normalized line.
|
* @returns {DeliveryLine} Normalized line.
|
||||||
*/
|
*/
|
||||||
export function createEmptyLineitem(line = {}) {
|
export function createEmptyLineitem(line = {}) {
|
||||||
const netRaw = line.netprice ?? line.net ?? line.eknetto ?? line.netPrice ?? null;
|
let netVal = null;
|
||||||
|
if (line.netprice != null || line.net != null || line.netPrice != null) {
|
||||||
|
const netRaw = line.netprice ?? line.net ?? line.netPrice;
|
||||||
|
netVal = netRaw != null ? (parseNum(netRaw) ?? netRaw) : null;
|
||||||
|
} else if (line.eknetto != null && line.eknetto !== '') {
|
||||||
|
const parsedCent = parseNum(line.eknetto);
|
||||||
|
netVal = parsedCent != null ? Math.round((parsedCent / 100) * 10000) / 10000 : null;
|
||||||
|
}
|
||||||
|
|
||||||
const taxRaw = line.taxrate ?? line.tax ?? line.mwst ?? line.taxRate ?? null;
|
const taxRaw = line.taxrate ?? line.tax ?? line.mwst ?? line.taxRate ?? null;
|
||||||
const amountRaw = line.amount ?? line.count ?? line.qty ?? line.quantity ?? null;
|
const amountRaw = line.amount ?? line.count ?? line.qty ?? line.quantity ?? null;
|
||||||
const puRaw = line.pu ?? line.vpe ?? null;
|
const puRaw = line.pu ?? line.vpe ?? null;
|
||||||
|
|
||||||
const netVal = netRaw != null ? (parseNum(netRaw) ?? netRaw) : null;
|
|
||||||
const taxVal = taxRaw != null ? (parseNum(taxRaw) ?? taxRaw) : null;
|
const taxVal = taxRaw != null ? (parseNum(taxRaw) ?? taxRaw) : null;
|
||||||
const amountVal = amountRaw != null ? (parseNum(amountRaw) ?? amountRaw) : null;
|
const amountVal = amountRaw != null ? (parseNum(amountRaw) ?? amountRaw) : null;
|
||||||
const puVal = puRaw != null ? (parseNum(puRaw) ?? puRaw) : null;
|
const puVal = puRaw != null ? (parseNum(puRaw) ?? puRaw) : null;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import DeleteForeverIcon from '@mui/icons-material/DeleteForever';
|
|||||||
import DeleteIcon from '@mui/icons-material/Delete';
|
import DeleteIcon from '@mui/icons-material/Delete';
|
||||||
import GoogleIcon from '@mui/icons-material/Google';
|
import GoogleIcon from '@mui/icons-material/Google';
|
||||||
import WebIcon from '@mui/icons-material/Web';
|
import WebIcon from '@mui/icons-material/Web';
|
||||||
import EscalatorWarningIcon from '@mui/icons-material/EscalatorWarning';
|
import EngineeringIcon from '@mui/icons-material/Engineering';
|
||||||
import PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf';
|
import PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf';
|
||||||
import ManageSearchIcon from '@mui/icons-material/ManageSearch';
|
import ManageSearchIcon from '@mui/icons-material/ManageSearch';
|
||||||
import LensBlurIcon from '@mui/icons-material/LensBlur';
|
import LensBlurIcon from '@mui/icons-material/LensBlur';
|
||||||
@@ -91,7 +91,9 @@ const TOOL_ICON_MAP = {
|
|||||||
rm: DeleteIcon,
|
rm: DeleteIcon,
|
||||||
web_search: GoogleFaviconIcon,
|
web_search: GoogleFaviconIcon,
|
||||||
url_get: WebIcon,
|
url_get: WebIcon,
|
||||||
sub_agent: EscalatorWarningIcon,
|
subagent: EngineeringIcon,
|
||||||
|
sub_agent: EngineeringIcon,
|
||||||
|
'sub-agent': EngineeringIcon,
|
||||||
pdf_read: PictureAsPdfIcon,
|
pdf_read: PictureAsPdfIcon,
|
||||||
search_articles: ManageSearchIcon,
|
search_articles: ManageSearchIcon,
|
||||||
edit_image: LensBlurIcon,
|
edit_image: LensBlurIcon,
|
||||||
|
|||||||
@@ -454,7 +454,7 @@ export function collectFilesForUpload(attachments = [], { onlyNew = false } = {}
|
|||||||
*/
|
*/
|
||||||
export async function buildManifestBody(
|
export async function buildManifestBody(
|
||||||
form,
|
form,
|
||||||
{ partyField, requireAtLeastOne, externalNumber: useExternalNumber, kind, isUpdate, mode },
|
{ partyField, requireAtLeastOne, externalNumber: useExternalNumber, kind, isUpdate, mode, omitLines },
|
||||||
) {
|
) {
|
||||||
const date = form.date;
|
const date = form.date;
|
||||||
if (!date) throw new Error('Datum fehlt.');
|
if (!date) throw new Error('Datum fehlt.');
|
||||||
@@ -462,6 +462,7 @@ export async function buildManifestBody(
|
|||||||
const externalNumber = String(form.externalNumber ?? '').trim();
|
const externalNumber = String(form.externalNumber ?? '').trim();
|
||||||
const isEdit = isUpdate != null ? Boolean(isUpdate) : (mode === 'edit' || !requireAtLeastOne);
|
const isEdit = isUpdate != null ? Boolean(isUpdate) : (mode === 'edit' || !requireAtLeastOne);
|
||||||
const shouldRequireLine = requireAtLeastOne !== false;
|
const shouldRequireLine = requireAtLeastOne !== false;
|
||||||
|
const shouldIncludeLines = !omitLines && form.lines !== undefined && form.lines !== null;
|
||||||
|
|
||||||
let body;
|
let body;
|
||||||
if (kind === 'delivery') {
|
if (kind === 'delivery') {
|
||||||
@@ -470,8 +471,10 @@ export async function buildManifestBody(
|
|||||||
body = {
|
body = {
|
||||||
externalNumber: externalNumber || null,
|
externalNumber: externalNumber || null,
|
||||||
date,
|
date,
|
||||||
lines: buildLines(form.lines, { requireAtLeastOne: shouldRequireLine }),
|
|
||||||
};
|
};
|
||||||
|
if (shouldIncludeLines) {
|
||||||
|
body.lines = buildLines(form.lines, { requireAtLeastOne: shouldRequireLine });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let number = String(form.number ?? '').trim();
|
let number = String(form.number ?? '').trim();
|
||||||
if (!number) {
|
if (!number) {
|
||||||
@@ -481,8 +484,10 @@ export async function buildManifestBody(
|
|||||||
body = {
|
body = {
|
||||||
number,
|
number,
|
||||||
date,
|
date,
|
||||||
lines: buildLines(form.lines, { requireAtLeastOne: shouldRequireLine }),
|
|
||||||
};
|
};
|
||||||
|
if (shouldIncludeLines) {
|
||||||
|
body.lines = buildLines(form.lines, { requireAtLeastOne: shouldRequireLine });
|
||||||
|
}
|
||||||
if (useExternalNumber || form.externalNumber != null) {
|
if (useExternalNumber || form.externalNumber != null) {
|
||||||
body.externalNumber = externalNumber || null;
|
body.externalNumber = externalNumber || null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,51 @@ import {
|
|||||||
YELLOW_BG,
|
YELLOW_BG,
|
||||||
} from '../../colors';
|
} 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 {
|
class LieferungNeuPage extends PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@@ -150,6 +195,7 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
this.automat = getDeliveryEditorAutomat(this.props.docId);
|
this.automat = getDeliveryEditorAutomat(this.props.docId);
|
||||||
this.unsubscribe = this.automat.subscribe(this);
|
this.unsubscribe = this.automat.subscribe(this);
|
||||||
this.setState({ ...this.automat.state });
|
this.setState({ ...this.automat.state });
|
||||||
|
this._initialLines = null;
|
||||||
if (this.props.docId != null) {
|
if (this.props.docId != null) {
|
||||||
void this.loadEdit();
|
void this.loadEdit();
|
||||||
} else {
|
} else {
|
||||||
@@ -227,6 +273,7 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
if (doc.number != null) this.automat.actions.setNumber(doc.number);
|
if (doc.number != null) this.automat.actions.setNumber(doc.number);
|
||||||
if (doc.externalNumber != null) this.automat.actions.setExternalNumber(String(doc.externalNumber));
|
if (doc.externalNumber != null) this.automat.actions.setExternalNumber(String(doc.externalNumber));
|
||||||
this.automat.actions.setLineitems(lines);
|
this.automat.actions.setLineitems(lines);
|
||||||
|
this._initialLines = lines;
|
||||||
|
|
||||||
// Restore attachments with thumbnails
|
// Restore attachments with thumbnails
|
||||||
const apiFiles = doc.files ?? [];
|
const apiFiles = doc.files ?? [];
|
||||||
@@ -786,9 +833,24 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePdfDelete(attachment) {
|
async handlePdfDelete(attachment) {
|
||||||
if (!attachment?.id) return;
|
if (!attachment) return;
|
||||||
this.automat.actions.removeAttachment(attachment.id);
|
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) {
|
async ensureAttachmentFile(attachment) {
|
||||||
@@ -1031,6 +1093,9 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
if (this.state.saving) return;
|
if (this.state.saving) return;
|
||||||
|
|
||||||
const isCreate = docId == null;
|
const isCreate = docId == null;
|
||||||
|
const linesModified =
|
||||||
|
isCreate || !this._initialLines || !areLinesEqual(this.state.lines, this._initialLines);
|
||||||
|
|
||||||
let body;
|
let body;
|
||||||
try {
|
try {
|
||||||
body = await buildManifestBody(
|
body = await buildManifestBody(
|
||||||
@@ -1039,13 +1104,17 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
externalNumber: this.state.externalNumber ?? '',
|
externalNumber: this.state.externalNumber ?? '',
|
||||||
date: this.state.date ?? '',
|
date: this.state.date ?? '',
|
||||||
partyId: this.state.partyId,
|
partyId: this.state.partyId,
|
||||||
lines: this.state.lines,
|
lines: linesModified ? this.state.lines : undefined,
|
||||||
attachments: this.state.attachments,
|
attachments: this.state.attachments,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
kind: cfg.kind,
|
||||||
partyField: cfg.partyField,
|
partyField: cfg.partyField,
|
||||||
requireAtLeastOne: isCreate,
|
requireAtLeastOne: isCreate,
|
||||||
externalNumber: cfg.externalNumber,
|
externalNumber: cfg.externalNumber,
|
||||||
|
isUpdate: !isCreate,
|
||||||
|
mode: isCreate ? 'create' : 'edit',
|
||||||
|
omitLines: !linesModified,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -1083,6 +1152,7 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
if (doc.number != null) this.automat.actions.setNumber(doc.number);
|
if (doc.number != null) this.automat.actions.setNumber(doc.number);
|
||||||
if (doc.externalNumber != null) this.automat.actions.setExternalNumber(String(doc.externalNumber));
|
if (doc.externalNumber != null) this.automat.actions.setExternalNumber(String(doc.externalNumber));
|
||||||
this.automat.actions.setLineitems(lines);
|
this.automat.actions.setLineitems(lines);
|
||||||
|
this._initialLines = lines;
|
||||||
void this.reloadLedgerSummary();
|
void this.reloadLedgerSummary();
|
||||||
|
|
||||||
// Restore attachments with thumbnails
|
// Restore attachments with thumbnails
|
||||||
|
|||||||
Reference in New Issue
Block a user