Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/mymoney/mymoneyforecast.cpp
Context not available. | |||||
31 | // Project Includes | 31 | // Project Includes | ||
---|---|---|---|---|---|
32 | 32 | | |||
33 | #include "mymoneyfile.h" | 33 | #include "mymoneyfile.h" | ||
34 | #include "mymoneysecurity.h" | ||||
35 | #include "mymoneybudget.h" | ||||
36 | #include "mymoneyschedule.h" | ||||
37 | #include "mymoneyprice.h" | ||||
38 | #include "mymoneytransaction.h" | ||||
34 | #include "mymoneytransactionfilter.h" | 39 | #include "mymoneytransactionfilter.h" | ||
35 | #include "mymoneyfinancialcalculator.h" | 40 | #include "mymoneyfinancialcalculator.h" | ||
36 | 41 | | |||
Context not available. | |||||
125 | 130 | | |||
126 | //workaround for stock accounts which have faulty opening dates | 131 | //workaround for stock accounts which have faulty opening dates | ||
127 | QDate openingDate; | 132 | QDate openingDate; | ||
128 | if (acc.accountType() == MyMoneyAccount::Stock) { | 133 | if (acc.accountType() == eMyMoney::Account::Stock) { | ||
129 | MyMoneyAccount parentAccount = file->account(acc.parentAccountId()); | 134 | MyMoneyAccount parentAccount = file->account(acc.parentAccountId()); | ||
130 | openingDate = parentAccount.openingDate(); | 135 | openingDate = parentAccount.openingDate(); | ||
131 | } else { | 136 | } else { | ||
Context not available. | |||||
138 | dailyBalances balance; | 143 | dailyBalances balance; | ||
139 | //FIXME deal with leap years | 144 | //FIXME deal with leap years | ||
140 | balance = m_accountListPast[acc.id()]; | 145 | balance = m_accountListPast[acc.id()]; | ||
141 | if (acc.accountType() == MyMoneyAccount::Income) {//if it is income, the balance is stored as negative number | 146 | if (acc.accountType() == eMyMoney::Account::Income) {//if it is income, the balance is stored as negative number | ||
142 | balance[(*it_t).postDate()] += ((*it_s).shares() * MyMoneyMoney::MINUS_ONE); | 147 | balance[(*it_t).postDate()] += ((*it_s).shares() * MyMoneyMoney::MINUS_ONE); | ||
143 | } else { | 148 | } else { | ||
144 | balance[(*it_t).postDate()] += (*it_s).shares(); | 149 | balance[(*it_t).postDate()] += (*it_s).shares(); | ||
Context not available. | |||||
214 | if (skipOpeningDate()) { | 219 | if (skipOpeningDate()) { | ||
215 | 220 | | |||
216 | QDate openingDate; | 221 | QDate openingDate; | ||
217 | if (acc.accountType() == MyMoneyAccount::Stock) { | 222 | if (acc.accountType() == eMyMoney::Account::Stock) { | ||
218 | MyMoneyAccount parentAccount = file->account(acc.parentAccountId()); | 223 | MyMoneyAccount parentAccount = file->account(acc.parentAccountId()); | ||
219 | openingDate = parentAccount.openingDate(); | 224 | openingDate = parentAccount.openingDate(); | ||
220 | } else { | 225 | } else { | ||
Context not available. | |||||
273 | MyMoneyAccount acc = *accList_t; | 278 | MyMoneyAccount acc = *accList_t; | ||
274 | if (acc.isClosed() //check the account is not closed | 279 | if (acc.isClosed() //check the account is not closed | ||
275 | || (!acc.isAssetLiability())) { | 280 | || (!acc.isAssetLiability())) { | ||
276 | //|| (acc.accountType() == MyMoneyAccount::Investment) ) {//check that it is not an Investment account and only include Stock accounts | 281 | //|| (acc.accountType() == eMyMoney::Account::Investment) ) {//check that it is not an Investment account and only include Stock accounts | ||
277 | //remove the account if it is not of the correct type | 282 | //remove the account if it is not of the correct type | ||
278 | accList_t = accList.erase(accList_t); | 283 | accList_t = accList.erase(accList_t); | ||
279 | } else { | 284 | } else { | ||
Context not available. | |||||
325 | } | 330 | } | ||
326 | //get all transactions for the period | 331 | //get all transactions for the period | ||
327 | filter.setDateFilter(startDate, QDate::currentDate()); | 332 | filter.setDateFilter(startDate, QDate::currentDate()); | ||
328 | if (acc.accountGroup() == MyMoneyAccount::Income | 333 | if (acc.accountGroup() == eMyMoney::Account::Income | ||
329 | || acc.accountGroup() == MyMoneyAccount::Expense) { | 334 | || acc.accountGroup() == eMyMoney::Account::Expense) { | ||
330 | filter.addCategory(acc.id()); | 335 | filter.addCategory(acc.id()); | ||
331 | } else { | 336 | } else { | ||
332 | filter.addAccount(acc.id()); | 337 | filter.addAccount(acc.id()); | ||
Context not available. | |||||
573 | dailyBalances balance; | 578 | dailyBalances balance; | ||
574 | balance = m_accountList[acc.id()]; | 579 | balance = m_accountList[acc.id()]; | ||
575 | //if it is income, the balance is stored as negative number | 580 | //if it is income, the balance is stored as negative number | ||
576 | if (acc.accountType() == MyMoneyAccount::Income) { | 581 | if (acc.accountType() == eMyMoney::Account::Income) { | ||
577 | balance[(*it_t).postDate()] += ((*it_s).shares() * MyMoneyMoney::MINUS_ONE); | 582 | balance[(*it_t).postDate()] += ((*it_s).shares() * MyMoneyMoney::MINUS_ONE); | ||
578 | } else { | 583 | } else { | ||
579 | balance[(*it_t).postDate()] += (*it_s).shares(); | 584 | balance[(*it_t).postDate()] += (*it_s).shares(); | ||
Context not available. | |||||
614 | // now process all the schedules that may have an impact | 619 | // now process all the schedules that may have an impact | ||
615 | QList<MyMoneySchedule> schedule; | 620 | QList<MyMoneySchedule> schedule; | ||
616 | 621 | | |||
617 | schedule = file->scheduleList("", MyMoneySchedule::TYPE_ANY, MyMoneySchedule::OCCUR_ANY, MyMoneySchedule::STYPE_ANY, | 622 | schedule = file->scheduleList(QString(), eMyMoney::Schedule::Type::Any, eMyMoney::Schedule::Occurrence::Any, eMyMoney::Schedule::PaymentType::Any, | ||
618 | QDate(), forecastEndDate()); | 623 | QDate(), forecastEndDate(), false); | ||
619 | if (schedule.count() > 0) { | 624 | if (schedule.count() > 0) { | ||
620 | QList<MyMoneySchedule>::Iterator it; | 625 | QList<MyMoneySchedule>::Iterator it; | ||
621 | do { | 626 | do { | ||
Context not available. | |||||
650 | 655 | | |||
651 | if (!acc.id().isEmpty()) { | 656 | if (!acc.id().isEmpty()) { | ||
652 | try { | 657 | try { | ||
653 | if (acc.accountType() != MyMoneyAccount::Investment) { | 658 | if (acc.accountType() != eMyMoney::Account::Investment) { | ||
654 | MyMoneyTransaction t = (*it).transaction(); | 659 | MyMoneyTransaction t = (*it).transaction(); | ||
655 | 660 | | |||
656 | // only process the entry, if it is still active | 661 | // only process the entry, if it is still active | ||
Context not available. | |||||
694 | if (QDate::currentDate() >= nextDate) | 699 | if (QDate::currentDate() >= nextDate) | ||
695 | forecastDate = QDate::currentDate().addDays(1); | 700 | forecastDate = QDate::currentDate().addDays(1); | ||
696 | 701 | | |||
697 | if (acc.accountType() == MyMoneyAccount::Income) { | 702 | if (acc.accountType() == eMyMoney::Account::Income) { | ||
698 | balance[forecastDate] += ((*it_s).shares() * MyMoneyMoney::MINUS_ONE); | 703 | balance[forecastDate] += ((*it_s).shares() * MyMoneyMoney::MINUS_ONE); | ||
699 | } else { | 704 | } else { | ||
700 | balance[forecastDate] += (*it_s).shares(); | 705 | balance[forecastDate] += (*it_s).shares(); | ||
Context not available. | |||||
791 | 796 | | |||
792 | balance = m_accountList[acc.id()]; | 797 | balance = m_accountList[acc.id()]; | ||
793 | 798 | | |||
794 | if (acc.accountGroup() == MyMoneyAccount::Asset) { | 799 | if (acc.accountGroup() == eMyMoney::Account::Asset) { | ||
795 | for (QDate it_day = QDate::currentDate() ; it_day <= forecastEndDate();) { | 800 | for (QDate it_day = QDate::currentDate() ; it_day <= forecastEndDate();) { | ||
796 | if (balance[it_day] < MyMoneyMoney()) { | 801 | if (balance[it_day] < MyMoneyMoney()) { | ||
797 | return QDate::currentDate().daysTo(it_day); | 802 | return QDate::currentDate().daysTo(it_day); | ||
798 | } | 803 | } | ||
799 | it_day = it_day.addDays(1); | 804 | it_day = it_day.addDays(1); | ||
800 | } | 805 | } | ||
801 | } else if (acc.accountGroup() == MyMoneyAccount::Liability) { | 806 | } else if (acc.accountGroup() == eMyMoney::Account::Liability) { | ||
802 | for (QDate it_day = QDate::currentDate() ; it_day <= forecastEndDate();) { | 807 | for (QDate it_day = QDate::currentDate() ; it_day <= forecastEndDate();) { | ||
803 | if (balance[it_day] > MyMoneyMoney()) { | 808 | if (balance[it_day] > MyMoneyMoney()) { | ||
804 | return QDate::currentDate().daysTo(it_day); | 809 | return QDate::currentDate().daysTo(it_day); | ||
Context not available. | |||||
1153 | if (forecastMethod() == eHistoric && historyMethod() == 2) { | 1158 | if (forecastMethod() == eHistoric && historyMethod() == 2) { | ||
1154 | //FIXME workaround for stock opening dates | 1159 | //FIXME workaround for stock opening dates | ||
1155 | QDate openingDate; | 1160 | QDate openingDate; | ||
1156 | if (acc.accountType() == MyMoneyAccount::Stock) { | 1161 | if (acc.accountType() == eMyMoney::Account::Stock) { | ||
1157 | MyMoneyAccount parentAccount = file->account(acc.parentAccountId()); | 1162 | MyMoneyAccount parentAccount = file->account(acc.parentAccountId()); | ||
1158 | openingDate = parentAccount.openingDate(); | 1163 | openingDate = parentAccount.openingDate(); | ||
1159 | } else { | 1164 | } else { | ||
Context not available. | |||||
1196 | 1201 | | |||
1197 | void MyMoneyForecast::calculateAutoLoan(const MyMoneySchedule& schedule, MyMoneyTransaction& transaction, const QMap<QString, MyMoneyMoney>& balances) | 1202 | void MyMoneyForecast::calculateAutoLoan(const MyMoneySchedule& schedule, MyMoneyTransaction& transaction, const QMap<QString, MyMoneyMoney>& balances) | ||
1198 | { | 1203 | { | ||
1199 | if (schedule.type() == MyMoneySchedule::TYPE_LOANPAYMENT) { | 1204 | if (schedule.type() == eMyMoney::Schedule::Type::LoanPayment) { | ||
1200 | 1205 | | |||
1201 | //get amortization and interest autoCalc splits | 1206 | //get amortization and interest autoCalc splits | ||
1202 | MyMoneySplit amortizationSplit = transaction.amortizationSplit(); | 1207 | MyMoneySplit amortizationSplit = transaction.amortizationSplit(); | ||
Context not available. | |||||
1232 | calc.setDisc(); | 1237 | calc.setDisc(); | ||
1233 | 1238 | | |||
1234 | calc.setPF(MyMoneySchedule::eventsPerYear(schedule.occurrence())); | 1239 | calc.setPF(MyMoneySchedule::eventsPerYear(schedule.occurrence())); | ||
1235 | MyMoneySchedule::occurrenceE compoundingOccurrence = static_cast<MyMoneySchedule::occurrenceE>(acc.interestCompounding()); | 1240 | eMyMoney::Schedule::Occurrence compoundingOccurrence = static_cast<eMyMoney::Schedule::Occurrence>(acc.interestCompounding()); | ||
1236 | if (compoundingOccurrence == MyMoneySchedule::OCCUR_ANY) | 1241 | if (compoundingOccurrence == eMyMoney::Schedule::Occurrence::Any) | ||
1237 | compoundingOccurrence = schedule.occurrence(); | 1242 | compoundingOccurrence = schedule.occurrence(); | ||
1238 | 1243 | | |||
1239 | calc.setCF(MyMoneySchedule::eventsPerYear(compoundingOccurrence)); | 1244 | calc.setCF(MyMoneySchedule::eventsPerYear(compoundingOccurrence)); | ||
Context not available. | |||||
1246 | interest = interest.abs(); // make sure it's positive for now | 1251 | interest = interest.abs(); // make sure it's positive for now | ||
1247 | amortization = acc.periodicPayment() - interest; | 1252 | amortization = acc.periodicPayment() - interest; | ||
1248 | 1253 | | |||
1249 | if (acc.accountType() == MyMoneyAccount::AssetLoan) { | 1254 | if (acc.accountType() == eMyMoney::Account::AssetLoan) { | ||
1250 | interest = -interest; | 1255 | interest = -interest; | ||
1251 | amortization = -amortization; | 1256 | amortization = -amortization; | ||
1252 | } | 1257 | } | ||
Context not available. |