2009-01-16 02:17:49 +01:00
|
|
|
module DeliveriesHelper
|
2009-01-18 17:42:51 +01:00
|
|
|
def link_to_invoice(delivery)
|
|
|
|
if delivery.invoice
|
|
|
|
link_to number_to_currency(delivery.invoice.amount), [:finance, delivery.invoice],
|
2021-03-01 15:27:26 +01:00
|
|
|
title: I18n.t('helpers.deliveries.show_invoice')
|
2009-01-18 17:42:51 +01:00
|
|
|
else
|
2013-04-10 17:29:06 +02:00
|
|
|
link_to I18n.t('helpers.deliveries.new_invoice'), new_finance_invoice_path(supplier_id: delivery.supplier.id, delivery_id: delivery.id),
|
2021-03-01 15:27:26 +01:00
|
|
|
class: 'btn btn-mini'
|
2009-01-18 17:42:51 +01:00
|
|
|
end
|
|
|
|
end
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2013-12-18 17:34:45 +01:00
|
|
|
def articles_for_select2(articles, except = [], &block)
|
|
|
|
articles = articles.reorder('articles.name ASC')
|
2023-05-12 13:01:12 +02:00
|
|
|
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})" }
|
2013-12-18 17:34:45 +01:00
|
|
|
articles.map do |a|
|
2023-05-12 13:01:12 +02:00
|
|
|
{ id: a.id, text: block.call(a) }
|
|
|
|
end.unshift({ id: '', text: '' })
|
2009-05-17 16:11:39 +02:00
|
|
|
end
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2013-12-18 17:34:45 +01:00
|
|
|
def articles_for_table(articles)
|
|
|
|
articles.undeleted.reorder('articles.name ASC')
|
2013-06-13 23:33:24 +02:00
|
|
|
end
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2013-06-26 15:16:52 +02:00
|
|
|
def stock_change_remove_link(stock_change_form)
|
2023-05-12 13:01:12 +02:00
|
|
|
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
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2013-06-26 15:16:52 +02:00
|
|
|
output = stock_change_form.hidden_field :_destroy
|
2023-05-12 13:01:12 +02:00
|
|
|
output += link_to t('deliveries.stock_change_fields.remove_article'), '#',
|
|
|
|
class: 'destroy_stock_change btn btn-small'
|
|
|
|
output.html_safe
|
2013-06-26 15:16:52 +02:00
|
|
|
end
|
2009-01-16 02:17:49 +01:00
|
|
|
end
|