|
@@ -1,17 +1,22 @@
|
|
|
use std::collections::BTreeMap;
|
|
|
|
|
|
+use itertools::Itertools;
|
|
|
+
|
|
|
use crate::data::{SourceFile, Spanned, Span, Root};
|
|
|
|
|
|
use super::{Balance, LedgerEntry};
|
|
|
|
|
|
-fn print_ledger_entry(root: &Root, entry: &LedgerEntry) {
|
|
|
+fn print_ledger_entry(root: &Root, entry: &LedgerEntry, padding: usize) {
|
|
|
println!("{}-{:02}-{:02}: {}", entry.datestamp.0, entry.datestamp.1, entry.datestamp.2, entry.title.as_ref().map(String::as_str).unwrap_or(""));
|
|
|
+
|
|
|
+ let force_show = entry.balances.iter().unique_by(|b| *b.account).count() > 1;
|
|
|
+
|
|
|
for bal in &entry.balances {
|
|
|
let spacer = if bal.amount.is_sign_positive() { " " } else { "" };
|
|
|
- if Some(bal.unit.as_ref()) == root.account_spec(*bal.account).unwrap().default_unit.as_ref() {
|
|
|
- println!(" - {:10}: {spacer}{}", bal.account, bal.amount);
|
|
|
+ if Some(bal.unit.as_ref()) == root.account_spec(*bal.account).unwrap().unit.as_ref() && !force_show {
|
|
|
+ println!(" - {:padding$}: {spacer}{}", bal.account, bal.amount, padding = padding);
|
|
|
} else {
|
|
|
- println!(" - {:10}: {spacer}{} {}", bal.account, bal.amount, bal.unit);
|
|
|
+ println!(" - {:padding$}: {spacer}{} {}", bal.account, bal.amount, bal.unit, padding = padding);
|
|
|
}
|
|
|
}
|
|
|
// empty line afterwards
|
|
@@ -26,10 +31,15 @@ pub fn print_ledger<'l>(root: &Root, entries: impl Iterator<Item = &'l Spanned<L
|
|
|
ordering.entry(e.span().context).or_default().insert(e.span(), e.as_ref());
|
|
|
});
|
|
|
|
|
|
+ let Some(padding) = root.spec_root.accounts.keys().map(|k| k.len()).max() else {
|
|
|
+ // no accounts
|
|
|
+ return
|
|
|
+ };
|
|
|
+
|
|
|
for (filename, entries) in ordering {
|
|
|
println!("==== file {} ====", std::path::Path::new(filename.as_ref()).display());
|
|
|
for (_span, le) in entries {
|
|
|
- print_ledger_entry(root, le);
|
|
|
+ print_ledger_entry(root, le, padding);
|
|
|
}
|
|
|
}
|
|
|
}
|