diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-05 05:11:39 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-05 05:11:39 -0500 |
commit | deb674586cced63fc5b048d76eef477b4ae2f3c1 (patch) | |
tree | 9b8d3175fab30210bf1f00c00b2f542fb7bb16f0 | |
parent | 4464ed187b28f9b253431e2b0dde3cb0e875b4d8 (diff) | |
download | fork-ledger-deb674586cced63fc5b048d76eef477b4ae2f3c1.tar.gz fork-ledger-deb674586cced63fc5b048d76eef477b4ae2f3c1.tar.bz2 fork-ledger-deb674586cced63fc5b048d76eef477b4ae2f3c1.zip |
Added new account_total value expression
This is used for accessing an account's current total within one's
Ledger file.
-rw-r--r-- | src/report.cc | 27 | ||||
-rw-r--r-- | src/report.h | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/report.cc b/src/report.cc index e6f3ccb4..3b570682 100644 --- a/src/report.cc +++ b/src/report.cc @@ -313,6 +313,31 @@ value_t report_t::fn_price(call_scope_t& scope) return args.value_at(0).price(); } +value_t report_t::fn_account_total(call_scope_t& args) +{ + account_t * acct = NULL; + string name; + if (args[0].is_string()) { + name = args[0].as_string(); + acct = session.journal->find_account(name, false); + } + else if (args[0].is_mask()) { + name = args[0].as_mask().expr.str(); + acct = session.journal->find_account_re(name); + } + else { + throw_(std::runtime_error, + _("Expected string or mask for argument 1, but received %1") + << args[0].label()); + } + + if (! acct) + throw_(std::runtime_error, + _("Could not find an account matching ") << name); + + return acct->amount(); +} + value_t report_t::fn_lot_date(call_scope_t& scope) { interactive_t args(scope, "v"); @@ -730,6 +755,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, return MAKE_FUNCTOR(report_t::fn_ansify_if); else if (is_eq(p, "abs")) return MAKE_FUNCTOR(report_t::fn_abs); + else if (is_eq(p, "account_total")) + return MAKE_FUNCTOR(report_t::fn_account_total); break; case 'b': diff --git a/src/report.h b/src/report.h index 32648648..431eac3c 100644 --- a/src/report.h +++ b/src/report.h @@ -160,6 +160,7 @@ public: value_t fn_ansify_if(call_scope_t& scope); value_t fn_percent(call_scope_t& scope); value_t fn_price(call_scope_t& scope); + value_t fn_account_total(call_scope_t& scope); value_t fn_lot_date(call_scope_t& scope); value_t fn_lot_price(call_scope_t& scope); value_t fn_lot_tag(call_scope_t& scope); |