2009-01-06 11:49:19 +01:00
|
|
|
|
module OrdersHelper
|
2021-03-01 15:27:26 +01:00
|
|
|
|
def update_articles_link(order, text, view, options = {})
|
|
|
|
|
options = { remote: true, id: "view_#{view}_btn", class: '' }.merge(options)
|
2014-01-17 15:03:46 +01:00
|
|
|
|
options[:class] += ' active' if view.to_s == @view.to_s
|
2014-01-17 13:14:49 +01:00
|
|
|
|
link_to text, order_path(order, view: view), options
|
2009-01-29 01:57:51 +01:00
|
|
|
|
end
|
|
|
|
|
|
2014-06-04 09:41:00 +02:00
|
|
|
|
# @param order [Order]
|
|
|
|
|
# @param document [String] Document to display, one of +groups+, +articles+, +fax+, +matrix+
|
|
|
|
|
# @param text [String] Link text
|
2015-04-10 21:30:04 +02:00
|
|
|
|
# @param options [Hash] Options passed to +link_to+
|
2014-06-04 09:41:00 +02:00
|
|
|
|
# @return [String] Link to order document
|
|
|
|
|
# @see OrdersController#show
|
2021-03-01 15:27:26 +01:00
|
|
|
|
def order_pdf(order, document, text, options = {})
|
2015-04-10 21:30:04 +02:00
|
|
|
|
options = options.merge(title: I18n.t('helpers.orders.order_pdf'))
|
|
|
|
|
link_to text, order_path(order, document: document, format: :pdf), options
|
2009-01-06 11:49:19 +01:00
|
|
|
|
end
|
2009-02-11 15:23:59 +01:00
|
|
|
|
|
|
|
|
|
def options_for_suppliers_to_select
|
2013-04-10 17:29:06 +02:00
|
|
|
|
options = [[I18n.t('helpers.orders.option_choose')]]
|
2021-03-01 15:27:26 +01:00
|
|
|
|
options += Supplier.map { |s| [s.name, url_for(action: "new", supplier_id: s.id)] }
|
2020-08-13 16:23:01 +02:00
|
|
|
|
options += [[I18n.t('helpers.orders.option_stock'), url_for(action: 'new', supplier_id: nil)]]
|
2011-06-10 13:53:51 +02:00
|
|
|
|
options_for_select(options)
|
2009-02-11 15:23:59 +01:00
|
|
|
|
end
|
2013-12-18 22:08:02 +01:00
|
|
|
|
|
2014-01-23 16:17:16 +01:00
|
|
|
|
# "1×2 ordered, 2×2 billed, 2×2 received"
|
2021-03-01 15:27:26 +01:00
|
|
|
|
def units_history_line(order_article, options = {})
|
2013-12-18 22:08:02 +01:00
|
|
|
|
if order_article.order.open?
|
|
|
|
|
nil
|
|
|
|
|
else
|
2014-01-31 14:04:16 +01:00
|
|
|
|
units_info = []
|
2014-01-31 13:07:13 +01:00
|
|
|
|
[:units_to_order, :units_billed, :units_received].map do |unit|
|
|
|
|
|
if n = order_article.send(unit)
|
2014-01-31 14:04:16 +01:00
|
|
|
|
line = n.to_s + ' '
|
2014-01-23 16:17:16 +01:00
|
|
|
|
line += pkg_helper(order_article.price, options) + ' ' unless n == 0
|
|
|
|
|
line += OrderArticle.human_attribute_name("#{unit}_short", count: n)
|
2014-01-31 14:04:16 +01:00
|
|
|
|
units_info << line
|
2014-01-31 13:07:13 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2014-01-31 14:04:16 +01:00
|
|
|
|
units_info.join(', ').html_safe
|
2013-12-18 22:08:02 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2014-01-02 22:30:04 +01:00
|
|
|
|
|
2014-06-04 09:41:00 +02:00
|
|
|
|
# @param article [Article]
|
|
|
|
|
# @option options [String] :icon +false+ to hide the icon
|
|
|
|
|
# @option options [String] :plain +true+ to not use HTML (implies +icon+=+false+)
|
|
|
|
|
# @option options [String] :soft_uq +true+ to hide unit quantity specifier on small screens.
|
|
|
|
|
# Sensible in tables with multiple columns.
|
|
|
|
|
# @return [String] Text showing unit and unit quantity when applicable.
|
2021-03-01 15:27:26 +01:00
|
|
|
|
def pkg_helper(article, options = {})
|
2015-01-14 21:15:08 +01:00
|
|
|
|
return '' if !article || article.unit_quantity == 1
|
2021-03-01 15:27:26 +01:00
|
|
|
|
|
2014-01-23 16:17:16 +01:00
|
|
|
|
uq_text = "× #{article.unit_quantity}"
|
2014-01-09 13:01:10 +01:00
|
|
|
|
uq_text = content_tag(:span, uq_text, class: 'hidden-phone') if options[:soft_uq]
|
2014-01-23 16:17:16 +01:00
|
|
|
|
if options[:plain]
|
|
|
|
|
uq_text
|
2015-01-14 21:15:08 +01:00
|
|
|
|
elsif options[:icon].nil? || 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
|
2021-03-01 15:27:26 +01:00
|
|
|
|
|
2014-06-04 09:41:00 +02:00
|
|
|
|
# @param c [Symbol, String] Tag to use
|
|
|
|
|
# @option options [String] :class CSS class(es) (in addition to +package+)
|
|
|
|
|
# @return [String] Icon used for displaying the unit quantity
|
2021-03-01 15:27:26 +01:00
|
|
|
|
def pkg_helper_icon(c = nil, options = {})
|
|
|
|
|
options = { tag: 'i', class: '' }.merge(options)
|
2014-01-09 12:17:25 +01:00
|
|
|
|
if c.nil?
|
2014-01-09 13:01:10 +01:00
|
|
|
|
c = " ".html_safe
|
2014-01-09 12:17:25 +01:00
|
|
|
|
options[:class] += " icon-only"
|
|
|
|
|
end
|
2014-01-09 13:01:10 +01:00
|
|
|
|
content_tag(options[:tag], c, class: "package #{options[:class]}").html_safe
|
2014-01-09 12:17:25 +01:00
|
|
|
|
end
|
2015-04-10 21:30:04 +02:00
|
|
|
|
|
2021-03-01 15:27:26 +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
|
2021-03-01 15:27:26 +01:00
|
|
|
|
|
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
|
2014-01-02 21:59:08 +01:00
|
|
|
|
end
|
2015-04-10 21:30:04 +02:00
|
|
|
|
|
2014-01-03 10:33:09 +01:00
|
|
|
|
def receive_input_field(form)
|
|
|
|
|
order_article = form.object
|
2015-01-14 21:15:08 +01:00
|
|
|
|
units_expected = (order_article.units_billed || order_article.units_to_order) *
|
2021-03-01 15:27:26 +01:00
|
|
|
|
1.0 * order_article.article.unit_quantity / order_article.article_price.unit_quantity
|
2015-04-10 21:30:04 +02:00
|
|
|
|
|
2014-01-13 11:37:18 +01:00
|
|
|
|
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,
|
2021-03-01 15:27:26 +01:00
|
|
|
|
data: { 'units-expected' => units_expected },
|
|
|
|
|
disabled: order_article.result_manually_changed?,
|
|
|
|
|
autocomplete: 'off'
|
2015-04-10 21:30:04 +02:00
|
|
|
|
|
2014-01-09 13:01:10 +01:00
|
|
|
|
if order_article.result_manually_changed?
|
2014-09-15 13:47:21 +02:00
|
|
|
|
input_html = content_tag(:span, class: 'input-prepend intable', title: t('orders.edit_amount.field_locked_title', default: '')) {
|
2014-01-09 13:01:10 +01:00
|
|
|
|
button_tag(nil, type: :button, class: 'btn unlocker') {
|
|
|
|
|
content_tag(:i, nil, class: 'icon icon-unlock')
|
|
|
|
|
} + input_html
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2014-01-03 22:26:20 +01:00
|
|
|
|
input_html.html_safe
|
2014-01-03 10:33:09 +01:00
|
|
|
|
end
|
2014-01-17 14:25:06 +01:00
|
|
|
|
|
2014-06-04 09:41:00 +02:00
|
|
|
|
# @param order [Order]
|
|
|
|
|
# @return [String] Number of ordergroups participating in order with groups in title.
|
2014-01-17 14:25:06 +01:00
|
|
|
|
def ordergroup_count(order)
|
|
|
|
|
group_orders = order.group_orders.includes(:ordergroup)
|
|
|
|
|
txt = "#{group_orders.count} #{Ordergroup.model_name.human count: group_orders.count}"
|
|
|
|
|
if group_orders.count == 0
|
|
|
|
|
return txt
|
|
|
|
|
else
|
2021-03-01 15:27:26 +01:00
|
|
|
|
desc = group_orders.includes(:ordergroup).map { |g| g.ordergroup_name }.join(', ')
|
2014-01-17 14:25:06 +01:00
|
|
|
|
content_tag(:abbr, txt, title: desc).html_safe
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-06-04 09:41:00 +02:00
|
|
|
|
# @param order_or_supplier [Order, Supplier] Order or supplier to link to
|
|
|
|
|
# @return [String] Link to order or supplier, showing its name.
|
2014-01-17 14:25:06 +01:00
|
|
|
|
def supplier_link(order_or_supplier)
|
2015-01-14 21:15:08 +01:00
|
|
|
|
if order_or_supplier.kind_of?(Order) && order_or_supplier.stockit?
|
2014-01-17 14:25:06 +01:00
|
|
|
|
link_to(order_or_supplier.name, stock_articles_path).html_safe
|
|
|
|
|
else
|
|
|
|
|
link_to(@order.supplier.name, supplier_path(@order.supplier)).html_safe
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-06-04 09:41:00 +02:00
|
|
|
|
|
|
|
|
|
# @param order_article [OrderArticle]
|
2014-06-04 10:05:18 +02:00
|
|
|
|
# @return [String] CSS class for +OrderArticle+ in table for admins (+used+, +partused+, +unused+ or +unavailable+).
|
2014-06-04 09:41:00 +02:00
|
|
|
|
def order_article_class(order_article)
|
|
|
|
|
if order_article.units > 0
|
2014-06-04 10:05:18 +02:00
|
|
|
|
if order_article.missing_units == 0
|
|
|
|
|
'used'
|
|
|
|
|
else
|
|
|
|
|
'partused'
|
|
|
|
|
end
|
2014-06-04 09:41:00 +02:00
|
|
|
|
elsif order_article.quantity > 0
|
|
|
|
|
'unused'
|
|
|
|
|
else
|
|
|
|
|
'unavailable'
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-04-10 21:25:09 +02:00
|
|
|
|
|
|
|
|
|
# Button for receiving an order.
|
|
|
|
|
# If the order hasn't been received before, the button is shown in green.
|
|
|
|
|
# @param order [Order]
|
|
|
|
|
# @option options [String] :class Classes added to the button's class attribute.
|
|
|
|
|
# @return [String] Order receive button.
|
2021-03-01 15:27:26 +01:00
|
|
|
|
def receive_button(order, options = {})
|
2015-04-10 21:25:09 +02:00
|
|
|
|
if order.stockit?
|
|
|
|
|
content_tag :div, t('orders.index.action_receive'), class: "btn disabled #{options[:class]}"
|
|
|
|
|
else
|
2021-02-05 11:55:41 +01:00
|
|
|
|
link_to t('orders.index.action_receive'), receive_order_path(order), class: "btn#{' btn-success' unless order.received?} #{options[:class]}"
|
2015-04-10 21:25:09 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2023-02-14 16:52:19 +01:00
|
|
|
|
|
|
|
|
|
def custom_csv_collection
|
|
|
|
|
[
|
|
|
|
|
OrderArticle.human_attribute_name(:units_to_order),
|
|
|
|
|
Article.human_attribute_name(:order_number),
|
|
|
|
|
Article.human_attribute_name(:name),
|
|
|
|
|
Article.human_attribute_name(:unit),
|
|
|
|
|
Article.human_attribute_name(:unit_quantity_short),
|
|
|
|
|
ArticlePrice.human_attribute_name(:price),
|
|
|
|
|
OrderArticle.human_attribute_name(:total_price)
|
|
|
|
|
]
|
|
|
|
|
end
|
2009-01-06 11:49:19 +01:00
|
|
|
|
end
|