summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/filters.cc9
-rw-r--r--src/filters.h7
-rw-r--r--src/report.cc15
-rw-r--r--src/report.h30
4 files changed, 51 insertions, 10 deletions
diff --git a/src/filters.cc b/src/filters.cc
index 3667c213..25649ad0 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -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;
diff --git a/src/filters.h b/src/filters.h
index 23a06482..3eb5da8d 100644
--- a/src/filters.h
+++ b/src/filters.h
@@ -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;
diff --git a/src/report.cc b/src/report.cc
index 6fc7626f..2f932115 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -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':
diff --git a/src/report.h b/src/report.h
index f0052128..baacd28c 100644
--- a/src/report.h
+++ b/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