diff --git a/kmymoney/mymoney/mymoneyfile.h b/kmymoney/mymoney/mymoneyfile.h --- a/kmymoney/mymoney/mymoneyfile.h +++ b/kmymoney/mymoney/mymoneyfile.h @@ -608,6 +608,8 @@ void transactionList(QList >& list, MyMoneyTransactionFilter& filter) const; + void transactionList(QList > >&list, MyMoneyTransactionFilter &filter) const; + /** * This method is used to remove a transaction from the transaction * pool (journal). diff --git a/kmymoney/mymoney/mymoneyfile.cpp b/kmymoney/mymoney/mymoneyfile.cpp --- a/kmymoney/mymoney/mymoneyfile.cpp +++ b/kmymoney/mymoney/mymoneyfile.cpp @@ -1600,6 +1600,12 @@ return list; } +void MyMoneyFile::transactionList(QList > >&list, MyMoneyTransactionFilter& filter) const +{ + d->checkStorage(); + d->m_storage->transactionList(list, filter); +} + const QList MyMoneyFile::payeeList() const { QList list; diff --git a/kmymoney/mymoney/storage/imymoneystorage.h b/kmymoney/mymoney/storage/imymoneystorage.h --- a/kmymoney/mymoney/storage/imymoneystorage.h +++ b/kmymoney/mymoney/storage/imymoneystorage.h @@ -496,6 +496,8 @@ virtual void transactionList(QList >& list, MyMoneyTransactionFilter& filter) const = 0; + virtual void transactionList(QList > >& list, MyMoneyTransactionFilter& filter) const = 0; + /** * Deletes an existing account from the file global account pool * This method only allows to remove accounts that are not diff --git a/kmymoney/mymoney/storage/mymoneydatabasemgr.h b/kmymoney/mymoney/storage/mymoneydatabasemgr.h --- a/kmymoney/mymoney/storage/mymoneydatabasemgr.h +++ b/kmymoney/mymoney/storage/mymoneydatabasemgr.h @@ -466,6 +466,16 @@ virtual void transactionList(QList >& list, MyMoneyTransactionFilter& filter) const; /** + * This method is the same as above, but the list contains transactions + * and a list of splits. + * + * @param list The set of transactions returned. The list passed in will + * be cleared before filling with results. + * @param filter MyMoneyTransactionFilter object with the match criteria + */ + virtual void transactionList(QList > >&list, MyMoneyTransactionFilter &filter) const; + + /** * Deletes an existing account from the file global account pool * This method only allows to remove accounts that are not * referenced by any split. Use moveSplits() to move splits diff --git a/kmymoney/mymoney/storage/mymoneydatabasemgr.cpp b/kmymoney/mymoney/storage/mymoneydatabasemgr.cpp --- a/kmymoney/mymoney/storage/mymoneydatabasemgr.cpp +++ b/kmymoney/mymoney/storage/mymoneydatabasemgr.cpp @@ -1066,6 +1066,28 @@ } } +void MyMoneyDatabaseMgr::transactionList(QList > >& list, MyMoneyTransactionFilter& filter) const +{ + list.clear(); + MyMoneyMap transactionList; + try { + if (m_sql) { + if (! m_sql->isOpen())((QSqlDatabase*)(m_sql.data()))->open(); + transactionList = m_sql->fetchTransactions(filter); + } + } catch (const MyMoneyException &) { + throw; + } + + QMap::ConstIterator it_t, txEnd = transactionList.end(); + + for (it_t = transactionList.begin(); it_t != txEnd; ++it_t) { + if (filter.match(*it_t)) { + list.append(qMakePair(*it_t, filter.matchingSplits())); + } + } +} + void MyMoneyDatabaseMgr::removeAccount(const MyMoneyAccount& account) { MyMoneyAccount parent; diff --git a/kmymoney/mymoney/storage/mymoneyseqaccessmgr.h b/kmymoney/mymoney/storage/mymoneyseqaccessmgr.h --- a/kmymoney/mymoney/storage/mymoneyseqaccessmgr.h +++ b/kmymoney/mymoney/storage/mymoneyseqaccessmgr.h @@ -535,6 +535,24 @@ const QList transactionList(MyMoneyTransactionFilter& filter) const; /** + * This method is used to pull a list of transactions from the file + * global transaction pool. It returns all those transactions + * that match the filter passed as argument. If the filter is empty, + * the whole journal will be returned. + * The list returned is sorted according to the transactions posting date. + * If more than one transaction exists for the same date, the order among + * them is undefined. + * + * The @p list will be cleared by this method. + * + * @param list reference to list + * @param filter MyMoneyTransactionFilter object with the match criteria + * + * @return set of transactions in form of a QList > > + */ + void transactionList(QList > >& list, MyMoneyTransactionFilter& filter) const; + + /** * @brief Return all onlineJobs */ const QList onlineJobList() const; diff --git a/kmymoney/mymoney/storage/mymoneyseqaccessmgr.cpp b/kmymoney/mymoney/storage/mymoneyseqaccessmgr.cpp --- a/kmymoney/mymoney/storage/mymoneyseqaccessmgr.cpp +++ b/kmymoney/mymoney/storage/mymoneyseqaccessmgr.cpp @@ -964,6 +964,20 @@ return list; } +void MyMoneySeqAccessMgr::transactionList(QList > >& list, MyMoneyTransactionFilter& filter) const +{ + list.clear(); + + QMap::ConstIterator it_t; + QMap::ConstIterator it_t_end = m_transactionList.end(); + + for (it_t = m_transactionList.begin(); it_t != it_t_end; ++it_t) { + if (filter.match(*it_t)) { + list.append(qMakePair(*it_t, filter.matchingSplits())); + } + } +} + const QList MyMoneySeqAccessMgr::onlineJobList() const { return m_onlineJobList.values(); diff --git a/kmymoney/reports/querytable.cpp b/kmymoney/reports/querytable.cpp --- a/kmymoney/reports/querytable.cpp +++ b/kmymoney/reports/querytable.cpp @@ -416,7 +416,7 @@ includeInvestmentSubAccounts(); MyMoneyReport report(m_config); - report.setReportAllSplits(false); + report.setReportAllSplits(true); report.setConsiderCategory(true); bool use_transfers = false; @@ -453,29 +453,33 @@ QMap accts; //get all transactions for this report - QList transactions = file->transactionList(report); - for (QList::const_iterator it_transaction = transactions.constBegin(); it_transaction != transactions.constEnd(); ++it_transaction) { + QList > >transactions; + file->transactionList(transactions, report); + for (QList > >::const_iterator it_t = transactions.constBegin(); it_t != transactions.constEnd(); ++it_t) { + const MyMoneyTransaction &t = (*it_t).first; + // TODO fix MyMoneyTransactionFilter to support "investment only" + const QList &splits = m_config.isInvestmentsOnly() ? t.splits() : (*it_t).second; TableRow qA, qS; QDate pd; QList tagIdListCache; - qA["id"] = qS["id"] = (* it_transaction).id(); - qA["entrydate"] = qS["entrydate"] = (* it_transaction).entryDate().toString(Qt::ISODate); - qA["postdate"] = qS["postdate"] = (* it_transaction).postDate().toString(Qt::ISODate); - qA["commodity"] = qS["commodity"] = (* it_transaction).commodity(); + qA["id"] = qS["id"] = t.id(); + qA["entrydate"] = qS["entrydate"] = t.entryDate().toString(Qt::ISODate); + qA["postdate"] = qS["postdate"] = t.postDate().toString(Qt::ISODate); + qA["commodity"] = qS["commodity"] = t.commodity(); - pd = (* it_transaction).postDate(); + pd = t.postDate(); qA["monthsort"] = qS["monthsort"] = i18n("Month of %1", QDate(pd.year(), pd.month(), 1).toString(Qt::ISODate)); qA["weeksort"] = qS["weeksort"] = i18n("Week of %1", pd.addDays(1 - pd.dayOfWeek()).toString(Qt::ISODate)); qA["month"] = qS["month"] = i18n("Month of %1", toDateString(QDate(pd.year(), pd.month(), 1))); qA["week"] = qS["week"] = i18n("Week of %1", toDateString(pd.addDays(1 - pd.dayOfWeek()))); qA["currency"] = qS["currency"] = ""; - if ((* it_transaction).commodity() != file->baseCurrency().id()) { + if (t.commodity() != file->baseCurrency().id()) { if (!report.isConvertCurrency()) { - qA["currency"] = qS["currency"] = (*it_transaction).commodity(); + qA["currency"] = qS["currency"] = t.commodity(); } } @@ -486,7 +490,6 @@ // to be the account (qA) that will have the sub-item "split" entries. we add // one transaction entry (qS) for each subsequent entry in the split. - const QList& splits = (*it_transaction).splits(); QList::const_iterator myBegin, it_split; for (it_split = splits.begin(), myBegin = splits.end(); it_split != splits.end(); ++it_split) { @@ -561,9 +564,9 @@ //convert to base currency if (m_config.isConvertCurrency()) { - xr = (splitAcc.deepCurrencyPrice((*it_transaction).postDate()) * splitAcc.baseCurrencyPrice((*it_transaction).postDate())).reduce(); + xr = (splitAcc.deepCurrencyPrice(t.postDate()) * splitAcc.baseCurrencyPrice(t.postDate())).reduce(); } else { - xr = (splitAcc.deepCurrencyPrice((*it_transaction).postDate())).reduce(); + xr = (splitAcc.deepCurrencyPrice(t.postDate())).reduce(); } if (splitAcc.isInvest()) { @@ -718,7 +721,7 @@ // if the currency of the split is different from the currency of the main split, then convert to the currency of the main split MyMoneyMoney ieXr(xr); if (!m_config.isConvertCurrency() && splitAcc.currency().id() != myBeginCurrency) { - ieXr = (xr * splitAcc.foreignCurrencyPrice(myBeginCurrency, (*it_transaction).postDate())).reduce(); + ieXr = (xr * splitAcc.foreignCurrencyPrice(myBeginCurrency, t.postDate())).reduce(); } qA["value"] = ((-(*it_split).shares()) * ieXr).convert(fraction).toString(); }