diff --git a/www/User.php b/www/User.php old mode 100644 new mode 100755 diff --git a/www/database.php b/www/database.php old mode 100644 new mode 100755 index ab8c6f1..981131a --- a/www/database.php +++ b/www/database.php @@ -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 . "]"; +} ?> \ No newline at end of file diff --git a/www/index.php b/www/index.php old mode 100644 new mode 100755 index 5aab6a2..3fbf024 --- a/www/index.php +++ b/www/index.php @@ -86,16 +86,13 @@ 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; +$categories = array(); -while($operation = $operations->fetchArray()) +// Statistics +foreach($operations as $i => $operation) { if ($operation["meta"] == "1") continue; @@ -151,6 +148,29 @@ function changeMonths() ?> } } +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
- >Expand groups
Disconnect @@ -208,23 +227,13 @@ function changeMonths()

- + fetchArray()) -{ - if ($_SESSION["expand"] == "1") - { - if ($operation["meta"] == "1") - continue; - } - else - { - if ($operation["parent"] != "") - continue; - } +foreach($operations as $i => $operation) +{ $category = $_SESSION["user"]->GetCategory($operation["category"]); if ($operation["fix_cost"] == "0") { @@ -237,7 +246,15 @@ while($operation = $operations->fetchArray()) else $tr_class = ""; } - echo ""; + if ($operation["meta"] == "1") + echo ""; + else + { + if ($operation["parent"] == "") + echo ""; + else + echo ""; + } echo ""; if ($operation["meta"] == "1" && $operation["amount"] == 0) { @@ -252,7 +269,7 @@ while($operation = $operations->fetchArray()) else echo ""; } - if ($operation["meta"] != "1") + if ($operation["meta"] != "1" && $category["id"] > 1) echo ""; else echo "\n"; + } + + if ($total_outcomes == 0) + $percent = 0; + else + { + $percent = ($categories[$category["id"]] * 100) / $total_outcomes; + $percent = round($percent, 0); + $percent = ($percent < 10) ? "0$percent" : "$percent"; + } + echo "\n"; } ?> diff --git a/www/kisscount.css b/www/kisscount.css old mode 100644 new mode 100755 diff --git a/www/kisscount.php b/www/kisscount.php old mode 100644 new mode 100755
DescriptionDateDebitCreditCategoryAccount
DescriptionDateDebitCreditCategoryAccount
" . $operation["description"] . "
" . $operation["description"] . "
" . $operation["description"] . "
Non fix" . number_format($value, 2) . " ($percent %)
" . $category["name"]. "" . number_format($categories[$category["id"]], 2) . " ($percent %)