Fix some typo bugs in Database query

Add Group/UnGroup/UpdateNextMonths buttons
Display correct title in AccountPannel
This commit is contained in:
2011-10-22 11:37:35 +02:00
parent c5cec6c9d6
commit 34112f7762
5 changed files with 313 additions and 352 deletions

View File

@@ -22,6 +22,7 @@
#include <QHeaderView>
#include <QGroupBox>
#include <QMessageBox>
#include "AccountPanel.hpp"
#include "grid/FloatDelegate.hpp"
@@ -151,14 +152,19 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
// _tree.SetIndent(5);
// wxButton* buttonGroup = new wxButton(this, GROUP_ID, _("Group"));
// wxButton* buttonUnGroup = new wxButton(this, UNGROUP_ID, _("UnGroup"));
// wxButton* buttonUpdateNextMonths = new wxButton(this, UPDATE_NEXT_MONTHS_ID, _("Update next months"));
QPushButton* buttonGroup = new QPushButton(_("Group"));
QPushButton* buttonUnGroup = new QPushButton(_("UnGroup"));
QPushButton* buttonUpdateNextMonths = new QPushButton(_("Update next months"));
connect(buttonGroup, SIGNAL(clicked()), this, SLOT(OnGroup()));
connect(buttonUnGroup, SIGNAL(clicked()), this, SLOT(OnUnGroup()));
connect(buttonUpdateNextMonths, SIGNAL(clicked()), this, SLOT(OnUpdateNextMonths()));
vbox3->addWidget(_tree);
// 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->addWidget(buttonUpdateNextMonths);
vbox3->addStretch(1);
vbox3->addWidget(buttonGroup);
vbox3->addWidget(buttonUnGroup);
vbox3->addStretch(1);
vbox3->addWidget(groupBox);
@@ -1026,10 +1032,12 @@ void AccountPanel::GenerateMonth(int month, int year)
void AccountPanel::OnShow()
{
// if (_curMonth != -1)
// _wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") + wxUI::months[_curMonth] + wxT(" ") + wxString::Format(wxT("%d"), _curYear));
// else
// _wxUI->SetTitle(_kiss->GetUser()->_name);
User* user = _kiss->GetUser();
if (_curMonth != -1)
_wxUI->setWindowTitle(user->_name + " - " + wxUI::months[_curMonth] + " " + QString::number(_curYear));
else
_wxUI->setWindowTitle(user->_name);
}
void AccountPanel::OnCalendarChange()
@@ -1044,117 +1052,117 @@ void AccountPanel::OnModeChange()
void AccountPanel::OnGroup()
{
// _grid->Group();
if (_grid)
_grid->Group();
}
void AccountPanel::OnUnGroup()
{
// _grid->UnGroup();
if (_grid)
_grid->UnGroup();
}
void AccountPanel::OnUpdateNextMonths()
{
// double* deltas, *cur_amounts, amount;
// int i, a;
// User* user = _kiss->GetUser();
// bool had_values, accounts_updated = false;
// int last_month = 0, last_year = 0, account_updated = 0;
// std::map<int, std::vector<int> > operations;
double* deltas, *cur_amounts, amount;
int i, a;
User* user = _kiss->GetUser();
bool had_values, accounts_updated = false;
int last_month = 0, last_year = 0, account_updated = 0;
std::map<int, std::vector<int> > operations;
// deltas = new double[user->_accounts.size()] ;
// cur_amounts = new double[user->_accounts.size()] ;
deltas = new double[user->_accounts.size()] ;
cur_amounts = new double[user->_accounts.size()] ;
// operations = _kiss->GetAllOperations();
operations = _kiss->GetAllOperations();
// if (_curMonth == 11)
// {
// last_month = 0;
// last_year = _curYear+1;
// }
// else
// {
// last_month = _curMonth+1;
// last_year = _curYear;
// }
if (_curMonth == 11)
{
last_month = 0;
last_year = _curYear+1;
}
else
{
last_month = _curMonth+1;
last_year = _curYear;
}
// for (i=0; i<(int)user->_accounts.size(); i++)
// {
// deltas[i] = _kiss->GetAccountAmount(user->_accounts[i].id, _curMonth, _curYear);
// cur_amounts[i] = deltas[i] += _kiss->CalcAccountAmount(user->_accounts[i].id, _curMonth, _curYear, &had_values);
for (i=0; i<(int)user->_accounts.size(); i++)
{
deltas[i] = _kiss->GetAccountAmount(user->_accounts[i].id, _curMonth, _curYear);
cur_amounts[i] = deltas[i] += _kiss->CalcAccountAmount(user->_accounts[i].id, _curMonth, _curYear, &had_values);
// for (a=0; a<(int)operations[last_year].size(); a++)
// if (operations[last_year][a] == last_month) break;
for (a=0; a<(int)operations[last_year].size(); a++)
if (operations[last_year][a] == last_month) break;
// if (a == (int)operations[last_year].size())
// {
// deltas[i] = 0;
// continue;
// }
if (a == (int)operations[last_year].size())
{
deltas[i] = 0;
continue;
}
// amount = _kiss->GetAccountAmount(user->_accounts[i].id, last_month, last_year);
amount = _kiss->GetAccountAmount(user->_accounts[i].id, last_month, last_year);
// deltas[i] -= amount;
deltas[i] -= amount;
// account_updated++;
// }
account_updated++;
}
// if (!account_updated)
// goto end;
if (!account_updated)
goto end;
// last_month = _curMonth;
// last_year = _curYear;
last_month = _curMonth;
last_year = _curYear;
// while (1)
// {
// account_updated = 0;
while (1)
{
account_updated = 0;
// if (last_month == 11)
// {
// last_month = 0;
// last_year = last_year+1;
// }
// else
// last_month++;
if (last_month == 11)
{
last_month = 0;
last_year = last_year+1;
}
else
last_month++;
// for (i=0; i<(int)user->_accounts.size(); i++)
// {
// if (deltas[i] == 0.0) continue;
for (i=0; i<(int)user->_accounts.size(); i++)
{
if (deltas[i] == 0.0) continue;
// amount = _kiss->GetAccountAmount(user->_accounts[i].id, last_month, last_year);
// if ((cur_amounts[i] - amount) != deltas[i]) continue;
amount = _kiss->GetAccountAmount(user->_accounts[i].id, last_month, last_year);
if ((cur_amounts[i] - amount) != deltas[i]) continue;
// cur_amounts[i] = amount + deltas[i];
// _kiss->SetAccountAmount(user->_accounts[i].id, last_month, last_year, cur_amounts[i]);
// cur_amounts[i] += _kiss->CalcAccountAmount(user->_accounts[i].id, last_month, last_year, &had_values);
cur_amounts[i] = amount + deltas[i];
_kiss->SetAccountAmount(user->_accounts[i].id, last_month, last_year, cur_amounts[i]);
cur_amounts[i] += _kiss->CalcAccountAmount(user->_accounts[i].id, last_month, last_year, &had_values);
// account_updated++;
// }
account_updated++;
}
// if (!account_updated) break;
if (!account_updated) break;
// accounts_updated = true;
// }
accounts_updated = true;
}
// if (last_month == 0)
// {
// last_month = 11;
// last_year--;
// }
// else
// last_month--;
if (last_month == 0)
{
last_month = 11;
last_year--;
}
else
last_month--;
// end:
// if (accounts_updated)
// {
// wxString message = _("Accounts updated until ") + wxUI::months[last_month];
end:
if (accounts_updated)
{
QString message = _("Accounts updated until ") + wxUI::months[last_month] + " " + QString::number(last_year);
// message += wxT(" ") + wxString::Format(wxT("%d"), last_year);
QMessageBox::information(0, "KissCount", message);
}
else
QMessageBox::information(0, "KissCount", _("Any account updated !"));
// wxMessageBox(message, wxT("KissCount"), wxICON_INFORMATION | wxOK);
// }
// else
// wxMessageBox(_("Any account updated !"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
// delete[] deltas;
// delete[] cur_amounts;
delete[] deltas;
delete[] cur_amounts;
}

View File

@@ -227,10 +227,6 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, int month,
DateDelegate* dateEditor = new DateDelegate(this, month+1, year);
setItemDelegateForColumn(OP_DATE, dateEditor);
// FloatDelegate* floatEditor = new FloatDelegate(this);
// setItemDelegateForColumn(DEBIT, floatEditor);
// setItemDelegateForColumn(CREDIT, floatEditor);
FormulaDelegate* formulaEditor = new FormulaDelegate(this, &_displayedOperations);
setItemDelegateForColumn(DEBIT, formulaEditor);
setItemDelegateForColumn(CREDIT, formulaEditor);
@@ -284,7 +280,7 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, int month,
void GridAccount::ComputeWeeks()
{
std::vector<Operation>::iterator it;
int curLine, curWeek, week, i;
int curLine;//, curWeek, week, i;
if (!_canAddOperation) return;
@@ -326,7 +322,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
{
std::vector<Operation>::iterator it;
std::vector<QString>::iterator it2;
int r, g, b, i;
int r, g, b;
double amount;
QColor color;
QDate curDate = QDate::currentDate();
@@ -1211,301 +1207,255 @@ void GridAccount::UpdateMeta(Operation& meta)
UpdateOperation(meta);
}
void GridAccount::GetSelectedOperations(std::vector<int>* rows)
{
// std::vector<int>::iterator it;
// rows->clear();
// // Blocks. We always expect btl and bbr to have the same size, since their
// // entries are supposed to correspond.
// const wxGridCellCoordsArray& btl(GetSelectionBlockTopLeft());
// const wxGridCellCoordsArray& bbr(GetSelectionBlockBottomRight());
// size_t blockCount = btl.size();
// if (blockCount == bbr.size())
// {
// for (size_t i = 0; i < blockCount; ++i)
// {
// const wxGridCellCoords& tl = btl[i];
// const wxGridCellCoords& br = bbr[i];
// for (int row = tl.GetRow(); row <= br.GetRow(); ++row)
// {
// it = std::find(rows->begin(), rows->end(), row);
// if (it != rows->end() || !row) continue;
// rows->push_back(row);
// }
// }
// }
// // Singly selected cells.
// const wxGridCellCoordsArray& cells(GetSelectedCells());
// for (size_t i = 0; i < cells.size(); ++i)
// {
// int row = cells[i].GetRow();
// if (!row) continue;
// it = std::find(rows->begin(), rows->end(), row);
// if (it != rows->end()) continue;
// rows->push_back(row);
// }
}
void GridAccount::Group()
{
// std::vector<int> selected, rows;
// std::vector<int>::iterator it;
// std::vector<Operation> ops;
// std::vector<Operation>::iterator it2;
// std::vector<wxString>::iterator it3;
// wxString parent = "";
// Operation op, op2;
// int fix = -1, i, a, row;
std::vector<int> rows;
std::vector<int>::iterator it;
std::vector<Operation> ops;
std::vector<Operation>::iterator it2;
std::vector<int>::iterator it3;
int parent = 0;
Operation op, op2;
int fix = -1, i, a, row;
// GetSelectedOperations(&selected);
QModelIndexList selected = selectedIndexes();
// for (size_t i = 0; i < selected.size(); ++i)
// {
// op = _displayedOperations[selected[i]] ;
for (int i = 0; i < selected.size(); ++i)
{
op = _displayedOperations[selected[i].row()] ;
// if (op.id)
// {
// if (!parent)
// {
// if (op.parent)
// {
// parent = op.parent;
// continue;
// }
// else if(op.meta)
// parent = op.id;
// }
// else
// {
// if ((parent && op.parent && op.parent != parent))
// {
// wxMessageBox(_("Cannot group these operations"), _("Error"), wxICON_ERROR | wxOK);
// return ;
// }
// }
if (op.id)
{
if (!parent)
{
if (op.parent)
{
parent = op.parent;
continue;
}
else if(op.meta)
parent = op.id;
}
else
{
if ((parent && op.parent && op.parent != parent))
{
QMessageBox::critical(0, _("Error"), _("Cannot group these operations"));
return ;
}
}
// if (fix != -1 && ((!fix && op.fix_cost) || (fix && !op.fix_cost)))
// {
// wxMessageBox(_("Cannot group these operations"), _("Error"), wxICON_ERROR | wxOK);
// return ;
// }
if (fix != -1 && ((!fix && op.fix_cost) || (fix && !op.fix_cost)))
{
QMessageBox::critical(0, _("Error"), _("Cannot group these operations"));
return ;
}
// if (fix == -1)
// fix = op.fix_cost ? 1 : 0;
if (fix == -1)
fix = op.fix_cost ? 1 : 0;
// ops.push_back(op);
// rows.push_back(selected[i]);
// }
// }
ops.push_back(op);
rows.push_back(selected[i].row());
}
}
// if (!ops.size()) return;
if (!ops.size()) return;
// if (!parent)
// {
// if (rows.size() < 2) return;
if (!parent)
{
if (rows.size() < 2) return;
// op.parent = "";
// op.day = ops[0].day;
// op.month = ops[0].month;
// op.year = ops[0].year;
// op.amount = 0;
// op.description = "";
// op.category = "";
// op.fix_cost = fix;
// op.account = "";
// op.checked = false;
// op.transfert = "";
// op.formula = "";
// op.meta = true;
// op.childs.clear();
op.parent = 0;
op.day = ops[0].day;
op.month = ops[0].month;
op.year = ops[0].year;
op.amount = 0;
op.description = "";
op.category = 0;
op.fix_cost = fix;
op.account = 0;
op.checked = false;
op.transfert = 0;
op.formula = "";
op.meta = true;
op.childs.clear();
// op.id = _kiss->AddOperation(op);
// }
// else
// {
// if (rows.size() < 1) return;
op.id = _kiss->AddOperation(op);
}
else
{
if (rows.size() < 1) return;
// row = GetDisplayedRow(parent);
// op = _displayedOperations[row];
row = GetDisplayedRow(parent);
op = _displayedOperations[row];
// //if (op.id) return;
// }
//if (op.id) return;
}
// std::sort(rows.begin(), rows.end());
std::sort(rows.begin(), rows.end());
// for(i=0; i<(int)rows.size(); i++)
// {
// if (ops[i].meta)
// RemoveMeta(ops[i], rows[i], true, false);
// else
// {
// if (ops[i].fix_cost) _fixCosts--;
// DeleteRows(rows[i], 1);
// _displayedOperations.erase(_displayedOperations.begin()+rows[i]);
for(i=0; i<(int)rows.size(); i++)
{
if (ops[i].meta)
RemoveMeta(ops[i], rows[i], true, false);
else
{
if (ops[i].fix_cost) _fixCosts--;
removeRow(rows[i]);
_displayedOperations.erase(_displayedOperations.begin()+rows[i]);
// for(a=i+1; a<(int)rows.size(); a++)
// if (rows[a] >= rows[i])
// rows[a]--;
// }
// }
for(a=i+1; a<(int)rows.size(); a++)
if (rows[a] >= rows[i])
rows[a]--;
}
}
// for(it2=ops.begin(); it2!=ops.end(); it2++)
// {
// if (it2->id == parent) continue;
for(it2=ops.begin(); it2!=ops.end(); it2++)
{
if (it2->id == parent) continue;
// for (i=0, it3=op.childs.begin(); it3!=op.childs.end(); it3++, i++)
// {
// op2 = GetOperation(*it3);
// if (*it3 == it2->id ||
// op2.day > it2->day)
// break;
// }
for (i=0, it3=op.childs.begin(); it3!=op.childs.end(); it3++, i++)
{
op2 = GetOperation(*it3);
if (*it3 == it2->id ||
op2.day > it2->day)
break;
}
// if (i) i--;
if (i) i--;
// if (it3 == op.childs.end())
// op.childs.push_back(it2->id);
// else if (*it3 == it2->id)
// continue;
// else
// op.childs.insert(op.childs.begin()+i, it2->id);
if (it3 == op.childs.end())
op.childs.push_back(it2->id);
else if (*it3 == it2->id)
continue;
else
op.childs.insert(op.childs.begin()+i, it2->id);
// it2->parent = op.id;
// UpdateOperation(*it2);
// }
it2->parent = op.id;
UpdateOperation(*it2);
}
// UpdateMeta(op);
UpdateMeta(op);
// InsertIntoGrid(op);
InsertIntoGrid(op);
// UpdateOperation(op);
UpdateOperation(op);
}
void GridAccount::UnGroup()
{
// std::vector<int> rows, selected;
// std::vector<int>::iterator it;
// std::vector<Operation> ops;
// std::vector<wxString> ops2;
// std::vector<Operation>::iterator it2;
// std::vector<wxString>::iterator it3;
// wxString parent = "";
// Operation op, op2;
// int fix = -1, i, a, line;
std::vector<int> rows;
std::vector<int>::iterator it;
std::vector<Operation> ops;
std::vector<int> ops2;
std::vector<Operation>::iterator it2;
std::vector<int>::iterator it3;
int parent = 0;
Operation op, op2;
int fix = -1, i, a, line;
// GetSelectedOperations(&selected);
QModelIndexList selected = selectedIndexes();
// for (size_t i = 0; i < selected.size(); ++i)
// {
// op = _displayedOperations[selected[i]] ;
for (int i = 0; i < selected.size(); ++i)
{
op = _displayedOperations[selected[i].row()] ;
// if (op.id)
// {
// if ((parent && op.parent != parent)
// || (!op.parent && !op.meta))
// {
// wxMessageBox(_("Cannot ungroup these operations"), _("Error"), wxICON_ERROR | wxOK);
// return ;
// }
if (op.id)
{
if ((parent && op.parent != parent)
|| (!op.parent && !op.meta))
{
QMessageBox::critical(0, _("Error"), _("Cannot ungroup these operations"));
return ;
}
// if (fix != -1 && ((!fix && op.fix_cost) || (fix && !op.fix_cost)))
// {
// wxMessageBox(_("Cannot ungroup these operations"), _("Error"), wxICON_ERROR | wxOK);
// return ;
// }
if (fix != -1 && ((!fix && op.fix_cost) || (fix && !op.fix_cost)))
{
QMessageBox::critical(0, _("Error"), _("Cannot ungroup these operations"));
return ;
}
// if (fix == -1)
// fix = op.fix_cost ? 1 : 0;
if (fix == -1)
fix = op.fix_cost ? 1 : 0;
// if(op.meta)
// {
// parent = op.id;
// continue;
// }
if(op.meta)
{
parent = op.id;
continue;
}
// if (!parent && op.parent)
// parent = op.parent;
if (!parent && op.parent)
parent = op.parent;
// ops.push_back(op);
// rows.push_back(selected[i]);
// }
// }
ops.push_back(op);
rows.push_back(selected[i].row());
}
}
// if (!ops.size() && !parent) return;
if (!ops.size() && !parent) return;
// removeLastGroup:
// // Only one meta is selected
// if (!ops.size())
// {
// line = GetDisplayedRow(parent);
// op = _displayedOperations[line];
// ops2 = op.childs;
// RemoveMeta(op, line, true, false);
removeLastGroup:
// Only one meta is selected
if (!ops.size())
{
line = GetDisplayedRow(parent);
op = _displayedOperations[line];
ops2 = op.childs;
RemoveMeta(op, line, true, false);
// for(i=0; i<(int)ops2.size(); i++)
// {
// op2 = GetOperation(ops2[i]);
// op2.parent = "";
// UpdateOperation(op2);
// InsertIntoGrid(op2);
// }
for(i=0; i<(int)ops2.size(); i++)
{
op2 = GetOperation(ops2[i]);
op2.parent = 0;
UpdateOperation(op2);
InsertIntoGrid(op2);
}
// _kiss->DeleteOperation(op);
// DeleteOperation(op);
// }
// else
// {
// if (!parent) return;
_kiss->DeleteOperation(op);
DeleteOperation(op);
}
else
{
if (!parent) return;
// line = GetDisplayedRow(parent);
// op2 = _displayedOperations[line];
line = GetDisplayedRow(parent);
op2 = _displayedOperations[line];
// for(i=0; i<(int)ops.size(); i++)
// {
// op = ops[i];
// op.parent = 0;
// UpdateOperation(op);
// line = GetDisplayedRow(op.id);
// DeleteRows(line, 1);
// _displayedOperations.erase(_displayedOperations.begin()+line);
// InsertIntoGrid(GetOperation(op.id));
// if (op.fix_cost) _fixCosts--;
// for (a=0; a<(int)op2.childs.size(); a++)
// if (op2.childs[a] == op.id)
// {
// op2.childs.erase(op2.childs.begin()+a);
// break;
// }
// UpdateMeta(op2);
// UpdateOperation(op2);
// }
for(i=0; i<(int)ops.size(); i++)
{
op = ops[i];
op.parent = 0;
UpdateOperation(op);
line = GetDisplayedRow(op.id);
removeRow(line);
_displayedOperations.erase(_displayedOperations.begin()+line);
InsertIntoGrid(GetOperation(op.id));
if (op.fix_cost) _fixCosts--;
for (a=0; a<(int)op2.childs.size(); a++)
if (op2.childs[a] == op.id)
{
op2.childs.erase(op2.childs.begin()+a);
break;
}
UpdateMeta(op2);
UpdateOperation(op2);
}
// line = GetDisplayedRow(parent);
// _displayedOperations[line] = op2;
line = GetDisplayedRow(parent);
_displayedOperations[line] = op2;
// if (op2.childs.size() < 2)
// {
// ops.clear();
// // Sorry ...
// goto removeLastGroup;
// }
if (op2.childs.size() < 2)
{
ops.clear();
// Sorry ...
goto removeLastGroup;
}
// UpdateOperation(op2);
// }
UpdateOperation(op2);
}
// ComputeWeeks();
ComputeWeeks();
}
void GridAccount::MassUpdate(std::vector<int>& rows, updateOperationFunc func, void** params)

View File

@@ -63,8 +63,6 @@ public:
void InsertOperationWithWeek(User* user, Operation& op, int line, bool fix, int month, int year) ;
void InsertOperation(User* user, Operation& op, int line, bool fix, int month, int year) ;
void GetSelectedOperations(std::vector<int>* rows);
void MassUpdate(std::vector<int>& rows, updateOperationFunc func, void** params);
void Group();