Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/reports/pivottable.cpp
Show First 20 Lines • Show All 130 Lines • ▼ Show 20 Line(s) | 100 | { | |||
---|---|---|---|---|---|
131 | m_numColumns = columnValue(m_endDate) - columnValue(m_beginDate) + 1 + m_startColumn; // 1 for m_beginDate values and m_startColumn for opening balance values | 131 | m_numColumns = columnValue(m_endDate) - columnValue(m_beginDate) + 1 + m_startColumn; // 1 for m_beginDate values and m_startColumn for opening balance values | ||
132 | 132 | | |||
133 | //Load what types of row the report is going to show | 133 | //Load what types of row the report is going to show | ||
134 | loadRowTypeList(); | 134 | loadRowTypeList(); | ||
135 | 135 | | |||
136 | // | 136 | // | ||
137 | // Initialize outer groups of the grid | 137 | // Initialize outer groups of the grid | ||
138 | // | 138 | // | ||
139 | if (m_config.rowType() == MyMoneyReport::eAssetLiability) { | 139 | if (m_config.rowType() == MyMoneyReport::Row::AssetLiability) { | ||
140 | m_grid.insert(MyMoneyAccount::accountTypeToString(eMyMoney::Account::Type::Asset), PivotOuterGroup(m_numColumns)); | 140 | m_grid.insert(MyMoneyAccount::accountTypeToString(eMyMoney::Account::Type::Asset), PivotOuterGroup(m_numColumns)); | ||
141 | m_grid.insert(MyMoneyAccount::accountTypeToString(eMyMoney::Account::Type::Liability), PivotOuterGroup(m_numColumns, PivotOuterGroup::m_kDefaultSortOrder, true /* inverted */)); | 141 | m_grid.insert(MyMoneyAccount::accountTypeToString(eMyMoney::Account::Type::Liability), PivotOuterGroup(m_numColumns, PivotOuterGroup::m_kDefaultSortOrder, true /* inverted */)); | ||
142 | } else { | 142 | } else { | ||
143 | m_grid.insert(MyMoneyAccount::accountTypeToString(eMyMoney::Account::Type::Income), PivotOuterGroup(m_numColumns, PivotOuterGroup::m_kDefaultSortOrder - 2)); | 143 | m_grid.insert(MyMoneyAccount::accountTypeToString(eMyMoney::Account::Type::Income), PivotOuterGroup(m_numColumns, PivotOuterGroup::m_kDefaultSortOrder - 2)); | ||
144 | m_grid.insert(MyMoneyAccount::accountTypeToString(eMyMoney::Account::Type::Expense), PivotOuterGroup(m_numColumns, PivotOuterGroup::m_kDefaultSortOrder - 1, true /* inverted */)); | 144 | m_grid.insert(MyMoneyAccount::accountTypeToString(eMyMoney::Account::Type::Expense), PivotOuterGroup(m_numColumns, PivotOuterGroup::m_kDefaultSortOrder - 1, true /* inverted */)); | ||
145 | // | 145 | // | ||
146 | // Create rows for income/expense reports with all accounts included | 146 | // Create rows for income/expense reports with all accounts included | ||
147 | // | 147 | // | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 216 | while (it_schedule != schedules.constEnd()) { | |||
247 | } | 247 | } | ||
248 | 248 | | |||
249 | ++it_schedule; | 249 | ++it_schedule; | ||
250 | } | 250 | } | ||
251 | } | 251 | } | ||
252 | 252 | | |||
253 | // whether asset & liability transactions are actually to be considered | 253 | // whether asset & liability transactions are actually to be considered | ||
254 | // transfers | 254 | // transfers | ||
255 | bool al_transfers = (m_config.rowType() == MyMoneyReport::eExpenseIncome) && (m_config.isIncludingTransfers()); | 255 | bool al_transfers = (m_config.rowType() == MyMoneyReport::Row::ExpenseIncome) && (m_config.isIncludingTransfers()); | ||
256 | 256 | | |||
257 | //this is to store balance for loan accounts when not included in the report | 257 | //this is to store balance for loan accounts when not included in the report | ||
258 | QMap<QString, MyMoneyMoney> loanBalances; | 258 | QMap<QString, MyMoneyMoney> loanBalances; | ||
259 | 259 | | |||
260 | QList<MyMoneyTransaction>::const_iterator it_transaction = transactions.constBegin(); | 260 | QList<MyMoneyTransaction>::const_iterator it_transaction = transactions.constBegin(); | ||
261 | int colofs = columnValue(m_beginDate) - m_startColumn; | 261 | int colofs = columnValue(m_beginDate) - m_startColumn; | ||
262 | while (it_transaction != transactions.constEnd()) { | 262 | while (it_transaction != transactions.constEnd()) { | ||
263 | MyMoneyTransaction tx = (*it_transaction); | 263 | MyMoneyTransaction tx = (*it_transaction); | ||
▲ Show 20 Lines • Show All 650 Lines • ▼ Show 20 Line(s) | 912 | case MyMoneyBudget::AccountGroup::eYearly: | |||
914 | value /= MyMoneyMoney(12, 1); | 914 | value /= MyMoneyMoney(12, 1); | ||
915 | // intentional fall through | 915 | // intentional fall through | ||
916 | 916 | | |||
917 | case MyMoneyBudget::AccountGroup::eNone: | 917 | case MyMoneyBudget::AccountGroup::eNone: | ||
918 | case MyMoneyBudget::AccountGroup::eMax: | 918 | case MyMoneyBudget::AccountGroup::eMax: | ||
919 | case MyMoneyBudget::AccountGroup::eMonthly: | 919 | case MyMoneyBudget::AccountGroup::eMonthly: | ||
920 | // place the single monthly value in each column of the report | 920 | // place the single monthly value in each column of the report | ||
921 | // only add the value if columns are monthly or longer | 921 | // only add the value if columns are monthly or longer | ||
922 | if (m_config.columnType() == MyMoneyReport::eBiMonths | 922 | if (m_config.columnType() == MyMoneyReport::Column::BiMonths | ||
923 | || m_config.columnType() == MyMoneyReport::eMonths | 923 | || m_config.columnType() == MyMoneyReport::Column::Months | ||
924 | || m_config.columnType() == MyMoneyReport::eYears | 924 | || m_config.columnType() == MyMoneyReport::Column::Years | ||
925 | || m_config.columnType() == MyMoneyReport::eQuarters) { | 925 | || m_config.columnType() == MyMoneyReport::Column::Quarters) { | ||
926 | QDate budgetDate = budget.budgetStart(); | 926 | QDate budgetDate = budget.budgetStart(); | ||
927 | while (column < m_numColumns && budget.budgetStart().addYears(1) > budgetDate) { | 927 | while (column < m_numColumns && budget.budgetStart().addYears(1) > budgetDate) { | ||
928 | //only show budget values if the budget year and the column date match | 928 | //only show budget values if the budget year and the column date match | ||
929 | //no currency conversion is done here because that is done for all columns later | 929 | //no currency conversion is done here because that is done for all columns later | ||
930 | if (budgetDate > columnDate(column)) { | 930 | if (budgetDate > columnDate(column)) { | ||
931 | ++column; | 931 | ++column; | ||
932 | } else { | 932 | } else { | ||
933 | if (budgetDate >= m_beginDate.addDays(-m_beginDate.day() + 1) | 933 | if (budgetDate >= m_beginDate.addDays(-m_beginDate.day() + 1) | ||
Show All 11 Lines | 943 | case MyMoneyBudget::AccountGroup::eMonthByMonth: | |||
945 | // budget periods are supposed to come in order just like columns | 945 | // budget periods are supposed to come in order just like columns | ||
946 | { | 946 | { | ||
947 | QMap<QDate, MyMoneyBudget::PeriodGroup>::const_iterator it_period = periods.begin(); | 947 | QMap<QDate, MyMoneyBudget::PeriodGroup>::const_iterator it_period = periods.begin(); | ||
948 | while (it_period != periods.end() && column < m_numColumns) { | 948 | while (it_period != periods.end() && column < m_numColumns) { | ||
949 | if ((*it_period).startDate() > columnDate(column)) { | 949 | if ((*it_period).startDate() > columnDate(column)) { | ||
950 | ++column; | 950 | ++column; | ||
951 | } else { | 951 | } else { | ||
952 | switch (m_config.columnType()) { | 952 | switch (m_config.columnType()) { | ||
953 | case MyMoneyReport::eYears: | 953 | case MyMoneyReport::Column::Years: | ||
954 | case MyMoneyReport::eBiMonths: | 954 | case MyMoneyReport::Column::BiMonths: | ||
955 | case MyMoneyReport::eQuarters: | 955 | case MyMoneyReport::Column::Quarters: | ||
956 | case MyMoneyReport::eMonths: { | 956 | case MyMoneyReport::Column::Months: { | ||
957 | if ((*it_period).startDate() >= m_beginDate.addDays(-m_beginDate.day() + 1) | 957 | if ((*it_period).startDate() >= m_beginDate.addDays(-m_beginDate.day() + 1) | ||
958 | && (*it_period).startDate() <= m_endDate.addDays(m_endDate.daysInMonth() - m_endDate.day()) | 958 | && (*it_period).startDate() <= m_endDate.addDays(m_endDate.daysInMonth() - m_endDate.day()) | ||
959 | && (*it_period).startDate() > (columnDate(column).addMonths(-m_config.columnType()))) { | 959 | && (*it_period).startDate() > (columnDate(column).addMonths(-m_config.columnType()))) { | ||
960 | //no currency conversion is done here because that is done for all columns later | 960 | //no currency conversion is done here because that is done for all columns later | ||
961 | value = (*it_period).amount() * reverse; | 961 | value = (*it_period).amount() * reverse; | ||
962 | assignCell(outergroup, splitAccount, column, value, true /*budget*/); | 962 | assignCell(outergroup, splitAccount, column, value, true /*budget*/); | ||
963 | } | 963 | } | ||
964 | ++it_period; | 964 | ++it_period; | ||
▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Line(s) | 1113 | while (it_innergroup != (*it_outergroup).end()) { | |||
1166 | 1166 | | |||
1167 | ++it_innergroup; | 1167 | ++it_innergroup; | ||
1168 | } | 1168 | } | ||
1169 | 1169 | | |||
1170 | // | 1170 | // | ||
1171 | // Outer Row Group Totals | 1171 | // Outer Row Group Totals | ||
1172 | // | 1172 | // | ||
1173 | 1173 | | |||
1174 | const bool isIncomeExpense = (m_config.rowType() == MyMoneyReport::eExpenseIncome); | 1174 | const bool isIncomeExpense = (m_config.rowType() == MyMoneyReport::Row::ExpenseIncome); | ||
1175 | const bool invert_total = (*it_outergroup).m_inverted; | 1175 | const bool invert_total = (*it_outergroup).m_inverted; | ||
1176 | auto column = 0; | 1176 | auto column = 0; | ||
1177 | while (column < m_numColumns) { | 1177 | while (column < m_numColumns) { | ||
1178 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | 1178 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | ||
1179 | if (m_grid.m_total[ m_rowTypeList[i] ].count() <= column) | 1179 | if (m_grid.m_total[ m_rowTypeList[i] ].count() <= column) | ||
1180 | throw MYMONEYEXCEPTION(QString("Column %1 out of grid range (%2) in PivotTable::calculateTotals, grid totals").arg(column).arg((*it_innergroup).m_total[ m_rowTypeList[i] ].count())); | 1180 | throw MYMONEYEXCEPTION(QString("Column %1 out of grid range (%2) in PivotTable::calculateTotals, grid totals").arg(column).arg((*it_innergroup).m_total[ m_rowTypeList[i] ].count())); | ||
1181 | 1181 | | |||
1182 | //calculate actual totals | 1182 | //calculate actual totals | ||
▲ Show 20 Lines • Show All 834 Lines • ▼ Show 20 Line(s) | 2000 | { | |||
2017 | 2017 | | |||
2018 | //adjust history dates if beginning date is before today | 2018 | //adjust history dates if beginning date is before today | ||
2019 | if (m_beginDate < QDate::currentDate()) { | 2019 | if (m_beginDate < QDate::currentDate()) { | ||
2020 | forecast.setHistoryEndDate(m_beginDate.addDays(-1)); | 2020 | forecast.setHistoryEndDate(m_beginDate.addDays(-1)); | ||
2021 | forecast.setHistoryStartDate(forecast.historyEndDate().addDays(-forecast.accountsCycle()*forecast.forecastCycles())); | 2021 | forecast.setHistoryStartDate(forecast.historyEndDate().addDays(-forecast.accountsCycle()*forecast.forecastCycles())); | ||
2022 | } | 2022 | } | ||
2023 | 2023 | | |||
2024 | //run forecast | 2024 | //run forecast | ||
2025 | if (m_config.rowType() == MyMoneyReport::eAssetLiability) { //asset and liability | 2025 | if (m_config.rowType() == MyMoneyReport::Row::AssetLiability) { //asset and liability | ||
2026 | forecast.doForecast(); | 2026 | forecast.doForecast(); | ||
2027 | } else { //income and expenses | 2027 | } else { //income and expenses | ||
2028 | MyMoneyBudget budget; | 2028 | MyMoneyBudget budget; | ||
2029 | forecast.createBudget(budget, m_beginDate.addYears(-1), m_beginDate.addDays(-1), m_beginDate, m_endDate, false); | 2029 | forecast.createBudget(budget, m_beginDate.addYears(-1), m_beginDate.addDays(-1), m_beginDate, m_endDate, false); | ||
2030 | } | 2030 | } | ||
2031 | 2031 | | |||
2032 | //go through the data and add forecast | 2032 | //go through the data and add forecast | ||
2033 | PivotGrid::iterator it_outergroup = m_grid.begin(); | 2033 | PivotGrid::iterator it_outergroup = m_grid.begin(); | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 2119 | { | |||
2124 | while (it_outergroup != m_grid.end()) { | 2124 | while (it_outergroup != m_grid.end()) { | ||
2125 | PivotOuterGroup::iterator it_innergroup = (*it_outergroup).begin(); | 2125 | PivotOuterGroup::iterator it_innergroup = (*it_outergroup).begin(); | ||
2126 | while (it_innergroup != (*it_outergroup).end()) { | 2126 | while (it_innergroup != (*it_outergroup).end()) { | ||
2127 | PivotInnerGroup::iterator it_row = (*it_innergroup).begin(); | 2127 | PivotInnerGroup::iterator it_row = (*it_innergroup).begin(); | ||
2128 | while (it_row != (*it_innergroup).end()) { | 2128 | while (it_row != (*it_innergroup).end()) { | ||
2129 | int column = m_startColumn; | 2129 | int column = m_startColumn; | ||
2130 | 2130 | | |||
2131 | //check whether columns are days or months | 2131 | //check whether columns are days or months | ||
2132 | if (m_config.columnType() == MyMoneyReport::eDays) { | 2132 | if (m_config.columnType() == MyMoneyReport::Column::Days) { | ||
2133 | while (column < m_numColumns) { | 2133 | while (column < m_numColumns) { | ||
2134 | MyMoneyMoney totalPrice = MyMoneyMoney(); | 2134 | MyMoneyMoney totalPrice = MyMoneyMoney(); | ||
2135 | 2135 | | |||
2136 | QDate averageStart = columnDate(column).addDays(-delta); | 2136 | QDate averageStart = columnDate(column).addDays(-delta); | ||
2137 | QDate averageEnd = columnDate(column).addDays(delta); | 2137 | QDate averageEnd = columnDate(column).addDays(delta); | ||
2138 | for (QDate averageDate = averageStart; averageDate <= averageEnd; averageDate = averageDate.addDays(1)) { | 2138 | for (QDate averageDate = averageStart; averageDate <= averageEnd; averageDate = averageDate.addDays(1)) { | ||
2139 | if (m_config.isConvertCurrency()) { | 2139 | if (m_config.isConvertCurrency()) { | ||
2140 | totalPrice += it_row.key().deepCurrencyPrice(averageDate) * it_row.key().baseCurrencyPrice(averageDate); | 2140 | totalPrice += it_row.key().deepCurrencyPrice(averageDate) * it_row.key().baseCurrencyPrice(averageDate); | ||
Show All 14 Lines | |||||
2155 | } | 2155 | } | ||
2156 | } else { | 2156 | } else { | ||
2157 | //if columns are months | 2157 | //if columns are months | ||
2158 | while (column < m_numColumns) { | 2158 | while (column < m_numColumns) { | ||
2159 | QDate averageStart = columnDate(column); | 2159 | QDate averageStart = columnDate(column); | ||
2160 | 2160 | | |||
2161 | //set the right start date depending on the column type | 2161 | //set the right start date depending on the column type | ||
2162 | switch (m_config.columnType()) { | 2162 | switch (m_config.columnType()) { | ||
2163 | case MyMoneyReport::eYears: { | 2163 | case MyMoneyReport::Column::Years: { | ||
2164 | averageStart = QDate(columnDate(column).year(), 1, 1); | 2164 | averageStart = QDate(columnDate(column).year(), 1, 1); | ||
2165 | break; | 2165 | break; | ||
2166 | } | 2166 | } | ||
2167 | case MyMoneyReport::eBiMonths: { | 2167 | case MyMoneyReport::Column::BiMonths: { | ||
2168 | averageStart = QDate(columnDate(column).year(), columnDate(column).month(), 1).addMonths(-1); | 2168 | averageStart = QDate(columnDate(column).year(), columnDate(column).month(), 1).addMonths(-1); | ||
2169 | break; | 2169 | break; | ||
2170 | } | 2170 | } | ||
2171 | case MyMoneyReport::eQuarters: { | 2171 | case MyMoneyReport::Column::Quarters: { | ||
2172 | averageStart = QDate(columnDate(column).year(), columnDate(column).month(), 1).addMonths(-1); | 2172 | averageStart = QDate(columnDate(column).year(), columnDate(column).month(), 1).addMonths(-1); | ||
2173 | break; | 2173 | break; | ||
2174 | } | 2174 | } | ||
2175 | case MyMoneyReport::eMonths: { | 2175 | case MyMoneyReport::Column::Months: { | ||
2176 | averageStart = QDate(columnDate(column).year(), columnDate(column).month(), 1); | 2176 | averageStart = QDate(columnDate(column).year(), columnDate(column).month(), 1); | ||
2177 | break; | 2177 | break; | ||
2178 | } | 2178 | } | ||
2179 | case MyMoneyReport::eWeeks: { | 2179 | case MyMoneyReport::Column::Weeks: { | ||
2180 | averageStart = columnDate(column).addDays(-columnDate(column).dayOfWeek() + 1); | 2180 | averageStart = columnDate(column).addDays(-columnDate(column).dayOfWeek() + 1); | ||
2181 | break; | 2181 | break; | ||
2182 | } | 2182 | } | ||
2183 | default: | 2183 | default: | ||
2184 | break; | 2184 | break; | ||
2185 | } | 2185 | } | ||
2186 | 2186 | | |||
2187 | //gather the actual data and calculate the average | 2187 | //gather the actual data and calculate the average | ||
▲ Show 20 Lines • Show All 156 Lines • Show Last 20 Lines |