);
}
/**
* What ages out, year by year, for planning what to replace and roughly what it will cost. The date is the end of support where there is one (the
* warranty's end stands in where there is not, and says so); the cost is the replacement cost, or what it was bought for.
*/
export default function InventoryLifecycle() {
const [years, setYears] = useState(5);
const [report, setReport] = useState(null);
const [error, setError] = useState(null);
useEffect(() => {
setReport(null);
api.inventory
.lifecycle(years)
.then((r) => {
setReport(r);
setError(null);
})
.catch((err) => setError(readableError(err)));
}, [years]);
const currency = report?.currency ?? "";
const dated = report ? report.past.length + report.later.length + report.years.reduce((n, y) => n + y.items.length, 0) : 0;
function exportCsv() {
if (!report) return;
const rows: (string | number)[][] = [];
const add = (group: string, i: LifecycleItem) => rows.push([group, i.name, kindLabel(i.kind), i.endsOn, i.basis === "support" ? "end of support" : "warranty", i.cost ?? "", i.costBasis ?? ""]);
report.past.forEach((i) => add("Already past", i));
for (const y of report.years) y.items.forEach((i) => add(String(y.year), i));
report.later.forEach((i) => add("Later", i));
report.undated.forEach((u) => rows.push(["No date", u.name, kindLabel(u.kind), "", "", "", ""]));
downloadCsv("lifecycle.csv", ["When", "Hardware", "Kind", "Ages out", "Because", "Replacement cost", "Cost is"], rows);
}
return (
<>
Lifecycle
Back to the inventory
What ages out, year by year, and roughly what replacing it will cost. Give a piece of hardware an end of support and a replacement cost in the inventory; until it has
an end of support, the end of its warranty stands in, and until it has a replacement cost, what it was bought for.