void MyMoneyForecast::addScheduledTransactions (void) { MyMoneyFile* file = MyMoneyFile::instance(); // now process all the schedules that may have an impact QValueList<MyMoneySchedule> schedule; schedule = file->scheduleList("", MyMoneySchedule::TYPE_ANY, MyMoneySchedule::OCCUR_ANY, MyMoneySchedule::STYPE_ANY, QDate(), forecastEndDate()); if(schedule.count() > 0) { QValueList<MyMoneySchedule>::Iterator it; do { qBubbleSort(schedule); it = schedule.begin(); if(it == schedule.end()) break; if((*it).isFinished()) { schedule.erase(it); continue; } QDate date = (*it).nextPayment((*it).lastPayment()); if(!date.isValid()) { schedule.remove(it); continue; } QDate nextDate = (*it).adjustedNextPayment((*it).adjustedDate((*it).lastPayment(), (*it).weekendOption())); if (nextDate > forecastEndDate()) { // We're done with this schedule, let's move on to the next schedule.remove(it); continue; } // found the next schedule. process it MyMoneyAccount acc = (*it).account(); if(!acc.id().isEmpty()) { try { if(acc.accountType() != MyMoneyAccount::Investment) { MyMoneyTransaction t = (*it).transaction(); // only process the entry, if it is still active if(!(*it).isFinished() && nextDate != QDate()) { // make sure we have all 'starting balances' so that the autocalc works QValueList<MyMoneySplit>::const_iterator it_s; QMap<QString, MyMoneyMoney> balanceMap; for(it_s = t.splits().begin(); it_s != t.splits().end(); ++it_s ) { MyMoneyAccount acc = file->account((*it_s).accountId()); if(isForecastAccount(acc)) { // collect all overdues on the first day QDate forecastDate = nextDate; if(QDate::currentDate() >= nextDate) forecastDate = QDate::currentDate().addDays(1); dailyBalances balance; balance = m_accountList[acc.id()]; for(QDate f_day = QDate::currentDate(); f_day < forecastDate; ) { balanceMap[acc.id()] += m_accountList[acc.id()][f_day]; f_day = f_day.addDays(1); } } } // take care of the autoCalc stuff calculateAutoLoan(*it, t, balanceMap); // now add the splits to the balances for(it_s = t.splits().begin(); it_s != t.splits().end(); ++it_s ) { MyMoneyAccount acc = file->account((*it_s).accountId()); if(isForecastAccount(acc)) { dailyBalances balance; balance = m_accountList[acc.id()]; //int offset = QDate::currentDate().daysTo(nextDate); //if(offset <= 0) { // collect all overdues on the first day // offset = 1; //} // collect all overdues on the first day QDate forecastDate = nextDate; if(QDate::currentDate() >= nextDate) forecastDate = QDate::currentDate().addDays(1); if(acc.accountType() == MyMoneyAccount::Income) { balance[forecastDate] += ((*it_s).shares() * MyMoneyMoney(-1, 1)); } else { balance[forecastDate] += (*it_s).shares(); } m_accountList[acc.id()] = balance; } } } } (*it).setLastPayment(date); } catch(MyMoneyException* e) { kdDebug(2) << __func__ << " Schedule " << (*it).id() << " (" << (*it).name() << "): " << e->what() << endl; schedule.remove(it); delete e; } } else { // remove schedule from list schedule.remove(it); } } while(1); } #if 0 { s << "\n\nAdded scheduled transactions\n"; QMap<QString, dailyBalances>::Iterator it_a; QMap<QString, QString>::ConstIterator it_n; for(it_n = m_nameIdx.begin(); it_n != m_nameIdx.end(); ++it_n) { MyMoneyAccount acc = file->account(*it_n); it_a = m_accountList.find(*it_n); s << "\"" << acc.name() << "\","; for(int i = 0; i < 90; ++i) { s << "\"" << (*it_a)[i].formatMoney("") << "\","; } s << "\n"; } } #endif }