From c565c7740df13184a12cafacac3abbee2d36d026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 5 May 2012 16:49:24 +0200 Subject: [PATCH] Show hidden accounts at the end in the list Simplify statistics computation in AccountPanel Don't take in account simple credit on blocked accounts --- src/model/Database.cpp | 4 +- src/view/AccountPanel.cpp | 166 +++++++++++--------------------------- 2 files changed, 49 insertions(+), 121 deletions(-) diff --git a/src/model/Database.cpp b/src/model/Database.cpp index 6d0ac09..b9e6360 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -266,7 +266,7 @@ User* Database::LoadUser(const QString& name) query.clear(); - req = QString("SELECT * FROM account WHERE user='%1' ORDER BY default_account DESC, blocked, virtual, name ASC").arg(user->_id); + req = QString("SELECT * FROM account WHERE user='%1' ORDER BY default_account DESC, hidden, blocked, virtual, name ASC").arg(user->_id); EXECUTE_SQL_QUERY_WITH_CODE(req, 0, {delete user;}, {delete user;}); @@ -279,7 +279,7 @@ User* Database::LoadUser(const QString& name) query.clear(); - req = QString("SELECT * FROM account WHERE id IN (SELECT account FROM shared_account WHERE user='%1') ORDER BY name, blocked, virtual ASC").arg(user->_id); + req = QString("SELECT * FROM account WHERE id IN (SELECT account FROM shared_account WHERE user='%1') ORDER BY default_account DESC, hidden, blocked, virtual, name ASC").arg(user->_id); EXECUTE_SQL_QUERY_WITH_CODE(req, 0, {delete user;}, {delete user;}); diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index ecc1663..d19adf7 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -619,133 +619,61 @@ void AccountPanel::UpdateStats() op = *it; blocked_account = false; - // A credit on a blocked account must be considered as a debit - if (op.transfert && op.amount > 0) - { - account = user->GetAccount(op.account); + if ((mode == REAL_MODE || mode == CHECK_MODE) && op._virtual) + continue; - if (account.blocked) - { - op.amount = -op.amount; - op.transfert = 0; - blocked_account = true; - } + if (mode == CHECK_MODE && !op.checked) + continue; + + account = user->GetAccount(op.account); + + if (account.blocked) + { + if (op.transfert && op.amount > 0) + { + // A Transfert on a blocked account must be considered as a debit + op.amount = -op.amount; + // op.transfert = 0; + blocked_account = true; + } + // else + // continue; } + if (op.amount >= 0) + { + if (!op.transfert && !account.blocked) + totalCredit += op.amount; - switch(mode) - { - case VIRTUAL_MODE: - if (op.amount >= 0) - { - if (!op.transfert) - totalCredit += op.amount; + if (day >= op.day) + { + if (!op.transfert && !account.blocked) + curCredit += op.amount; + curAccountAmount[op.account] += op.amount; + } + finalAccountAmount[op.account] += op.amount; + } + else + { + if ((!op.transfert || account.blocked) && user->GetCategoryName(op.category) != _("Unknown")) + _categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -op.amount ; - if (day >= op.day) - { - if (!op.transfert) - curCredit += op.amount; - curAccountAmount[op.account] += op.amount; - } - finalAccountAmount[op.account] += op.amount; - } - else - { - if (!op.transfert && user->GetCategoryName(op.category) != _("Unknown")) - _categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -op.amount ; + if (!op.transfert || account.blocked) + totalDebit += -op.amount; - if (!op.transfert) - totalDebit += -op.amount; + if (day >= op.day) + { + if (!op.transfert || account.blocked) + curDebit += -op.amount; + } - if (blocked_account) - op.amount = -op.amount; + if (blocked_account) + op.amount = -op.amount; - if (day >= op.day) - { - if (!op.transfert) - curDebit += -op.amount; - curAccountAmount[op.account] += op.amount; - } - finalAccountAmount[op.account] += op.amount; - } - break; - case REAL_MODE: - if (op.amount >= 0) - { - if (!op.transfert) - totalCredit += op.amount; - - if (day >= op.day) - { - if (!op.transfert) - curCredit += op.amount; - if (!op._virtual) - curAccountAmount[op.account] += op.amount; - } - if (!op._virtual) - finalAccountAmount[op.account] += op.amount; - } - else - { - if (!op.transfert && user->GetCategoryName(op.category) != _("Unknown")) - _categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -op.amount ; - - if (!op.transfert && !op._virtual) - totalDebit += -op.amount; - - if (blocked_account) - op.amount = -op.amount; - - if (day >= op.day) - { - if (!op.transfert && !op._virtual) - curDebit += -op.amount; - if (!op._virtual) - curAccountAmount[op.account] += op.amount; - } - if (!op._virtual) - finalAccountAmount[op.account] += op.amount; - } - break; - case CHECK_MODE: - if (op.amount >= 0) - { - if (!op.transfert && !op._virtual) - totalCredit += op.amount; - - if (day >= op.day) - { - if (!op.transfert && !op._virtual) - curCredit += op.amount; - if (op.checked && !op._virtual) - curAccountAmount[op.account] += op.amount; - } - if (op.checked && !op._virtual) - finalAccountAmount[op.account] += op.amount; - } - else - { - if (!op.transfert && user->GetCategoryName(op.category) != _("Unknown")) - _categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -op.amount ; - - if (!op.transfert && !op._virtual) - totalDebit += -op.amount; - - if (blocked_account) - op.amount = -op.amount; - - if (day >= op.day) - { - if (!op.transfert && !op._virtual) - curDebit += -op.amount; - if (op.checked && !op._virtual) - curAccountAmount[op.account] += op.amount; - } - if (op.checked && !op._virtual) - finalAccountAmount[op.account] += op.amount; - } - break; - } + if (day >= op.day) + curAccountAmount[op.account] += op.amount; + finalAccountAmount[op.account] += op.amount; + } } balance = totalCredit - totalDebit;