From 8568c423390e8b5bb9197f5631bed9eda80718ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Fri, 6 Aug 2010 21:20:19 +0200 Subject: [PATCH] Early support of operation fusion and formula --- init.sql | 2 +- src/model/Database.cpp | 14 +++++++++++--- src/model/Operation.h | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/init.sql b/init.sql index 923bc97..20dd6ef 100644 --- a/init.sql +++ b/init.sql @@ -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"); diff --git a/src/model/Database.cpp b/src/model/Database.cpp index 29c4465..0d6b33a 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -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")); diff --git a/src/model/Operation.h b/src/model/Operation.h index b4f45db..79d5c52 100644 --- a/src/model/Operation.h +++ b/src/model/Operation.h @@ -23,6 +23,7 @@ along with KissCount. If not, see . 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