1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
|
/***************************************************************************
kforecastview.cpp
-------------------
copyright : (C) 2007 by Alvaro Soliverez
email : asoliverez@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
// ----------------------------------------------------------------------------
// QT Includes
#include <tqtabwidget.h>
#include <tqspinbox.h>
#include <tqlabel.h>
#include <tqbuttongroup.h>
#include <tqtextedit.h>
#include <tqlayout.h>
// ----------------------------------------------------------------------------
// KDE Includes
#include <kdebug.h>
#include <klocale.h>
#include <klistview.h>
#include <kpushbutton.h>
// ----------------------------------------------------------------------------
// Project Includes
#include <kmymoney/mymoneyfile.h>
#include "kforecastview.h"
#include "../kmymoneyglobalsettings.h"
#include "../kmymoney2.h"
#include "../kmymoneyutils.h"
#include "../mymoney/mymoneyforecast.h"
#include "../widgets/kmymoneyforecastlistviewitem.h"
#include "../widgets/kmymoneyaccounttreeforecast.h"
#include "../reports/pivottable.h"
#include "../reports/pivotgrid.h"
KForecastView::KForecastView(TQWidget *parent, const char *name) :
KForecastViewDecl(parent,name)
{
for(int i=0; i < MaxViewTabs; ++i)
m_needReload[i] = false;
KConfig *config = KGlobal::config();
config->setGroup("Last Use Settings");
m_tab->setCurrentPage(config->readNumEntry("KForecastView_LastType", 0));
connect(m_tab, TQT_SIGNAL(currentChanged(TQWidget*)), this, TQT_SLOT(slotTabChanged(TQWidget*)));
connect(MyMoneyFile::instance(), TQT_SIGNAL(dataChanged()), this, TQT_SLOT(slotLoadForecast()));
connect(m_forecastButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotManualForecast()));
m_forecastList->setAllColumnsShowFocus(true);
m_summaryList->setAllColumnsShowFocus(true);
//m_adviceList->setAllColumnsShowFocus(true);
m_advancedList->setAllColumnsShowFocus(true);
m_forecastChart = new KReportChartView(m_tabChart, "forecastChart" );
m_forecastChart->setSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding );
loadForecastSettings();
}
KForecastView::~KForecastView()
{
}
void KForecastView::slotTabChanged(TQWidget* _tab)
{
ForecastViewTab tab = static_cast<ForecastViewTab>(m_tab->indexOf(_tab));
// remember this setting for startup
KConfig *config = KGlobal::config();
config->setGroup("Last Use Settings");
config->writeEntry("KForecastView_LastType", tab);
loadForecast(tab);
}
void KForecastView::loadForecast(ForecastViewTab tab)
{
if(m_needReload[tab]) {
switch(tab) {
case ListView:
loadListView();
break;
case SummaryView:
loadSummaryView();
break;
case AdvancedView:
loadAdvancedView();
break;
case BudgetView:
loadBudgetView();
break;
case ChartView:
loadChartView();
break;
default:
break;
}
m_needReload[tab] = false;
}
}
void KForecastView::show(void)
{
// don't forget base class implementation
KForecastViewDecl::show();
slotTabChanged(m_tab->currentPage());
}
void KForecastView::slotLoadForecast(void)
{
m_needReload[SummaryView] = true;
m_needReload[ListView] = true;
m_needReload[AdvancedView] = true;
m_needReload[BudgetView] = true;
m_needReload[ChartView] = true;
//refresh settings
loadForecastSettings();
if(isVisible())
slotTabChanged(m_tab->currentPage());
}
void KForecastView::slotManualForecast(void)
{
m_needReload[SummaryView] = true;
m_needReload[ListView] = true;
m_needReload[AdvancedView] = true;
m_needReload[BudgetView] = true;
m_needReload[ChartView] = true;
if(isVisible())
slotTabChanged(m_tab->currentPage());
}
void KForecastView::loadForecastSettings(void)
{
//fill the settings controls
m_forecastDays->setValue(KMyMoneyGlobalSettings::forecastDays());
m_accountsCycle->setValue(KMyMoneyGlobalSettings::forecastAccountCycle());
m_beginDay->setValue(KMyMoneyGlobalSettings::beginForecastDay());
m_forecastCycles->setValue(KMyMoneyGlobalSettings::forecastCycles());
m_historyMethod->setButton(KMyMoneyGlobalSettings::historyMethod());
switch(KMyMoneyGlobalSettings::forecastMethod()) {
case 0:
m_forecastMethod->setText(i18n("Scheduled"));
m_forecastCycles->setDisabled(true);
m_historyMethod->setDisabled(true);
break;
case 1:
m_forecastMethod->setText(i18n("History"));
m_forecastCycles->setEnabled(true);
m_historyMethod->setEnabled(true);
break;
default:
m_forecastMethod->setText(i18n("Unknown"));
break;
}
}
void KForecastView::loadListView(void)
{
MyMoneyForecast forecast;
MyMoneyFile* file = MyMoneyFile::instance();
m_forecastList->setBaseCurrency(file->baseCurrency());
//get the settings from current page
forecast.setForecastDays(m_forecastDays->value());
forecast.setAccountsCycle(m_accountsCycle->value());
forecast.setBeginForecastDay(m_beginDay->value());
forecast.setForecastCycles(m_forecastCycles->value());
forecast.setHistoryMethod(m_historyMethod->selectedId());
forecast.doForecast();
//clear the list, including columns
m_forecastList->clearColumns();
//add columns
m_forecastList->showAccount();
m_forecastList->showDetailed(forecast);
//add default rows
addTotalRow(m_forecastList, forecast);
addAssetLiabilityRows(forecast);
//load asset and liability forecast accounts
loadAccounts(forecast, file->asset(), m_assetItem, KMyMoneyAccountTreeForecastItem::eDetailed);
loadAccounts(forecast, file->liability(), m_liabilityItem, KMyMoneyAccountTreeForecastItem::eDetailed);
m_forecastList->show();
}
void KForecastView::loadSummaryView(void)
{
MyMoneyForecast forecast;
TQValueList<MyMoneyAccount> accList;
int dropMinimum;
int dropZero;
MyMoneyFile* file = MyMoneyFile::instance();
m_summaryList->setBaseCurrency(file->baseCurrency());
//get the settings from current page
forecast.setForecastDays(m_forecastDays->value());
forecast.setAccountsCycle(m_accountsCycle->value());
forecast.setBeginForecastDay(m_beginDay->value());
forecast.setForecastCycles(m_forecastCycles->value());
forecast.setHistoryMethod(m_historyMethod->selectedId());
forecast.doForecast();
//clear the list, including columns
m_summaryList->clearColumns();
//add columns
m_summaryList->showAccount();
m_summaryList->showSummary(forecast);
//add default rows
addTotalRow(m_summaryList, forecast);
addAssetLiabilityRows(forecast);
loadAccounts(forecast, file->asset(), m_assetItem, KMyMoneyAccountTreeForecastItem::eSummary);
loadAccounts(forecast, file->liability(), m_liabilityItem, KMyMoneyAccountTreeForecastItem::eSummary);
//Add comments to the advice list
//Get all accounts of the right type to calculate forecast
m_nameIdx.clear();
accList = forecast.accountList();
TQValueList<MyMoneyAccount>::const_iterator accList_t = accList.begin();
for(; accList_t != accList.end(); ++accList_t ) {
MyMoneyAccount acc = *accList_t;
if(m_nameIdx[acc.id()] != acc.id()) { //Check if the account is there
m_nameIdx[acc.id()] = acc.id();
}
}
TQMap<TQString, TQString>::ConstIterator it_nc;
for(it_nc = m_nameIdx.begin(); it_nc != m_nameIdx.end(); ++it_nc) {
const MyMoneyAccount& acc = file->account(*it_nc);
MyMoneySecurity currency;
//change currency to deep currency if account is an investment
if(acc.isInvest()) {
MyMoneySecurity underSecurity = file->security(acc.currencyId());
currency = file->security(underSecurity.tradingCurrency());
} else {
currency = file->security(acc.currencyId());
}
//Check if the account is going to be below zero or below the minimal balance in the forecast period
TQString minimumBalance = acc.value("minimumBalance");
MyMoneyMoney minBalance = MyMoneyMoney(minimumBalance);
//Check if the account is going to be below minimal balance
dropMinimum = forecast.daysToMinimumBalance(acc);
//Check if the account is going to be below zero in the future
dropZero = forecast.daysToZeroBalance(acc);
// spit out possible warnings
TQString msg;
// if a minimum balance has been specified, an appropriate warning will
// only be shown, if the drop below 0 is on a different day or not present
if(dropMinimum != -1
&& !minBalance.isZero()
&& (dropMinimum < dropZero
|| dropZero == -1)) {
switch(dropMinimum) {
case -1:
break;
case 0:
msg = TQString("<font color=\"%1\">").arg(KMyMoneyGlobalSettings::listNegativeValueColor().name());
msg += i18n("The balance of %2 is below the minimum balance %3 today.").arg(acc.name()).arg(minBalance.formatMoney(acc, currency));
msg += TQString("</font>");
break;
default:
msg = TQString("<font color=\"%1\">").arg(KMyMoneyGlobalSettings::listNegativeValueColor().name());
msg += i18n("The balance of %1 will drop below the minimum balance %2 in %3 days.").arg(acc.name()).arg(minBalance.formatMoney(acc, currency)).arg(dropMinimum-1);
msg += TQString("</font>");
}
if(!msg.isEmpty()) {
m_adviceText->append(msg);
}
}
// a drop below zero is always shown
msg = TQString();
switch(dropZero) {
case -1:
break;
case 0:
if(acc.accountGroup() == MyMoneyAccount::Asset) {
msg = TQString("<font color=\"%1\">").arg(KMyMoneyGlobalSettings::listNegativeValueColor().name());
msg += i18n("The balance of %1 is below %2 today.").arg(acc.name()).arg(MyMoneyMoney().formatMoney(acc, currency));
msg += TQString("</font>");
break;
}
if(acc.accountGroup() == MyMoneyAccount::Liability) {
msg = i18n("The balance of %1 is above %2 today.").arg(acc.name()).arg(MyMoneyMoney().formatMoney(acc, currency));
break;
}
break;
default:
if(acc.accountGroup() == MyMoneyAccount::Asset) {
msg = TQString("<font color=\"%1\">").arg(KMyMoneyGlobalSettings::listNegativeValueColor().name());
msg += i18n("The balance of %1 will drop below %2 in %3 days.").arg(acc.name()).arg(MyMoneyMoney().formatMoney(acc, currency)).arg(dropZero);
msg += TQString("</font>");
break;
}
if(acc.accountGroup() == MyMoneyAccount::Liability) {
msg = i18n("The balance of %1 will raise above %2 in %3 days.").arg(acc.name()).arg(MyMoneyMoney().formatMoney(acc, currency)).arg(dropZero);
break;
}
}
if(!msg.isEmpty()) {
m_adviceText->append(msg);
}
//advice about trends
msg = TQString();
MyMoneyMoney accCycleVariation = forecast.accountCycleVariation(acc);
if (accCycleVariation < MyMoneyMoney(0, 1)) {
msg = TQString("<font color=\"%1\">").arg(KMyMoneyGlobalSettings::listNegativeValueColor().name());
msg += i18n("The account %1 is decreasing %2 per cycle.").arg(acc.name()).arg(accCycleVariation.formatMoney(acc, currency));
msg += TQString("</font>");
}
if(!msg.isEmpty()) {
m_adviceText->append(msg);
}
}
m_summaryList->show();
m_adviceText->show();
}
void KForecastView::loadAdvancedView(void)
{
MyMoneyFile* file = MyMoneyFile::instance();
TQValueList<MyMoneyAccount> accList;
MyMoneySecurity baseCurrency = file->baseCurrency();
MyMoneyForecast forecast;
int daysToBeginDay;
//get the settings from current page
forecast.setForecastDays(m_forecastDays->value());
forecast.setAccountsCycle(m_accountsCycle->value());
forecast.setBeginForecastDay(m_beginDay->value());
forecast.setForecastCycles(m_forecastCycles->value());
forecast.setHistoryMethod(m_historyMethod->selectedId());
forecast.doForecast();
//Get all accounts of the right type to calculate forecast
m_nameIdx.clear();
accList = forecast.accountList();
TQValueList<MyMoneyAccount>::const_iterator accList_t = accList.begin();
for(; accList_t != accList.end(); ++accList_t ) {
MyMoneyAccount acc = *accList_t;
if(m_nameIdx[acc.id()] != acc.id()) { //Check if the account is there
m_nameIdx[acc.id()] = acc.id();
}
}
//clear the list, including columns
m_advancedList->clear();
for(;m_advancedList->columns() > 0;) {
m_advancedList->removeColumn(0);
}
//add first column of both lists
int accountColumn = m_advancedList->addColumn(i18n("Account"), -1);
//if beginning of forecast is today, set the begin day to next cycle to avoid repeating the first cycle
if(TQDate::currentDate() < forecast.beginForecastDate()) {
daysToBeginDay = TQDate::currentDate().daysTo(forecast.beginForecastDate());
} else {
daysToBeginDay = forecast.accountsCycle();
}
//add columns
for(int i = 1; ((i * forecast.accountsCycle()) + daysToBeginDay) <= forecast.forecastDays(); ++i) {
int col = m_advancedList->addColumn(i18n("Min Bal %1").arg(i), -1);
m_advancedList->setColumnAlignment(col, TQt::AlignRight);
m_advancedList->addColumn(i18n("Min Date %1").arg(i), -1);
}
for(int i = 1; ((i * forecast.accountsCycle()) + daysToBeginDay) <= forecast.forecastDays(); ++i) {
int col = m_advancedList->addColumn(i18n("Max Bal %1").arg(i), -1);
m_advancedList->setColumnAlignment(col, TQt::AlignRight);
m_advancedList->addColumn(i18n("Max Date %1").arg(i), -1);
}
int col = m_advancedList->addColumn(i18n("Average"), -1);
m_advancedList->setColumnAlignment(col, TQt::AlignRight);
m_advancedList->setSorting(-1);
KMyMoneyForecastListViewItem *advancedItem = 0;
TQMap<TQString, TQString>::ConstIterator it_nc;
for(it_nc = m_nameIdx.begin(); it_nc != m_nameIdx.end(); ++it_nc) {
const MyMoneyAccount& acc = file->account(*it_nc);
TQString amount;
MyMoneyMoney amountMM;
MyMoneySecurity currency;
//change currency to deep currency if account is an investment
if(acc.isInvest()) {
MyMoneySecurity underSecurity = file->security(acc.currencyId());
currency = file->security(underSecurity.tradingCurrency());
} else {
currency = file->security(acc.currencyId());
}
advancedItem = new KMyMoneyForecastListViewItem(m_advancedList, advancedItem, false);
advancedItem->setText(accountColumn, acc.name());
int it_c = 1; // iterator for the columns of the listview
//get minimum balance list
TQValueList<TQDate> minBalanceList = forecast.accountMinimumBalanceDateList(acc);
TQValueList<TQDate>::Iterator t_min;
for(t_min = minBalanceList.begin(); t_min != minBalanceList.end() ; ++t_min)
{
TQDate minDate = *t_min;
amountMM = forecast.forecastBalance(acc, minDate);
amount = amountMM.formatMoney(acc, currency);
advancedItem->setText(it_c, amount, amountMM.isNegative());
it_c++;
TQString dateString = KGlobal::locale()->formatDate(minDate, true);
advancedItem->setText(it_c, dateString, amountMM.isNegative());
it_c++;
}
//get maximum balance list
TQValueList<TQDate> maxBalanceList = forecast.accountMaximumBalanceDateList(acc);
TQValueList<TQDate>::Iterator t_max;
for(t_max = maxBalanceList.begin(); t_max != maxBalanceList.end() ; ++t_max)
{
TQDate maxDate = *t_max;
amountMM = forecast.forecastBalance(acc, maxDate);
amount = amountMM.formatMoney(acc, currency);
advancedItem->setText(it_c, amount, amountMM.isNegative());
it_c++;
TQString dateString = KGlobal::locale()->formatDate(maxDate, true);
advancedItem->setText(it_c, dateString, amountMM.isNegative());
it_c++;
}
//get average balance
amountMM = forecast.accountAverageBalance(acc);
amount = amountMM.formatMoney(acc, currency);
advancedItem->setText(it_c, amount, amountMM.isNegative());
it_c++;
}
m_advancedList->show();
}
void KForecastView::loadBudgetView(void)
{
MyMoneyFile* file = MyMoneyFile::instance();
MyMoneyForecast forecast;
// TQValueList<MyMoneyAccount> accList;
m_budgetList->setBaseCurrency(file->baseCurrency());
//get the settings from current page and calculate this year based on last year
TQDate historyEndDate = TQDate(TQDate::currentDate().year()-1, 12, 31);
TQDate historyStartDate = historyEndDate.addDays(-m_accountsCycle->value() * m_forecastCycles->value());
TQDate forecastStartDate = TQDate(TQDate::currentDate().year(), 1, 1);
TQDate forecastEndDate = TQDate::currentDate().addDays(m_forecastDays->value());
forecast.setHistoryMethod(m_historyMethod->selectedId());
MyMoneyBudget budget;
forecast.createBudget(budget, historyStartDate, historyEndDate, forecastStartDate, forecastEndDate, false);
//clear the list, including columns
m_budgetList->clearColumns();
//add columns
m_budgetList->showAccount();
m_budgetList->showBudget(forecast);
//add default rows
addTotalRow(m_budgetList, forecast);
addIncomeExpenseRows(forecast);
//load income and expense budget accounts
loadAccounts(forecast, file->income(), m_incomeItem, KMyMoneyAccountTreeForecastItem::eBudget);
loadAccounts(forecast, file->expense(), m_expenseItem, KMyMoneyAccountTreeForecastItem::eBudget);
m_budgetList->show();
}
TQValueList<MyMoneyPrice> KForecastView::getAccountPrices(const MyMoneyAccount& acc)
{
MyMoneyFile* file = MyMoneyFile::instance();
TQValueList<MyMoneyPrice> prices;
MyMoneySecurity security = file->baseCurrency();
try {
if(acc.isInvest()) {
security = file->security(acc.currencyId());
if(security.tradingCurrency() != file->baseCurrency().id()) {
MyMoneySecurity sec = file->security(security.tradingCurrency());
prices += file->price(sec.id(), file->baseCurrency().id());
}
} else if(acc.currencyId() != file->baseCurrency().id()) {
if(acc.currencyId() != file->baseCurrency().id()) {
security = file->security(acc.currencyId());
prices += file->price(acc.currencyId(), file->baseCurrency().id());
}
}
} catch(MyMoneyException *e) {
kdDebug(2) << __PRETTY_FUNCTION__ << " caught exception while adding " << acc.name() << "[" << acc.id() << "]: " << e->what();
delete e;
}
return prices;
}
void KForecastView::addAssetLiabilityRows(const MyMoneyForecast& forecast)
{
MyMoneyFile* file = MyMoneyFile::instance();
TQValueList<MyMoneyPrice> basePrices;
m_assetItem = new KMyMoneyAccountTreeForecastItem( m_totalItem, file->asset(), forecast, basePrices, file->baseCurrency() );
m_assetItem->setOpen(true);
m_liabilityItem = new KMyMoneyAccountTreeForecastItem( m_totalItem, file->liability(), forecast, basePrices, file->baseCurrency());
m_liabilityItem->setOpen(true);
}
void KForecastView::addIncomeExpenseRows(const MyMoneyForecast& forecast)
{
MyMoneyFile* file = MyMoneyFile::instance();
TQValueList<MyMoneyPrice> basePrices;
m_incomeItem = new KMyMoneyAccountTreeForecastItem( m_totalItem, file->income(), forecast, basePrices, file->baseCurrency() );
m_incomeItem->setOpen(true);
m_expenseItem = new KMyMoneyAccountTreeForecastItem( m_totalItem, file->expense(), forecast, basePrices, file->baseCurrency());
m_expenseItem->setOpen(true);
}
void KForecastView::addTotalRow(KMyMoneyAccountTreeForecast* forecastList, const MyMoneyForecast& forecast)
{
MyMoneyFile* file = MyMoneyFile::instance();
m_totalItem = new KMyMoneyAccountTreeForecastItem( forecastList, file->asset(), forecast, file->baseCurrency(), i18n("Total") );
m_totalItem->setOpen(true);
}
bool KForecastView::includeAccount(MyMoneyForecast& forecast, const MyMoneyAccount& acc)
{
MyMoneyFile* file = MyMoneyFile::instance();
if( forecast.isForecastAccount(acc) )
return true;
TQStringList accounts = acc.accountList();
if(accounts.size() > 0) {
TQStringList::ConstIterator it_acc;
for(it_acc = accounts.begin(); it_acc != accounts.end(); ++it_acc) {
MyMoneyAccount account = file->account(*it_acc);
if( includeAccount(forecast, account) )
return true;
}
}
return false;
}
void KForecastView::loadAccounts(MyMoneyForecast& forecast, const MyMoneyAccount& account, KMyMoneyAccountTreeForecastItem* parentItem, int forecastType )
{
TQMap<TQString, TQString> nameIdx;
TQStringList accList;
MyMoneyFile* file = MyMoneyFile::instance();
KMyMoneyAccountTreeForecastItem *forecastItem = 0;
//Get all accounts of the right type to calculate forecast
accList = account.accountList();
if(accList.size() == 0)
return;
TQStringList::ConstIterator accList_t;
for(accList_t = accList.begin(); accList_t != accList.end(); ++accList_t ) {
MyMoneyAccount subAccount = file->account(*accList_t);
//only add the account if it is a forecast account or the parent of a forecast account
if(includeAccount(forecast, subAccount)) {
nameIdx[subAccount.id()] = subAccount.id();
}
}
TQMap<TQString, TQString>::ConstIterator it_nc;
for(it_nc = nameIdx.begin(); it_nc != nameIdx.end(); ++it_nc) {
const MyMoneyAccount subAccount = file->account(*it_nc);
MyMoneySecurity currency;
if(subAccount.isInvest()) {
MyMoneySecurity underSecurity = file->security(subAccount.currencyId());
currency = file->security(underSecurity.tradingCurrency());
} else {
currency = file->security(subAccount.currencyId());
}
TQString amount;
TQString vAmount;
MyMoneyMoney vAmountMM;
//get prices
TQValueList<MyMoneyPrice> prices = getAccountPrices(subAccount);
forecastItem = new KMyMoneyAccountTreeForecastItem( parentItem, subAccount, forecast, prices, currency, static_cast<KMyMoneyAccountTreeForecastItem::EForecastViewType>(forecastType) );
forecastItem->setOpen(true);
loadAccounts(forecast, subAccount, forecastItem, forecastType);
}
}
void KForecastView::loadChartView(void)
{
MyMoneyReport::EDetailLevel detailLevel[4] = { MyMoneyReport::eDetailAll, MyMoneyReport::eDetailTop, MyMoneyReport::eDetailGroup, MyMoneyReport::eDetailTotal };
MyMoneyReport reportCfg = MyMoneyReport(
MyMoneyReport::eAssetLiability,
MyMoneyReport::eMonths,
MyMoneyTransactionFilter::userDefined, // overridden by the setDateFilter() call below
detailLevel[m_comboDetail->currentItem()],
i18n("Networth Forecast"),
i18n("Generated Report"));
reportCfg.setChartByDefault(true);
reportCfg.setChartGridLines(false);
reportCfg.setChartType(MyMoneyReport::eChartLine);
reportCfg.setIncludingSchedules( false );
reportCfg.addAccountGroup(MyMoneyAccount::Asset);
reportCfg.addAccountGroup(MyMoneyAccount::Liability);
reportCfg.setColumnsAreDays( true );
reportCfg.setConvertCurrency( true );
reportCfg.setIncludingForecast( true );
reportCfg.setDateFilter(TQDate::currentDate(),TQDate::currentDate().addDays(m_forecastDays->value()));
reports::PivotTable table(reportCfg);
table.drawChart(*m_forecastChart);
// Adjust the size
m_forecastChart->resize(m_tab->width()-30, m_tab->height()-60);
m_forecastChart->update();
}
#include "kforecastview.moc"
|