80 lines
2.9 KiB
JavaScript
80 lines
2.9 KiB
JavaScript
const KEYS = {
|
|
data: "wbjw_data",
|
|
evRows: "ev_voortgang_rows",
|
|
users: "wbjw_users",
|
|
exitplan: "exitplan_data",
|
|
// Weergavevoorkeuren: per browser, net als de kolombreedtes. Ze staan bewust
|
|
// los van de financiële data, dus ze gaan niet mee in de backup-ZIP.
|
|
thema: "vibefinance_thema",
|
|
darkMode: "vibefinance_darkmode",
|
|
};
|
|
|
|
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;
|
|
}
|