Module: OrdersHelper
Instance Method Summary collapse
- #article_version_change_hint(order_article, gross = false) ⇒ Object
- #format_units_to_order(order_article, strip_insignificant_zeros: false) ⇒ Object
- #options_for_suppliers_to_select ⇒ Object
-
#order_article_class(order_article) ⇒ String
CSS class for
OrderArticlein table for admins (used,partused,unusedorunavailable). -
#order_pdf(order, document, text, options = {}) ⇒ String
Link to order document.
- #ordered_quantities_different_from_group_orders?(order_article, ordered_mark = '!', billed_mark = '?', received_mark = '?') ⇒ Boolean
-
#ordergroup_count(order) ⇒ String
Number of ordergroups participating in order with groups in title.
-
#pkg_helper(article, options = {}) ⇒ String
Text showing unit and unit quantity when applicable.
-
#pkg_helper_icon(c = nil, options = {}) ⇒ String
Icon used for displaying the unit quantity.
- #ratio_quantity_data(order_article, default_unit = nil) ⇒ Object
-
#receive_button(order, options = {}) ⇒ String
Button for receiving an order.
- #receive_input_field(form) ⇒ Object
-
#supplier_link(order_or_supplier) ⇒ String
Link to order or supplier, showing its name.
-
#units_history_line(order_article, options = {}) ⇒ Object
“1×2 ordered, 2×2 billed, 2×2 received”.
- #update_articles_link(order, text, view, options = {}) ⇒ Object
Instance Method Details
#article_version_change_hint(order_article, gross = false) ⇒ Object
113 114 115 116 117 118 119 |
# File 'app/helpers/orders_helper.rb', line 113 def article_version_change_hint(order_article, gross = false) return nil if order_article.article_version.price == order_article.article_version.price title = "#{t('helpers.orders.old_price')}: #{number_to_currency order_article.article_version.price}" title += " / #{number_to_currency order_article.article_version.gross_price}" if gross content_tag(:i, nil, class: 'glyphicon-asterisk', title: j(title)).html_safe end |
#format_units_to_order(order_article, strip_insignificant_zeros: false) ⇒ Object
26 27 28 |
# File 'app/helpers/orders_helper.rb', line 26 def format_units_to_order(order_article, strip_insignificant_zeros: false) format_amount(order_article.units_to_order, order_article, strip_insignificant_zeros: strip_insignificant_zeros) end |
#options_for_suppliers_to_select ⇒ Object
19 20 21 22 23 24 |
# File 'app/helpers/orders_helper.rb', line 19 def = [[I18n.t('helpers.orders.option_choose')]] += Supplier.map { |s| [s.name, url_for(action: 'new', supplier_id: s.id)] } += [[I18n.t('helpers.orders.option_stock'), url_for(action: 'new', supplier_id: nil)]] () end |
#order_article_class(order_article) ⇒ String
Returns CSS class for OrderArticle in table for admins (used, partused, unused or unavailable).
187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'app/helpers/orders_helper.rb', line 187 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.
14 15 16 17 |
# File 'app/helpers/orders_helper.rb', line 14 def order_pdf(order, document, text, = {}) = .merge(title: I18n.t('helpers.orders.order_pdf')) link_to text, order_path(order, document: document, format: :pdf), end |
#ordered_quantities_different_from_group_orders?(order_article, ordered_mark = '!', billed_mark = '?', received_mark = '?') ⇒ Boolean
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/orders_helper.rb', line 50 def ordered_quantities_different_from_group_orders?(order_article, ordered_mark = '!', billed_mark = '?', received_mark = '?') price = order_article.price group_orders_sum_quantity = order_article.group_orders_sum[:quantity] if !order_article.units_received.nil? if price.convert_quantity(order_article.units_received, price.supplier_order_unit, price.group_order_unit).round(3) == group_orders_sum_quantity false else received_mark end elsif !order_article.units_billed.nil? order_article.units_billed == group_orders_sum_quantity ? false : billed_mark elsif !order_article.units_to_order.nil? if price.convert_quantity(order_article.units_to_order, price.supplier_order_unit, price.group_order_unit).round(3) == group_orders_sum_quantity false else ordered_mark end end end |
#ordergroup_count(order) ⇒ String
Returns Number of ordergroups participating in order with groups in title.
166 167 168 169 170 171 172 173 |
# File 'app/helpers/orders_helper.rb', line 166 def ordergroup_count(order) group_orders = order.group_orders.includes(:ordergroup) txt = "#{group_orders.count} #{Ordergroup.model_name.human count: group_orders.count}" return txt if group_orders.count == 0 desc = group_orders.includes(:ordergroup).map { |g| g.ordergroup_name }.join(', ') content_tag(:abbr, txt, title: desc).html_safe end |
#pkg_helper(article, options = {}) ⇒ String
Returns Text showing unit and unit quantity when applicable.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/helpers/orders_helper.rb', line 79 def pkg_helper(article, = {}) unit_code = [:unit] || article.supplier_order_unit if unit_code == article.supplier_order_unit first_ratio = article&.article_unit_ratios&.first if first_ratio.nil? || first_ratio.quantity == 1 return "x #{article.unit}" if unit_code.nil? return ArticleUnitsLib.human_readable_unit(unit_code) end uq_text = "× #{number_with_precision(first_ratio.quantity, precision: 3, strip_insignificant_zeros: true)} #{ArticleUnitsLib.human_readable_unit(first_ratio.unit)}" else uq_text = ArticleUnitsLib.human_readable_unit(unit_code) end uq_text = content_tag(:span, uq_text, class: 'hidden-xs') if [:soft_uq] if [:plain] uq_text elsif [:icon].nil? || [: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.
107 108 109 110 111 |
# File 'app/helpers/orders_helper.rb', line 107 def pkg_helper_icon(c = nil, = {}) = { tag: 'i', class: '' }.merge() c = ' '.html_safe if c.nil? content_tag([:tag], c, class: "package #{options[:class]}").html_safe end |
#ratio_quantity_data(order_article, default_unit = nil) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/helpers/orders_helper.rb', line 151 def ratio_quantity_data(order_article, default_unit = nil) data = {} data['supplier-order-unit'] = order_article.article_version.supplier_order_unit data['default-unit'] = default_unit data['custom-unit'] = order_article.article_version.unit order_article.article_version.article_unit_ratios.each_with_index do |ratio, index| data["ratio-quantity-#{index}"] = ratio.quantity data["ratio-unit-#{index}"] = ratio.unit end data 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.
206 207 208 209 210 211 212 213 |
# File 'app/helpers/orders_helper.rb', line 206 def (order, = {}) if order.stockit? content_tag :div, t('orders.index.action_receive'), class: "btn disabled #{options[:class]}" else link_to t('orders.index.action_receive'), receive_order_path(order), class: "btn#{' btn-success' unless order.received?} #{options[:class]}" end end |
#receive_input_field(form) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/helpers/orders_helper.rb', line 121 def receive_input_field(form) order_article = form.object price = order_article.article_version quantity = order_article.units_billed || order_article.units_to_order # units_expected = (order_article.units_billed || order_article.units_to_order) * # 1.0 * order_article.article_version.unit_quantity / order_article.article_version.unit_quantity units_expected = price.convert_quantity(quantity, price.supplier_order_unit, price.billing_unit) input_classes = 'form-control numeric units_received' input_classes += ' package' unless price.unit_quantity == 1 || price.supplier_order_unit != price.billing_unit data = { units_expected: units_expected, billing_unit: price.billing_unit } data.merge!(ratio_quantity_data(order_article, price.billing_unit)) input_html = form.text_field :units_received, class: input_classes, data: data, disabled: order_article.result_manually_changed?, autocomplete: 'off' span_html = if order_article.result_manually_changed? content_tag(:span, class: 'input-prepend input-append intable', title: t('orders.edit_amount.field_locked_title', default: '')) do (nil, type: :button, class: 'btn unlocker') { content_tag(:i, nil, class: 'glyphicon glyphicon-unlock') } + input_html end else content_tag(:span, class: 'btn-group numeric-step d-flex') { input_html } end span_html.html_safe end |
#supplier_link(order_or_supplier) ⇒ String
Returns Link to order or supplier, showing its name.
177 178 179 180 181 182 183 |
# File 'app/helpers/orders_helper.rb', line 177 def supplier_link(order_or_supplier) if order_or_supplier.is_a?(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”
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/orders_helper.rb', line 31 def units_history_line(order_article, = {}) if order_article.order.open? nil else units_info = [] price = order_article.price i[units_to_order units_billed units_received].map do |unit| next unless n = order_article.send(unit) converted_quantity = price.convert_quantity(n, price.supplier_order_unit, [:unit].presence || price.supplier_order_unit) line = converted_quantity.round(3).to_s + ' ' line += pkg_helper(price, ) + ' ' unless n == 0 line += OrderArticle.human_attribute_name("#{unit}_short", count: converted_quantity) units_info << line end units_info.join(', ').html_safe end end |
#update_articles_link(order, text, view, options = {}) ⇒ Object
2 3 4 5 6 |
# File 'app/helpers/orders_helper.rb', line 2 def update_articles_link(order, text, view, = {}) = { remote: true, id: "view_#{view}_btn", class: '' }.merge() [:class] += ' active' if view.to_s == @view.to_s link_to text, order_path(order, view: view), end |