From 9c5a8fd2c4d988a9a46463da8e1aa2621e3ca496 Mon Sep 17 00:00:00 2001 From: Katja Lutz Date: Thu, 30 Jun 2022 11:30:01 +0200 Subject: [PATCH] feat: implemented AgileCalculator component --- src/components/AgileCalculator.tsx | 150 +++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/components/AgileCalculator.tsx diff --git a/src/components/AgileCalculator.tsx b/src/components/AgileCalculator.tsx new file mode 100644 index 0000000..2573e49 --- /dev/null +++ b/src/components/AgileCalculator.tsx @@ -0,0 +1,150 @@ +import Big from "big.js"; +import { Component, createMemo } from "solid-js"; +import { createStore } from "solid-js/store"; +import { TextInput } from "./Form"; +import { calculateAgileQuantity } from "./Positions"; +import { formatAmount } from "./SwissInvoice"; + +const AgileCalculator: Component = () => { + const [agileCalculator, setAgileCalculator] = createStore({ + minPoints: 0, + maxPoints: 10, + risk: 70, + singlePrice: 10.0, + hoursPerPoint: 1, + }); + const calculatorQuantity = createMemo(() => + calculateAgileQuantity( + agileCalculator.hoursPerPoint, + new Big(agileCalculator.risk).div(100).toNumber(), + agileCalculator.minPoints, + agileCalculator.maxPoints + ) + ); + + return ( +
+

Rechnungsbeispiel

+ + !Number.isNaN(e.currentTarget.valueAsNumber) && + setAgileCalculator("risk", e.currentTarget.valueAsNumber) + } + /> + + !Number.isNaN(e.currentTarget.valueAsNumber) && + setAgileCalculator("hoursPerPoint", e.currentTarget.valueAsNumber) + } + /> + + !Number.isNaN(e.currentTarget.valueAsNumber) && + setAgileCalculator("minPoints", e.currentTarget.valueAsNumber) + } + /> + + !Number.isNaN(e.currentTarget.valueAsNumber) && + setAgileCalculator("maxPoints", e.currentTarget.valueAsNumber) + } + /> + + !Number.isNaN(e.currentTarget.valueAsNumber) && + setAgileCalculator("singlePrice", e.currentTarget.valueAsNumber) + } + /> +
+
+ {"("} + + {new Big(-100).plus(agileCalculator.risk).abs().toNumber()}% + {" "} + *{" "} + + {agileCalculator.minPoints} SP + + {")"} + {"("} + + {agileCalculator.risk}% + {" "} + *{" "} + + {agileCalculator.maxPoints > agileCalculator.minPoints + ? agileCalculator.maxPoints + : agileCalculator.minPoints}{" "} + SP + + {")"} = +
+
+
+ Gewichtete Story Points: + {new Big(calculatorQuantity()) + .div(agileCalculator.hoursPerPoint) + .toNumber()}{" "} + SP +
+
+
+ + {new Big(calculatorQuantity()) + .div(agileCalculator.hoursPerPoint) + .toNumber()}{" "} + SP + {" "} + *{" "} + + {agileCalculator.hoursPerPoint} h + {" "} + *{" "} + + {agileCalculator.singlePrice} CHF + {" "} + = +
+
+
+ Gesamtpreis: + {formatAmount( + calculatorQuantity() * agileCalculator.singlePrice + )}{" "} + CHF +
+
+
+
+ ); +}; + +export default AgileCalculator;