Browse code

Neues Modul für unsere Buchhaltung, Jahresreporte

Bernd Wurst authored on 08/06/2017 11:10:42
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+<?php
2
+
3
+$role = $_SESSION['role'];
4
+if ($role & ROLE_SYSADMIN) {
5
+  $menu["buchhaltung_report"] = array("label" => "Report", "file" => "report", "weight" => -10);
6
+}
7
+
0 8
new file mode 100644
... ...
@@ -0,0 +1,117 @@
1
+<?php
2
+
3
+require_role(ROLE_SYSADMIN);
4
+
5
+$title = 'Report';
6
+
7
+
8
+$year = date("Y")-1;
9
+
10
+$typeresult = db_query("SELECT id, description FROM buchhaltung.types");
11
+$dataresult = db_query("SELECT id, date, description, invoice_id, direction, type, amount, tax_rate, gross FROM buchhaltung.transactions WHERE date BETWEEN :from and :to", array(":from" => $year."-01-01", ":to" => $year."-12-31"));
12
+
13
+$types = array();
14
+$data_by_type = array();
15
+$sum_by_type = array();
16
+while ($t = $typeresult->fetch()) {
17
+    $types[$t['id']] = $t['description'];
18
+    $data_by_type[$t['id']] = array();
19
+    $sum_by_type[$t['id']] = 0.0;
20
+}
21
+
22
+while ($line = $dataresult->fetch()) {
23
+    $data_by_type[$line['type']][] = $line;
24
+}
25
+
26
+
27
+output("Journal für $year (01.01.$year-31.12.$year, gruppiert nach Buchungskonten)");
28
+
29
+DEBUG($types);
30
+$net_by_type = array(0 => array(-1 => array(), 0 => array(), 19 => array()));
31
+$umsatzsteuer = 0.0;
32
+$vorsteuer = 0.0;
33
+foreach ($types as $id => $t) {
34
+    if (count($data_by_type[$id]) == 0) {
35
+        continue;
36
+    }
37
+    output("<h3>$t</h3>");
38
+    output("<table>");
39
+    $umsatz19proz = 0.0;
40
+    $umsatz0proz = 0.0;
41
+    $umsatzandereproz = 0.0;
42
+    $netsum = 0.0;
43
+    $ustsum = 0.0;
44
+    foreach ($data_by_type[$id] as $line) {
45
+        $net = $line['amount'];
46
+        if ($line['gross'] == 1 && $line['tax_rate'] > 0) {
47
+            $net = $net / (1.0+($line['tax_rate']/100));
48
+        }
49
+        if ($line['direction'] == 'out') {
50
+            $net = -$net;
51
+        }
52
+        $ust = $net * ($line['tax_rate']/100);
53
+        if ($line['tax_rate'] == 19.0) {
54
+            $umsatz19proz += $net;
55
+        } elseif ($line['tax_rate'] == 0.0) {
56
+            $umsatz0proz += $net;
57
+        } else {
58
+            $umsatzandereproz += $net;
59
+        }
60
+        $netsum += $net;
61
+        $ustsum += $ust;
62
+        if ($id == 0) {
63
+            $umsatzsteuer += $ust;
64
+        } else {
65
+            $vorsteuer += $ust;
66
+        }
67
+        $gross = $net + $ust;
68
+        $net = str_replace('.', ',', sprintf('%.2f €', $net));
69
+        $ust = str_replace('.', ',', sprintf('%.2f €', $ust));
70
+        $gross = str_replace('.', ',', sprintf('%.2f €', $gross));
71
+        output("<tr><td>".$line['date']."</td><td>".$line['description']."</td><td style=\"text-align: right;\">".$net."</td><td style=\"text-align: right;\">".$ust."</td><td style=\"text-align: right;\">".$gross."</td></tr>\n");
72
+    }
73
+    if ($id == 0) {
74
+        $net_by_type[0][-1] = $umsatzandereproz;
75
+        $net_by_type[0][0] = $umsatz0proz;
76
+        $net_by_type[0][19] = $umsatz19proz;
77
+    } else {
78
+        $net_by_type[$id] = $netsum;
79
+    }
80
+    $netsum = str_replace('.', ',', sprintf('%.2f €', $netsum));
81
+    $ustsum = str_replace('.', ',', sprintf('%.2f €', $ustsum));
82
+    output("<tr><td colspan=\"2\" style=\"font-weight: bold;text-align: right;\">Summe dieser Kategorie:</td><td style=\"font-weight: bold;text-align: right;\">$netsum</td><td style=\"font-weight: bold;text-align: right;\">$ustsum</td><td></td></tr>\n");
83
+    output('</table>');
84
+}
85
+
86
+output("<h3>Summen</h3>");
87
+
88
+output('<table>');
89
+$einnahmensumme = 0.0;
90
+output("<tr><td>Einnahmen 19% USt netto</td><td style=\"text-align: right;\">".number_format($net_by_type[0][19], 2, ',', '.')." €</td></tr>");
91
+$einnahmensumme += $net_by_type[0][19];
92
+output("<tr><td>Einnahmen innergem. Lieferung (steuerfrei §4/1b UStG)</td><td style=\"text-align: right;\">".number_format($net_by_type[0][0], 2, ',', '.')." €</td></tr>");
93
+$einnahmensumme += $net_by_type[0][0];
94
+output("<tr><td>Einnahmen EU-Ausland (VATMOSS)</td><td style=\"text-align: right;\">".number_format($net_by_type[0][-1], 2, ',', '.')." €</td></tr>");
95
+$einnahmensumme += $net_by_type[0][-1];
96
+output("<tr><td>Einnahme Umsatzsteuer</td><td style=\"text-align: right;\">".number_format($umsatzsteuer, 2, ',', '.')." €</td></tr>");
97
+$einnahmensumme += $umsatzsteuer;
98
+
99
+output("<tr><td><b>Summe Einnahmen:</b></td><td style=\"text-align: right;\"><b>".number_format($einnahmensumme, 2, ',', '.')." €</td></tr>");
100
+output("<tr><td colspan=\"2\"></td></tr>");
101
+$ausgabensumme = 0.0;
102
+foreach ($types as $id => $t) {
103
+    if ($id == 0 || !isset($net_by_type[$id])) {
104
+        continue;
105
+    }
106
+    $ausgabensumme -= $net_by_type[$id];
107
+    output("<tr><td>".$t."</td><td style=\"text-align: right;\">".number_format(-$net_by_type[$id], 2, ',', '.')." €</td></tr>");
108
+}
109
+
110
+output("<tr><td>Vorsteuer</td><td style=\"text-align: right;\">".number_format(-$vorsteuer, 2, ',', '.')." €</td></tr>");
111
+$ausgabensumme -= $vorsteuer;
112
+output("<tr><td><b>Summe Ausgaben:</b></td><td style=\"text-align: right;\"><b>".number_format($ausgabensumme, 2, ',', '.')." €</td></tr>");
113
+output("<tr><td colspan=\"2\"></td></tr>");
114
+
115
+output("<tr><td><b>Überschuss aus laufendem Betrieb:</b></td><td style=\"text-align: right;\"><b>".number_format($einnahmensumme-$ausgabensumme, 2, ',', '.')." €</td></tr>");
116
+output('</table>');
117
+
0 118
new file mode 100644
... ...
@@ -0,0 +1,46 @@
1
+<?php
2
+
3
+require_role(ROLE_SYSADMIN);
4
+
5
+$title = 'Report';
6
+
7
+
8
+$year = date("Y")-1;
9
+
10
+$typeresult = db_query("SELECT id, description FROM buchhaltung.types");
11
+$dataresult = db_query("SELECT id, date, description, invoice_id, direction, type, amount, tax_rate, gross FROM buchhaltung.transactions WHERE date BETWEEN :from and :to", array(":from" => $year."-01-01", ":to" => $year."-12-31"));
12
+
13
+$types = array();
14
+$data = array();
15
+while ($t = $typeresult->fetch()) {
16
+    $types[$t['id']] = $t['description'];
17
+}
18
+
19
+while ($line = $dataresult->fetch()) {
20
+    $data[] = $line;
21
+}
22
+
23
+
24
+output("Journal für $year (01.01.$year-31.12.$year, sortiert nach Datum)");
25
+output("<h3>$t</h3>");
26
+output("<table>");
27
+
28
+foreach ($data as $line) {
29
+        $net = $line['amount'];
30
+        if ($line['gross'] == 1 && $line['tax_rate'] > 0) {
31
+            $net = $net / (1.0+($line['tax_rate']/100));
32
+        }
33
+        if ($line['direction'] == 'out') {
34
+            $net = -$net;
35
+        }
36
+        $ust = $net * ($line['tax_rate']/100);
37
+        $gross = $net + $ust;
38
+        $net = str_replace('.', ',', sprintf('%.2f €', $net));
39
+        $ust = str_replace('.', ',', sprintf('%.2f €', $ust));
40
+        $gross = str_replace('.', ',', sprintf('%.2f €', $gross));
41
+        $typetext = $types[$line['type']];
42
+        output("<tr><td>".$line['date']."</td><td>".$typetext."</td><td>".$line['description']."</td><td style=\"text-align: right;\">".$net."</td><td style=\"text-align: right;\">".$ust."</td><td style=\"text-align: right;\">".$gross."</td></tr>\n");
43
+}
44
+
45
+output('</table>');
46
+