wip
This commit is contained in:
parent
ea12a1b16c
commit
7d1f9ee120
|
@ -142,3 +142,27 @@ std::map<int, std::vector<int> > KissCount::GetAllOperations()
|
||||||
{
|
{
|
||||||
return _db->GetAllOperations(_user);
|
return _db->GetAllOperations(_user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo)
|
||||||
|
{
|
||||||
|
std::vector<operation>::iterator it;
|
||||||
|
operation op;
|
||||||
|
|
||||||
|
_db->GenerateMonth(_user, monthFrom, yearFrom, monthTo, yearTo);
|
||||||
|
if (monthFrom != -1 && yearFrom != -1)
|
||||||
|
{
|
||||||
|
LoadYear(yearFrom, false);
|
||||||
|
|
||||||
|
for(it = (*_user->_operations[yearFrom])[monthFrom].begin();
|
||||||
|
it != (*_user->_operations[yearFrom])[monthFrom].end()
|
||||||
|
&& it->fix_cost;
|
||||||
|
it++)
|
||||||
|
{
|
||||||
|
op = *it;
|
||||||
|
op.month = monthTo;
|
||||||
|
op.year = yearTo;
|
||||||
|
AddOperation(op);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_wxUI->GenerateMonth(monthTo, yearTo);
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@ class KissCount
|
||||||
void DeleteCategory(struct category category);
|
void DeleteCategory(struct category category);
|
||||||
|
|
||||||
std::map<int, std::vector<int> > GetAllOperations();
|
std::map<int, std::vector<int> > GetAllOperations();
|
||||||
|
|
||||||
|
void GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo);
|
||||||
private:
|
private:
|
||||||
wxUI* _wxUI;
|
wxUI* _wxUI;
|
||||||
Database* _db;
|
Database* _db;
|
||||||
|
|
|
@ -605,3 +605,60 @@ std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Database::GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo)
|
||||||
|
{
|
||||||
|
std::vector<Account>::iterator it;
|
||||||
|
wxString req;
|
||||||
|
wxSQLite3ResultSet set;
|
||||||
|
double amount;
|
||||||
|
|
||||||
|
if (monthFrom == -1 || yearFrom == -1)
|
||||||
|
{
|
||||||
|
for (it = user->_accounts.begin(); it != user->_accounts.end(); it++)
|
||||||
|
{
|
||||||
|
req = _("INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('") ;
|
||||||
|
req += it->id + _("'");
|
||||||
|
req += _(" ,'") + wxString::Format(_("%d"), yearTo) + _("'");
|
||||||
|
req += _(" ,'") + wxString::Format(_("%d"), monthTo) + _("'");
|
||||||
|
req += _(" ,'0.0'");
|
||||||
|
req += _(")");
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (it = user->_accounts.begin(); it != user->_accounts.end(); it++)
|
||||||
|
{
|
||||||
|
amount = 0.0;
|
||||||
|
req = _("SELECT SUM(amount) FROM operation WHERE") ;
|
||||||
|
req += _(" account='") + it->id + _("'");
|
||||||
|
req += _(" AND year='") + wxString::Format(_("%d"), yearFrom) + _("'");
|
||||||
|
req += _(" AND month='") + wxString::Format(_("%d"), monthFrom) + _("'");
|
||||||
|
|
||||||
|
EXECUTE_SQL_QUERY(req, set, );
|
||||||
|
|
||||||
|
if (set.NextRow())
|
||||||
|
amount = set.GetDouble(_("amount"));
|
||||||
|
|
||||||
|
req = _("SELECT amount FROM account_amount WHERE") ;
|
||||||
|
req += _(" account='") + it->id + _("'");
|
||||||
|
req += _(" AND year='") + wxString::Format(_("%d"), yearFrom) + _("'");
|
||||||
|
req += _(" AND month='") + wxString::Format(_("%d"), monthFrom) + _("'");
|
||||||
|
|
||||||
|
EXECUTE_SQL_QUERY(req, set, );
|
||||||
|
|
||||||
|
if (set.NextRow())
|
||||||
|
amount += set.GetDouble(_("amount"));
|
||||||
|
|
||||||
|
req = _("INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('") ;
|
||||||
|
req += it->id + _("'");
|
||||||
|
req += _(" ,'") + wxString::Format(_("%d"), yearTo) + _("'");
|
||||||
|
req += _(" ,'") + wxString::Format(_("%d"), monthTo) + _("'");
|
||||||
|
req += _(" ,'") + wxString::Format(_("%.2lf"), amount) + _("'");
|
||||||
|
req += _(")");
|
||||||
|
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ class Database
|
||||||
void DeleteCategory(User* user, struct category category);
|
void DeleteCategory(User* user, struct category category);
|
||||||
|
|
||||||
std::map<int, std::vector<int> > GetAllOperations(User* user);
|
std::map<int, std::vector<int> > GetAllOperations(User* user);
|
||||||
|
void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxSQLite3Database _db;
|
wxSQLite3Database _db;
|
||||||
|
|
|
@ -226,11 +226,12 @@ void AccountPanel::LoadYear(int year, bool showMonth)
|
||||||
std::map<unsigned int, std::vector<operation> >::iterator it;
|
std::map<unsigned int, std::vector<operation> >::iterator it;
|
||||||
wxDateTime curDate;
|
wxDateTime curDate;
|
||||||
wxTreeItemId parentNode, curMonthNode;
|
wxTreeItemId parentNode, curMonthNode;
|
||||||
|
//std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
|
||||||
|
|
||||||
if (user->_operations[year])
|
if (user->_operations[year])
|
||||||
{
|
{
|
||||||
if (showMonth)
|
if (showMonth)
|
||||||
ShowMonth(year, -1);
|
ShowMonth(-1, year);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +257,7 @@ void AccountPanel::LoadYear(int year, bool showMonth)
|
||||||
if (showMonth)
|
if (showMonth)
|
||||||
{
|
{
|
||||||
_tree.SelectItem(curMonthNode, true);
|
_tree.SelectItem(curMonthNode, true);
|
||||||
ShowMonth(year, curMonth);
|
ShowMonth(curMonth, year);
|
||||||
}
|
}
|
||||||
|
|
||||||
_wxUI->Layout();
|
_wxUI->Layout();
|
||||||
|
@ -267,7 +268,7 @@ void AccountPanel::LoadYear(int year, bool showMonth)
|
||||||
_grid->SetCellBackgroundColour(row, i, color);\
|
_grid->SetCellBackgroundColour(row, i, color);\
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountPanel::ShowMonth(int year, int month)
|
void AccountPanel::ShowMonth(int month, int year)
|
||||||
{
|
{
|
||||||
std::vector<operation> operations;
|
std::vector<operation> operations;
|
||||||
std::vector<operation>::iterator it;
|
std::vector<operation>::iterator it;
|
||||||
|
@ -278,7 +279,6 @@ void AccountPanel::ShowMonth(int year, int month)
|
||||||
std::vector<category>::iterator categoryIt;
|
std::vector<category>::iterator categoryIt;
|
||||||
std::map<unsigned int, std::vector<operation> >::iterator monthIt;
|
std::map<unsigned int, std::vector<operation> >::iterator monthIt;
|
||||||
wxDateTime curDate;
|
wxDateTime curDate;
|
||||||
|
|
||||||
curDate.SetToCurrent();
|
curDate.SetToCurrent();
|
||||||
|
|
||||||
if (month == -1)
|
if (month == -1)
|
||||||
|
@ -846,7 +846,7 @@ void AccountPanel::OnTreeChange(wxTreeEvent& event)
|
||||||
|
|
||||||
if (year != _curYear || month != _curMonth)
|
if (year != _curYear || month != _curMonth)
|
||||||
{
|
{
|
||||||
ShowMonth(year, month);
|
ShowMonth(month, year);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -893,3 +893,64 @@ void AccountPanel::OnMenuDelete(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AccountPanel::GenerateMonth(int month, int year)
|
||||||
|
{
|
||||||
|
wxTreeItemId root, years, node ;
|
||||||
|
wxTreeItemIdValue cookie;
|
||||||
|
wxString monthString, yearString;
|
||||||
|
std::map<unsigned int, std::vector<operation> >::iterator it;
|
||||||
|
int i;
|
||||||
|
User* user = _kiss->GetUser();
|
||||||
|
|
||||||
|
root = _tree.GetRootItem();
|
||||||
|
yearString = wxString::Format(wxT("%d"), year);
|
||||||
|
monthString = months[month];
|
||||||
|
|
||||||
|
if (_tree.GetChildrenCount(root, true) < 1)
|
||||||
|
{
|
||||||
|
node = _tree.AppendItem(root, yearString);
|
||||||
|
node = _tree.AppendItem(node, monthString);
|
||||||
|
|
||||||
|
_tree.SelectItem(node, true);
|
||||||
|
ShowMonth(month, year);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
years = _tree.GetFirstChild(root, cookie);
|
||||||
|
while (years.IsOk())
|
||||||
|
{
|
||||||
|
if (_tree.GetItemText(years) == yearString)
|
||||||
|
break;
|
||||||
|
if (wxAtoi(_tree.GetItemText(years)) > year)
|
||||||
|
{
|
||||||
|
years = _tree.GetPrevSibling(years);
|
||||||
|
if (!years.IsOk())
|
||||||
|
years = _tree.PrependItem(root, yearString);
|
||||||
|
else
|
||||||
|
years = _tree.InsertItem(root, years, yearString);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
years = _tree.GetNextSibling(years);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!years.IsOk())
|
||||||
|
years = _tree.PrependItem(root, yearString);
|
||||||
|
|
||||||
|
if (!_tree.GetChildrenCount(years, true))
|
||||||
|
node = _tree.AppendItem(years, monthString);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(i=0, it = user->_operations[year]->begin();
|
||||||
|
it != user->_operations[year]->end();
|
||||||
|
it++, i++)
|
||||||
|
{
|
||||||
|
if ((int)it->first >= month)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
years = _tree.InsertItem(years, i, monthString);
|
||||||
|
}
|
||||||
|
|
||||||
|
_tree.SelectItem(node, true);
|
||||||
|
ShowMonth(month, year);
|
||||||
|
}
|
||||||
|
|
|
@ -35,7 +35,8 @@ public:
|
||||||
~AccountPanel();
|
~AccountPanel();
|
||||||
void ChangeUser();
|
void ChangeUser();
|
||||||
void LoadYear(int year, bool showMonth=true);
|
void LoadYear(int year, bool showMonth=true);
|
||||||
void ShowMonth(int year, int month);
|
void ShowMonth(int month, int year);
|
||||||
|
void GenerateMonth(int month, int year);
|
||||||
|
|
||||||
void OnOperationModified(wxGridEvent& event);
|
void OnOperationModified(wxGridEvent& event);
|
||||||
void OnAccountModified(wxGridEvent& event);
|
void OnAccountModified(wxGridEvent& event);
|
||||||
|
|
|
@ -168,8 +168,39 @@ void GenerateDialog::OnYearToChange(wxCommandEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateDialog::OnOK(wxCommandEvent& event)
|
void GenerateDialog::OnOK(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
|
int monthFrom, yearFrom, monthTo, yearTo, i;
|
||||||
|
|
||||||
|
if (_yearFrom->GetString(_yearTo->GetCurrentSelection()) == _(""))
|
||||||
|
{
|
||||||
|
monthFrom = -1;
|
||||||
|
yearFrom = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i=0; i<12; i++)
|
||||||
|
{
|
||||||
|
if (months[i] == _monthFrom->GetString(_monthFrom->GetCurrentSelection()))
|
||||||
|
{
|
||||||
|
monthFrom = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yearFrom = wxAtoi(_yearFrom->GetString(_yearFrom->GetCurrentSelection()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0; i<12; i++)
|
||||||
|
{
|
||||||
|
if (months[i] == _monthTo->GetString(_monthTo->GetCurrentSelection()))
|
||||||
|
{
|
||||||
|
monthTo = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yearTo = wxAtoi(_yearTo->GetString(_yearTo->GetCurrentSelection()));
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
|
_kiss->GenerateMonth(monthFrom, yearFrom, monthTo, yearTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateDialog::OnCancel(wxCommandEvent& event)
|
void GenerateDialog::OnCancel(wxCommandEvent& event)
|
||||||
|
|
|
@ -101,3 +101,8 @@ void wxUI::ShowPanel(wxPanel* panel)
|
||||||
_curPanel->Show();
|
_curPanel->Show();
|
||||||
Layout();
|
Layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxUI::GenerateMonth(int month, int year)
|
||||||
|
{
|
||||||
|
_accountPanel->GenerateMonth(month, year);
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
|
|
||||||
void ShowAccount();
|
void ShowAccount();
|
||||||
void ShowPreferences();
|
void ShowPreferences();
|
||||||
|
void GenerateMonth(int month, int year);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KissCount *_kiss;
|
KissCount *_kiss;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user