From 115bf8f3055bbf11d03461c28bc79339e751ea63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Fri, 5 Nov 2010 19:25:11 +0100 Subject: [PATCH] Fix a bug with blocked account computation --- ressources/po/kisscount.pot | 22 +++++++++++----------- src/model/Database.cpp | 7 +++++-- src/view/AccountPanel.cpp | 17 +++++++++++++---- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/ressources/po/kisscount.pot b/ressources/po/kisscount.pot index c25267b..5247582 100644 --- a/ressources/po/kisscount.pot +++ b/ressources/po/kisscount.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-11-01 11:34+0100\n" +"POT-Creation-Date: 2010-11-03 20:33+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -35,7 +35,7 @@ msgstr "" msgid " not found, aborting" msgstr "" -#: src/view/AccountPanel.cpp:727 +#: src/view/AccountPanel.cpp:724 msgid " operations ?" msgstr "" @@ -84,11 +84,11 @@ msgid "Amount to" msgstr "" #: src/view/PreferencesPanel.cpp:401 src/view/PreferencesPanel.cpp:774 -#: src/view/AccountPanel.cpp:722 +#: src/view/AccountPanel.cpp:719 msgid "Are you sure want to delete " msgstr "" -#: src/view/PreferencesPanel.cpp:641 src/view/grid/GridAccount.cpp:760 +#: src/view/PreferencesPanel.cpp:641 src/view/grid/GridAccount.cpp:761 msgid "Are you sure want to delete : \n" msgstr "" @@ -113,11 +113,11 @@ msgstr "" msgid "Cancel" msgstr "" -#: src/view/grid/GridAccount.cpp:1144 src/view/grid/GridAccount.cpp:1151 +#: src/view/grid/GridAccount.cpp:1145 src/view/grid/GridAccount.cpp:1152 msgid "Cannot group these operations" msgstr "" -#: src/view/grid/GridAccount.cpp:1280 src/view/grid/GridAccount.cpp:1286 +#: src/view/grid/GridAccount.cpp:1271 src/view/grid/GridAccount.cpp:1277 msgid "Cannot ungroup these operations" msgstr "" @@ -217,9 +217,9 @@ msgstr "" #: src/view/PreferencesPanel.cpp:439 src/view/PreferencesPanel.cpp:660 #: src/view/PreferencesPanel.cpp:679 src/view/PreferencesPanel.cpp:719 #: src/view/PreferencesPanel.cpp:725 src/view/PasswordDialog.cpp:72 -#: src/view/PasswordDialog.cpp:78 src/view/AccountPanel.cpp:718 -#: src/view/grid/GridAccount.cpp:1144 src/view/grid/GridAccount.cpp:1151 -#: src/view/grid/GridAccount.cpp:1280 src/view/grid/GridAccount.cpp:1286 +#: src/view/PasswordDialog.cpp:78 src/view/AccountPanel.cpp:715 +#: src/view/grid/GridAccount.cpp:1145 src/view/grid/GridAccount.cpp:1152 +#: src/view/grid/GridAccount.cpp:1271 src/view/grid/GridAccount.cpp:1277 #: src/view/grid/wxGridCellFormulaEditor.cpp:69 src/model/Database.cpp:38 #: src/model/Database.cpp:55 src/model/Database.cpp:95 #: src/model/Database.cpp:102 src/model/Database.cpp:120 @@ -236,7 +236,7 @@ msgstr "" msgid "Final value" msgstr "" -#: src/view/SearchPanel.cpp:76 src/view/grid/GridAccount.cpp:300 +#: src/view/SearchPanel.cpp:76 src/view/grid/GridAccount.cpp:301 #: src/model/Database.cpp:331 src/controller/KissCount.cpp:335 msgid "Fix" msgstr "" @@ -317,7 +317,7 @@ msgstr "" msgid "It must be at least one account !" msgstr "" -#: src/view/AccountPanel.cpp:718 +#: src/view/AccountPanel.cpp:715 msgid "It must be at least one month !" msgstr "" diff --git a/src/model/Database.cpp b/src/model/Database.cpp index f40fa4f..4f1d843 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -462,7 +462,7 @@ void Database::LinkOrUnlinkOperation(Operation& op) if (op.transfert.Length()) { // No one or not linked - if (!GetOperation(op.transfert, &linked) || op.description != linked.description || op.amount != -linked.amount) + if (!GetOperation(op.transfert, &linked) || op.description != linked.description || op.amount != -linked.amount || op.account == linked.account) { req = wxT("UPDATE operation SET transfert='' where id='") + op.id + wxT("'") ; EXECUTE_SQL_UPDATE(req, ); @@ -486,12 +486,15 @@ void Database::LinkOrUnlinkOperation(Operation& op) req += wxT(" AND month='") + wxString::Format(wxT("%d"), op.month) + wxT("'"); req += wxT(" AND year='") + wxString::Format(wxT("%d"), op.year) + wxT("'"); req += wxT(" AND amount='") + DoubleToString(-op.amount) + wxT("'"); + req += wxT(" AND meta='0'"); + req += wxT(" AND account !='") + op.account + wxT("'"); + req += wxT(" AND id !='") + op.id + wxT("'"); req += wxT(" AND (transfert='' OR transfert IS NULL)"); EXECUTE_SQL_QUERY(req, set, ); // Don't need to link - if (!set.NextRow()) return ; + if (!set.NextRow()) return ; // Link linked.id = set.GetAsString(wxT("id")); diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index 33e6802..0a68f66 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -414,6 +414,7 @@ void AccountPanel::UpdateStats() std::map* notChecked = NULL; Account account; Operation op; + bool blocked_account ; curCredit = curDebit = totalCredit = totalDebit = percents = 0.0; @@ -438,6 +439,7 @@ void AccountPanel::UpdateStats() if (it->meta) continue; op = *it; + blocked_account = false; // A credit on a blocked account must be considered as a debit if (op.transfert.Length() && op.amount > 0) @@ -448,11 +450,15 @@ void AccountPanel::UpdateStats() { op.amount = -op.amount; op.transfert = wxT(""); + blocked_account = true; } } if (op.amount >= 0) { + if (!op.transfert.Length()) + totalCredit += op.amount; + if (day >= op.day) { if (!op.transfert.Length()) @@ -460,8 +466,6 @@ void AccountPanel::UpdateStats() if (!checkMode || (checkMode && op.checked)) curAccountAmount[op.account] += op.amount; } - if (!op.transfert.Length()) - totalCredit += op.amount; if (!checkMode || (checkMode && op.checked)) finalAccountAmount[op.account] += op.amount; } @@ -469,6 +473,13 @@ void AccountPanel::UpdateStats() { if (!op.transfert.Length()) _categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -op.amount ; + + if (!op.transfert.Length()) + totalDebit += -op.amount; + + if (blocked_account) + op.amount = -op.amount; + if (day >= op.day) { if (!op.transfert.Length()) @@ -476,8 +487,6 @@ void AccountPanel::UpdateStats() if (!checkMode || (checkMode && op.checked)) curAccountAmount[op.account] += op.amount; } - if (!op.transfert.Length()) - totalDebit += -op.amount; if (!checkMode || (checkMode && op.checked)) finalAccountAmount[op.account] += op.amount; }