$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>' .
+ $out .= sprintf('<tr id="%d"><td>%s</td><td>%s</td><td><span route="SpritLog/EditTankstelle" item_id="%d">%s</span></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->city, $row->id, $row->tankstelle,
$row->price_liter, $row->liter,$row->price,
$row->km, $row->km_total);
$total_km += $row->km;
'</tr></tfoot>' .
'</table>';
}
- return $out;
+ return array($out, $total_liter, $total_price, $total_km);
}
public function ajaxList(Array $data)
{
- return array('html' => array('list_'.$data['year'] => $this->formatYear($data['year'])));
+ list($table, $liter, $price, $km) = $this->formatYear($data['year']);
+
+ return array('html' => array('list_'.$data['year'] => $table,
+ 'sum_'.$data['year'] => sprintf('€ %.2f %d km', $price, $km),
+ ));
}
public function ajaxAdd(Array $data)
$d = explode('-', $data['date']);
return array('status' => $ok, 'year' => $d[0]);
+ }
+
+ public function ajaxSuggestCity(Array $data)
+ {
+ $data['query'] .= '%';
+ $sql = sprintf("SELECT DISTINCT city FROM sprit_log WHERE lower(city) LIKE %s ORDER BY city",
+ $this->quote(strtolower($data['query'])));
+ $list = array();
+ foreach ($this->fetchObjectList($sql) as $row)
+ $list[] = array('value' => $row->city, 'data' => $row->city);
+ return array('suggestions' => $list);
+ }
+ public function ajaxSuggestTankstelle(Array $data)
+ {
+ $data['query'] .= '%';
+ $sql = sprintf("SELECT DISTINCT tankstelle FROM sprit_log WHERE city = %s AND lower(tankstelle) LIKE %s ORDER BY tankstelle",
+ $this->quote($data['city']),
+ $this->quote(strtolower($data['query'])));
+ $list = array();
+ foreach ($this->fetchObjectList($sql) as $row)
+ $list[] = array('value' => $row->tankstelle, 'data' => $row->tankstelle);
+ return array('suggestions' => $list);
}
+
+ public function ajaxEditTankstelle(Array $data)
+ {
+ if (!strlen($data['content'])) return false;
+ return $this->modify('tankstelle', $data['content']);
+ }
+
}