diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-08-12 00:09:21 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-08-12 00:09:21 -0400 |
commit | ca12c28f744c34b27c57dd832ac5f713eff61ab4 (patch) | |
tree | 866f8a6e995c79391002891cb4e004cf7eb09a17 /src/checks.rs | |
parent | 430b17c92ee8e15bacce2c058d3e56f187da5fc3 (diff) | |
download | ynab-api-ca12c28f744c34b27c57dd832ac5f713eff61ab4.tar.gz ynab-api-ca12c28f744c34b27c57dd832ac5f713eff61ab4.zip |
start building out a cursive ui
Diffstat (limited to 'src/checks.rs')
-rw-r--r-- | src/checks.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/checks.rs b/src/checks.rs new file mode 100644 index 0000000..7882fae --- /dev/null +++ b/src/checks.rs @@ -0,0 +1,32 @@ +pub fn run_checks(budget: &super::ynab::Budget) { + check_reconciled(budget); + check_has_inflows(budget); +} + +fn check_reconciled(budget: &super::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: ${}", + super::ynab::format_amount(reconciled_amount) + ); + std::process::exit(1); + } +} + +fn check_has_inflows(budget: &super::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); + } +} |