Created modular system for calculators, added soap and candles calculators, universal components, updated backend
74 lines
1.7 KiB
TypeScript
74 lines
1.7 KiB
TypeScript
// Функции расчета для калькулятора свечей
|
|
|
|
export function calculateCandleStep(
|
|
stepId: string,
|
|
values: Record<string, number>
|
|
): number {
|
|
const {
|
|
waxWeight = 0,
|
|
waxPrice = 0,
|
|
wickCount = 0,
|
|
wickPrice = 0,
|
|
fragrancePrice = 0,
|
|
fragranceWeight = 0,
|
|
dyePrice = 0,
|
|
dyeWeight = 0,
|
|
} = values;
|
|
|
|
switch (stepId) {
|
|
case 'wax':
|
|
if (waxWeight <= 0 || waxPrice <= 0) return 0;
|
|
return (waxWeight / 1000) * waxPrice;
|
|
|
|
case 'wick':
|
|
if (wickCount <= 0 || wickPrice <= 0) return 0;
|
|
return wickCount * wickPrice;
|
|
|
|
case 'fragrance':
|
|
if (waxWeight <= 0 || fragranceWeight <= 0 || fragrancePrice <= 0) return 0;
|
|
// 10% отдушки от веса воска
|
|
return ((waxWeight * 0.10) / fragranceWeight) * fragrancePrice;
|
|
|
|
case 'dye':
|
|
if (waxWeight <= 0 || dyeWeight <= 0 || dyePrice <= 0) return 0;
|
|
// 1% красителя от веса воска
|
|
return ((waxWeight * 0.01) / dyeWeight) * dyePrice;
|
|
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
export function calculateCandleSubtotal(
|
|
subtotalId: string,
|
|
values: Record<string, number>,
|
|
steps: Record<string, number>
|
|
): number {
|
|
switch (subtotalId) {
|
|
case 'operational':
|
|
const subtotal =
|
|
(steps.wax || 0) +
|
|
(steps.wick || 0) +
|
|
(steps.fragrance || 0) +
|
|
(steps.dye || 0);
|
|
return subtotal * 0.05;
|
|
|
|
case 'total':
|
|
return (
|
|
(steps.wax || 0) +
|
|
(steps.wick || 0) +
|
|
(steps.fragrance || 0) +
|
|
(steps.dye || 0) +
|
|
(steps.operational || 0)
|
|
);
|
|
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
export function round(val: number): number {
|
|
return Math.round(val * 10) / 10;
|
|
}
|
|
|