Rudimentaere Buchhaltung hinzugefuegt.
[infodrom.org/service.infodrom.org] / src / InfoCon / buch / list.wml
1 #include <infocon.style>
2
3 <page title="Kontoführung">
4
5 <headline "Buchhaltung">
6
7 <table width=100% border=1 cellpadding=2 cellspacing=0>
8 <tr>
9   <th width=15%>Datum</th>
10   <th width=20%>Kategorie</th>
11   <th width=50%>Verwendungszweck</th>
12   <th width=15%>Betrag</th>
13 </tr>
14 <?
15   $dbh = pg_pconnect ("kuolema", "5432", "<db>")
16                or die("Unable to connect to SQL server");
17
18   pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
19
20   if (strlen($year)) {
21     # $where[] = "date >= '$year-01-01'";
22     # $year++;
23     # $where[] = "date < '$year-01-01'";
24     $where[] = "date ~* '$year'";
25   }
26   if (strlen($category)) {
27     $where[] = "category = '$category'";
28   }
29   if ($input && !$output) {
30     $where[] = "price > 0.0";
31   } elseif ($output && !$input) {
32     $where[] = "price < 0.0";
33   }
34
35   $query = "SELECT date,oid,category,description,price FROM sales ";
36   if (count($where) > 0) {
37     $query .= " WHERE " . implode ($where, " AND ");
38   }
39   $query .= " ORDER BY date,oid";
40   $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
41
42   $sum = 0.0;
43   for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
44     $row = pg_fetch_array ($sth, $nr);
45
46     # $date = explode (" ", $row['date']);
47     # $date = explode ("-", $date[0]);
48     # $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
49     $date = substr ($row['date'],6,2) . "." . substr ($row['date'],4,2) . "." . substr ($row['date'],0,4);
50
51     echo ("<tr>");
52     printf ("<td width=\"15%%\" align=\"right\">%s</td>", $date);
53     printf ("<td width=\"20%%\">%s</td>", $row['category']);
54     printf ("<td width=\"50%%\"><a href=\"edit.php3?oid=%d\">%s</a></td>", $row['oid'], $row['description']);
55     printf ("<td width=\"15%%\" align=\"right\">%5.2f</td>", $row['price']);
56     $sum += $row['price'];
57     echo ("</tr>");
58   }
59   echo ("<tr>");
60   echo ("<td width=\"85%\" colspan=\"3\">Summe</td>");
61   printf ("<td width=\"15%%\" align=\"right\">%5.2f</td>", $sum);
62   echo ("</tr>");
63
64   if (!strlen($category)) {
65
66     $query = "SELECT DISTINCT category FROM sales ";
67     if (strlen($year)) {
68       $query .= "WHERE date ~* '$year'";
69     }
70
71     $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
72
73     for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
74       $row = pg_fetch_array ($sth, $nr);
75       $catz[] = $row['category'];
76     }
77
78     if (count ($catz) > 0) {
79       echo ("<h3>Nach Kategorien sortiert</h3>");
80       echo ("<table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">");
81       echo ("<tr><th width=\"70%\">Kategorie</th><th width=\"10%\">Einnahmen</th><th width=\"10%\">Ausgaben</th>"
82            ."<th width=\"10%\">Summe</th></tr>");
83       sort ($catz);
84
85       for ($i=0; $i < count ($catz); $i++) {
86         $query = sprintf ("SELECT SUM (price) FROM sales WHERE category = '%s' AND price > 0.0", $catz[$i]);
87         if (strlen($year)) {
88           $query .= " AND date ~* '$year'";
89         }
90         $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
91         $row = pg_fetch_array ($sth, 0);
92         $input = $row[0]; $sum_input += $input;
93         $query = sprintf ("SELECT SUM (price) FROM sales WHERE category = '%s' AND price < 0.0", $catz[$i]);
94         if (strlen($year)) {
95           $query .= " AND date ~* '$year'";
96         }
97         $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
98         $row = pg_fetch_array ($sth, 0);
99         $output = -$row[0]; $sum_output += $output;
100
101         printf ("<tr><td width=\"70%%\">%s</td><td align=\"right\" width=\"10%%\">%.2f</td>"
102                ."<td align=\"right\" width=\"10%%\">%.2f</td>"
103                ."<td align=\"right\" width=\"10%%\">%.2f</td></tr>",$catz[$i], $input, $output, $input - $output);
104       }
105
106       printf ("<tr><td width=\"70%%\">Summe</td><td align=\"right\" width=\"10%%\">%.2f</td>"
107              ."<td align=\"right\" width=\"10%%\">%.2f</td>"
108              ."<td align=\"right\" width=\"10%%\">%.2f</td></tr>",$sum_input, $sum_output, $sum_input - $sum_output);
109       echo ("</table>");
110
111     }
112   }
113 ?>
114 </table><p>
115
116 <a href="edit.php3">Neuer Eintrag</a><p>
117
118
119 </page>
120
121 # Local variables:
122 # mode: text
123 # mode: auto-fill
124 # mode: iso-accents
125 # end: