From: Joey Schulze Date: Sun, 17 Jul 2016 20:33:16 +0000 (+0200) Subject: Simple sprit accounting module X-Git-Url: https://git.infodrom.org/?p=infodrom.org%2Fservice.infodrom.org;a=commitdiff_plain;h=3ec1026a03f1af926a3d1048d0c7c10d3fb4ab25;ds=sidebyside Simple sprit accounting module --- diff --git a/class/spritlog.class.php b/class/spritlog.class.php new file mode 100644 index 0000000..2e501e4 --- /dev/null +++ b/class/spritlog.class.php @@ -0,0 +1,55 @@ +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('%s%s%s' . + '%.2f%.2f%.2f' . + '%d%d', + $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 = '' . + '' . + '' . + '' . + '' . + $out . + '' . + '' . + sprintf('', + $total_liter, $total_price, $total_km). + '' . + '
DatumOrtTankstelleEUR/llEURkmgesamt
Summe%.2f%.2f%d 
'; + } + return $out; + } + +} + diff --git a/src/InfoCon/sprit/index.wml b/src/InfoCon/sprit/index.wml new file mode 100644 index 0000000..8c00f34 --- /dev/null +++ b/src/InfoCon/sprit/index.wml @@ -0,0 +1,67 @@ +#include + + + + + +
    +
+Neues Fahrzeug + + + +
+ + + + diff --git a/src/InfoCon/sprit/list.wml b/src/InfoCon/sprit/list.wml new file mode 100644 index 0000000..c66cbed --- /dev/null +++ b/src/InfoCon/sprit/list.wml @@ -0,0 +1,103 @@ +#include + + + + + + + + + +distinctYears(); + foreach ($list as $row) { + printf('

%d

', $row->year, $row->year); + printf('
', $row->year); + } + if (count($list)) { + $out = << +$(function(){ + load_year({$list[0]->year}); + $('h3.year').click(function(e){ + var year = \$(this).attr('year'); + load_year(year); + }); +}); + +EOT; +echo $out; + } +?> + +
+ diff --git a/src/InfoCon/sprit/moduleajaxbackend.class.php b/src/InfoCon/sprit/moduleajaxbackend.class.php new file mode 100644 index 0000000..8684bba --- /dev/null +++ b/src/InfoCon/sprit/moduleajaxbackend.class.php @@ -0,0 +1,73 @@ +db->fetchObjectList($sql) as $row) { + $out .= sprintf('
  • %s ', $row->name); + $out .= '
    '; + $out .= sprintf('', $row->id); + $out .= sprintf('', + $this->relativeRootPath());; + $out .= '
    '; + $out .= '
  • '; + } + return array('status' => true, 'list' => $out);; + } + + public function savemachine() + { + if (empty($_POST['id'])) { + $sql = sprintf("INSERT INTO sprit_machine (name,active,sys_user,sys_edit) " . + "VALUES (%s,1,%s,now())", + $this->db->quote(utf8_decode($_POST['name'])), + $this->db->quote($_SERVER['REMOTE_USER'])); + } else { + $sql = sprintf("UPDATE sprit_machine SET name=%s,sys_edit=now(),sys_user=%s WHERE id = %d", + $this->db->quote(utf8_decode($_POST['name'])), + $this->db->quote($_SERVER['REMOTE_USER']), + $_POST['id']); + } + return array('status' => $this->db->execute($sql)); + } + + public function savelog() + { + $data = array('machine' => intval($_POST['machine']), + 'date' => assert_iso_date($_POST['date']), + 'city' => $_POST['city'], + 'tankstelle' => $_POST['tankstelle'], + 'price_liter' => str_replace(',','.',$_POST['price_liter']), + 'liter' => str_replace(',','.',$_POST['liter']), + 'price' => str_replace(',','.',$_POST['price']), + 'km' => intval($_POST['km']), + 'km_total' => intval($_POST['km_total']), + 'sys_edit' => 'now()', + 'sys_user' => $_SERVER['REMOTE_USER']); + + foreach ($data as $k => $v) + if (empty($v)) + json_error(sprintf('Field %s must not be empty', $k)); + + if (empty($_POST['id'])) { + $ok = $this->db->insertInto('sprit_log', $data); + } else { + $ok = $this->db->update('sprit_log', $data, 'id = ' . intval($_POST['id'])); + } + + $d = explode('-', $data['date']); + return array('status' => $ok, 'year' => $d[0]); + } + + public function loadyear() + { + $log = new SpritLog(); + return array('status' => true, + 'list' => $log->formatYear($_POST['year']), + 'year' => $_POST['year']); + } + +} diff --git a/src/InfoCon/sprit/submenu.inc b/src/InfoCon/sprit/submenu.inc new file mode 100644 index 0000000..af47d24 --- /dev/null +++ b/src/InfoCon/sprit/submenu.inc @@ -0,0 +1,17 @@ +Menu
    + + 
    + +" "list" />> + Neuer Eintrag + + + + +#include "../functions.inc" prefix="../" + +# Local variables: +# mode: indented-text +# mode: auto-fill +# mode: iso-accents +# end: