diff --git a/kmymoney/plugins/reconciliationreport/reconciliationreport.cpp b/kmymoney/plugins/reconciliationreport/reconciliationreport.cpp index c42c76c5f..a6221625a 100644 --- a/kmymoney/plugins/reconciliationreport/reconciliationreport.cpp +++ b/kmymoney/plugins/reconciliationreport/reconciliationreport.cpp @@ -1,336 +1,341 @@ /*************************************************************************** * Copyright 2009 Cristian Onet onet.cristian@gmail.com * * * * 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) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * 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 * ***************************************************************************/ #include "reconciliationreport.h" //! @todo remove #include #include #include #include // KDE includes #include #include #include // KMyMoney includes #include "mymoneyfile.h" #include "mymoneyaccount.h" #include "mymoneypayee.h" #include "mymoneysecurity.h" #include "mymoneysplit.h" #include "mymoneytransaction.h" #include "mymoneytransactionfilter.h" #include "mymoneyutils.h" #include "viewinterface.h" #include "mymoneyenums.h" #include "kreconciliationreportdlg.h" ReconciliationReport::ReconciliationReport(QObject *parent, const QVariantList &args) : KMyMoneyPlugin::Plugin(parent, "reconciliationreport"/*must be the same as X-KDE-PluginInfo-Name*/) { Q_UNUSED(args); qDebug("Plugins: reconciliation report loaded"); } ReconciliationReport::~ReconciliationReport() { qDebug("Plugins: reconciliation report unloaded"); } void ReconciliationReport::plug() { connect(viewInterface(), &KMyMoneyPlugin::ViewInterface::accountReconciled, this, &ReconciliationReport::slotGenerateReconciliationReport); // qDebug() << "Connect was done" << viewInterface(); } void ReconciliationReport::unplug() { disconnect(viewInterface(), &KMyMoneyPlugin::ViewInterface::accountReconciled, this, &ReconciliationReport::slotGenerateReconciliationReport); } void ReconciliationReport::slotGenerateReconciliationReport(const MyMoneyAccount& account, const QDate& date, const MyMoneyMoney& startingBalance, const MyMoneyMoney& endingBalance, const QList >& transactionList) { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneySecurity currency = file->currency(account.currencyId()); QString filename; if (!MyMoneyFile::instance()->value("reportstylesheet").isEmpty()) filename = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("html/%1").arg(MyMoneyFile::instance()->value("reportstylesheet"))); if (filename.isEmpty()) filename = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "html/kmymoney.css"); QString header = QString("\n") + QString("").arg(QUrl::fromLocalFile(filename).url()); header += ""; QColor tcolor = KColorScheme(QPalette::Active).foreground(KColorScheme::NormalText).color(); QString css; css += "\n"; header += css; header += "\n"; QString footer = "\n"; MyMoneyMoney clearedBalance = startingBalance; MyMoneyMoney clearedDepositAmount, clearedPaymentAmount; int clearedDeposits = 0; int clearedPayments = 0; MyMoneyMoney outstandingDepositAmount, outstandingPaymentAmount; int outstandingDeposits = 0; int outstandingPayments = 0; QList >::const_iterator it; for (it = transactionList.begin(); it != transactionList.end(); ++it) { // if this split is a stock split, we can't just add the amount of shares if ((*it).second.reconcileFlag() == eMyMoney::Split::State::NotReconciled) { if ((*it).second.shares().isNegative()) { outstandingPayments++; outstandingPaymentAmount += (*it).second.shares(); } else { outstandingDeposits++; outstandingDepositAmount += (*it).second.shares(); } } else { if ((*it).second.shares().isNegative()) { clearedPayments++; clearedPaymentAmount += (*it).second.shares(); } else { clearedDeposits++; clearedDepositAmount += (*it).second.shares(); } clearedBalance += (*it).second.shares(); } } QString reportName = i18n("Reconciliation report of account %1", account.name()); QString report = QString("

%1

\n").arg(reportName); report += QString("
"); report += QString("%1").arg(QLocale().toString(date, QLocale::ShortFormat)); report += QString("
\n"); report += QString("
 
\n"); report += QString("
"); report += i18n("All values shown in %1", file->baseCurrency().name()); report += QString("
\n"); report += QString("
 
\n"); report += "\n"; report += ""; report += "\n"; // row 1 report += ""; // row 2 report += ""; // row 3 report += ""; // row 4 report += ""; // separator report += ""; // row 5 report += ""; // row 6 report += ""; // row 7 report += ""; // row 8 report += ""; // retrieve list of all transactions after the reconciliation date that are not reconciled or cleared QList > afterTransactionList; MyMoneyTransactionFilter filter(account.id()); filter.addState((int)eMyMoney::TransactionFilter::State::Cleared); filter.addState((int)eMyMoney::TransactionFilter::State::NotReconciled); filter.setDateFilter(date.addDays(1), QDate()); filter.setConsiderCategory(false); filter.setReportAllSplits(true); file->transactionList(afterTransactionList, filter); MyMoneyMoney afterDepositAmount, afterPaymentAmount; int afterDeposits = 0; int afterPayments = 0; for (it = afterTransactionList.constBegin(); it != afterTransactionList.constEnd(); ++it) { // if this split is a stock split, we can't just add the amount of shares if ((*it).second.reconcileFlag() == eMyMoney::Split::State::NotReconciled) { if ((*it).second.shares().isNegative()) { afterPayments++; afterPaymentAmount += (*it).second.shares(); } else { afterDeposits++; afterDepositAmount += (*it).second.shares(); } } } // row 9 report += ""; // row 10 report += ""; // row 11 report += ""; // end of the table report += "
" + i18n("Summary") + "
"; report += i18n("Starting balance on bank statement"); report += ""; report += MyMoneyUtils::formatMoney(startingBalance, currency); report += "
"; report += i18np("%1 cleared payment", "%1 cleared payments in total", clearedPayments); report += ""; report += MyMoneyUtils::formatMoney(clearedPaymentAmount, currency); report += "
"; report += i18np("%1 cleared deposit", "%1 cleared deposits in total", clearedDeposits); report += ""; report += MyMoneyUtils::formatMoney(clearedDepositAmount, currency); report += "
"; report += i18n("Ending balance on bank statement"); report += ""; report += MyMoneyUtils::formatMoney(endingBalance, currency); report += "
"; report += i18n("Cleared balance"); report += ""; report += MyMoneyUtils::formatMoney(clearedBalance, currency); report += "
"; report += i18np("%1 outstanding payment", "%1 outstanding payments in total", outstandingPayments); report += ""; report += MyMoneyUtils::formatMoney(outstandingPaymentAmount, currency); report += "
"; report += i18np("%1 outstanding deposit", "%1 outstanding deposits in total", outstandingDeposits); report += ""; report += MyMoneyUtils::formatMoney(outstandingDepositAmount, currency); report += "
"; report += i18n("Register balance as of %1", QLocale().toString(date, QLocale::ShortFormat)); report += ""; report += MyMoneyUtils::formatMoney(MyMoneyFile::instance()->balance(account.id(), date), currency); report += "
"; report += i18np("%1 payment after %2", "%1 payments after %2", afterPayments, QLocale().toString(date, QLocale::ShortFormat)); report += ""; report += MyMoneyUtils::formatMoney(afterPaymentAmount, currency); report += "
"; report += i18np("%1 deposit after %2", "%1 deposits after %2", afterDeposits, QLocale().toString(date, QLocale::ShortFormat)); report += ""; report += MyMoneyUtils::formatMoney(afterDepositAmount, currency); report += "
"; report += i18n("Register ending balance"); report += ""; report += MyMoneyUtils::formatMoney(MyMoneyFile::instance()->balance(account.id()), currency); report += "
\n"; QString detailsTableHeader; detailsTableHeader += "\n"; detailsTableHeader += ""; detailsTableHeader += ""; detailsTableHeader += ""; detailsTableHeader += ""; detailsTableHeader += ""; detailsTableHeader += ""; detailsTableHeader += "\n"; QString detailsReport = QString("

%1

\n").arg(i18n("Outstanding payments")); detailsReport += detailsTableHeader; auto index = 0; foreach (const auto transaction, transactionList) { if (transaction.second.reconcileFlag() == eMyMoney::Split::State::NotReconciled && transaction.second.shares().isNegative()) { QString category; foreach (const auto split, transaction.first.splits()) { if (split.accountId() != account.id()) { if (!category.isEmpty()) category += ", "; // this is a split transaction category = file->account(split.accountId()).name(); } } detailsReport += QString(""; } } detailsReport += ""; detailsReport += QString("").arg(i18np("One outstanding payment of", "Total of %1 outstanding payments amounting to", outstandingPayments)).arg(MyMoneyUtils::formatMoney(outstandingPaymentAmount, currency)); detailsReport += "
" + i18n("Date") + "" + i18n("Number") + "" + i18n("Payee") + "" + i18n("Memo") + "" + i18n("Category") + "" + i18n("Amount") + "
").arg((index++ % 2 == 1) ? "row-odd" : "row-even"); detailsReport += QString("%1").arg(QLocale().toString(transaction.first.entryDate(), QLocale::ShortFormat)); detailsReport += ""; detailsReport += QString("%1").arg(transaction.second.number()); detailsReport += ""; detailsReport += QString("%1").arg(file->payee(transaction.second.payeeId()).name()); detailsReport += ""; detailsReport += QString("%1").arg(transaction.first.memo()); detailsReport += ""; detailsReport += QString("%1").arg(category); detailsReport += ""; detailsReport += QString("%1").arg(MyMoneyUtils::formatMoney(transaction.second.shares(), file->currency(account.currencyId()))); detailsReport += "
%1%2
\n"; - detailsReport += QString("

%1

\n").arg(i18n("Outstanding deposits")); + detailsReport += QString("

%1

\n").arg( + account.accountType() == eMyMoney::Account::Type::CreditCard ? i18n("Outstanding charges") : i18n("Outstanding deposits")); detailsReport += detailsTableHeader; index = 0; for (it = transactionList.begin(); it != transactionList.end(); ++it) { if ((*it).second.reconcileFlag() == eMyMoney::Split::State::NotReconciled && !(*it).second.shares().isNegative()) { QString category; foreach (const auto split, (*it).first.splits()) { if (split.accountId() != account.id()) { if (!category.isEmpty()) category += ", "; // this is a split transaction category = file->account(split.accountId()).name(); } } detailsReport += QString("").arg((index++ % 2 == 1) ? "row-odd" : "row-even") + QString("%1").arg(QLocale().toString((*it).first.entryDate(), QLocale::ShortFormat)) + "" + QString("%1").arg((*it).second.number()) + "" + QString("%1").arg(file->payee((*it).second.payeeId()).name()) + "" + QString("%1").arg((*it).first.memo()) + "" + QString("%1").arg(category) + "" + QString("%1").arg(MyMoneyUtils::formatMoney((*it).second.shares(), file->currency(account.currencyId()))) + ""; } } detailsReport += "" - + QString("%1%2").arg(i18np("One outstanding deposit of", "Total of %1 outstanding deposits amounting to", outstandingDeposits)).arg(MyMoneyUtils::formatMoney(outstandingDepositAmount, currency)) + + QString("%1%2").arg( + account.accountType() == eMyMoney::Account::Type::CreditCard ? + i18np("One outstanding charges of", "Total of %1 outstanding charges amounting to", outstandingDeposits) : + i18np("One outstanding deposit of", "Total of %1 outstanding deposits amounting to", outstandingDeposits) + ).arg(MyMoneyUtils::formatMoney(outstandingDepositAmount, currency)) // end of the table + "\n"; QPointer dlg = new KReportDlg(0, header + report + footer, header + detailsReport + footer); dlg->exec(); delete dlg; } K_PLUGIN_FACTORY_WITH_JSON(ReconciliationReportFactory, "reconciliationreport.json", registerPlugin();) #include "reconciliationreport.moc"