Add stats

This commit is contained in:
Grégory Soutadé 2011-09-13 21:39:22 +02:00
parent 98513c1ca9
commit ae4a0eb7ac
3 changed files with 406 additions and 346 deletions

View File

@ -413,7 +413,8 @@ double Database::GetAccountAmount(int id, int month, int year)
double res = 0.0;
QSqlQuery query(_db);
req = QString("SELECT amount FROM account_amount WHERE account='%1' AND month='%2' AND year='%3'").arg(id, month, year) ;
req = QString("SELECT amount FROM account_amount WHERE account='%1' AND month='%2' AND year='%3'")
.arg(QString::number(id), QString::number(month), QString::number(year)) ;
EXECUTE_SQL_QUERY(req, 0.0);
@ -437,7 +438,8 @@ double Database::CalcAccountAmount(int id, int month, int year, bool* had_values
double res = 0.0;
QSqlQuery query(_db);
req = QString("SELECT SUM(id) AS id, SUM(amount) AS amount FROM operation WHERE account='%1' AND month='%2' AND year='%3' AND meta='0'").arg(id, month ,year) ;
req = QString("SELECT SUM(id) AS id, SUM(amount) AS amount FROM operation WHERE account='%1' AND month='%2' AND year='%3' AND meta='0'").
arg(QString::number(id), QString::number(month), QString::number(year)) ;
EXECUTE_SQL_QUERY(req, 0.0);
@ -465,7 +467,7 @@ bool Database::GetOperation(int id, Operation* op)
QString req;
QSqlQuery query(_db);
req = QString("SELECT * FROM operation WHERE id='%1").arg(id);
req = QString("SELECT * FROM operation WHERE id='%1").arg(QString::number(id));
EXECUTE_SQL_QUERY(req, false);

View File

@ -20,6 +20,9 @@
// #include "grid/wxGridCellBitmapRenderer.hpp"
// #include "GenerateDialog.hpp"
#include <QHeaderView>
#include <QGroupBox>
#include "AccountPanel.hpp"
enum {ACCOUNT_NUMBER, ACCOUNT_NAME, ACCOUNT_INIT, ACCOUNT_CUR, ACCOUNT_FINAL, NUMBER_COLS_ACCOUNTS};
@ -46,6 +49,7 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
_tree = new QTreeWidget(this);
_tree->headerItem()->setHidden(true);
_tree->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
// ColorScheme* colorScheme = new ColorScheme(wxUI::categoryColors, WXSIZEOF(wxUI::categoryColors));
// _pie = new PiePlot();
@ -54,6 +58,8 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
_calendar->setFirstDayOfWeek(Qt::Monday);
_calendar->setNavigationBarVisible(false);
_calendar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
_accounts = new QString[user->GetAccountsNumber()];
for (i=0,
accountIt = user->_accounts.begin();
@ -87,21 +93,31 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
// _grid = new GridAccount(_kiss, this, OPS_GRID_ID, true, true, true);
// _accountsGrid = new wxGrid(this, ACCOUNTS_GRID_ID);
// _accountsGrid->CreateGrid(0, NUMBER_COLS_ACCOUNTS);
// _accountsGrid->SetRowLabelSize(0);
_accountsGrid = new QTableWidget(this);
_accountsGrid->setColumnCount(NUMBER_COLS_ACCOUNTS);
_accountsGrid->setRowCount(0);
_accountsGrid->verticalHeader()->setHidden(true);
// _accountsGrid->SetDefaultCellFont(font);
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_NUMBER, new QTableWidgetItem(_("Account number")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_NAME, new QTableWidgetItem(_("Account name")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_INIT, new QTableWidgetItem(_("Initial value")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_CUR, new QTableWidgetItem(_("Current value")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_FINAL, new QTableWidgetItem(_("Final value")));
// _accountsGrid->SetColLabelValue(ACCOUNT_NUMBER, _("Account number"));
// _accountsGrid->SetColLabelValue(ACCOUNT_NAME, _("Account name"));
// _accountsGrid->SetColLabelValue(ACCOUNT_INIT, _("Initial value"));
// _accountsGrid->SetColLabelValue(ACCOUNT_CUR, _("Current value"));
// _accountsGrid->SetColLabelValue(ACCOUNT_FINAL, _("Final value"));
_accountsGrid->resizeColumnsToContents();
_accountsGrid->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
for(i=0; i<NUMBER_COLS_ACCOUNTS; i++)
{
QFont font = _accountsGrid->horizontalHeaderItem(i)->font();
font.setBold(true);
_accountsGrid->horizontalHeaderItem(i)->setFont(font);
}
// _accountsGrid->AutoSizeColumns(true);
// _statsGrid = new wxGrid(this, wxID_ANY);
_statsGrid = new QTableWidget(this);
_statsGrid->verticalHeader()->setHidden(true);
_statsGrid->horizontalHeader()->setHidden(true);
_statsGrid->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
// chart = new wxChartPanel(this);
// chart->SetChart(new Chart(_pie, _("Cost repartition")));
@ -110,6 +126,23 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
// chart->SetMinSize(// chart->GetSize()
// wxSize(200,300));
QGroupBox *groupBox = new QGroupBox(_("Mode"));
_virtual = new QRadioButton(_("Virtual"));
_real = new QRadioButton(_("Real"));
_check = new QRadioButton(_("Check"));
_virtual->setChecked(true);
{
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(_virtual);
vbox->addWidget(_real);
vbox->addWidget(_check);
groupBox->setLayout(vbox);
}
// wxString modes[3] = {_("Virtual"), _("Real"), _("Check")};
// _radioMode = new wxRadioBox(this, DISPLAY_MODE_ID, _("Mode"), wxDefaultPosition, wxDefaultSize,
// 3, modes);
@ -124,18 +157,18 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
// vbox3->Add(buttonUpdateNextMonths, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10);
// vbox3->Add(buttonGroup, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10);
// vbox3->Add(buttonUnGroup, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10);
// vbox3->Add(_radioMode, 0, wxALIGN_CENTER_HORIZONTAL|wxUP, 50);
vbox3->addStretch(1);
vbox3->addWidget(groupBox);
hbox->addLayout(vbox3);
// // hbox->Add(vbox3, 0, wxGROW|wxALL, 2);
// hbox2->Add(_accountsGrid, 0, wxGROW|wxALL, 2);
hbox2->addWidget(_accountsGrid, 2);
hbox2->addWidget(_calendar);
vbox2->addLayout(hbox2);
// vbox2->Add(_grid, 0, wxGROW|wxALL, 2);
hbox->addLayout(vbox2);
// vbox->Add(_statsGrid, 0, wxGROW);
vbox->addWidget(_statsGrid);
// vbox->Add(chart, 0, wxALIGN_CENTER_HORIZONTAL|wxUP, 10);
// hbox->Add(vbox, 0, wxGROW|wxALL, 2);
hbox->addLayout(vbox);
ChangeUser();
@ -177,60 +210,71 @@ QString AccountPanel::GetToolTip()
void AccountPanel::InitStatsGrid(User* user)
{
// int i;
// int nb_categories = user->GetCategoriesNumber();
// DEFAULT_FONT(font);
int i;
int nb_categories = user->GetCategoriesNumber();
DEFAULT_FONT(font);
// if (!_statsGrid->GetNumberRows())
// {
// _statsGrid->CreateGrid(nb_categories+CATS_STATS+1, 2); // Headers + blank + categories + non fix
// _statsGrid->SetColLabelSize(0);
// _statsGrid->SetRowLabelSize(0);
// _statsGrid->EnableEditing(false);
// }
// else
// {
// _statsGrid->DeleteRows(0, _statsGrid->GetNumberRows());
// _statsGrid->InsertRows(0, nb_categories+CATS_STATS);
// }
if (!_statsGrid->rowCount())
{
_statsGrid->setColumnCount(2);
//_statsGrid->EnableEditing(false);
}
else
{
_statsGrid->clear();
}
_statsGrid->setRowCount(nb_categories+CATS_STATS+1); // Headers + blank + categories + non fix
// _statsGrid->SetDefaultCellFont(font);
// _statsGrid->SetCellValue(TOTAL_CREDIT, 0, _("Total Credit"));
// _statsGrid->SetCellValue(TOTAL_DEBIT, 0, _("Total Debit"));
_statsGrid->setItem(TOTAL_CREDIT, 0, new QTableWidgetItem(_("Total Credit")));
_statsGrid->setItem(TOTAL_DEBIT, 0, new QTableWidgetItem(_("Total Debit")));
// for(i=0; i<nb_categories; i++)
// {
// if (i)
// {
// _statsGrid->SetCellValue(CATS_STATS+i+1, 0, _categories[i]);
// _statsGrid->SetCellAlignment(CATS_STATS+i+1, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
// }
// else
// {
// _statsGrid->SetCellValue(CATS_STATS+i, 0, _categories[i]);
// _statsGrid->SetCellAlignment(CATS_STATS+i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
// }
// }
for(i=0; i<nb_categories; i++)
{
if (i)
{
_statsGrid->setItem(CATS_STATS+i+1, 0, new QTableWidgetItem(_categories[i]));
_statsGrid->setItem(CATS_STATS+i+1, 1, new QTableWidgetItem(""));
_statsGrid->item(CATS_STATS+i+1, 1)->setTextAlignment(Qt::AlignRight);
}
else
{
_statsGrid->setItem(CATS_STATS+i, 0, new QTableWidgetItem(_categories[i]));
_statsGrid->setItem(CATS_STATS+i, 1, new QTableWidgetItem(""));
_statsGrid->item(CATS_STATS+i, 1)->setTextAlignment(Qt::AlignRight);
}
}
// _statsGrid->AutoSizeColumn(0, false);
// font.SetWeight(wxFONTWEIGHT_BOLD);
// _statsGrid->SetCellFont(CUR_CREDIT, 0, font);
// _statsGrid->SetCellFont(CUR_DEBIT, 0, font);
// _statsGrid->SetCellFont(BALANCE, 0, font);
// _statsGrid->SetCellFont(BALANCE, 1, font);
font.setBold(true);
// _statsGrid->SetCellValue(CUR_CREDIT, 0, _("Cur Credit"));
// _statsGrid->SetCellValue(CUR_DEBIT, 0, _("Cur Debit"));
// _statsGrid->SetCellValue(BALANCE, 0, _("Balance"));
// _statsGrid->SetCellValue(NON_FIX, 0, _("Non fix"));
_statsGrid->setItem(CUR_CREDIT, 0, new QTableWidgetItem(_("Cur Credit")));
_statsGrid->setItem(CUR_DEBIT, 0, new QTableWidgetItem(_("Cur Debit")));
_statsGrid->setItem(TOTAL_CREDIT, 0, new QTableWidgetItem(_("Total Credit")));
_statsGrid->setItem(TOTAL_DEBIT, 0, new QTableWidgetItem(_("Total Debit")));
_statsGrid->setItem(BALANCE, 0, new QTableWidgetItem(_("Balance")));
_statsGrid->setItem(NON_FIX, 0, new QTableWidgetItem(_("Non fix")));
// _statsGrid->SetCellAlignment(CUR_DEBIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
// _statsGrid->SetCellAlignment(CUR_CREDIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
// _statsGrid->SetCellAlignment(TOTAL_DEBIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
// _statsGrid->SetCellAlignment(TOTAL_CREDIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
// _statsGrid->SetCellAlignment(BALANCE, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
// _statsGrid->SetCellAlignment(NON_FIX, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
_statsGrid->setItem(CUR_CREDIT, 1, new QTableWidgetItem(_("")));
_statsGrid->setItem(CUR_DEBIT, 1, new QTableWidgetItem(_("")));
_statsGrid->setItem(TOTAL_CREDIT, 1, new QTableWidgetItem(_("")));
_statsGrid->setItem(TOTAL_DEBIT, 1, new QTableWidgetItem(_("")));
_statsGrid->setItem(BALANCE, 1, new QTableWidgetItem(_("")));
_statsGrid->setItem(NON_FIX, 1, new QTableWidgetItem(_("")));
_statsGrid->item(CUR_DEBIT, 0)->setFont(font);
_statsGrid->item(CUR_CREDIT, 0)->setFont(font);
_statsGrid->item(BALANCE, 0)->setFont(font);
_statsGrid->item(BALANCE, 1)->setFont(font);
_statsGrid->item(CUR_CREDIT, 1)->setTextAlignment(Qt::AlignRight);
_statsGrid->item(CUR_DEBIT, 1)->setTextAlignment(Qt::AlignRight);
_statsGrid->item(TOTAL_CREDIT, 1)->setTextAlignment(Qt::AlignRight);
_statsGrid->item(TOTAL_DEBIT, 1)->setTextAlignment(Qt::AlignRight);
_statsGrid->item(BALANCE, 1)->setTextAlignment(Qt::AlignRight);
_statsGrid->item(NON_FIX, 1)->setTextAlignment(Qt::AlignRight);
_accountsGrid->resizeColumnToContents(0);
}
void AccountPanel::ChangeUser()
@ -321,52 +365,52 @@ void AccountPanel::ShowMonth(int month, int year)
{
// std::vector<Operation> operations;
// _fixCosts = 0;
// User* user = _kiss->GetUser();
User* user = _kiss->GetUser();
// DEFAULT_FONT(font);
// std::vector<Category>::iterator categoryIt;
// std::map<unsigned int, std::vector<Operation> >::iterator monthIt;
std::map<unsigned int, std::vector<Operation> >::iterator monthIt;
QDate curDate = QDate::currentDate();
QDate dateStart = QDate::currentDate();
QDate dateEnd = QDate::currentDate();
// if (month == -1)
// {
// // Near month
// if (year == curDate.GetYear())
// {
// for (monthIt = user->_operations[year]->begin(); monthIt != user->_operations[year]->end(); monthIt++)
// {
// if ((int)monthIt->first <= curDate.GetMonth())
// {
// month = monthIt->first;
// }
// }
// }
if (month == -1)
{
// Near month
if (year == curDate.year())
{
for (monthIt = user->_operations[year]->begin(); monthIt != user->_operations[year]->end(); monthIt++)
{
if ((int)monthIt->first <= curDate.month())
{
month = monthIt->first;
}
}
}
// // First month
// if (month == -1)
// {
// monthIt = user->_operations[year]->begin();
// if (user->_operations[year]->size() == 0 && year == curDate.GetYear())
// month = curDate.GetMonth();
// else
// month = monthIt->first;
// }
// }
// First month
if (month == -1)
{
monthIt = user->_operations[year]->begin();
if (user->_operations[year]->size() == 0 && year == curDate.year())
month = curDate.month();
else
month = monthIt->first;
}
}
// _curYear = year;
// _curMonth = month;
// _wxUI->SetTitle(user->_name + wxT(" - ") + wxUI::months[month] + wxT(" ") + wxString::Format(wxT("%d"), year));
_curYear = year;
_curMonth = month;
_wxUI->setWindowTitle(user->_name + " - " + wxUI::months[month-1] + " " + QString::number(year));
// if (_grid->GetNumberRows() > 1)
// _grid->DeleteRows(1, _grid->GetNumberRows()-1);
// // Operations are ordered
// _curOperations = &((*user->_operations[year])[month]);
// Operations are ordered
_curOperations = &((*user->_operations[year])[month]);
// _grid->LoadOperations(_curOperations, _curMonth, _curYear);
// InitAccountsGrid(user, month, year);
InitAccountsGrid(user, month, year);
dateStart.setDate(dateStart.year(), dateStart.month(), 1);
dateEnd.setDate(dateEnd.year(), dateEnd.month(), dateStart.daysInMonth());
@ -377,311 +421,322 @@ void AccountPanel::ShowMonth(int month, int year)
_calendar->setSelectedDate (dateEnd) ;
else if ((curDate.month()-1) < month || curDate.year() < year)
_calendar->setSelectedDate(dateStart) ;
// _calendar->EnableMonthChange(false);
// _calendar->EnableYearChange(false);
// _calendar->SetSize(_calendar->GetMinSize());
// UpdateStats();
UpdateStats();
// Fit();
// // SetMinSize(GetSize());
layout();
}
void AccountPanel::InitAccountsGrid(User* user, int month, int year)
{
// std::vector<Account>::iterator it;
// int curLine = 0;
// double value;
// int i, a;
// DEFAULT_FONT(font);
std::vector<Account>::iterator it;
int curLine = 0;
double value;
int i, a;
QTableWidgetItem* item;
QString v;
QFont font;
// if (_accountsGrid->GetNumberRows())
// _accountsGrid->DeleteRows(0, _accountsGrid->GetNumberRows());
if (_accountsGrid->rowCount())
_accountsGrid->clear();
// font.SetWeight(wxFONTWEIGHT_BOLD);
_accountsGrid->setRowCount(user->_accounts.size());
// for (i=0, it = user->_accounts.begin(); it != user->_accounts.end(); i++, it++, curLine++)
// {
// _accountsGrid->AppendRows();
for (i=0, it = user->_accounts.begin(); it != user->_accounts.end(); i++, it++, curLine++)
{
if (it->shared)
_accountsGrid->setItem(curLine, ACCOUNT_NUMBER, new QTableWidgetItem(it->number + "*"));
else
_accountsGrid->setItem(curLine, ACCOUNT_NUMBER, new QTableWidgetItem(it->number));
// if (it->shared)
// _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number + wxT("*"));
// else
// _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number);
_accountsGrid->setItem(curLine, ACCOUNT_NAME, new QTableWidgetItem(it->name));
value = _kiss->GetAccountAmount(it->id, month, year);
// _accountsGrid->SetCellEditor(curLine, ACCOUNT_INIT, new wxGridCellFloatEditor(-1, 2));
// _accountsGrid->setItem(curLine, ACCOUNT_INIT, wxString::Format(wxT("%.2lf"), value));
_accountsGrid->setItem(curLine, ACCOUNT_INIT, new QTableWidgetItem(v.sprintf("%.2lf", value)));
_accountsGrid->setItem(curLine, ACCOUNT_CUR, new QTableWidgetItem(""));
_accountsGrid->setItem(curLine, ACCOUNT_FINAL, new QTableWidgetItem(""));
for (a=0; a<NUMBER_COLS_ACCOUNTS; a++)
{
item = _accountsGrid->item(curLine, a);
if (a != ACCOUNT_INIT)
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
if (a == ACCOUNT_CUR)
{
font = item->font();
font.setBold(true);
item->setFont(font);
}
}
_accountsInitValues[it->id] = value;
_accountsGrid->item(curLine, ACCOUNT_INIT)->setTextAlignment(Qt::AlignRight);
_accountsGrid->item(curLine, ACCOUNT_CUR)->setTextAlignment(Qt::AlignRight);
_accountsGrid->item(curLine, ACCOUNT_FINAL)->setTextAlignment(Qt::AlignRight);
}
// _accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name);
// value = _kiss->GetAccountAmount(it->id, month, year);
// _accountsGrid->SetCellEditor(curLine, ACCOUNT_INIT, new wxGridCellFloatEditor(-1, 2));
// _accountsGrid->SetCellValue(curLine, ACCOUNT_INIT, wxString::Format(wxT("%.2lf"), value));
// for (a=0; a<NUMBER_COLS_ACCOUNTS; a++)
// _accountsGrid->SetReadOnly(curLine, a, a != ACCOUNT_INIT);
// _accountsGrid->SetCellFont(curLine, ACCOUNT_CUR, font);
// _accountsInitValues[it->id] = value;
// _accountsGrid->SetCellAlignment(curLine, ACCOUNT_INIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
// _accountsGrid->SetCellAlignment(curLine, ACCOUNT_CUR, wxALIGN_RIGHT, wxALIGN_CENTRE);
// _accountsGrid->SetCellAlignment(curLine, ACCOUNT_FINAL, wxALIGN_RIGHT, wxALIGN_CENTRE);
// }
// _accountsGrid->AutoSizeColumns(true);
_accountsGrid->resizeColumnsToContents();
}
void AccountPanel::UpdateStats()
{
// int i;
// User* user = _kiss->GetUser();
// std::vector<Operation>::iterator it;
// double curCredit, curDebit, totalCredit, totalDebit, balance, value, value2, percents;
// std::map<wxString, double> curAccountAmount, finalAccountAmount;
// std::map<wxString, double>::iterator doubleIt;
// std::map<wxString, int>::iterator intIt;
// std::vector<Account>::iterator accountIt;
// unsigned int day;
// int mode;
// std::map<wxString, double>* notChecked = 0;
// std::map<wxString, double>* virtuals = 0;
// Account account;
// Operation op;
// bool blocked_account ;
int i;
User* user = _kiss->GetUser();
std::vector<Operation>::iterator it;
double curCredit, curDebit, totalCredit, totalDebit, balance, value, value2, percents;
std::map<int, double> curAccountAmount, finalAccountAmount;
std::map<int, double>::iterator doubleIt;
std::map<int, int>::iterator intIt;
std::vector<Account>::iterator accountIt;
unsigned int day;
int mode;
std::map<int, double>* notChecked = 0;
std::map<int, double>* virtuals = 0;
Account account;
Operation op;
bool blocked_account ;
QString v;
// mode = _radioMode->GetSelection();
if (_virtual->isChecked()) mode = VIRTUAL_MODE;
else if (_real->isChecked()) mode = REAL_MODE;
else if (_check->isChecked()) mode = CHECK_MODE;
// curCredit = curDebit = totalCredit = totalDebit = percents = 0.0;
curCredit = curDebit = totalCredit = totalDebit = percents = 0.0;
// if (mode == CHECK_MODE)
// notChecked = _kiss->GetNotChecked(_curMonth, _curYear);
if (mode == CHECK_MODE)
notChecked = _kiss->GetNotChecked(_curMonth, _curYear);
// if (mode == REAL_MODE || mode == CHECK_MODE)
// virtuals = _kiss->GetVirtualAmount(_curMonth, _curYear);
if (mode == REAL_MODE || mode == CHECK_MODE)
virtuals = _kiss->GetVirtualAmount(_curMonth, _curYear);
// day = _calendar->GetDate().GetDay()-1;
day = _calendar->selectedDate().day()-1;
// for (i=0; i<user->GetCategoriesNumber(); i++)
// _categoriesValues[i] = 0.0;
for (i=0; i<user->GetCategoriesNumber(); i++)
_categoriesValues[i] = 0.0;
// for (doubleIt=_accountsInitValues.begin(); doubleIt!=_accountsInitValues.end(); doubleIt++)
// {
// curAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first];
// finalAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first];
for (doubleIt=_accountsInitValues.begin(); doubleIt!=_accountsInitValues.end(); doubleIt++)
{
curAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first];
finalAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first];
// if (mode == REAL_MODE || mode == CHECK_MODE)
// {
// curAccountAmount[doubleIt->first] += -(*virtuals)[doubleIt->first];
// finalAccountAmount[doubleIt->first] += -(*virtuals)[doubleIt->first];
// }
// }
if (mode == REAL_MODE || mode == CHECK_MODE)
{
curAccountAmount[doubleIt->first] += -(*virtuals)[doubleIt->first];
finalAccountAmount[doubleIt->first] += -(*virtuals)[doubleIt->first];
}
}
// for (it=_curOperations->begin(); it!=_curOperations->end(); it++)
// {
// if (it->meta) continue;
for (it=_curOperations->begin(); it!=_curOperations->end(); it++)
{
if (it->meta) continue;
// op = *it;
// blocked_account = false;
op = *it;
blocked_account = false;
// // A credit on a blocked account must be considered as a debit
// if (op.transfert.Length() && op.amount > 0)
// {
// account = user->GetAccount(op.account);
// A credit on a blocked account must be considered as a debit
if (op.transfert && op.amount > 0)
{
account = user->GetAccount(op.account);
// if (account.blocked)
// {
// op.amount = -op.amount;
// op.transfert = wxT("");
// blocked_account = true;
// }
// }
if (account.blocked)
{
op.amount = -op.amount;
op.transfert = 0;
blocked_account = true;
}
}
// switch(mode)
// {
// case VIRTUAL_MODE:
// if (op.amount >= 0)
// {
// if (!op.transfert.Length())
// 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.Length())
// curCredit += op.amount;
// curAccountAmount[op.account] += op.amount;
// }
// finalAccountAmount[op.account] += op.amount;
// }
// else
// {
// if (!op.transfert.Length() && 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.Length())
// totalDebit += -op.amount;
if (!op.transfert)
totalDebit += -op.amount;
// if (blocked_account)
// op.amount = -op.amount;
if (blocked_account)
op.amount = -op.amount;
// if (day >= op.day)
// {
// if (!op.transfert.Length())
// curDebit += -op.amount;
// curAccountAmount[op.account] += op.amount;
// }
// finalAccountAmount[op.account] += op.amount;
// }
// break;
// case REAL_MODE:
// if (op.amount >= 0)
// {
// if (!op.transfert.Length())
// totalCredit += 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.Length())
// curCredit += op.amount;
// if (!op._virtual)
// curAccountAmount[op.account] += op.amount;
// }
// if (!op._virtual)
// finalAccountAmount[op.account] += op.amount;
// }
// else
// {
// if (!op.transfert.Length() && user->GetCategoryName(op.category) != _("Unknown"))
// _categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -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.Length() && !op._virtual)
// totalDebit += -op.amount;
if (!op.transfert && !op._virtual)
totalDebit += -op.amount;
// if (blocked_account)
// op.amount = -op.amount;
if (blocked_account)
op.amount = -op.amount;
// if (day >= op.day)
// {
// if (!op.transfert.Length() && !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.Length() && !op._virtual)
// totalCredit += 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.Length() && !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.Length() && user->GetCategoryName(op.category) != _("Unknown"))
// _categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -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.Length() && !op._virtual)
// totalDebit += -op.amount;
if (!op.transfert && !op._virtual)
totalDebit += -op.amount;
// if (blocked_account)
// op.amount = -op.amount;
if (blocked_account)
op.amount = -op.amount;
// if (day >= op.day)
// {
// if (!op.transfert.Length() && !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)
{
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;
}
}
// balance = totalCredit - totalDebit;
// _statsGrid->SetCellValue(CUR_CREDIT, 1, wxString::Format(wxT("%.2lf"), curCredit));
// _statsGrid->SetCellValue(CUR_DEBIT, 1, wxString::Format(wxT("%.2lf"), curDebit));
// _statsGrid->SetCellValue(TOTAL_CREDIT, 1, wxString::Format(wxT("%.2lf"), totalCredit));
// _statsGrid->SetCellValue(TOTAL_DEBIT, 1, wxString::Format(wxT("%.2lf"), totalDebit));
balance = totalCredit - totalDebit;
_statsGrid->item(CUR_CREDIT, 1)->setText(v.sprintf("%.2lf", curCredit));
_statsGrid->item(CUR_DEBIT, 1)->setText(v.sprintf("%.2lf", curDebit));
_statsGrid->item(TOTAL_CREDIT, 1)->setText(v.sprintf("%.2lf", totalCredit));
_statsGrid->item(TOTAL_DEBIT, 1)->setText(v.sprintf("%.2lf", totalDebit));
// _statsGrid->SetCellTextColour(BALANCE, 1, (balance >= 0) ? wxColor(0x00, 0xFF, 0x00) : wxColor(0xFF, 0x00, 0x00));
// _statsGrid->SetCellValue(BALANCE, 1, wxString::Format(wxT("%.2lf"), balance));
_statsGrid->item(BALANCE, 1)->setText(v.sprintf("%.2lf", balance));
// for(i=0; i<user->GetCategoriesNumber()+1; i++)
// {
// if (totalDebit != 0)
// percents = ((double) (_categoriesValues[i]*100))/totalDebit;
// else
// percents = 0.0;
// if (i)
// _statsGrid->SetCellValue(CATS_STATS+i+1, 1, wxString::Format(wxT("%.2lf (%02d %%)"), _categoriesValues[i], (int)percents));
// else
// _statsGrid->SetCellValue(CATS_STATS+i, 1, wxString::Format(wxT("%.2lf (%02d %%)"), _categoriesValues[i], (int)percents));
// }
for(i=0; i<user->GetCategoriesNumber(); i++)
{
if (totalDebit != 0)
percents = ((double) (_categoriesValues[i]*100))/totalDebit;
else
percents = 0.0;
if (i)
_statsGrid->item(CATS_STATS+i+1, 1)->setText(v.sprintf("%.2lf (%02d %%)", _categoriesValues[i], (int)percents));
else
_statsGrid->item(CATS_STATS+i, 1)->setText(v.sprintf("%.2lf (%02d %%)", _categoriesValues[i], (int)percents));
}
// value = totalDebit - _categoriesValues[0];
// if (totalDebit != 0)
// percents = ((double) (value*100))/totalDebit;
// else
// percents = 0.0;
// _statsGrid->SetCellValue(NON_FIX, 1, wxString::Format(wxT("%.2lf (%02d %%)"), value, (int)percents));
value = totalDebit - _categoriesValues[0];
if (totalDebit != 0)
percents = ((double) (value*100))/totalDebit;
else
percents = 0.0;
_statsGrid->item(NON_FIX, 1)->setText(v.sprintf("%.2lf (%02d %%)", value, (int)percents));
// for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++)
// {
// if (mode != CHECK_MODE)
// {
// value = _accountsInitValues[accountIt->id];
// if (mode == REAL_MODE)
// value -= (*virtuals)[accountIt->id];
// _accountsGrid->SetCellValue(i, ACCOUNT_INIT, wxString::Format(wxT("%.2lf"), value));
// value = curAccountAmount[accountIt->id];
// _accountsGrid->SetCellValue(i, ACCOUNT_CUR, wxString::Format(wxT("%.2lf"), value));
// _accountsGrid->SetCellTextColour(i, ACCOUNT_CUR, (value >= 0.0) ? wxColor(0x00, 0x00, 0x00) : wxColor(0xFF, 0x00, 0x00));
// value = finalAccountAmount[accountIt->id];
// _accountsGrid->SetCellValue(i, ACCOUNT_FINAL, wxString::Format(wxT("%.2lf"), value));
// }
// else
// {
// value = _accountsInitValues[accountIt->id] - (*virtuals)[accountIt->id];
// value2 = (*notChecked)[accountIt->id];
for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++)
{
if (mode != CHECK_MODE)
{
value = _accountsInitValues[accountIt->id];
if (mode == REAL_MODE)
value -= (*virtuals)[accountIt->id];
_accountsGrid->item(i, ACCOUNT_INIT)->setText(v.sprintf("%.2lf", value));
value = curAccountAmount[accountIt->id];
_accountsGrid->item(i, ACCOUNT_CUR)->setText(v.sprintf("%.2lf", value));
// _accountsGrid->SetCellTextColour(i, ACCOUNT_CUR, (value >= 0.0) ? wxColor(0x00, 0x00, 0x00) : wxColor(0xFF, 0x00, 0x00));
value = finalAccountAmount[accountIt->id];
_accountsGrid->item(i, ACCOUNT_FINAL)->setText(v.sprintf("%.2lf", value));
}
else
{
value = _accountsInitValues[accountIt->id] - (*virtuals)[accountIt->id];
value2 = (*notChecked)[accountIt->id];
// _accountsGrid->SetCellValue(i, ACCOUNT_INIT, wxString::Format(wxT("%.2lf (%.2lf)"), value, value-value2));
// value = curAccountAmount[accountIt->id];
// _accountsGrid->SetCellValue(i, ACCOUNT_CUR, wxString::Format(wxT("%.2lf (%.2lf)"), value, value-value2));
// _accountsGrid->SetCellTextColour(i, ACCOUNT_CUR, (value >= 0.0) ? wxColor(0x00, 0x00, 0x00) : wxColor(0xFF, 0x00, 0x00));
// value = finalAccountAmount[accountIt->id];
// _accountsGrid->SetCellValue(i, ACCOUNT_FINAL, wxString::Format(wxT("%.2lf (%.2lf)"), value, value-value2));
// }
// }
_accountsGrid->item(i, ACCOUNT_INIT)->setText(v.sprintf("%.2lf (%.2lf)", value, value-value2));
value = curAccountAmount[accountIt->id];
_accountsGrid->item(i, ACCOUNT_CUR)->setText(v.sprintf("%.2lf (%.2lf)", value, value-value2));
// _accountsGrid->SetCellTextColour(i, ACCOUNT_CUR, (value >= 0.0) ? wxColor(0x00, 0x00, 0x00) : wxColor(0xFF, 0x00, 0x00));
value = finalAccountAmount[accountIt->id];
_accountsGrid->item(i, ACCOUNT_FINAL)->setText(v.sprintf("%.2lf (%.2lf)", value, value-value2));
}
}
// _accountsGrid->AutoSizeColumn(ACCOUNT_INIT, true);
// _accountsGrid->AutoSizeColumn(ACCOUNT_CUR, true);
// _accountsGrid->AutoSizeColumn(ACCOUNT_FINAL, true);
_accountsGrid->resizeColumnToContents(ACCOUNT_INIT);
_accountsGrid->resizeColumnToContents(ACCOUNT_CUR);
_accountsGrid->resizeColumnToContents(ACCOUNT_FINAL);
// if (notChecked) delete notChecked;
// if (virtuals) delete virtuals;
// _statsGrid->AutoSizeColumn(1, true);
if (notChecked) delete notChecked;
if (virtuals) delete virtuals;
_statsGrid->resizeColumnToContents(1);
// _pie->DatasetChanged(_dataset);
// Layout();
layout();
}
void AccountPanel::OnOperationModified()
{
// UpdateStats();
UpdateStats();
// Fit();
layout();
}
void AccountPanel::OnAccountModified()

View File

@ -29,6 +29,8 @@
#include <QTreeWidget>
#include <QCalendarWidget>
#include <QTableWidget>
#include <QRadioButton>
#include "view.hpp"
@ -75,16 +77,17 @@ private:
QTreeWidget *_tree;
QCalendarWidget* _calendar;
// GridAccount* _grid;
// wxGrid *_statsGrid, *_accountsGrid;
QTableWidget* _accountsGrid, *_statsGrid;
// PiePlot* _pie;
double *_categoriesValues;
// wxRadioBox *_radioMode;
std::map<QString, int> _categoriesIndexes;
std::vector<Operation>* _curOperations;
QString* _categories, *_accounts;
std::map<QString, double> _accountsInitValues;
std::map<int, double> _accountsInitValues;
// CategorySimpleDataset* _dataset;
int _fixCosts;
QRadioButton *_virtual, *_real, *_check;
void InitStatsGrid(User* user);
void InitAccountsGrid(User* user, int month, int year);