2012-09-29 17:52:25 +02:00
|
|
|
class AppleBar
|
2012-10-06 17:14:57 +02:00
|
|
|
attr_reader :ordergroup
|
2012-09-29 17:52:25 +02:00
|
|
|
|
|
|
|
def initialize(ordergroup)
|
|
|
|
@ordergroup = ordergroup
|
|
|
|
@group_avg = ordergroup.avg_jobs_per_euro.to_f
|
|
|
|
@global_avg = Ordergroup.avg_jobs_per_euro
|
|
|
|
end
|
|
|
|
|
|
|
|
# Show group bar in following colors:
|
|
|
|
# Green if higher than 100
|
|
|
|
# Yellow if lower than 100 an higher than stop_ordering_under option value
|
|
|
|
# Red if below stop_ordering_under, the ordergroup isn't allowed to participate in an order anymore
|
2012-10-06 17:14:57 +02:00
|
|
|
def group_bar_state
|
2012-09-29 17:52:25 +02:00
|
|
|
if apples >= 100
|
2012-10-06 17:14:57 +02:00
|
|
|
'success'
|
2023-01-06 16:27:41 +01:00
|
|
|
elsif FoodsoftConfig[:stop_ordering_under].present? &&
|
|
|
|
(apples >= FoodsoftConfig[:stop_ordering_under])
|
|
|
|
'warning'
|
2012-09-29 17:52:25 +02:00
|
|
|
else
|
2023-01-06 16:27:41 +01:00
|
|
|
'danger'
|
2012-09-29 17:52:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-06 17:14:57 +02:00
|
|
|
# Use apples as percentage, but show at least 10 percent
|
|
|
|
def group_bar_width
|
2023-01-06 16:27:41 +01:00
|
|
|
[@ordergroup.apples, 2].max
|
2012-10-06 17:14:57 +02:00
|
|
|
end
|
|
|
|
|
2012-09-29 17:52:25 +02:00
|
|
|
def mean_order_amount_per_job
|
2023-01-06 16:27:41 +01:00
|
|
|
(1 / @global_avg).round
|
2023-05-12 13:01:12 +02:00
|
|
|
rescue StandardError
|
2023-01-06 16:27:41 +01:00
|
|
|
0
|
2012-09-29 17:52:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def apples
|
|
|
|
@apples ||= @ordergroup.apples
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_restriction?
|
|
|
|
FoodsoftConfig[:stop_ordering_under].present?
|
|
|
|
end
|
2021-03-01 15:27:26 +01:00
|
|
|
end
|