Added --dc option, for debit/credit style reports

This commit is contained in:
John Wiegley 2012-03-10 21:34:51 -06:00
parent 1956393a44
commit 860610fdaf
13 changed files with 119 additions and 23 deletions

View file

@ -300,6 +300,7 @@ See
.It Fl \-date-format Ar DATEFMT Pq Fl y
.It Fl \-datetime-format Ar FMT
.It Fl \-date-width Ar INT
.It Fl \-dc
.It Fl \-debug Ar STR
.It Fl \-decimal-comma
.It Fl \-depth Ar INT

View file

@ -204,10 +204,22 @@ void report_t::normalize_options(const string& verb)
! HANDLED(amount_width_) &&
! HANDLED(total_width_)) {
long total = (4 /* the spaces between */ + date_width + payee_width +
account_width + amount_width + total_width);
if (total > cols) {
account_width + amount_width + total_width +
(HANDLED(dc) ? 1 + amount_width : 0));
while (total > cols && account_width > 5 && payee_width > 5) {
DEBUG("auto.columns", "adjusting account down");
account_width -= total - cols;
if (total > cols) {
--account_width;
--total;
if (total > cols) {
--account_width;
--total;
}
}
if (total > cols) {
--payee_width;
--total;
}
DEBUG("auto.columns", "account_width now = " << account_width);
}
}
@ -1029,6 +1041,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
else OPT(date_);
else OPT(date_format_);
else OPT(datetime_format_);
else OPT(dc);
else OPT(depth_);
else OPT(deviation);
else OPT_(display_);

View file

@ -215,7 +215,7 @@ public:
bool lots = HANDLED(lots) || HANDLED(lots_actual);
return keep_details_t(lots || HANDLED(lot_prices),
lots || HANDLED(lot_dates),
lots || HANDLED(lot_tags),
lots || HANDLED(lot_notes),
HANDLED(lots_actual));
}
@ -250,6 +250,7 @@ public:
HANDLER(date_).report(out);
HANDLER(date_format_).report(out);
HANDLER(datetime_format_).report(out);
HANDLER(dc).report(out);
HANDLER(depth_).report(out);
HANDLER(deviation).report(out);
HANDLER(display_).report(out);
@ -277,7 +278,7 @@ public:
HANDLER(limit_).report(out);
HANDLER(lot_dates).report(out);
HANDLER(lot_prices).report(out);
HANDLER(lot_tags).report(out);
HANDLER(lot_notes).report(out);
HANDLER(lots).report(out);
HANDLER(lots_actual).report(out);
HANDLER(market).report(out);
@ -518,6 +519,73 @@ public:
OPTION(report_t, date_format_);
OPTION(report_t, datetime_format_);
OPTION_(report_t, dc, DO() {
OTHER(amount_).expr.set_base_expr
("(amount > 0 ? amount : 0, amount < 0 ? amount : 0)");
OTHER(register_format_)
.on(none,
"%(ansify_if("
" ansify_if(justify(format_date(date), int(date_width)),"
" green if color and date > today),"
" bold if should_bold))"
" %(ansify_if("
" ansify_if(justify(truncated(payee, int(payee_width)), int(payee_width)), "
" bold if color and !cleared and actual),"
" bold if should_bold))"
" %(ansify_if("
" ansify_if(justify(truncated(display_account, int(account_width), "
" abbrev_len), int(account_width)),"
" blue if color),"
" bold if should_bold))"
" %(ansify_if("
" justify(scrub(abs(get_at(display_amount, 0))), int(amount_width), "
" 3 + int(meta_width) + int(date_width) + int(payee_width)"
" + int(account_width) + int(amount_width) + int(prepend_width),"
" true, color),"
" bold if should_bold))"
" %(ansify_if("
" justify(scrub(abs(get_at(display_amount, 1))), int(amount_width), "
" 4 + int(meta_width) + int(date_width) + int(payee_width)"
" + int(account_width) + int(amount_width) + int(amount_width) + int(prepend_width),"
" true, color),"
" bold if should_bold))"
" %(ansify_if("
" justify(scrub(get_at(display_total, 0) + get_at(display_total, 1)), int(total_width), "
" 5 + int(meta_width) + int(date_width) + int(payee_width)"
" + int(account_width) + int(amount_width) + int(amount_width) + int(total_width)"
" + int(prepend_width), true, color),"
" bold if should_bold))\n%/"
"%(justify(\" \", int(date_width)))"
" %(ansify_if("
" justify(truncated(has_tag(\"Payee\") ? payee : \" \", "
" int(payee_width)), int(payee_width)),"
" bold if should_bold))"
" %$3 %$4 %$5 %$6\n");
OTHER(balance_format_)
.on(none,
"%(ansify_if("
" justify(scrub(abs(get_at(display_total, 0))), 14,"
" 14 + int(prepend_width), true, color),"
" bold if should_bold)) "
"%(ansify_if("
" justify(scrub(abs(get_at(display_total, 1))), 14,"
" 14 + 1 + int(prepend_width) + int(total_width), true, color),"
" bold if should_bold)) "
"%(ansify_if("
" justify(scrub(get_at(display_total, 0) + get_at(display_total, 1)), 14,"
" 14 + 2 + int(prepend_width) + int(total_width) + int(total_width), true, color),"
" bold if should_bold))"
" %(!options.flat ? depth_spacer : \"\")"
"%-(ansify_if("
" ansify_if(partial_account(options.flat), blue if color),"
" bold if should_bold))\n%/"
"%$1 %$2 %$3\n%/"
"%(prepend_width ? \" \" * int(prepend_width) : \"\")"
"--------------------------------------------\n");
});
OPTION_(report_t, depth_, DO_(str) {
OTHER(display_).on(whence, string("depth<=") + str);
});
@ -590,9 +658,7 @@ public:
OPTION_(report_t, gain, DO() { // -G
OTHER(revalued).on(whence);
OTHER(amount_).expr.set_base_expr("(amount, cost)");
OTHER(total_).expr.set_base_expr("total");
// Since we are displaying the amounts of revalued postings, they
// will end up being composite totals, and hence a pair of pairs.
@ -653,7 +719,7 @@ public:
OPTION(report_t, lot_dates);
OPTION(report_t, lot_prices);
OPTION(report_t, lot_tags);
OPTION(report_t, lot_notes);
OPTION(report_t, lots);
OPTION(report_t, lots_actual);

16
test/baseline/opt-dc.test Normal file
View file

@ -0,0 +1,16 @@
2012-03-10 Employer
Assets:Cash $100
Income:Employer
2012-03-10 KFC
Expenses:Food $20
Assets:Cash
2012-03-10 KFC - Rebate
Assets:Cash
Expenses:Food $-5
2012-03-10 KFC - Food & Rebate
Expenses:Food $20
Expenses:Food $-5
Assets:Cash

View file

@ -9,6 +9,6 @@
; :AnotherTag:
test reg --meta Sample --meta-width=15
Another Value 04-May-27 Credit card com.. Liab:MasterCard $20.00 $20.00
Value As:Ban:Checking $-20.00 0
Another Value 04-May-27 Credit card co.. Liabi:MasterCard $20.00 $20.00
Value As:Bank:Checking $-20.00 0
end test

View file

@ -15,6 +15,6 @@
Liabilities:Credit Card
test reg --columns=60 food and code xfer
09-Oct-29 Panera Bread Expenses:Food $4.50 $4.50
09-Oct-30 Panera Bread Expenses:Food $4.50 $9.00
09-Oct-29 Panera Bread Expenses:Food $4.50 $4.50
09-Oct-30 Panera Bread Expenses:Food $4.50 $9.00
end test

View file

@ -17,6 +17,6 @@
Assets:Checking
test reg --columns=60 food and note eat
09-Nov-01 Panera Bread Expenses:Food $4.50 $4.50
09-Nov-01 Panera Bread Expenses:Food $4.50 $9.00
09-Nov-01 Panera Bread Expenses:Food $4.50 $4.50
09-Nov-01 Panera Bread Expenses:Food $4.50 $9.00
end test

View file

@ -17,5 +17,5 @@
Assets:Checking
test reg --columns=60 food and tag eating
09-Nov-01 Panera Bread Expenses:Food $4.50 $4.50
09-Nov-01 Panera Bread Expenses:Food $4.50 $4.50
end test

View file

@ -17,5 +17,5 @@
Assets:Checking
test reg --columns=60 food and tag type=dining
09-Nov-01 Panera Bread Expenses:Food $4.50 $4.50
09-Nov-01 Panera Bread Expenses:Food $4.50 $4.50
end test

View file

@ -11,7 +11,7 @@
Assets
test reg --columns=60 food
09-Oct-31 Panera Bread Expenses:Food $4.50 $4.50
09-Nov-01 Panera Bread Expenses:Food $4.50 $9.00
09-Nov-02 Panera Bread Expenses:Food $4.50 $13.50
09-Oct-31 Panera Bread Expenses:Food $4.50 $4.50
09-Nov-01 Panera Bread Expenses:Food $4.50 $9.00
09-Nov-02 Panera Bread Expenses:Food $4.50 $13.50
end test

View file

@ -11,5 +11,5 @@
Assets
test reg --columns=60 food --cleared
09-Oct-31 Panera Bread Expenses:Food $4.50 $4.50
09-Oct-31 Panera Bread Expenses:Food $4.50 $4.50
end test

View file

@ -11,6 +11,6 @@
Assets
test reg --columns=60 food --uncleared
09-Nov-01 Panera Bread Expenses:Food $4.50 $4.50
09-Nov-02 Panera Bread Expenses:Food $4.50 $9.00
09-Nov-01 Panera Bread Expenses:Food $4.50 $4.50
09-Nov-02 Panera Bread Expenses:Food $4.50 $9.00
end test

View file

@ -11,5 +11,5 @@
Assets
test reg --columns=60 food --pending
09-Nov-01 Panera Bread Expenses:Food $4.50 $4.50
09-Nov-01 Panera Bread Expenses:Food $4.50 $4.50
end test