2012-08-24 11:11:40 +02:00
|
|
|
module GroupOrdersHelper
|
2011-06-19 15:30:33 +02:00
|
|
|
def data_to_js(ordering_data)
|
2011-06-19 19:56:04 +02:00
|
|
|
ordering_data[:order_articles].map { |id, data|
|
|
|
|
[id, data[:price], data[:unit], data[:total_price], data[:others_quantity], data[:others_tolerance], data[:used_quantity], data[:quantity_available]]
|
|
|
|
}.map { |row|
|
|
|
|
"addData(#{row.join(', ')});"
|
|
|
|
}.join("\n")
|
2011-06-19 15:30:33 +02:00
|
|
|
end
|
|
|
|
|
2011-06-19 19:56:04 +02:00
|
|
|
def link_to_ordering(order, options = {})
|
2011-06-19 15:30:33 +02:00
|
|
|
path = if group_order = order.group_order(current_user.ordergroup)
|
|
|
|
edit_group_order_path(group_order, :order_id => order.id)
|
|
|
|
else
|
|
|
|
new_group_order_path(:order_id => order.id)
|
|
|
|
end
|
2011-06-19 19:56:04 +02:00
|
|
|
link_to order.name, path, options
|
2011-06-19 15:30:33 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Return css class names for order result table
|
2011-06-19 19:56:04 +02:00
|
|
|
|
2011-06-19 15:30:33 +02:00
|
|
|
def order_article_class_name(quantity, tolerance, result)
|
|
|
|
if (quantity + tolerance > 0)
|
|
|
|
result > 0 ? 'success' : 'failed'
|
|
|
|
else
|
|
|
|
'ignored'
|
|
|
|
end
|
|
|
|
end
|
2012-12-16 16:50:09 +01:00
|
|
|
|
|
|
|
def get_order_results(order_article, group_order_id)
|
|
|
|
goa = order_article.group_order_articles.detect { |goa| goa.group_order_id == group_order_id }
|
|
|
|
quantity, tolerance, result, sub_total = if goa.present?
|
|
|
|
[goa.quantity, goa.tolerance, goa.result, goa.total_price(order_article)]
|
|
|
|
else
|
|
|
|
[0, 0, 0, 0]
|
|
|
|
end
|
|
|
|
|
|
|
|
{group_order_article: goa, quantity: quantity, tolerance: tolerance, result: result, sub_total: sub_total}
|
|
|
|
end
|
2011-06-19 15:30:33 +02:00
|
|
|
end
|