Add virtual accounts (potential bugs)

This commit is contained in:
Grégory Soutadé 2011-02-14 20:56:59 +01:00
parent c03562851a
commit bf417a503d
14 changed files with 150 additions and 27 deletions

View File

@ -1,4 +1,4 @@
v0.2_dev (13/02/2011) v0.2_dev (14/02/2011)
** User ** ** User **
Better use of sizers (so better interface!) Better use of sizers (so better interface!)
@ -8,6 +8,7 @@ v0.2_dev (13/02/2011)
Possibility to choose a replacement when deleting accounts and categories Possibility to choose a replacement when deleting accounts and categories
Possibility to find operations with unknown category/account Possibility to find operations with unknown category/account
Possibility to work on multiple operations (rename, change category, change account) Possibility to work on multiple operations (rename, change category, change account)
Add virtual accounts
** Dev ** ** Dev **
Use a factory to create panels (prepare for plug-in) Use a factory to create panels (prepare for plug-in)

View File

@ -3,7 +3,7 @@ CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255), password VARCHAR(2
CREATE TABLE account(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), number VARCHAR(255), shared CHAR(1), blocked CHAR(1), default_account CHAR(1)); CREATE TABLE account(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), number VARCHAR(255), shared CHAR(1), blocked CHAR(1), default_account CHAR(1));
CREATE TABLE shared_account(account REFERENCES account(id), user REFERENCES user(id)); CREATE TABLE shared_account(account REFERENCES account(id), user REFERENCES user(id));
CREATE TABLE account_amount(id INTEGER PRIMARY KEY, account REFERENCES account(id), year INTEGER, month INTEGER, amount FLOAT); CREATE TABLE account_amount(id INTEGER PRIMARY KEY, account REFERENCES account(id), year INTEGER, month INTEGER, amount FLOAT);
CREATE TABLE operation(id INTEGER PRIMARY KEY, parent REFERENCES operation(id), user REFERENCES user(id), account REFERENCES account(id), year INTEGER, month INTEGER, day INTEGER, amount FLOAT, description VARCHAR(255), category REFERENCES category(id), fix_cost CHAR(1), checked CHAR(1), formula VARCHAR(255), transfert REFERENCES operation(id), meta CHAR(1)); CREATE TABLE operation(id INTEGER PRIMARY KEY, parent REFERENCES operation(id), user REFERENCES user(id), account REFERENCES account(id), year INTEGER, month INTEGER, day INTEGER, amount FLOAT, description VARCHAR(255), category REFERENCES category(id), fix_cost CHAR(1), checked CHAR(1), formula VARCHAR(255), transfert REFERENCES operation(id), meta CHAR(1), virtual CHAR(1));
CREATE TABLE category(id INTEGER PRIMARY KEY, user REFERENCES user(id), parent REFERENCES category(id), name VARCHAR(255), backcolor VARCHAR(10), forecolor VARCHAR(10), font VARCHAR(255), fix_cost CHAR(1)); CREATE TABLE category(id INTEGER PRIMARY KEY, user REFERENCES user(id), parent REFERENCES category(id), name VARCHAR(255), backcolor VARCHAR(10), forecolor VARCHAR(10), font VARCHAR(255), fix_cost CHAR(1));
CREATE TABLE preference(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), value VARCHAR(255)); CREATE TABLE preference(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), value VARCHAR(255));
INSERT INTO kisscount ("db_version") VALUES ("2"); INSERT INTO kisscount ("db_version") VALUES ("2");

View File

@ -104,7 +104,7 @@ void KissCount::UpdateOperation(Operation& op)
op.transfert = wxT(""); op.transfert = wxT("");
_user->LinkOrUnlinkOperation(op); _user->LinkOrUnlinkOperation(op);
_db->UpdateOperation(op); _db->UpdateOperation(_user, op);
// Link // Link
_user->LinkOrUnlinkOperation(op); _user->LinkOrUnlinkOperation(op);
@ -127,7 +127,7 @@ void KissCount::DeleteOperation(Operation& op)
op.transfert = wxT(""); op.transfert = wxT("");
_user->LinkOrUnlinkOperation(op); _user->LinkOrUnlinkOperation(op);
} }
_db->DeleteOperation(op); _db->DeleteOperation(_user, op);
} }
void KissCount::DeleteOperations(int month, int year) void KissCount::DeleteOperations(int month, int year)
@ -310,6 +310,7 @@ void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int year
op.checked = false; op.checked = false;
op.id = AddOperation(op); op.id = AddOperation(op);
op.childs.clear(); op.childs.clear();
op._virtual = false;
if (op.meta) if (op.meta)
meta[it->id] = op.id; meta[it->id] = op.id;
(*_user->_operations[yearTo])[monthTo].push_back(op); (*_user->_operations[yearTo])[monthTo].push_back(op);
@ -494,6 +495,11 @@ std::map<wxString, double>* KissCount::GetNotChecked(int month, int year)
return _db->GetNotChecked(_user, month, year); return _db->GetNotChecked(_user, month, year);
} }
std::map<wxString, double>* KissCount::GetVirtualAmount(int month, int year)
{
return _db->GetVirtualAmount(_user, month, year);
}
wxFont KissCount::ExtractFont(wxString strFont) wxFont KissCount::ExtractFont(wxString strFont)
{ {
long int pos, pointSize, family, style, weight; long int pos, pointSize, family, style, weight;

View File

@ -97,6 +97,7 @@ public:
std::map<wxString, double>* categories); std::map<wxString, double>* categories);
std::map<wxString, double>* GetNotChecked(int month, int year); std::map<wxString, double>* GetNotChecked(int month, int year);
std::map<wxString, double>* GetVirtualAmount(int month, int year);
static wxFont ExtractFont(wxString strFont); static wxFont ExtractFont(wxString strFont);
static wxString CompactFont(const wxFont& font); static wxString CompactFont(const wxFont& font);

View File

@ -33,6 +33,7 @@ public:
bool blocked; bool blocked;
bool _default; bool _default;
bool is_owner; bool is_owner;
bool _virtual;
}; };
#endif #endif

View File

@ -222,6 +222,7 @@ User* Database::LoadUser(const wxString& name)
account.shared = set.GetBool(wxT("shared")); account.shared = set.GetBool(wxT("shared"));
account.blocked = set.GetBool(wxT("blocked")); account.blocked = set.GetBool(wxT("blocked"));
account._default = set.GetBool(wxT("default_account")); account._default = set.GetBool(wxT("default_account"));
account._virtual = set.GetBool(wxT("virtual"));
account.is_owner = true; account.is_owner = true;
user->_accounts.push_back(account); user->_accounts.push_back(account);
} }
@ -239,6 +240,7 @@ User* Database::LoadUser(const wxString& name)
account.shared = set.GetBool(wxT("shared")); account.shared = set.GetBool(wxT("shared"));
account.blocked = set.GetBool(wxT("blocked")); account.blocked = set.GetBool(wxT("blocked"));
account._default = set.GetBool(wxT("default_account")); account._default = set.GetBool(wxT("default_account"));
account._virtual = set.GetBool(wxT("virtual"));
account.is_owner = false; account.is_owner = false;
user->_accounts.push_back(account); user->_accounts.push_back(account);
} }
@ -339,6 +341,7 @@ void Database::LoadYear(User* user, int year)
op.transfert = set.GetAsString(wxT("transfert")); op.transfert = set.GetAsString(wxT("transfert"));
op.formula = set.GetAsString(wxT("formula")); op.formula = set.GetAsString(wxT("formula"));
op.meta = set.GetBool(wxT("meta")); op.meta = set.GetBool(wxT("meta"));
op._virtual = set.GetBool(wxT("virtual"));
(*user->_operations[op.year])[op.month].push_back(op); (*user->_operations[op.year])[op.month].push_back(op);
} }
@ -427,26 +430,30 @@ bool Database::GetOperation(const wxString& id, Operation* op)
op->fix_cost = set.GetBool(wxT("fix_cost")); op->fix_cost = set.GetBool(wxT("fix_cost"));
op->checked = set.GetBool(wxT("checked")); op->checked = set.GetBool(wxT("checked"));
op->transfert = set.GetAsString(wxT("transfert")); op->transfert = set.GetAsString(wxT("transfert"));
op->formula = set.GetAsString(wxT("formula")); op->formula = set.GetAsString(wxT("formula"));
op->meta = set.GetBool(wxT("meta")); op->meta = set.GetBool(wxT("meta"));
op->_virtual = set.GetBool(wxT("virtual"));
return true; return true;
} }
void Database::LinkOrUnlinkOperation(Operation& op) void Database::LinkOrUnlinkOperation(User* user, Operation& op)
{ {
Operation linked; Operation linked;
wxString req; wxString req;
wxSQLite3ResultSet set; wxSQLite3ResultSet set;
Account account, account2;
bool _virtual;
if (op.transfert.Length()) if (op.transfert.Length())
{ {
// No one or not linked // No one or not linked
if (!GetOperation(op.transfert, &linked) || op.description != linked.description || op.amount != -linked.amount || op.account == linked.account) if (!GetOperation(op.transfert, &linked) || op.description != linked.description || op.amount != -linked.amount || op.account == linked.account)
{ {
req = wxT("UPDATE operation SET transfert='' where id='") + op.id + wxT("'") ; req = wxT("UPDATE operation SET transfert='' virtual='0' WHERE id='") + op.id + wxT("'") ;
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
op.transfert = wxT(""); op.transfert = wxT("");
op._virtual = 0;
return; return;
} }
} }
@ -459,11 +466,11 @@ void Database::LinkOrUnlinkOperation(Operation& op)
if (set.NextRow()) if (set.NextRow())
{ {
req = wxT("UPDATE operation SET transfert='' where id='") + set.GetAsString(wxT("id")) + wxT("'") ; req = wxT("UPDATE operation SET transfert='', virtual='0' WHERE id='") + set.GetAsString(wxT("id")) + wxT("'") ;
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
} }
req = wxT("SELECT id FROM operation WHERE description=\"") + op.description + wxT("\""); req = wxT("SELECT id, account FROM operation WHERE description=\"") + op.description + wxT("\"");
req += wxT(" AND month='") + wxString::Format(wxT("%d"), op.month) + wxT("'"); 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 year='") + wxString::Format(wxT("%d"), op.year) + wxT("'");
req += wxT(" AND amount='") + DoubleToString(-op.amount) + wxT("'"); req += wxT(" AND amount='") + DoubleToString(-op.amount) + wxT("'");
@ -473,6 +480,8 @@ void Database::LinkOrUnlinkOperation(Operation& op)
EXECUTE_SQL_QUERY(req, set, ); EXECUTE_SQL_QUERY(req, set, );
op._virtual = false;
// Don't need to link // Don't need to link
if (!set.NextRow()) return ; if (!set.NextRow()) return ;
@ -481,19 +490,37 @@ void Database::LinkOrUnlinkOperation(Operation& op)
op.transfert = linked.id; op.transfert = linked.id;
req = wxT("UPDATE operation SET transfert='") + linked.id + wxT("' where id='") + op.id + wxT("'") ; account = user->GetAccount(op.account);
account2 = user->GetAccount(set.GetAsString(wxT("account")));
_virtual = account._virtual || account2._virtual;
req = wxT("UPDATE operation SET transfert='") + linked.id + wxT("'");
if (_virtual)
req += wxT(", virtual='1'");
else
req += wxT(", virtual='0'");
req += wxT(" WHERE id='") + op.id + wxT("'") ;
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
req = wxT("UPDATE operation SET transfert='") + op.id + wxT("' where id='") + linked.id + wxT("'") ; req = wxT("UPDATE operation SET transfert='") + op.id + wxT("'") ;
if (_virtual)
req += wxT(", virtual='1'");
else
req += wxT(", virtual='0'");
req += wxT(" WHERE id='") + linked.id + wxT("'") ;
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
op._virtual = _virtual;
} }
} }
void Database::UpdateOperation(Operation& op) void Database::UpdateOperation(User* user, Operation& op)
{ {
wxString req; wxString req;
LinkOrUnlinkOperation(op); LinkOrUnlinkOperation(user, op);
ESCAPE_CHARS(op.description); ESCAPE_CHARS(op.description);
@ -519,12 +546,16 @@ void Database::UpdateOperation(Operation& op)
req += wxT(", meta='1'"); req += wxT(", meta='1'");
else else
req += wxT(", meta='0'"); req += wxT(", meta='0'");
if (op._virtual)
req += wxT(", virtual='1'");
else
req += wxT(", virtual='0'");
req += wxT(", formula='") + op.formula + wxT("'"); req += wxT(", formula='") + op.formula + wxT("'");
req += wxT(" WHERE id='") + op.id + wxT("'"); req += wxT(" WHERE id='") + op.id + wxT("'");
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
LinkOrUnlinkOperation(op); LinkOrUnlinkOperation(user, op);
} }
wxString Database::AddOperation(User* user, Operation& op) wxString Database::AddOperation(User* user, Operation& op)
@ -534,7 +565,7 @@ wxString Database::AddOperation(User* user, Operation& op)
ESCAPE_CHARS(op.description); ESCAPE_CHARS(op.description);
req = wxT("INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost', 'formula', 'transfert', 'meta') VALUES ('") ; req = wxT("INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost', 'formula', 'transfert', 'meta', 'virtual') VALUES ('") ;
req += user->_id + wxT("'"); req += user->_id + wxT("'");
req += wxT(", '") + op.parent + wxT("'"); req += wxT(", '") + op.parent + wxT("'");
req += wxT(", '") + op.account + wxT("'"); req += wxT(", '") + op.account + wxT("'");
@ -554,6 +585,10 @@ wxString Database::AddOperation(User* user, Operation& op)
req += wxT(", '1'") ; req += wxT(", '1'") ;
else else
req += wxT(", '0'") ; req += wxT(", '0'") ;
if (op._virtual)
req += wxT(", '1'") ;
else
req += wxT(", '0'") ;
req += wxT(")"); req += wxT(")");
EXECUTE_SQL_UPDATE(req, wxT("0")); EXECUTE_SQL_UPDATE(req, wxT("0"));
@ -562,19 +597,19 @@ wxString Database::AddOperation(User* user, Operation& op)
op.id = res; op.id = res;
LinkOrUnlinkOperation(op); LinkOrUnlinkOperation(user, op);
return res; return res;
} }
void Database::DeleteOperation(Operation& op) void Database::DeleteOperation(User* user, Operation& op)
{ {
wxString req; wxString req;
req = wxT("DELETE FROM operation WHERE id='") + op.id + wxT("'"); req = wxT("DELETE FROM operation WHERE id='") + op.id + wxT("'");
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
LinkOrUnlinkOperation(op); LinkOrUnlinkOperation(user, op);
} }
void Database::DeleteOperations(User* user, int month, int year) void Database::DeleteOperations(User* user, int month, int year)
@ -638,8 +673,9 @@ bool Database::LoadOperation(User* user, const wxString& id)
op.fix_cost = set.GetBool(wxT("fix_cost")); op.fix_cost = set.GetBool(wxT("fix_cost"));
op.checked = set.GetBool(wxT("checked")); op.checked = set.GetBool(wxT("checked"));
op.transfert = set.GetAsString(wxT("transfert")); op.transfert = set.GetAsString(wxT("transfert"));
op.formula = set.GetAsString(wxT("formula")); op.formula = set.GetAsString(wxT("formula"));
op.meta = set.GetBool(wxT("meta")); op.meta = set.GetBool(wxT("meta"));
op._virtual = set.GetBool(wxT("virtual"));
if (user->_operations[op.year]) if (user->_operations[op.year])
{ {
@ -747,7 +783,7 @@ wxString Database::AddAccount(User* user, Account& ac)
{ {
wxString req; wxString req;
req = wxT("INSERT INTO account ('user', 'name', 'number', 'shared', 'blocked', 'default_account') VALUES ('") ; req = wxT("INSERT INTO account ('user', 'name', 'number', 'shared', 'blocked', 'default_account', 'virtual') VALUES ('") ;
req += user->_id + wxT("'"); req += user->_id + wxT("'");
req += wxT(", '") + ac.name + wxT("'"); req += wxT(", '") + ac.name + wxT("'");
req += wxT(", '") + ac.number + wxT("'"); req += wxT(", '") + ac.number + wxT("'");
@ -763,6 +799,10 @@ wxString Database::AddAccount(User* user, Account& ac)
req += wxT(", '1'") ; req += wxT(", '1'") ;
else else
req += wxT(", '0'") ; req += wxT(", '0'") ;
if (ac._virtual)
req += wxT(", '1'") ;
else
req += wxT(", '0'") ;
req += wxT(")"); req += wxT(")");
EXECUTE_SQL_UPDATE(req, wxT("0")); EXECUTE_SQL_UPDATE(req, wxT("0"));
@ -788,6 +828,10 @@ void Database::UpdateAccount(Account& ac)
req += wxT(", default_account='1'"); req += wxT(", default_account='1'");
else else
req += wxT(", default_account='0'"); req += wxT(", default_account='0'");
if (ac._virtual)
req += wxT(", virtual='1'");
else
req += wxT(", virtual='0'");
req += wxT(" WHERE id='") + ac.id + wxT("'"); req += wxT(" WHERE id='") + ac.id + wxT("'");
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
@ -1595,6 +1639,32 @@ std::map<wxString, double>* Database::GetNotChecked(User* user, int month, int y
return res; return res;
} }
std::map<wxString, double>* Database::GetVirtualAmount(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 virtual='1'");
req += wxT(" AND meta='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;
}
std::map<wxString, wxString> Database::getSharedAccountOwners(const wxString& account) std::map<wxString, wxString> Database::getSharedAccountOwners(const wxString& account)
{ {
std::map<wxString, wxString> res; std::map<wxString, wxString> res;

View File

@ -107,9 +107,9 @@ public:
User* LoadUser(const wxString& name); User* LoadUser(const wxString& name);
void LoadYear(User* user, int year); void LoadYear(User* user, int year);
void UpdateOperation(Operation& op); void UpdateOperation(User* user, Operation& op);
wxString AddOperation(User* user, Operation& op); wxString AddOperation(User* user, Operation& op);
void DeleteOperation(Operation& op); void DeleteOperation(User* user, Operation& op);
void DeleteOperations(User* user, int month, int year); void DeleteOperations(User* user, int month, int year);
bool LoadOperation(User* user, const wxString& id); bool LoadOperation(User* user, const wxString& id);
double MetaAmount(const wxString& id); double MetaAmount(const wxString& id);
@ -158,6 +158,7 @@ public:
wxString getSharedAccountOwner(const wxString& account); wxString getSharedAccountOwner(const wxString& account);
std::map<wxString, double>* GetNotChecked(User* user, int month, int year); std::map<wxString, double>* GetNotChecked(User* user, int month, int year);
std::map<wxString, double>* GetVirtualAmount(User* user, int month, int year);
/* Database Update */ /* Database Update */
@ -169,7 +170,7 @@ private:
void CreateDatabase(); void CreateDatabase();
wxString HashPassword(const wxString& password); wxString HashPassword(const wxString& password);
void LinkOrUnlinkOperation(Operation& op); void LinkOrUnlinkOperation(User* user, Operation& op);
}; };
#endif #endif

View File

@ -55,7 +55,15 @@ static void Version_1_to_2(wxSQLite3Database& _db)
req = wxT("UPDATE account SET virtual='0'"); req = wxT("UPDATE account SET virtual='0'");
UPDATE_TABLE("1", "2", "5"); UPDATE_TABLE("1", "2", "5");
/* Operation */
req = wxT("ALTER TABLE operation ADD virtual CHAR(1)");
UPDATE_TABLE("1", "2", "6");
req = wxT("UPDATE operation SET virtual='0'");
UPDATE_TABLE("1", "2", "7");
} }
static update_func updates[] = { static update_func updates[] = {

View File

@ -36,6 +36,7 @@ public:
wxString transfert; wxString transfert;
wxString formula; wxString formula;
bool meta; bool meta;
bool _virtual;
std::vector<wxString> childs; std::vector<wxString> childs;
} ; } ;

View File

@ -168,6 +168,7 @@ wxLanguage User::GetLanguage()
void User::LinkOrUnlinkOperation(Operation& op) void User::LinkOrUnlinkOperation(Operation& op)
{ {
std::vector<Operation>::iterator it; std::vector<Operation>::iterator it;
Account account, account2;
// Not Linked // Not Linked
if (!op.transfert.Length()) if (!op.transfert.Length())
@ -177,6 +178,7 @@ void User::LinkOrUnlinkOperation(Operation& op)
if (it->id != op.id && it->transfert == op.id) if (it->id != op.id && it->transfert == op.id)
{ {
it->transfert = wxT(""); it->transfert = wxT("");
it->_virtual = false;
return; return;
} }
} }
@ -188,11 +190,16 @@ void User::LinkOrUnlinkOperation(Operation& op)
{ {
if (it->id != op.id && it->id == op.transfert) if (it->id != op.id && it->id == op.transfert)
{ {
account = GetAccount(it->account);
account2 = GetAccount(op.account);
it->transfert = op.id; it->transfert = op.id;
it->_virtual = account._virtual || account2._virtual;
op._virtual = account._virtual || account2._virtual;
return; return;
} }
} }
op.transfert = wxT(""); op.transfert = wxT("");
op._virtual = false;
} }
} }

View File

@ -434,6 +434,7 @@ void AccountPanel::UpdateStats()
unsigned int day; unsigned int day;
bool checkMode = _checkCheckMode->IsChecked(); bool checkMode = _checkCheckMode->IsChecked();
std::map<wxString, double>* notChecked = NULL; std::map<wxString, double>* notChecked = NULL;
std::map<wxString, double>* virtuals = NULL;
Account account; Account account;
Operation op; Operation op;
bool blocked_account ; bool blocked_account ;
@ -443,6 +444,7 @@ void AccountPanel::UpdateStats()
if (checkMode) if (checkMode)
{ {
notChecked = _kiss->GetNotChecked(_curMonth, _curYear); notChecked = _kiss->GetNotChecked(_curMonth, _curYear);
virtuals = _kiss->GetVirtualAmount(_curMonth, _curYear);
} }
day = _calendar->GetDate().GetDay()-1; day = _calendar->GetDate().GetDay()-1;
@ -454,6 +456,12 @@ void AccountPanel::UpdateStats()
{ {
curAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first]; curAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first];
finalAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first]; finalAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first];
if (virtuals)
{
curAccountAmount[doubleIt->first] += -(*virtuals)[doubleIt->first];
finalAccountAmount[doubleIt->first] += -(*virtuals)[doubleIt->first];
}
} }
for (it=_curOperations->begin(); it!=_curOperations->end(); it++) for (it=_curOperations->begin(); it!=_curOperations->end(); it++)
@ -547,7 +555,7 @@ void AccountPanel::UpdateStats()
else else
{ {
value = _accountsInitValues[accountIt->id]; value = _accountsInitValues[accountIt->id];
value2 = (*notChecked)[accountIt->id]; value2 = (*notChecked)[accountIt->id] + (*virtuals)[accountIt->id];
_accountsGrid->SetCellValue(i, ACCOUNT_INIT, wxString::Format(wxT("%.2lf (%.2lf)"), value, value-value2)); _accountsGrid->SetCellValue(i, ACCOUNT_INIT, wxString::Format(wxT("%.2lf (%.2lf)"), value, value-value2));
value = curAccountAmount[accountIt->id]; value = curAccountAmount[accountIt->id];
@ -563,6 +571,7 @@ void AccountPanel::UpdateStats()
_accountsGrid->AutoSizeColumn(ACCOUNT_FINAL, true); _accountsGrid->AutoSizeColumn(ACCOUNT_FINAL, true);
if (notChecked) delete notChecked; if (notChecked) delete notChecked;
if (virtuals) delete virtuals;
_statsGrid->AutoSizeColumn(1, true); _statsGrid->AutoSizeColumn(1, true);

View File

@ -19,7 +19,7 @@
#include "PreferencesPanel.h" #include "PreferencesPanel.h"
enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_DEFAULT, ACCOUNT_BLOCKED, ACCOUNT_DELETE, NUMBER_COLS_ACCOUNT}; enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_DEFAULT, ACCOUNT_VIRTUAL, ACCOUNT_BLOCKED, ACCOUNT_DELETE, NUMBER_COLS_ACCOUNT};
enum {CATEGORY_NAME, CATEGORY_BACKGROUND_COLOR, CATEGORY_FOREGROUND_COLOR, CATEGORY_FONT, CATEGORY_DELETE, NUMBER_COLS_CATEGORY}; enum {CATEGORY_NAME, CATEGORY_BACKGROUND_COLOR, CATEGORY_FOREGROUND_COLOR, CATEGORY_FONT, CATEGORY_DELETE, NUMBER_COLS_CATEGORY};
enum {CATEGORIES_GRID_ID=1, ACCOUNTS_GRID_ID, NAME_ID, CHANGE_NAME_ID, CHANGE_PASSWORD_ID, KILL_ME_ID, LANGUAGE_ID, enum {CATEGORIES_GRID_ID=1, ACCOUNTS_GRID_ID, NAME_ID, CHANGE_NAME_ID, CHANGE_PASSWORD_ID, KILL_ME_ID, LANGUAGE_ID,
@ -196,6 +196,7 @@ void PreferencesPanel::InitAccounts(User* user)
_accountsGrid->SetColLabelValue(ACCOUNT_NAME, _("Name")); _accountsGrid->SetColLabelValue(ACCOUNT_NAME, _("Name"));
_accountsGrid->SetColLabelValue(ACCOUNT_NUMBER, _("Number")); _accountsGrid->SetColLabelValue(ACCOUNT_NUMBER, _("Number"));
_accountsGrid->SetColLabelValue(ACCOUNT_DEFAULT, _("Default")); _accountsGrid->SetColLabelValue(ACCOUNT_DEFAULT, _("Default"));
_accountsGrid->SetColLabelValue(ACCOUNT_VIRTUAL, _("Virtual"));
_accountsGrid->SetColLabelValue(ACCOUNT_BLOCKED, _("Blocked")); _accountsGrid->SetColLabelValue(ACCOUNT_BLOCKED, _("Blocked"));
_accountsGrid->SetColLabelValue(ACCOUNT_DELETE, _("Delete")); _accountsGrid->SetColLabelValue(ACCOUNT_DELETE, _("Delete"));
_accountsGrid->SetDefaultCellFont(font); _accountsGrid->SetDefaultCellFont(font);
@ -224,6 +225,8 @@ void PreferencesPanel::AddAccount(int line, Account ac)
_accountsGrid->SetCellEditor(line, ACCOUNT_NUMBER, new wxGridCellStarEditor ()); _accountsGrid->SetCellEditor(line, ACCOUNT_NUMBER, new wxGridCellStarEditor ());
_accountsGrid->SetCellRenderer(line, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellRenderer(line, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(line, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellEditor(line, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellRenderer(line, ACCOUNT_VIRTUAL, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(line, ACCOUNT_VIRTUAL, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellRenderer(line, ACCOUNT_BLOCKED, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellRenderer(line, ACCOUNT_BLOCKED, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(line, ACCOUNT_BLOCKED, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellEditor(line, ACCOUNT_BLOCKED, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellRenderer(line, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellRenderer(line, ACCOUNT_DELETE, new wxGridCellBoolRenderer ());
@ -232,6 +235,7 @@ void PreferencesPanel::AddAccount(int line, Account ac)
_accountsGrid->SetCellValue(line, ACCOUNT_BLOCKED, (ac.blocked)?wxT("1"):wxT("0")); _accountsGrid->SetCellValue(line, ACCOUNT_BLOCKED, (ac.blocked)?wxT("1"):wxT("0"));
_accountsGrid->SetCellAlignment(line, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE); _accountsGrid->SetCellAlignment(line, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(line, ACCOUNT_VIRTUAL, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(line, ACCOUNT_BLOCKED, wxALIGN_CENTRE, wxALIGN_CENTRE); _accountsGrid->SetCellAlignment(line, ACCOUNT_BLOCKED, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(line, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); _accountsGrid->SetCellAlignment(line, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
@ -240,11 +244,13 @@ void PreferencesPanel::AddAccount(int line, Account ac)
_accountsGrid->SetReadOnly(line, ACCOUNT_NAME, true); _accountsGrid->SetReadOnly(line, ACCOUNT_NAME, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_NUMBER, true); _accountsGrid->SetReadOnly(line, ACCOUNT_NUMBER, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, true); _accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_VIRTUAL, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, true); _accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, true);
} }
else else
{ {
_accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, false); _accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, false);
_accountsGrid->SetReadOnly(line, ACCOUNT_VIRTUAL, false);
_accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, false); _accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, false);
_accountsGrid->SetReadOnly(line, ACCOUNT_DELETE, false); _accountsGrid->SetReadOnly(line, ACCOUNT_DELETE, false);
} }
@ -252,6 +258,7 @@ void PreferencesPanel::AddAccount(int line, Account ac)
else else
{ {
_accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, true); _accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_VIRTUAL, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, true); _accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, true);
_accountsGrid->SetReadOnly(line, ACCOUNT_DELETE, true); _accountsGrid->SetReadOnly(line, ACCOUNT_DELETE, true);
@ -402,6 +409,12 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
else else
new_account._default = false; new_account._default = false;
value = _accountsGrid->GetCellValue(row, ACCOUNT_VIRTUAL);
if (value.Length() && value != wxT("0"))
new_account._virtual = true;
else
new_account._virtual = false;
value = _accountsGrid->GetCellValue(row, ACCOUNT_BLOCKED); value = _accountsGrid->GetCellValue(row, ACCOUNT_BLOCKED);
if (value.Length() && value != wxT("0")) if (value.Length() && value != wxT("0"))
new_account.blocked = true; new_account.blocked = true;
@ -507,6 +520,7 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
new_account.shared = false; new_account.shared = false;
new_account.blocked = false; new_account.blocked = false;
new_account.is_owner = true; new_account.is_owner = true;
new_account._virtual = false;
AddAccount(row, new_account); AddAccount(row, new_account);
_kiss->AddAccount(new_account); _kiss->AddAccount(new_account);

View File

@ -901,6 +901,7 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
new_op.meta = cur_op.meta; new_op.meta = cur_op.meta;
new_op.parent = cur_op.parent; new_op.parent = cur_op.parent;
new_op.childs = cur_op.childs; new_op.childs = cur_op.childs;
new_op._virtual = cur_op._virtual;
if (cur_op.day != new_op.day) if (cur_op.day != new_op.day)
{ {
@ -929,6 +930,7 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
fix_op = true; fix_op = true;
new_op.fix_cost = true; new_op.fix_cost = true;
new_op.meta = false; new_op.meta = false;
new_op._virtual = false;
for(i=0; i<NUMBER_COLS_OPS; i++) for(i=0; i<NUMBER_COLS_OPS; i++)
{ {
@ -952,6 +954,7 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
new_op.meta = cur_op.meta; new_op.meta = cur_op.meta;
new_op.parent = cur_op.parent; new_op.parent = cur_op.parent;
new_op.childs = cur_op.childs; new_op.childs = cur_op.childs;
new_op._virtual = cur_op._virtual;
if (col == OP_DELETE) if (col == OP_DELETE)
{ {
@ -1026,6 +1029,7 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
fix_op = false; fix_op = false;
new_op.fix_cost = false; new_op.fix_cost = false;
new_op.meta = false; new_op.meta = false;
new_op._virtual = false;
for(i=0; i<NUMBER_COLS_OPS; i++) for(i=0; i<NUMBER_COLS_OPS; i++)
{ {

View File

@ -63,7 +63,7 @@ if (!isset($_SESSION["user"]))
echo "<input type=\"submit\" value=\"Connect\"/>\n"; echo "<input type=\"submit\" value=\"Connect\"/>\n";
echo "</form></center>\n"; echo "</form></center>\n";
echo "<br /><br />\n"; echo "<br /><br />\n";
echo "<center><a href=\"http://indefero.soutade.fr/p/kisscount\">KissCount</a> &copy; 2010 Grégory Soutadé</center>\n"; echo "<center><a href=\"http://indefero.soutade.fr/p/kisscount\">KissCount</a> &copy; 2010-2011 Grégory Soutadé</center>\n";
die(); die();
} }
else else