Module: OrdersHelper

Defined in:
app/helpers/orders_helper.rb

Instance Method Summary collapse

Instance Method Details

#article_price_change_hint(order_article, gross = false) ⇒ Object


76
77
78
79
80
81
# File 'app/helpers/orders_helper.rb', line 76

def article_price_change_hint(order_article, gross=false)
  return nil if order_article.article.price == order_article.price.price
  title = "#{t('helpers.orders.old_price')}: #{number_to_currency order_article.article.price}"
  title += " / #{number_to_currency order_article.article.gross_price}" if gross
  (:i, nil, class: 'icon-asterisk', title: j(title)).html_safe
end

#options_for_suppliers_to_selectObject


21
22
23
24
25
26
# File 'app/helpers/orders_helper.rb', line 21

def options_for_suppliers_to_select
  options = [[I18n.t('helpers.orders.option_choose')]]
  options += Supplier.map {|s| [ s.name, url_for(action: "new", supplier_id: s)] }
  options += [[I18n.t('helpers.orders.option_stock'), url_for(action: 'new', supplier_id: 0)]]
  options_for_select(options)
end

#order_article_class(order_article) ⇒ String

Returns CSS class for OrderArticle in table for admins (used, partused, unused or unavailable).

Parameters:

Returns:

  • (String)

    CSS class for OrderArticle in table for admins (used, partused, unused or unavailable).


131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/helpers/orders_helper.rb', line 131

def order_article_class(order_article)
  if order_article.units > 0
    if order_article.missing_units == 0
      'used'
    else
      'partused'
    end
  elsif order_article.quantity > 0
    'unused'
  else
    'unavailable'
  end
end

#order_pdf(order, document, text, options = {}) ⇒ String

Returns Link to order document

Parameters:

  • order (Order)
  • document (String)

    Document to display, one of groups, articles, fax, matrix

  • text (String)

    Link text

  • options (Hash) (defaults to: {})

    Options passed to link_to

Returns:

  • (String)

    Link to order document

See Also:


16
17
18
19
# File 'app/helpers/orders_helper.rb', line 16

def order_pdf(order, document, text, options={})
  options = options.merge(title: I18n.t('helpers.orders.order_pdf'))
  link_to text, order_path(order, document: document, format: :pdf), options
end

#ordergroup_count(order) ⇒ String

Returns Number of ordergroups participating in order with groups in title.

Parameters:

Returns:

  • (String)

    Number of ordergroups participating in order with groups in title.


108
109
110
111
112
113
114
115
116
117
# File 'app/helpers/orders_helper.rb', line 108

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
    desc = group_orders.includes(:ordergroup).map {|g| g.ordergroup_name}.join(', ')
    (:abbr, txt, title: desc).html_safe
  end
end

#pkg_helper(article, options = {}) ⇒ String

Returns Text showing unit and unit quantity when applicable.

Parameters:

  • article (Article)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :icon (String)

    false to hide the icon

  • :plain (String)

    true to not use HTML (implies icon=false)

  • :soft_uq (String)

    true to hide unit quantity specifier on small screens. Sensible in tables with multiple columns.

Returns:

  • (String)

    Text showing unit and unit quantity when applicable.


52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/orders_helper.rb', line 52

def pkg_helper(article, options={})
  return '' if !article || article.unit_quantity == 1
  uq_text = "× #{article.unit_quantity}"
  uq_text = (:span, uq_text, class: 'hidden-phone') if options[:soft_uq]
  if options[:plain]
    uq_text
  elsif options[:icon].nil? || options[:icon]
    pkg_helper_icon(uq_text)
  else
    pkg_helper_icon(uq_text, tag: :span)
  end
end

#pkg_helper_icon(c = nil, options = {}) ⇒ String

Returns Icon used for displaying the unit quantity

Parameters:

  • c (Symbol, String) (defaults to: nil)

    Tag to use

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :class (String)

    CSS class(es) (in addition to package)

Returns:

  • (String)

    Icon used for displaying the unit quantity


67
68
69
70
71
72
73
74
# File 'app/helpers/orders_helper.rb', line 67

def pkg_helper_icon(c=nil, options={})
  options = {tag: 'i', class: ''}.merge(options)
  if c.nil?
    c = " ".html_safe
    options[:class] += " icon-only"
  end
  (options[:tag], c, class: "package #{options[:class]}").html_safe
end

#receive_button(order, options = {}) ⇒ String

Button for receiving an order.

If the order hasn't been received before, the button is shown in green.

Parameters:

  • order (Order)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :class (String)

    Classes added to the button's class attribute.

Returns:

  • (String)

    Order receive button.


150
151
152
153
154
155
156
157
# File 'app/helpers/orders_helper.rb', line 150

def receive_button(order, options={})
  if order.stockit?
     :div, t('orders.index.action_receive'), class: "btn disabled #{options[:class]}"
  else
    was_received = order.order_articles.where('units_received IS NOT NULL').any?
    link_to t('orders.index.action_receive'), receive_order_path(order), class: "btn#{' btn-success' unless was_received} #{options[:class]}"
  end
end

#receive_input_field(form) ⇒ Object


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/helpers/orders_helper.rb', line 83

def receive_input_field(form)
  order_article = form.object
  units_expected = (order_article.units_billed || 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'

  if order_article.result_manually_changed?
    input_html = (:span, class: 'input-prepend intable', title: t('orders.edit_amount.field_locked_title', default: '')) {
      button_tag(nil, type: :button, class: 'btn unlocker') {
        (:i, nil, class: 'icon icon-unlock')
      } + input_html
    }
  end

  input_html.html_safe
end

Returns Link to order or supplier, showing its name.

Parameters:

  • order_or_supplier (Order, Supplier)

    Order or supplier to link to

Returns:

  • (String)

    Link to order or supplier, showing its name.


121
122
123
124
125
126
127
# File 'app/helpers/orders_helper.rb', line 121

def supplier_link(order_or_supplier)
  if order_or_supplier.kind_of?(Order) && order_or_supplier.stockit?
    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

#units_history_line(order_article, options = {}) ⇒ Object

“1×2 ordered, 2×2 billed, 2×2 received”


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/orders_helper.rb', line 29

def units_history_line(order_article, options={})
  if order_article.order.open?
    nil
  else
    units_info = []
    [:units_to_order, :units_billed, :units_received].map do |unit|
      if n = order_article.send(unit)
        line = n.to_s + ' '
        line += pkg_helper(order_article.price, options) + ' ' unless n == 0
        line += OrderArticle.human_attribute_name("#{unit}_short", count: n)
        units_info << line
      end
    end
    units_info.join(', ').html_safe
  end
end

4
5
6
7
8
# File 'app/helpers/orders_helper.rb', line 4

def update_articles_link(order, text, view, options={})
  options = {remote: true, id: "view_#{view}_btn", class: ''}.merge(options)
  options[:class] += ' active' if view.to_s == @view.to_s
  link_to text, order_path(order, view: view), options
end