Added a new "budget" report
This is a balance report with four columns: Amount spent | Budgeted Amount | Difference | Percentage
This commit is contained in:
parent
a8768587c8
commit
88460db2fb
4 changed files with 51 additions and 10 deletions
|
|
@ -752,6 +752,15 @@ void budget_posts::report_budget_items(const date_t& date)
|
|||
post_t& temp = temps.copy_post(post, xact);
|
||||
temp.amount.in_place_negate();
|
||||
|
||||
if (flags & BUDGET_WRAP_VALUES) {
|
||||
value_t seq;
|
||||
seq.push_back(0L);
|
||||
seq.push_back(temp.amount);
|
||||
|
||||
temp.xdata().compound_value = seq;
|
||||
temp.xdata().add_flags(POST_EXT_COMPOUND);
|
||||
}
|
||||
|
||||
++pair.first;
|
||||
begin = *pair.first.start;
|
||||
|
||||
|
|
|
|||
|
|
@ -733,9 +733,10 @@ public:
|
|||
*/
|
||||
class budget_posts : public generate_posts
|
||||
{
|
||||
#define BUDGET_NO_BUDGET 0x00
|
||||
#define BUDGET_BUDGETED 0x01
|
||||
#define BUDGET_UNBUDGETED 0x02
|
||||
#define BUDGET_NO_BUDGET 0x00
|
||||
#define BUDGET_BUDGETED 0x01
|
||||
#define BUDGET_UNBUDGETED 0x02
|
||||
#define BUDGET_WRAP_VALUES 0x04
|
||||
|
||||
uint_least8_t flags;
|
||||
|
||||
|
|
|
|||
|
|
@ -700,11 +700,24 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
|
|||
if (WANT_CMD()) { const char * q = p + CMD_PREFIX_LEN;
|
||||
switch (*q) {
|
||||
case 'b':
|
||||
if (*(q + 1) == '\0' || is_eq(q, "bal") || is_eq(q, "balance"))
|
||||
if (*(q + 1) == '\0' || is_eq(q, "bal") || is_eq(q, "balance")) {
|
||||
return expr_t::op_t::wrap_functor
|
||||
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
|
||||
(new format_accounts(*this, report_format(HANDLER(balance_format_))),
|
||||
*this, "#balance"));
|
||||
}
|
||||
else if (is_eq(q, "budget")) {
|
||||
HANDLER(amount_).set_expr(string("#budget"), "(amount, 0)");
|
||||
|
||||
budget_flags |= BUDGET_WRAP_VALUES;
|
||||
if (! (budget_flags & ~BUDGET_WRAP_VALUES))
|
||||
budget_flags |= BUDGET_BUDGETED;
|
||||
|
||||
return expr_t::op_t::wrap_functor
|
||||
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
|
||||
(new format_accounts(*this, report_format(HANDLER(budget_format_))),
|
||||
*this, "#budget"));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
|
|
|
|||
30
src/report.h
30
src/report.h
|
|
@ -117,9 +117,10 @@ public:
|
|||
session_t& session;
|
||||
output_stream_t output_stream;
|
||||
|
||||
#define BUDGET_NO_BUDGET 0x00
|
||||
#define BUDGET_BUDGETED 0x01
|
||||
#define BUDGET_UNBUDGETED 0x02
|
||||
#define BUDGET_NO_BUDGET 0x00
|
||||
#define BUDGET_BUDGETED 0x01
|
||||
#define BUDGET_UNBUDGETED 0x02
|
||||
#define BUDGET_WRAP_VALUES 0x04
|
||||
|
||||
datetime_t terminus;
|
||||
uint_least8_t budget_flags;
|
||||
|
|
@ -205,6 +206,7 @@ public:
|
|||
HANDLER(basis).report(out);
|
||||
HANDLER(begin_).report(out);
|
||||
HANDLER(budget).report(out);
|
||||
HANDLER(budget_format_).report(out);
|
||||
HANDLER(by_payee).report(out);
|
||||
HANDLER(cleared).report(out);
|
||||
HANDLER(code_as_payee).report(out);
|
||||
|
|
@ -314,7 +316,7 @@ public:
|
|||
});
|
||||
|
||||
OPTION_(report_t, add_budget, DO() {
|
||||
parent->budget_flags = BUDGET_BUDGETED | BUDGET_UNBUDGETED;
|
||||
parent->budget_flags |= BUDGET_BUDGETED | BUDGET_UNBUDGETED;
|
||||
});
|
||||
|
||||
OPTION__
|
||||
|
|
@ -368,7 +370,23 @@ public:
|
|||
});
|
||||
|
||||
OPTION_(report_t, budget, DO() {
|
||||
parent->budget_flags = BUDGET_BUDGETED;
|
||||
parent->budget_flags |= BUDGET_BUDGETED;
|
||||
});
|
||||
|
||||
OPTION__(report_t, budget_format_, CTOR(report_t, budget_format_) {
|
||||
on(none,
|
||||
"%(justify(scrub(get_at(total_expr, 0)), 12, -1, true, color))"
|
||||
" %(justify(scrub(- get_at(total_expr, 1)), 12, -1, true, color))"
|
||||
" %(justify(scrub(get_at(total_expr, 1) + get_at(total_expr, 0)), 12, -1, true, color))"
|
||||
" %(justify(scrub((100% * get_at(total_expr, 0)) / - get_at(total_expr, 1)), 5, -1, true, color))"
|
||||
" %(!options.flat ? depth_spacer : \"\")"
|
||||
"%-(ansify_if(partial_account(options.flat), blue if color))\n"
|
||||
"%/"
|
||||
"%(justify(scrub(get_at(total_expr, 0)), 12, -1, true, color))"
|
||||
" %(justify(scrub(- get_at(total_expr, 1)), 12, -1, true, color))"
|
||||
" %(justify(scrub(get_at(total_expr, 1) + get_at(total_expr, 0)), 12, -1, true, color))"
|
||||
" %(justify(scrub((100% * get_at(total_expr, 0)) / - get_at(total_expr, 1)), 5, -1, true, color))\n%/"
|
||||
"------------ ------------ ------------ -----\n");
|
||||
});
|
||||
|
||||
OPTION(report_t, by_payee); // -P
|
||||
|
|
@ -772,7 +790,7 @@ public:
|
|||
});
|
||||
|
||||
OPTION_(report_t, unbudgeted, DO() {
|
||||
parent->budget_flags = BUDGET_UNBUDGETED;
|
||||
parent->budget_flags |= BUDGET_UNBUDGETED;
|
||||
});
|
||||
|
||||
OPTION_(report_t, uncleared, DO() { // -U
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue