From 28c92d3b28f07b7cbd446c222309c30f4b3abe15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 24 Oct 2010 16:04:56 +0200 Subject: [PATCH] Add shared account management --- TODO | 6 +- init.sql | 2 +- ressources/po/french.mo | Bin 6932 -> 6942 bytes ressources/po/french.po | 164 +++++++++---------- ressources/po/kisscount.pot | 126 +++++++-------- src/controller/KissCount.cpp | 25 +++ src/controller/KissCount.h | 9 +- src/model/Database.cpp | 258 +++++++++++++++++++++++++----- src/model/Database.h | 10 ++ src/model/User.cpp | 29 +++- src/model/User.h | 9 +- src/model/model.h | 7 + src/view/PreferencesPanel.cpp | 132 +++++++++++---- src/view/PreferencesPanel.h | 6 + src/view/grid/GridAccount.cpp | 19 +-- src/view/wxGridCellStarEditor.cpp | 53 ++++++ src/view/wxGridCellStarEditor.h | 37 +++++ 17 files changed, 655 insertions(+), 237 deletions(-) create mode 100644 src/view/wxGridCellStarEditor.cpp create mode 100644 src/view/wxGridCellStarEditor.h diff --git a/TODO b/TODO index 490082e..dceed5c 100644 --- a/TODO +++ b/TODO @@ -8,7 +8,6 @@ Can type a letter with a comboboxes Windows version Need packaging Better build system for wxFreeChart (hacked by me) -Shared accounts Documentation (en) Cool for 0.1: @@ -36,5 +35,6 @@ Undo/redo =============================================================== BUGS -When we broke a transfert into a meta operation and re create it, -it's not taken in account by UpdateStats \ No newline at end of file +* When we broke a transfert into a meta operation and re create it, +it's not taken in account by UpdateStats + diff --git a/init.sql b/init.sql index 7475882..9584c1c 100644 --- a/init.sql +++ b/init.sql @@ -1,7 +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 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 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)); diff --git a/ressources/po/french.mo b/ressources/po/french.mo index 1787d5b2847aef32b4799914271582c9f7b83e06..fa3a7b4793148d74209bece0276d26e937c902fd 100644 GIT binary patch delta 1304 zcmXZbOGs2v9LMo<9dFKCS; z_tVf(=TJL7XT5~l`3+Qn+o&DfL*0o-sDRH<^Il*ZzCxW)d8`ySg8ID;hfzBmMO8e8yf*U$_u@3_Qbp=ZJCC6fHlYe@#a-BmB)u_%1f$IBEkks043p{}bw!&Rc(?)-9vr zhgj_MZ!s|%`g_%*Cd5$_no*Z!8>Vol9Y2Ojn8O5~M{VG~^)YJwb5z_}>ub~rze5%F zvC(Y*ALuIs3b=r}j7!#Es3ZT2S`b)UnpcGi6fMqIBpl~(J{0P3PUpKq86CJe%Cm=O zh^H@qEA++bE#@kJyKZu@|72hBR88CordyI*ytd7m;+=3$&`lm3=?=Tto|LSFP-61hYv94Ez3^3-h1Py?5?C=iK|h^PuN$&$DE} z-)Lqd5wl7>hh=yf19%Oq@H%e7ELPw{+>Fzxb+6p`JLF>@_}YM9u^gA3Mdu1C?`p(+ z3(^QgZQUwVf(BH87H0=4P#jfQCu&^+H9v(R+=E9wvjeDk)3v37o?spQIjqM;tj6!P zere$f1BV&VESlDjN-&J7^b~5RqZr1kNDdoE6_7)nP~JI%+vvZ+IQ~Et7$Lh(E{0my z?bFy!BZWI~02Sy4Dq+?+iK;k{3NY(j#0L7ysKV80f;!Z^PE?{kRNOQw?h&j(e~^Zb z`V4BvW6mq6o!>$QxP#ikebk+JgbMf^HSZ;+@Ga_u)=+W7jiujfks7TDb;ouhaePbA z(9U{MiPFw~=P^{JL#O~}u^n%^ejc0Y&!bM@GpfL%8~=yYVlj?G^SV&4CXKD+x6?F~ zcpSCEd#D}dkk@99@gUBjE>(C-Y3ET?!WL9vUAPbXkeqfKbw{R9JDx$sn?*v|du$-T zeWRhHTty`g@&dJk8dTtB+>Z(5W0&~S5l>(Yr%)T1Me$59DKuno_nHZbALq1Hb|#eLy?jXL24RAGxT>s=4@ zkpTr\n" "Language-Team: \n" @@ -20,16 +20,16 @@ msgstr "" # FIRST AUTHOR , YEAR. # #: src/view/StatsPanel.cpp:282 -#: src/view/PreferencesPanel.cpp:660 +#: src/view/PreferencesPanel.cpp:743 msgid " - " msgstr " - " #: src/view/UsersDialog.cpp:118 -#: src/view/PreferencesPanel.cpp:384 -#: src/view/PreferencesPanel.cpp:403 -#: src/view/PreferencesPanel.cpp:553 -#: src/view/PreferencesPanel.cpp:572 -#: src/view/PreferencesPanel.cpp:618 +#: src/view/PreferencesPanel.cpp:404 +#: src/view/PreferencesPanel.cpp:423 +#: src/view/PreferencesPanel.cpp:636 +#: src/view/PreferencesPanel.cpp:655 +#: src/view/PreferencesPanel.cpp:701 msgid " already exists" msgstr " existe déjà " @@ -41,11 +41,11 @@ msgstr " entrées trouvées" msgid " not found, aborting" msgstr " non trouvé, arrêt" -#: src/view/AccountPanel.cpp:705 +#: src/view/AccountPanel.cpp:709 msgid " operations ?" msgstr " opérations ?" -#: src/view/PreferencesPanel.cpp:667 +#: src/view/PreferencesPanel.cpp:750 msgid " profil ?" msgstr " profil ?" @@ -66,8 +66,8 @@ msgstr "A propos" msgid "Account" msgstr "Compte" -#: src/view/PreferencesPanel.cpp:384 -#: src/view/PreferencesPanel.cpp:403 +#: src/view/PreferencesPanel.cpp:404 +#: src/view/PreferencesPanel.cpp:423 msgid "Account " msgstr "Le compte " @@ -80,7 +80,7 @@ msgid "Account number" msgstr "Numéro de compte" #: src/view/StatsPanel.cpp:247 -#: src/view/PreferencesPanel.cpp:55 +#: src/view/PreferencesPanel.cpp:59 msgid "Accounts" msgstr "Comptes" @@ -92,22 +92,22 @@ msgstr "Montant min" msgid "Amount to" msgstr "Montant max" -#: src/view/PreferencesPanel.cpp:365 -#: src/view/PreferencesPanel.cpp:667 -#: src/view/AccountPanel.cpp:700 +#: src/view/PreferencesPanel.cpp:385 +#: src/view/PreferencesPanel.cpp:750 +#: src/view/AccountPanel.cpp:704 msgid "Are you sure want to delete " msgstr "Etes vous sûr de vouloir supprimer " -#: src/view/PreferencesPanel.cpp:534 -#: src/view/grid/GridAccount.cpp:743 +#: src/view/PreferencesPanel.cpp:617 +#: src/view/grid/GridAccount.cpp:745 msgid "Are you sure want to delete : \n" msgstr "Etes vous sûr de vouloir supprimer : \n" -#: src/view/PreferencesPanel.cpp:280 +#: src/view/PreferencesPanel.cpp:306 msgid "Ascending" msgstr "Croissant" -#: src/view/PreferencesPanel.cpp:221 +#: src/view/PreferencesPanel.cpp:247 msgid "Background color" msgstr "Couleur d'arrière plan" @@ -117,17 +117,17 @@ msgstr "Couleur d'arrière plan" msgid "Cancel" msgstr "Annuler" -#: src/view/grid/GridAccount.cpp:1067 -#: src/view/grid/GridAccount.cpp:1074 +#: src/view/grid/GridAccount.cpp:1129 +#: src/view/grid/GridAccount.cpp:1136 msgid "Cannot group these operations" msgstr "Impossible de grouper ces opérations" -#: src/view/grid/GridAccount.cpp:1202 -#: src/view/grid/GridAccount.cpp:1208 +#: src/view/grid/GridAccount.cpp:1263 +#: src/view/grid/GridAccount.cpp:1269 msgid "Cannot ungroup these operations" msgstr "Impossible de dégrouper ces opérations" -#: src/view/PreferencesPanel.cpp:56 +#: src/view/PreferencesPanel.cpp:60 msgid "Categories" msgstr "Catégories" @@ -136,16 +136,16 @@ msgstr "Catégories" msgid "Category" msgstr "Catégorie" -#: src/view/PreferencesPanel.cpp:553 -#: src/view/PreferencesPanel.cpp:572 +#: src/view/PreferencesPanel.cpp:636 +#: src/view/PreferencesPanel.cpp:655 msgid "Category " msgstr "Catégorie" -#: src/view/PreferencesPanel.cpp:72 +#: src/view/PreferencesPanel.cpp:77 msgid "Change Name" msgstr "Changer de nom" -#: src/view/PreferencesPanel.cpp:73 +#: src/view/PreferencesPanel.cpp:78 msgid "Change Password" msgstr "Changer le mot de passe" @@ -202,17 +202,17 @@ msgstr "Date max" msgid "Debit" msgstr "Débit" -#: src/view/PreferencesPanel.cpp:166 +#: src/view/PreferencesPanel.cpp:186 msgid "Default" msgstr "Défaut" -#: src/view/PreferencesPanel.cpp:167 -#: src/view/PreferencesPanel.cpp:224 -#: src/view/AccountPanel.cpp:559 +#: src/view/PreferencesPanel.cpp:187 +#: src/view/PreferencesPanel.cpp:250 +#: src/view/AccountPanel.cpp:563 msgid "Delete" msgstr "Supprimer" -#: src/view/PreferencesPanel.cpp:281 +#: src/view/PreferencesPanel.cpp:307 msgid "Descending" msgstr "Décroissant" @@ -227,21 +227,21 @@ msgstr "Description" #: src/view/SearchPanel.cpp:145 #: src/view/SearchPanel.cpp:159 #: src/view/SearchPanel.cpp:170 -#: src/view/PreferencesPanel.cpp:361 -#: src/view/PreferencesPanel.cpp:384 -#: src/view/PreferencesPanel.cpp:403 -#: src/view/PreferencesPanel.cpp:553 -#: src/view/PreferencesPanel.cpp:572 -#: src/view/PreferencesPanel.cpp:612 -#: src/view/PreferencesPanel.cpp:618 +#: src/view/PreferencesPanel.cpp:381 +#: src/view/PreferencesPanel.cpp:404 +#: src/view/PreferencesPanel.cpp:423 +#: src/view/PreferencesPanel.cpp:636 +#: src/view/PreferencesPanel.cpp:655 +#: src/view/PreferencesPanel.cpp:695 +#: src/view/PreferencesPanel.cpp:701 #: src/view/PasswordDialog.cpp:72 #: src/view/PasswordDialog.cpp:78 -#: src/view/AccountPanel.cpp:696 -#: src/view/grid/GridAccount.cpp:1067 -#: src/view/grid/GridAccount.cpp:1074 -#: src/view/grid/GridAccount.cpp:1202 -#: src/view/grid/GridAccount.cpp:1208 -#: src/view/grid/wxGridCellFormulaEditor.cpp:68 +#: src/view/AccountPanel.cpp:700 +#: src/view/grid/GridAccount.cpp:1129 +#: src/view/grid/GridAccount.cpp:1136 +#: src/view/grid/GridAccount.cpp:1263 +#: src/view/grid/GridAccount.cpp:1269 +#: src/view/grid/wxGridCellFormulaEditor.cpp:69 #: src/model/Database.cpp:38 #: src/model/Database.cpp:55 #: src/model/Database.cpp:95 @@ -262,16 +262,16 @@ msgid "Final value" msgstr "Valeur finale" #: src/view/grid/GridAccount.cpp:300 -#: src/model/Database.cpp:312 -#: src/controller/KissCount.cpp:305 +#: src/model/Database.cpp:329 +#: src/controller/KissCount.cpp:335 msgid "Fix" msgstr "Fixe" -#: src/view/PreferencesPanel.cpp:223 +#: src/view/PreferencesPanel.cpp:249 msgid "Font" msgstr "Police" -#: src/view/PreferencesPanel.cpp:222 +#: src/view/PreferencesPanel.cpp:248 msgid "Foreground color" msgstr "Couleur d'avant plan" @@ -284,11 +284,11 @@ msgid "From " msgstr "A partir de " #: src/view/GenerateDialog.cpp:31 -#: src/view/AccountPanel.cpp:556 +#: src/view/AccountPanel.cpp:560 msgid "Generate month" msgstr "Générer mois" -#: src/controller/KissCount.cpp:307 +#: src/controller/KissCount.cpp:337 msgid "Groceries" msgstr "Courses" @@ -296,7 +296,7 @@ msgstr "Courses" msgid "Group" msgstr "Grouper" -#: src/controller/KissCount.cpp:309 +#: src/controller/KissCount.cpp:339 msgid "Hobbies" msgstr "Loisirs" @@ -320,11 +320,11 @@ msgstr "Montant max invalide" msgid "Invalid date range" msgstr "Intervalle de temps invalide" -#: src/view/grid/wxGridCellFormulaEditor.cpp:68 +#: src/view/grid/wxGridCellFormulaEditor.cpp:69 msgid "Invalid formula !" msgstr "Formule invalide !" -#: src/view/PreferencesPanel.cpp:612 +#: src/view/PreferencesPanel.cpp:695 msgid "Invalid name" msgstr "Nom invalide" @@ -340,43 +340,43 @@ msgstr "Mot de passe invalide" msgid "Invalide date range" msgstr "Intervalle de temps invalide" -#: src/view/PreferencesPanel.cpp:361 +#: src/view/PreferencesPanel.cpp:381 msgid "It must be at least one account !" msgstr "Il doit y avoir au moins un compte !" -#: src/view/AccountPanel.cpp:696 +#: src/view/AccountPanel.cpp:700 msgid "It must be at least one month !" msgstr "Il doit rester au mois un mois" -#: src/view/PreferencesPanel.cpp:74 +#: src/view/PreferencesPanel.cpp:79 msgid "Kill me" msgstr "Kill me" #: src/view/StatsPanel.cpp:302 -#: src/view/PreferencesPanel.cpp:652 -#: src/view/PreferencesPanel.cpp:655 +#: src/view/PreferencesPanel.cpp:735 +#: src/view/PreferencesPanel.cpp:738 msgid "KissCount" msgstr "KissCount" -#: src/view/PreferencesPanel.cpp:57 +#: src/view/PreferencesPanel.cpp:61 msgid "Language" msgstr "Langue" -#: src/view/PreferencesPanel.cpp:655 +#: src/view/PreferencesPanel.cpp:738 msgid "Language not changed" msgstr "Langue non changée" -#: src/view/PreferencesPanel.cpp:652 +#: src/view/PreferencesPanel.cpp:735 msgid "Language successfully changed, please go to another panel" msgstr "Langue changée, allez sur un autre panneau pour rendre le changement effectif" -#: src/view/PreferencesPanel.cpp:66 -#: src/view/PreferencesPanel.cpp:163 -#: src/view/PreferencesPanel.cpp:220 +#: src/view/PreferencesPanel.cpp:71 +#: src/view/PreferencesPanel.cpp:184 +#: src/view/PreferencesPanel.cpp:246 msgid "Name" msgstr "Nom" -#: src/view/PreferencesPanel.cpp:624 +#: src/view/PreferencesPanel.cpp:707 msgid "Name changed" msgstr "Nom changé" @@ -401,7 +401,7 @@ msgstr "" msgid "No entry found" msgstr "Pas d'entrée trouvée" -#: src/view/PreferencesPanel.cpp:164 +#: src/view/PreferencesPanel.cpp:185 msgid "Number" msgstr "Numéro de compte" @@ -415,11 +415,11 @@ msgstr "OK" msgid "Old password " msgstr "Ancien mot de passe" -#: src/controller/KissCount.cpp:311 +#: src/controller/KissCount.cpp:341 msgid "Operating exepense" msgstr "Frais de fonctionnement" -#: src/view/PreferencesPanel.cpp:58 +#: src/view/PreferencesPanel.cpp:62 msgid "Operation order" msgstr "Ordre des opérations" @@ -427,7 +427,7 @@ msgstr "Ordre des opérations" msgid "Operations" msgstr "Opérations" -#: src/controller/KissCount.cpp:315 +#: src/controller/KissCount.cpp:345 msgid "Other" msgstr "Autres" @@ -453,8 +453,8 @@ msgstr "" msgid "Please retype new password" msgstr "Re entrez le mot de passe" -#: src/view/PreferencesPanel.cpp:626 -#: src/view/PreferencesPanel.cpp:660 +#: src/view/PreferencesPanel.cpp:709 +#: src/view/PreferencesPanel.cpp:743 #: src/view/ButtonPanel.cpp:72 msgid "Preferences" msgstr "Préférences" @@ -486,9 +486,9 @@ msgstr "Chercher" msgid "Serie 1" msgstr "Série 1" -#: src/view/PreferencesPanel.cpp:165 -msgid "Shared" -msgstr "Partagé" +#: src/view/PreferencesPanel.cpp:63 +msgid "Shared with" +msgstr "Partagé avec" #: src/view/StatsPanel.cpp:282 #: src/view/ButtonPanel.cpp:70 @@ -522,13 +522,13 @@ msgstr "Dégrouper" msgid "Unable to open Database" msgstr "Impossible d'ouvrir la base de données" -#: src/controller/KissCount.cpp:313 +#: src/controller/KissCount.cpp:343 msgid "Unexpected" msgstr "Exceptionnel" -#: src/model/User.cpp:46 -#: src/model/User.cpp:61 -#: src/model/User.cpp:92 +#: src/model/User.cpp:52 +#: src/model/User.cpp:72 +#: src/model/User.cpp:112 msgid "Unknown" msgstr "Inconnu" @@ -536,13 +536,13 @@ msgstr "Inconnu" msgid "Update failed !\n" msgstr "La mise à jour à échouée !\n" -#: src/view/PreferencesPanel.cpp:54 +#: src/view/PreferencesPanel.cpp:58 msgid "User" msgstr "Utilisateur" #: src/view/UsersDialog.cpp:38 #: src/view/UsersDialog.cpp:118 -#: src/view/PreferencesPanel.cpp:618 +#: src/view/PreferencesPanel.cpp:701 msgid "User " msgstr "Utilisateur" diff --git a/ressources/po/kisscount.pot b/ressources/po/kisscount.pot index 1005abc..17e1888 100644 --- a/ressources/po/kisscount.pot +++ b/ressources/po/kisscount.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-10-14 20:46+0200\n" +"POT-Creation-Date: 2010-10-24 16:03+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,13 +17,13 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: src/view/StatsPanel.cpp:282 src/view/PreferencesPanel.cpp:660 +#: src/view/StatsPanel.cpp:282 src/view/PreferencesPanel.cpp:743 msgid " - " msgstr "" -#: src/view/UsersDialog.cpp:118 src/view/PreferencesPanel.cpp:384 -#: src/view/PreferencesPanel.cpp:403 src/view/PreferencesPanel.cpp:553 -#: src/view/PreferencesPanel.cpp:572 src/view/PreferencesPanel.cpp:618 +#: src/view/UsersDialog.cpp:118 src/view/PreferencesPanel.cpp:404 +#: src/view/PreferencesPanel.cpp:423 src/view/PreferencesPanel.cpp:636 +#: src/view/PreferencesPanel.cpp:655 src/view/PreferencesPanel.cpp:701 msgid " already exists" msgstr "" @@ -35,11 +35,11 @@ msgstr "" msgid " not found, aborting" msgstr "" -#: src/view/AccountPanel.cpp:705 +#: src/view/AccountPanel.cpp:709 msgid " operations ?" msgstr "" -#: src/view/PreferencesPanel.cpp:667 +#: src/view/PreferencesPanel.cpp:750 msgid " profil ?" msgstr "" @@ -59,7 +59,7 @@ msgstr "" msgid "Account" msgstr "" -#: src/view/PreferencesPanel.cpp:384 src/view/PreferencesPanel.cpp:403 +#: src/view/PreferencesPanel.cpp:404 src/view/PreferencesPanel.cpp:423 msgid "Account " msgstr "" @@ -71,7 +71,7 @@ msgstr "" msgid "Account number" msgstr "" -#: src/view/StatsPanel.cpp:247 src/view/PreferencesPanel.cpp:55 +#: src/view/StatsPanel.cpp:247 src/view/PreferencesPanel.cpp:59 msgid "Accounts" msgstr "" @@ -83,20 +83,20 @@ msgstr "" msgid "Amount to" msgstr "" -#: src/view/PreferencesPanel.cpp:365 src/view/PreferencesPanel.cpp:667 -#: src/view/AccountPanel.cpp:700 +#: src/view/PreferencesPanel.cpp:385 src/view/PreferencesPanel.cpp:750 +#: src/view/AccountPanel.cpp:704 msgid "Are you sure want to delete " msgstr "" -#: src/view/PreferencesPanel.cpp:534 src/view/grid/GridAccount.cpp:743 +#: src/view/PreferencesPanel.cpp:617 src/view/grid/GridAccount.cpp:745 msgid "Are you sure want to delete : \n" msgstr "" -#: src/view/PreferencesPanel.cpp:280 +#: src/view/PreferencesPanel.cpp:306 msgid "Ascending" msgstr "" -#: src/view/PreferencesPanel.cpp:221 +#: src/view/PreferencesPanel.cpp:247 msgid "Background color" msgstr "" @@ -105,15 +105,15 @@ msgstr "" msgid "Cancel" msgstr "" -#: src/view/grid/GridAccount.cpp:1067 src/view/grid/GridAccount.cpp:1074 +#: src/view/grid/GridAccount.cpp:1129 src/view/grid/GridAccount.cpp:1136 msgid "Cannot group these operations" msgstr "" -#: src/view/grid/GridAccount.cpp:1202 src/view/grid/GridAccount.cpp:1208 +#: src/view/grid/GridAccount.cpp:1263 src/view/grid/GridAccount.cpp:1269 msgid "Cannot ungroup these operations" msgstr "" -#: src/view/PreferencesPanel.cpp:56 +#: src/view/PreferencesPanel.cpp:60 msgid "Categories" msgstr "" @@ -121,15 +121,15 @@ msgstr "" msgid "Category" msgstr "" -#: src/view/PreferencesPanel.cpp:553 src/view/PreferencesPanel.cpp:572 +#: src/view/PreferencesPanel.cpp:636 src/view/PreferencesPanel.cpp:655 msgid "Category " msgstr "" -#: src/view/PreferencesPanel.cpp:72 +#: src/view/PreferencesPanel.cpp:77 msgid "Change Name" msgstr "" -#: src/view/PreferencesPanel.cpp:73 +#: src/view/PreferencesPanel.cpp:78 msgid "Change Password" msgstr "" @@ -185,16 +185,16 @@ msgstr "" msgid "Debit" msgstr "" -#: src/view/PreferencesPanel.cpp:166 +#: src/view/PreferencesPanel.cpp:186 msgid "Default" msgstr "" -#: src/view/PreferencesPanel.cpp:167 src/view/PreferencesPanel.cpp:224 -#: src/view/AccountPanel.cpp:559 +#: src/view/PreferencesPanel.cpp:187 src/view/PreferencesPanel.cpp:250 +#: src/view/AccountPanel.cpp:563 msgid "Delete" msgstr "" -#: src/view/PreferencesPanel.cpp:281 +#: src/view/PreferencesPanel.cpp:307 msgid "Descending" msgstr "" @@ -205,14 +205,14 @@ msgstr "" #: src/view/UsersDialog.cpp:88 src/view/UsersDialog.cpp:118 #: src/view/SearchPanel.cpp:135 src/view/SearchPanel.cpp:145 #: src/view/SearchPanel.cpp:159 src/view/SearchPanel.cpp:170 -#: src/view/PreferencesPanel.cpp:361 src/view/PreferencesPanel.cpp:384 -#: src/view/PreferencesPanel.cpp:403 src/view/PreferencesPanel.cpp:553 -#: src/view/PreferencesPanel.cpp:572 src/view/PreferencesPanel.cpp:612 -#: src/view/PreferencesPanel.cpp:618 src/view/PasswordDialog.cpp:72 -#: src/view/PasswordDialog.cpp:78 src/view/AccountPanel.cpp:696 -#: src/view/grid/GridAccount.cpp:1067 src/view/grid/GridAccount.cpp:1074 -#: src/view/grid/GridAccount.cpp:1202 src/view/grid/GridAccount.cpp:1208 -#: src/view/grid/wxGridCellFormulaEditor.cpp:68 src/model/Database.cpp:38 +#: src/view/PreferencesPanel.cpp:381 src/view/PreferencesPanel.cpp:404 +#: src/view/PreferencesPanel.cpp:423 src/view/PreferencesPanel.cpp:636 +#: src/view/PreferencesPanel.cpp:655 src/view/PreferencesPanel.cpp:695 +#: src/view/PreferencesPanel.cpp:701 src/view/PasswordDialog.cpp:72 +#: src/view/PasswordDialog.cpp:78 src/view/AccountPanel.cpp:700 +#: src/view/grid/GridAccount.cpp:1129 src/view/grid/GridAccount.cpp:1136 +#: src/view/grid/GridAccount.cpp:1263 src/view/grid/GridAccount.cpp:1269 +#: src/view/grid/wxGridCellFormulaEditor.cpp:69 src/model/Database.cpp:38 #: src/model/Database.cpp:55 src/model/Database.cpp:95 #: src/model/Database.cpp:102 src/model/Database.cpp:120 #: src/model/Database.cpp:147 src/model/Database.cpp:155 @@ -228,16 +228,16 @@ msgstr "" msgid "Final value" msgstr "" -#: src/view/grid/GridAccount.cpp:300 src/model/Database.cpp:312 -#: src/controller/KissCount.cpp:305 +#: src/view/grid/GridAccount.cpp:300 src/model/Database.cpp:329 +#: src/controller/KissCount.cpp:335 msgid "Fix" msgstr "" -#: src/view/PreferencesPanel.cpp:223 +#: src/view/PreferencesPanel.cpp:249 msgid "Font" msgstr "" -#: src/view/PreferencesPanel.cpp:222 +#: src/view/PreferencesPanel.cpp:248 msgid "Foreground color" msgstr "" @@ -249,11 +249,11 @@ msgstr "" msgid "From " msgstr "" -#: src/view/GenerateDialog.cpp:31 src/view/AccountPanel.cpp:556 +#: src/view/GenerateDialog.cpp:31 src/view/AccountPanel.cpp:560 msgid "Generate month" msgstr "" -#: src/controller/KissCount.cpp:307 +#: src/controller/KissCount.cpp:337 msgid "Groceries" msgstr "" @@ -261,7 +261,7 @@ msgstr "" msgid "Group" msgstr "" -#: src/controller/KissCount.cpp:309 +#: src/controller/KissCount.cpp:339 msgid "Hobbies" msgstr "" @@ -285,11 +285,11 @@ msgstr "" msgid "Invalid date range" msgstr "" -#: src/view/grid/wxGridCellFormulaEditor.cpp:68 +#: src/view/grid/wxGridCellFormulaEditor.cpp:69 msgid "Invalid formula !" msgstr "" -#: src/view/PreferencesPanel.cpp:612 +#: src/view/PreferencesPanel.cpp:695 msgid "Invalid name" msgstr "" @@ -305,41 +305,41 @@ msgstr "" msgid "Invalide date range" msgstr "" -#: src/view/PreferencesPanel.cpp:361 +#: src/view/PreferencesPanel.cpp:381 msgid "It must be at least one account !" msgstr "" -#: src/view/AccountPanel.cpp:696 +#: src/view/AccountPanel.cpp:700 msgid "It must be at least one month !" msgstr "" -#: src/view/PreferencesPanel.cpp:74 +#: src/view/PreferencesPanel.cpp:79 msgid "Kill me" msgstr "" -#: src/view/StatsPanel.cpp:302 src/view/PreferencesPanel.cpp:652 -#: src/view/PreferencesPanel.cpp:655 +#: src/view/StatsPanel.cpp:302 src/view/PreferencesPanel.cpp:735 +#: src/view/PreferencesPanel.cpp:738 msgid "KissCount" msgstr "" -#: src/view/PreferencesPanel.cpp:57 +#: src/view/PreferencesPanel.cpp:61 msgid "Language" msgstr "" -#: src/view/PreferencesPanel.cpp:655 +#: src/view/PreferencesPanel.cpp:738 msgid "Language not changed" msgstr "" -#: src/view/PreferencesPanel.cpp:652 +#: src/view/PreferencesPanel.cpp:735 msgid "Language successfully changed, please go to another panel" msgstr "" -#: src/view/PreferencesPanel.cpp:66 src/view/PreferencesPanel.cpp:163 -#: src/view/PreferencesPanel.cpp:220 +#: src/view/PreferencesPanel.cpp:71 src/view/PreferencesPanel.cpp:184 +#: src/view/PreferencesPanel.cpp:246 msgid "Name" msgstr "" -#: src/view/PreferencesPanel.cpp:624 +#: src/view/PreferencesPanel.cpp:707 msgid "Name changed" msgstr "" @@ -361,7 +361,7 @@ msgstr "" msgid "No entry found" msgstr "" -#: src/view/PreferencesPanel.cpp:164 +#: src/view/PreferencesPanel.cpp:185 msgid "Number" msgstr "" @@ -374,11 +374,11 @@ msgstr "" msgid "Old password " msgstr "" -#: src/controller/KissCount.cpp:311 +#: src/controller/KissCount.cpp:341 msgid "Operating exepense" msgstr "" -#: src/view/PreferencesPanel.cpp:58 +#: src/view/PreferencesPanel.cpp:62 msgid "Operation order" msgstr "" @@ -386,7 +386,7 @@ msgstr "" msgid "Operations" msgstr "" -#: src/controller/KissCount.cpp:315 +#: src/controller/KissCount.cpp:345 msgid "Other" msgstr "" @@ -409,7 +409,7 @@ msgstr "" msgid "Please retype new password" msgstr "" -#: src/view/PreferencesPanel.cpp:626 src/view/PreferencesPanel.cpp:660 +#: src/view/PreferencesPanel.cpp:709 src/view/PreferencesPanel.cpp:743 #: src/view/ButtonPanel.cpp:72 msgid "Preferences" msgstr "" @@ -439,8 +439,8 @@ msgstr "" msgid "Serie 1" msgstr "" -#: src/view/PreferencesPanel.cpp:165 -msgid "Shared" +#: src/view/PreferencesPanel.cpp:63 +msgid "Shared with" msgstr "" #: src/view/StatsPanel.cpp:282 src/view/ButtonPanel.cpp:70 @@ -472,11 +472,11 @@ msgstr "" msgid "Unable to open Database" msgstr "" -#: src/controller/KissCount.cpp:313 +#: src/controller/KissCount.cpp:343 msgid "Unexpected" msgstr "" -#: src/model/User.cpp:46 src/model/User.cpp:61 src/model/User.cpp:92 +#: src/model/User.cpp:52 src/model/User.cpp:72 src/model/User.cpp:112 msgid "Unknown" msgstr "" @@ -484,12 +484,12 @@ msgstr "" msgid "Update failed !\n" msgstr "" -#: src/view/PreferencesPanel.cpp:54 +#: src/view/PreferencesPanel.cpp:58 msgid "User" msgstr "" #: src/view/UsersDialog.cpp:38 src/view/UsersDialog.cpp:118 -#: src/view/PreferencesPanel.cpp:618 +#: src/view/PreferencesPanel.cpp:701 msgid "User " msgstr "" diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 64c505b..671c23b 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -138,6 +138,16 @@ void KissCount::DeleteOperations(int month, int year) } } +double KissCount::MetaAmount(const wxString& id) +{ + return _db->MetaAmount(id); +} + +double KissCount::MetaPositiveAmount(const wxString& id) +{ + return _db->MetaPositiveAmount(id); +} + void KissCount::SetAccountAmount(int month, int year, const wxString& accountId, double amount) { _db->SetAccountAmount(month, year, accountId, amount); @@ -181,6 +191,21 @@ void KissCount::AddSharedAccount(Account& ac, const wxString& granted) _db->AddSharedAccount(ac, granted); } +void KissCount::RemoveSharedAccount(Account& ac, const wxString& granted) +{ + _db->RemoveSharedAccount(ac, granted); +} + +std::map KissCount::getSharedAccountOwners(const wxString& account) +{ + return _db->getSharedAccountOwners(account); +} + +wxString KissCount::getSharedAccountOwner(const wxString& account) +{ + return _db->getSharedAccountOwner(account); +} + wxString KissCount::AddCategory(Category& category) { wxString id; diff --git a/src/controller/KissCount.h b/src/controller/KissCount.h index b40fda1..093bfb9 100644 --- a/src/controller/KissCount.h +++ b/src/controller/KissCount.h @@ -55,6 +55,8 @@ public: void UpdateOperation(Operation& op); void DeleteOperation(Operation& op); void DeleteOperations(int month, int year); + double MetaAmount(const wxString& id); + double MetaPositiveAmount(const wxString& id); double GetAccountAmount(const wxString& id, int month, int year); void SetAccountAmount(int month, int year, const wxString& accountId, double value); @@ -62,6 +64,9 @@ public: void UpdateAccount(Account& ac); void DeleteAccount(Account& ac); void AddSharedAccount(Account& ac, const wxString& granted); + void RemoveSharedAccount(Account& ac, const wxString& granted); + std::map getSharedAccountOwners(const wxString& account); + wxString getSharedAccountOwner(const wxString& account); wxString AddCategory(Category& category); void UpdateCategory(Category& category); @@ -87,8 +92,8 @@ public: std::map* GetNotChecked(int month, int year); - wxFont ExtractFont(wxString strFont); - wxString CompactFont(const wxFont& font); + static wxFont ExtractFont(wxString strFont); + static wxString CompactFont(const wxFont& font); private: wxUI* _wxUI; diff --git a/src/model/Database.cpp b/src/model/Database.cpp index e4e19d8..5b505fb 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -211,7 +211,7 @@ std::list Database::GetUsers() while (set.NextRow()) { - res.push_front(set.GetAsString(0)); + res.push_back(set.GetAsString(0)); } set.Finalize(); @@ -251,7 +251,7 @@ User* Database::LoadUser(const wxString& name) if (!set.NextRow()) return NULL; - user = new User(); + user = new User(this); user->_id = set.GetAsString(wxT("id")); user->_name = set.GetAsString(wxT("name")); @@ -277,7 +277,7 @@ User* Database::LoadUser(const wxString& name) } set.Finalize(); - req = wxT("SELECT * FROM account WHERE id IN (SELECT id FROM shared_account WHERE user='") + user->_id + wxT("') ORDER BY name ASC"); + req = wxT("SELECT * FROM account WHERE id IN (SELECT account FROM shared_account WHERE user='") + user->_id + wxT("') ORDER BY name ASC"); EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;}); @@ -621,7 +621,103 @@ void Database::DeleteOperations(User* user, int month, int year) req += wxT(" AND month='") + wxString::Format(wxT("%d"), month) + wxT("'"); EXECUTE_SQL_UPDATE(req, ); +} +bool Database::LoadOperation(User* user, const wxString& id) +{ + wxSQLite3ResultSet set; + wxString req; + bool ret = false; + std::vector::iterator it; + + req = wxT("SELECT * FROM operation WHERE id='") + id + wxT("'"); + + EXECUTE_SQL_QUERY(req, set, false); + + if (set.NextRow()) + { + 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")); + op.year = set.GetInt(wxT("year")); + op.amount = set.GetDouble(wxT("amount")); + op.description = set.GetAsString(wxT("description")); + op.category = set.GetAsString(wxT("category")); + op.fix_cost = set.GetBool(wxT("fix_cost")); + op.checked = set.GetBool(wxT("checked")); + op.transfert = set.GetAsString(wxT("transfert")); + op.formula = set.GetAsString(wxT("formula")); + op.meta = set.GetBool(wxT("meta")); + for (it = (*user->_operations[op.year])[op.month].begin(); + it != (*user->_operations[op.year])[op.month].end(); + it++) + { + if (!op.fix_cost && it->fix_cost) continue; + if (op.fix_cost && !it->fix_cost) + { + it--; + break; + } + if (it->day > op.day) + { + it--; + break; + } + } + if (it == (*user->_operations[op.year])[op.month].end()) + (*user->_operations[op.year])[op.month].push_back(op); + else + (*user->_operations[op.year])[op.month].insert(it, op); + // if (op.fix_cost) + // else + // (*user->_operations[op.year])[op.month].push_back(op); + ret = true; + } + + set.Finalize(); + + return ret; +} + +// We may not have access to all operations if we have a shared account +double Database::MetaAmount(const wxString& id) +{ + wxSQLite3ResultSet set; + wxString req; + double res = 0.0; + + req = wxT("SELECT SUM(amount) as amount FROM operation WHERE parent='") + id + wxT("'"); + + EXECUTE_SQL_QUERY(req, set, false); + + if (set.NextRow()) + res = set.GetDouble(wxT("amount")); + + set.Finalize(); + + return res; +} + +// Idem +double Database::MetaPositiveAmount(const wxString& id) +{ + wxSQLite3ResultSet set; + wxString req; + double res = 0.0; + + req = wxT("SELECT SUM(amount) as amount FROM operation WHERE amount > 0 AND parent='") + id + wxT("'"); + + EXECUTE_SQL_QUERY(req, set, false); + + if (set.NextRow()) + res = set.GetDouble(wxT("amount")); + + set.Finalize(); + + return res; } void Database::SetAccountAmount(int month, int year, const wxString& accountId, double amount) @@ -697,7 +793,7 @@ void Database::UpdateAccount(Account& ac) if (!ac.shared && ac.is_owner) { - req = wxT("DELETE FROM shared_account WHERE id='") + ac.id + wxT("'"); + req = wxT("DELETE FROM shared_account WHERE account='") + ac.id + wxT("'"); EXECUTE_SQL_UPDATE(req, ); } @@ -706,45 +802,66 @@ void Database::UpdateAccount(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("'"); + req = wxT("DELETE FROM shared_account WHERE account='") + 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("'"); + + req = wxT("DELETE FROM account_amount WHERE account='") + ac.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); - } } + else + RemoveSharedAccount(ac, user->_id); } void Database::AddSharedAccount(Account& ac, const wxString& granted) { wxString req; + wxSQLite3ResultSet set; - req = wxT("INSERT INTO shared_account ('id', 'user') VALUES ('") + ac.id + wxT("', '") + granted + wxT("'"); + req = wxT("SELECT id FROM user WHERE name='") + granted + wxT("'"); + + EXECUTE_SQL_QUERY(req, set, ); + + req = wxT("INSERT INTO shared_account ('account', 'user') VALUES ('") + ac.id + wxT("', '") + set.GetAsString(wxT("id")) + wxT("')"); EXECUTE_SQL_UPDATE(req, ); + + if (!ac.shared) + { + ac.shared = true; + UpdateAccount(ac); + } +} + +void Database::RemoveSharedAccount(Account& ac, const wxString& granted) +{ + wxString req; + wxSQLite3ResultSet set; + + req = wxT("DELETE FROM shared_account WHERE user='") + granted + wxT("' AND account='") + ac.id + wxT("'"); + + EXECUTE_SQL_UPDATE(req, ); + + req = wxT("SELECT COUNT(user) AS cnt FROM shared_account WHERE account='") + ac.id + wxT("'"); + + EXECUTE_SQL_QUERY(req, set, ); + + if (!set.GetInt(wxT("cnt"))) + { + ac.shared = false; + UpdateAccount(ac); + } + } wxString Database::AddCategory(User* user, Category& category) @@ -817,6 +934,35 @@ void Database::DeleteCategory(User* user, Category& category) EXECUTE_SQL_UPDATE(req, ); } +bool Database::LoadCategory(const wxString& id, const wxString& name, Category& category) +{ + wxSQLite3ResultSet set; + wxString req; + bool ret = false ; + + if (id.Length()) + req = wxT("SELECT * FROM category WHERE id='") + id + wxT("'"); + else + req = wxT("SELECT * FROM category WHERE name='") + name + wxT("'"); + + EXECUTE_SQL_QUERY(req, set, false); + + if (set.NextRow()) + { + category.id = set.GetAsString(wxT("id")); + category.parent = set.GetAsString(wxT("parent")); + category.name = set.GetAsString(wxT("name")); + category.backcolor = wxColour(set.GetAsString(wxT("backcolor"))); + category.forecolor = wxColour(set.GetAsString(wxT("forecolor"))); + category.font = set.GetAsString(wxT("font")); + ret = true; + } + + set.Finalize(); + + return ret; +} + std::map > Database::GetAllOperations(User* user) { wxString req, req2, reqUnion; @@ -1016,33 +1162,26 @@ void Database::KillMe(User* user) if (!user->_accounts.empty()) { + for (it = user->_accounts.begin(); it != user->_accounts.end(); it++) + DeleteAccount(user, *it); + it = user->_accounts.begin(); - req = wxT("DELETE FROM account_amount WHERE account IN('") + it->id; + if (it->is_owner) + req = wxT("DELETE FROM operation WHERE account IN('") + it->id; + else + req = wxT("DELETE FROM operation WHERE account IN('-1"); it++; for (;it != user->_accounts.end(); it++) { - req += wxT("', '") + it->id ; + if (it->is_owner) + req += wxT("', '") + it->id ; } req += wxT("')"); - - EXECUTE_SQL_UPDATE(req, ); - - it = user->_accounts.begin(); - req = wxT("DELETE FROM operation WHERE account IN('") + it->id; - it++; - for (;it != user->_accounts.end(); it++) - { - req += wxT("', '") + it->id ; - } - req += wxT("')"); - req += wxT(" OR user='") + user->_id + wxT("'"); + req += wxT(" OR (user='") + user->_id + wxT("' AND account='')"); EXECUTE_SQL_UPDATE(req, ); } - req = wxT("DELETE FROM account WHERE user='") + user->_id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); - req = wxT("DELETE FROM category WHERE user='") + user->_id + wxT("'"); EXECUTE_SQL_UPDATE(req, ); @@ -1281,7 +1420,7 @@ void Database::GetStats(User* user, const wxString& monthFrom, const wxString& y std::map* Database::GetNotChecked(User* user, int month, int year) { -std::vector::iterator accountIt; + std::vector::iterator accountIt; std::map* res = new std::map; wxSQLite3ResultSet set; wxString req; @@ -1304,3 +1443,44 @@ std::vector::iterator accountIt; return res; } + +std::map Database::getSharedAccountOwners(const wxString& account) +{ + std::map res; + wxSQLite3ResultSet set, set2; + wxString req; + + req = wxT("SELECT user FROM shared_account WHERE account='") + account + wxT("'"); + + EXECUTE_SQL_QUERY(req, set, res); + + while(set.NextRow()) + { + req = wxT("SELECT name FROM user WHERE id='") + set.GetAsString(wxT("user")) + wxT("'"); + + EXECUTE_SQL_QUERY(req, set2, res); + + res[set2.GetAsString(wxT("name"))] = set.GetAsString(wxT("user")); + } + + return res; +} + +wxString Database::getSharedAccountOwner(const wxString& account) +{ + wxSQLite3ResultSet set, set2; + wxString req; + + req = wxT("SELECT user FROM account WHERE id='") + account + wxT("'"); + + EXECUTE_SQL_QUERY(req, set, wxT("")); + + while(set.NextRow()) + { + req = wxT("SELECT name FROM user WHERE id='") + set.GetAsString(wxT("user")) + wxT("'"); + + EXECUTE_SQL_QUERY(req, set2, wxT("")); + } + + return set2.GetAsString(wxT("name")); +} diff --git a/src/model/Database.h b/src/model/Database.h index 4660327..72b6ea6 100644 --- a/src/model/Database.h +++ b/src/model/Database.h @@ -34,6 +34,7 @@ #define INIT_SCRIPT "init.sql" class KissCount; +class User; class Database { @@ -50,6 +51,10 @@ public: wxString AddOperation(User* user, Operation& op); void DeleteOperation(Operation& op); void DeleteOperations(User* user, int month, int year); + bool LoadOperation(User* user, const wxString& id); + double MetaAmount(const wxString& id); + double MetaPositiveAmount(const wxString& id); + double GetAccountAmount(const wxString& id, int month, int year); void SetAccountAmount(int month, int year, const wxString& accountId, double amount); @@ -57,10 +62,12 @@ public: void UpdateAccount(Account& ac); void DeleteAccount(User* user, Account& ac); void AddSharedAccount(Account& ac, const wxString& granted); + void RemoveSharedAccount(Account& ac, const wxString& granted); wxString AddCategory(User* user, Category& category); void UpdateCategory(Category& category); void DeleteCategory(User* user, Category& category); + bool LoadCategory(const wxString& id, const wxString& name, Category& category); std::map > GetAllOperations(User* user); void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo); @@ -82,6 +89,9 @@ public: void KillMe(User* user); bool GetOperation(const wxString& id, Operation* op); + std::map getSharedAccountOwners(const wxString& account); + wxString getSharedAccountOwner(const wxString& account); + std::map* GetNotChecked(User* user, int month, int year); private: diff --git a/src/model/User.cpp b/src/model/User.cpp index a8c6c34..911e8b7 100644 --- a/src/model/User.cpp +++ b/src/model/User.cpp @@ -19,6 +19,9 @@ #include "User.h" +User::User(Database* db) : _db(db) +{} + User::~User() { std::map >* >::iterator it; @@ -41,6 +44,9 @@ Category User::GetCategory(wxString& catId) if (it->id == catId) return *it; + if (_db->LoadCategory(catId, wxT(""), cat)) + return cat; + cat.id = wxT("0"); cat.parent = wxT("0"); cat.name = _("Unknown"); @@ -53,32 +59,46 @@ Category User::GetCategory(wxString& catId) wxString User::GetCategoryName(wxString& catId) { + Category cat; std::vector::iterator it; + for (it=_categories.begin(); it !=_categories.end(); it++) if (it->id == catId) return it->name; + if (_db->LoadCategory(catId, wxT(""), cat)) + return cat.name; + return _("Unknown") ; } wxString User::GetCategoryId(wxString& catName) { std::vector::iterator it; + Category cat; + for (it=_categories.begin(); it !=_categories.end(); it++) if (it->name == catName) return it->id; + if ( _db->LoadCategory(wxT(""), catName, cat)) + return cat.id; + return wxT("0") ; } -const wxFont& User::GetCategoryFont(wxString& catId) +const wxFont User::GetCategoryFont(wxString& catId) { wxFont f; + Category cat; for (unsigned int i=0; i<_categories.size(); i++) if (_categories[i].id == catId) return _categoriesFonts[i]; + if (_db->LoadCategory(catId, wxT(""), cat)) + return KissCount::ExtractFont(cat.font); + return f; } @@ -176,9 +196,14 @@ void User::Group(const Operation& op) // Already into childs if (it2 != it->childs.end()) return; it->childs.push_back(op.id); - break; + return; } } + + if (_db->LoadOperation(this, op.parent)) + { + (*_operations[op.year])[op.month][(*_operations[op.year])[op.month].size()-1].childs.push_back(op.id); + } } void User::UnGroup(const Operation& op) diff --git a/src/model/User.h b/src/model/User.h index 716dbe7..a7c13e5 100644 --- a/src/model/User.h +++ b/src/model/User.h @@ -28,10 +28,14 @@ #include "Category.h" #include "Account.h" #include "Operation.h" +#include "Database.h" + +class Database; class User { public: + User(Database* db); ~User(); wxString _id; @@ -46,7 +50,7 @@ public: Category GetCategory(wxString& catId); wxString GetCategoryName(wxString& catId); wxString GetCategoryId(wxString& catName); - const wxFont& GetCategoryFont(wxString& catId); + const wxFont GetCategoryFont(wxString& catId); wxString GetAccountName(const wxString& accountId); wxString GetAccountId(wxString& accountName); int GetCategoriesNumber(); @@ -57,6 +61,9 @@ public: void Group(const Operation& op); void UnGroup(const Operation& op); void ResolveGroups(int year); + +private: + Database* _db; }; #endif diff --git a/src/model/model.h b/src/model/model.h index 9da861f..9b1ab4e 100644 --- a/src/model/model.h +++ b/src/model/model.h @@ -20,7 +20,14 @@ #ifndef MODEL_H #define MODEL_H +class User; +class Database; +class Account; +class Operation; + #include "User.h" #include "Database.h" +#include "Account.h" +#include "Operation.h" #endif diff --git a/src/view/PreferencesPanel.cpp b/src/view/PreferencesPanel.cpp index 406496a..e2fb30f 100644 --- a/src/view/PreferencesPanel.cpp +++ b/src/view/PreferencesPanel.cpp @@ -19,11 +19,11 @@ #include "PreferencesPanel.h" -enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_SHARED, ACCOUNT_DEFAULT, ACCOUNT_DELETE, NUMBER_COLS_ACCOUNT}; +enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_DEFAULT, ACCOUNT_DELETE, NUMBER_COLS_ACCOUNT}; 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, - OPERATION_ORDER_ID}; + OPERATION_ORDER_ID, SHARED_WITH_ID}; BEGIN_EVENT_TABLE(PreferencesPanel, wxPanel) EVT_BUTTON(CHANGE_NAME_ID, PreferencesPanel::OnChangeName) @@ -31,24 +31,28 @@ EVT_BUTTON(CHANGE_PASSWORD_ID, PreferencesPanel::OnChangePassword) EVT_BUTTON(KILL_ME_ID, PreferencesPanel::OnKillMe) EVT_GRID_CMD_CELL_CHANGE(CATEGORIES_GRID_ID, PreferencesPanel::OnCategoryModified) EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountModified) +EVT_GRID_CMD_SELECT_CELL(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountCellChanged) EVT_COMBOBOX(OPERATION_ORDER_ID, PreferencesPanel::OnOperationOrderChange) EVT_COMBOBOX(LANGUAGE_ID, PreferencesPanel::OnLanguageChange) +EVT_CHECKLISTBOX(SHARED_WITH_ID, PreferencesPanel::OnSharedChange) EVT_SHOW(PreferencesPanel::OnShow) END_EVENT_TABLE() -PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent) +PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _sharedWith(NULL), _curAccountRow(-1) { wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); wxBoxSizer *hbox1 = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL); //wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); - wxStaticBox* staticUser, *staticAccount, *staticCategories, *staticLanguage, *staticOperationOrder; + wxStaticBox* staticUser, *staticAccount, *staticCategories, *staticLanguage, *staticOperationOrder, *staticSharedWith; User* user = _kiss->GetUser(); wxGridBagSizer *gridBagSizer; wxStaticText* label; wxButton* buttonChangeName, *buttonChangePassword, *killMe; wxStaticBoxSizer * staticBoxSizer; - + std::list users; + std::list::iterator it; + SetSizer(vbox); staticUser = new wxStaticBox(this, wxID_ANY, _("User")); @@ -56,6 +60,7 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p staticCategories = new wxStaticBox(this, wxID_ANY, _("Categories")); staticLanguage = new wxStaticBox(this, wxID_ANY, _("Language")); staticOperationOrder = new wxStaticBox(this, wxID_ANY, _("Operation order")); + staticSharedWith = new wxStaticBox(this, wxID_ANY, _("Shared with")); // User staticBoxSizer = new wxStaticBoxSizer (staticUser, wxVERTICAL); @@ -84,9 +89,9 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p staticBoxSizer = new wxStaticBoxSizer (staticAccount, wxVERTICAL); { - int clicks[] = {ACCOUNT_SHARED, ACCOUNT_DEFAULT, ACCOUNT_DELETE}; + int clicks[] = {ACCOUNT_DEFAULT, ACCOUNT_DELETE}; - _accountsGrid = new wxMyGrid(this, ACCOUNTS_GRID_ID, clicks, 3); + _accountsGrid = new wxMyGrid(this, ACCOUNTS_GRID_ID, clicks, 2); } InitAccounts(user); @@ -96,6 +101,22 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p hbox1->Add(staticBoxSizer); hbox1->Add(-1, 20); + staticBoxSizer = new wxStaticBoxSizer (staticSharedWith, wxVERTICAL); + _sharedWith = new wxCheckListBox(this, SHARED_WITH_ID); + + staticBoxSizer->Add(_sharedWith); + + users = _kiss->GetUsers(); + + for(it=users.begin(); it!=users.end(); it++) + if (*it != user->_name) + _sharedWith->Append(*it); + + _sharedWith->Enable(false); + + hbox1->Add(staticBoxSizer); + hbox1->Add(-1, 20); + // Categories staticBoxSizer = new wxStaticBoxSizer (staticCategories, wxVERTICAL); @@ -109,12 +130,12 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p InitCategories(user); - hbox1->Add(staticBoxSizer); - hbox1->Add(-1, 20); - vbox->Add(hbox1); vbox->Add(-1, 20); + vbox->Add(staticBoxSizer); + vbox->Add(-1, 20); + // Operation Order staticBoxSizer = new wxStaticBoxSizer (staticOperationOrder, wxVERTICAL); @@ -162,7 +183,6 @@ void PreferencesPanel::InitAccounts(User* user) _accountsGrid->SetRowLabelSize(0); _accountsGrid->SetColLabelValue(ACCOUNT_NAME, _("Name")); _accountsGrid->SetColLabelValue(ACCOUNT_NUMBER, _("Number")); - _accountsGrid->SetColLabelValue(ACCOUNT_SHARED, _("Shared")); _accountsGrid->SetColLabelValue(ACCOUNT_DEFAULT, _("Default")); _accountsGrid->SetColLabelValue(ACCOUNT_DELETE, _("Delete")); _accountsGrid->SetDefaultCellFont(font); @@ -177,22 +197,20 @@ void PreferencesPanel::InitAccounts(User* user) else _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number); - _accountsGrid->SetCellRenderer(curLine, ACCOUNT_SHARED, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(curLine, ACCOUNT_SHARED, new wxGridCellFastBoolEditor ()); + _accountsGrid->SetCellEditor(curLine, ACCOUNT_NUMBER, new wxGridCellStarEditor ()); _accountsGrid->SetCellRenderer(curLine, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellEditor(curLine, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellRenderer(curLine, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellEditor(curLine, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); - _accountsGrid->SetCellValue(curLine, ACCOUNT_SHARED, (it->shared)?wxT("1"):wxT("0")); _accountsGrid->SetCellValue(curLine, ACCOUNT_DEFAULT, (it->_default)?wxT("1"):wxT("0")); - _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_NAME, true); + _accountsGrid->SetReadOnly(curLine, ACCOUNT_NUMBER, true); _accountsGrid->SetReadOnly(curLine, ACCOUNT_DEFAULT, true); } } @@ -200,7 +218,6 @@ void PreferencesPanel::InitAccounts(User* user) _accountsGrid->AutoSizeColumns(true); _accountsGrid->AppendRows(); - _accountsGrid->SetReadOnly(curLine, ACCOUNT_SHARED, true); _accountsGrid->SetReadOnly(curLine, ACCOUNT_DEFAULT, true); _accountsGrid->SetReadOnly(curLine, ACCOUNT_DELETE, true); } @@ -297,7 +314,7 @@ void PreferencesPanel::InitOperationOrder(User* user) void PreferencesPanel::OnAccountModified(wxGridEvent& event) { - int op_complete = 2; + int op_complete = 1; wxString value ; Account new_account, account; User* user = _kiss->GetUser(); @@ -324,12 +341,6 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event) op_complete--; } - value = _accountsGrid->GetCellValue(row, ACCOUNT_SHARED); - if (value.Length() && value != wxT("0")) - new_account.shared = true; - else - new_account.shared = false; - value = _accountsGrid->GetCellValue(row, ACCOUNT_DEFAULT); if (value.Length() && value != wxT("0")) new_account._default = true; @@ -414,17 +425,13 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event) return ; } - _accountsGrid->SetCellRenderer(row, ACCOUNT_SHARED, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(row, ACCOUNT_SHARED, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellRenderer(row, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellEditor(row, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellRenderer(row, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); _accountsGrid->SetCellEditor(row, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); - _accountsGrid->SetCellAlignment(row, ACCOUNT_SHARED, wxALIGN_CENTRE, wxALIGN_CENTRE); _accountsGrid->SetCellAlignment(row, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE); _accountsGrid->SetCellAlignment(row, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); - _accountsGrid->SetReadOnly(row, ACCOUNT_SHARED, false); _accountsGrid->SetReadOnly(row, ACCOUNT_DEFAULT, false); _accountsGrid->SetReadOnly(row, ACCOUNT_DELETE, false); @@ -437,7 +444,6 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event) _accountsGrid->AutoSizeColumns(true); _accountsGrid->AppendRows(); - _accountsGrid->SetReadOnly(row+1, ACCOUNT_SHARED, true); _accountsGrid->SetReadOnly(row+1, ACCOUNT_DEFAULT, true); _accountsGrid->SetReadOnly(row+1, ACCOUNT_DELETE, true); @@ -449,6 +455,74 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event) inModification = false; } +void PreferencesPanel::OnAccountCellChanged(wxGridEvent& event) +{ + User* user = _kiss->GetUser(); + int row = event.GetRow(); + std::map::iterator it; + int i; + bool own; + wxString owner; + + if (!_sharedWith || _curAccountRow == row) + { + event.Skip(); + return ; + } + + _curAccountRow = row ; + + if (row >= (int) user->_accounts.size()) + { + for(i=0; i<(int)_sharedWith->GetCount(); i++) + _sharedWith->Check(i, false); + own = false; + } + else + { + _sharedOwners = _kiss->getSharedAccountOwners(user->_accounts[row].id); + owner = _kiss->getSharedAccountOwner(user->_accounts[row].id); + for(i=0; i<(int)_sharedWith->GetCount(); i++) + { + _sharedWith->Check(i, _sharedOwners[_sharedWith->GetString(i)].Length() > 0 || + _sharedWith->GetString(i) == owner); + } + own = user->_accounts[row].is_owner; + } + + _sharedWith->Enable(own); + event.Skip(); +} + +void PreferencesPanel::OnSharedChange(wxCommandEvent& event) +{ + User* user = _kiss->GetUser(); + + // Event is fired before change + if (_sharedWith->IsChecked(event.GetSelection())) + { + if (!user->_accounts[_curAccountRow].shared) + _accountsGrid->SetCellValue(_curAccountRow, ACCOUNT_NUMBER, + user->_accounts[_curAccountRow].number + wxT("*")); + + _kiss->AddSharedAccount(user->_accounts[_curAccountRow], + _sharedWith->GetString(event.GetSelection())); + } + else + { + _kiss->RemoveSharedAccount(user->_accounts[_curAccountRow], + _sharedOwners[_sharedWith->GetString( + event.GetSelection())]); + + if (!user->_accounts[_curAccountRow].shared) + _accountsGrid->SetCellValue(_curAccountRow, ACCOUNT_NUMBER, user->_accounts[_curAccountRow].number); + } + + _wxUI->NeedReload(); + + event.Skip(); +} + void PreferencesPanel::OnCategoryModified(wxGridEvent& event) { int op_complete = 1; diff --git a/src/view/PreferencesPanel.h b/src/view/PreferencesPanel.h index ffaf471..24b4f85 100644 --- a/src/view/PreferencesPanel.h +++ b/src/view/PreferencesPanel.h @@ -36,6 +36,7 @@ #include #include "PasswordDialog.h" #include "SupportedLanguages.h" +#include "wxGridCellStarEditor.h" class wxUI; class KissCount; @@ -47,6 +48,8 @@ public: void ChangeUser(); void OnAccountModified(wxGridEvent& event); + void OnAccountCellChanged(wxGridEvent& event); + void OnSharedChange(wxCommandEvent& event); void OnCategoryModified(wxGridEvent& event); void OnChangeName(wxCommandEvent& event); void OnChangePassword(wxCommandEvent& event); @@ -63,6 +66,9 @@ private: wxTextCtrl* _name; wxBitmapComboBox* _language; wxComboBox* _operationOrder; + wxCheckListBox* _sharedWith; + int _curAccountRow; + std::map _sharedOwners; void InitAccounts(User* user); void InitCategories(User* user); diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 67fa197..e7b8ed6 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -352,13 +352,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, if (op.meta && !op.amount) { - amount = 0; - for(it2=op.childs.begin(); it2!=op.childs.end(); it2++) - { - op2 = GetOperation(*it2); - if (op2.amount > 0) - amount += op2.amount; - } + amount = _kiss->MetaPositiveAmount(op.id); SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), amount)); SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), amount)); @@ -979,13 +973,7 @@ void GridAccount::OnOperationModified(wxGridEvent& event) if (!_displayedOperations[row].amount) { - amount = 0; - for(it=new_op.childs.begin(); it!=new_op.childs.end(); it++) - { - op2 = GetOperation(*it); - if (op2.amount > 0) - amount += op2.amount; - } + amount = _kiss->MetaPositiveAmount(new_op.id); SetCellValue(row, DEBIT, wxString::Format(wxT("%.2lf"), amount)); SetCellValue(row, CREDIT, wxString::Format(wxT("%.2lf"), amount)); @@ -1030,7 +1018,6 @@ void GridAccount::UpdateMeta(Operation& op) op.month = op_.month; op.day = op_.day; } - op.amount += op_.amount; op.checked &= op_.checked; if (!op.description.Length() && op_.description.Length()) op.description = op_.description; @@ -1053,6 +1040,8 @@ void GridAccount::UpdateMeta(Operation& op) if (updateCat) op.category = category; + op.amount = _kiss->MetaAmount(op.id); + UpdateOperation(op); } diff --git a/src/view/wxGridCellStarEditor.cpp b/src/view/wxGridCellStarEditor.cpp new file mode 100644 index 0000000..1db025e --- /dev/null +++ b/src/view/wxGridCellStarEditor.cpp @@ -0,0 +1,53 @@ +/* + Copyright 2010 Grégory Soutadé + + This file is part of KissCount. + + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . +*/ + +#include "wxGridCellStarEditor.h" + +void wxGridCellStarEditor::BeginEdit (int row, int col, wxGrid *grid) { + static bool inModification = false; + wxString value; + + if (inModification) return ; + + inModification = true; + + value = grid->GetCellValue(row, col); + _has_star = (value[value.Length()-1] == '*'); + + if (_has_star) + grid->SetCellValue(row, col, value.RemoveLast()); + + wxGridCellTextEditor::BeginEdit(row, col, grid); + + inModification = false; +} + +bool wxGridCellStarEditor::EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/) +{ + wxString res = GetValue(); + bool ret; + + ret = wxGridCellTextEditor::EndEdit(row, col, grid); + + if (_has_star) + grid->SetCellValue(row, col, res + wxT("*")); + + return ret; +} + diff --git a/src/view/wxGridCellStarEditor.h b/src/view/wxGridCellStarEditor.h new file mode 100644 index 0000000..1937348 --- /dev/null +++ b/src/view/wxGridCellStarEditor.h @@ -0,0 +1,37 @@ +/* + Copyright 2010 Grégory Soutadé + + This file is part of KissCount. + + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . +*/ + +#ifndef WXGRIDCELLSTAREDITOR_H +#define WXGRIDCELLSTAREDITOR_H + +#include +#include +#include + +class wxGridCellStarEditor : public wxGridCellTextEditor +{ +public: + void BeginEdit (int row, int col, wxGrid *grid); + bool EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/); + +private: + bool _has_star; +}; + +#endif