diff options
-rw-r--r-- | src/chain.cc | 12 | ||||
-rw-r--r-- | src/filters.cc | 11 | ||||
-rw-r--r-- | src/filters.h | 5 | ||||
-rw-r--r-- | src/report.cc | 2 | ||||
-rw-r--r-- | src/report.h | 2 | ||||
-rw-r--r-- | test/baseline/opt-actual.test | 14 | ||||
-rw-r--r-- | test/baseline/opt-forecast-while.test | 285 |
7 files changed, 318 insertions, 13 deletions
diff --git a/src/chain.cc b/src/chain.cc index c67de108..2fc6123e 100644 --- a/src/chain.cc +++ b/src/chain.cc @@ -48,6 +48,14 @@ xact_handler_ptr chain_xact_handlers(report_t& report, expr.set_context(&report); if (! only_preliminaries) { + // Make sure only forecast transactions which match are allowed through + if (report.HANDLED(forecast_while_)) { + handler.reset(new filter_xacts + (handler, item_predicate(report.HANDLER(forecast_while_).str(), + report.what_to_keep()), + report)); + } + // truncate_entries cuts off a certain number of _entries_ from being // displayed. It does not affect calculation. if (report.HANDLED(head_) || report.HANDLED(tail_)) @@ -183,10 +191,10 @@ xact_handler_ptr chain_xact_handlers(report_t& report, report.what_to_keep()), report)); } - else if (report.HANDLED(forecast_)) { + else if (report.HANDLED(forecast_while_)) { forecast_xacts * forecast_handler = new forecast_xacts(handler, - item_predicate(report.HANDLER(forecast_).str(), + item_predicate(report.HANDLER(forecast_while_).str(), report.what_to_keep()), report); forecast_handler->add_period_entries(report.session.journal->period_entries); diff --git a/src/filters.cc b/src/filters.cc index 0bb4cf98..06bc4487 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -660,16 +660,14 @@ void dow_xacts::flush() subtotal_xacts::flush(); } -void generate_xacts::add_period_entries - (period_entries_list& period_entries) +void generate_xacts::add_period_entries(period_entries_list& period_entries) { foreach (period_entry_t * entry, period_entries) foreach (xact_t * xact, entry->xacts) add_xact(entry->period, *xact); } -void generate_xacts::add_xact(const interval_t& period, - xact_t& xact) +void generate_xacts::add_xact(const interval_t& period, xact_t& xact) { pending_xacts.push_back(pending_xacts_pair(period, &xact)); } @@ -722,7 +720,7 @@ void budget_xacts::operator()(xact_t& xact) { bool xact_in_budget = false; - foreach (pending_xacts_list::value_type& pair, pending_xacts) + foreach (pending_xacts_list::value_type& pair, pending_xacts) { for (account_t * acct = xact.reported_account(); acct; acct = acct->parent) { @@ -735,6 +733,7 @@ void budget_xacts::operator()(xact_t& xact) goto handle; } } + } handle: if (xact_in_budget && flags & BUDGET_BUDGETED) { @@ -763,7 +762,7 @@ void forecast_xacts::add_xact(const interval_t& period, xact_t& xact) void forecast_xacts::flush() { xacts_list passed; - date_t last; + date_t last; while (pending_xacts.size() > 0) { pending_xacts_list::iterator least = pending_xacts.begin(); diff --git a/src/filters.h b/src/filters.h index 985fbf94..6089ef75 100644 --- a/src/filters.h +++ b/src/filters.h @@ -741,7 +741,7 @@ class generate_xacts : public item_handler<xact_t> protected: typedef std::pair<interval_t, xact_t *> pending_xacts_pair; - typedef std::list<pending_xacts_pair> pending_xacts_list; + typedef std::list<pending_xacts_pair> pending_xacts_list; pending_xacts_list pending_xacts; std::list<entry_t> entry_temps; @@ -815,8 +815,7 @@ class forecast_xacts : public generate_xacts TRACE_DTOR(forecast_xacts); } - virtual void add_xact(const interval_t& period, - xact_t& xact); + virtual void add_xact(const interval_t& period, xact_t& xact); virtual void flush(); }; diff --git a/src/report.cc b/src/report.cc index 877e6bbb..ce63101b 100644 --- a/src/report.cc +++ b/src/report.cc @@ -371,7 +371,7 @@ option_t<report_t> * report_t::lookup_option(const char * p) break; case 'f': OPT(flat); - else OPT(forecast_); + else OPT_ALT(forecast_while_, forecast_); else OPT(format_); else OPT_ALT(head_, first_); break; diff --git a/src/report.h b/src/report.h index 991d60ba..53bddaae 100644 --- a/src/report.h +++ b/src/report.h @@ -372,7 +372,7 @@ public: OPTION(report_t, equity); OPTION(report_t, flat); - OPTION(report_t, forecast_); + OPTION(report_t, forecast_while_); OPTION(report_t, format_); // -F OPTION(report_t, gain); // -G OPTION(report_t, head_); diff --git a/test/baseline/opt-actual.test b/test/baseline/opt-actual.test new file mode 100644 index 00000000..3b08e9b9 --- /dev/null +++ b/test/baseline/opt-actual.test @@ -0,0 +1,14 @@ +print --actual +<<< += account =~ /Books/ + Expenses:Taxes 0.05 + +2008/01/01 January + Expenses:Books $10.00 + Assets:Cash $-10.00 +>>>1 +2008/01/01 January + Expenses:Books $10.00 + Assets:Cash $-10.00 +>>>2 +=== 0 diff --git a/test/baseline/opt-forecast-while.test b/test/baseline/opt-forecast-while.test new file mode 100644 index 00000000..a4f25ac2 --- /dev/null +++ b/test/baseline/opt-forecast-while.test @@ -0,0 +1,285 @@ +reg --forecast-while='total < $3500' books +<<< +~ monthly + Expenses:Books $10.00 + Assets:Cash + +2008/01/01 January + Expenses:Books $10.00 + Assets:Cash + +2008/01/31 End of January + Expenses:Books $10.00 + Assets:Cash + +2008/02/01 February + Expenses:Books $20.00 + Assets:Cash + +2008/02/28 End of February + Expenses:Books $20.00 + Assets:Cash + +2008/03/01 March + Expenses:Books $30.00 + Assets:Cash + +2008/03/31 End of March + Expenses:Books $30.00 + Assets:Cash + +2008/04/01 April + Expenses:Books $40.00 + Assets:Cash + +2008/04/30 End of April + Expenses:Books $40.00 + Assets:Cash + +2008/05/01 May + Expenses:Books $50.00 + Assets:Cash + +2008/05/31 End of May + Expenses:Books $50.00 + Assets:Cash + +2008/06/01 June + Expenses:Books $60.00 + Assets:Cash + +2008/06/30 End of June + Expenses:Books $60.00 + Assets:Cash + +2008/07/01 July + Expenses:Books $70.00 + Assets:Cash + +2008/07/31 End of July + Expenses:Books $70.00 + Assets:Cash + +2008/08/01 August + Expenses:Books $80.00 + Assets:Cash + +2008/08/31 End of August + Expenses:Books $80.00 + Assets:Cash + +2008/09/01 September + Expenses:Books $90.00 + Assets:Cash + +2008/09/30 End of September + Expenses:Books $90.00 + Assets:Cash + +2008/10/01 October + Expenses:Books $100.00 + Assets:Cash + +2008/10/31 End of October + Expenses:Books $100.00 + Assets:Cash + +2008/11/01 November + Expenses:Books $110.00 + Assets:Cash + +2008/11/30 End of November + Expenses:Books $110.00 + Assets:Cash + +2008/12/01 December + Expenses:Books $120.00 + Assets:Cash + +2008/12/31 End of December + Expenses:Books $120.00 + Assets:Cash + +2009/01/01 January + Expenses:Books $10.00 + Assets:Cash + +2009/01/31 End of January + Expenses:Books $10.00 + Assets:Cash + +2009/02/01 February + Expenses:Books $20.00 + Assets:Cash + +2009/02/28 End of February + Expenses:Books $20.00 + Assets:Cash + +2009/03/01 March + Expenses:Books $30.00 + Assets:Cash + +2009/03/31 End of March + Expenses:Books $30.00 + Assets:Cash + +2009/04/01 April + Expenses:Books $40.00 + Assets:Cash + +2009/04/30 End of April + Expenses:Books $40.00 + Assets:Cash + +2009/05/01 May + Expenses:Books $50.00 + Assets:Cash + +2009/05/31 End of May + Expenses:Books $50.00 + Assets:Cash + +2009/06/01 June + Expenses:Books $60.00 + Assets:Cash + +2009/06/30 End of June + Expenses:Books $60.00 + Assets:Cash + +2009/07/01 July + Expenses:Books $70.00 + Assets:Cash + +2009/07/31 End of July + Expenses:Books $70.00 + Assets:Cash + +2009/08/01 August + Expenses:Books $80.00 + Assets:Cash + +2009/08/31 End of August + Expenses:Books $80.00 + Assets:Cash + +2009/09/01 September + Expenses:Books $90.00 + Assets:Cash + +2009/09/30 End of September + Expenses:Books $90.00 + Assets:Cash + +2009/10/01 October + Expenses:Books $100.00 + Assets:Cash + +2009/10/31 End of October + Expenses:Books $100.00 + Assets:Cash + +2009/11/01 November + Expenses:Books $110.00 + Assets:Cash + +2009/11/30 End of November + Expenses:Books $110.00 + Assets:Cash + +2009/12/01 December + Expenses:Books $120.00 + Assets:Cash + +2009/12/31 End of December + Expenses:Books $120.00 + Assets:Cash +>>>1 +08-Jan-01 January Expenses:Books $10.00 $10.00 +08-Jan-31 End of January Expenses:Books $10.00 $20.00 +08-Feb-01 February Expenses:Books $20.00 $40.00 +08-Feb-28 End of February Expenses:Books $20.00 $60.00 +08-Mar-01 March Expenses:Books $30.00 $90.00 +08-Mar-31 End of March Expenses:Books $30.00 $120.00 +08-Apr-01 April Expenses:Books $40.00 $160.00 +08-Apr-30 End of April Expenses:Books $40.00 $200.00 +08-May-01 May Expenses:Books $50.00 $250.00 +08-May-31 End of May Expenses:Books $50.00 $300.00 +08-Jun-01 June Expenses:Books $60.00 $360.00 +08-Jun-30 End of June Expenses:Books $60.00 $420.00 +08-Jul-01 July Expenses:Books $70.00 $490.00 +08-Jul-31 End of July Expenses:Books $70.00 $560.00 +08-Aug-01 August Expenses:Books $80.00 $640.00 +08-Aug-31 End of August Expenses:Books $80.00 $720.00 +08-Sep-01 September Expenses:Books $90.00 $810.00 +08-Sep-30 End of September Expenses:Books $90.00 $900.00 +08-Oct-01 October Expenses:Books $100.00 $1000.00 +08-Oct-31 End of October Expenses:Books $100.00 $1100.00 +08-Nov-01 November Expenses:Books $110.00 $1210.00 +08-Nov-30 End of November Expenses:Books $110.00 $1320.00 +08-Dec-01 December Expenses:Books $120.00 $1440.00 +08-Dec-31 End of December Expenses:Books $120.00 $1560.00 +09-Jan-01 January Expenses:Books $10.00 $1570.00 +09-Jan-31 End of January Expenses:Books $10.00 $1580.00 +09-Feb-01 February Expenses:Books $20.00 $1600.00 +09-Feb-28 End of February Expenses:Books $20.00 $1620.00 +09-Mar-01 March Expenses:Books $30.00 $1650.00 +09-Mar-31 End of March Expenses:Books $30.00 $1680.00 +09-Apr-01 April Expenses:Books $40.00 $1720.00 +09-Apr-30 End of April Expenses:Books $40.00 $1760.00 +09-May-01 May Expenses:Books $50.00 $1810.00 +09-May-31 End of May Expenses:Books $50.00 $1860.00 +09-Jun-01 June Expenses:Books $60.00 $1920.00 +09-Jun-30 End of June Expenses:Books $60.00 $1980.00 +09-Jul-01 July Expenses:Books $70.00 $2050.00 +09-Jul-31 End of July Expenses:Books $70.00 $2120.00 +09-Aug-01 August Expenses:Books $80.00 $2200.00 +09-Aug-31 End of August Expenses:Books $80.00 $2280.00 +09-Sep-01 September Expenses:Books $90.00 $2370.00 +09-Sep-30 End of September Expenses:Books $90.00 $2460.00 +09-Oct-01 October Expenses:Books $100.00 $2560.00 +09-Oct-31 End of October Expenses:Books $100.00 $2660.00 +09-Nov-01 November Expenses:Books $110.00 $2770.00 +09-Nov-30 End of November Expenses:Books $110.00 $2880.00 +09-Dec-01 December Expenses:Books $120.00 $3000.00 +09-Dec-31 End of December Expenses:Books $120.00 $3120.00 +09-Mar-01 Forecast entry Expenses:Books $10.00 $3130.00 +09-Apr-01 Forecast entry Expenses:Books $10.00 $3140.00 +09-May-01 Forecast entry Expenses:Books $10.00 $3150.00 +09-Jun-01 Forecast entry Expenses:Books $10.00 $3160.00 +09-Jul-01 Forecast entry Expenses:Books $10.00 $3170.00 +09-Aug-01 Forecast entry Expenses:Books $10.00 $3180.00 +09-Sep-01 Forecast entry Expenses:Books $10.00 $3190.00 +09-Oct-01 Forecast entry Expenses:Books $10.00 $3200.00 +09-Nov-01 Forecast entry Expenses:Books $10.00 $3210.00 +09-Dec-01 Forecast entry Expenses:Books $10.00 $3220.00 +10-Jan-01 Forecast entry Expenses:Books $10.00 $3230.00 +10-Feb-01 Forecast entry Expenses:Books $10.00 $3240.00 +10-Mar-01 Forecast entry Expenses:Books $10.00 $3250.00 +10-Apr-01 Forecast entry Expenses:Books $10.00 $3260.00 +10-May-01 Forecast entry Expenses:Books $10.00 $3270.00 +10-Jun-01 Forecast entry Expenses:Books $10.00 $3280.00 +10-Jul-01 Forecast entry Expenses:Books $10.00 $3290.00 +10-Aug-01 Forecast entry Expenses:Books $10.00 $3300.00 +10-Sep-01 Forecast entry Expenses:Books $10.00 $3310.00 +10-Oct-01 Forecast entry Expenses:Books $10.00 $3320.00 +10-Nov-01 Forecast entry Expenses:Books $10.00 $3330.00 +10-Dec-01 Forecast entry Expenses:Books $10.00 $3340.00 +11-Jan-01 Forecast entry Expenses:Books $10.00 $3350.00 +11-Feb-01 Forecast entry Expenses:Books $10.00 $3360.00 +11-Mar-01 Forecast entry Expenses:Books $10.00 $3370.00 +11-Apr-01 Forecast entry Expenses:Books $10.00 $3380.00 +11-May-01 Forecast entry Expenses:Books $10.00 $3390.00 +11-Jun-01 Forecast entry Expenses:Books $10.00 $3400.00 +11-Jul-01 Forecast entry Expenses:Books $10.00 $3410.00 +11-Aug-01 Forecast entry Expenses:Books $10.00 $3420.00 +11-Sep-01 Forecast entry Expenses:Books $10.00 $3430.00 +11-Oct-01 Forecast entry Expenses:Books $10.00 $3440.00 +11-Nov-01 Forecast entry Expenses:Books $10.00 $3450.00 +11-Dec-01 Forecast entry Expenses:Books $10.00 $3460.00 +12-Jan-01 Forecast entry Expenses:Books $10.00 $3470.00 +12-Feb-01 Forecast entry Expenses:Books $10.00 $3480.00 +12-Mar-01 Forecast entry Expenses:Books $10.00 $3490.00 +>>>2 +=== 0 |