1 /*
2 * Copyright 2005-2009 Thomas Baumgart <tbaumgart@kde.org>
3 * Copyright 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "kmymoneyfileinfodlg.h"
20
21 // ----------------------------------------------------------------------------
22 // QT Includes
23
24 #include <QLabel>
25 #include <QList>
26 #include <QDate>
27
28 // ----------------------------------------------------------------------------
29 // KDE Includes
30
31 // ----------------------------------------------------------------------------
32 // Project Includes
33
34 #include "ui_kmymoneyfileinfodlg.h"
35
36 #include "mymoneystoragemgr.h"
37 #include "mymoneyfile.h"
38 #include "mymoneyinstitution.h"
39 #include "mymoneyaccount.h"
40 #include "mymoneypayee.h"
41 #include "mymoneyprice.h"
42 #include "mymoneyschedule.h"
43 #include "mymoneytransaction.h"
44 #include "mymoneytransactionfilter.h"
45 #include "mymoneyenums.h"
46
KMyMoneyFileInfoDlg(QWidget * parent)47 KMyMoneyFileInfoDlg::KMyMoneyFileInfoDlg(QWidget *parent) :
48 QDialog(parent),
49 ui(new Ui::KMyMoneyFileInfoDlg)
50 {
51 ui->setupUi(this);
52 // Now fill the fields with data
53 auto storage = MyMoneyFile::instance()->storage();
54
55 ui->m_creationDate->setText(storage->creationDate().toString(Qt::ISODate));
56 ui->m_lastModificationDate->setText(storage->lastModificationDate().toString(Qt::ISODate));
57 ui->m_baseCurrency->setText(storage->value("kmm-baseCurrency"));
58
59 ui->m_payeeCount->setText(QString::fromLatin1("%1").arg(storage->payeeList().count()));
60 ui->m_institutionCount->setText(QString::fromLatin1("%1").arg(storage->institutionList().count()));
61
62 QList<MyMoneyAccount> a_list;
63 storage->accountList(a_list);
64 ui->m_accountCount->setText(QString::fromLatin1("%1").arg(a_list.count()));
65
66 QMap<eMyMoney::Account::Type, int> accountMap;
67 QMap<eMyMoney::Account::Type, int> accountMapClosed;
68 QList<MyMoneyAccount>::const_iterator it_a;
69 for (it_a = a_list.constBegin(); it_a != a_list.constEnd(); ++it_a) {
70 accountMap[(*it_a).accountType()] = accountMap[(*it_a).accountType()] + 1;
71 accountMapClosed[(*it_a).accountType()] = accountMapClosed[(*it_a).accountType()] + 0;
72 if ((*it_a).isClosed())
73 accountMapClosed[(*it_a).accountType()] = accountMapClosed[(*it_a).accountType()] + 1;
74 }
75
76 QMap<eMyMoney::Account::Type, int>::const_iterator it_m;
77 for (it_m = accountMap.constBegin(); it_m != accountMap.constEnd(); ++it_m) {
78 QTreeWidgetItem *item = new QTreeWidgetItem();
79 item->setText(0, MyMoneyAccount::accountTypeToString(it_m.key()));
80 item->setText(1, QString::fromLatin1("%1").arg(*it_m));
81 item->setText(2, QString::fromLatin1("%1").arg(accountMapClosed[it_m.key()]));
82 ui->m_accountView->invisibleRootItem()->addChild(item);
83 }
84
85 MyMoneyTransactionFilter filter;
86 filter.setReportAllSplits(false);
87 ui->m_transactionCount->setText(QString::fromLatin1("%1").arg(storage->transactionList(filter).count()));
88 filter.setReportAllSplits(true);
89 ui->m_splitCount->setText(QString::fromLatin1("%1").arg(storage->transactionList(filter).count()));
90 ui->m_scheduleCount->setText(QString::fromLatin1("%1").arg(storage->scheduleList(QString(), eMyMoney::Schedule::Type::Any, eMyMoney::Schedule::Occurrence::Any, eMyMoney::Schedule::PaymentType::Any,
91 QDate(), QDate(), false).count()));
92 MyMoneyPriceList list = storage->priceList();
93 MyMoneyPriceList::const_iterator it_p;
94 int pCount = 0;
95 for (it_p = list.constBegin(); it_p != list.constEnd(); ++it_p)
96 pCount += (*it_p).count();
97 ui->m_priceCount->setText(QString::fromLatin1("%1").arg(pCount));
98 }
99
~KMyMoneyFileInfoDlg()100 KMyMoneyFileInfoDlg::~KMyMoneyFileInfoDlg()
101 {
102 delete ui;
103 }
104