Restored the -p, -b and -e reporting options.

This commit is contained in:
John Wiegley 2008-08-14 02:40:32 -04:00
parent a50bab1865
commit c7c709cd0b
2 changed files with 162 additions and 75 deletions

View file

@ -400,6 +400,34 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::option_amount_); return MAKE_FUNCTOR(report_t::option_amount_);
break; break;
case 'b':
if (std::strcmp(p, "b_") == 0 ||
std::strcmp(p, "begin_") == 0)
return MAKE_FUNCTOR(report_t::option_begin_);
else if (std::strcmp(p, "by-payee") == 0)
return MAKE_FUNCTOR(report_t::option_by_payee);
break;
case 'c':
if (std::strcmp(p, "comm_as_payee") == 0)
return MAKE_FUNCTOR(report_t::option_comm_as_payee);
else if (std::strcmp(p, "code_as_payee") == 0)
return MAKE_FUNCTOR(report_t::option_code_as_payee);
break;
case 'd':
if (std::strcmp(p, "daily") == 0)
return MAKE_FUNCTOR(report_t::option_daily);
else if (std::strcmp(p, "dow") == 0)
return MAKE_FUNCTOR(report_t::option_dow);
break;
case 'e':
if (std::strcmp(p, "e_") == 0 ||
std::strcmp(p, "end_") == 0)
return MAKE_FUNCTOR(report_t::option_end_);
break;
case 'f': case 'f':
if (std::strcmp(p, "F_") == 0 || if (std::strcmp(p, "F_") == 0 ||
std::strcmp(p, "format_") == 0) std::strcmp(p, "format_") == 0)
@ -416,17 +444,28 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::option_amount_data); return MAKE_FUNCTOR(report_t::option_amount_data);
break; break;
case 'J':
if (! (*p + 1))
return MAKE_FUNCTOR(report_t::option_total_data);
break;
case 'l': case 'l':
if (std::strcmp(p, "l_") == 0 if (std::strcmp(p, "l_") == 0
|| std::strcmp(p, "limit_") == 0) || std::strcmp(p, "limit_") == 0)
return MAKE_FUNCTOR(report_t::option_limit_); return MAKE_FUNCTOR(report_t::option_limit_);
break; break;
case 'm':
if (std::strcmp(p, "monthly") == 0)
return MAKE_FUNCTOR(report_t::option_monthly);
break;
case 'p':
if (std::strcmp(p, "p_") == 0 ||
std::strcmp(p, "period_") == 0)
return MAKE_FUNCTOR(report_t::option_period_);
break;
case 'q':
if (std::strcmp(p, "quarterly") == 0)
return MAKE_FUNCTOR(report_t::option_quarterly);
break;
case 't': case 't':
if (std::strcmp(p, "t_") == 0) if (std::strcmp(p, "t_") == 0)
return MAKE_FUNCTOR(report_t::option_amount_); return MAKE_FUNCTOR(report_t::option_amount_);
@ -436,10 +475,50 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::option_tail_); return MAKE_FUNCTOR(report_t::option_tail_);
break; break;
case 'w':
if (std::strcmp(p, "weekly") == 0)
return MAKE_FUNCTOR(report_t::option_weekly);
break;
case 'x':
if (std::strcmp(p, "x"))
return MAKE_FUNCTOR(report_t::option_comm_as_payee);
break;
case 'y':
if (std::strcmp(p, "yearly") == 0)
return MAKE_FUNCTOR(report_t::option_yearly);
break;
case 'J':
if (! (*p + 1))
return MAKE_FUNCTOR(report_t::option_total_data);
break;
case 'M':
if (std::strcmp(p, "M") == 0)
return MAKE_FUNCTOR(report_t::option_monthly);
break;
case 'P':
if (std::strcmp(p, "P") == 0)
return MAKE_FUNCTOR(report_t::option_by_payee);
break;
case 'T': case 'T':
if (std::strcmp(p, "T_") == 0) if (std::strcmp(p, "T_") == 0)
return MAKE_FUNCTOR(report_t::option_total_); return MAKE_FUNCTOR(report_t::option_total_);
break; break;
case 'W':
if (std::strcmp(p, "W") == 0)
return MAKE_FUNCTOR(report_t::option_weekly);
break;
case 'Y':
if (std::strcmp(p, "Y") == 0)
return MAKE_FUNCTOR(report_t::option_yearly);
break;
} }
} }
break; break;

View file

@ -250,19 +250,6 @@ public:
config->account = optarg; config->account = optarg;
} }
value_t option_debug(call_scope_t& args) { // :
config->debug_mode = true;
::setenv("DEBUG_CLASS", optarg, 1);
}
value_t option_verbose(call_scope_t& args) {
config->verbose_mode = true;
}
value_t option_trace(call_scope_t& args) {
config->trace_mode = true;
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// //
// Report filtering // Report filtering
@ -270,37 +257,44 @@ public:
value_t option_effective(call_scope_t& args) { value_t option_effective(call_scope_t& args) {
xact_t::use_effective_date = true; xact_t::use_effective_date = true;
} }
#endif
value_t option_begin(call_scope_t& args) { // b: value_t option_begin_(call_scope_t& args) { // b:
char buf[128]; interval_t interval(args[0].to_string());
interval_t interval(optarg); if (! is_valid(interval.begin))
if (! interval.begin)
throw_(std::invalid_argument, throw_(std::invalid_argument,
"Could not determine beginning of period '" << optarg << "'"); "Could not determine beginning of period '"
<< args[0].to_string() << "'");
if (! report->predicate.empty()) if (! predicate.empty())
report->predicate += "&"; predicate += "&";
report->predicate += "d>=["; predicate += "date>=[";
report->predicate += interval.begin.to_string(); predicate += to_iso_extended_string(interval.begin);
report->predicate += "]"; predicate += "]";
return true;
} }
value_t option_end(call_scope_t& args) { // e: value_t option_end_(call_scope_t& args) { // e:
char buf[128]; interval_t interval(args[0].to_string());
interval_t interval(optarg); if (! is_valid(interval.begin))
if (! interval.begin)
throw_(std::invalid_argument, throw_(std::invalid_argument,
"Could not determine end of period '" << optarg << "'"); "Could not determine end of period '"
<< args[0].to_string() << "'");
if (! report->predicate.empty()) if (! predicate.empty())
report->predicate += "&"; predicate += "&";
report->predicate += "d<["; predicate += "date<[";
report->predicate += interval.begin.to_string(); predicate += to_iso_extended_string(interval.begin);
report->predicate += "]"; predicate += "]";
#if 0
terminus = interval.begin; terminus = interval.begin;
#endif
return true;
} }
#if 0
value_t option_current(call_scope_t& args) { // c value_t option_current(call_scope_t& args) { // c
if (! report->predicate.empty()) if (! report->predicate.empty())
report->predicate += "&"; report->predicate += "&";
@ -500,91 +494,105 @@ public:
value_t option_descend_if(call_scope_t& args) { value_t option_descend_if(call_scope_t& args) {
report->descend_expr = optarg; report->descend_expr = optarg;
} }
#endif
value_t option_period(call_scope_t& args) { // p: value_t option_period_(call_scope_t& args) { // p:
if (report->report_period.empty()) { if (report_period.empty()) {
report->report_period = optarg; report_period = args[0].to_string();
} else { } else {
report->report_period += " "; report_period += " ";
report->report_period += optarg; report_period += args[0].to_string();
} }
// If the period gives a beginning and/or ending date, make sure to // If the period gives a beginning and/or ending date, make sure to
// modify the calculation predicate (via the --begin and --end // modify the calculation predicate (via the --begin and --end
// options) to take this into account. // options) to take this into account.
interval_t interval(report->report_period); interval_t interval(report_period);
if (interval.begin) { if (is_valid(interval.begin)) {
if (! report->predicate.empty()) if (! predicate.empty())
report->predicate += "&"; predicate += "&";
report->predicate += "d>=["; predicate += "date>=[";
report->predicate += interval.begin.to_string(); predicate += to_iso_extended_string(interval.begin);
report->predicate += "]"; predicate += "]";
} }
if (interval.end) { if (is_valid(interval.end)) {
if (! report->predicate.empty()) if (! predicate.empty())
report->predicate += "&"; predicate += "&";
report->predicate += "d<["; predicate += "date<[";
report->predicate += interval.end.to_string(); predicate += to_iso_extended_string(interval.end);
report->predicate += "]"; predicate += "]";
#if 0
terminus = interval.end; terminus = interval.end;
#endif
} }
return true;
} }
value_t option_daily(call_scope_t& args) { value_t option_daily(call_scope_t& args) {
if (report->report_period.empty()) if (report_period.empty())
report->report_period = "daily"; report_period = "daily";
else else
report->report_period = std::string("daily ") + report->report_period; report_period = string("daily ") + report_period;
return true;
} }
value_t option_weekly(call_scope_t& args) { // W value_t option_weekly(call_scope_t& args) { // W
if (report->report_period.empty()) if (report_period.empty())
report->report_period = "weekly"; report_period = "weekly";
else else
report->report_period = std::string("weekly ") + report->report_period; report_period = string("weekly ") + report_period;
return true;
} }
value_t option_monthly(call_scope_t& args) { // M value_t option_monthly(call_scope_t& args) { // M
if (report->report_period.empty()) if (report_period.empty())
report->report_period = "monthly"; report_period = "monthly";
else else
report->report_period = std::string("monthly ") + report->report_period; report_period = string("monthly ") + report_period;
return true;
} }
value_t option_quarterly(call_scope_t& args) { value_t option_quarterly(call_scope_t& args) {
if (report->report_period.empty()) if (report_period.empty())
report->report_period = "quarterly"; report_period = "quarterly";
else else
report->report_period = std::string("quarterly ") + report->report_period; report_period = string("quarterly ") + report_period;
return true;
} }
value_t option_yearly(call_scope_t& args) { // Y value_t option_yearly(call_scope_t& args) { // Y
if (report->report_period.empty()) if (report_period.empty())
report->report_period = "yearly"; report_period = "yearly";
else else
report->report_period = std::string("yearly ") + report->report_period; report_period = string("yearly ") + report_period;
return true;
} }
value_t option_dow(call_scope_t& args) { value_t option_dow(call_scope_t& args) {
report->days_of_the_week = true; days_of_the_week = true;
return true;
} }
value_t option_by_payee(call_scope_t& args) { // P value_t option_by_payee(call_scope_t& args) { // P
report->by_payee = true; by_payee = true;
return true;
} }
value_t option_comm_as_payee(call_scope_t& args) { // x value_t option_comm_as_payee(call_scope_t& args) { // x
report->comm_as_payee = true; comm_as_payee = true;
return true;
} }
value_t option_code_as_payee(call_scope_t& args) { value_t option_code_as_payee(call_scope_t& args) {
report->code_as_payee = true; code_as_payee = true;
return true;
} }
#if 0
value_t option_budget(call_scope_t& args) { value_t option_budget(call_scope_t& args) {
report->budget_flags = BUDGET_BUDGETED; report->budget_flags = BUDGET_BUDGETED;
} }