first commit
This commit is contained in:
33
frontend/src/utils/format.js
Normal file
33
frontend/src/utils/format.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/** Euro formatter (nl-NL, geen decimalen) */
|
||||
export const fmt = (n) =>
|
||||
new Intl.NumberFormat("nl-NL", {
|
||||
style: "currency", currency: "EUR", maximumFractionDigits: 0,
|
||||
}).format(n || 0);
|
||||
|
||||
/** Percentage formatter */
|
||||
export const pct = (n, d = 1) => `${((n || 0) * 100).toFixed(d)}%`;
|
||||
|
||||
/** ISO datum (YYYY-MM-DD) → Nederlandse notatie (DD-MM-YYYY) */
|
||||
export const fmtDatum = (s) => {
|
||||
if (!s) return s;
|
||||
const [y, m, d] = s.split("-");
|
||||
return `${d}-${m}-${y}`;
|
||||
};
|
||||
|
||||
/** Crypto-bedrag formatter (4 decimalen standaard) */
|
||||
export const fmtCrypto = (n, d = 4) => (parseFloat(n) || 0).toFixed(d);
|
||||
|
||||
/**
|
||||
* Bedrag in USD of EUR opmaken afhankelijk van geselecteerde valuta.
|
||||
* @param {number} amount
|
||||
* @param {"USD"|"EUR"} currency
|
||||
* @param {number} usdEurRate
|
||||
*/
|
||||
export function fmtMoney(amount, currency = "EUR", usdEurRate = 0.92) {
|
||||
const v = currency === "EUR" ? amount * usdEurRate : amount;
|
||||
return new Intl.NumberFormat("nl-NL", {
|
||||
style: "currency",
|
||||
currency,
|
||||
maximumFractionDigits: 0,
|
||||
}).format(v || 0);
|
||||
}
|
||||
2
frontend/src/utils/index.js
Normal file
2
frontend/src/utils/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./format.js";
|
||||
export * from "./storage.js";
|
||||
75
frontend/src/utils/storage.js
Normal file
75
frontend/src/utils/storage.js
Normal file
@@ -0,0 +1,75 @@
|
||||
const KEYS = {
|
||||
data: "wbjw_data",
|
||||
evRows: "ev_voortgang_rows",
|
||||
users: "wbjw_users",
|
||||
exitplan: "exitplan_data",
|
||||
};
|
||||
|
||||
export function loadFromStorage(key) {
|
||||
try {
|
||||
const raw = localStorage.getItem(KEYS[key] ?? key);
|
||||
return raw ? JSON.parse(raw) : null;
|
||||
} catch { return null; }
|
||||
}
|
||||
|
||||
export function saveToStorage(key, value) {
|
||||
try { localStorage.setItem(KEYS[key] ?? key, JSON.stringify(value)); } catch {}
|
||||
}
|
||||
|
||||
export function clearStorage(key) {
|
||||
try { localStorage.removeItem(KEYS[key] ?? key); } catch {}
|
||||
}
|
||||
|
||||
/** Exporteer alle data als JSON-backup blob */
|
||||
export function buildBackup() {
|
||||
return {
|
||||
wbjw_data: localStorage.getItem(KEYS.data),
|
||||
ev_voortgang_rows: localStorage.getItem(KEYS.evRows),
|
||||
wbjw_users: localStorage.getItem(KEYS.users),
|
||||
exitplan_data: localStorage.getItem(KEYS.exitplan),
|
||||
datum: new Date().toISOString(),
|
||||
versie: "2.0",
|
||||
};
|
||||
}
|
||||
|
||||
/** Herstel een backup-object naar localStorage */
|
||||
export function restoreBackup(backup) {
|
||||
if (backup.wbjw_data) localStorage.setItem(KEYS.data, backup.wbjw_data);
|
||||
if (backup.ev_voortgang_rows) localStorage.setItem(KEYS.evRows, backup.ev_voortgang_rows);
|
||||
if (backup.wbjw_users) localStorage.setItem(KEYS.users, backup.wbjw_users);
|
||||
if (backup.exitplan_data) localStorage.setItem(KEYS.exitplan, backup.exitplan_data);
|
||||
}
|
||||
|
||||
/** Migreer oud schuld-formaat naar blokken-formaat */
|
||||
export function migrateData(parsed) {
|
||||
if (parsed.schuld && !parsed.schuld.blokken) {
|
||||
const h = parsed.schuld.hypotheek || {};
|
||||
const b = parsed.schuld.belastingdienst || {};
|
||||
const ex = parsed.schuld.extra || [];
|
||||
parsed.schuld.blokken = [
|
||||
{
|
||||
id: "s1", naam: "Hypotheek", color: "#ef4444",
|
||||
items: Object.entries({
|
||||
deel1: "Leningdeel 1", deel2: "Leningdeel 2",
|
||||
deel3: "Leningdeel 3", deel4: "Leningdeel 4",
|
||||
deel5: "Sub-categorie 5",
|
||||
}).map(([k, n], i) => ({ id: `s1i${i + 1}`, naam: n, waarde: h[k] || 0 })),
|
||||
},
|
||||
{
|
||||
id: "s2", naam: "Belastingdienst", color: "#f97316",
|
||||
items: Object.entries({
|
||||
sub1: "Kinderopvangtoeslag", sub2: "Sub-categorie 2",
|
||||
sub3: "Sub-categorie 3", sub4: "Sub-categorie 4",
|
||||
sub5: "Sub-categorie 5",
|
||||
}).map(([k, n], i) => ({ id: `s2i${i + 1}`, naam: n, waarde: b[k] || 0 })),
|
||||
},
|
||||
...ex.map((cat, ci) => ({ ...cat, id: `s${ci + 3}` })),
|
||||
];
|
||||
delete parsed.schuld.hypotheek;
|
||||
delete parsed.schuld.belastingdienst;
|
||||
delete parsed.schuld.extra;
|
||||
}
|
||||
if (!parsed.schuld.schuldHistory) parsed.schuld.schuldHistory = [];
|
||||
if (!parsed.schuld.initieleSchuld) parsed.schuld.initieleSchuld = 303000;
|
||||
return parsed;
|
||||
}
|
||||
Reference in New Issue
Block a user