* Add early shared account support (Database schema has changed)

* Update TODO
This commit is contained in:
Grégory Soutadé 2010-10-20 20:54:23 +02:00
parent 5b5637f53a
commit d800f23029
9 changed files with 89 additions and 7 deletions

2
TODO
View File

@ -24,7 +24,7 @@ More translations
Import/Export module Import/Export module
Printing (maybe in html) Printing (maybe in html)
Refactor web view code Refactor web view code
Plugins ?
=============================================================== ===============================================================
Will not be implemented Will not be implemented

View File

@ -1,6 +1,7 @@
CREATE TABLE kisscount(db_version VARCHAR(20)); CREATE TABLE kisscount(db_version VARCHAR(20));
CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255), password VARCHAR(255)); CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255), password VARCHAR(255));
CREATE TABLE account(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), number VARCHAR(255), shared 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), default_account CHAR(1));
CREATE TABLE shared_account(id 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));
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)); 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));

View File

@ -167,7 +167,7 @@ void KissCount::DeleteAccount(Account& ac)
std::vector<Account>::iterator it; std::vector<Account>::iterator it;
int i; int i;
_db->DeleteAccount(ac); _db->DeleteAccount(_user, ac);
for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++) for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++)
if (it->id == ac.id) if (it->id == ac.id)
{ {
@ -176,6 +176,11 @@ void KissCount::DeleteAccount(Account& ac)
} }
} }
void KissCount::AddSharedAccount(Account& ac, const wxString& granted)
{
_db->AddSharedAccount(ac, granted);
}
wxString KissCount::AddCategory(Category& category) wxString KissCount::AddCategory(Category& category)
{ {
wxString id; wxString id;

View File

@ -61,6 +61,7 @@ public:
wxString AddAccount(Account& ac); wxString AddAccount(Account& ac);
void UpdateAccount(Account& ac); void UpdateAccount(Account& ac);
void DeleteAccount(Account& ac); void DeleteAccount(Account& ac);
void AddSharedAccount(Account& ac, const wxString& granted);
wxString AddCategory(Category& category); wxString AddCategory(Category& category);
void UpdateCategory(Category& category); void UpdateCategory(Category& category);

View File

@ -31,6 +31,7 @@ public:
wxString number; wxString number;
bool shared; bool shared;
bool _default; bool _default;
bool is_owner;
}; };
#endif #endif

View File

@ -272,6 +272,23 @@ User* Database::LoadUser(const wxString& name)
account.number = set.GetAsString(wxT("number")); account.number = set.GetAsString(wxT("number"));
account.shared = set.GetBool(wxT("shared")); account.shared = set.GetBool(wxT("shared"));
account._default = set.GetBool(wxT("default_account")); account._default = set.GetBool(wxT("default_account"));
account.is_owner = true;
user->_accounts.push_back(account);
}
set.Finalize();
req = wxT("SELECT * FROM account WHERE id IN (SELECT id FROM shared_account WHERE user='") + user->_id + wxT("') ORDER BY name ASC");
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;});
while (set.NextRow())
{
account.id = set.GetAsString(wxT("id"));
account.name = set.GetAsString(wxT("name"));
account.number = set.GetAsString(wxT("number"));
account.shared = set.GetBool(wxT("shared"));
account._default = set.GetBool(wxT("default_account"));
account.is_owner = false;
user->_accounts.push_back(account); user->_accounts.push_back(account);
} }
set.Finalize(); set.Finalize();
@ -677,13 +694,56 @@ void Database::UpdateAccount(Account& ac)
req += wxT(" WHERE id='") + ac.id + wxT("'"); req += wxT(" WHERE id='") + ac.id + wxT("'");
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
if (!ac.shared && ac.is_owner)
{
req = wxT("DELETE FROM shared_account WHERE id='") + ac.id + wxT("'");
EXECUTE_SQL_UPDATE(req, );
}
} }
void Database::DeleteAccount(Account& ac) void Database::DeleteAccount(User* user, Account& ac)
{ {
wxString req; wxString req;
wxSQLite3ResultSet set;
if (ac.is_owner)
{
if (ac.shared)
{
req = wxT("DELETE FROM shared_account WHERE id='") + ac.id + wxT("'");
EXECUTE_SQL_UPDATE(req, );
}
req = wxT("DELETE FROM account WHERE id='") + ac.id + wxT("'"); req = wxT("DELETE FROM account WHERE id='") + ac.id + wxT("'");
EXECUTE_SQL_UPDATE(req, );
}
else
{
req = wxT("DELETE FROM shared_account WHERE user='") + user->_id + wxT("'");
EXECUTE_SQL_UPDATE(req, );
req = wxT("SELECT COUNT(user) AS cnt FROM shared_account WHERE id='") + ac.id + wxT("'");
EXECUTE_SQL_QUERY(req, set, );
if (!set.GetInt(wxT("cnt")))
{
ac.shared = false;
UpdateAccount(ac);
}
}
}
void Database::AddSharedAccount(Account& ac, const wxString& granted)
{
wxString req;
req = wxT("INSERT INTO shared_account ('id', 'user') VALUES ('") + ac.id + wxT("', '") + granted + wxT("'");
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
} }

View File

@ -55,7 +55,8 @@ public:
wxString AddAccount(User* user, Account& ac); wxString AddAccount(User* user, Account& ac);
void UpdateAccount(Account& ac); void UpdateAccount(Account& ac);
void DeleteAccount(Account& ac); void DeleteAccount(User* user, Account& ac);
void AddSharedAccount(Account& ac, const wxString& granted);
wxString AddCategory(User* user, Category& category); wxString AddCategory(User* user, Category& category);
void UpdateCategory(Category& category); void UpdateCategory(Category& category);

View File

@ -377,7 +377,11 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year)
{ {
_accountsGrid->AppendRows(); _accountsGrid->AppendRows();
if (it->shared)
_accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number + wxT("*"));
else
_accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number); _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number);
_accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name); _accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name);
value = _kiss->GetAccountAmount(it->id, month, year); value = _kiss->GetAccountAmount(it->id, month, year);
_accountsGrid->SetCellEditor(curLine, ACCOUNT_INIT, new wxGridCellFloatEditor(-1, 2)); _accountsGrid->SetCellEditor(curLine, ACCOUNT_INIT, new wxGridCellFloatEditor(-1, 2));

View File

@ -172,6 +172,9 @@ void PreferencesPanel::InitAccounts(User* user)
_accountsGrid->AppendRows(); _accountsGrid->AppendRows();
_accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name); _accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name);
if (it->shared)
_accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number + wxT("*"));
else
_accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number); _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number);
_accountsGrid->SetCellRenderer(curLine, ACCOUNT_SHARED, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellRenderer(curLine, ACCOUNT_SHARED, new wxGridCellBoolRenderer ());
@ -186,6 +189,12 @@ void PreferencesPanel::InitAccounts(User* user)
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_SHARED, wxALIGN_CENTRE, wxALIGN_CENTRE); _accountsGrid->SetCellAlignment(curLine, ACCOUNT_SHARED, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE); _accountsGrid->SetCellAlignment(curLine, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); _accountsGrid->SetCellAlignment(curLine, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
if (!it->is_owner)
{
_accountsGrid->SetReadOnly(curLine, ACCOUNT_SHARED, true);
_accountsGrid->SetReadOnly(curLine, ACCOUNT_DEFAULT, true);
}
} }
_accountsGrid->AutoSizeColumns(true); _accountsGrid->AutoSizeColumns(true);