$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>");
}
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 €</td><td>(%s)</td></tr>',
+ 'Summe Steuern', $foo, $foo>0?'Nachzahlung':'Rückzahlung');
+ printf('<tr><td>%s</td><td align="right">%.2f €</td><td> </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 €</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 €</td><td> </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);
$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;
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");