Mercurial > hg > syntilista
diff src/main.cpp @ 130:10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 23 Aug 2017 16:53:05 +0300 |
parents | f6685c2eb75d |
children | dc9fe580da42 |
line wrap: on
line diff
--- a/src/main.cpp Wed Aug 23 14:11:27 2017 +0300 +++ b/src/main.cpp Wed Aug 23 16:53:05 2017 +0300 @@ -84,7 +84,8 @@ { QTextStream out(&fh); out << - slDateTimeToLocal(QDateTime::currentDateTimeUtc()).toString(QStringLiteral("yyyy-MM-dd hh:mm:ss")) + slDateTimeToLocal(QDateTime::currentDateTimeUtc()). + toString(QStringLiteral("yyyy-MM-dd hh:mm:ss")) << " : " << msg << "\n"; fh.close(); } @@ -914,7 +915,7 @@ // void SyntilistaMainWindow::updatePersonList() { - static QString queryBase = + static const QString queryBase = "SELECT id,last_name,first_name," "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance," "updated FROM people"; @@ -976,6 +977,44 @@ model_People->setHeaderData(2, Qt::Horizontal, tr("Etunimi")); model_People->setHeaderData(3, Qt::Horizontal, tr("Tase")); model_People->setHeaderData(4, Qt::Horizontal, tr("Muutettu")); + + updateTotalBalance(); +} + + +// +// Update total balance value in the UI +// +void SyntilistaMainWindow::updateTotalBalance() +{ + // Update total balance value + QSqlQuery query; + query.prepare(QStringLiteral("SELECT TOTAL(value) FROM transactions AS balance")); + query.exec(); + if (!slCheckAndReportSQLError("updatePersonList() get total balance query", query.lastError())) + { + slErrorMsg( + tr("SQL-tietokantavirhe"), + tr("Tietokantaa kyseltäessä tapahtui virhe.")); + } + else + { + double balance; + QString tmp ; + if (query.next()) + { + balance = query.value(0).toDouble();; + tmp = slMoneyValueToStr(balance); + } + else + { + balance = -1; + tmp = "?"; + } + + ui->label_TotalBalanceValue->setText(tmp); + ui->label_TotalBalanceValue->setStyleSheet(balance < 0 ? "color: red;" : "color: green;"); + } } @@ -1023,6 +1062,8 @@ QSqlDatabase::database().commit(); + updateTotalBalance(); + return 0; }