Module: DeliveriesHelper

Defined in:
app/helpers/deliveries_helper.rb

Instance Method Summary collapse

Instance Method Details

#articles_for_select2(articles, except = [], &block) ⇒ Object



12
13
14
15
16
17
18
19
# File 'app/helpers/deliveries_helper.rb', line 12

def articles_for_select2(articles, except = [], &block)
  articles = articles.reorder('articles.name ASC')
  articles = articles.reject { |a| !except.index(a.id).nil? } if except
  block_given? or block = proc { |a| "#{a.name} (#{number_to_currency a.price}/#{a.unit})" }
  articles.map do |a|
    { id: a.id, text: block.call(a) }
  end.unshift({ id: '', text: '' })
end

#articles_for_table(articles) ⇒ Object



21
22
23
# File 'app/helpers/deliveries_helper.rb', line 21

def articles_for_table(articles)
  articles.undeleted.reorder('articles.name ASC')
end


2
3
4
5
6
7
8
9
10
# File 'app/helpers/deliveries_helper.rb', line 2

def link_to_invoice(delivery)
  if delivery.invoice
    link_to number_to_currency(delivery.invoice.amount), [:finance, delivery.invoice],
            title: I18n.t('helpers.deliveries.show_invoice')
  else
    link_to I18n.t('helpers.deliveries.new_invoice'), new_finance_invoice_path(supplier_id: delivery.supplier.id, delivery_id: delivery.id),
            class: 'btn btn-mini'
  end
end


25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/deliveries_helper.rb', line 25

def stock_change_remove_link(stock_change_form)
  if stock_change_form.object.new_record?
    return link_to t('deliveries.stock_change_fields.remove_article'), '#',
                   class: 'remove_new_stock_change btn btn-small'
  end

  output = stock_change_form.hidden_field :_destroy
  output += link_to t('deliveries.stock_change_fields.remove_article'), '#',
                    class: 'destroy_stock_change btn btn-small'
  output.html_safe
end