diff --git a/README b/README index 3dd1684..c4d323c 100644 --- a/README +++ b/README @@ -6,4 +6,6 @@ wxWidgets 2.8 and sqlite3 is needed A modified version of wxFreeChart is used : warning during recompilation, don't overwrite autotools files with ./configure +If you use web view, edit database.php and set $BDD_FILE, it's higly recommanded to use an SSL certificate. + More information can be found at http://indefero.soutade.fr/p/kisscount diff --git a/README.fr b/README.fr index 75561b2..3910da5 100644 --- a/README.fr +++ b/README.fr @@ -6,4 +6,6 @@ wxWidgets 2.8 et sqlite3 sont nécessaire Une version modifiée de wxFreeChart est utilisée : attention à lors de la recompilation à ne pas écraser les fichiers des autotools (pas de ./configure) +Si vous utilisez la version web pour visualiser vos comptes, éditez d'abord le fichier database.php en positionnant correctement la variable $BDD_FILE, il est fortement recommandé d'utiliser un certificat SSL. + Plus d'informations peuvent être trouvé sur http://indefero.soutade.fr/p/kisscount diff --git a/www/User.php b/www/User.php new file mode 100644 index 0000000..fb0ace3 --- /dev/null +++ b/www/User.php @@ -0,0 +1,46 @@ +/* + 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 . +*/ + +categories as $i => $category) + if ($category["id"] == "$id") return $category; + + return ""; + } + + function GetAccountName($id) + { + foreach($this->accounts as $i => $account) + if ($account["id"] == "$id") return $account["name"]; + + return ""; + } +} + +?> \ No newline at end of file diff --git a/www/database.php b/www/database.php new file mode 100644 index 0000000..9b0d0cd --- /dev/null +++ b/www/database.php @@ -0,0 +1,195 @@ +/* + 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 . +*/ + +query("SELECT name FROM user ORDER BY name"); + + while ($row = $result->fetchArray()) + array_push($res, $row['name']); + + return $res; +} + +function IsUserValid($user, $password) +{ + global $db; + + $result = $db->query("SELECT id FROM user WHERE name='" . $db->escapeString($user) . "' AND password='" . sha1($db->escapeString($password)) . "'"); + + return $result->fetchArray(); +} + +function LoadUser($name) +{ + global $db; + + $user = new User(); + + $name = $db->escapeString($name); + + $result = $db->query("SELECT * FROM user WHERE name='$name'"); + + if (!($row = $result->fetchArray())) + return NULL; + + $user->id = $row["id"]; + + $result = $db->query("SELECT * FROM account WHERE user='$user->id' ORDER BY default_account DESC, name ASC"); + + $user->accounts = array(); + + while ($row = $result->fetchArray()) + array_push($user->accounts, $row); + + $result = $db->query("SELECT * FROM category WHERE user='$user->id' ORDER by name"); + + $user->categories = array(); + + while ($row = $result->fetchArray()) + array_push($user->categories, $row); + + $result = $db->query("SELECT * FROM preference WHERE user='$user->id' ORDER by name"); + + $user->preferences = array(); + + $user->preferences["operation_order"] = "ASC"; + + while ($row = $result->fetchArray()) + array_push($user->preferences, $row); + + return $user; +} + +function GetAccountAmount($id, $month, $year) +{ + global $db; + + $req = "SELECT amount FROM account_amount WHERE account='$id' AND month='$month' AND year='$year'"; + + $result = $db->query($req); + + if ($row = $result->fetchArray()) + return $row["amount"]; + + return 0; +} + +function LoadMonth($user, $month, $year) +{ + global $db; + + if (!isset($user->accounts[0])) return; + + $req = "SELECT * FROM operation WHERE (account IN('" . $user->accounts[0]["id"] ; + foreach($user->accounts as $i => $account) + { + $req .= "', '" . $account["id"]; + } + + $req .= "')"; + $req .= " OR user='$user->id')"; + $req .= " AND year='$year' AND month='$month'"; + $req .= " ORDER BY fix_cost DESC, year, month ASC, day "; + $req .= $user->preferences["operation_order"]; + + return $db->query($req); + +} + +function GetAllOperations($user, &$last_year, &$last_month) +{ + $res; + global $db; + + if (!isset($user->accounts[0])) return $res; + + $req = "SELECT DISTINCT year FROM account_amount WHERE account IN('" . $user->accounts[0]["id"] ; + foreach($user->accounts as $i => $account) + { + $req .= "', '" . $account["id"]; + } + $req .= "')"; + + $req2 = "SELECT DISTINCT year FROM operation WHERE account IN('" .$user->accounts[0]["id"] ; + foreach($user->accounts as $i => $account) + { + $req2 .= "', '" . $account["id"]; + } + $req2 .= "')"; + $req2 .= " OR user='" . $user->id . "'"; + $req2 .= " ORDER BY year ASC"; + + $reqUnion = $req . " UNION " . $req2; + + $result = $db->query($reqUnion); + + while ($row = $result->fetchArray()) + { + $last_year = $year = $row["year"]; + + $req = "SELECT DISTINCT month FROM account_amount WHERE account IN('" . $user->accounts[0]["id"] ; + foreach($user->accounts as $i => $account) + { + $req .= "', '" . $account["id"]; + } + $req .= "')"; + $req .= " AND year='" . $year . "'"; + + $req2 = "SELECT DISTINCT month FROM operation WHERE (account IN('" . $user->accounts[0]["id"] ; + foreach($user->accounts as $i => $account) + { + $req2 .= "', '" . $account["id"]; + } + $req2 .= "')"; + $req2 .= " OR user='" . $user->id . "')"; + $req2 .= " AND year='" . $year . "'"; + $req2 .= " ORDER BY month ASC"; + + $reqUnion = $req . " UNION " . $req2; + + $result2 = $db->query($reqUnion); + + while ($row = $result2->fetchArray()) + { + if (!isset($res[$year])) $res[$year] = array(); + array_push($res[$year], $row["month"]); + $last_month = $row["month"]; + } + } + + return $res; +} +?> \ No newline at end of file diff --git a/www/index.php b/www/index.php new file mode 100644 index 0000000..27d5f5e --- /dev/null +++ b/www/index.php @@ -0,0 +1,257 @@ +/* + 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 . +*/ + + + + + + + + KissCount + + +

Invalid password

\n"; + else + $display_login = 0; + } + + if ($display_login == 1) + { + $users = GetUsers(); + echo "

KissCount



\n"; + echo "
\n"; + echo "Login :

\n"; + echo "Password :

\n"; + echo "\n"; + echo "
\n"; + echo "

\n"; + echo "
KissCount © 2010 Grégory Soutadé
\n"; + die(); + } + else + $_SESSION["user"] = LoadUser($_POST["user"]); +} + +if (!isset($_SESSION["operations"])) +{ + $_SESSION["operations"] = GetAllOperations($_SESSION["user"], $_SESSION["last_year"], $_SESSION["last_month"]); +} + +if (!isset($_POST["year"])) +{ + $_SESSION["cur_year"] = $_SESSION["last_year"]; + $_SESSION["cur_month"] = $_SESSION["last_month"]; +} +else +{ + $_SESSION["cur_year"] = $_POST["year"]; + $_SESSION["cur_month"] = $_POST["month"]; +} + +$operations = LoadMonth($_SESSION["user"], $_SESSION["cur_month"], $_SESSION["cur_year"]); +$cur_date = mktime(0, 0, 0, date("m") , date("d"), date("Y")); +$total_incomes = $total_outcomes = $cur_incomes = $cur_outcomes = 0; + +while($operation = $operations->fetchArray()) +{ + $date = mktime(0, 0, 0, $operation["month"]+1, $operation["day"]+1, $operation["year"]); + + $accounts[$operation["account"]]["total"] += $operation["amount"]; + + if ($date <= $cur_date) + $accounts[$operation["account"]]["cur"] += $operation["amount"]; + + if ($operation["transfert"] != "") continue; + + if ($operation["amount"] < 0) + { + $categories[$operation["category"]] -= $operation["amount"]; + $total_outcomes -= $operation["amount"]; + if ($date <= $cur_date) + $cur_outcomes -= $operation["amount"]; + } + else + { + $total_incomes += $operation["amount"]; + if ($date <= $cur_date) + $cur_incomes += $operation["amount"]; + } +} +?> + +
+ + + +
+ Disconnect +

+
+
+ + + accounts as $i => $account) + { + $val = GetAccountAmount($account["id"], $_SESSION["cur_month"], $_SESSION["cur_year"]); + echo ""; + echo ""; + echo ""; + echo ""; + if (($accounts[$account["id"]]["cur"] + $val) < 0) + echo "" ; + else + echo "" ; + echo "" ; + echo "\n"; + } +?> +
Account numberAccount nameInitial valueCur valueFinal value
" . $account["number"] . "" . $account["name"] . "" . number_format($val, 2) . "" . number_format($accounts[$account["id"]]["cur"] + $val, 2) . "" . number_format($accounts[$account["id"]]["cur"] + $val, 2) . "" . number_format($accounts[$account["id"]]["total"] + $val, 2) . "
+
+

+
+ + + fetchArray()) +{ + $category = $_SESSION["user"]->GetCategory($operation["category"]); + if ($operation["fix_cost"] == "0") + { + $cur_week = date("W", mktime(0, 0, 0, $operation["month"]+1, $operation["day"]+1, $operation["year"])); + if ($cur_week > $prev_week) + { + $tr_class = "class=\"new_week\""; + $prev_week = $cur_week; + } + else + $tr_class = ""; + } + echo ""; + echo ""; + if ($operation["amount"] < 0) + echo ""; + echo ""; + echo ""; + echo "\n"; +} +?> +
DescriptionDateDebitCreditCategoryAccount
" . $operation["description"] . "" . date("d/m/Y", mktime(0, 0, 0, $operation["month"]+1, $operation["day"]+1, $operation["year"])) . "" . number_format(-$operation["amount"], 2) . ""; + else + echo "" . number_format($operation["amount"], 2) . "" . $category["name"] . "" . $_SESSION["user"]->GetAccountName($operation["account"]) . "
+
+
+
+
+ + + + + + + " . number_format($total_incomes - $total_outcomes, 2) . ""; + else + echo ""; +?> + + + categories as $i => $category) +{ + $percent = ($categories[$category["id"]] * 100) / $total_outcomes; + $percent = round($percent, 0); + $percent = ($percent < 10) ? "0$percent" : "$percent"; + echo "\n"; +} +?> +
Cur credit
Cur debit
Total credit
Total debit
Remains " . number_format($total_incomes - $total_outcomes, 2) . "
_
" . $category["name"]. "" . number_format($categories[$category["id"]], 2) . " ($percent %)
+
+
+

+
KissCount © 2010 Grégory Soutadé
+ + \ No newline at end of file diff --git a/www/kisscount.css b/www/kisscount.css new file mode 100644 index 0000000..a083e7b --- /dev/null +++ b/www/kisscount.css @@ -0,0 +1,11 @@ +table {background-color:white;border:1px solid black; border-collapse:collapse;} +.bordered {border:1px solid black} +td {border-right:1px solid black; padding:3px} +tr.header > td {border:1px solid black; text-align:center; font-weight:bold; padding:2px} +tr.bordered > td {border:1px solid black;padding:2px} +tr.new_week {border-top:1px solid black;} +div {display:inline;} +table {display:inline-table;} +#date {display: inline;} +#disconnect {float:right;} +#login {border:1px solid black;padding:2px;margin-left:350px;margin-right:350px} \ No newline at end of file diff --git a/www/kisscount.php b/www/kisscount.php new file mode 100644 index 0000000..eef4985 --- /dev/null +++ b/www/kisscount.php @@ -0,0 +1,26 @@ +/* + 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 . +*/ + + \ No newline at end of file