-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.php
executable file
·102 lines (79 loc) · 2.62 KB
/
report.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
require_once('item.php');
class Report {
var $items;
var $order;
var $root_node;
function __construct($order, $sums) {
$this->order = $order;
$this->sums = $sums;
$this->items = array();
for ($i=0;$i<100;$i++) {
$this->items[] = new Item();
}
$this->root_node = array();
foreach ($this->items as $item) {
$this->insert_node($this->root_node, $item, 0);
}
self::sort($this->root_node);
}
function insert_node(&$node, $item, $order_index) {
$group = $this->order[$order_index];
$text = $item->$group;
//reverse lookup key map to find sort index
$arr = KEY_MAP[$group];
$sort_index = array_search($text, $arr);
if (empty($node[$sort_index])) {
$node[$sort_index] = array(
"text" => $text,
"children" => array(),
"values" => array(
"amount" => 0,
"total" => 0
)
);
}
//if not yet reached end of order, recurse, else put the summed values
if ($order_index < count($this->order) - 1) {
$values = $this->insert_node($node[$sort_index]["children"], $item, $order_index + 1);
}
else {
$values["amount"] = $item->amount;
$values["total"] = $item->total;
}
$node[$sort_index]["values"]["amount"] += $values["amount"];
$node[$sort_index]["values"]["total"] += $values["total"];
return $values;
}
static function sort(&$array) {
foreach ($array as &$value) {
$children = &$value["children"];
if (is_array($children) && sizeof($children)) {
self::sort($children);
}
}
return ksort($array);
}
static function zsort(&$node) {
foreach ($node as $k => $subnode) {
if (sizeof($subnode["children"])) {
self::sort($subnode["children"]);
}
}
uksort($node, function($a, $b) use (&$node) {
return $node[$a] - $node[$b] ?: $a - $b;
});
}
function draw_row($key, $node, $level, $parent_id = null) {
$id = uniqid();
$text = $node["text"];
include("row.php");
foreach ($node["children"] as $key => $node) {
$this->draw_row($key, $node, $level + 1, $id);
}
}
function render() {
include("table.php");
}
}
?>