Set background calendar color to red or yellow when one account is negative or less than 200€

This commit is contained in:
Grégory Soutadé 2017-01-01 17:20:08 +01:00
parent 23829bdf70
commit 0b037cff7c
2 changed files with 81 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/*
Copyright 2010-2015 Grégory Soutadé
Copyright 2010-2016 Grégory Soutadé
This file is part of KissCount.
@ -30,7 +30,7 @@
#include <view/wxUI.hpp>
#define APP_VERSION "0.6"
#define APP_VERSION "0.7"
#define ESCAPE_CHARS(s) s = s.replace("\"", " ");
// #define ESCAPE_CHARS(s) s = s.replace("\"", "\\\""); s = s.replace("\'", "\\\'");

View File

@ -506,11 +506,12 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year)
void AccountPanel::UpdateStats()
{
int i;
int i, nbDays, minimalValue;
User* user = _kiss->GetUser();
std::vector<Operation>::iterator it;
int curCredit, curDebit, totalCredit, totalDebit, balance, value, value2, percents;
std::map<int, int> curAccountAmount, finalAccountAmount;
std::map<int, int> finalAccountAmount;
std::map<int, int>* curAccountAmounts; // For each day
std::map<int, int>::iterator intIt;
std::vector<Account>::iterator accountIt;
unsigned int day;
@ -521,6 +522,10 @@ void AccountPanel::UpdateStats()
Operation op;
bool blocked_account ;
QString v;
QDate selectedDate;
QTextCharFormat textFormat;
QBrush brush;
int minStartAccount = 0;
_inModification = true;
@ -536,19 +541,24 @@ void AccountPanel::UpdateStats()
if (mode == REAL_MODE || mode == CHECK_MODE)
virtuals = _kiss->GetVirtualAmount(_curMonth, _curYear);
day = _calendar->selectedDate().day()-1;
selectedDate = _calendar->selectedDate();
day = selectedDate.day()-1;
nbDays = selectedDate.daysInMonth();
curAccountAmounts = new std::map<int, int>[nbDays];
for (i=0; i<user->GetCategoriesNumber(); i++)
_categoriesValues[i] = 0.0;
for (intIt=_accountsInitValues.begin(); intIt!=_accountsInitValues.end(); intIt++)
{
curAccountAmount[intIt->first] = _accountsInitValues[intIt->first];
finalAccountAmount[intIt->first] = _accountsInitValues[intIt->first];
finalAccountAmount[intIt->first] = _accountsInitValues[intIt->first];
for(i=0; i<nbDays; i++)
curAccountAmounts[i][intIt->first] = _accountsInitValues[intIt->first];
if (mode == REAL_MODE || mode == CHECK_MODE)
{
curAccountAmount[intIt->first] += -(*virtuals)[intIt->first];
for(i=0; i<nbDays; i++)
curAccountAmounts[i][intIt->first] += -(*virtuals)[intIt->first];
finalAccountAmount[intIt->first] += -(*virtuals)[intIt->first];
}
}
@ -590,9 +600,7 @@ void AccountPanel::UpdateStats()
{
if (!op.transfert && !account.blocked)
curCredit += op.amount;
curAccountAmount[op.account] += op.amount;
}
finalAccountAmount[op.account] += op.amount;
}
else
{
@ -610,11 +618,67 @@ void AccountPanel::UpdateStats()
if (blocked_account)
op.amount = -op.amount;
if (day >= op.day)
curAccountAmount[op.account] += op.amount;
finalAccountAmount[op.account] += op.amount;
}
finalAccountAmount[op.account] += op.amount;
curAccountAmounts[op.day][op.account] += op.amount;
for(i=op.day+1; i<nbDays; i++)
curAccountAmounts[i][op.account] = curAccountAmounts[op.day][op.account];
}
if (mode != CHECK_MODE)
{
for (intIt=curAccountAmounts[0].begin(); intIt!=curAccountAmounts[0].end(); intIt++)
{
if (!user->GetAccount(intIt->first).hidden)
{
minStartAccount = intIt->first;
break;
}
}
}
for(i=0; i<nbDays; i++)
{
textFormat = _calendar->dateTextFormat(QDate(_curYear, _curMonth+1, i+1));
if (mode != CHECK_MODE)
{
minimalValue = curAccountAmounts[i][minStartAccount];
for (intIt=curAccountAmounts[i].begin(); intIt!=curAccountAmounts[i].end(); intIt++)
{
if (user->GetAccount(intIt->first).hidden)
continue;
if (curAccountAmounts[i][intIt->first] < minimalValue)
minimalValue = curAccountAmounts[i][intIt->first];
}
if (minimalValue <= 0)
{
brush.setColor(Qt::red);
textFormat.setBackground(brush);
QDate date(_curYear, _curMonth+1, i+1);
if (date.dayOfWeek() == 6 || date.dayOfWeek() == 7)
{
brush.setColor(Qt::black);
textFormat.setForeground(brush);
}
}
else if (minimalValue <= 200*100)
{
brush.setColor(QColor(240,195,0));
textFormat.setBackground(brush);
}
else
{
textFormat.clearBackground();
}
}
else
{
textFormat.clearBackground();
}
_calendar->setDateTextFormat(QDate(_curYear, _curMonth+1, i+1), textFormat);
}
balance = totalCredit - totalDebit;
@ -640,7 +704,7 @@ void AccountPanel::UpdateStats()
if (mode == REAL_MODE)
value -= (*virtuals)[accountIt->id];
_accountsGrid->item(i, ACCOUNT_INIT)->setText(v.sprintf("%.2lf", (double)value/100));
value = curAccountAmount[accountIt->id];
value = curAccountAmounts[day][accountIt->id];
_accountsGrid->item(i, ACCOUNT_CUR)->setText(v.sprintf("%.2lf", (double)value/100));
_accountsGrid->item(i, ACCOUNT_CUR)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red));
value = finalAccountAmount[accountIt->id];
@ -652,7 +716,7 @@ void AccountPanel::UpdateStats()
value2 = (*notChecked)[accountIt->id];
_accountsGrid->item(i, ACCOUNT_INIT)->setText(v.sprintf("%.2lf (%.2lf)", (double)value/100, (double)(value-value2)/100));
value = curAccountAmount[accountIt->id];
value = curAccountAmounts[day][accountIt->id];
_accountsGrid->item(i, ACCOUNT_CUR)->setText(v.sprintf("%.2lf (%.2lf)", (double)value/100, (double)(value-value2)/100));
_accountsGrid->item(i, ACCOUNT_CUR)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red));
value = finalAccountAmount[accountIt->id];
@ -668,6 +732,7 @@ void AccountPanel::UpdateStats()
if (notChecked) delete notChecked;
if (virtuals) delete virtuals;
delete[] curAccountAmounts;
_statsGrid->resizeColumnToContents(1);