Add Expand Group option to web view

This commit is contained in:
Grégory Soutadé 2010-10-27 21:00:40 +02:00
parent dc6ec437fa
commit 13db50e271
3 changed files with 63 additions and 7 deletions

View File

@ -27,6 +27,18 @@ class User
function GetCategory($id)
{
if ($id == "")
{
$cat["id"] = "";
$cat["forecolor"] = "black";
$cat["backcolor"] = "#3DEB3D";
$s = "background-color:" . $cat["backcolor"] . ";";
$s .= "color:" . $cat["forecolor"] . ";";
$cat["style"] = $s;
return $cat;
}
foreach($this->categories as $i => $category)
if ($category["id"] == "$id") return $category;

View File

@ -173,6 +173,20 @@ function LoadMonth($user, $month, $year)
return $db->query($req);
}
function MetaPositiveAmount($id)
{
global $db;
$req = "SELECT SUM(amount) as amount FROM operation WHERE amount > 0 AND parent='$id'";
$result = $db->query($req);
if ($row = $result->fetchArray())
return $row["amount"];
else
return 0.0;
}
function GetAllOperations($user, &$last_year, &$last_month)
{
$res;

View File

@ -86,6 +86,11 @@ else
$_SESSION["cur_month"] = $_POST["month"];
}
if (isset($_POST["expand"]))
$_SESSION["expand"] = "1";
else
$_SESSION["expand"] = "0";
$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;
@ -162,6 +167,7 @@ function changeMonths()
}
?>
</select>
<input type="checkbox" name="expand" <?php if ($_SESSION["expand"] == "1") echo "checked";?>>Expand groups</input>
<input type="submit" value="OK"/>
</form>
<a id="disconnect" href="?disconnect=1">Disconnect</a>
@ -175,7 +181,10 @@ function changeMonths()
{
$val = GetAccountAmount($account["id"], $_SESSION["cur_month"], $_SESSION["cur_year"]);
echo "<tr class='bordered'>";
echo "<td>" . $account["number"] . "</td>";
if ($account["shared"] == "1")
echo "<td>" . $account["number"] . "*</td>";
else
echo "<td>" . $account["number"] . "</td>";
echo "<td>" . $account["name"] . "</td>";
echo "<td align='right'>" . number_format($val, 2) . "</td>";
if (($accounts[$account["id"]]["cur"] + $val) < 0)
@ -197,8 +206,17 @@ function changeMonths()
$operations = LoadMonth($_SESSION["user"], $_SESSION["cur_month"], $_SESSION["cur_year"]);
while($operation = $operations->fetchArray())
{
if ($operation["meta"] == "1") continue;
if ($_SESSION["expand"] == "1")
{
if ($operation["meta"] == "1")
continue;
}
else
{
if ($operation["parent"] != "")
continue;
}
$category = $_SESSION["user"]->GetCategory($operation["category"]);
if ($operation["fix_cost"] == "0")
{
@ -213,11 +231,23 @@ while($operation = $operations->fetchArray())
}
echo "<tr $tr_class style='" . $category["style"] . "'><td>" . $operation["description"] . "</td>";
echo "<td>" . date("d/m/Y", mktime(0, 0, 0, $operation["month"]+1, $operation["day"]+1, $operation["year"])) . "</td>";
if ($operation["amount"] < 0)
echo "<td align='right'>" . number_format(-$operation["amount"], 2) . "</td><td />";
if ($operation["meta"] == "1" && $operation["amount"] == 0)
{
$amount = MetaPositiveAmount($operation["id"]);
echo "<td align='right'>" . number_format($amount, 2) . "</td>";
echo "<td align='right'>" . number_format($amount, 2) . "</td>";
}
else
echo "<td /><td align='right'>" . number_format($operation["amount"], 2) . "</td>";
echo "<td>" . $category["name"] . "</td>";
{
if ($operation["amount"] < 0)
echo "<td align='right'>" . number_format(-$operation["amount"], 2) . "</td><td />";
else
echo "<td /><td align='right'>" . number_format($operation["amount"], 2) . "</td>";
}
if ($operation["meta"] != "1")
echo "<td>" . $category["name"] . "</td>";
else
echo "<td />";
echo "<td>" . $_SESSION["user"]->GetAccountName($operation["account"]) . "</td>";
echo "</tr>\n";
}