Work on web view :

Add Button to show/hide sub operations
	Re order accounts
	Pack operations and their sub operations
This commit is contained in:
www-data
2011-06-02 12:03:02 +02:00
parent 6fae41b4e8
commit 63f2a72a06
5 changed files with 124 additions and 28 deletions

63
www/database.php Normal file → Executable file
View File

@@ -88,7 +88,7 @@ function LoadUser($name)
$user->id = $row["id"];
$result = $db->query("SELECT * FROM account WHERE user='$user->id' ORDER BY default_account DESC, name ASC");
$result = $db->query("SELECT * FROM account WHERE user='$user->id' ORDER BY default_account DESC, virtual, blocked, name ASC");
$user->accounts = array();
@@ -96,7 +96,7 @@ function LoadUser($name)
array_push($user->accounts, $row);
// Shared accounts
$result = $db->query("SELECT * FROM account WHERE id IN (SELECT account FROM shared_account WHERE user='$user->id') ORDER BY name ASC");
$result = $db->query("SELECT * FROM account WHERE id IN (SELECT account FROM shared_account WHERE user='$user->id') ORDER BY name, blocked, virtual ASC");
while ($row = $result->fetchArray())
array_push($user->accounts, $row);
@@ -152,9 +152,19 @@ function GetAccountAmount($id, $month, $year)
return 0;
}
function array_insert($array,$pos,$val)
{
$array2 = array_splice($array,$pos);
$array[] = $val;
$array = array_merge($array,$array2);
return $array;
}
function LoadMonth($user, $month, $year)
{
global $db;
$res = array();
if (!isset($user->accounts[0])) return;
@@ -170,7 +180,37 @@ function LoadMonth($user, $month, $year)
$req .= " ORDER BY fix_cost DESC, year, month ASC, day ";
$req .= $user->preferences["operation_order"];
return $db->query($req);
$result = $db->query($req);
// Pack operations and their sub operations
while ($row = $result->fetchArray())
{
$inserted = 0;
foreach($res as $i => $value)
{
if ($value["parent"] == $row["id"])
{
$res = array_insert($res, $i, $row);
$inserted = 1;
break;
}
if ($row["parent"] == $value["id"])
{
$res = array_insert($res, $i+1, $row);
$inserted = 1;
break;
}
}
// Append
if ($inserted == 0)
{
$res = array_insert($res, $i+1, $row);
}
}
return $res;
}
function MetaPositiveAmount($id)
@@ -250,4 +290,21 @@ function GetAllOperations($user, &$last_year, &$last_month)
return $res;
}
function GetSubOperations($parent)
{
$res = "[";
global $db;
$req = "SELECT id FROM operation WHERE parent=\"" . $parent . "\"";
$result = $db->query($req);
while ($row = $result->fetchArray())
$res .= $row["id"] . ", ";
if (strlen($res) > 1)
$res = substr($res, 0, strlen($res)-2);
return $res . "]";
}
?>