Update web view

Database.php :
	* Change account order
	* Forgot $db variable in LoadCategory
User.php :
	* Add default category for index 0
index.php :
	* Initialize $categories and $accounts arrays
	* Typo error for hidden accounts
	* Forgive credit on blocked account
	* Forgot to divide amounts by 100
	* Forgot to initialize tr_class variable in some case
This commit is contained in:
Grégory Soutadé 2012-05-22 20:29:08 +02:00
parent 102daf9a96
commit a5531465f6
4 changed files with 44 additions and 24 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -27,14 +27,13 @@ class User
function GetCategory($id) function GetCategory($id)
{ {
if ($id == "") if ($id == "" || $id == "0")
{ {
$cat["id"] = ""; $cat["id"] = "0";
$cat["forecolor"] = "black"; $cat["forecolor"] = "black";
$cat["backcolor"] = "#3DEB3D"; $cat["backcolor"] = "#3DEB3D";
$s = "background-color:" . $cat["backcolor"] . ";"; $cat["font"] = "";
$s .= "color:" . $cat["forecolor"] . ";"; ExtractStyle($cat);
$cat["style"] = $s;
return $cat; return $cat;
} }

View File

@ -88,7 +88,7 @@ function LoadUser($name)
$user->id = $row["id"]; $user->id = $row["id"];
$result = $db->query("SELECT * FROM account WHERE user='$user->id' ORDER BY default_account DESC, virtual, blocked, name ASC"); $result = $db->query("SELECT * FROM account WHERE user='$user->id' ORDER BY default_account DESC, hidden, blocked, virtual, name ASC");
$user->accounts = array(); $user->accounts = array();
@ -96,7 +96,7 @@ function LoadUser($name)
array_push($user->accounts, $row); array_push($user->accounts, $row);
// Shared accounts // Shared accounts
$result = $db->query("SELECT * FROM account WHERE id IN (SELECT account FROM shared_account WHERE user='$user->id') ORDER BY name, blocked, virtual ASC"); $result = $db->query("SELECT * FROM account WHERE id IN (SELECT account FROM shared_account WHERE user='$user->id') ORDER BY default_account DESC, hidden, blocked, virtual, name ASC");
while ($row = $result->fetchArray()) while ($row = $result->fetchArray())
array_push($user->accounts, $row); array_push($user->accounts, $row);
@ -125,6 +125,8 @@ function LoadUser($name)
function LoadCategory(&$user, $id) function LoadCategory(&$user, $id)
{ {
global $db;
$result = $db->query("SELECT * FROM category WHERE id='$id'"); $result = $db->query("SELECT * FROM category WHERE id='$id'");
if ($row = $result->fetchArray()) if ($row = $result->fetchArray())

View File

@ -90,6 +90,18 @@ $operations = LoadMonth($_SESSION["user"], $_SESSION["cur_month"], $_SESSION["cu
$cur_date = mktime(0, 0, 0, date("m") , date("d"), date("Y")); $cur_date = mktime(0, 0, 0, date("m") , date("d"), date("Y"));
$total_incomes = $total_outcomes = $cur_incomes = $cur_outcomes = 0; $total_incomes = $total_outcomes = $cur_incomes = $cur_outcomes = 0;
$categories = array(); $categories = array();
$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;
}
// Statistics // Statistics
foreach($operations as $i => $operation) foreach($operations as $i => $operation)
@ -104,7 +116,12 @@ foreach($operations as $i => $operation)
if ($date <= $cur_date) if ($date <= $cur_date)
$accounts[$operation["account"]]["cur"] += $operation["amount"]; $accounts[$operation["account"]]["cur"] += $operation["amount"];
if (!($operation["transfert"] == "" || ($operation["amount"] > 0 && $_SESSION["user"]->IsAccountBlocked($operation["account"])))) // 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"]))
continue; continue;
@ -206,7 +223,7 @@ function toggleOperations(parent, operations)
<?php <?php
foreach($_SESSION["user"]->accounts as $i => $account) foreach($_SESSION["user"]->accounts as $i => $account)
{ {
if ($accounts["hidden"] == "1") continue; if ($account["hidden"] == "1") continue;
$val = GetAccountAmount($account["id"], $_SESSION["cur_month"], $_SESSION["cur_year"]); $val = GetAccountAmount($account["id"], $_SESSION["cur_month"], $_SESSION["cur_year"]);
echo "<tr class='bordered'>"; echo "<tr class='bordered'>";
if ($account["shared"] == "1") if ($account["shared"] == "1")
@ -214,12 +231,12 @@ function toggleOperations(parent, operations)
else else
echo "<td>" . $account["number"] . "</td>"; echo "<td>" . $account["number"] . "</td>";
echo "<td>" . $account["name"] . "</td>"; echo "<td>" . $account["name"] . "</td>";
echo "<td align='right'>" . number_format($val, 2) . "</td>"; echo "<td align='right'>" . number_format($val/100, 2) . "</td>";
if (($accounts[$account["id"]]["cur"] + $val) < 0) if (($accounts[$account["id"]]["cur"] + $val) < 0)
echo "<td align='right' style=\"font-weight:bold;color:red;\">" . number_format($accounts[$account["id"]]["cur"] + $val, 2) . "</td>" ; echo "<td align='right' style=\"font-weight:bold;color:red;\">" . number_format(($accounts[$account["id"]]["cur"] + $val)/100, 2) . "</td>" ;
else else
echo "<td align='right' style=\"font-weight:bold;\">" . number_format($accounts[$account["id"]]["cur"] + $val, 2) . "</td>" ; 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, 2) . "</td>" ; echo "<td align='right'>" . number_format(($accounts[$account["id"]]["total"] + $val)/100, 2) . "</td>" ;
echo "</tr>\n"; echo "</tr>\n";
} }
?> ?>
@ -247,6 +264,8 @@ foreach($operations as $i => $operation)
else else
$tr_class = ""; $tr_class = "";
} }
else
$tr_class = "";
if ($operation["meta"] == "1") 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>"; 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 else
@ -259,16 +278,16 @@ foreach($operations as $i => $operation)
echo "<td>" . date("d/m/Y", mktime(0, 0, 0, $operation["month"]+1, $operation["day"]+1, $operation["year"])) . "</td>"; echo "<td>" . date("d/m/Y", mktime(0, 0, 0, $operation["month"]+1, $operation["day"]+1, $operation["year"])) . "</td>";
if ($operation["meta"] == "1" && $operation["amount"] == 0) if ($operation["meta"] == "1" && $operation["amount"] == 0)
{ {
$amount = MetaPositiveAmount($operation["id"]); $amount = MetaPositiveAmount($operation["id"])/100;
echo "<td align='right'>" . number_format($amount, 2) . "</td>"; echo "<td align='right'>" . number_format($amount, 2) . "</td>";
echo "<td align='right'>" . number_format($amount, 2) . "</td>"; echo "<td align='right'>" . number_format($amount, 2) . "</td>";
} }
else else
{ {
if ($operation["amount"] < 0) if ($operation["amount"] < 0)
echo "<td align='right'>" . number_format(-$operation["amount"], 2) . "</td><td />"; echo "<td align='right'>" . number_format(-$operation["amount"]/100, 2) . "</td><td />";
else else
echo "<td /><td align='right'>" . number_format($operation["amount"], 2) . "</td>"; echo "<td /><td align='right'>" . number_format($operation["amount"]/100, 2) . "</td>";
} }
if ($operation["meta"] != "1" && $category["id"] > 1) if ($operation["meta"] != "1" && $category["id"] > 1)
echo "<td>" . $category["name"] . "</td>"; echo "<td>" . $category["name"] . "</td>";
@ -284,16 +303,16 @@ foreach($operations as $i => $operation)
<div id="stats"> <div id="stats">
<div id="money_stats"> <div id="money_stats">
<table> <table>
<tr class="bordered"><td style="font-weight:bold">Cur credit</td><td align="right"><?php echo number_format($cur_incomes, 2) ?></td></tr> <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, 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, 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, 2); ?></td></tr> <tr class="bordered"><td>Total debit</td><td align="right"><?php echo number_format($total_outcomes/100, 2); ?></td></tr>
<tr class="bordered"><td style="font-weight:bold">Remains</td> <tr class="bordered"><td style="font-weight:bold">Remains</td>
<?php <?php
if ($total_outcomes < $total_incomes) if ($total_outcomes < $total_incomes)
echo "<td style=\"text-align:right;font-weight:bold;color:green\">" . number_format($total_incomes - $total_outcomes, 2) . "</td>"; echo "<td style=\"text-align:right;font-weight:bold;color:green\">" . number_format(($total_incomes - $total_outcomes)/100, 2) . "</td>";
else else
echo "<td style=\"text-align:right;font-weight:bold;color:red\"> " . number_format($total_incomes - $total_outcomes, 2) . "</td>"; echo "<td style=\"text-align:right;font-weight:bold;color:red\"> " . number_format(($total_incomes - $total_outcomes)/100, 2) . "</td>";
?> ?>
</tr> </tr>
<tr class="bordered"><td>_</td><td> </td></tr> <tr class="bordered"><td>_</td><td> </td></tr>
@ -313,7 +332,7 @@ foreach($operations as $i => $operation)
$percent = ($percent < 10) ? "0$percent" : "$percent"; $percent = ($percent < 10) ? "0$percent" : "$percent";
} }
echo "<tr class=\"bordered\"><td>Non fix</td><td align=\"right\">" . number_format($value, 2) . " ($percent %)</td></tr>\n"; echo "<tr class=\"bordered\"><td>Non fix</td><td align=\"right\">" . number_format($value/100, 2) . " ($percent %)</td></tr>\n";
} }
if ($total_outcomes == 0) if ($total_outcomes == 0)
@ -325,7 +344,7 @@ foreach($operations as $i => $operation)
$percent = ($percent < 10) ? "0$percent" : "$percent"; $percent = ($percent < 10) ? "0$percent" : "$percent";
} }
echo "<tr class=\"bordered\"><td>" . $category["name"]. "</td><td align=\"right\">" . number_format($categories[$category["id"]], 2) . " ($percent %)</td></tr>\n"; echo "<tr class=\"bordered\"><td>" . $category["name"]. "</td><td align=\"right\">" . number_format($categories[$category["id"]]/100, 2) . " ($percent %)</td></tr>\n";
} }
?> ?>
</table> </table>