Add check mode

Fix bug with KissCount title on start
This commit is contained in:
2010-08-21 11:49:03 +02:00
parent d12e00c6fb
commit 9f7d858bc3
10 changed files with 179 additions and 81 deletions
+5
View File
@@ -365,3 +365,8 @@ void KissCount::GetStats(int monthFrom, int yearFrom, int monthTo, int yearTo,
_db->GetStats(_user, monthF, yearF, monthT, yearT, accountAmounts, categories);
}
std::map<wxString, double>* KissCount::GetNotChecked(int month, int year)
{
return _db->GetNotChecked(_user, month, year);
}
+2
View File
@@ -80,6 +80,8 @@ class KissCount
std::map<wxString, std::map<int, std::map<int, double> > >* accountAmounts,
std::map<wxString, double>* categories);
std::map<wxString, double>* GetNotChecked(int month, int year);
private:
wxUI* _wxUI;
Database* _db;
+27 -2
View File
@@ -411,7 +411,7 @@ void Database::LinkOrUnlinkOperation(Operation& op)
req += wxT(" AND month='") + wxString::Format(wxT("%d"), op.month) + wxT("'");
req += wxT(" AND year='") + wxString::Format(wxT("%d"), op.year) + wxT("'");
req += wxT(" AND amount='") + DoubleToString(-op.amount) + wxT("'");
req += wxT(" AND transfert=''");
req += wxT(" AND (transfert='' OR transfert IS NULL)");
EXECUTE_SQL_QUERY(req, set, );
@@ -1196,8 +1196,8 @@ void Database::GetStats(User* user, const wxString& monthFrom, const wxString& y
req += wxT(" AND (year > '") + yearFrom + wxT("' OR (year == '") + yearFrom + wxT("' AND month >= '") + monthFrom + wxT("'))");
req += wxT(" AND (year < '") + yearTo + wxT("' OR (year == '") + yearTo + wxT("' AND month <= '") + monthTo + wxT("'))");
req += wxT(" AND (transfert='' OR transfert IS NULL)");
req += wxT(" AND amount < 0");
req += wxT(" AND transfert=''");
EXECUTE_SQL_QUERY(req, set, );
@@ -1209,3 +1209,28 @@ void Database::GetStats(User* user, const wxString& monthFrom, const wxString& y
}
}
}
std::map<wxString, double>* Database::GetNotChecked(User* user, int month, int year)
{
std::vector<Account>::iterator accountIt;
std::map<wxString, double>* res = new std::map<wxString, double>;
wxSQLite3ResultSet set;
wxString req;
for (accountIt = user->_accounts.begin() ;accountIt != user->_accounts.end(); accountIt++)
{
req = wxT("SELECT SUM(amount) AS amount FROM operation WHERE account='") + accountIt->id + wxT("'");
req += wxT(" AND checked='0'");
req += wxT(" AND (year < '") + wxString::Format(wxT("%d"), year) + wxT("'") ;
req += wxT(" OR (year == '") + wxString::Format(wxT("%d"), year) + wxT("'") ;
req += wxT(" AND month < '") + wxString::Format(wxT("%d"), month) + wxT("'") ;
req += wxT("))");
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, delete res, delete res);
if (set.NextRow())
(*res)[accountIt->id] = set.GetDouble(wxT("amount"));
}
return res;
}
+2
View File
@@ -78,6 +78,8 @@ class Database
void KillMe(User* user);
bool GetOperation(const wxString& id, Operation* op);
std::map<wxString, double>* GetNotChecked(User* user, int month, int year);
private:
wxSQLite3Database _db;
+69 -17
View File
@@ -21,7 +21,7 @@ along with KissCount. If not, see <http://www.gnu.org/licenses/>.
enum {ACCOUNT_NUMBER, ACCOUNT_NAME, ACCOUNT_INIT, ACCOUNT_CUR, ACCOUNT_FINAL, NUMBER_COLS_ACCOUNTS};
enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, REMAINS, STATS_ROW, CATS_STATS};
enum {CALENDAR_TREE_ID=1, OPS_GRID_ID, CALENDAR_ID, ACCOUNTS_GRID_ID, MENU_GENERATE_ID, MENU_DELETE_ID};
enum {CALENDAR_TREE_ID=1, OPS_GRID_ID, CALENDAR_ID, ACCOUNTS_GRID_ID, MENU_GENERATE_ID, MENU_DELETE_ID, CHECK_MODE_ID};
BEGIN_EVENT_TABLE(AccountPanel, wxPanel)
EVT_GRID_CMD_CELL_CHANGE(OPS_GRID_ID, AccountPanel::OnOperationModified)
@@ -33,6 +33,7 @@ EVT_MENU(MENU_GENERATE_ID, AccountPanel::OnMenuGenerate)
EVT_MENU(MENU_DELETE_ID, AccountPanel::OnMenuDelete)
EVT_SHOW(AccountPanel::OnShow)
EVT_CALENDAR_SEL_CHANGED(CALENDAR_ID, AccountPanel::OnCalendarChange)
EVT_CHECKBOX(CHECK_MODE_ID, AccountPanel::OnCheckMode)
END_EVENT_TABLE()
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*parent)), _curMonth(-1), _curYear(-1), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT)
@@ -113,6 +114,9 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*
chart->Layout();
chart->SetMinSize(// chart->GetSize()
wxSize(200,250));
_checkCheckMode = new wxCheckBox(this, CHECK_MODE_ID, _("Check mode"));
hbox->Add(&_tree, 0);
hbox2->Add(_accountsGrid, 0);
hbox2->Add(_calendar, 0);
@@ -124,6 +128,8 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*
vbox->Add(-1, 10);
vbox->Add(chart, 0);
hbox->Add(-1, 10);
vbox->Add(_checkCheckMode, 0);
hbox->Add(-1, 10);
hbox->Add(vbox, 0);
ChangeUser();
@@ -437,12 +443,20 @@ void AccountPanel::UpdateStats()
int i;
User* user = _kiss->GetUser();
std::vector<Operation>::iterator it;
double curCredit, curDebit, totalCredit, totalDebit, remains, value, percents;
double curCredit, curDebit, totalCredit, totalDebit, remains, 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;
bool checkMode = _checkCheckMode->IsChecked();
std::map<wxString, double>* notChecked = NULL;
if (checkMode)
{
notChecked = _kiss->GetNotChecked(_curMonth, _curYear);
}
day = _calendar->GetDate().GetDay()-1;
curCredit = curDebit = totalCredit = totalDebit = 0.0;
@@ -458,27 +472,35 @@ void AccountPanel::UpdateStats()
for (it=_curOperations->begin(); it!=_curOperations->end(); it++)
{
if (it->transfert.Length()) continue;
if (it->amount > 0)
{
if (day >= it->day)
{
curCredit += it->amount;
curAccountAmount[it->account] += it->amount;
if (!it->transfert.Length())
curCredit += it->amount;
if (!checkMode || (checkMode && it->checked))
curAccountAmount[it->account] += it->amount;
}
totalCredit += it->amount;
finalAccountAmount[it->account] += it->amount;
if (!it->transfert.Length())
totalCredit += it->amount;
if (!checkMode || (checkMode && it->checked))
finalAccountAmount[it->account] += it->amount;
}
else
{
_categoriesValues[_categoriesIndexes[user->GetCategoryName(it->category)]] += -it->amount ;
if (!it->transfert.Length())
_categoriesValues[_categoriesIndexes[user->GetCategoryName(it->category)]] += -it->amount ;
if (day >= it->day)
{
curDebit += -it->amount;
curAccountAmount[it->account] += it->amount;
if (!it->transfert.Length())
curDebit += -it->amount;
if (!checkMode || (checkMode && it->checked))
curAccountAmount[it->account] += it->amount;
}
totalDebit += -it->amount;
finalAccountAmount[it->account] += it->amount;
if (!it->transfert.Length())
totalDebit += -it->amount;
if (!checkMode || (checkMode && it->checked))
finalAccountAmount[it->account] += it->amount;
}
}
@@ -499,16 +521,41 @@ void AccountPanel::UpdateStats()
for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++)
{
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));
if (!checkMode || !notChecked)
{
value = _accountsInitValues[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];
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->AutoSizeColumn(ACCOUNT_INIT, true);
_accountsGrid->AutoSizeColumn(ACCOUNT_CUR, true);
_accountsGrid->AutoSizeColumn(ACCOUNT_FINAL, true);
if (notChecked) delete notChecked;
_statsGrid->AutoSizeColumn(1, true);
_pie->DatasetChanged(_dataset);
Layout();
}
void AccountPanel::OnOperationModified(wxGridEvent& event)
@@ -1048,3 +1095,8 @@ void AccountPanel::OnCalendarChange(wxCalendarEvent& event)
{
UpdateStats();
}
void AccountPanel::OnCheckMode(wxCommandEvent& event)
{
UpdateStats();
}
+2
View File
@@ -70,6 +70,7 @@ class AccountPanel: public wxScrolledWindow
wxGrid *_statsGrid, *_accountsGrid;
PiePlot* _pie;
double *_categoriesValues;
wxCheckBox *_checkCheckMode;
std::map<wxString, int> _categoriesIndexes;
std::vector<Operation>* _curOperations;
wxString* _categories, *_accounts;
@@ -82,6 +83,7 @@ class AccountPanel: public wxScrolledWindow
void UpdateStats();
void InsertOperation(User* user, Operation* op, int line, bool fix);
void GetTreeSelection(int* month, int* year);
void OnCheckMode(wxCommandEvent& event);
DECLARE_EVENT_TABLE();
};
+2
View File
@@ -149,6 +149,7 @@ void wxUI::ChangeUser()
void wxUI::LoadUser()
{
User* user = _kiss->GetUser();
wxShowEvent event;
if (_curPanel)
{
@@ -177,6 +178,7 @@ void wxUI::LoadUser()
_preferencesPanel = new PreferencesPanel(_kiss, this);
ShowPanel(_accountPanel);
_accountPanel->OnShow(event);
}
void wxUI::ShowPanel(wxPanel* panel)