2012-04-15 19:59:39 +02:00
|
|
|
# encoding: utf-8
|
2009-01-06 11:49:19 +01:00
|
|
|
module OrdersHelper
|
|
|
|
|
2009-01-29 01:57:51 +01:00
|
|
|
def update_articles_link(order, text, view)
|
2012-10-15 21:19:17 +02:00
|
|
|
link_to text, order_path(order, view: view), remote: true
|
2009-01-29 01:57:51 +01:00
|
|
|
end
|
|
|
|
|
2012-10-15 21:19:17 +02:00
|
|
|
def order_pdf(order, document, text)
|
2013-04-10 17:29:06 +02:00
|
|
|
link_to text, order_path(order, document: document, format: :pdf), title: I18n.t('helpers.orders.order_pdf')
|
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')]]
|
2012-10-15 21:19:17 +02:00
|
|
|
options += Supplier.all.map {|s| [ s.name, url_for(action: "new", supplier_id: s)] }
|
2013-04-10 17:29:06 +02:00
|
|
|
options += [[I18n.t('helpers.orders.option_stock'), url_for(action: 'new', supplier_id: 0)]]
|
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
|
|
|
|
|
|
|
def units_history_line(order_article)
|
|
|
|
if order_article.order.open?
|
|
|
|
nil
|
|
|
|
else
|
2014-01-08 00:06:25 +01:00
|
|
|
units_info = "#{order_article.units_to_order} #{heading_helper OrderArticle, :units_to_order}"
|
|
|
|
units_info += ", #{order_article.units_billed} #{heading_helper OrderArticle, :units_billed}" unless order_article.units_billed.nil?
|
|
|
|
units_info += ", #{order_article.units_received} #{heading_helper OrderArticle, :units_received}" unless order_article.units_received.nil?
|
2013-12-18 22:08:02 +01:00
|
|
|
end
|
|
|
|
end
|
2014-01-02 22:30:04 +01:00
|
|
|
|
|
|
|
# can be article or article_price
|
|
|
|
def pkg_helper(article, icon=true)
|
2014-01-03 12:42:36 +01:00
|
|
|
return nil if article.unit_quantity == 1
|
2014-01-02 22:30:04 +01:00
|
|
|
if icon
|
|
|
|
"<i class='package'> × #{article.unit_quantity}</i>".html_safe
|
|
|
|
else
|
|
|
|
"<span class='package'> × #{article.unit_quantity}</span>".html_safe
|
|
|
|
end
|
|
|
|
end
|
2014-01-03 10:33:09 +01:00
|
|
|
|
2014-01-03 12:42:36 +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
|
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
|
|
|
|
"<i class='icon-asterisk' title='#{j title}'></i>".html_safe
|
2014-01-02 21:59:08 +01:00
|
|
|
end
|
|
|
|
|
2014-01-03 10:33:09 +01:00
|
|
|
def receive_input_field(form)
|
|
|
|
order_article = form.object
|
|
|
|
units_expected = (order_article.units_billed or order_article.units_to_order)
|
2014-01-03 22:26:20 +01:00
|
|
|
|
|
|
|
# unlock button, to prevent overwriting if it was manually distributed
|
|
|
|
input_html = ''
|
|
|
|
if order_article.result_manually_changed?
|
|
|
|
input_html += '<span class="input-prepend intable">' +
|
|
|
|
button_tag(nil, type: :button, class: 'btn unlocker', title: t('.locked_to_protect_unlock_button')) {'<i class="icon icon-unlock"></i>'.html_safe}
|
|
|
|
end
|
|
|
|
|
|
|
|
input_html += form.text_field :units_received, class: 'input input-nano package units_received',
|
2014-01-03 10:33:09 +01:00
|
|
|
data: {'units-expected' => units_expected},
|
2014-01-03 10:59:42 +01:00
|
|
|
disabled: order_article.result_manually_changed?,
|
2014-01-03 10:33:09 +01:00
|
|
|
title: order_article.result_manually_changed? ? t('.locked_to_protect_manual_update') : nil,
|
|
|
|
autocomplete: 'off'
|
2014-01-03 22:26:20 +01:00
|
|
|
|
|
|
|
input_html += '</span>' if order_article.result_manually_changed?
|
|
|
|
input_html.html_safe
|
2014-01-03 10:33:09 +01:00
|
|
|
end
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|