foodsoft/app/helpers/orders_helper.rb

82 lines
3.4 KiB
Ruby
Raw Normal View History

# encoding: utf-8
2009-01-06 11:49:19 +01:00
module OrdersHelper
def update_articles_link(order, text, view)
link_to text, order_path(order, view: view), remote: true
end
def order_pdf(order, document, text)
2013-04-10 17:29:06 +02:00
link_to text, order_path(order, document: document, format: :pdf), title: I18n.t('helpers.orders.order_pdf')
2009-01-06 11:49:19 +01:00
end
def options_for_suppliers_to_select
2013-04-10 17:29:06 +02:00
options = [[I18n.t('helpers.orders.option_choose')]]
options += Supplier.all.map {|s| [ s.name, url_for(action: "new", supplier_id: s)] }
2013-04-10 17:29:06 +02:00
options += [[I18n.t('helpers.orders.option_stock'), url_for(action: 'new', supplier_id: 0)]]
2011-06-10 13:53:51 +02:00
options_for_select(options)
end
2013-12-18 22:08:02 +01:00
def units_history_line(order_article)
if order_article.order.open?
nil
else
2014-01-08 13:39:49 +01:00
units_info = "#{order_article.units_to_order} #{OrderArticle.human_attribute_name :units_to_order, count: order_article.units_to_order}"
units_info += ", #{order_article.units_billed} #{OrderArticle.human_attribute_name :units_billed_short, count: order_article.units_billed}" unless order_article.units_billed.nil?
units_info += ", #{order_article.units_received} #{OrderArticle.human_attribute_name :units_received_short, count: order_article.units_received}" unless order_article.units_received.nil?
2013-12-18 22:08:02 +01:00
end
end
2014-01-02 22:30:04 +01:00
# can be article or article_price
# icon: `false` to not show the icon
# soft_uq: `true` to hide unit quantity specifier on small screens
# sensible in tables with multiple columns calling `pkg_helper`
def pkg_helper(article, options={})
2014-01-03 12:42:36 +01:00
return nil if article.unit_quantity == 1
2014-01-09 13:01:10 +01:00
uq_text = "× #{article.unit_quantity}".html_safe
uq_text = content_tag(:span, uq_text, class: 'hidden-phone') if options[:soft_uq]
if options[:icon].nil? or options[:icon]
2014-01-09 13:01:10 +01:00
pkg_helper_icon(uq_text)
2014-01-02 22:30:04 +01:00
else
2014-01-09 13:01:10 +01:00
pkg_helper_icon(uq_text, tag: :span)
2014-01-02 22:30:04 +01:00
end
end
def pkg_helper_icon(c=nil, options={})
options = {tag: 'i', class: ''}.merge(options)
if c.nil?
2014-01-09 13:01:10 +01:00
c = " ".html_safe
options[:class] += " icon-only"
end
2014-01-09 13:01:10 +01:00
content_tag(options[:tag], c, class: "package #{options[:class]}").html_safe
end
2014-01-03 12:42:36 +01:00
def article_price_change_hint(order_article, gross=false)
2014-01-03 13:00:14 +01:00
return nil if order_article.article.price == order_article.price.price
2014-01-03 14:11:50 +01:00
title = "#{t('helpers.orders.old_price')}: #{number_to_currency order_article.article.price}"
2014-01-03 12:42:36 +01:00
title += " / #{number_to_currency order_article.article.gross_price}" if gross
2014-01-09 13:01:10 +01:00
content_tag(:i, nil, class: 'icon-asterisk', title: j(title)).html_safe
end
def receive_input_field(form)
order_article = form.object
units_expected = (order_article.units_billed or order_article.units_to_order) *
1.0 * order_article.article.unit_quantity / order_article.article_price.unit_quantity
input_classes = 'input input-nano units_received'
input_classes += ' package' unless order_article.article_price.unit_quantity == 1
input_html = form.text_field :units_received, class: input_classes,
data: {'units-expected' => units_expected},
disabled: order_article.result_manually_changed?,
autocomplete: 'off'
2014-01-09 13:01:10 +01:00
if order_article.result_manually_changed?
input_html = content_tag(:span, class: 'input-prepend intable', title: t('.field_locked_title', default: '')) {
button_tag(nil, type: :button, class: 'btn unlocker') {
content_tag(:i, nil, class: 'icon icon-unlock')
} + input_html
}
end
input_html.html_safe
end
2009-01-06 11:49:19 +01:00
end