u
This commit is contained in:
@@ -14,6 +14,7 @@ import ManifestLines from './ManifestLines';
|
||||
import ManifestPdfDialog from './ManifestPdfDialog';
|
||||
import ArticleSearchDialog from './ArticleSearchDialog';
|
||||
import artikelAutomat, { getArticle } from '../../automats/artikelAutomat';
|
||||
import { netFromGross, getArticleGross } from '../../utils/price';
|
||||
import {
|
||||
buildManifestBody,
|
||||
restoreAttachmentsFromApi,
|
||||
@@ -23,6 +24,7 @@ import {
|
||||
loadParties,
|
||||
manifestConfig,
|
||||
apiFor,
|
||||
parseNum,
|
||||
} from './manifestConfig';
|
||||
|
||||
class ManifestForm extends PureComponent {
|
||||
@@ -195,18 +197,70 @@ class ManifestForm extends PureComponent {
|
||||
|
||||
handleLineChange(key, field, value) {
|
||||
this.setState((prev) => ({
|
||||
lines: prev.lines.map((line) =>
|
||||
line.key === key
|
||||
? {
|
||||
...line,
|
||||
[field]: value,
|
||||
...(field === 'net' ? { netprice: value } : {}),
|
||||
...(field === 'netprice' ? { net: value } : {}),
|
||||
...(field === 'tax' ? { taxrate: value } : {}),
|
||||
...(field === 'taxrate' ? { tax: value } : {}),
|
||||
lines: prev.lines.map((line) => {
|
||||
if (line.key !== key) return line;
|
||||
|
||||
if (field === 'gross') {
|
||||
const taxVal = parseNum(line.tax ?? line.taxrate) ?? 0;
|
||||
const grossNum = parseNum(value);
|
||||
let updatedNet = line.net;
|
||||
if (grossNum != null) {
|
||||
const netNum = netFromGross(grossNum, taxVal);
|
||||
if (netNum != null) {
|
||||
updatedNet = String(netNum);
|
||||
}
|
||||
: line,
|
||||
),
|
||||
} else if (value === '') {
|
||||
updatedNet = '';
|
||||
}
|
||||
return {
|
||||
...line,
|
||||
gross: value,
|
||||
net: updatedNet,
|
||||
netprice: updatedNet,
|
||||
};
|
||||
}
|
||||
|
||||
if (field === 'net' || field === 'netprice') {
|
||||
const taxVal = parseNum(line.tax ?? line.taxrate) ?? 0;
|
||||
const netNum = parseNum(value);
|
||||
let updatedGross = line.gross;
|
||||
if (netNum != null) {
|
||||
const grossNum = Math.round((netNum * (1 + taxVal / 100) + Number.EPSILON) * 100) / 100;
|
||||
updatedGross = String(grossNum);
|
||||
} else if (value === '') {
|
||||
updatedGross = '';
|
||||
}
|
||||
return {
|
||||
...line,
|
||||
[field]: value,
|
||||
net: value,
|
||||
netprice: value,
|
||||
gross: updatedGross,
|
||||
};
|
||||
}
|
||||
|
||||
if (field === 'tax' || field === 'taxrate') {
|
||||
const taxNum = parseNum(value) ?? 0;
|
||||
const netNum = parseNum(line.net ?? line.netprice);
|
||||
let updatedGross = line.gross;
|
||||
if (netNum != null) {
|
||||
const grossNum = Math.round((netNum * (1 + taxNum / 100) + Number.EPSILON) * 100) / 100;
|
||||
updatedGross = String(grossNum);
|
||||
}
|
||||
return {
|
||||
...line,
|
||||
[field]: value,
|
||||
tax: value,
|
||||
taxrate: value,
|
||||
gross: updatedGross,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...line,
|
||||
[field]: value,
|
||||
};
|
||||
}),
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -233,6 +287,16 @@ class ManifestForm extends PureComponent {
|
||||
: art.tax != null
|
||||
? String(art.tax)
|
||||
: '';
|
||||
const netNum = parseNum(netVal);
|
||||
const taxNum = parseNum(taxVal);
|
||||
const artGross = getArticleGross(art, 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);
|
||||
}
|
||||
return {
|
||||
...l,
|
||||
sku: art.sku || l.sku,
|
||||
@@ -241,6 +305,7 @@ class ManifestForm extends PureComponent {
|
||||
taxrate: l.taxrate || taxVal,
|
||||
net: l.net || netVal,
|
||||
netprice: l.netprice || netVal,
|
||||
gross: l.gross || grossVal,
|
||||
unit: art.unit || l.unit || 'Stück',
|
||||
};
|
||||
}),
|
||||
@@ -271,6 +336,16 @@ class ManifestForm extends PureComponent {
|
||||
: article.tax != null
|
||||
? String(article.tax)
|
||||
: '';
|
||||
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 newLine = {
|
||||
key: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
||||
@@ -281,6 +356,7 @@ class ManifestForm extends PureComponent {
|
||||
taxrate: taxVal,
|
||||
net: netVal,
|
||||
netprice: netVal,
|
||||
gross: grossVal,
|
||||
rebate: '',
|
||||
pu: '1',
|
||||
unit: article.unit || 'Stück',
|
||||
@@ -332,6 +408,16 @@ class ManifestForm extends PureComponent {
|
||||
: article.tax != null
|
||||
? String(article.tax)
|
||||
: '';
|
||||
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);
|
||||
}
|
||||
|
||||
this.setState((prev) => ({
|
||||
lines: prev.lines.map((l) => {
|
||||
@@ -344,6 +430,7 @@ class ManifestForm extends PureComponent {
|
||||
taxrate: taxVal || l.taxrate,
|
||||
net: netVal || l.net,
|
||||
netprice: netVal || l.netprice,
|
||||
gross: grossVal || l.gross,
|
||||
unit: article.unit || l.unit || 'Stück',
|
||||
};
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user