1 /*
2  * Copyright 2004-2006  Ace Jones <acejones@users.sourceforge.net>
3  * Copyright 2006       Darren Gould <darren_gould@gmx.de>
4  * Copyright 2007-2010  Alvaro Soliverez <asoliverez@gmail.com>
5  * Copyright 2017-2018  Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
6  * Copyright 2018       Michael Kiefer <Michael-Kiefer@web.de>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef MYMONEYREPORT_P_H
23 #define MYMONEYREPORT_P_H
24 
25 #include "mymoneyreport.h"
26 
27 // ----------------------------------------------------------------------------
28 // QT Includes
29 
30 #include <QString>
31 #include <QHash>
32 #include <QDate>
33 #include <QList>
34 
35 // ----------------------------------------------------------------------------
36 // KDE Includes
37 
38 // ----------------------------------------------------------------------------
39 // Project Includes
40 
41 #include "mymoneyobject_p.h"
42 #include "mymoneyenums.h"
43 
44 class MyMoneyReportPrivate : public MyMoneyObjectPrivate
45 {
46 public:
MyMoneyReportPrivate()47   MyMoneyReportPrivate() :
48     m_name(QStringLiteral("Unconfigured Pivot Table Report")),
49     m_detailLevel(eMyMoney::Report::DetailLevel::None),
50     m_investmentSum(eMyMoney::Report::InvestmentSum::Sold),
51     m_hideTransactions(false),
52     m_convertCurrency(true),
53     m_favorite(false),
54     m_tax(false),
55     m_investments(false),
56     m_loans(false),
57     m_reportType(rowTypeToReportType(eMyMoney::Report::RowType::ExpenseIncome)),
58     m_rowType(eMyMoney::Report::RowType::ExpenseIncome),
59     m_columnType(eMyMoney::Report::ColumnType::Months),
60     m_columnsAreDays(false),
61     m_queryColumns(eMyMoney::Report::QueryColumn::None),
62     m_dateLock(eMyMoney::TransactionFilter::Date::UserDefined),
63     m_accountGroupFilter(false),
64     m_chartType(eMyMoney::Report::ChartType::Line),
65     m_chartPalette(eMyMoney::Report::ChartPalette::Application),
66     m_chartDataLabels(true),
67     m_chartCHGridLines(true),
68     m_chartSVGridLines(true),
69     m_chartByDefault(false),
70     m_chartLineWidth(MyMoneyReport::m_lineWidth),
71     m_logYaxis(false),
72     m_negExpenses(false),
73     m_dataRangeStart('0'),
74     m_dataRangeEnd('0'),
75     m_dataMajorTick('0'),
76     m_dataMinorTick('0'),
77     m_yLabelsPrecision(2),
78     m_dataLock(eMyMoney::Report::DataLock::Automatic),
79     m_includeSchedules(false),
80     m_includeTransfers(false),
81     m_includeBudgetActuals(false),
82     m_includeUnusedAccounts(false),
83     m_showRowTotals(false),
84     m_showColumnTotals(true),
85     m_includeForecast(false),
86     m_includeMovingAverage(false),
87     m_movingAverageDays(0),
88     m_includePrice(false),
89     m_includeAveragePrice(false),
90     m_mixedTime(false),
91     m_currentDateColumn(0),
92     m_settlementPeriod(3),
93     m_showSTLTCapitalGains(false),
94     m_tseparator(QDate::currentDate().addYears(-1)),
95     m_skipZero(false)
96   {
97   }
98 
rowTypeToReportType(eMyMoney::Report::RowType rowType)99   static eMyMoney::Report::ReportType rowTypeToReportType(eMyMoney::Report::RowType rowType)
100   {
101     static const QHash<eMyMoney::Report::RowType, eMyMoney::Report::ReportType> reportTypes {
102       {eMyMoney::Report::RowType::NoRows,               eMyMoney::Report::ReportType::NoReport},
103       {eMyMoney::Report::RowType::AssetLiability,       eMyMoney::Report::ReportType::PivotTable},
104       {eMyMoney::Report::RowType::ExpenseIncome,        eMyMoney::Report::ReportType::PivotTable},
105       {eMyMoney::Report::RowType::Category,             eMyMoney::Report::ReportType::QueryTable},
106       {eMyMoney::Report::RowType::TopCategory,          eMyMoney::Report::ReportType::QueryTable},
107       {eMyMoney::Report::RowType::Account,              eMyMoney::Report::ReportType::QueryTable},
108       {eMyMoney::Report::RowType::Tag,                  eMyMoney::Report::ReportType::QueryTable},
109       {eMyMoney::Report::RowType::Payee,                eMyMoney::Report::ReportType::QueryTable},
110       {eMyMoney::Report::RowType::Month,                eMyMoney::Report::ReportType::QueryTable},
111       {eMyMoney::Report::RowType::Week,                 eMyMoney::Report::ReportType::QueryTable},
112       {eMyMoney::Report::RowType::TopAccount,           eMyMoney::Report::ReportType::QueryTable},
113       {eMyMoney::Report::RowType::AccountByTopAccount,  eMyMoney::Report::ReportType::QueryTable},
114       {eMyMoney::Report::RowType::EquityType,           eMyMoney::Report::ReportType::QueryTable},
115       {eMyMoney::Report::RowType::AccountType,          eMyMoney::Report::ReportType::QueryTable},
116       {eMyMoney::Report::RowType::Institution,          eMyMoney::Report::ReportType::QueryTable},
117       {eMyMoney::Report::RowType::Budget,               eMyMoney::Report::ReportType::PivotTable},
118       {eMyMoney::Report::RowType::BudgetActual,         eMyMoney::Report::ReportType::PivotTable},
119       {eMyMoney::Report::RowType::Schedule,             eMyMoney::Report::ReportType::InfoTable},
120       {eMyMoney::Report::RowType::AccountInfo,          eMyMoney::Report::ReportType::InfoTable},
121       {eMyMoney::Report::RowType::AccountLoanInfo,      eMyMoney::Report::ReportType::InfoTable},
122       {eMyMoney::Report::RowType::AccountReconcile,     eMyMoney::Report::ReportType::QueryTable},
123       {eMyMoney::Report::RowType::CashFlow,             eMyMoney::Report::ReportType::QueryTable},
124     };
125     return reportTypes.value(rowType, eMyMoney::Report::ReportType::Invalid);
126   }
127 
128   /**
129     * The user-assigned name of the report
130     */
131   QString m_name;
132   /**
133     * The user-assigned comment for the report, in case they want to make
134     * additional notes for themselves about the report.
135     */
136   QString m_comment;
137   /**
138     * Where to group this report amongst the others in the UI view.  This
139     * should be assigned by the UI system.
140     */
141   QString m_group;
142   /**
143     * How much detail to show in the accounts
144     */
145   eMyMoney::Report::DetailLevel m_detailLevel;
146   /**
147     * Whether to sum: all, sold, bought or owned value
148     */
149   eMyMoney::Report::InvestmentSum m_investmentSum;
150   /**
151     * Whether to show transactions or just totals.
152     */
153   bool m_hideTransactions;
154   /**
155     * Whether to convert all currencies to the base currency of the file (true).
156     * If this is false, it's up to the report generator to decide how to handle
157     * the currency.
158     */
159   bool m_convertCurrency;
160   /**
161     * Whether this is one of the users' favorite reports
162     */
163   bool m_favorite;
164   /**
165     * Whether this report should only include categories marked as "Tax"="Yes"
166     */
167   bool m_tax;
168   /**
169     * Whether this report should only include investment accounts
170     */
171   bool m_investments;
172   /**
173     * Whether this report should only include loan accounts
174     * Applies only to querytable reports.  Mutually exclusive with
175     * m_investments.
176     */
177   bool m_loans;
178   /**
179     * What sort of algorithm should be used to run the report
180     */
181   eMyMoney::Report::ReportType m_reportType;
182   /**
183     * What sort of values should show up on the ROWS of this report
184     */
185   eMyMoney::Report::RowType m_rowType;
186   /**
187     * What sort of values should show up on the COLUMNS of this report,
188     * in the case of a 'PivotTable' report.  Really this is used more as a
189     * QUANTITY of months or days.  Whether it's months or days is determined
190     * by m_columnsAreDays.
191     */
192   eMyMoney::Report::ColumnType m_columnType;
193   /**
194    * Whether the base unit of columns of this report is days.  Only applies to
195    * 'PivotTable' reports.  If false, then columns are months or multiples thereof.
196    */
197   bool m_columnsAreDays;
198   /**
199      * What sort of values should show up on the COLUMNS of this report,
200      * in the case of a 'QueryTable' report
201      */
202   eMyMoney::Report::QueryColumn m_queryColumns;
203 
204   /**
205     * The plain-language description of what the date range should be locked
206     * to.  'userDefined' means NO locking, in any other case, the report
207     * will be adjusted to match the date lock.  So if the date lock is
208     * 'currentMonth', the start and end dates of the underlying filter will
209     * be updated to whatever the current month is.  This updating happens
210     * automatically when the report is loaded, and should also be done
211     * manually by calling updateDateFilter() before generating the report
212     */
213   eMyMoney::TransactionFilter::Date m_dateLock;
214   /**
215     * Which account groups should be included in the report.  This filter
216     * is applied to the individual splits AFTER a transaction has been
217     * matched using the underlying filter.
218     */
219   QList<eMyMoney::Account::Type> m_accountGroups;
220   /**
221     * Whether an account group filter has been set (see m_accountGroups)
222     */
223   bool m_accountGroupFilter;
224   /**
225     * What format should be used to draw this report as a chart
226     */
227   eMyMoney::Report::ChartType m_chartType;
228   /**
229     * What color palette should be used to draw this report as a chart
230     */
231   eMyMoney::Report::ChartPalette m_chartPalette;
232   /**
233     * Whether the value of individual data points should be drawn on the chart
234     */
235   bool m_chartDataLabels;
236   /**
237     * Whether grid lines should be drawn on the chart
238     */
239   bool m_chartCHGridLines;
240   bool m_chartSVGridLines;
241   /**
242     * Whether this report should be shown as a chart by default (otherwise it
243     * should be shown as a textual report)
244     */
245   bool m_chartByDefault;
246   /**
247    * Width of the chart lines
248    */
249   uint m_chartLineWidth;
250 
251   /**
252     * Whether Y axis is logarithmic or linear
253     */
254   bool m_logYaxis;
255 
256   /**
257     * Whether expenses should be plotted downwards
258     */
259   bool m_negExpenses;
260 
261   /**
262     * Y data range
263     */
264   QString m_dataRangeStart;
265   QString m_dataRangeEnd;
266 
267   /**
268     * Y data range division
269     */
270   QString m_dataMajorTick;
271   QString m_dataMinorTick;
272 
273   /**
274     * Y labels precision
275     */
276   uint m_yLabelsPrecision;
277 
278   /**
279     * Whether data range should be calculated automatically or is user defined
280     */
281   eMyMoney::Report::DataLock m_dataLock;
282 
283   /**
284     * Whether to include scheduled transactions
285     */
286   bool m_includeSchedules;
287   /**
288     * Whether to include transfers.  Only applies to Income/Expense reports
289     */
290   bool m_includeTransfers;
291   /**
292     * The id of the budget associated with this report.
293     */
294   QString m_budgetId;
295   /**
296     * Whether this report should print the actual data to go along with
297     * the budget.  This is only valid if the report has a budget.
298     */
299   bool m_includeBudgetActuals;
300   /**
301     * Whether this report should include all accounts and not only
302     * accounts with transactions.
303     */
304   bool m_includeUnusedAccounts;
305   /**
306    * Whether this report should include columns for row totals
307    */
308   bool m_showRowTotals;
309   /**
310    * Whether this report should include rows for column totals
311    */
312   bool m_showColumnTotals;
313   /**
314    * Whether this report should include forecast balance
315    */
316   bool m_includeForecast;
317   /**
318    * Whether this report should include moving average
319    */
320   bool m_includeMovingAverage;
321   /**
322    * The amount of days that spans each moving average
323    */
324   int m_movingAverageDays;
325   /**
326    * Whether this report should include prices
327    */
328   bool m_includePrice;
329   /**
330    * Whether this report should include moving average prices
331    */
332   bool m_includeAveragePrice;
333   /**
334    * Make the actual and forecast lines display as one
335    */
336   bool m_mixedTime;
337   /**
338    * This stores the column for the current date
339    * This value is calculated dynamically and thus it is not saved in the file
340    */
341   int m_currentDateColumn;
342   /**
343    * Time in days between the settlement date and the transaction date.
344    */
345   uint m_settlementPeriod;
346   /**
347    * Controls showing short-term and long-term capital gains.
348    */
349   bool m_showSTLTCapitalGains;
350   /**
351    * Date separating shot-term from long-term gains.
352    */
353   QDate m_tseparator;
354 
355   /**
356     * This option is for investments reports only which
357     * show prices instead of balances as all other reports do.
358     * <p>
359     * Select this option to include prices for the given period (week, month,
360     * quarter, ...) only.
361     * </p>
362     * <p>
363     * If this option is off the last existing price is shown for a period, if
364     * it is on, in a table the value is '0' shown and in a chart a linear
365     * interpolation for the missing values will be performed.
366     * <br>Example:
367     * <br>There are prices for January and March, but there is no price for
368     * February.
369     * <ul>
370     * <li><b>OFF</b>: shows the price for February as the last price of
371     * January
372     * <li><b>ON</b>: in a table the value is '0', in a chart a linear
373     * interpolation for the February-price will be performed
374     * (so it makes a kind of average-value using the January- and the
375     * March-price in the chart)
376     * </ul>
377     * </p>
378     */
379   bool m_skipZero;
380 };
381 
382 #endif
383