diff --git a/kmymoney/CMakeLists.txt b/kmymoney/CMakeLists.txt --- a/kmymoney/CMakeLists.txt +++ b/kmymoney/CMakeLists.txt @@ -17,7 +17,6 @@ ${CMAKE_CURRENT_BINARY_DIR}/dialogs/settings/ ${CMAKE_CURRENT_BINARY_DIR}/mymoney/storage/ ${CMAKE_CURRENT_BINARY_DIR}/mymoney/ - ${CMAKE_CURRENT_SOURCE_DIR}/reports/ ${CMAKE_CURRENT_SOURCE_DIR}/wizards/endingbalancedlg/ ${CMAKE_CURRENT_BINARY_DIR}/wizards/endingbalancedlg/ ${CMAKE_CURRENT_SOURCE_DIR}/wizards/newinvestmentwizard/ @@ -40,7 +39,6 @@ add_subdirectory( settings ) add_subdirectory( models ) add_subdirectory( plugins ) -add_subdirectory( reports ) add_subdirectory( widgets ) add_subdirectory( dialogs ) add_subdirectory( views ) @@ -120,7 +118,6 @@ add_executable( kmymoney ${kmymoney_SRCS} ) target_link_libraries(kmymoney views - reports kmymoney_base kmymoney_common newuserwizard diff --git a/kmymoney/converter/tests/converter-test.cpp b/kmymoney/converter/tests/converter-test.cpp --- a/kmymoney/converter/tests/converter-test.cpp +++ b/kmymoney/converter/tests/converter-test.cpp @@ -21,7 +21,7 @@ #include // uses helper functions from reports tests -#include "reportstestcommon.h" +#include "views/reports/core/tests/reportstestcommon.h" using namespace test; #include "mymoneyinstitution.h" diff --git a/kmymoney/dialogs/CMakeLists.txt b/kmymoney/dialogs/CMakeLists.txt --- a/kmymoney/dialogs/CMakeLists.txt +++ b/kmymoney/dialogs/CMakeLists.txt @@ -8,7 +8,6 @@ investtransactioneditor.cpp kaccountselectdlg.cpp kbackupdlg.cpp - kbalancechartdlg.cpp kbalancewarning.cpp kcategoryreassigndlg.cpp kchooseimportexportdlg.cpp diff --git a/kmymoney/kmymoney.cpp b/kmymoney/kmymoney.cpp --- a/kmymoney/kmymoney.cpp +++ b/kmymoney/kmymoney.cpp @@ -104,7 +104,6 @@ #include "dialogs/kpayeereassigndlg.h" #include "dialogs/kcategoryreassigndlg.h" #include "wizards/endingbalancedlg/kendingbalancedlg.h" -#include "dialogs/kbalancechartdlg.h" #include "dialogs/kloadtemplatedlg.h" #include "dialogs/ktemplateexportdlg.h" #include "dialogs/transactionmatcher.h" @@ -2194,6 +2193,7 @@ onlineJobAdministration::instance()->setOnlinePlugins(pPlugins.extended); d->m_myMoneyView->setOnlinePlugins(pPlugins.online); d->updateActions(); + d->m_myMoneyView->slotRefreshViews(); return; } MyMoneyTransactionFilter::setFiscalYearStart(KMyMoneySettings::firstFiscalMonth(), KMyMoneySettings::firstFiscalDay()); diff --git a/kmymoney/mymoney/mymoneyaccount.h b/kmymoney/mymoney/mymoneyaccount.h --- a/kmymoney/mymoney/mymoneyaccount.h +++ b/kmymoney/mymoney/mymoneyaccount.h @@ -348,6 +348,29 @@ */ QString currencyId() const; + /** There are three different currencies in play with a single Account: + * - The underlying currency: What currency the account itself is denominated in + * - The deep currency: The underlying currency's own underlying currency. This + * is only a factor if the underlying currency of this account IS NOT a + * currency itself, but is some other kind of security. In that case, the + * underlying security has its own currency. The deep currency is the + * currency of the underlying security. On the other hand, if the account + * has a currency itself, then the deep currency == the underlying currency, + * and this function will return 1.0. + * - The base currency: The base currency of the user's overall file + * + * @return id of deep currency + */ + QString tradingCurrencyId() const; + + /** + * Determine if this account's deep currency is different from the file's + * base currency + * + * @return bool True if this account is in a foreign currency + */ + bool isForeignCurrency() const; + /** * This method sets the id of the currency used with this account. * @@ -511,6 +534,12 @@ */ bool isLiquidAsset() const; + /** + * Returns whether this account is a liquid liability + * + */ + bool isLiquidLiability() const; + /** * This method returns true if a costcenter assignment is required for this account */ diff --git a/kmymoney/mymoney/mymoneyaccount.cpp b/kmymoney/mymoney/mymoneyaccount.cpp --- a/kmymoney/mymoney/mymoneyaccount.cpp +++ b/kmymoney/mymoney/mymoneyaccount.cpp @@ -368,6 +368,24 @@ return d->m_currencyId; } +QString MyMoneyAccount::tradingCurrencyId() const +{ + const auto file = MyMoneyFile::instance(); + + // First, get the trading currency (formerly deep currency) + auto deepcurrency = file->security(currencyId()); + if (!deepcurrency.isCurrency()) + deepcurrency = file->security(deepcurrency.tradingCurrency()); + + // Return the trading currency's ID + return deepcurrency.id(); +} + +bool MyMoneyAccount::isForeignCurrency() const +{ + return (tradingCurrencyId() != MyMoneyFile::instance()->baseCurrency().id()); +} + void MyMoneyAccount::setCurrencyId(const QString& id) { Q_D(MyMoneyAccount); @@ -401,6 +419,11 @@ accountType() == Account::Type::Cash; } +bool MyMoneyAccount::isLiquidLiability() const +{ + return accountType() == Account::Type::CreditCard; +} + bool MyMoneyAccount::isCostCenterRequired() const { return value("CostCenter").toLower() == QLatin1String("yes"); diff --git a/kmymoney/mymoney/storage/tests/CMakeLists.txt b/kmymoney/mymoney/storage/tests/CMakeLists.txt --- a/kmymoney/mymoney/storage/tests/CMakeLists.txt +++ b/kmymoney/mymoney/storage/tests/CMakeLists.txt @@ -10,7 +10,6 @@ Qt5::Gui kmm_mymoney kmm_testutils - reports_testcommon kmm_utils_platformtools onlinetask_interfaces ) diff --git a/kmymoney/mymoney/tests/mymoneyforecast-test.cpp b/kmymoney/mymoney/tests/mymoneyforecast-test.cpp --- a/kmymoney/mymoney/tests/mymoneyforecast-test.cpp +++ b/kmymoney/mymoney/tests/mymoneyforecast-test.cpp @@ -26,7 +26,7 @@ #include "mymoneyexception.h" #include "mymoneystoragedump.h" -#include "reportstestcommon.h" +#include "views/reports/core/tests/reportstestcommon.h" #include "mymoneyinstitution.h" #include "mymoneysecurity.h" diff --git a/kmymoney/plugins/views/CMakeLists.txt b/kmymoney/plugins/views/CMakeLists.txt --- a/kmymoney/plugins/views/CMakeLists.txt +++ b/kmymoney/plugins/views/CMakeLists.txt @@ -2,7 +2,7 @@ add_subdirectory(forecast) endif() -if(ENABLE_REPORTSVIEW) +if(ENABLE_REPORTSVIEW OR BUILD_TESTING) add_subdirectory(reports) endif() diff --git a/kmymoney/plugins/views/forecast/CMakeLists.txt b/kmymoney/plugins/views/forecast/CMakeLists.txt --- a/kmymoney/plugins/views/forecast/CMakeLists.txt +++ b/kmymoney/plugins/views/forecast/CMakeLists.txt @@ -23,8 +23,8 @@ PUBLIC kmm_plugin KF5::TextWidgets - reports kmm_widgets + kmymoney_common ) # the KCM module diff --git a/kmymoney/plugins/views/forecast/kforecastview_p.h b/kmymoney/plugins/views/forecast/kforecastview_p.h --- a/kmymoney/plugins/views/forecast/kforecastview_p.h +++ b/kmymoney/plugins/views/forecast/kforecastview_p.h @@ -54,15 +54,13 @@ #include "mymoneysecurity.h" #include "kmymoneysettings.h" #include "mymoneybudget.h" -#include "pivottable.h" #include "fixedcolumntreeview.h" -#include "kreportchartview.h" -#include "reportaccount.h" #include "icons.h" #include "mymoneyenums.h" #include "kmymoneyutils.h" +#include "kmymoneyplugin.h" +#include "plugins/views/reports/reportsviewenums.h" -using namespace reports; using namespace Icons; typedef enum { @@ -100,7 +98,7 @@ m_incomeItem(0), m_expenseItem(0), m_chartLayout(0), - m_forecastChart(0) + m_forecastChart(nullptr) { } @@ -115,8 +113,6 @@ m_needLoad = false; ui->setupUi(q); - m_forecastChart = new KReportChartView(ui->m_tabChart); - for (int i = 0; i < MaxViewTabs; ++i) m_needReload[i] = false; @@ -145,10 +141,8 @@ q->connect(ui->m_budgetList, &QTreeWidget::itemExpanded, q, &KForecastView::itemExpanded); q->connect(ui->m_budgetList, &QTreeWidget::itemCollapsed, q, &KForecastView::itemCollapsed); - m_forecastChart->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_chartLayout = ui->m_tabChart->layout(); m_chartLayout->setSpacing(6); - m_chartLayout->addWidget(m_forecastChart); loadForecastSettings(); } @@ -655,36 +649,23 @@ void loadChartView() { - eMyMoney::Report::DetailLevel detailLevel[4] = { eMyMoney::Report::DetailLevel::All, eMyMoney::Report::DetailLevel::Top, eMyMoney::Report::DetailLevel::Group, eMyMoney::Report::DetailLevel::Total }; - - MyMoneyReport reportCfg = MyMoneyReport( - eMyMoney::Report::RowType::AssetLiability, - static_cast(eMyMoney::Report::ColumnType::Months), - eMyMoney::TransactionFilter::Date::UserDefined, // overridden by the setDateFilter() call below - detailLevel[ui->m_comboDetail->currentIndex()], - i18n("Net Worth Forecast"), - i18n("Generated Report")); - - reportCfg.setChartByDefault(true); - reportCfg.setChartCHGridLines(false); - reportCfg.setChartSVGridLines(false); - reportCfg.setChartType(eMyMoney::Report::ChartType::Line); - reportCfg.setIncludingSchedules(false); - // FIXME: this causes a crash - //reportCfg.setColumnsAreDays( true ); - reportCfg.setChartDataLabels(false); - reportCfg.setConvertCurrency(true); - reportCfg.setIncludingForecast(true); - reportCfg.setDateFilter(QDate::currentDate(), QDate::currentDate().addDays(ui->m_forecastDays->value())); - reports::PivotTable table(reportCfg); - - table.drawChart(*m_forecastChart); - - // Adjust the size - m_forecastChart->resize(ui->m_tab->width() - 10, ui->m_tab->height()); - //m_forecastChart->show(); - m_forecastChart->update(); - + if (m_forecastChart) + delete m_forecastChart; + + if (const auto reportsPlugin = pPlugins.data.value("reportsview", nullptr)) { + const auto args = + QString::number(ui->m_comboDetail->currentIndex()) + ';' + + QString::number(ui->m_forecastDays->value()) + ';' + + QString::number(ui->m_tab->width()) + ';' + + QString::number(ui->m_tab->height()); + + const auto variantReport = reportsPlugin->requestData(args, eWidgetPlugin::WidgetType::NetWorthForecastWithArgs); + if (!variantReport.isNull()) + m_forecastChart = variantReport.value(); + } else { + m_forecastChart = new QLabel(i18n("Enable reports plugin to see this chart.")); + } + m_chartLayout->addWidget(m_forecastChart); } void loadForecastSettings() @@ -846,10 +827,11 @@ MyMoneyAccount account = item->data(0, AccountRole).value(); //calculate the balance in base currency for the total row if (account.currencyId() != MyMoneyFile::instance()->baseCurrency().id()) { - ReportAccount repAcc = ReportAccount(account.id()); - MyMoneyMoney curPrice = repAcc.baseCurrencyPrice(forecastDate); - MyMoneyMoney baseAmountMM = amount * curPrice; - MyMoneyMoney value = baseAmountMM.convert(MyMoneyFile::instance()->baseCurrency().smallestAccountFraction()); + const auto file = MyMoneyFile::instance(); + const auto curPrice = file->price(account.tradingCurrencyId(), file->baseCurrency().id(), forecastDate); + const auto curRate = curPrice.rate(file->baseCurrency().id()); + auto baseAmountMM = amount * curRate; + auto value = baseAmountMM.convert(file->baseCurrency().smallestAccountFraction()); item->setData(column, ValueRole, QVariant::fromValue(value)); adjustParentValue(item->parent(), column, value); } else { @@ -1038,7 +1020,7 @@ QTreeWidgetItem* m_expenseItem; QLayout* m_chartLayout; - reports::KReportChartView* m_forecastChart; + QWidget *m_forecastChart; QScopedPointer m_fixedColumnView; QMap m_nameIdx; }; diff --git a/kmymoney/plugins/views/reports/CMakeLists.txt b/kmymoney/plugins/views/reports/CMakeLists.txt --- a/kmymoney/plugins/views/reports/CMakeLists.txt +++ b/kmymoney/plugins/views/reports/CMakeLists.txt @@ -1,3 +1,5 @@ +add_subdirectory(core) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/reportsview.json.in ${CMAKE_CURRENT_BINARY_DIR}/reportsview.json @ONLY) set(reportsview_SOURCES @@ -9,6 +11,7 @@ kreportconfigurationfilterdlg.cpp reporttabimpl.cpp reportcontrolimpl.cpp + kbalancechartdlg.cpp ../../../views/kmymoneywebpage.cpp ) diff --git a/kmymoney/reports/CMakeLists.txt b/kmymoney/plugins/views/reports/core/CMakeLists.txt rename from kmymoney/reports/CMakeLists.txt rename to kmymoney/plugins/views/reports/core/CMakeLists.txt diff --git a/kmymoney/reports/kbalanceaxis.h b/kmymoney/plugins/views/reports/core/kbalanceaxis.h rename from kmymoney/reports/kbalanceaxis.h rename to kmymoney/plugins/views/reports/core/kbalanceaxis.h diff --git a/kmymoney/reports/kbalanceaxis.cpp b/kmymoney/plugins/views/reports/core/kbalanceaxis.cpp rename from kmymoney/reports/kbalanceaxis.cpp rename to kmymoney/plugins/views/reports/core/kbalanceaxis.cpp diff --git a/kmymoney/reports/kreportchartview.h b/kmymoney/plugins/views/reports/core/kreportchartview.h rename from kmymoney/reports/kreportchartview.h rename to kmymoney/plugins/views/reports/core/kreportchartview.h diff --git a/kmymoney/reports/kreportchartview.cpp b/kmymoney/plugins/views/reports/core/kreportchartview.cpp rename from kmymoney/reports/kreportchartview.cpp rename to kmymoney/plugins/views/reports/core/kreportchartview.cpp diff --git a/kmymoney/reports/listtable.h b/kmymoney/plugins/views/reports/core/listtable.h rename from kmymoney/reports/listtable.h rename to kmymoney/plugins/views/reports/core/listtable.h diff --git a/kmymoney/reports/listtable.cpp b/kmymoney/plugins/views/reports/core/listtable.cpp rename from kmymoney/reports/listtable.cpp rename to kmymoney/plugins/views/reports/core/listtable.cpp diff --git a/kmymoney/reports/objectinfotable.h b/kmymoney/plugins/views/reports/core/objectinfotable.h rename from kmymoney/reports/objectinfotable.h rename to kmymoney/plugins/views/reports/core/objectinfotable.h diff --git a/kmymoney/reports/objectinfotable.cpp b/kmymoney/plugins/views/reports/core/objectinfotable.cpp rename from kmymoney/reports/objectinfotable.cpp rename to kmymoney/plugins/views/reports/core/objectinfotable.cpp diff --git a/kmymoney/reports/pivotgrid.h b/kmymoney/plugins/views/reports/core/pivotgrid.h rename from kmymoney/reports/pivotgrid.h rename to kmymoney/plugins/views/reports/core/pivotgrid.h diff --git a/kmymoney/reports/pivotgrid.cpp b/kmymoney/plugins/views/reports/core/pivotgrid.cpp rename from kmymoney/reports/pivotgrid.cpp rename to kmymoney/plugins/views/reports/core/pivotgrid.cpp diff --git a/kmymoney/reports/pivottable.h b/kmymoney/plugins/views/reports/core/pivottable.h rename from kmymoney/reports/pivottable.h rename to kmymoney/plugins/views/reports/core/pivottable.h diff --git a/kmymoney/reports/pivottable.cpp b/kmymoney/plugins/views/reports/core/pivottable.cpp rename from kmymoney/reports/pivottable.cpp rename to kmymoney/plugins/views/reports/core/pivottable.cpp diff --git a/kmymoney/reports/querytable.h b/kmymoney/plugins/views/reports/core/querytable.h rename from kmymoney/reports/querytable.h rename to kmymoney/plugins/views/reports/core/querytable.h diff --git a/kmymoney/reports/querytable.cpp b/kmymoney/plugins/views/reports/core/querytable.cpp rename from kmymoney/reports/querytable.cpp rename to kmymoney/plugins/views/reports/core/querytable.cpp diff --git a/kmymoney/reports/reportaccount.h b/kmymoney/plugins/views/reports/core/reportaccount.h rename from kmymoney/reports/reportaccount.h rename to kmymoney/plugins/views/reports/core/reportaccount.h --- a/kmymoney/reports/reportaccount.h +++ b/kmymoney/plugins/views/reports/core/reportaccount.h @@ -148,14 +148,6 @@ */ MyMoneySecurity currency() const; - /** - * Determine if this account's deep currency is different from the file's - * base currency - * - * @return bool True if this account is in a foreign currency - */ - bool isForeignCurrency() const; - /** * The name of only this account. No matter how deep the hierarchy, this * method only returns the last name in the list, which is the engine name] @@ -223,12 +215,6 @@ */ unsigned hierarchyDepth() const; - /** - * Returns whether this account is a liquid liability - * - */ - bool isLiquidLiability() const; - protected: /** * Calculates the full account hierarchy of this account diff --git a/kmymoney/reports/reportaccount.cpp b/kmymoney/plugins/views/reports/core/reportaccount.cpp rename from kmymoney/reports/reportaccount.cpp rename to kmymoney/plugins/views/reports/core/reportaccount.cpp --- a/kmymoney/reports/reportaccount.cpp +++ b/kmymoney/plugins/views/reports/core/reportaccount.cpp @@ -209,17 +209,6 @@ return deepcurrency; } -/** - * Determine if this account's deep currency is different from the file's - * base currency - * - * @return bool True if this account is in a foreign currency - */ -bool ReportAccount::isForeignCurrency() const -{ - return (currency().id() != MyMoneyFile::instance()->baseCurrency().id()); -} - bool ReportAccount::operator<(const ReportAccount& second) const { // DEBUG_ENTER(Q_FUNC_INFO); @@ -323,13 +312,4 @@ return m_nameHierarchy.first(); } -bool ReportAccount::isLiquidLiability() const -{ - return accountType() == eMyMoney::Account::Type::CreditCard; - -} - - - - } // end namespace reports diff --git a/kmymoney/reports/reportdebug.h b/kmymoney/plugins/views/reports/core/reportdebug.h rename from kmymoney/reports/reportdebug.h rename to kmymoney/plugins/views/reports/core/reportdebug.h diff --git a/kmymoney/reports/reporttable.h b/kmymoney/plugins/views/reports/core/reporttable.h rename from kmymoney/reports/reporttable.h rename to kmymoney/plugins/views/reports/core/reporttable.h diff --git a/kmymoney/reports/reporttable.cpp b/kmymoney/plugins/views/reports/core/reporttable.cpp rename from kmymoney/reports/reporttable.cpp rename to kmymoney/plugins/views/reports/core/reporttable.cpp diff --git a/kmymoney/reports/tests/CMakeLists.txt b/kmymoney/plugins/views/reports/core/tests/CMakeLists.txt rename from kmymoney/reports/tests/CMakeLists.txt rename to kmymoney/plugins/views/reports/core/tests/CMakeLists.txt diff --git a/kmymoney/reports/tests/chart-test.h b/kmymoney/plugins/views/reports/core/tests/chart-test.h rename from kmymoney/reports/tests/chart-test.h rename to kmymoney/plugins/views/reports/core/tests/chart-test.h diff --git a/kmymoney/reports/tests/chart-test.cpp b/kmymoney/plugins/views/reports/core/tests/chart-test.cpp rename from kmymoney/reports/tests/chart-test.cpp rename to kmymoney/plugins/views/reports/core/tests/chart-test.cpp diff --git a/kmymoney/reports/tests/kreportsview-test.h b/kmymoney/plugins/views/reports/core/tests/kreportsview-test.h rename from kmymoney/reports/tests/kreportsview-test.h rename to kmymoney/plugins/views/reports/core/tests/kreportsview-test.h diff --git a/kmymoney/reports/tests/pivotgrid-test.h b/kmymoney/plugins/views/reports/core/tests/pivotgrid-test.h rename from kmymoney/reports/tests/pivotgrid-test.h rename to kmymoney/plugins/views/reports/core/tests/pivotgrid-test.h diff --git a/kmymoney/reports/tests/pivotgrid-test.cpp b/kmymoney/plugins/views/reports/core/tests/pivotgrid-test.cpp rename from kmymoney/reports/tests/pivotgrid-test.cpp rename to kmymoney/plugins/views/reports/core/tests/pivotgrid-test.cpp diff --git a/kmymoney/reports/tests/pivottable-test.h b/kmymoney/plugins/views/reports/core/tests/pivottable-test.h rename from kmymoney/reports/tests/pivottable-test.h rename to kmymoney/plugins/views/reports/core/tests/pivottable-test.h diff --git a/kmymoney/reports/tests/pivottable-test.cpp b/kmymoney/plugins/views/reports/core/tests/pivottable-test.cpp rename from kmymoney/reports/tests/pivottable-test.cpp rename to kmymoney/plugins/views/reports/core/tests/pivottable-test.cpp diff --git a/kmymoney/reports/tests/querytable-test.h b/kmymoney/plugins/views/reports/core/tests/querytable-test.h rename from kmymoney/reports/tests/querytable-test.h rename to kmymoney/plugins/views/reports/core/tests/querytable-test.h diff --git a/kmymoney/reports/tests/querytable-test.cpp b/kmymoney/plugins/views/reports/core/tests/querytable-test.cpp rename from kmymoney/reports/tests/querytable-test.cpp rename to kmymoney/plugins/views/reports/core/tests/querytable-test.cpp diff --git a/kmymoney/reports/tests/reportstestcommon.h b/kmymoney/plugins/views/reports/core/tests/reportstestcommon.h rename from kmymoney/reports/tests/reportstestcommon.h rename to kmymoney/plugins/views/reports/core/tests/reportstestcommon.h diff --git a/kmymoney/reports/tests/reportstestcommon.cpp b/kmymoney/plugins/views/reports/core/tests/reportstestcommon.cpp rename from kmymoney/reports/tests/reportstestcommon.cpp rename to kmymoney/plugins/views/reports/core/tests/reportstestcommon.cpp diff --git a/kmymoney/dialogs/kbalancechartdlg.h b/kmymoney/plugins/views/reports/kbalancechartdlg.h rename from kmymoney/dialogs/kbalancechartdlg.h rename to kmymoney/plugins/views/reports/kbalancechartdlg.h diff --git a/kmymoney/dialogs/kbalancechartdlg.cpp b/kmymoney/plugins/views/reports/kbalancechartdlg.cpp rename from kmymoney/dialogs/kbalancechartdlg.cpp rename to kmymoney/plugins/views/reports/kbalancechartdlg.cpp diff --git a/kmymoney/plugins/views/reports/kreportsview.cpp b/kmymoney/plugins/views/reports/kreportsview.cpp --- a/kmymoney/plugins/views/reports/kreportsview.cpp +++ b/kmymoney/plugins/views/reports/kreportsview.cpp @@ -71,6 +71,7 @@ #include "objectinfotable.h" #include "kreportconfigurationfilterdlg.h" #include "icons/icons.h" +#include "kbalancechartdlg.h" #include #include "tocitem.h" #include "tocitemgroup.h" @@ -128,6 +129,15 @@ slotCloseAll(); break; + case eView::Action::ShowBalanceChart: + { + Q_D(KReportsView); + QPointer dlg = new KBalanceChartDlg(d->m_currentAccount, this); + dlg->exec(); + delete dlg; + } + break; + default: break; } diff --git a/kmymoney/plugins/views/reports/reportsview.h b/kmymoney/plugins/views/reports/reportsview.h --- a/kmymoney/plugins/views/reports/reportsview.h +++ b/kmymoney/plugins/views/reports/reportsview.h @@ -29,9 +29,10 @@ class KReportsView; -class ReportsView : public KMyMoneyPlugin::Plugin +class ReportsView : public KMyMoneyPlugin::Plugin, public KMyMoneyPlugin::DataPlugin { Q_OBJECT + Q_INTERFACES(KMyMoneyPlugin::DataPlugin) public: explicit ReportsView(QObject *parent, const QVariantList &args); @@ -40,7 +41,26 @@ void plug() final override; void unplug() final override; + QVariant requestData(const QString &arg, uint type) final override; + private: + QWidget *netWorthForecast() const; + /** + * @brief netWorthForecast + * @param arg consists of following arguments: + * 1) detail level of a chart (eMyMoney::Report::DetailLevel) + * 2) forecast days of a chart + * 3) width of a chart + * 3) height a chart + * correctly written arg variable looks as follows: + * "2;5;800;600" + * @return self-handling widget with a chart + */ + QWidget *netWorthForecast(const QString &arg) const; + QString budget() const; + QString showColoredAmount(const QString &amount, bool isNegative) const; + QString link(const QString& view, const QString& query, const QString& _title) const; + QString linkend() const; KReportsView* m_view; }; diff --git a/kmymoney/plugins/views/reports/reportsview.cpp b/kmymoney/plugins/views/reports/reportsview.cpp --- a/kmymoney/plugins/views/reports/reportsview.cpp +++ b/kmymoney/plugins/views/reports/reportsview.cpp @@ -31,6 +31,16 @@ #include "viewinterface.h" #include "kreportsview.h" +#include "kreportchartview.h" +#include "kmymoneysettings.h" +#include "pivottable.h" +#include "pivotgrid.h" +#include "mymoneyfile.h" +#include "mymoneysecurity.h" +#include "mymoneyenums.h" +#include "reportsviewenums.h" + +#define VIEW_LEDGER "ledger" ReportsView::ReportsView(QObject *parent, const QVariantList &args) : KMyMoneyPlugin::Plugin(parent, "reportsview"/*must be the same as X-KDE-PluginInfo-Name*/), @@ -58,6 +68,264 @@ viewInterface()->removeView(View::Reports); } +QVariant ReportsView::requestData(const QString &arg, uint type) +{ + switch(type) { + case eWidgetPlugin::WidgetType::NetWorthForecast: + return QVariant::fromValue(netWorthForecast()); + case eWidgetPlugin::WidgetType::NetWorthForecastWithArgs: + return QVariant::fromValue(netWorthForecast(arg)); + case eWidgetPlugin::WidgetType::Budget: + return QVariant(budget()); + default: + return QVariant(); + } + +} + +QWidget *ReportsView::netWorthForecast() const +{ + MyMoneyReport reportCfg = MyMoneyReport( + eMyMoney::Report::RowType::AssetLiability, + static_cast(eMyMoney::Report::ColumnType::Months), + eMyMoney::TransactionFilter::Date::UserDefined, // overridden by the setDateFilter() call below + eMyMoney::Report::DetailLevel::Total, + i18n("Net Worth Forecast"), + i18n("Generated Report")); + + reportCfg.setChartByDefault(true); + reportCfg.setChartCHGridLines(false); + reportCfg.setChartSVGridLines(false); + reportCfg.setChartDataLabels(false); + reportCfg.setChartType(eMyMoney::Report::ChartType::Line); + reportCfg.setIncludingSchedules(false); + reportCfg.addAccountGroup(eMyMoney::Account::Type::Asset); + reportCfg.addAccountGroup(eMyMoney::Account::Type::Liability); + reportCfg.setColumnsAreDays(true); + reportCfg.setConvertCurrency(true); + reportCfg.setIncludingForecast(true); + reportCfg.setDateFilter(QDate::currentDate(), QDate::currentDate().addDays(+ 90)); + reports::PivotTable table(reportCfg); + + auto chartWidget = new reports::KReportChartView(nullptr); + + table.drawChart(*chartWidget); + return chartWidget; +} + +QWidget *ReportsView::netWorthForecast(const QString &arg) const +{ + const QStringList liArgs = arg.split(';'); + if (liArgs.count() != 4) + return new QWidget(); + + eMyMoney::Report::DetailLevel detailLevel[4] = { eMyMoney::Report::DetailLevel::All, eMyMoney::Report::DetailLevel::Top, eMyMoney::Report::DetailLevel::Group, eMyMoney::Report::DetailLevel::Total }; + + MyMoneyReport reportCfg = MyMoneyReport( + eMyMoney::Report::RowType::AssetLiability, + static_cast(eMyMoney::Report::ColumnType::Months), + eMyMoney::TransactionFilter::Date::UserDefined, // overridden by the setDateFilter() call below + detailLevel[liArgs.at(0).toInt()], + i18n("Net Worth Forecast"), + i18n("Generated Report")); + + reportCfg.setChartByDefault(true); + reportCfg.setChartCHGridLines(false); + reportCfg.setChartSVGridLines(false); + reportCfg.setChartType(eMyMoney::Report::ChartType::Line); + reportCfg.setIncludingSchedules(false); + // FIXME: this causes a crash + //reportCfg.setColumnsAreDays( true ); + reportCfg.setChartDataLabels(false); + reportCfg.setConvertCurrency(true); + reportCfg.setIncludingForecast(true); + reportCfg.setDateFilter(QDate::currentDate(), QDate::currentDate().addDays(liArgs.at(2).toLongLong())); + reports::PivotTable table(reportCfg); + + auto forecastChart = new reports::KReportChartView(nullptr); + forecastChart->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + table.drawChart(*forecastChart); + + // Adjust the size + forecastChart->resize(liArgs.at(2).toInt() - 10, liArgs.at(3).toInt()); + //forecastChart->show(); + forecastChart->update(); + return forecastChart; +} + +QString ReportsView::budget() const +{ + const auto file = MyMoneyFile::instance(); + + QString html; + if (file->countBudgets() == 0) { + html += QString(""); + html += QString("
%1
").arg(i18n("You have no budgets to display.")); + html += QString(""); + return html; + } + + auto prec = MyMoneyMoney::denomToPrec(file->baseCurrency().smallestAccountFraction()); + auto isOverrun = false; + int i = 0; + + //config report just like "Monthly Budgeted vs Actual + MyMoneyReport reportCfg = MyMoneyReport( + eMyMoney::Report::RowType::BudgetActual, + static_cast(eMyMoney::Report::ColumnType::Months), + eMyMoney::TransactionFilter::Date::CurrentMonth, + eMyMoney::Report::DetailLevel::All, + i18n("Monthly Budgeted vs. Actual"), + i18n("Generated Report")); + + reportCfg.setBudget("Any", true); + + reports::PivotTable table(reportCfg); + + reports::PivotGrid grid = table.grid(); + + //div header + html += "
" + i18n("Budget") + "
\n
 
\n"; + + //display budget summary + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + + html += QString(""); + + MyMoneyMoney totalBudgetValue = grid.m_total[reports::eBudget].m_total; + MyMoneyMoney totalActualValue = grid.m_total[reports::eActual].m_total; + MyMoneyMoney totalBudgetDiffValue = grid.m_total[reports::eBudgetDiff].m_total; + + QString totalBudgetAmount = totalBudgetValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); + QString totalActualAmount = totalActualValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); + QString totalBudgetDiffAmount = totalBudgetDiffValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); + + html += QString("").arg(showColoredAmount(totalBudgetAmount, totalBudgetValue.isNegative())); + html += QString("").arg(showColoredAmount(totalActualAmount, totalActualValue.isNegative())); + html += QString("").arg(showColoredAmount(totalBudgetDiffAmount, totalBudgetDiffValue.isNegative())); + html += ""; + html += "
"; + html += i18n("Current Month Summary"); + html += "
"; + html += i18n("Budgeted"); + html += ""; + html += i18n("Actual"); + html += ""; + html += i18n("Difference"); + html += "
%1%1%1
"; + + //budget overrun + html += "
 
\n"; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + + reports::PivotGrid::iterator it_outergroup = grid.begin(); + while (it_outergroup != grid.end()) { + i = 0; + reports::PivotOuterGroup::iterator it_innergroup = (*it_outergroup).begin(); + while (it_innergroup != (*it_outergroup).end()) { + reports::PivotInnerGroup::iterator it_row = (*it_innergroup).begin(); + while (it_row != (*it_innergroup).end()) { + //column number is 1 because the report includes only current month + if (it_row.value()[reports::eBudgetDiff].value(1).isNegative()) { + //get report account to get the name later + reports::ReportAccount rowname = it_row.key(); + + //write the outergroup if it is the first row of outergroup being shown + if (i == 0) { + html += ""; + html += QString("").arg(MyMoneyAccount::accountTypeToString(rowname.accountType())); + html += ""; + } + html += QString("").arg(i++ & 0x01 ? "even" : "odd"); + + //get values from grid + MyMoneyMoney actualValue = it_row.value()[reports::eActual][1]; + MyMoneyMoney budgetValue = it_row.value()[reports::eBudget][1]; + MyMoneyMoney budgetDiffValue = it_row.value()[reports::eBudgetDiff][1]; + + //format amounts + QString actualAmount = actualValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); + QString budgetAmount = budgetValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); + QString budgetDiffAmount = budgetDiffValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); + + //account name + html += QString(""; + + //show amounts + html += QString("").arg(showColoredAmount(budgetAmount, budgetValue.isNegative())); + html += QString("").arg(showColoredAmount(actualAmount, actualValue.isNegative())); + html += QString("").arg(showColoredAmount(budgetDiffAmount, budgetDiffValue.isNegative())); + html += ""; + + //set the flag that there are overruns + isOverrun = true; + } + ++it_row; + } + ++it_innergroup; + } + ++it_outergroup; + } + + //if no negative differences are found, then inform that + if (!isOverrun) { + html += QString::fromLatin1("").arg(((i++ & 1) == 1) ? QLatin1String("even") : QLatin1String("odd")); + html += QString::fromLatin1("").arg(i18n("No Budget Categories have been overrun")); + html += ""; + } + html += "
"; + html += i18n("Budget Overruns"); + html += "
"; + html += i18n("Account"); + html += ""; + html += i18n("Budgeted"); + html += ""; + html += i18n("Actual"); + html += ""; + html += i18n("Difference"); + html += "
%1
") + link(VIEW_LEDGER, QString("?id=%1").arg(rowname.id()), QString()) + rowname.name() + linkend() + "%1%1%1
%1
"; + return html; +} + +QString ReportsView::showColoredAmount(const QString &amount, bool isNegative) const +{ + if (isNegative) { + //if negative, get the settings for negative numbers + return QString("%2").arg(KMyMoneySettings::schemeColor(SchemeColor::Negative).name(), amount); + } + + //if positive, return the same string + return amount; +} + +QString ReportsView::link(const QString& view, const QString& query, const QString& _title) const +{ + QString titlePart; + QString title(_title); + if (!title.isEmpty()) + titlePart = QString(" title=\"%1\"").arg(title.replace(QLatin1Char(' '), " ")); + + return QString("").arg(view, query, titlePart); +} + +QString ReportsView::linkend() const +{ + return QStringLiteral(""); +} + K_PLUGIN_FACTORY_WITH_JSON(ReportsViewFactory, "reportsview.json", registerPlugin();) #include "reportsview.moc" diff --git a/kmymoney/plugins/views/reports/reportsviewenums.h b/kmymoney/plugins/views/reports/reportsviewenums.h new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/views/reports/reportsviewenums.h @@ -0,0 +1,29 @@ +/* + * Copyright 2018 Łukasz Wojniłowicz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef REPORTSVIEWENUMS_H +#define REPORTSVIEWENUMS_H + +namespace eWidgetPlugin { + enum WidgetType { + NetWorthForecast, + NetWorthForecastWithArgs, // for forecast view + Budget + }; +} + +#endif diff --git a/kmymoney/views/kaccountsview.cpp b/kmymoney/views/kaccountsview.cpp --- a/kmymoney/views/kaccountsview.cpp +++ b/kmymoney/views/kaccountsview.cpp @@ -36,7 +36,6 @@ #include "onlinejobadministration.h" #include "knewaccountwizard.h" -#include "kbalancechartdlg.h" #include "kmymoneyutils.h" #include "kmymoneysettings.h" #include "storageenums.h" @@ -378,9 +377,7 @@ { Q_D(KAccountsView); if (!d->m_currentAccount.id().isEmpty()) { - QPointer dlg = new KBalanceChartDlg(d->m_currentAccount, this); - dlg->exec(); - delete dlg; + emit customActionRequested(View::Accounts, eView::Action::ShowBalanceChart); } } diff --git a/kmymoney/views/khomeview_p.h b/kmymoney/views/khomeview_p.h --- a/kmymoney/views/khomeview_p.h +++ b/kmymoney/views/khomeview_p.h @@ -69,11 +69,9 @@ #include "mymoneyfile.h" #include "mymoneyaccount.h" #include "mymoneyprice.h" +#include "mymoneyreport.h" +#include "mymoneymoney.h" #include "mymoneyforecast.h" -#include "kreportchartview.h" -#include "pivottable.h" -#include "pivotgrid.h" -#include "reportaccount.h" #include "mymoneysplit.h" #include "mymoneytransaction.h" #include "icons.h" @@ -81,8 +79,10 @@ #include "mymoneyschedule.h" #include "mymoneysecurity.h" #include "mymoneyexception.h" +#include "kmymoneyplugin.h" #include "mymoneyenums.h" #include "menuenums.h" +#include "plugins/views/reports/reportsviewenums.h" #define VIEW_LEDGER "ledger" #define VIEW_SCHEDULE "schedule" @@ -116,8 +116,6 @@ return acc1.name().localeAwareCompare(acc2.name()) < 0; } -using namespace reports; - class KHomeViewPrivate : public KMyMoneyViewBasePrivate { Q_DECLARE_PUBLIC(KHomeView) @@ -285,8 +283,7 @@ void showAccountEntry(const MyMoneyAccount& acc) { - MyMoneyFile* file = MyMoneyFile::instance(); - MyMoneySecurity currency = file->currency(acc.currencyId()); + const auto file = MyMoneyFile::instance(); MyMoneyMoney value; bool showLimit = KMyMoneySettings::showLimitInfo(); @@ -301,9 +298,9 @@ //get balance for normal accounts value = file->balance(acc.id(), QDate::currentDate()); if (acc.currencyId() != file->baseCurrency().id()) { - ReportAccount repAcc = ReportAccount(acc.id()); - MyMoneyMoney curPrice = repAcc.baseCurrencyPrice(QDate::currentDate()); - MyMoneyMoney baseValue = value * curPrice; + const auto curPrice = file->price(acc.tradingCurrencyId(), file->baseCurrency().id(), QDate::currentDate()); + const auto curRate = curPrice.rate(file->baseCurrency().id()); + auto baseValue = value * curRate; baseValue = baseValue.convert(file->baseCurrency().smallestAccountFraction()); m_total += baseValue; } else { @@ -520,54 +517,30 @@ void showNetWorthGraph() { Q_Q(KHomeView); - m_html += QString("
%1
\n
 
\n").arg(i18n("Net Worth Forecast")); - - MyMoneyReport reportCfg = MyMoneyReport( - eMyMoney::Report::RowType::AssetLiability, - static_cast(eMyMoney::Report::ColumnType::Months), - TransactionFilter::Date::UserDefined, // overridden by the setDateFilter() call below - eMyMoney::Report::DetailLevel::Total, - i18n("Net Worth Forecast"), - i18n("Generated Report")); - - reportCfg.setChartByDefault(true); - reportCfg.setChartCHGridLines(false); - reportCfg.setChartSVGridLines(false); - reportCfg.setChartDataLabels(false); - reportCfg.setChartType(eMyMoney::Report::ChartType::Line); - reportCfg.setIncludingSchedules(false); - reportCfg.addAccountGroup(Account::Type::Asset); - reportCfg.addAccountGroup(Account::Type::Liability); - reportCfg.setColumnsAreDays(true); - reportCfg.setConvertCurrency(true); - reportCfg.setIncludingForecast(true); - reportCfg.setDateFilter(QDate::currentDate(), QDate::currentDate().addDays(+ 90)); - reports::PivotTable table(reportCfg); - - reports::KReportChartView* chartWidget = new reports::KReportChartView(0); - - table.drawChart(*chartWidget); // Adjust the size QSize netWorthGraphSize = q->size(); netWorthGraphSize -= QSize(80, 30); - // consider the computed size valid only if it's smaller on both axes that the applications size -// if (netWorthGraphSize.width() < kmymoney->width() || netWorthGraphSize.height() < kmymoney->height()) { - m_netWorthGraphLastValidSize = netWorthGraphSize; -// } - chartWidget->resize(m_netWorthGraphLastValidSize); - - //save the chart to an image - QString chart = QPixmapToDataUri(chartWidget->coordinatePlane()->parent()->grab()); + m_netWorthGraphLastValidSize = netWorthGraphSize; + m_html += QString("
%1
\n
 
\n").arg(i18n("Net Worth Forecast")); m_html += QString(""); m_html += QString(""); - m_html += QString("").arg(chart); + + if (const auto reportsPlugin = pPlugins.data.value(QStringLiteral("reportsview"), nullptr)) { + const auto variantReport = reportsPlugin->requestData(QString(), eWidgetPlugin::WidgetType::NetWorthForecast); + if (!variantReport.isNull()) { + auto report = variantReport.value(); + report->resize(m_netWorthGraphLastValidSize); + m_html += QString("").arg(QPixmapToDataUri(report->grab())); + delete report; + } + } else { + m_html += QString("").arg(i18n("Enable reports plugin to see this chart.")); + } + m_html += QString(""); m_html += QString("
\"Networth\"
\"Networth\"
%1
"); - - //delete the widget since we no longer need it - delete chartWidget; } void showPayments() @@ -1369,9 +1342,9 @@ //calculate balance for foreign currency accounts if ((*asset_it).currencyId() != file->baseCurrency().id()) { - ReportAccount repAcc = ReportAccount((*asset_it).id()); - MyMoneyMoney curPrice = repAcc.baseCurrencyPrice(QDate::currentDate()); - MyMoneyMoney baseValue = value * curPrice; + const auto curPrice = file->price((*asset_it).tradingCurrencyId(), file->baseCurrency().id(), QDate::currentDate()); + const auto curRate = curPrice.rate(file->baseCurrency().id()); + auto baseValue = value * curRate; baseValue = baseValue.convert(10000); netAssets += baseValue; } else { @@ -1394,9 +1367,9 @@ value = MyMoneyFile::instance()->balance((*liabilities_it).id(), QDate::currentDate()); //calculate balance if foreign currency if ((*liabilities_it).currencyId() != file->baseCurrency().id()) { - ReportAccount repAcc = ReportAccount((*liabilities_it).id()); - MyMoneyMoney curPrice = repAcc.baseCurrencyPrice(QDate::currentDate()); - MyMoneyMoney baseValue = value * curPrice; + const auto curPrice = file->price((*liabilities_it).tradingCurrencyId(), file->baseCurrency().id(), QDate::currentDate()); + const auto curRate = curPrice.rate(file->baseCurrency().id()); + auto baseValue = value * curRate; baseValue = baseValue.convert(10000); netLiabilities += baseValue; } else { @@ -1449,143 +1422,20 @@ void showBudget() { - MyMoneyFile* file = MyMoneyFile::instance(); - - if (file->countBudgets()) { - int prec = MyMoneyMoney::denomToPrec(file->baseCurrency().smallestAccountFraction()); - bool isOverrun = false; - int i = 0; - - //config report just like "Monthly Budgeted vs Actual - MyMoneyReport reportCfg = MyMoneyReport( - eMyMoney::Report::RowType::BudgetActual, - static_cast(eMyMoney::Report::ColumnType::Months), - TransactionFilter::Date::CurrentMonth, - eMyMoney::Report::DetailLevel::All, - i18n("Monthly Budgeted vs. Actual"), - i18n("Generated Report")); - - reportCfg.setBudget("Any", true); - - reports::PivotTable table(reportCfg); - - PivotGrid grid = table.grid(); - - //div header - m_html += "
" + i18n("Budget") + "
\n
 
\n"; - - //display budget summary - m_html += ""; - m_html += ""; - m_html += ""; - m_html += ""; - m_html += ""; - m_html += ""; - m_html += ""; - - m_html += QString(""); - - MyMoneyMoney totalBudgetValue = grid.m_total[eBudget].m_total; - MyMoneyMoney totalActualValue = grid.m_total[eActual].m_total; - MyMoneyMoney totalBudgetDiffValue = grid.m_total[eBudgetDiff].m_total; - - QString totalBudgetAmount = totalBudgetValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); - QString totalActualAmount = totalActualValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); - QString totalBudgetDiffAmount = totalBudgetDiffValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); - - m_html += QString("").arg(showColoredAmount(totalBudgetAmount, totalBudgetValue.isNegative())); - m_html += QString("").arg(showColoredAmount(totalActualAmount, totalActualValue.isNegative())); - m_html += QString("").arg(showColoredAmount(totalBudgetDiffAmount, totalBudgetDiffValue.isNegative())); - m_html += ""; - m_html += "
"; - m_html += i18n("Current Month Summary"); - m_html += "
"; - m_html += i18n("Budgeted"); - m_html += ""; - m_html += i18n("Actual"); - m_html += ""; - m_html += i18n("Difference"); - m_html += "
%1%1%1
"; - - //budget overrun - m_html += "
 
\n"; - m_html += ""; - m_html += ""; - m_html += ""; - m_html += ""; - m_html += ""; - m_html += ""; - m_html += ""; - m_html += ""; - - - PivotGrid::iterator it_outergroup = grid.begin(); - while (it_outergroup != grid.end()) { - i = 0; - PivotOuterGroup::iterator it_innergroup = (*it_outergroup).begin(); - while (it_innergroup != (*it_outergroup).end()) { - PivotInnerGroup::iterator it_row = (*it_innergroup).begin(); - while (it_row != (*it_innergroup).end()) { - //column number is 1 because the report includes only current month - if (it_row.value()[eBudgetDiff].value(1).isNegative()) { - //get report account to get the name later - ReportAccount rowname = it_row.key(); - - //write the outergroup if it is the first row of outergroup being shown - if (i == 0) { - m_html += ""; - m_html += QString("").arg(MyMoneyAccount::accountTypeToString(rowname.accountType())); - m_html += ""; - } - m_html += QString("").arg(i++ & 0x01 ? "even" : "odd"); - - //get values from grid - MyMoneyMoney actualValue = it_row.value()[eActual][1]; - MyMoneyMoney budgetValue = it_row.value()[eBudget][1]; - MyMoneyMoney budgetDiffValue = it_row.value()[eBudgetDiff][1]; - - //format amounts - QString actualAmount = actualValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); - QString budgetAmount = budgetValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); - QString budgetDiffAmount = budgetDiffValue.formatMoney(file->baseCurrency().tradingSymbol(), prec); - - //account name - m_html += QString(""; - - //show amounts - m_html += QString("").arg(showColoredAmount(budgetAmount, budgetValue.isNegative())); - m_html += QString("").arg(showColoredAmount(actualAmount, actualValue.isNegative())); - m_html += QString("").arg(showColoredAmount(budgetDiffAmount, budgetDiffValue.isNegative())); - m_html += ""; - - //set the flag that there are overruns - isOverrun = true; - } - ++it_row; - } - ++it_innergroup; - } - ++it_outergroup; - } + m_html += "
" + i18n("Budget") + "
\n
 
\n"; + m_html += "
"; - m_html += i18n("Budget Overruns"); - m_html += "
"; - m_html += i18n("Account"); - m_html += ""; - m_html += i18n("Budgeted"); - m_html += ""; - m_html += i18n("Actual"); - m_html += ""; - m_html += i18n("Difference"); - m_html += "
%1
") + link(VIEW_LEDGER, QString("?id=%1").arg(rowname.id())) + rowname.name() + linkend() + "%1%1%1
"; - //if no negative differences are found, then inform that - if (!isOverrun) { - m_html += QString::fromLatin1("").arg(((i++ & 1) == 1) ? QLatin1String("even") : QLatin1String("odd")); - m_html += QString::fromLatin1("").arg(i18n("No Budget Categories have been overrun")); - m_html += ""; - } - m_html += "
%1
"; + if (const auto reportsPlugin = pPlugins.data.value(QStringLiteral("reportsview"), nullptr)) { + const auto variantReport = reportsPlugin->requestData(QString(), eWidgetPlugin::WidgetType::Budget); + if (!variantReport.isNull()) + m_html.append(variantReport.toString()); + } else { + m_html += QString(""); + m_html += QString("
%1
").arg(i18n("Enable reports plugin to see this chart.")); + m_html += QString(""); } + + m_html += QString("
"); } void showCashFlowSummary() @@ -1615,7 +1465,7 @@ //get the splits for each transaction foreach (const auto split, transaction.splits()) { if (!split.shares().isZero()) { - ReportAccount repSplitAcc = ReportAccount(split.accountId()); + auto repSplitAcc = file->account(split.accountId()); //only add if it is an income or expense if (repSplitAcc.isIncomeExpense()) { @@ -1623,8 +1473,9 @@ //convert to base currency if necessary if (repSplitAcc.currencyId() != file->baseCurrency().id()) { - MyMoneyMoney curPrice = repSplitAcc.baseCurrencyPrice(transaction.postDate()); - value = (split.shares() * MyMoneyMoney::MINUS_ONE) * curPrice; + const auto curPrice = file->price(repSplitAcc.tradingCurrencyId(), file->baseCurrency().id(), QDate::currentDate()); + const auto curRate = curPrice.rate(file->baseCurrency().id()); + value = (split.shares() * MyMoneyMoney::MINUS_ONE) * curRate; value = value.convert(10000); } else { value = (split.shares() * MyMoneyMoney::MINUS_ONE); @@ -1719,15 +1570,16 @@ QList::const_iterator split_it; for (split_it = splits.constBegin(); split_it != splits.constEnd(); ++split_it) { if ((*split_it).accountId() != acc.id()) { - ReportAccount repSplitAcc = ReportAccount((*split_it).accountId()); + auto repSplitAcc = file->account((*split_it).accountId()); //get the shares and multiply by the quantity of occurrences in the period MyMoneyMoney value = (*split_it).shares() * cnt; //convert to foreign currency if needed if (repSplitAcc.currencyId() != file->baseCurrency().id()) { - MyMoneyMoney curPrice = repSplitAcc.baseCurrencyPrice(QDate::currentDate()); - value = value * curPrice; + const auto curPrice = file->price(repSplitAcc.tradingCurrencyId(), file->baseCurrency().id(), QDate::currentDate()); + const auto curRate = curPrice.rate(file->baseCurrency().id()); + value = value * curRate; value = value.convert(10000); } @@ -1781,9 +1633,9 @@ MyMoneyMoney value = MyMoneyFile::instance()->balance((*account_it).id(), QDate::currentDate()); //calculate balance for foreign currency accounts if ((*account_it).currencyId() != file->baseCurrency().id()) { - ReportAccount repAcc = ReportAccount((*account_it).id()); - MyMoneyMoney curPrice = repAcc.baseCurrencyPrice(QDate::currentDate()); - MyMoneyMoney baseValue = value * curPrice; + const auto curPrice = file->price((*account_it).tradingCurrencyId(), file->baseCurrency().id(), QDate::currentDate()); + const auto curRate = curPrice.rate(file->baseCurrency().id()); + auto baseValue = value * curRate; liquidAssets += baseValue; liquidAssets = liquidAssets.convert(10000); } else { @@ -1797,9 +1649,9 @@ value = MyMoneyFile::instance()->balance((*account_it).id(), QDate::currentDate()); //calculate balance if foreign currency if ((*account_it).currencyId() != file->baseCurrency().id()) { - ReportAccount repAcc = ReportAccount((*account_it).id()); - MyMoneyMoney curPrice = repAcc.baseCurrencyPrice(QDate::currentDate()); - MyMoneyMoney baseValue = value * curPrice; + const auto curPrice = file->price((*account_it).tradingCurrencyId(), file->baseCurrency().id(), QDate::currentDate()); + const auto curRate = curPrice.rate(file->baseCurrency().id()); + auto baseValue = value * curRate; liquidLiabilities += baseValue; liquidLiabilities = liquidLiabilities.convert(10000); } else { diff --git a/kmymoney/views/kmymoneyview.cpp b/kmymoney/views/kmymoneyview.cpp --- a/kmymoney/views/kmymoneyview.cpp +++ b/kmymoney/views/kmymoneyview.cpp @@ -809,6 +809,10 @@ case eView::Action::SwitchView: showPage(view); break; + case eView::Action::ShowBalanceChart: + if (viewBases.contains(View::Reports)) + viewBases[View::Reports]->executeCustomAction(action); + break; default: break; } diff --git a/kmymoney/views/viewenums.h b/kmymoney/views/viewenums.h --- a/kmymoney/views/viewenums.h +++ b/kmymoney/views/viewenums.h @@ -66,7 +66,8 @@ EditSchedule, CleanupBeforeFileClose, InitializeAfterFileOpen, - DisableViewDepenedendActions + DisableViewDepenedendActions, + ShowBalanceChart }; }