* Add early shared account support (Database schema has changed)
* Update TODO
This commit is contained in:
parent
5b5637f53a
commit
d800f23029
2
TODO
2
TODO
|
@ -24,7 +24,7 @@ More translations
|
|||
Import/Export module
|
||||
Printing (maybe in html)
|
||||
Refactor web view code
|
||||
|
||||
Plugins ?
|
||||
|
||||
===============================================================
|
||||
Will not be implemented
|
||||
|
|
1
init.sql
1
init.sql
|
@ -1,6 +1,7 @@
|
|||
CREATE TABLE kisscount(db_version VARCHAR(20));
|
||||
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 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 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));
|
||||
|
|
|
@ -167,7 +167,7 @@ void KissCount::DeleteAccount(Account& ac)
|
|||
std::vector<Account>::iterator it;
|
||||
int i;
|
||||
|
||||
_db->DeleteAccount(ac);
|
||||
_db->DeleteAccount(_user, ac);
|
||||
for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++)
|
||||
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 id;
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
wxString AddAccount(Account& ac);
|
||||
void UpdateAccount(Account& ac);
|
||||
void DeleteAccount(Account& ac);
|
||||
void AddSharedAccount(Account& ac, const wxString& granted);
|
||||
|
||||
wxString AddCategory(Category& category);
|
||||
void UpdateCategory(Category& category);
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
wxString number;
|
||||
bool shared;
|
||||
bool _default;
|
||||
bool is_owner;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -272,6 +272,23 @@ User* Database::LoadUser(const wxString& name)
|
|||
account.number = set.GetAsString(wxT("number"));
|
||||
account.shared = set.GetBool(wxT("shared"));
|
||||
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);
|
||||
}
|
||||
set.Finalize();
|
||||
|
@ -677,13 +694,56 @@ void Database::UpdateAccount(Account& ac)
|
|||
req += wxT(" WHERE id='") + ac.id + wxT("'");
|
||||
|
||||
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;
|
||||
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("'");
|
||||
|
||||
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, );
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,8 @@ public:
|
|||
|
||||
wxString AddAccount(User* user, 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);
|
||||
void UpdateCategory(Category& category);
|
||||
|
|
|
@ -377,7 +377,11 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year)
|
|||
{
|
||||
_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_NAME, it->name);
|
||||
value = _kiss->GetAccountAmount(it->id, month, year);
|
||||
_accountsGrid->SetCellEditor(curLine, ACCOUNT_INIT, new wxGridCellFloatEditor(-1, 2));
|
||||
|
|
|
@ -172,6 +172,9 @@ void PreferencesPanel::InitAccounts(User* user)
|
|||
_accountsGrid->AppendRows();
|
||||
|
||||
_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->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_DEFAULT, 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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user