MyMoneyMoney ReportAccount::deepCurrencyPrice(const QDate& date, bool exactDate) const { DEBUG_ENTER(Q_FUNC_INFO); MyMoneyMoney result(1, 1); MyMoneyFile* file = MyMoneyFile::instance(); MyMoneySecurity undersecurity = file->security(currencyId()); if (! undersecurity.isCurrency()) { const MyMoneyPrice &price = file->price(undersecurity.id(), undersecurity.tradingCurrency(), date, exactDate); if (price.isValid()) { result = price.rate(undersecurity.tradingCurrency()); DEBUG_OUTPUT(QString("Converting under %1 to deep %2, price on %3 is %4") .arg(undersecurity.name()) .arg(file->security(undersecurity.tradingCurrency()).name()) .arg(date.toString()) .arg(result.toDouble())); } else { DEBUG_OUTPUT(QString("No price to convert under %1 to deep %2 on %3") .arg(undersecurity.name()) .arg(file->security(undersecurity.tradingCurrency()).name()) .arg(date.toString())); result = MyMoneyMoney(); } } return result; }
MyMoneyMoney ReportAccount::baseCurrencyPrice(const QDate& date, bool exactDate) const { // Note that whether or not the user chooses to convert to base currency, all the values // for a given account/category are converted to the currency for THAT account/category // The "Convert to base currency" tells the report to convert from the account/category // currency to the file's base currency. // // An example where this matters is if Category 'C' and account 'U' are in USD, but // Account 'J' is in JPY. Say there are two transactions, one is US$100 from U to C, // the other is JPY10,000 from J to C. Given a JPY price of USD$0.01, this means // C will show a balance of $200 NO MATTER WHAT the user chooses for 'convert to base // currency. This confused me for a while, which is why I wrote this comment. // --acejones DEBUG_ENTER(Q_FUNC_INFO); MyMoneyMoney result(1, 1); MyMoneyFile* file = MyMoneyFile::instance(); if (isForeignCurrency()) { result = foreignCurrencyPrice(file->baseCurrency().id(), date, exactDate); } return result; }
void KNewAccountDlg::showSubAccounts(QStringList accounts, KMyMoneyAccountTreeBaseItem *parentItem, const QString& parentId, const QString& accountId) { MyMoneyFile *file = MyMoneyFile::instance(); for ( QStringList::ConstIterator it = accounts.begin(); it != accounts.end(); ++it ) { KMyMoneyAccountTreeBaseItem *accountItem = new KMyMoneyAccountTreeItem(parentItem, file->account(*it)); QString id = file->account(*it).id(); if(parentId == id) { m_parentItem = accountItem; } else if(accountId == id) { if(m_isEditing) accountItem->setSelectable(false); m_accountItem = accountItem; } QStringList subAccounts = file->account(*it).accountList(); if (subAccounts.count() >= 1) { showSubAccounts(subAccounts, accountItem, parentId, accountId); } } }
void KMyMoneyUtils::updateLastNumberUsed(const MyMoneyAccount& acc, const QString& number) { MyMoneyAccount accnt = acc; QString num = number; // now check if this number has been used already MyMoneyFile* file = MyMoneyFile::instance(); if (file->checkNoUsed(accnt.id(), num)) { // if a number has been entered which is immediately prior to // an existing number, the next new number produced would clash // so need to look ahead for free next number bool free = false; for (int i = 0; i < 10; i++) { // find next unused number - 10 tries (arbitrary) if (file->checkNoUsed(accnt.id(), num)) { // increment and try again num = getAdjacentNumber(num); } else { // found a free number free = true; break; } } if (!free) { qDebug() << "No free number found - set to '1'"; num = '1'; } setLastNumberUsed(getAdjacentNumber(num, - 1)); } }
void KMyMoneyAccountTreeForecastItem::updateBudget() { MyMoneySecurity currency; MyMoneyMoney tAmountMM; MyMoneyFile* file = MyMoneyFile::instance(); int it_c = 1; // iterator for the columns of the listview QDate forecastDate = m_forecast.forecastStartDate(); if(m_account.isInvest()) { MyMoneySecurity underSecurity = file->security(m_account.currencyId()); currency = file->security(underSecurity.tradingCurrency()); } else { currency = file->security(m_account.currencyId()); } //iterate columns for(; forecastDate <= m_forecast.forecastEndDate(); forecastDate = forecastDate.addMonths(1), ++it_c) { MyMoneyMoney amountMM; amountMM = m_forecast.forecastBalance(m_account,forecastDate); if(m_account.accountType() == MyMoneyAccount::Expense) amountMM = -amountMM; tAmountMM += amountMM; setAmount(it_c, amountMM); setValue(it_c, amountMM, forecastDate); showAmount(it_c, amountMM, currency); } //set total column setAmount(it_c, tAmountMM); setValue(it_c, tAmountMM, m_forecast.forecastEndDate()); showAmount(it_c, tAmountMM, currency); }
void KMyMoneyAccountTreeForecastItem::updateDetailed() { QString amount; QString vAmount; MyMoneyMoney vAmountMM; MyMoneyFile* file = MyMoneyFile::instance(); MyMoneySecurity currency; if(m_account.isInvest()) { MyMoneySecurity underSecurity = file->security(m_account.currencyId()); currency = file->security(underSecurity.tradingCurrency()); } else { currency = file->security(m_account.currencyId()); } int it_c = 1; // iterator for the columns of the listview for(QDate forecastDate = QDate::currentDate(); forecastDate <= m_forecast.forecastEndDate(); ++it_c, forecastDate = forecastDate.addDays(1)) { MyMoneyMoney amountMM = m_forecast.forecastBalance(m_account, forecastDate); //calculate the balance in base currency for the total row setAmount(it_c, amountMM); setValue(it_c, amountMM, forecastDate); showAmount(it_c, amountMM, currency); } //calculate and add variation per cycle vAmountMM = m_forecast.accountTotalVariation(m_account); setAmount(it_c, vAmountMM); setValue(it_c, vAmountMM, m_forecast.forecastEndDate()); showAmount(it_c, vAmountMM, currency); }
void MyMoneyQifWriter::writeTransactionEntry(QTextStream &s, const MyMoneyTransaction& t, const QString& accountId) { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneySplit split = t.splitByAccount(accountId); s << "D" << m_qifProfile.date(t.postDate()) << endl; switch(split.reconcileFlag()) { case MyMoneySplit::Cleared: s << "C*" << endl; break; case MyMoneySplit::Reconciled: case MyMoneySplit::Frozen: s << "CX" << endl; break; default: break; } if(split.memo().length() > 0) { QString m = split.memo(); m.replace('\n', "\\n"); s << "M" << m << endl; } s << "T" << m_qifProfile.value('T', split.value()) << endl; if(split.number().length() > 0) s << "N" << split.number() << endl; if(!split.payeeId().isEmpty()) { MyMoneyPayee payee = file->payee(split.payeeId()); s << "P" << payee.name() << endl; } QValueList<MyMoneySplit> list = t.splits(); if(list.count() > 1) { MyMoneySplit sp = t.splitByAccount(accountId, false); MyMoneyAccount acc = file->account(sp.accountId()); if(acc.accountGroup() != MyMoneyAccount::Income && acc.accountGroup() != MyMoneyAccount::Expense) { s << "L" << m_qifProfile.accountDelimiter()[0] << MyMoneyFile::instance()->accountToCategory(sp.accountId()) << m_qifProfile.accountDelimiter()[1] << endl; } else { s << "L" << file->accountToCategory(sp.accountId()) << endl; } if(list.count() > 2) { QValueList<MyMoneySplit>::ConstIterator it; for(it = list.begin(); it != list.end(); ++it) { if(!((*it) == split)) { writeSplitEntry(s, *it); } } } } s << "^" << endl; }
void CsvUtil::previouslyUsedCategories(const QString& investmentAccount, QString& feesId, QString& interestId) { feesId.clear(); interestId.clear(); MyMoneyFile* file = MyMoneyFile::instance(); try { MyMoneyAccount acc = file->account(investmentAccount); MyMoneyTransactionFilter filter(investmentAccount); filter.setReportAllSplits(false); // since we assume an investment account here, we need to collect the stock accounts as well filter.addAccount(acc.accountList()); QList< QPair<MyMoneyTransaction, MyMoneySplit> > list; file->transactionList(list, filter); QList< QPair<MyMoneyTransaction, MyMoneySplit> >::const_iterator it_t; for (it_t = list.constBegin(); it_t != list.constEnd(); ++it_t) { const MyMoneyTransaction& t = (*it_t).first; const MyMoneySplit&s = (*it_t).second; MyMoneySplit assetAccountSplit; QList<MyMoneySplit> feeSplits; QList<MyMoneySplit> interestSplits; MyMoneySecurity security; MyMoneySecurity currency; MyMoneySplit::investTransactionTypeE transactionType; dissectTransaction(t, s, assetAccountSplit, feeSplits, interestSplits, security, currency, transactionType); if (feeSplits.count() == 1) { feesId = feeSplits.first().accountId(); } if (interestSplits.count() == 1) { interestId = interestSplits.first().accountId(); } } } catch (const MyMoneyException &) { } }
void KInstitutionsView::loadSubAccounts(KMyMoneyAccountTreeItem* parent) { bool showClosedAccounts = kmymoney2->toggleAction("view_show_all_accounts")->isChecked() || !KMyMoneyGlobalSettings::hideClosedAccounts(); const MyMoneyAccount& account = dynamic_cast<const MyMoneyAccount&>(parent->itemObject()); QValueList<QString>::const_iterator it_a; MyMoneyFile* file = MyMoneyFile::instance(); for(it_a = account.accountList().begin(); it_a != account.accountList().end(); ++it_a) { MyMoneyAccount acc = m_accountMap[(*it_a)]; if(!acc.isInvest()) continue; if(acc.isClosed() && !showClosedAccounts) continue; const MyMoneySecurity& security = m_securityMap[acc.currencyId()]; QValueList<MyMoneyPrice> prices; prices += file->price(acc.currencyId(), security.tradingCurrency()); if(security.tradingCurrency() != file->baseCurrency().id()) { MyMoneySecurity sec = m_securityMap[security.tradingCurrency()]; prices += file->price(sec.id(), file->baseCurrency().id()); } KMyMoneyAccountTreeItem* item = new KMyMoneyAccountTreeItem(parent, acc, prices, security); if(acc.id() == m_reconciliationAccount.id()) item->setReconciliation(true); } }
void makePrice(const QString& _currencyid, const QDate& _date, const MyMoneyMoney& _price ) { MyMoneyFileTransaction ft; MyMoneyFile* file = MyMoneyFile::instance(); MyMoneySecurity curr = file->currency(_currencyid); MyMoneyPrice price(_currencyid, file->baseCurrency().id(), _date, _price, "test"); file->addPrice(price); ft.commit(); }
MyMoneyMoney MyMoneyForecast::calculateAccountTrend(const MyMoneyAccount& acc, int trendDays) { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneyTransactionFilter filter; MyMoneyMoney netIncome; QDate startDate; QDate openingDate = acc.openingDate(); //validate arguments if(trendDays < 1) { throw new MYMONEYEXCEPTION("Illegal arguments when calling calculateAccountTrend. trendDays must be higher than 0"); } //If it is a new account, we don't take into account the first day //because it is usually a weird one and it would mess up the trend if(openingDate.daysTo(QDate::currentDate())<trendDays){ startDate = (acc.openingDate()).addDays(1); } else { startDate = QDate::currentDate().addDays(-trendDays); } //get all transactions for the period filter.setDateFilter(startDate, QDate::currentDate()); if(acc.accountGroup() == MyMoneyAccount::Income || acc.accountGroup() == MyMoneyAccount::Expense) { filter.addCategory(acc.id()); } else { filter.addAccount(acc.id()); } filter.setReportAllSplits(false); QValueList<MyMoneyTransaction> transactions = file->transactionList(filter); QValueList<MyMoneyTransaction>::const_iterator it_t = transactions.begin(); //add all transactions for that account for(; it_t != transactions.end(); ++it_t ) { const QValueList<MyMoneySplit>& splits = (*it_t).splits(); QValueList<MyMoneySplit>::const_iterator it_s = splits.begin(); for(; it_s != splits.end(); ++it_s ) { if(!(*it_s).shares().isZero()) { if(acc.id()==(*it_s).accountId()) netIncome += (*it_s).value(); } } } //calculate trend of the account in the past period MyMoneyMoney accTrend; //don't take into account the first day of the account if(openingDate.daysTo(QDate::currentDate())<trendDays) { accTrend = netIncome/MyMoneyMoney(openingDate.daysTo(QDate::currentDate())-1,1); } else { accTrend = netIncome/MyMoneyMoney(trendDays,1); } return accTrend; }
void MyMoneyForecast::addFutureTransactions(void) { MyMoneyTransactionFilter filter; MyMoneyFile* file = MyMoneyFile::instance(); // collect and process all transactions that have already been entered but // are located in the future. filter.setDateFilter(forecastStartDate(), forecastEndDate()); filter.setReportAllSplits(false); QValueList<MyMoneyTransaction> transactions = file->transactionList(filter); QValueList<MyMoneyTransaction>::const_iterator it_t = transactions.begin(); for(; it_t != transactions.end(); ++it_t ) { const QValueList<MyMoneySplit>& splits = (*it_t).splits(); QValueList<MyMoneySplit>::const_iterator it_s = splits.begin(); for(; it_s != splits.end(); ++it_s ) { if(!(*it_s).shares().isZero()) { MyMoneyAccount acc = file->account((*it_s).accountId()); if(isForecastAccount(acc)) { dailyBalances balance; balance = m_accountList[acc.id()]; //if it is income, the balance is stored as negative number if(acc.accountType() == MyMoneyAccount::Income) { balance[(*it_t).postDate()] += ((*it_s).shares() * MyMoneyMoney(-1, 1)); } else { balance[(*it_t).postDate()] += (*it_s).shares(); } m_accountList[acc.id()] = balance; } } } } #if 0 QFile trcFile("forecast.csv"); trcFile.open(IO_WriteOnly); QTextStream s(&trcFile); { s << "Already present 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 }
/** * Fetch the trading currency of this account's currency * * @return The account's currency trading currency */ MyMoneySecurity ReportAccount::currency() const { MyMoneyFile* file = MyMoneyFile::instance(); // First, get the deep currency MyMoneySecurity deepcurrency = file->security(currencyId()); if (! deepcurrency.isCurrency()) deepcurrency = file->security(deepcurrency.tradingCurrency()); // Return the deep currency's ID return deepcurrency; }
void MyMoneyForecast::calculateHistoricDailyBalances() { MyMoneyFile* file = MyMoneyFile::instance(); calculateAccountTrendList(); //Calculate account daily balances 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); //set the starting balance of the account setStartingBalance(acc); switch(historyMethod()) { case 0: case 1: { for(QDate f_day = forecastStartDate(); f_day <= forecastEndDate(); ) { for(int t_day = 1; t_day <= accountsCycle(); ++t_day) { MyMoneyMoney balanceDayBefore = m_accountList[acc.id()][(f_day.addDays(-1))];//balance of the day before MyMoneyMoney accountDailyTrend = m_accountTrendList[acc.id()][t_day]; //trend for that day //balance of the day is the balance of the day before multiplied by the trend for the day m_accountList[acc.id()][f_day] = balanceDayBefore; m_accountList[acc.id()][f_day] += accountDailyTrend; //movement trend for that particular day m_accountList[acc.id()][f_day] = m_accountList[acc.id()][f_day].convert(acc.fraction()); //m_accountList[acc.id()][f_day] += m_accountListPast[acc.id()][f_day.addDays(-historyDays())]; f_day = f_day.addDays(1); } } } break; case 2: { QDate baseDate = QDate::currentDate().addDays(-accountsCycle()); for(int t_day = 1; t_day <= accountsCycle(); ++t_day) { int f_day = 1; QDate fDate = baseDate.addDays(accountsCycle()+1); while (fDate <= forecastEndDate()) { //the calculation is based on the balance for the last month, that is then multiplied by the trend m_accountList[acc.id()][fDate] = m_accountListPast[acc.id()][baseDate] + (m_accountTrendList[acc.id()][t_day] * MyMoneyMoney(f_day,1)); m_accountList[acc.id()][fDate] = m_accountList[acc.id()][fDate].convert(acc.fraction()); ++f_day; fDate = baseDate.addDays(accountsCycle() * f_day); } baseDate = baseDate.addDays(1); } } } } }
void makeEquityPrice(const QString& _id, const QDate& _date, const MyMoneyMoney& _price ) { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneyFileTransaction ft; QString basecurrencyid = file->baseCurrency().id(); MyMoneyPrice price = file->price( _id, basecurrencyid, _date, true ); if ( !price.isValid() ) { MyMoneyPrice newprice( _id, basecurrencyid, _date, _price, "test" ); file->addPrice(newprice); } ft.commit(); }
void KForecastView::updateSummary(QTreeWidgetItem *item) { MyMoneyMoney amountMM; int it_c = 1; // iterator for the columns of the listview MyMoneyFile* file = MyMoneyFile::instance(); int daysToBeginDay; MyMoneyForecast forecast = item->data(0, ForecastRole).value<MyMoneyForecast>(); if (QDate::currentDate() < forecast.beginForecastDate()) { daysToBeginDay = QDate::currentDate().daysTo(forecast.beginForecastDate()); } else { daysToBeginDay = forecast.accountsCycle(); } MyMoneyAccount account = item->data(0, AccountRole).value<MyMoneyAccount>(); MyMoneySecurity currency; if (account.isInvest()) { MyMoneySecurity underSecurity = file->security(account.currencyId()); currency = file->security(underSecurity.tradingCurrency()); } else { currency = file->security(account.currencyId()); } //add current balance column QDate summaryDate = QDate::currentDate(); amountMM = forecast.forecastBalance(account, summaryDate); //calculate the balance in base currency for the total row setAmount(item, it_c, amountMM); setValue(item, it_c, amountMM, summaryDate); showAmount(item, it_c, amountMM, currency); it_c++; //iterate through all other columns for (QDate summaryDate = QDate::currentDate().addDays(daysToBeginDay); summaryDate <= forecast.forecastEndDate(); summaryDate = summaryDate.addDays(forecast.accountsCycle()), ++it_c) { amountMM = forecast.forecastBalance(account, summaryDate); //calculate the balance in base currency for the total row setAmount(item, it_c, amountMM); setValue(item, it_c, amountMM, summaryDate); showAmount(item, it_c, amountMM, currency); } //calculate and add variation per cycle setNegative(item, forecast.accountTotalVariation(account).isNegative()); setAmount(item, it_c, forecast.accountTotalVariation(account)); setValue(item, it_c, forecast.accountTotalVariation(account), forecast.forecastEndDate()); showAmount(item, it_c, forecast.accountTotalVariation(account), currency); }
void KForecastView::addTotalRow(QTreeWidget* forecastList, const MyMoneyForecast& forecast) { MyMoneyFile* file = MyMoneyFile::instance(); m_totalItem = new QTreeWidgetItem(forecastList); QFont font; font.setBold(true); m_totalItem->setFont(0, font); m_totalItem->setText(0, i18nc("Total balance", "Total")); m_totalItem->setIcon(0, file->asset().accountPixmap()); m_totalItem->setData(0, ForecastRole, QVariant::fromValue(forecast)); m_totalItem->setData(0, AccountRole, QVariant::fromValue(file->asset())); m_totalItem->setExpanded(true); }
const MyMoneyAccount& KNewAccountDlg::parentAccount(void) { if (!m_bSelectedParentAccount) { MyMoneyFile *file = MyMoneyFile::instance(); switch (m_account.accountGroup()) { case MyMoneyAccount::Asset: m_parentAccount = file->asset(); break; case MyMoneyAccount::Liability: m_parentAccount = file->liability(); break; case MyMoneyAccount::Income: m_parentAccount = file->income(); break; case MyMoneyAccount::Expense: m_parentAccount = file->expense(); break; case MyMoneyAccount::Equity: m_parentAccount = file->equity(); break; default: qDebug("Seems we have an account that hasn't been mapped to the top five"); if(m_categoryEditor) m_parentAccount = file->income(); else m_parentAccount = file->asset(); } } return m_parentAccount; }
void KForecastView::loadBudgetView() { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneyForecast forecast = KMyMoneyGlobalSettings::forecast(); //get the settings from current page and calculate this year based on last year QDate historyEndDate = QDate(QDate::currentDate().year() - 1, 12, 31); QDate historyStartDate = historyEndDate.addDays(-m_accountsCycle->value() * m_forecastCycles->value()); QDate forecastStartDate = QDate(QDate::currentDate().year(), 1, 1); QDate forecastEndDate = QDate::currentDate().addDays(m_forecastDays->value()); forecast.setHistoryMethod(m_historyMethod->checkedId()); MyMoneyBudget budget; forecast.createBudget(budget, historyStartDate, historyEndDate, forecastStartDate, forecastEndDate, false); m_budgetList->clear(); m_budgetList->setIconSize(QSize(22, 22)); m_budgetList->setSortingEnabled(true); m_budgetList->sortByColumn(0, Qt::AscendingOrder); //add columns QStringList headerLabels; headerLabels << i18n("Account"); { QDate forecastStartDate = forecast.forecastStartDate(); QDate forecastEndDate = forecast.forecastEndDate(); //add cycle interval columns QDate f_date = forecastStartDate; for (; f_date <= forecastEndDate; f_date = f_date.addMonths(1)) { headerLabels << QDate::longMonthName(f_date.month()); } } //add total column headerLabels << i18nc("Total balance", "Total"); //set the columns m_budgetList->setHeaderLabels(headerLabels); //add default rows addTotalRow(m_budgetList, forecast); addIncomeExpenseRows(forecast); //load income and expense budget accounts loadAccounts(forecast, file->income(), m_incomeItem, eBudget); loadAccounts(forecast, file->expense(), m_expenseItem, eBudget); adjustHeadersAndResizeToContents(m_budgetList); }
void KForecastView::loadListView() { MyMoneyForecast forecast = KMyMoneyGlobalSettings::forecast(); MyMoneyFile* file = MyMoneyFile::instance(); //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->checkedId()); forecast.doForecast(); m_forecastList->clear(); m_forecastList->setColumnCount(0); m_forecastList->setIconSize(QSize(22, 22)); m_forecastList->setSortingEnabled(true); m_forecastList->sortByColumn(0, Qt::AscendingOrder); //add columns QStringList headerLabels; headerLabels << i18n("Account"); //add cycle interval columns headerLabels << i18nc("Today's forecast", "Current"); for (int i = 1; i <= forecast.forecastDays(); ++i) { QDate forecastDate = QDate::currentDate().addDays(i); headerLabels << QLocale().toString(forecastDate, QLocale::LongFormat); } //add variation columns headerLabels << i18n("Total variation"); //set the columns m_forecastList->setHeaderLabels(headerLabels); //add default rows addTotalRow(m_forecastList, forecast); addAssetLiabilityRows(forecast); //load asset and liability forecast accounts loadAccounts(forecast, file->asset(), m_assetItem, eDetailed); loadAccounts(forecast, file->liability(), m_liabilityItem, eDetailed); adjustHeadersAndResizeToContents(m_forecastList); // add the fixed column only if the horizontal scroll bar is visible m_fixedColumnView.reset(m_forecastList->horizontalScrollBar()->isVisible() ? new FixedColumnTreeView(m_forecastList) : 0); }
void KEquityPriceUpdateDlg::storePrices() { // update the new prices into the equities MyMoneyFile* file = MyMoneyFile::instance(); QList<MyMoneySecurity> equities = file->securityList(); QTreeWidgetItem* item = 0; MyMoneyFileTransaction ft; QString name; try { for (int i = 0; i < lvEquityList->invisibleRootItem()->childCount(); ++i) { item = lvEquityList->invisibleRootItem()->child(i); // turn on signals before we modify the last entry in the list MyMoneyFile::instance()->blockSignals(i < lvEquityList->invisibleRootItem()->childCount() - 1); MyMoneyMoney rate(item->text(PRICE_COL)); if (!rate.isZero()) { QString id = item->text(ID_COL).toUtf8(); // if the ID has a space, then this is TWO ID's, so it's a currency quote if (QString(id).contains(" ")) { QStringList ids = id.split(' ', QString::SkipEmptyParts); QString fromid = ids[0].toUtf8(); QString toid = ids[1].toUtf8(); name = QString("%1 --> %2").arg(fromid).arg(toid); MyMoneyPrice price(fromid, toid, QDate().fromString(item->text(DATE_COL), Qt::ISODate), rate, item->text(SOURCE_COL)); file->addPrice(price); } else // otherwise, it's a security quote { MyMoneySecurity security = MyMoneyFile::instance()->security(id); name = security.name(); MyMoneyPrice price(id, security.tradingCurrency(), QDate().fromString(item->text(DATE_COL), Qt::ISODate), rate, item->text(SOURCE_COL)); // TODO (Ace) Better handling of the case where there is already a price // for this date. Currently, it just overrides the old value. Really it // should check to see if the price is the same and prompt the user. MyMoneyFile::instance()->addPrice(price); } } } ft.commit(); } catch (const MyMoneyException &) { qDebug("Unable to add price information for %s", qPrintable(name)); } }
void KImportDlg::addCategories(QStringList& strList, const QString& id, const QString& leadIn) const { MyMoneyFile *file = MyMoneyFile::instance(); QString name; MyMoneyAccount account = file->account(id); QStringList accList = account.accountList(); QStringList::ConstIterator it_a; for (it_a = accList.constBegin(); it_a != accList.constEnd(); ++it_a) { account = file->account(*it_a); strList << leadIn + account.name(); addCategories(strList, *it_a, leadIn + account.name() + MyMoneyFile::AccountSeperator); } }
void ReportAccount::calculateAccountHierarchy() { DEBUG_ENTER(Q_FUNC_INFO); MyMoneyFile* file = MyMoneyFile::instance(); QString resultid = id(); QString parentid = parentAccountId(); #ifdef DEBUG_HIDE_SENSITIVE m_nameHierarchy.prepend(file->account(resultid).id()); #else m_nameHierarchy.prepend(file->account(resultid).name()); #endif while (!parentid.isEmpty() && !file->isStandardAccount(parentid)) { // take on the identity of our parent resultid = parentid; // and try again parentid = file->account(resultid).parentAccountId(); #ifdef DEBUG_HIDE_SENSITIVE m_nameHierarchy.prepend(file->account(resultid).id()); #else m_nameHierarchy.prepend(file->account(resultid).name()); #endif } }
void CsvUtil::dissectTransaction(const MyMoneyTransaction& transaction, const MyMoneySplit& split, MyMoneySplit& assetAccountSplit, QList<MyMoneySplit>& feeSplits, QList<MyMoneySplit>& interestSplits, MyMoneySecurity& security, MyMoneySecurity& currency, MyMoneySplit::investTransactionTypeE& transactionType) { // collect the splits. split references the stock account and should already // be set up. assetAccountSplit references the corresponding asset account (maybe // empty), feeSplits is the list of all expenses and interestSplits // the list of all incomes MyMoneyFile* file = MyMoneyFile::instance(); QList<MyMoneySplit>::ConstIterator it_s; for (it_s = transaction.splits().constBegin(); it_s != transaction.splits().constEnd(); ++it_s) { MyMoneyAccount acc = file->account((*it_s).accountId()); if ((*it_s).id() == split.id()) { security = file->security(acc.currencyId()); } else if (acc.accountGroup() == MyMoneyAccount::Expense) { feeSplits.append(*it_s); } else if (acc.accountGroup() == MyMoneyAccount::Income) { interestSplits.append(*it_s); } else { assetAccountSplit = *it_s; } } // determine transaction type if (split.action() == MyMoneySplit::ActionAddShares) { transactionType = (!split.shares().isNegative()) ? MyMoneySplit::AddShares : MyMoneySplit::RemoveShares; } else if (split.action() == MyMoneySplit::ActionBuyShares) { transactionType = (!split.value().isNegative()) ? MyMoneySplit::BuyShares : MyMoneySplit::SellShares; } else if (split.action() == MyMoneySplit::ActionDividend) { transactionType = MyMoneySplit::Dividend; } else if (split.action() == MyMoneySplit::ActionReinvestDividend) { transactionType = MyMoneySplit::ReinvestDividend; } else if (split.action() == MyMoneySplit::ActionYield) { transactionType = MyMoneySplit::Yield; } else if (split.action() == MyMoneySplit::ActionSplitShares) { transactionType = MyMoneySplit::SplitShares; } else if (split.action() == MyMoneySplit::ActionInterestIncome) { transactionType = MyMoneySplit::InterestIncome; } else transactionType = MyMoneySplit::BuyShares; currency.setTradingSymbol("???"); try { currency = file->security(transaction.commodity()); } catch (const MyMoneyException &) { } }
void MyMoneyForecast::doFutureScheduledForecast(void) { MyMoneyFile* file = MyMoneyFile::instance(); if(isIncludingFutureTransactions()) addFutureTransactions(); if(isIncludingScheduledTransactions()) addScheduledTransactions(); //do not show accounts with no transactions if(!isIncludingUnusedAccounts()) purgeForecastAccountsList(m_accountList); //adjust value of investments to deep currency 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 ); if ( acc.isInvest() ) { //get the id of the security for that account MyMoneySecurity undersecurity = file->security ( acc.currencyId() ); //only do it if the security is not an actual currency if ( ! undersecurity.isCurrency() ) { //set the default value MyMoneyMoney rate = MyMoneyMoney ( 1, 1 ); MyMoneyPrice price; for (QDate it_day = QDate::currentDate(); it_day <= forecastEndDate(); ) { //get the price for the tradingCurrency that day price = file->price ( undersecurity.id(), undersecurity.tradingCurrency(), it_day ); if ( price.isValid() ) { rate = price.rate ( undersecurity.tradingCurrency() ); } //value is the amount of shares multiplied by the rate of the deep currency m_accountList[acc.id() ][it_day] = m_accountList[acc.id() ][it_day] * rate; it_day = it_day.addDays(1); } } } } }
ReportAccount ReportAccount::topParent() const { DEBUG_ENTER(Q_FUNC_INFO); MyMoneyFile* file = MyMoneyFile::instance(); QString resultid = id(); QString parentid = parentAccountId(); while (!parentid.isEmpty() && !file->isStandardAccount(parentid)) { // take on the identity of our parent resultid = parentid; // and try again parentid = file->account(resultid).parentAccountId(); } return ReportAccount(resultid); }
TransactionHelper::TransactionHelper( const QDate& _date, const QString& _action, MyMoneyMoney _value, const QString& _accountid, const QString& _categoryid, const QString& _currencyid, const QString& _payee ) { // _currencyid is the currency of the transaction, and of the _value // both the account and category can have their own currency (athough the category having // a foreign currency is not yet supported by the program, the reports will still allow it, // so it must be tested.) MyMoneyFile* file = MyMoneyFile::instance(); bool haspayee = ! _payee.isEmpty(); MyMoneyPayee payeeTest = file->payeeByName(_payee); MyMoneyFileTransaction ft; setPostDate(_date); QString currencyid = _currencyid; if ( currencyid.isEmpty() ) currencyid=MyMoneyFile::instance()->baseCurrency().id(); setCommodity(currencyid); MyMoneyMoney price; MyMoneySplit splitLeft; if ( haspayee ) splitLeft.setPayeeId(payeeTest.id()); splitLeft.setAction(_action); splitLeft.setValue(-_value); price = MyMoneyFile::instance()->price(currencyid, file->account(_accountid).currencyId(),_date).rate(file->account(_accountid).currencyId()); splitLeft.setShares(-_value * price); splitLeft.setAccountId(_accountid); addSplit(splitLeft); MyMoneySplit splitRight; if ( haspayee ) splitRight.setPayeeId(payeeTest.id()); splitRight.setAction(_action); splitRight.setValue(_value); price = MyMoneyFile::instance()->price(currencyid, file->account(_categoryid).currencyId(),_date).rate(file->account(_categoryid).currencyId()); splitRight.setShares(_value * price ); splitRight.setAccountId(_categoryid); addSplit(splitRight); MyMoneyFile::instance()->addTransaction(*this); ft.commit(); }
void MyMoneyQifWriter::writeCategoryEntries(QTextStream &s) { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneyAccount income; MyMoneyAccount expense; income = file->income(); expense = file->expense(); s << "!Type:Cat" << endl; QStringList list = income.accountList() + expense.accountList(); emit signalProgress(0, list.count()); QStringList::Iterator it; int count = 0; for(it = list.begin(); it != list.end(); ++it) { writeCategoryEntry(s, *it, ""); emit signalProgress(++count, 0); } }
bool KForecastView::includeAccount(MyMoneyForecast& forecast, const MyMoneyAccount& acc) { MyMoneyFile* file = MyMoneyFile::instance(); if (forecast.isForecastAccount(acc)) return true; QStringList accounts = acc.accountList(); if (accounts.size() > 0) { QStringList::ConstIterator it_acc; for (it_acc = accounts.constBegin(); it_acc != accounts.constEnd(); ++it_acc) { MyMoneyAccount account = file->account(*it_acc); if (includeAccount(forecast, account)) return true; } } return false; }
void KEquityPriceUpdateDlg::addPricePair(const MyMoneySecurityPair& pair, bool dontCheckExistance) { MyMoneyFile* file = MyMoneyFile::instance(); QString symbol = QString("%1 > %2").arg(pair.first, pair.second); QString id = QString("%1 %2").arg(pair.first, pair.second); // Check that the pair does not already exist if (lvEquityList->findItems(id, Qt::MatchExactly, ID_COL).empty()) { const MyMoneyPrice &pr = file->price(pair.first, pair.second); if (pr.source() != "KMyMoney") { bool keep = true; if ((pair.first == file->baseCurrency().id()) || (pair.second == file->baseCurrency().id())) { const QString& foreignCurrency = file->foreignCurrency(pair.first, pair.second); // check that the foreign currency is still in use QList<MyMoneyAccount>::const_iterator it_a; QList<MyMoneyAccount> list; file->accountList(list); for (it_a = list.constBegin(); !dontCheckExistance && it_a != list.constEnd(); ++it_a) { // if it's an account denominated in the foreign currency // keep it if (((*it_a).currencyId() == foreignCurrency) && !(*it_a).isClosed()) break; // if it's an investment traded in the foreign currency // keep it if ((*it_a).isInvest() && !(*it_a).isClosed()) { MyMoneySecurity sec = file->security((*it_a).currencyId()); if (sec.tradingCurrency() == foreignCurrency) break; } } // if it is in use, it_a is not equal to list.end() if (it_a == list.constEnd() && !dontCheckExistance) keep = false; } if (keep) { QTreeWidgetItem* item = new QTreeWidgetItem(); item->setText(SYMBOL_COL, symbol); item->setText(NAME_COL, i18n("%1 units in %2", pair.first, pair.second)); if (pr.isValid()) { item->setText(PRICE_COL, pr.rate(pair.second).formatMoney(file->currency(pair.second).tradingSymbol(), KMyMoneyGlobalSettings::pricePrecision())); item->setText(DATE_COL, pr.date().toString(Qt::ISODate)); } item->setText(ID_COL, id); item->setText(SOURCE_COL, "Yahoo Currency"); // This string value should not be localized lvEquityList->invisibleRootItem()->addChild(item); } } } }