void mmReportPayeeExpenses::getPayeeStats(std::map<int, std::pair<double, double> > &payeeStats , mmDateRange* date_range, bool ignoreFuture) const { //Get base currency rates for all accounts std::map<int, double> acc_conv_rates; for (const auto& account: Model_Account::instance().all()) { Model_Currency::Data* currency = Model_Account::currency(account); acc_conv_rates[account.ACCOUNTID] = currency->BASECONVRATE; } const auto &transactions = Model_Checking::instance().find( Model_Checking::STATUS(Model_Checking::VOID_, NOT_EQUAL) , Model_Checking::TRANSDATE(m_date_range->start_date(), GREATER_OR_EQUAL) , Model_Checking::TRANSDATE(m_date_range->end_date(), LESS_OR_EQUAL)); const wxDateTime today = m_date_range->today(); const auto all_splits = Model_Splittransaction::instance().get_all(); for (const auto& trx: transactions) { if (Model_Checking::type(trx) == Model_Checking::TRANSFER) continue; // Do not include asset or stock transfers in income expense calculations. if (Model_Checking::foreignTransactionAsTransfer(trx)) continue; double convRate = acc_conv_rates[trx.ACCOUNTID]; Model_Splittransaction::Data_Set splits; if (all_splits.count(trx.id())) splits = all_splits.at(trx.id()); if (splits.empty()) { if (Model_Checking::type(trx) == Model_Checking::DEPOSIT) payeeStats[trx.PAYEEID].first += trx.TRANSAMOUNT * convRate; else payeeStats[trx.PAYEEID].second -= trx.TRANSAMOUNT * convRate; } else { for (const auto& entry : splits) { if (Model_Checking::type(trx) == Model_Checking::DEPOSIT) { if (entry.SPLITTRANSAMOUNT >= 0) payeeStats[trx.PAYEEID].first += entry.SPLITTRANSAMOUNT * convRate; else payeeStats[trx.PAYEEID].second += entry.SPLITTRANSAMOUNT * convRate; } else { if (entry.SPLITTRANSAMOUNT < 0) payeeStats[trx.PAYEEID].first -= entry.SPLITTRANSAMOUNT * convRate; else payeeStats[trx.PAYEEID].second -= entry.SPLITTRANSAMOUNT * convRate; } } } } }
void mmReportPayeeExpenses::getPayeeStats(std::map<int, std::pair<double, double> > &payeeStats , mmDateRange* date_range, bool ignoreFuture) const { //Get base currency rates for all accounts std::map<int, double> acc_conv_rates; for (const auto& account: Model_Account::instance().all()) { Model_Currency::Data* currency = Model_Account::currency(account); acc_conv_rates[account.ACCOUNTID] = currency->BASECONVRATE; } const auto &transactions = Model_Checking::instance().all(); const auto all_splits = Model_Splittransaction::instance().get_all(); for (const auto & trx: transactions) { if (Model_Checking::status(trx) == Model_Checking::VOID_) continue; if (Model_Checking::type(trx) == Model_Checking::TRANSFER) continue; wxDateTime trx_date = Model_Checking::TRANSDATE(trx); if (ignoreFuture) { if (trx_date.IsLaterThan(wxDateTime::Today())) continue; //skip future dated transactions } if (!trx_date.IsBetween(date_range->start_date(), date_range->end_date())) continue; //skip double convRate = acc_conv_rates[trx.ACCOUNTID]; Model_Splittransaction::Data_Set splits; if (all_splits.count(trx.id())) splits = all_splits.at(trx.id()); if (splits.empty()) { if (Model_Checking::type(trx) == Model_Checking::DEPOSIT) payeeStats[trx.PAYEEID].first += trx.TRANSAMOUNT * convRate; else payeeStats[trx.PAYEEID].second -= trx.TRANSAMOUNT * convRate; } else { for (const auto& entry : splits) { if (Model_Checking::type(trx) == Model_Checking::DEPOSIT) { if (entry.SPLITTRANSAMOUNT >= 0) payeeStats[trx.PAYEEID].first += entry.SPLITTRANSAMOUNT * convRate; else payeeStats[trx.PAYEEID].second += entry.SPLITTRANSAMOUNT * convRate; } else { if (entry.SPLITTRANSAMOUNT < 0) payeeStats[trx.PAYEEID].first -= entry.SPLITTRANSAMOUNT * convRate; else payeeStats[trx.PAYEEID].second -= entry.SPLITTRANSAMOUNT * convRate; } } } } }