From ea6a3204168fa9b7c9ff61719ed8ef16ae3e7194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Tue, 29 Jan 2019 19:31:35 +0100 Subject: [PATCH] Now fixed operations is not necessary bound to fix category --- src/model/Database.cpp | 5 ++++- src/view/AccountPanel.cpp | 4 ++++ src/view/CostRepartitionBanner.cpp | 12 +++++++----- src/view/SearchPanel.cpp | 7 +------ src/view/grid/GridAccount.cpp | 31 ++++++++++++++++++++++-------- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/model/Database.cpp b/src/model/Database.cpp index bff8c0e..071ed20 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -1617,7 +1617,10 @@ void Database::GetStats(User* user, int monthFrom, int yearFrom, int monthTo, { for (categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++) { - req = "SELECT SUM(amount) as amount FROM operation AS o1 WHERE category='" + QString::number(categoryIt->id) + "'"; + if (categoryIt->id == 1) + req = "SELECT SUM(amount) as amount FROM operation AS o1 WHERE (category='" + QString::number(categoryIt->id) + "' OR fix_cost='1')"; + else + req = "SELECT SUM(amount) as amount FROM operation AS o1 WHERE category='" + QString::number(categoryIt->id) + "'"; accountIt = user->_accounts.begin(); req += " AND (account IN('" + QString::number(accountIt->id); accountIt++; diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index 5fabb5d..67c5df4 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -632,7 +632,11 @@ void AccountPanel::UpdateStats() else { if ((!op.transfert || force_debit) && user->GetCategoryName(op.category) != _("Unknown")) + { + if (op.fix_cost && op.category != 1) + _categoriesValues[0] += -op.amount ; _categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -op.amount ; + } if (!op.transfert || force_debit) { diff --git a/src/view/CostRepartitionBanner.cpp b/src/view/CostRepartitionBanner.cpp index a39193c..8b62ba5 100644 --- a/src/view/CostRepartitionBanner.cpp +++ b/src/view/CostRepartitionBanner.cpp @@ -52,8 +52,9 @@ CostRepartitionBanner::CostRepartitionBanner(KissCount* kiss, QFrame* parent, QS legend->setShowToolTips(true); _pie->setMargins(QMargins(5, 5, 5, 5)); - - for(i=0; iappend(_categories[i], 0); if (i < wxUI::MAX_CATEGORY) @@ -149,11 +150,12 @@ void CostRepartitionBanner::UpdateCosts(int *categoriesValues, int totalDebit) if (!i) _statsGrid->item(i, 1)->setText(v.sprintf("%.2lf (%02d %%)", (double)categoriesValues[i]/100, (int)percents)); else + { _statsGrid->item(i+1, 1)->setText(v.sprintf("%.2lf (%02d %%)", (double)categoriesValues[i]/100, (int)percents)); - - slices[i]->setValue(categoriesValues[i] / 100); - slices[i]->setLabelVisible(categoriesValues[i] != 0.0); + slices[i-1]->setValue(categoriesValues[i] / 100); + slices[i-1]->setLabelVisible(categoriesValues[i] != 0.0); + } } value = totalDebit - categoriesValues[0]; diff --git a/src/view/SearchPanel.cpp b/src/view/SearchPanel.cpp index b1f2edc..75a6796 100644 --- a/src/view/SearchPanel.cpp +++ b/src/view/SearchPanel.cpp @@ -216,10 +216,8 @@ void SearchPanel::OnButtonChangeAccount() static void ChangeCategory(Operation* op, void** params) { int* category = (int*) params[0]; - bool* fix = (bool*) params[1]; op->category = *category; - op->fix_cost = * fix; } void SearchPanel::OnButtonChangeCategory() @@ -231,8 +229,7 @@ void SearchPanel::OnButtonChangeCategory() std::vector::iterator it; QString res; int category; - bool fix; - void * params[] = {&category, &fix}; + void * params[] = {&category}; if (!_operations) return; @@ -248,12 +245,10 @@ void SearchPanel::OnButtonChangeCategory() { a = categories.indexOf(res); category = user->_categories[a-1].id ; - fix = user->_categories[a-1].fix_cost; } else { category = 0; - fix = false; } _grid->MassUpdate(rows, true, ChangeCategory, params); diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 2cbc899..bbe5ac6 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -431,9 +431,6 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, if (fix) { - item = new QTableWidgetItem(_("Fix")); - setItem(line, CATEGORY, item); - SET_READ_ONLY(item); _fixCosts++; } @@ -459,8 +456,8 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, if (!op.meta) setItem(line, ACCOUNT, new QTableWidgetItem(user->GetAccountName(op.account))); - if (!fix && !op.meta) - setItem(line, CATEGORY, new QTableWidgetItem(_(cat.name.toStdString().c_str()))); + if (!op.meta) + setItem(line, CATEGORY, new QTableWidgetItem(_(cat.name.toStdString().c_str()))); if (tag.id) setItem(line, TAG, new QTableWidgetItem(_(tag.name.toStdString().c_str()))); @@ -481,10 +478,15 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, setItem(line, CREDIT, new QTableWidgetItem(v.sprintf("%.2lf", (double)amount/100))); } + if (line <= _fixCosts) + cat = user->GetCategory(1); + if (op.category) color = cat.backcolor; else - color = view::OWN_GREEN; + { + color = (op.fix_cost) ? view::OWN_YELLOW : view::OWN_GREEN; + } if (op.checked) { @@ -705,6 +707,7 @@ void GridAccount::CheckOperation(Operation& op, int line, bool check, bool force QColor color; int r,g,b; User* user = _kiss->GetUser(); + Category cat; if (!force) { @@ -718,7 +721,12 @@ void GridAccount::CheckOperation(Operation& op, int line, bool check, bool force checkBox->setCheckState(check ? Qt::Checked : Qt::Unchecked); } - color = user->GetCategory(op.category).backcolor; + if (line <= _fixCosts) + cat = user->GetCategory(1); + else + cat = user->GetCategory(op.category); + + color = cat.backcolor; if (check) { @@ -1147,7 +1155,14 @@ void GridAccount::OnOperationModified(int row, int col) (_displayedOperations)[row] = new_op; cat = user->GetCategory(new_op.category); CheckOperation(new_op, row, new_op.checked, true); - SET_ROW_FONT(row, user->GetCategoryFont(cat.id)); + if (row <= _fixCosts) + { + SET_ROW_FONT(row, user->GetCategoryFont(0)); + } + else + { + SET_ROW_FONT(row, user->GetCategoryFont(cat.id)); + } } } // Add an operation