/* Účtovníček — Účtová osnova: účty po triedach, hľadanie, úprava, nový účet */ const ACCOUNT_CLASSES = { '0': 'Dlhodobý majetok', '1': 'Zásoby', '2': 'Finančné účty', '3': 'Zúčtovacie vzťahy', '4': 'Kapitálové účty a dlhodobé záväzky', '5': 'Náklady', '6': 'Výnosy', '7': 'Uzávierkové účty', '8': 'Vnútroorganizačné účtovníctvo', '9': 'Podsúvahové účty', }; const ACCOUNT_KIND = { S: 'súvahový', V: 'výsledkový', Z: 'závierkový', N: 'podsúvahový' }; const ACCOUNT_SIDE = { A: 'aktívny', P: 'pasívny', D: 'výsledkový', C: 'výsledkový', N: '—' }; function PageAccounts({ go }) { const [search, setSearch] = React.useState(''); const [editing, setEditing] = React.useState(null); // null | {} (nový) | account const [onlyUsed, setOnlyUsed] = React.useState(false); const [used, setUsed] = React.useState(null); const [setToast, Toast] = useToast(); const accounts = uctStore.accounts.list(); React.useEffect(() => { if (!onlyUsed || used) return; uctStore.journal.ledger('', '').then(rows => setUsed(new Set(rows.map(r => r.account)))).catch(() => setUsed(new Set())); }, [onlyUsed]); const q = search.trim().toLowerCase(); const list = accounts.filter(a => (!q || a.code.includes(q) || a.name.toLowerCase().includes(q)) && (!onlyUsed || !used || used.has(a.code))); const groups = {}; list.forEach(a => { (groups[a.code[0]] = groups[a.code[0]] || []).push(a); }); return (

Účtová osnova

{accounts.length} účtov · šesťmiestne čísla ako v Profit365: syntetika 311 + analytika 001
setSearch(e.target.value)} />
{Object.keys(groups).sort().map(cls => (
Trieda {cls} · {ACCOUNT_CLASSES[cls] || ''}
{groups[cls].map(a => ( setEditing(a)} style={a.active === false ? {opacity:0.5} : undefined}> ))}
ÚčetNázovDruhZostatokStav
{a.code} {a.name}{a.source === 'profit365' && !a.code.endsWith('001') && vlastný} {ACCOUNT_KIND[a.kind] || a.kind} {ACCOUNT_SIDE[a.side] || a.side} {a.active === false ? vypnutý : aktívny}
))} {list.length === 0 &&

Nič sa nenašlo

Skús iné číslo alebo názov.
} {editing && setEditing(null)} onSaved={(a, msg) => { setEditing(null); setToast(msg); }} go={go} />} {Toast}
); } function AccountDrawer({ account, onClose, onSaved, go }) { const isNew = !account; const [a, setA] = React.useState(() => isNew ? { code: '', name: '', kind: '', side: '', active: true, note: '' } : { ...account }); const [error, setError] = React.useState(null); const [askConfirm, ConfirmUI] = useConfirm(); const set = (k) => (e) => setA({ ...a, [k]: e.target.value }); const save = async () => { setError(null); try { const saved = isNew ? await uctStore.accounts.create(a) : await uctStore.accounts.update(a); onSaved(saved, isNew ? `Účet ${saved.code} založený.` : 'Účet uložený.'); } catch (e) { setError(e.message); } }; const remove = async () => { if (!await askConfirm({ title: `Vymazať účet ${a.code}?`, message: 'Účet s pohybmi v denníku sa vymazať nedá - ten sa dá len vypnúť.', confirmLabel: 'Vymazať', danger: true })) return; try { await uctStore.accounts.remove(a.id); onSaved(a, 'Účet vymazaný.'); } catch (e) { setError(e.message); } }; return ( {!isNew && } {!isNew && } }> setError(null)} />
setA({ ...a, code: e.target.value.replace(/\D/g, '').slice(0, 6) })} placeholder="311004" />