Files
FiscusPublic/crates/fiscus-ledger/src/categories.rs
T
mnovak 03dc2061f9 [insight] Plans and statistics: category plans, categories of your own, one definition of spending, the month in numbers; v0.5.0
- category.planned (carries forward, zero removes it; spending categories only) and category.created
- fiscus-insight: spending (outflows, inflow, largest-remainder thousandths that add up to 1000), plan (the
  month against its plan with the pace, a suggested plan from the last three months), stats (pie slices, in,
  out, net, six months, same day last month, top merchants, subscriptions' share)
- docs/04_plans_stats.md; 11 new tests
2026-11-06 13:02:39 +01:00

42 lines
1.5 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! The categories the app offers. A category is an id; the label is what the app shows.
pub const UNCATEGORISED: &str = "uncategorised";
/// Money between your own accounts: never spending.
pub const TRANSFERS: &str = "transfers";
pub const INCOME: &str = "income";
/// Categories a monthly plan cannot be for: money in, money moved, and money not yet sorted.
pub const NOT_PLANNABLE: [&str; 3] = [INCOME, TRANSFERS, UNCATEGORISED];
/// The most a category's monthly plan can be: 100 000 000 CZK, far from any sum overflowing.
pub const MAX_PLAN: crate::money::Haler = crate::money::Haler(10_000_000_000);
/// `(id, label)` in the order the app lists them.
pub const DEFAULT: &[(&str, &str)] = &[
("groceries", "Groceries"),
("eating-out", "Eating out"),
("transport", "Transport"),
("housing", "Housing"),
("utilities", "Utilities"),
("subscriptions", "Subscriptions"),
("shopping", "Shopping"),
("health", "Health"),
("kids", "Kids"),
("fun", "Fun"),
("travel", "Travel"),
("gifts", "Gifts"),
(INCOME, "Income"),
(TRANSFERS, "Transfers"),
("other", "Other"),
(UNCATEGORISED, "Uncategorised"),
];
/// A category id is lowercase ASCII letters, digits and `-`, 1–40 characters.
pub fn is_valid(id: &str) -> bool {
(1..=40).contains(&id.len()) && id.bytes().all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'-')
}
pub fn label(id: &str) -> &str {
DEFAULT.iter().find(|(i, _)| *i == id).map(|(_, l)| *l).unwrap_or(id)
}