Early support of operation fusion and formula

This commit is contained in:
Grégory Soutadé 2010-08-06 21:20:19 +02:00
parent 8ad5e7d0ad
commit 8568c42339
3 changed files with 14 additions and 4 deletions

View File

@ -2,7 +2,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 account_amount(id INTEGER PRIMARY KEY, account REFERENCES account(id), year INTEGER, month INTEGER, amount FLOAT);
CREATE TABLE operation(id INTEGER PRIMARY KEY, 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));
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));
CREATE TABLE category(id INTEGER PRIMARY KEY, user REFERENCES user(id), parent REFERENCES category(id), name VARCHAR(255), color VARCHAR(255), font 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 ("1");

View File

@ -306,6 +306,7 @@ void Database::LoadYear(User* user, int year)
{
Operation op;
op.id = set.GetAsString(wxT("id"));
op.parent = set.GetAsString(wxT("parent"));
op.account = set.GetAsString(wxT("account"));
op.day = set.GetInt(wxT("day"));
op.month = set.GetInt(wxT("month"));
@ -315,6 +316,7 @@ void Database::LoadYear(User* user, int year)
op.category = set.GetAsString(wxT("category"));
op.fix_cost = set.GetBool(wxT("fix_cost"));
op.checked = set.GetBool(wxT("checked"));
op.formula = set.GetAsString(wxT("formula"));
(*user->_operations[op.year])[op.month].push_back(op);
}
@ -351,7 +353,8 @@ void Database::UpdateOperation(Operation& op)
{
wxString req;
req = wxT("UPDATE operation SET ") ;
req += wxT("account='") + op.account + wxT("'");
req += wxT("parent='") + op.parent + wxT("'");
req += wxT(", account='") + op.account + wxT("'");
req += wxT(", year='") + wxString::Format(wxT("%d"), op.year) + wxT("'");
req += wxT(", month='") + wxString::Format(wxT("%d"), op.month) + wxT("'");
req += wxT(", day='") + wxString::Format(wxT("%d"), op.day) + wxT("'");
@ -362,6 +365,7 @@ void Database::UpdateOperation(Operation& op)
req += wxT(", checked='1'");
else
req += wxT(", checked='0'");
req += wxT(", forumla='") + op.formula + wxT("'");
req += wxT(" WHERE id='") + op.id + wxT("'");
EXECUTE_SQL_UPDATE(req, );
@ -372,8 +376,9 @@ wxString Database::AddOperation(User* user, Operation& op)
wxString req, res;
wxSQLite3ResultSet set;
req = wxT("INSERT INTO operation ('user', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost') VALUES ('") ;
req = wxT("INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost', 'formula') VALUES ('") ;
req += user->_id + wxT("'");
req += wxT(", '") + op.parent + wxT("'");
req += wxT(", '") + op.account + wxT("'");
req += wxT(", '") + wxString::Format(wxT("%d"), op.year) + wxT("'");
req += wxT(", '") + wxString::Format(wxT("%d"), op.month) + wxT("'");
@ -385,12 +390,14 @@ wxString Database::AddOperation(User* user, Operation& op)
req += wxT(", '1'") ;
else
req += wxT(", '0'") ;
req += wxT(", '") + op.formula + wxT("'");
req += wxT(")");
EXECUTE_SQL_UPDATE(req, wxT("0"));
req = wxT("SELECT id FROM operation WHERE ");
req += wxT("user='") + user->_id + wxT("'");
req += wxT(" AND parent='") + op.parent + wxT("'");
req += wxT(" AND account='") + op.account + wxT("'");
req += wxT(" AND year='") + wxString::Format(wxT("%d"), op.year) + wxT("'");
req += wxT(" AND month='") + wxString::Format(wxT("%d"), op.month) + wxT("'");
@ -402,7 +409,8 @@ wxString Database::AddOperation(User* user, Operation& op)
req += wxT(" AND fix_cost='1'") ;
else
req += wxT(" AND fix_cost='0'") ;
req += wxT("ORDER BY ID DESC") ;
req += wxT(" AND formula='") + op.formula + wxT("'");
req += wxT("ORDER BY id DESC") ;
EXECUTE_SQL_QUERY(req , set, wxT("0"));

View File

@ -23,6 +23,7 @@ along with KissCount. If not, see <http://www.gnu.org/licenses/>.
class Operation {
public:
wxString id;
wxString parent;
unsigned int day;
unsigned int month;
unsigned int year;
@ -32,6 +33,7 @@ class Operation {
bool fix_cost;
wxString account;
bool checked;
wxString formula;
} ;
#endif