2010-09-10 21:58:34 +02:00
|
|
|
<?php
|
2010-08-31 21:36:07 +02:00
|
|
|
/*
|
2012-02-01 11:02:54 +01:00
|
|
|
Copyright 2010-2012 Grégory Soutadé
|
2010-08-31 21:36:07 +02:00
|
|
|
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
include "kisscount.php" ;
|
|
|
|
|
|
|
|
session_start();
|
|
|
|
?>
|
|
|
|
<!DOCTYPE HTML SYSTEM>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
|
|
|
|
<link rel="stylesheet" type="text/css" href= "kisscount.css" />
|
|
|
|
<title>KissCount</title>
|
|
|
|
</head>
|
|
|
|
<body bgcolor="#CCCCCC">
|
|
|
|
<?php
|
|
|
|
|
|
|
|
if (isset($_GET["disconnect"]))
|
|
|
|
{
|
|
|
|
$_SESSION = array();
|
|
|
|
session_destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($_SESSION["user"]))
|
|
|
|
{
|
|
|
|
$display_login = 1;
|
|
|
|
|
|
|
|
if (isset($_POST["user"]))
|
|
|
|
{
|
|
|
|
if (!IsUserValid($_POST["user"], $_POST["password"]))
|
|
|
|
echo "<center><font color=\"red\"><h3>Invalid password</h3></font></center>\n";
|
|
|
|
else
|
|
|
|
$display_login = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($display_login == 1)
|
|
|
|
{
|
|
|
|
$users = GetUsers();
|
|
|
|
echo "<center><h1>KissCount</h1><br /><br/>\n";
|
2010-10-27 15:52:59 +02:00
|
|
|
echo "<form id=\"login\" method=\"post\" action='index.php'>\n";
|
2015-11-05 18:06:21 +01:00
|
|
|
echo "Login : <select name=\"user\" autofocus>\n";
|
2010-08-31 21:36:07 +02:00
|
|
|
foreach($users as $i => $name)
|
|
|
|
echo "<option value=\"$name\">$name</option>\n";
|
|
|
|
echo "</select><br /><br />\n";
|
|
|
|
echo "Password : <input type=\"password\" name=\"password\" /><br /><br />\n";
|
2010-10-04 09:21:00 +02:00
|
|
|
echo "<input type=\"submit\" value=\"Connect\"/>\n";
|
2010-08-31 21:36:07 +02:00
|
|
|
echo "</form></center>\n";
|
|
|
|
echo "<br /><br />\n";
|
2015-11-05 18:06:21 +01:00
|
|
|
echo "<center><a href=\"http://indefero.soutade.fr/p/kisscount\">KissCount</a> © 2010-2015 Grégory Soutadé</center>\n";
|
2010-08-31 21:36:07 +02:00
|
|
|
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;
|
2011-06-02 12:03:02 +02:00
|
|
|
$categories = array();
|
2012-05-22 20:29:08 +02:00
|
|
|
$accounts = array();
|
|
|
|
|
|
|
|
// Init arrays
|
|
|
|
foreach($_SESSION["user"]->accounts as $i => $account)
|
|
|
|
{
|
|
|
|
$accounts[$account["id"]]["total"] = 0;
|
|
|
|
$accounts[$account["id"]]["cur"] = 0;
|
|
|
|
}
|
|
|
|
foreach($_SESSION["user"]->categories as $i => $category)
|
|
|
|
{
|
|
|
|
$categories[$category["id"]] = 0;
|
|
|
|
}
|
2010-08-31 21:36:07 +02:00
|
|
|
|
2011-06-02 12:03:02 +02:00
|
|
|
// Statistics
|
|
|
|
foreach($operations as $i => $operation)
|
2010-08-31 21:36:07 +02:00
|
|
|
{
|
2010-11-02 20:09:32 +01:00
|
|
|
if ($operation["meta"] == "1")
|
2010-11-02 19:59:49 +01:00
|
|
|
continue;
|
2010-10-04 09:21:00 +02:00
|
|
|
|
2010-11-02 20:09:32 +01:00
|
|
|
$date = mktime(0, 0, 0, $operation["month"]+1, $operation["day"]+1, $operation["year"]);
|
2010-08-31 21:36:07 +02:00
|
|
|
|
2010-11-02 20:09:32 +01:00
|
|
|
$accounts[$operation["account"]]["total"] += $operation["amount"];
|
2010-08-31 21:36:07 +02:00
|
|
|
|
2010-11-02 20:09:32 +01:00
|
|
|
if ($date <= $cur_date)
|
|
|
|
$accounts[$operation["account"]]["cur"] += $operation["amount"];
|
|
|
|
|
2012-05-22 20:29:08 +02:00
|
|
|
// Forgive transfert on non blocked accounts
|
|
|
|
if ($operation["transfert"] != "" && !$_SESSION["user"]->IsAccountBlocked($operation["account"]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Forgive credit on blocked account
|
|
|
|
if ($operation["transfert"] == "" && $_SESSION["user"]->IsAccountBlocked($operation["account"]))
|
2010-11-02 20:09:32 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if ($operation["transfert"] != "")
|
2010-11-02 19:59:49 +01:00
|
|
|
$operation["amount"] = -$operation["amount"];
|
2010-08-31 21:36:07 +02:00
|
|
|
|
|
|
|
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"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<script>
|
|
|
|
function changeMonths()
|
|
|
|
{
|
|
|
|
document.getElementById("date_month").innerHTML = "";
|
|
|
|
switch(document.getElementById("date_year").value)
|
|
|
|
{
|
|
|
|
<?php
|
|
|
|
global $months_strings;
|
|
|
|
foreach($_SESSION["operations"] as $year => $months)
|
|
|
|
{
|
|
|
|
echo "case \"$year\":\n";
|
|
|
|
$tmp = "";
|
|
|
|
foreach($months as $i => $month)
|
|
|
|
{
|
|
|
|
$tmp .= "<option value=\\'" . $month . "\\'>" . $months_strings[$month] . "</option>";
|
|
|
|
}
|
|
|
|
echo "document.getElementById(\"date_month\").innerHTML = '" . $tmp . "'\n";
|
|
|
|
echo "break\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
}
|
|
|
|
}
|
2011-06-02 12:03:02 +02:00
|
|
|
function toggleOperations(parent, operations)
|
|
|
|
{
|
|
|
|
var obj = document.getElementById(operations[0]);
|
|
|
|
var obj2 = document.getElementById(parent);
|
|
|
|
var visibility;
|
|
|
|
|
|
|
|
if (obj.style.display == "none")
|
|
|
|
{
|
|
|
|
obj2.value = "-";
|
|
|
|
visibility = "table-row";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
obj2.value = "+";
|
|
|
|
visibility = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i=0; i<operations.length; i++)
|
|
|
|
{
|
|
|
|
obj = document.getElementById(operations[i]);
|
|
|
|
obj.style.display = visibility;
|
|
|
|
}
|
|
|
|
}
|
2010-08-31 21:36:07 +02:00
|
|
|
</script>
|
2010-10-27 15:52:59 +02:00
|
|
|
<form id="date" method="POST" action="index.php">
|
2010-08-31 21:36:07 +02:00
|
|
|
<select name="month" id="date_month">
|
|
|
|
<?php
|
|
|
|
foreach($_SESSION["operations"][$_SESSION["cur_year"]] as $i => $month)
|
|
|
|
{
|
|
|
|
if ($month != $_SESSION["cur_month"])
|
|
|
|
echo "<option value='" . $month . "'>" . $months_strings[$month] . "</option>\n";
|
|
|
|
else
|
|
|
|
echo "<option value='" . $month . "' selected>" . $months_strings[$month] . "</option>\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</select>
|
|
|
|
<select name="year" id="date_year" onChange="changeMonths();">
|
|
|
|
<?php
|
|
|
|
foreach($_SESSION["operations"] as $year => $months)
|
|
|
|
{
|
|
|
|
if ($year != $_SESSION["cur_year"])
|
|
|
|
echo "<option value='" . $year . "'>" . $year . "</option>\n";
|
|
|
|
else
|
|
|
|
echo "<option value='" . $year . "' selected>" . $year . "</option>\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</select>
|
2010-10-04 09:21:00 +02:00
|
|
|
<input type="submit" value="OK"/>
|
2010-08-31 21:36:07 +02:00
|
|
|
</form>
|
|
|
|
<a id="disconnect" href="?disconnect=1">Disconnect</a>
|
|
|
|
<br /><br />
|
|
|
|
<div id="informations">
|
|
|
|
<div id="accounts">
|
|
|
|
<table>
|
|
|
|
<tr class="header"><td>Account number</td><td>Account name</td><td>Initial value</td><td>Cur value</td><td>Final value</td></tr>
|
|
|
|
<?php
|
|
|
|
foreach($_SESSION["user"]->accounts as $i => $account)
|
|
|
|
{
|
2012-05-22 20:29:08 +02:00
|
|
|
if ($account["hidden"] == "1") continue;
|
2010-08-31 21:36:07 +02:00
|
|
|
$val = GetAccountAmount($account["id"], $_SESSION["cur_month"], $_SESSION["cur_year"]);
|
|
|
|
echo "<tr class='bordered'>";
|
2010-10-27 21:00:40 +02:00
|
|
|
if ($account["shared"] == "1")
|
|
|
|
echo "<td>" . $account["number"] . "*</td>";
|
|
|
|
else
|
|
|
|
echo "<td>" . $account["number"] . "</td>";
|
2010-08-31 21:36:07 +02:00
|
|
|
echo "<td>" . $account["name"] . "</td>";
|
2012-05-22 20:29:08 +02:00
|
|
|
echo "<td align='right'>" . number_format($val/100, 2) . "</td>";
|
2010-08-31 21:36:07 +02:00
|
|
|
if (($accounts[$account["id"]]["cur"] + $val) < 0)
|
2012-05-22 20:29:08 +02:00
|
|
|
echo "<td align='right' style=\"font-weight:bold;color:red;\">" . number_format(($accounts[$account["id"]]["cur"] + $val)/100, 2) . "</td>" ;
|
2010-08-31 21:36:07 +02:00
|
|
|
else
|
2012-05-22 20:29:08 +02:00
|
|
|
echo "<td align='right' style=\"font-weight:bold;\">" . number_format(($accounts[$account["id"]]["cur"] + $val)/100, 2) . "</td>" ;
|
|
|
|
echo "<td align='right'>" . number_format(($accounts[$account["id"]]["total"] + $val)/100, 2) . "</td>" ;
|
2010-08-31 21:36:07 +02:00
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
<br /><br />
|
|
|
|
<div id="operations">
|
|
|
|
<table>
|
2014-11-27 18:27:31 +01:00
|
|
|
<tr class="header" bgcolor="#99CCFF"><td/><td>Description</td><td>Date</td><td>Debit</td><td>Credit</td><td>Category</td><td>Account</td><td>Tag</td></tr>
|
2010-08-31 21:36:07 +02:00
|
|
|
<?php
|
|
|
|
$prev_week=-1;
|
|
|
|
$operations = LoadMonth($_SESSION["user"], $_SESSION["cur_month"], $_SESSION["cur_year"]);
|
2010-10-27 21:00:40 +02:00
|
|
|
|
2011-06-02 12:03:02 +02:00
|
|
|
foreach($operations as $i => $operation)
|
|
|
|
{
|
2010-08-31 21:36:07 +02:00
|
|
|
$category = $_SESSION["user"]->GetCategory($operation["category"]);
|
2014-11-27 18:27:31 +01:00
|
|
|
$tag = $_SESSION["user"]->GetTag($operation["tag"]);
|
2010-08-31 21:36:07 +02:00
|
|
|
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 = "";
|
|
|
|
}
|
2012-05-22 20:29:08 +02:00
|
|
|
else
|
|
|
|
$tr_class = "";
|
2011-06-02 12:03:02 +02:00
|
|
|
if ($operation["meta"] == "1")
|
|
|
|
echo "<tr $tr_class style='" . $category["style"] . "'><td><input id=\"" . $operation["id"] . "\" type=\"button\" value=\"+\" onClick=\"var ids = " . GetSubOperations($operation["id"]) . " ; toggleOperations(" . $operation["id"] . ", ids);\"/></td><td>" . $operation["description"] . "</td>";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($operation["parent"] == "")
|
|
|
|
echo "<tr id=\"" . $operation["id"] . "\" $tr_class style='" . $category["style"] . "'><td></td><td>" . $operation["description"] . "</td>";
|
|
|
|
else
|
|
|
|
echo "<tr id=\"" . $operation["id"] . "\" $tr_class style='" . $category["style"] . ";display:none'><td></td><td> " . $operation["description"] . "</td>";
|
|
|
|
}
|
2010-08-31 21:36:07 +02:00
|
|
|
echo "<td>" . date("d/m/Y", mktime(0, 0, 0, $operation["month"]+1, $operation["day"]+1, $operation["year"])) . "</td>";
|
2010-10-27 21:00:40 +02:00
|
|
|
if ($operation["meta"] == "1" && $operation["amount"] == 0)
|
|
|
|
{
|
2012-05-22 20:29:08 +02:00
|
|
|
$amount = MetaPositiveAmount($operation["id"])/100;
|
2010-10-27 21:00:40 +02:00
|
|
|
echo "<td align='right'>" . number_format($amount, 2) . "</td>";
|
|
|
|
echo "<td align='right'>" . number_format($amount, 2) . "</td>";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($operation["amount"] < 0)
|
2012-05-22 20:29:08 +02:00
|
|
|
echo "<td align='right'>" . number_format(-$operation["amount"]/100, 2) . "</td><td />";
|
2010-10-27 21:00:40 +02:00
|
|
|
else
|
2012-05-22 20:29:08 +02:00
|
|
|
echo "<td /><td align='right'>" . number_format($operation["amount"]/100, 2) . "</td>";
|
2010-10-27 21:00:40 +02:00
|
|
|
}
|
2011-06-02 12:03:02 +02:00
|
|
|
if ($operation["meta"] != "1" && $category["id"] > 1)
|
2010-10-27 21:00:40 +02:00
|
|
|
echo "<td>" . $category["name"] . "</td>";
|
2010-08-31 21:36:07 +02:00
|
|
|
else
|
2010-10-27 21:00:40 +02:00
|
|
|
echo "<td />";
|
2010-08-31 21:36:07 +02:00
|
|
|
echo "<td>" . $_SESSION["user"]->GetAccountName($operation["account"]) . "</td>";
|
2014-11-27 18:27:31 +01:00
|
|
|
echo "<td>" . $tag["name"] . "</td>";
|
2010-08-31 21:36:07 +02:00
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="stats">
|
|
|
|
<div id="money_stats">
|
|
|
|
<table>
|
2012-05-22 20:29:08 +02:00
|
|
|
<tr class="bordered"><td style="font-weight:bold">Cur credit</td><td align="right"><?php echo number_format($cur_incomes/100, 2) ?></td></tr>
|
|
|
|
<tr class="bordered"><td style="font-weight:bold">Cur debit</td><td align="right"><?php echo number_format($cur_outcomes/100, 2) ?></td></tr>
|
|
|
|
<tr class="bordered"><td>Total credit</td><td align="right"><?php echo number_format($total_incomes/100, 2); ?></td></tr>
|
|
|
|
<tr class="bordered"><td>Total debit</td><td align="right"><?php echo number_format($total_outcomes/100, 2); ?></td></tr>
|
2010-08-31 21:36:07 +02:00
|
|
|
<tr class="bordered"><td style="font-weight:bold">Remains</td>
|
|
|
|
<?php
|
|
|
|
if ($total_outcomes < $total_incomes)
|
2012-05-22 20:29:08 +02:00
|
|
|
echo "<td style=\"text-align:right;font-weight:bold;color:green\">" . number_format(($total_incomes - $total_outcomes)/100, 2) . "</td>";
|
2010-08-31 21:36:07 +02:00
|
|
|
else
|
2012-05-22 20:29:08 +02:00
|
|
|
echo "<td style=\"text-align:right;font-weight:bold;color:red\"> " . number_format(($total_incomes - $total_outcomes)/100, 2) . "</td>";
|
2010-08-31 21:36:07 +02:00
|
|
|
?>
|
|
|
|
</tr>
|
|
|
|
<tr class="bordered"><td>_</td><td> </td></tr>
|
|
|
|
<?php
|
|
|
|
foreach($_SESSION["user"]->categories as $i => $category)
|
|
|
|
{
|
2011-06-02 12:03:02 +02:00
|
|
|
// Non fix
|
|
|
|
if ($i == 1)
|
|
|
|
{
|
|
|
|
$value = $total_outcomes - $categories[1];
|
|
|
|
if ($total_outcomes == 0)
|
|
|
|
$percent = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$percent = ($value * 100) / $total_outcomes;
|
|
|
|
$percent = round($percent, 0);
|
|
|
|
$percent = ($percent < 10) ? "0$percent" : "$percent";
|
|
|
|
}
|
|
|
|
|
2012-05-22 20:29:08 +02:00
|
|
|
echo "<tr class=\"bordered\"><td>Non fix</td><td align=\"right\">" . number_format($value/100, 2) . " ($percent %)</td></tr>\n";
|
2011-06-02 12:03:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($total_outcomes == 0)
|
|
|
|
$percent = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$percent = ($categories[$category["id"]] * 100) / $total_outcomes;
|
|
|
|
$percent = round($percent, 0);
|
|
|
|
$percent = ($percent < 10) ? "0$percent" : "$percent";
|
|
|
|
}
|
|
|
|
|
2012-05-22 20:29:08 +02:00
|
|
|
echo "<tr class=\"bordered\"><td>" . $category["name"]. "</td><td align=\"right\">" . number_format($categories[$category["id"]]/100, 2) . " ($percent %)</td></tr>\n";
|
2010-08-31 21:36:07 +02:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<br /><br />
|
2014-11-27 18:27:31 +01:00
|
|
|
<center><a href="http://indefero.soutade.fr/p/kisscount">KissCount</a> © 2010-2014 Grégory Soutadé</center>
|
2010-08-31 21:36:07 +02:00
|
|
|
</body>
|
|
|
|
</html>
|