aboutsummaryrefslogtreecommitdiffstats
path: root/src/checks.rs
blob: dfd5362e35fabb1d212899989b33d2f4a2c45f08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pub fn run_checks(budget: &crate::ynab::Budget) {
    check_reconciled(budget);
    check_has_inflows(budget);
}

fn check_reconciled(budget: &crate::ynab::Budget) {
    let reconciled_amount: i64 = budget
        .reimbursables()
        .iter()
        .filter(|t| t.reimbursed)
        .map(|t| t.amount)
        .sum();
    if reconciled_amount != 0 {
        eprintln!(
            "reconciled reimbursables don't sum to $0.00: ${}",
            crate::ynab::format_amount(reconciled_amount)
        );
        std::process::exit(1);
    }
}

fn check_has_inflows(budget: &crate::ynab::Budget) {
    let txns = budget
        .reimbursables()
        .iter()
        .filter(|t| !t.reimbursed && t.amount > 0)
        .count();
    if txns == 0 {
        eprintln!("no transactions to reconcile");
        std::process::exit(1);
    }
}