Now fixed operations is not necessary bound to fix category

This commit is contained in:
Grégory Soutadé 2019-01-29 19:31:35 +01:00
parent 1fbb920cb3
commit ea6a320416
5 changed files with 39 additions and 20 deletions

View File

@ -1617,6 +1617,9 @@ void Database::GetStats(User* user, int monthFrom, int yearFrom, int monthTo,
{
for (categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++)
{
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);

View File

@ -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)
{

View File

@ -53,7 +53,8 @@ CostRepartitionBanner::CostRepartitionBanner(KissCount* kiss, QFrame* parent, QS
_pie->setMargins(QMargins(5, 5, 5, 5));
for(i=0; i<nbCategories; i++)
/* Ignore fix category */
for(i=1; i<nbCategories; i++)
{
slice = series->append(_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];

View File

@ -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<Operation>::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);

View File

@ -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,7 +456,7 @@ 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)
if (!op.meta)
setItem(line, CATEGORY, new QTableWidgetItem(_(cat.name.toStdString().c_str())));
if (tag.id)
@ -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,9 +1155,16 @@ 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);
if (row <= _fixCosts)
{
SET_ROW_FONT(row, user->GetCategoryFont(0));
}
else
{
SET_ROW_FONT(row, user->GetCategoryFont(cat.id));
}
}
}
// Add an operation
else
{