Files
wanderbooks/crates/ledger-gui/src/nav.rs
T
swaitsandClaude Opus 5.5 cd085108c1 Fixed assets, fully featured: tags, serials, acquisition links, label sheets, the fixed asset register, and an Assets section in the viewer; fix a flaky verify
- core: asset tags (generated PREFIX-0001 or the human's own; unique ignoring case; never reused by another asset) and serial numbers (rules.md B-24); a journaled link from an asset to the entry that acquired it (posted, unreversed, debiting the cost account); fixed_asset_register(as_of), reconciled to the GL (unposted depreciation, unregistered cost)
- store: asset.tagged, asset.serial_set, asset.acquisition_linked journaled, replayed, projected (schema v9); differs_from now also compares control roles and tag history
- config: [books] asset_tag_prefix, default the company's initials without legal-form words
- import: Avery 5160/8160 label sheets with QR codes (geometry vendored from Avery, docs/spec/sources/avery-5160.md); the register as XLSX and PDF
- mcp: register_asset tags (and links) automatically; books.label_asset, books.asset_labels; asset tools take a tag; books.show asset / assets page / register report; export fixed_asset_register (json, csv, xlsx, pdf) and in the CPA package
- viewer: Assets page (register, reconciliation), asset page (identity, schedule posted vs not, entries, documents), Fixed asset register report, global search by tag/serial/description, journal text, needs-attention items
- fix: verify compared snapshot amounts as strings; a zero total summed in hash-map order could print "0" or "0.00", so agreeing books failed verify at random. Now by value (regression test)
- tests: spec-blind suites for tags, register, prefix, store, MCP; label and register PDF/XLSX tests; viewer tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GWVo7x3UHw5kwCUaWxiejX
2026-10-15 12:18:00 -06:00

220 lines
6.2 KiB
Rust

//! Where you are and how you got there: a browser-style history.
use ledger_core::{AccountId, AssetId, EntryId};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ReportKind {
ProfitAndLoss,
BalanceSheet,
CashFlow,
TrialBalance,
GeneralLedger,
MembersEquity,
TaxSummary,
ArAging,
ApAging,
Vendor1099,
FixedAssetRegister,
}
impl ReportKind {
pub const ALL: [ReportKind; 11] = [
ReportKind::ProfitAndLoss,
ReportKind::BalanceSheet,
ReportKind::CashFlow,
ReportKind::MembersEquity,
ReportKind::TrialBalance,
ReportKind::GeneralLedger,
ReportKind::FixedAssetRegister,
ReportKind::TaxSummary,
ReportKind::Vendor1099,
ReportKind::ArAging,
ReportKind::ApAging,
];
pub fn title(self) -> &'static str {
match self {
ReportKind::ProfitAndLoss => "Profit and loss",
ReportKind::BalanceSheet => "Balance sheet",
ReportKind::CashFlow => "Cash flow",
ReportKind::TrialBalance => "Trial balance",
ReportKind::GeneralLedger => "General ledger",
ReportKind::MembersEquity => "Owners' equity",
ReportKind::TaxSummary => "Tax summary",
ReportKind::ArAging => "Receivables aging",
ReportKind::ApAging => "Payables aging",
ReportKind::Vendor1099 => "1099 worksheet",
ReportKind::FixedAssetRegister => "Fixed asset register",
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum Route {
Overview,
Cash,
Profit,
Transactions,
Entry(EntryId),
Reports(ReportKind),
Accounts,
Account(AccountId),
/// The fixed asset register.
Assets,
/// One fixed asset.
Asset(AssetId),
Documents,
Document(u64),
Company,
Journal,
JournalEvent(u64),
}
impl Route {
/// The sidebar section this route belongs to.
pub fn section(&self) -> Section {
match self {
Route::Overview => Section::Overview,
Route::Cash => Section::Cash,
Route::Profit => Section::Profit,
Route::Transactions | Route::Entry(_) => Section::Transactions,
Route::Reports(_) => Section::Reports,
Route::Accounts | Route::Account(_) => Section::Accounts,
Route::Assets | Route::Asset(_) => Section::Assets,
Route::Documents | Route::Document(_) => Section::Documents,
Route::Company => Section::Company,
Route::Journal | Route::JournalEvent(_) => Section::Journal,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Section {
Overview,
Cash,
Profit,
Transactions,
Reports,
Accounts,
Assets,
Documents,
Company,
Journal,
}
impl Section {
pub const ALL: [Section; 10] = [
Section::Overview,
Section::Cash,
Section::Profit,
Section::Transactions,
Section::Reports,
Section::Accounts,
Section::Assets,
Section::Documents,
Section::Company,
Section::Journal,
];
pub fn title(self) -> &'static str {
match self {
Section::Overview => "Overview",
Section::Cash => "Cash",
Section::Profit => "Profit",
Section::Transactions => "Transactions",
Section::Reports => "Reports",
Section::Accounts => "Accounts",
Section::Assets => "Assets",
Section::Documents => "Documents",
Section::Company => "Company",
Section::Journal => "Journal",
}
}
pub fn icon(self) -> &'static str {
use egui_phosphor::regular as i;
match self {
Section::Overview => i::SQUARES_FOUR,
Section::Cash => i::BANK,
Section::Profit => i::TREND_UP,
Section::Transactions => i::LIST_BULLETS,
Section::Reports => i::FILE_TEXT,
Section::Accounts => i::TREE_STRUCTURE,
Section::Assets => i::PACKAGE,
Section::Documents => i::FILES,
Section::Company => i::BUILDINGS,
Section::Journal => i::SCROLL,
}
}
pub fn home(self) -> Route {
match self {
Section::Overview => Route::Overview,
Section::Cash => Route::Cash,
Section::Profit => Route::Profit,
Section::Transactions => Route::Transactions,
Section::Reports => Route::Reports(ReportKind::ProfitAndLoss),
Section::Accounts => Route::Accounts,
Section::Assets => Route::Assets,
Section::Documents => Route::Documents,
Section::Company => Route::Company,
Section::Journal => Route::Journal,
}
}
}
/// ```text
/// GOAL: back and forward behave like a web browser's.
/// SOURCE: CONVENTION (browser session history: going somewhere new
/// drops the forward list).
/// INVARIANTS:
/// 1. go(r) to a different route makes it current, pushes the old one
/// on back, and clears forward; go to the current route does nothing.
/// 2. back() then forward() returns to the same route (and vice versa);
/// either does nothing when its list is empty.
/// 3. can_back/can_forward say whether back/forward would move.
/// ```
/// Back/forward history.
pub struct Nav {
back: Vec<Route>,
forward: Vec<Route>,
pub current: Route,
}
impl Nav {
pub fn new(start: Route) -> Self {
Self {
back: Vec::new(),
forward: Vec::new(),
current: start,
}
}
pub fn go(&mut self, to: Route) {
if to != self.current {
self.back.push(std::mem::replace(&mut self.current, to));
self.forward.clear();
}
}
pub fn can_back(&self) -> bool {
!self.back.is_empty()
}
pub fn can_forward(&self) -> bool {
!self.forward.is_empty()
}
pub fn back(&mut self) {
if let Some(r) = self.back.pop() {
self.forward.push(std::mem::replace(&mut self.current, r));
}
}
pub fn forward(&mut self) {
if let Some(r) = self.forward.pop() {
self.back.push(std::mem::replace(&mut self.current, r));
}
}
}