Repository navigation
Expand file tree
/
Copy pathtinyreport.php
More file actions
106 lines (103 loc) · 4 KB
/
Copy pathtinyreport.php
File metadata and controls
106 lines (103 loc) · 4 KB
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
103
104
105
106
<?php
function tiny_report($konto, $date_begin, $date_end)
{
global $realtype_req,$dbconn;
$cond = " AND account LIKE '$konto%' ";
if (str_contains($konto, ",")) {
$konto = "'" . implode("','", explode(",", $konto)) . "'";
$cond = " AND account IN ($konto)";
}
if ($date_begin) {
$cond .= " AND date >= '$date_begin' ";
}
if ($date_end) {
$cond .= " AND date <= '$date_end' ";
}
echo '
<table><tr><td>
<h3>Einnahmen</h3>
<table>
';
$query = "SELECT id,name FROM type WHERE income = 1 $realtype_req ORDER BY realtype ASC,id ASC";
$result = db_query($dbconn, $query);
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "<tr><td>" . html_escape($line['name']) . "</td><td>";
$query2 = "SELECT SUM(amount) AS sum FROM vouchers LEFT JOIN type T ON T.id = type WHERE NOT deleted AND realtype = {$line['id']} " . $cond;
$result2 = db_query($dbconn, $query2);
while ($line2 = pg_fetch_array($result2, null, PGSQL_ASSOC)) {
echo format_amount($line2['sum'], " €") . "</td></tr>\n";
}
pg_free_result($result2);
}
pg_free_result($result);
echo "<tr><td><b>Summe</b></td><td>";
$query2 = "SELECT SUM(amount) AS sum FROM vouchers LEFT JOIN type T ON T.id = type WHERE NOT deleted AND realtype IN (SELECT id FROM type WHERE income = 1) " . $cond;
$result2 = db_query($dbconn, $query2);
while ($line2 = pg_fetch_array($result2, null, PGSQL_ASSOC)) {
echo format_amount($line2['sum'], " €") . "</td></tr>\n";
}
pg_free_result($result2);
echo '
</table>
</td>
<td>
<h3>Ausgaben</h3>
<table>
';
$query = "SELECT id,name FROM type WHERE income <= 0 $realtype_req ORDER BY realtype ASC,id ASC";
$result = db_query($dbconn, $query);
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "<tr><td>" . html_escape($line['name']) . "</td><td>";
$query2 = "SELECT SUM(amount) AS sum FROM vouchers LEFT JOIN type T ON T.id = type WHERE NOT deleted AND realtype = {$line['id']} " . $cond;
$result2 = db_query($dbconn, $query2);
while ($line2 = pg_fetch_array($result2, null, PGSQL_ASSOC)) {
echo format_amount($line2['sum'], " €") . "</td></tr>\n";
}
pg_free_result($result2);
}
pg_free_result($result);
echo "<tr><td><b>Summe</b></td><td>";
$query2 = "SELECT SUM(amount) AS sum FROM vouchers LEFT JOIN type T ON T.id = type WHERE NOT deleted AND realtype IN (SELECT id FROM type WHERE income <= 0) " . $cond;
$result2 = db_query($dbconn, $query2);
while ($line2 = pg_fetch_array($result2, null, PGSQL_ASSOC)) {
echo format_amount($line2['sum'], " €") . "</td></tr>\n";
}
pg_free_result($result2);
echo '
</table>
</td>
</tr>
</table>
';
}
function page_tinyreport($rights)
{
global $dbconn;
if (strlen($rights ?? '') > 0) {
$query2 = "SELECT account FROM vouchers WHERE NOT deleted AND amount != 0 GROUP BY account ORDER BY account";
$result2 = db_query($dbconn, $query2);
echo "<ul>";
while ($line2 = pg_fetch_array($result2, null, PGSQL_ASSOC)) {
$k = $line2['account'];
echo "<li><a href=\"" . html_escape("tinyreport?konto=" . rawurlencode($k ?? '')) . "\">Konto '" . html_escape($k) . "'</a></li>";
}
echo "</ul>";
pg_free_result($result2);
}
$konto = "";
$date_begin = "";
$date_end = "";
if (isset($_GET["konto"]) && preg_match('/^[ A-Z0-9-,]+$/i', $_GET["konto"]) == 1) {
$konto = $_GET["konto"];
}
if (isset($_GET["date_begin"]) && preg_match('/^[0-9]+-[0-9]+-[0-9]+$/i', $_GET["date_begin"]) == 1) {
$date_begin = $_GET["date_begin"];
}
if (isset($_GET["date_end"]) && preg_match('/^[0-9]+-[0-9]+-[0-9]+$/i', $_GET["date_end"]) == 1) {
$date_end = $_GET["date_end"];
}
echo "<h1>Bericht Konto $konto</h1><br>";
block_start();
tiny_report($konto, $date_begin, $date_end);
block_end();
}