本文整理汇总了C++中MyMoneyFile::transactionList方法的典型用法代码示例。如果您正苦于以下问题:C++ MyMoneyFile::transactionList方法的具体用法?C++ MyMoneyFile::transactionList怎么用?C++ MyMoneyFile::transactionList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyMoneyFile
的用法示例。
在下文中一共展示了MyMoneyFile::transactionList方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: previouslyUsedCategories
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 &) {
}
}
示例2: calculateAccountTrend
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;
}
示例3: addFutureTransactions
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
}
示例4: writeAccountEntry
void MyMoneyQifWriter::writeAccountEntry(QTextStream &s, const QString& accountId, const QDate& startDate, const QDate& endDate)
{
MyMoneyFile* file = MyMoneyFile::instance();
MyMoneyAccount account;
account = file->account(accountId);
MyMoneyTransactionFilter filter(accountId);
filter.setDateFilter(startDate, endDate);
QValueList<MyMoneyTransaction> list = file->transactionList(filter);
QString openingBalanceTransactionId;
s << "!Type:" << m_qifProfile.profileType() << endl;
if(!startDate.isValid() || startDate <= account.openingDate()) {
s << "D" << m_qifProfile.date(account.openingDate()) << endl;
openingBalanceTransactionId = file->openingBalanceTransaction(account);
MyMoneySplit split;
if(!openingBalanceTransactionId.isEmpty()) {
MyMoneyTransaction openingBalanceTransaction = file->transaction(openingBalanceTransactionId);
split = openingBalanceTransaction.splitByAccount(account.id(), true /* match */);
}
s << "T" << m_qifProfile.value('T', split.value()) << endl;
} else {
s << "D" << m_qifProfile.date(startDate) << endl;
s << "T" << m_qifProfile.value('T', file->balance(accountId, startDate.addDays(-1))) << endl;
}
s << "CX" << endl;
s << "P" << m_qifProfile.openingBalanceText() << endl;
s << "L";
if(m_qifProfile.accountDelimiter().length())
s << m_qifProfile.accountDelimiter()[0];
s << account.name();
if(m_qifProfile.accountDelimiter().length() > 1)
s << m_qifProfile.accountDelimiter()[1];
s << endl;
s << "^" << endl;
QValueList<MyMoneyTransaction>::ConstIterator it;
signalProgress(0, list.count());
int count = 0;
for(it = list.begin(); it != list.end(); ++it) {
// don't include the openingBalanceTransaction again
if((*it).id() != openingBalanceTransactionId)
writeTransactionEntry(s, *it, accountId);
signalProgress(++count, 0);
}
}
示例5: pastTransactions
void MyMoneyForecast::pastTransactions()
{
MyMoneyFile* file = MyMoneyFile::instance();
MyMoneyTransactionFilter filter;
filter.setDateFilter(historyStartDate(), historyEndDate());
filter.setReportAllSplits(false);
QValueList<MyMoneyTransaction> transactions = file->transactionList(filter);
QValueList<MyMoneyTransaction>::const_iterator it_t = transactions.begin();
//Check past transactions
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());
//workaround for stock accounts which have faulty opening dates
QDate openingDate;
if(acc.accountType() == MyMoneyAccount::Stock) {
MyMoneyAccount parentAccount = file->account(acc.parentAccountId());
openingDate = parentAccount.openingDate();
} else {
openingDate = acc.openingDate();
}
if(isForecastAccount(acc) //If it is one of the accounts we are checking, add the amount of the transaction
&& ( (openingDate < (*it_t).postDate() && skipOpeningDate())
|| !skipOpeningDate() ) ){ //don't take the opening day of the account to calculate balance
dailyBalances balance;
//FIXME deal with leap years
balance = m_accountListPast[acc.id()];
if(acc.accountType() == MyMoneyAccount::Income) {//if it is income, the balance is stored as negative number
balance[(*it_t).postDate()] += ((*it_s).shares() * MyMoneyMoney(-1, 1));
} else {
balance[(*it_t).postDate()] += (*it_s).shares();
}
// check if this is a new account for us
m_accountListPast[acc.id()] = balance;
}
}
}
}
//purge those accounts with no transactions on the period
if(isIncludingUnusedAccounts() == false)
purgeForecastAccountsList(m_accountListPast);
//calculate running sum
QMap<QString, QString>::Iterator it_n;
for(it_n = m_nameIdx.begin(); it_n != m_nameIdx.end(); ++it_n) {
MyMoneyAccount acc = file->account(*it_n);
m_accountListPast[acc.id()][historyStartDate().addDays(-1)] = file->balance(acc.id(), historyStartDate().addDays(-1));
for(QDate it_date = historyStartDate(); it_date <= historyEndDate(); ) {
m_accountListPast[acc.id()][it_date] += m_accountListPast[acc.id()][it_date.addDays(-1)]; //Running sum
it_date = it_date.addDays(1);
}
}
//adjust value of investments to deep currency
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() );
if ( ! undersecurity.isCurrency() ) //only do it if the security is not an actual currency
{
MyMoneyMoney rate = MyMoneyMoney ( 1, 1 ); //set the default value
MyMoneyPrice price;
for ( QDate it_date = historyStartDate().addDays(-1) ; it_date <= historyEndDate();) {
//get the price for the tradingCurrency that day
price = file->price ( undersecurity.id(), undersecurity.tradingCurrency(), it_date );
if ( price.isValid() )
{
rate = price.rate ( undersecurity.tradingCurrency() );
}
//value is the amount of shares multiplied by the rate of the deep currency
m_accountListPast[acc.id() ][it_date] = m_accountListPast[acc.id() ][it_date] * rate;
it_date = it_date.addDays(1);
}
}
}
}
}
示例6: showTransactions
void KTagsView::showTransactions()
{
MyMoneyMoney balance;
MyMoneyFile *file = MyMoneyFile::instance();
MyMoneySecurity base = file->baseCurrency();
// setup sort order
m_register->setSortOrder(KMyMoneyGlobalSettings::sortSearchView());
// clear the register
m_register->clear();
if (m_tag.id().isEmpty() || !m_tabWidget->isEnabled()) {
m_balanceLabel->setText(i18n("Balance: %1", balance.formatMoney(file->baseCurrency().smallestAccountFraction())));
return;
}
// setup the list and the pointer vector
MyMoneyTransactionFilter filter;
filter.addTag(m_tag.id());
filter.setDateFilter(KMyMoneyGlobalSettings::startDate().date(), QDate());
// retrieve the list from the engine
file->transactionList(m_transactionList, filter);
// create the elements for the register
QList<QPair<MyMoneyTransaction, MyMoneySplit> >::const_iterator it;
QMap<QString, int> uniqueMap;
MyMoneyMoney deposit, payment;
int splitCount = 0;
bool balanceAccurate = true;
for (it = m_transactionList.constBegin(); it != m_transactionList.constEnd(); ++it) {
const MyMoneySplit& split = (*it).second;
MyMoneyAccount acc = file->account(split.accountId());
++splitCount;
uniqueMap[(*it).first.id()]++;
KMyMoneyRegister::Register::transactionFactory(m_register, (*it).first, (*it).second, uniqueMap[(*it).first.id()]);
// take care of foreign currencies
MyMoneyMoney val = split.shares().abs();
if (acc.currencyId() != base.id()) {
const MyMoneyPrice &price = file->price(acc.currencyId(), base.id());
// in case the price is valid, we use it. Otherwise, we keep
// a flag that tells us that the balance is somewhat inaccurate
if (price.isValid()) {
val *= price.rate(base.id());
} else {
balanceAccurate = false;
}
}
if (split.shares().isNegative()) {
payment += val;
} else {
deposit += val;
}
}
balance = deposit - payment;
// add the group markers
m_register->addGroupMarkers();
// sort the transactions according to the sort setting
m_register->sortItems();
// remove trailing and adjacent markers
m_register->removeUnwantedGroupMarkers();
m_register->updateRegister(true);
// we might end up here with updates disabled on the register so
// make sure that we enable updates here
m_register->setUpdatesEnabled(true);
m_balanceLabel->setText(i18n("Balance: %1%2",
balanceAccurate ? "" : "~",
balance.formatMoney(file->baseCurrency().smallestAccountFraction())));
}