Year/month changement ok

This commit is contained in:
Grégory Soutadé 2010-06-22 20:46:30 +02:00
parent e176e2f235
commit 391aef379b
4 changed files with 128 additions and 29 deletions

View File

@ -17,16 +17,19 @@ INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color
-- No password
INSERT INTO user ("id", "name", "password") VALUES ("0", "Greg", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
INSERT INTO account ("id", "user", "name", "number", "shared", "default_account") VALUES ("0", "0", "Compte Courant", "000" , "0", "1");
-- May 2009
INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("1", "0", "2009", "4", "500");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("1", "0", "0", "2009", "4", "0", "1234", "Opé May 1", "1", "1", "0");
-- May 2010
INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("1", "0", "2010", "4", "500");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("1", "0", "0", "2010", "4", "0", "1234", "Opé May 1", "1", "1", "0");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("2", "0", "0", "2010", "4", "1", "-56", "Opé May 2", "2", "0", "0");
INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("2", "0", "2010", "4", "500");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("2", "0", "0", "2010", "4", "0", "1234", "Opé May 1", "1", "1", "0");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("3", "0", "0", "2010", "4", "1", "-56", "Opé May 2", "2", "0", "0");
-- June 2010
INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("2", "0", "2010", "5", "1000");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("3", "0", "0", "2010", "5", "0", "1234", "Opé 1", "1", "1", "0");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("4", "0", "0", "2010", "5", "1", "-56", "Opé 2", "2", "0", "0");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("5", "0", "0", "2010", "5", "8", "12", "Opé 3", "3", "0", "1");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("6", "0", "0", "2010", "5", "29", "-2056", "Opé 4", "4", "0", "0");
INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("3", "0", "2010", "5", "1000");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("4", "0", "0", "2010", "5", "0", "1234", "Opé 1", "1", "1", "0");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("5", "0", "0", "2010", "5", "1", "-56", "Opé 2", "2", "0", "0");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("6", "0", "0", "2010", "5", "8", "12", "Opé 3", "3", "0", "1");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("7", "0", "0", "2010", "5", "29", "-2056", "Opé 4", "4", "0", "0");
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Fixe");
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Courses");
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Loisirs");

View File

@ -252,7 +252,9 @@ void Database::LoadYear(User* user, int year)
{
req += _("', '") + it->id ;
}
req += _("') ORDER BY fix_cost DESC, year,month,day ASC");
req += _("')");
req += _(" AND year='") + wxString::Format(_("%d"), year) + _("'");
req += _(" ORDER BY fix_cost DESC, year,month,day ASC");
EXECUTE_SQL_QUERY(req, set, );

View File

@ -15,7 +15,7 @@ EVT_TREE_SEL_CHANGED(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
EVT_TREE_KEY_DOWN(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
END_EVENT_TABLE()
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID)
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT)
{
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
@ -193,20 +193,31 @@ void AccountPanel::ChangeUser()
int curYear = -1;
std::map<unsigned int, std::map<unsigned int, std::vector<operation> >* >::iterator it;
wxDateTime curDate;
wxTreeItemId rootNode, curNode;
_tree.DeleteAllItems();
rootNode = _tree.AddRoot(_(""));
curDate.SetToCurrent();
for(it = user->_operations.begin(); it != user->_operations.end(); it++)
{
if ((int)it->first <= curDate.GetYear())
curYear = it->first;
_tree.AddRoot(wxString::Format(wxT("%d"), it->first));
{
curYear = it->first;
curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
}
else
_tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
}
if (curYear != -1)
LoadYear(curYear);
{
_tree.SelectItem(curNode, true);
LoadYear(curYear);
}
}
void AccountPanel::LoadYear(int year)
void AccountPanel::LoadYear(int year, bool showMonth)
{
User* user = _kiss->GetUser();
int curMonth = -1;
@ -214,13 +225,14 @@ void AccountPanel::LoadYear(int year)
wxDateTime curDate;
wxTreeItemId parentNode, curMonthNode;
_curYear = year ;
if (user->_operations[year] != NULL)
if (user->_operations[year])
{
ShowMonth(year, 0);
if (showMonth)
ShowMonth(year, -1);
return;
}
_curYear = year ;
_kiss->LoadYear(year);
curDate.SetToCurrent();
@ -228,24 +240,24 @@ void AccountPanel::LoadYear(int year)
for (it = user->_operations[year]->begin(); it != user->_operations[year]->end(); it++)
{
if (year == curDate.GetYear() && (int)it->first <= curDate.GetMonth())
if (curMonth == -1 || (year == curDate.GetYear() && (int)it->first <= curDate.GetMonth()))
{
curMonth = it->first;
curMonthNode = _tree.AppendItem(parentNode, months[it->first]);
}
else if(curMonth == -1)
{
curMonthNode = _tree.AppendItem(parentNode, months[it->first]);
curMonth++;
}
else
_tree.AppendItem(parentNode, months[it->first]);
}
_tree.Expand(parentNode);
_tree.SelectItem(curMonthNode, true);
ShowMonth(year, curMonth);
if (showMonth)
{
_tree.SelectItem(curMonthNode, true);
ShowMonth(year, curMonth);
}
_wxUI->Layout();
}
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS_OPS; i++) \
@ -262,8 +274,34 @@ void AccountPanel::ShowMonth(int year, int month)
User* user = _kiss->GetUser();
DEFAULT_FONT(font);
std::vector<category>::iterator categoryIt;
//wxGridCellChoiceEditor* categoryEditor, *accountEditor;
std::map<unsigned int, std::vector<operation> >::iterator monthIt;
wxDateTime curDate;
curDate.SetToCurrent();
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;
}
}
}
// First month
if (month == -1)
{
monthIt = user->_operations[year]->begin();
month = monthIt->first;
}
}
_curYear = year;
_curMonth = month;
_wxUI->SetTitle(user->_name + _(" - ") + months[month] + _(" ") + wxString::Format(wxT("%d"), year));
@ -275,7 +313,7 @@ void AccountPanel::ShowMonth(int year, int month)
it = _curOperations->begin();
for (;it->fix_cost && it != _curOperations->end(); it++)
for (;it != _curOperations->end() && it->fix_cost; it++)
InsertOperation(user, &(*it), ++curLine, true);
InsertOperation(user, NULL, ++curLine, true);
@ -742,9 +780,65 @@ void AccountPanel::OnAccountModified(wxGridEvent& event)
void AccountPanel::OnTreeRightClick(wxTreeEvent& event)
{
ShowMonth(2010,4);
// ShowMonth(2010,4);
}
void AccountPanel::OnTreeChange(wxTreeEvent& event)
{
int month=-1, year;
int i;
wxString monthString;
static bool inModification = false ;
if (inModification) return;
inModification = true;
monthString = _tree.GetItemText(event.GetItem());
for (i=0; i<12; i++)
if (monthString == months[i])
{
month = i;
break;
}
if (month == -1)
{
year = wxAtoi(monthString);
// Error
if (year == 0)
{
inModification = false;
return;
}
if (year == _curYear)
{
inModification = false;
return;
}
// _tree.CollapseAll();
// _tree.Expand(event.GetItem());
LoadYear(year, false);
}
else
{
year = wxAtoi(_tree.GetItemText(_tree.GetItemParent(event.GetItem())));
// Error
if (year == 0)
{
inModification = false;
return;
}
if (year != _curYear || month != _curMonth)
{
ShowMonth(year, month);
}
}
inModification = false;
}

View File

@ -34,7 +34,7 @@ public:
AccountPanel(KissCount* kiss, wxUI *parent);
~AccountPanel();
void ChangeUser();
void LoadYear(int year);
void LoadYear(int year, bool showMonth=true);
void ShowMonth(int year, int month);
void OnOperationModified(wxGridEvent& event);