Improvements
authorJoey Schulze <joey@infodrom.org>
Mon, 15 Sep 2008 18:56:30 +0000 (18:56 +0000)
committerJoey Schulze <joey@infodrom.org>
Mon, 15 Sep 2008 18:56:30 +0000 (18:56 +0000)
src/InfoCon/buch/list.wml

index 8bbdca1..faa6f04 100644 (file)
@@ -119,12 +119,13 @@ if ($_POST["submit"] == "List") {
        $color = !$color;
       }
 
-       $sum = $sum_input - $sum_output;
+      $sum = $sum_input - $sum_output;
       printf ("<tr class=\"t%d\"><td width=\"40%%\"><b>Summe</b></td>"
             ."<td align=\"right\" width=\"20%%\"><b>%.2f</b></td>"
             ."<td align=\"right\" width=\"20%%\"><b>%.2f</b></td>"
             ."<td align=\"right\" width=\"20%%\" class=\"%s\"><b>%.2f</b></td></tr>",
              $color, $sum_input, $sum_output, $sum>0?'in':'out', $sum);
+
       echo ("</table></div>");
 
     }
@@ -139,28 +140,44 @@ if ($_POST["submit"] == "List") {
     else
       echo ("<h3>Abrechnung</h3>");
 
-    $output = tally ($dbh, "Ausgaben", $where . "price < 0.0");
+    $input = tally ($dbh, "Einnahmen", $where, 'in');
     echo '<div style="padding-top: 15px;"></div>';
-    $input = tally ($dbh, "Einnahmen", $where . "price > 0.0");
+    $output = tally ($dbh, "Ausgaben", $where, 'out');
 
     if (strlen($_POST[year])) {
+      echo '<div style="padding-top: 15px;"></div>';
+      echo('<table class="smallfont border" cellspacing="1" cellpadding="1">');
       $foo = $input["tax"] - $output["tax"];
-      printf ("<p>Summe Steuern: %.2f", $foo);
-      if ($foo > 0)
-       echo (" (<strong>Nachzahlung</strong>)");
-      elseif ($foo < 0)
-       echo (" (<strong>Rückzahlung</strong>)");
-      printf ("<br>Summe netto: %.2f", $input["netto"] - $output["netto"]);
+      printf('<tr><td>%s</td><td align="right">%.2f&nbsp;&euro;</td><td>(%s)</td></tr>',
+            'Summe Steuern', $foo, $foo>0?'Nachzahlung':'Rückzahlung');
+      printf('<tr><td>%s</td><td align="right">%.2f&nbsp;&euro;</td><td>&nbsp;</td></tr>',
+            'Summe netto', $input["netto"] - $output["netto"]);
       $foo = $input["brutto"] - $output["brutto"];
-      printf ("<br>Summe brutto: %.2f</p>", $foo);
-      if ($foo > 0)
-       echo (" (<strong>Gewinn</strong>)");
-      elseif ($foo < 0)
-       echo (" (<strong>Verlust</strong>)");
+      printf('<tr><td>%s</td><td align="right">%.2f&nbsp;&euro;</td><td>(%s)</td></tr>',
+            'Summe brutto', $foo, $foo>0?'Gewinn':'Verlust');
+      if (($privat = privat($dbh, $where)))
+       printf('<tr><td>%s</td><td align="right">%.2f&nbsp;&euro;</td><td>&nbsp;</td></tr>',
+              'Privatentnahme', $privat);
+      echo('</table>');
     }
   }
 
-function tally ($dbh, $head, $where)
+function privat ($dbh, $where)
+{
+  $query = "SELECT sum(price) * -1 AS privat"
+    . " FROM sales WHERE " . $where
+    . " category = 'privat'";
+
+  error_log($query);
+  $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
+  if (pg_NumRows($sth) != 1)
+    return 0;
+
+  $row = pg_fetch_array ($sth, $nr);
+  return $row['privat'];
+}
+
+function tally ($dbh, $head, $where, $class)
 {
   echo ("<div align=\"center\"><table class=\"smallfont border\" width=\"60%\" cellpadding=\"1\" cellspacing=\"1\" summary=\"\">");
   printf ("<tr class=\"head\"><th colspan=\"4\" align=\"left\"><strong>%s</strong></td></tr>", $head);
@@ -172,6 +189,8 @@ function tally ($dbh, $head, $where)
   
   $query = "SELECT tax_percent,sum(tax_assigned) AS tax,sum(price-tax_assigned) AS netto,sum(price) AS brutto"
     . " FROM sales WHERE " . $where
+    . ($class=='in'?"price > 0.0":"price < 0.0")
+    . " AND category <> 'privat' "
     . " GROUP BY tax_percent ORDER BY tax_percent";
 
   $color = 0;
@@ -202,9 +221,9 @@ function tally ($dbh, $head, $where)
   printf ("<tr class=\"t%d\"><td width=\"10%%\"><b>Sum</b></td>"
          ."<td align=\"right\" width=\"30%%\"><b>%.2f</b></td>"
          ."<td align=\"right\" width=\"30%%\"><b>%.2f</b></td>"
-         ."<td align=\"right\" width=\"30%%\"><b>%.2f</b></td></tr>",
+         ."<td align=\"right\" width=\"30%%\" class=\"%s\"><b>%.2f</b></td></tr>",
          $color,
-         $sum["tax"], $sum["netto"], $sum["brutto"]);
+         $sum["tax"], $sum["netto"], $class, $sum["brutto"]);
 
   echo ("</table></div>\n");