Commit c9ba0f0f authored by Johannes Knödtel's avatar Johannes Knödtel 🎶
Browse files

add tables for too much or too little food

fixes #15
parent eb41e368
......@@ -309,6 +309,60 @@
</ul>
</div>
</div>
<div class="row">
<div class=" col s12">
<h4>Zu Viel</h4>
<table class="highlight">
<thead>
<tr>
<th>Fressen</th>
<th>Extra-Würste</th>
<th>Wunsch</th>
<th>Gekauft</th>
<th>Differenz</th>
</tr>
</thead>
<tbody>
{% for item in too_much %}
<tr>
<td>{{item.food_name}}</td>
<td>{{item.comment}}</td>
<td>{{item.number}}</td>
<td>{{item.total_ammount}}</td>
<td>{{item.difference}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="row">
<div class=" col s12">
<h4>Zu Wenig</h4>
<table class="highlight">
<thead>
<tr>
<th>Fressen</th>
<th>Extra-Würste</th>
<th>Wunsch</th>
<th>Gekauft</th>
<th>Differenz</th>
</tr>
</thead>
<tbody>
{% for item in too_little %}
<tr>
<td>{{item.food_name}}</td>
<td>{{item.comment}}</td>
<td>{{item.number}}</td>
<td>{{item.total_ammount}}</td>
<td>{{item.difference}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
......
......@@ -59,13 +59,22 @@
:food stats})
(group-by (juxt :food_name :comment) numbers)))
(defn add-difference [summed-numbers]
(map #(assoc % :difference (- (:total_ammount %) (:number %))) summed-numbers))
(defn list-page
([session headers] (list-page [] session headers))
([food-options session headers]
(let [items (db/run db/get-food {:session session})
numbers (group-numbers (db/run db/get-food-numbers {:session session}))
summed-numbers (db/run db/get-summed-food-numbers {:session session})
summed-numbers (add-difference (db/run db/get-summed-food-numbers {:session session}))
paid (apply hash-set (mapcat vals (db/run db/get-already-paid {:session session})))
too-much (->> summed-numbers
(filter (comp not (partial > 0.0M) :difference))
(filter (comp pos? :difference)))
too-little (->> summed-numbers
(filter (comp not (partial < 0.0M) :difference))
(filter (comp neg? :difference)))
bills (calculate-user-bills (db/run db/get-bills {:session session}) paid)]
(if (user-agent-curl? headers)
(with-out-str
......@@ -77,6 +86,8 @@
:items items
:food_stats numbers
:summed_food_stats summed-numbers
:too_much too-much
:too_little too-little
:food_options food-options
:bills bills})))))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment