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

@@ -45,12 +45,26 @@ export function parsePriceInput(value) {
}
/** Convert gross (brutto) → net for PUT /prices. Rounded to 4 decimal places. */
export function netFromGross(gross, taxRate) {
export function netFromGross(gross, taxRate, rebate = 0) {
if (gross == null || taxRate == null) return null;
if (!Number.isFinite(gross) || !Number.isFinite(taxRate) || taxRate < 0) return null;
const factor = 1 + taxRate / 100;
if (factor <= 0) return null;
return Math.round((gross / factor) * 10000) / 10000;
const taxFactor = 1 + taxRate / 100;
if (taxFactor <= 0) return null;
const r = Number.isFinite(rebate) ? rebate : 0;
const rebateFactor = 1 - r / 100;
if (rebateFactor <= 0) return 0;
return Math.round((gross / (taxFactor * rebateFactor)) * 10000) / 10000;
}
/** Convert net → gross taking taxRate and optional rebate into account. Rounded to 2 decimal places. */
export function grossFromNet(net, taxRate = 0, rebate = 0) {
if (net == null) return null;
const netNum = Number(net);
if (!Number.isFinite(netNum)) return null;
const taxNum = Number(taxRate) || 0;
const rebateNum = Number(rebate) || 0;
const factor = (1 + taxNum / 100) * (1 - rebateNum / 100);
return Math.round((netNum * factor + Number.EPSILON) * 100) / 100;
}
/**