u
This commit is contained in:
@@ -16,6 +16,7 @@ import ArticleSearchDialog from './ArticleSearchDialog';
|
||||
import artikelAutomat, { getArticle } from '../../automats/artikelAutomat';
|
||||
import entityAutomat from '../../automats/entityAutomat';
|
||||
import supplierAutomat from '../../automats/supplierAutomat';
|
||||
import companyAutomat, { selectCompanyTaxrate } from '../../automats/companyAutomat';
|
||||
import { netFromGross, getArticleGross } from '../../utils/price';
|
||||
import {
|
||||
buildManifestBody,
|
||||
@@ -95,6 +96,35 @@ class ManifestForm extends PureComponent {
|
||||
}));
|
||||
}
|
||||
|
||||
if (companyAutomat.state.status === 'idle') {
|
||||
void companyAutomat.actions.load();
|
||||
}
|
||||
this.unsubCompany = companyAutomat.subscribe(this, (state) => {
|
||||
const taxrate = state.current?.taxrate;
|
||||
if (taxrate != null) {
|
||||
this.setState((prev) => {
|
||||
if (
|
||||
prev.lines.length === 1 &&
|
||||
!prev.lines[0].sku &&
|
||||
!prev.lines[0].name &&
|
||||
!prev.lines[0].net &&
|
||||
prev.lines[0].tax !== String(taxrate)
|
||||
) {
|
||||
return {
|
||||
lines: [
|
||||
{
|
||||
...prev.lines[0],
|
||||
tax: String(taxrate),
|
||||
taxrate: String(taxrate),
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (this.props.mode === 'edit') void this.loadEdit();
|
||||
else void this.loadPartiesOnly();
|
||||
}
|
||||
@@ -111,6 +141,7 @@ class ManifestForm extends PureComponent {
|
||||
componentWillUnmount() {
|
||||
this._cancelled = true;
|
||||
this.unsubParties?.();
|
||||
this.unsubCompany?.();
|
||||
if (this._parseAbortController) {
|
||||
this._parseAbortController.abort();
|
||||
this._parseAbortController = null;
|
||||
@@ -323,12 +354,21 @@ class ManifestForm extends PureComponent {
|
||||
const g = Math.round((netNum * (1 + (taxNum ?? 0) / 100) + Number.EPSILON) * 100) / 100;
|
||||
grossVal = String(g);
|
||||
}
|
||||
const normTax = selectCompanyTaxrate() != null ? String(selectCompanyTaxrate()) : '19';
|
||||
const finalTax =
|
||||
art.taxrate != null
|
||||
? String(art.taxrate)
|
||||
: art.tax != null
|
||||
? String(art.tax)
|
||||
: l.tax || normTax;
|
||||
return {
|
||||
...l,
|
||||
amount: l.amount || '1',
|
||||
sku: art.sku || l.sku,
|
||||
name: art.name || l.name || '',
|
||||
tax: l.tax || taxVal,
|
||||
taxrate: l.taxrate || taxVal,
|
||||
tax: finalTax,
|
||||
taxrate: finalTax,
|
||||
rebate: l.rebate || '0',
|
||||
net: l.net || netVal,
|
||||
netprice: l.netprice || netVal,
|
||||
gross: l.gross || grossVal,
|
||||
@@ -348,6 +388,7 @@ class ManifestForm extends PureComponent {
|
||||
|
||||
handleAddArticleLine(article) {
|
||||
if (!article) return;
|
||||
const normTax = selectCompanyTaxrate() != null ? String(selectCompanyTaxrate()) : '19';
|
||||
const netVal =
|
||||
article.price != null
|
||||
? String(article.price)
|
||||
@@ -361,7 +402,7 @@ class ManifestForm extends PureComponent {
|
||||
? String(article.taxrate)
|
||||
: article.tax != null
|
||||
? String(article.tax)
|
||||
: '';
|
||||
: normTax;
|
||||
const netNum = parseNum(netVal);
|
||||
const taxNum = parseNum(taxVal);
|
||||
const artGross = getArticleGross(article, taxNum ?? 0);
|
||||
@@ -383,7 +424,7 @@ class ManifestForm extends PureComponent {
|
||||
net: netVal,
|
||||
netprice: netVal,
|
||||
gross: grossVal,
|
||||
rebate: '',
|
||||
rebate: '0',
|
||||
pu: '1',
|
||||
unit: article.unit || 'Stück',
|
||||
};
|
||||
@@ -420,6 +461,7 @@ class ManifestForm extends PureComponent {
|
||||
});
|
||||
return;
|
||||
}
|
||||
const normTax = selectCompanyTaxrate() != null ? String(selectCompanyTaxrate()) : '19';
|
||||
const netVal =
|
||||
article.price != null
|
||||
? String(article.price)
|
||||
@@ -433,7 +475,7 @@ class ManifestForm extends PureComponent {
|
||||
? String(article.taxrate)
|
||||
: article.tax != null
|
||||
? String(article.tax)
|
||||
: '';
|
||||
: normTax;
|
||||
const netNum = parseNum(netVal);
|
||||
const taxNum = parseNum(taxVal);
|
||||
const artGross = getArticleGross(article, taxNum ?? 0);
|
||||
@@ -450,10 +492,12 @@ class ManifestForm extends PureComponent {
|
||||
if (l.key !== targetLine.key) return l;
|
||||
return {
|
||||
...l,
|
||||
amount: l.amount || '1',
|
||||
sku: article.sku || l.sku,
|
||||
name: article.name || l.name,
|
||||
tax: taxVal || l.tax,
|
||||
taxrate: taxVal || l.taxrate,
|
||||
tax: taxVal || l.tax || normTax,
|
||||
taxrate: taxVal || l.taxrate || normTax,
|
||||
rebate: l.rebate || '0',
|
||||
net: netVal || l.net,
|
||||
netprice: netVal || l.netprice,
|
||||
gross: grossVal || l.gross,
|
||||
|
||||
Reference in New Issue
Block a user