From 430b17c92ee8e15bacce2c058d3e56f187da5fc3 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 11 Aug 2019 19:47:39 -0400 Subject: validate reconciled amounts, and also handle split transactions --- src/main.rs | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 46f8042..0bba75a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,13 +4,41 @@ fn main() { let key = std::env::args().nth(1).unwrap(); let client = ynab::Client::new(&key); let budget = client.default_budget(); + let reimbursables = budget.reimbursables(); println!("using budget {} ({})", budget.name(), budget.id()); - for t in budget.reimbursables() { - if t.reimbursed { - continue; - } + let reconciled_amount: i64 = reimbursables + .iter() + .filter(|t| t.reimbursed) + .map(|t| t.amount) + .sum(); + if reconciled_amount != 0 { + eprintln!( + "reconciled reimbursables don't sum to $0.00: ${}", + ynab::format_amount(reconciled_amount) + ); + std::process::exit(1); + } + println!("reconciled reimbursables correctly sum to $0.00"); + + println!("ready for reconciliation:"); + for t in reimbursables + .iter() + .filter(|t| !t.reimbursed && t.amount > 0) + { + println!( + "{} | {} | {}", + t.date, + t.payee, + ynab::format_amount(t.amount) + ) + } + println!("match against reconcilable:"); + for t in reimbursables + .iter() + .filter(|t| !t.reimbursed && t.amount <= 0) + { println!( "{} | {} | {}", t.date, -- cgit v1.2.3-54-g00ecf