ec5ed2ed870b5374ab2c05502621d0c161c3c2d8
Bernd Wurst Neues Modul für unsere Buch...

Bernd Wurst authored 6 years ago

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");
Bernd Wurst Korrekte Dortierung der Rep...

Bernd Wurst authored 6 years ago

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 ORDER BY date", array(":from" => $year."-01-01", ":to" => $year."-12-31"));
Bernd Wurst Neues Modul für unsere Buch...

Bernd Wurst authored 6 years ago

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>");
Bernd Wurst Korrekte Dortierung der Rep...

Bernd Wurst authored 6 years ago

38)     output('<table style="font-size: 10pt;">');
Bernd Wurst Neues Modul für unsere Buch...

Bernd Wurst authored 6 years ago

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));
Bernd Wurst Korrekte Dortierung der Rep...

Bernd Wurst authored 6 years ago

82)     output("<tr><td colspan=\"2\" style=\"font-weight: bold;text-align: right;\">Summe $t:</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");