u
This commit is contained in:
@@ -127,6 +127,24 @@ export function formatPrice(amount) {
|
|||||||
return CURRENCY_FORMATTER.format(Number(amount));
|
return CURRENCY_FORMATTER.format(Number(amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BASEPRICE_FORMATTER = new Intl.NumberFormat('de-DE', {
|
||||||
|
minimumFractionDigits: 2,
|
||||||
|
maximumFractionDigits: 2,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** Formats the price per base unit, e.g. "€ 4,05 / L". Empty when unit data or price is missing. */
|
||||||
|
export function formatBasePrice(net, taxRate, article) {
|
||||||
|
const unit = article?.unit;
|
||||||
|
const unitamount = Number(article?.unitamount);
|
||||||
|
const factor = Number(unit?.basesifactor);
|
||||||
|
if (net == null || !unit || !(unitamount > 0) || !(factor > 0)) return '';
|
||||||
|
const baseAmount = unitamount * factor;
|
||||||
|
const perBase = (net * (1 + taxRate / 100)) / baseAmount;
|
||||||
|
const label = factor === 1 ? (unit.symbol || unit.basesi) : unit.basesi;
|
||||||
|
if (!label) return '';
|
||||||
|
return `€ ${BASEPRICE_FORMATTER.format(perBase)} / ${label}`;
|
||||||
|
}
|
||||||
|
|
||||||
export function interpolateString(str, article) {
|
export function interpolateString(str, article) {
|
||||||
if (typeof str !== 'string') return str;
|
if (typeof str !== 'string') return str;
|
||||||
const basePrice = Array.isArray(article?.prices) && article.prices.length > 0
|
const basePrice = Array.isArray(article?.prices) && article.prices.length > 0
|
||||||
@@ -144,6 +162,7 @@ export function interpolateString(str, article) {
|
|||||||
|
|
||||||
return str
|
return str
|
||||||
.replace(/\{\{name\}\}/gi, article?.name || '')
|
.replace(/\{\{name\}\}/gi, article?.name || '')
|
||||||
|
.replace(/\{\{baseprice\}\}/gi, formatBasePrice(net, taxRate, article))
|
||||||
.replace(/\{\{price\}\}/gi, formatPrice(gross));
|
.replace(/\{\{price\}\}/gi, formatPrice(gross));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user