Added new account_total value expression
This is used for accessing an account's current total within one's Ledger file.
This commit is contained in:
parent
4464ed187b
commit
deb674586c
2 changed files with 28 additions and 0 deletions
|
|
@ -313,6 +313,31 @@ value_t report_t::fn_price(call_scope_t& scope)
|
||||||
return args.value_at(0).price();
|
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)
|
value_t report_t::fn_lot_date(call_scope_t& scope)
|
||||||
{
|
{
|
||||||
interactive_t args(scope, "v");
|
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);
|
return MAKE_FUNCTOR(report_t::fn_ansify_if);
|
||||||
else if (is_eq(p, "abs"))
|
else if (is_eq(p, "abs"))
|
||||||
return MAKE_FUNCTOR(report_t::fn_abs);
|
return MAKE_FUNCTOR(report_t::fn_abs);
|
||||||
|
else if (is_eq(p, "account_total"))
|
||||||
|
return MAKE_FUNCTOR(report_t::fn_account_total);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'b':
|
case 'b':
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,7 @@ public:
|
||||||
value_t fn_ansify_if(call_scope_t& scope);
|
value_t fn_ansify_if(call_scope_t& scope);
|
||||||
value_t fn_percent(call_scope_t& scope);
|
value_t fn_percent(call_scope_t& scope);
|
||||||
value_t fn_price(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_date(call_scope_t& scope);
|
||||||
value_t fn_lot_price(call_scope_t& scope);
|
value_t fn_lot_price(call_scope_t& scope);
|
||||||
value_t fn_lot_tag(call_scope_t& scope);
|
value_t fn_lot_tag(call_scope_t& scope);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue