Skip to content

Commit 7e05cc9

Browse files
authored
Merge pull request moneymanagerex#8314 from JoshuaLampert/filter-accounts-summary-of-accounts-report
Add filtering for accounts and time period in summary of accounts report
2 parents 0464fb8 + c691628 commit 7e05cc9

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

src/report/BalanceReport.cpp

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ std::map<mmDate, double> BalanceReport::loadAccountBalance_mDate(const AccountDa
5454

5555
double BalanceReport::getCheckingBalance(const AccountData* account_n, const mmDate& date)
5656
{
57-
std::map<mmDate, double> date_balance_m = m_account_balance_mDate_mId[account_n->m_id];
57+
const auto account_it = m_account_balance_mDate_mId.find(account_n->m_id);
58+
if (account_it == m_account_balance_mDate_mId.end())
59+
return account_n->m_open_balance;
60+
61+
const auto& date_balance_m = account_it->second;
5862
auto const& it = std::upper_bound(date_balance_m.rbegin(), date_balance_m.rend(),
5963
std::pair<mmDate, double>(date, 0),
6064
[](const std::pair<mmDate, double> x, std::pair<mmDate, double> y) {
@@ -121,16 +125,39 @@ wxString BalanceReport::getHTMLText()
121125
_t("Accounts Balance - %s"),
122126
m_period_id == PERIOD_ID::MONTH ? _t("Monthly Report") : _t("Yearly Report")
123127
);
124-
hb.addReportHeader(name);
128+
hb.addReportHeader(name,
129+
m_date_range ? m_date_range->startDay() : 0,
130+
m_date_range ? m_date_range->isFutureIgnored() : false
131+
);
132+
if (m_date_range)
133+
hb.displayDateHeading(m_date_range);
125134

126135
m_currencyDateRateCache.clear();
127136
m_stock_xa.clear();
128137

129-
mmDate start_date = mmDate::today();
138+
mmDate selected_start_date = m_date_range
139+
? mmDate(m_date_range->start_date())
140+
: mmDate::today();
141+
mmDate selected_end_date = m_date_range
142+
? mmDate(m_date_range->end_date())
143+
: mmDate::today();
144+
145+
if (selected_end_date > mmDate::today())
146+
selected_end_date = mmDate::today();
147+
148+
mmDate start_date = selected_start_date;
149+
bool has_included_accounts = false;
150+
mmDate earliest_open_date = selected_end_date;
130151
// Calculate the report date
131152
for (const auto& account_d : AccountModel::instance().find_all()) {
132-
if (account_d.m_open_date < start_date)
133-
start_date = account_d.m_open_date;
153+
if (m_account_a && wxNOT_FOUND == m_account_a->Index(account_d.m_name))
154+
continue;
155+
156+
if (!has_included_accounts || account_d.m_open_date < earliest_open_date) {
157+
earliest_open_date = account_d.m_open_date;
158+
has_included_accounts = true;
159+
}
160+
134161
m_account_balance_mDate_mId[account_d.m_id] = loadAccountBalance_mDate(account_d);
135162
if (AccountModel::type_id(account_d) != mmNavigatorItem::TYPE_ID_INVESTMENT)
136163
continue;
@@ -149,7 +176,11 @@ wxString BalanceReport::getHTMLText()
149176
}
150177
}
151178

152-
wxDateTime end_datetime = mmDate::today().dateTime();
179+
// Skip leading periods where selected accounts cannot have any balance yet.
180+
if (has_included_accounts && start_date < earliest_open_date)
181+
start_date = earliest_open_date;
182+
183+
wxDateTime end_datetime = selected_end_date.dateTime();
153184
wxDateSpan span;
154185
if (m_period_id == PERIOD_ID::MONTH) {
155186
end_datetime.SetToLastMonthDay(end_datetime.GetMonth(), end_datetime.GetYear());
@@ -182,6 +213,9 @@ wxString BalanceReport::getHTMLText()
182213
std::fill(balance_a.begin(), balance_a.end(), 0.0);
183214
int idx;
184215
for (const auto& account_d : AccountModel::instance().find_all()) {
216+
if (m_account_a && wxNOT_FOUND == m_account_a->Index(account_d.m_name))
217+
continue;
218+
185219
idx = mmNavigatorList::instance().getAccountTypeIdx(account_d.m_type_);
186220
if (idx == -1) {
187221
idx = mmNavigatorList::instance().getAccountTypeIdx(mmNavigatorItem::TYPE_ID_CHECKING);
@@ -300,6 +334,7 @@ wxString BalanceReport::getHTMLText()
300334
hb.endTable();
301335
}
302336
hb.endDiv();
337+
hb.displayFooter(getAccountNames());
303338

304339
hb.end();
305340

src/report/_ReportBase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void ReportBase::setReportParameters(ReportBase::REPORT_ID report_id)
5353

5454
switch (report_id) {
5555
case MyUsage: m_parameters = M_DATE_RANGE | M_CHART; break;
56-
case MonthlySummaryofAccounts: m_parameters = M_CHART; break;
57-
case YearlySummaryofAccounts: m_parameters = M_CHART; break;
56+
case MonthlySummaryofAccounts: m_parameters = M_DATE_RANGE | M_ACCOUNT | M_CHART; break;
57+
case YearlySummaryofAccounts: m_parameters = M_DATE_RANGE | M_ACCOUNT | M_CHART; break;
5858
case WheretheMoneyGoes: m_parameters = M_DATE_RANGE | M_ACCOUNT | M_CHART; break;
5959
case WheretheMoneyComesFrom: m_parameters = M_DATE_RANGE | M_ACCOUNT | M_CHART; break;
6060
case CategoriesSummary: m_parameters = M_DATE_RANGE | M_ACCOUNT | M_CHART; break;

0 commit comments

Comments
 (0)