Add option to restrict ordering when not enough apples.

This commit is contained in:
benni 2012-09-29 17:52:25 +02:00
parent d3abc03e56
commit ff4ab44bcc
11 changed files with 104 additions and 28 deletions

View file

@ -5,6 +5,7 @@ class GroupOrdersController < ApplicationController
before_filter :ensure_ordergroup_member
before_filter :ensure_open_order, :only => [:new, :create, :edit, :update, :order, :stock_order, :saveOrder]
before_filter :ensure_my_group_order, only: [:show, :edit, :update]
before_filter :enough_apples?, only: [:new, :create]
# Index page.
def index
@ -88,4 +89,12 @@ class GroupOrdersController < ApplicationController
redirect_to group_orders_url, alert: 'Fehlerhafte URL, das ist nicht Deine Bestellung.'
end
def enough_apples?
if @ordergroup.not_enough_apples?
redirect_to group_orders_url,
alert: t('not_enough_apples', scope: 'group_orders.messages', apples: @ordergroup.apples,
stop_ordering_under: FoodsoftConfig[:stop_ordering_under])
end
end
end

View file

@ -72,6 +72,15 @@ class Ordergroup < Group
((avg_jobs_per_euro / Ordergroup.avg_jobs_per_euro) * 100).to_i rescue 0
end
# If the the option stop_ordering_under is set, the ordergroup is only allowed to participate in an order,
# when the apples value is above the configured amount.
# Only ordergroups, which have participated in more than 5 order are affected
def not_enough_apples?
FoodsoftConfig[:stop_ordering_under].present? and
apples < FoodsoftConfig[:stop_ordering_under] and
group_orders.count > 5
end
# Global average
def self.avg_jobs_per_euro
stats = Ordergroup.all.collect(&:stats)

View file

@ -0,0 +1,14 @@
Engagement Deiner Bestellgruppe
.stats-bar{style: "width:#{apple_bar.length_of_group_bar}px; background-color:#{apple_bar.group_bar_color}"}
= apple_bar.apples
= " Äpfel" if apple_bar.length_of_group_bar > 50
Durchschnittsengagement
.stats-bar{style: "width:#{apple_bar.length_of_global_bar}px"}
100 Birnen
%span.description
Abgebildet ist das Verhältnis von erledigten Aufgaben zu dem Bestellvolumen Deiner Bestellgruppe im Vergleich zum Durchschnitt in der Foodcoop.
Konkret: Pro #{number_to_currency(apple_bar.mean_order_amount_per_job, :precision => 0 )} Bestellsumme solltest Du eine Aufgabe machen!
- if FoodsoftConfig[:stop_ordering_under].present?
Achtung, hast Du weniger als #{FoodsoftConfig[:stop_ordering_under]} Äpfel, darfst Du nicht mehr bestellen!

View file

@ -1,27 +0,0 @@
<%
max_width = 600
global_avg = Ordergroup.avg_jobs_per_euro
group_avg = ordergroup.avg_jobs_per_euro.to_f
unless global_avg == 0 or global_avg.nan?
length_of_global_bar = max_width / 2.0
length_of_group_bar = (group_avg / global_avg) * length_of_global_bar
length_of_group_bar = max_width if length_of_group_bar > max_width
color = group_avg >= global_avg ? "#78b74e" : "red"
%>
Engagement Deiner Bestellgruppe
<div class="stats-bar" style="width:<%= length_of_group_bar -%>px; background-color:<%= color -%>">
<%= ordergroup.apples -%><%= " Äpfel" if length_of_group_bar > 50 -%>
</div>
Durchschnittsengagement
<div class="stats-bar" style="width:<%= length_of_global_bar -%>px">
100 Birnen
</div>
<span class="description">
Abgebildet ist das Verhältnis von erledigten Aufgaben zu dem Bestellvolumen Deiner Bestellgruppe im Vergleich zum Durchschnitt in der Foodcoop.
Konkret: Pro <%= number_to_currency( (1/global_avg).round, :precision => 0 ) %> Bestellsumme solltest Du eine Aufgabe machen!
</span>
<%- end -%>

View file

@ -36,7 +36,7 @@
.box_title
%h2 Engagement Deiner Bestellgruppe
.column_content
= render :partial => "stats", :locals => {:ordergroup => current_user.ordergroup}
= render :partial => "apple_bar", :locals => {:apple_bar => AppleBar.new(current_user.ordergroup)}
- unless Message.public.empty?
.box_title

View file

@ -1,6 +1,9 @@
.box_title
%h2 Laufende Bestellungen
.column_content
- if ordergroup.not_enough_apples?
.warning
%p Achtung, Deine Bestellgruppe hat zu wenig Äpfel um Bestellen zu können!
- unless Order.open.empty?
%table.list
%thead