This commit is contained in:
seb
2026-10-14 23:58:37 +02:00
parent e2a2d02cb4
commit ed7bb80006
5 changed files with 200 additions and 48 deletions

View File

@@ -17,7 +17,7 @@ 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 { netFromGross, grossFromNet, getArticleGross } from '../../utils/price';
import {
buildManifestBody,
restoreAttachmentsFromApi,
@@ -421,10 +421,11 @@ class ManifestForm extends PureComponent {
if (field === 'gross') {
const taxVal = parseNum(line.tax ?? line.taxrate) ?? 0;
const rebateVal = parseNum(line.rebate) ?? 0;
const grossNum = parseNum(value);
let updatedNet = line.net;
if (grossNum != null) {
const netNum = netFromGross(grossNum, taxVal);
const netNum = netFromGross(grossNum, taxVal, rebateVal);
if (netNum != null) {
updatedNet = String(netNum);
}
@@ -441,11 +442,12 @@ class ManifestForm extends PureComponent {
if (field === 'net' || field === 'netprice') {
const taxVal = parseNum(line.tax ?? line.taxrate) ?? 0;
const rebateVal = parseNum(line.rebate) ?? 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);
const grossNum = grossFromNet(netNum, taxVal, rebateVal);
updatedGross = grossNum != null ? String(grossNum) : '';
} else if (value === '') {
updatedGross = '';
}
@@ -460,11 +462,12 @@ class ManifestForm extends PureComponent {
if (field === 'tax' || field === 'taxrate') {
const taxNum = parseNum(value) ?? 0;
const rebateVal = parseNum(line.rebate) ?? 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);
const grossNum = grossFromNet(netNum, taxNum, rebateVal);
updatedGross = grossNum != null ? String(grossNum) : '';
}
return {
...line,
@@ -475,6 +478,22 @@ class ManifestForm extends PureComponent {
};
}
if (field === 'rebate') {
const rebateNum = parseNum(value) ?? 0;
const taxVal = parseNum(line.tax ?? line.taxrate) ?? 0;
const netNum = parseNum(line.net ?? line.netprice);
let updatedGross = line.gross;
if (netNum != null) {
const grossNum = grossFromNet(netNum, taxVal, rebateNum);
updatedGross = grossNum != null ? String(grossNum) : '';
}
return {
...line,
rebate: value,
gross: updatedGross,
};
}
return {
...line,
[field]: value,
@@ -508,13 +527,15 @@ class ManifestForm extends PureComponent {
: '';
const netNum = parseNum(netVal);
const taxNum = parseNum(taxVal);
const rebateNum = parseNum(l.rebate) ?? 0;
const artGross = getArticleGross(art, taxNum ?? 0);
let grossVal = '';
if (artGross != null) {
if (artGross != null && rebateNum === 0) {
grossVal = String(artGross);
} else if (netNum != null) {
const g = Math.round((netNum * (1 + (taxNum ?? 0) / 100) + Number.EPSILON) * 100) / 100;
grossVal = String(g);
grossVal = String(grossFromNet(netNum, taxNum ?? 0, rebateNum));
} else if (artGross != null) {
grossVal = String(Math.round((artGross * (1 - rebateNum / 100) + Number.EPSILON) * 100) / 100);
}
const normTax = selectCompanyTaxrate() != null ? String(selectCompanyTaxrate()) : '19';
const finalTax =
@@ -640,13 +661,15 @@ class ManifestForm extends PureComponent {
: normTax;
const netNum = parseNum(netVal);
const taxNum = parseNum(taxVal);
const rebateNum = parseNum(targetLine.rebate) ?? 0;
const artGross = getArticleGross(article, taxNum ?? 0);
let grossVal = '';
if (artGross != null) {
if (artGross != null && rebateNum === 0) {
grossVal = String(artGross);
} else if (netNum != null) {
const g = Math.round((netNum * (1 + (taxNum ?? 0) / 100) + Number.EPSILON) * 100) / 100;
grossVal = String(g);
grossVal = String(grossFromNet(netNum, taxNum ?? 0, rebateNum));
} else if (artGross != null) {
grossVal = String(Math.round((artGross * (1 - rebateNum / 100) + Number.EPSILON) * 100) / 100);
}
this.setState((prev) => ({