--- /dev/null
+<?php
+
+class SpritLog extends DatabaseTable {
+
+ public function __construct($id=false)
+ {
+ parent::__construct('sprit_log', $id);
+ }
+
+ public function distinctYears()
+ {
+ $sql = "SELECT DISTINCT EXTRACT(YEAR from date) AS year FROM sprit_log ORDER BY year DESC";
+ return $this->db->fetchObjectList($sql);
+ }
+
+ public function formatYear($year)
+ {
+ $out = '';
+ $sql = sprintf("SELECT * FROM sprit_log WHERE EXTRACT(YEAR from date) = %d ORDER BY date ASC", $year);;
+
+ $total_km = 0;
+ $total_liter = 0;
+ $total_price = 0;
+ foreach ($this->db->fetchObjectList($sql) as $row) {
+ $out .= sprintf('<tr id="%d"><td>%s</td><td>%s</td><td>%s</td>' .
+ '<td class="right">%.2f</td><td class="right">%.2f</td><td class="right">%.2f</td>' .
+ '<td class="right">%d</td><td class="right">%d</td></tr>',
+ $row->id, assert_german_date($row->date),
+ $row->city, $row->tankstelle,
+ $row->price_liter, $row->liter,$row->price,
+ $row->km, $row->km_total);
+ $total_km += $row->km;
+ $total_liter += $row->liter;
+ $total_price += $row->price;
+ }
+
+ if (strlen($out)) {
+ $out = '<table class="smallfont" width="100%">' .
+ '<thead><tr>' .
+ '<th width="70">Datum</th><th width="130" class="left">Ort</th><th class="left">Tankstelle</th>' .
+ '<th width="40">EUR/l</th><th width="40">l</th><th width="40">EUR</th><th width="40">km</th><th width="40">gesamt</th>' .
+ '</tr></thead>' .
+ $out .
+ '<tfoot><tr>' .
+ '<th colspan="4" class="left">Summe</th>' .
+ sprintf('<th class="right">%.2f</th><th class="right">%.2f</th><th class="right">%d</th><th> </th>',
+ $total_liter, $total_price, $total_km).
+ '</tr></tfoot>' .
+ '</table>';
+ }
+ return $out;
+ }
+
+}
+