03dc2061f9
- 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
42 lines
1.5 KiB
Rust
42 lines
1.5 KiB
Rust
//! 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)
|
||
}
|