make orders helpers clearer
This commit is contained in:
parent
ffd1c06729
commit
fee0cfbdc7
2 changed files with 31 additions and 7 deletions
|
@ -7,6 +7,11 @@ module OrdersHelper
|
||||||
link_to text, order_path(order, view: view), options
|
link_to text, order_path(order, view: view), options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param order [Order]
|
||||||
|
# @param document [String] Document to display, one of +groups+, +articles+, +fax+, +matrix+
|
||||||
|
# @param text [String] Link text
|
||||||
|
# @return [String] Link to order document
|
||||||
|
# @see OrdersController#show
|
||||||
def order_pdf(order, document, text)
|
def order_pdf(order, document, text)
|
||||||
link_to text, order_path(order, document: document, format: :pdf), title: I18n.t('helpers.orders.order_pdf')
|
link_to text, order_path(order, document: document, format: :pdf), title: I18n.t('helpers.orders.order_pdf')
|
||||||
end
|
end
|
||||||
|
@ -36,11 +41,12 @@ module OrdersHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# can be article or article_price
|
# @param article [Article]
|
||||||
# icon: `false` to not show the icon
|
# @option options [String] :icon +false+ to hide the icon
|
||||||
# plain: `true` to not use html (implies icon: false)
|
# @option options [String] :plain +true+ to not use HTML (implies +icon+=+false+)
|
||||||
# soft_uq: `true` to hide unit quantity specifier on small screens
|
# @option options [String] :soft_uq +true+ to hide unit quantity specifier on small screens.
|
||||||
# sensible in tables with multiple columns calling `pkg_helper`
|
# Sensible in tables with multiple columns.
|
||||||
|
# @return [String] Text showing unit and unit quantity when applicable.
|
||||||
def pkg_helper(article, options={})
|
def pkg_helper(article, options={})
|
||||||
return '' if not article or article.unit_quantity == 1
|
return '' if not article or article.unit_quantity == 1
|
||||||
uq_text = "× #{article.unit_quantity}"
|
uq_text = "× #{article.unit_quantity}"
|
||||||
|
@ -53,6 +59,9 @@ module OrdersHelper
|
||||||
pkg_helper_icon(uq_text, tag: :span)
|
pkg_helper_icon(uq_text, tag: :span)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# @param c [Symbol, String] Tag to use
|
||||||
|
# @option options [String] :class CSS class(es) (in addition to +package+)
|
||||||
|
# @return [String] Icon used for displaying the unit quantity
|
||||||
def pkg_helper_icon(c=nil, options={})
|
def pkg_helper_icon(c=nil, options={})
|
||||||
options = {tag: 'i', class: ''}.merge(options)
|
options = {tag: 'i', class: ''}.merge(options)
|
||||||
if c.nil?
|
if c.nil?
|
||||||
|
@ -92,6 +101,8 @@ module OrdersHelper
|
||||||
input_html.html_safe
|
input_html.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param order [Order]
|
||||||
|
# @return [String] Number of ordergroups participating in order with groups in title.
|
||||||
def ordergroup_count(order)
|
def ordergroup_count(order)
|
||||||
group_orders = order.group_orders.includes(:ordergroup)
|
group_orders = order.group_orders.includes(:ordergroup)
|
||||||
txt = "#{group_orders.count} #{Ordergroup.model_name.human count: group_orders.count}"
|
txt = "#{group_orders.count} #{Ordergroup.model_name.human count: group_orders.count}"
|
||||||
|
@ -103,6 +114,8 @@ module OrdersHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param order_or_supplier [Order, Supplier] Order or supplier to link to
|
||||||
|
# @return [String] Link to order or supplier, showing its name.
|
||||||
def supplier_link(order_or_supplier)
|
def supplier_link(order_or_supplier)
|
||||||
if order_or_supplier.kind_of?(Order) and order_or_supplier.stockit?
|
if order_or_supplier.kind_of?(Order) and order_or_supplier.stockit?
|
||||||
link_to(order_or_supplier.name, stock_articles_path).html_safe
|
link_to(order_or_supplier.name, stock_articles_path).html_safe
|
||||||
|
@ -110,4 +123,16 @@ module OrdersHelper
|
||||||
link_to(@order.supplier.name, supplier_path(@order.supplier)).html_safe
|
link_to(@order.supplier.name, supplier_path(@order.supplier)).html_safe
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param order_article [OrderArticle]
|
||||||
|
# @return [String] CSS class for +OrderArticle+ in table for admins
|
||||||
|
def order_article_class(order_article)
|
||||||
|
if order_article.units > 0
|
||||||
|
'used'
|
||||||
|
elsif order_article.quantity > 0
|
||||||
|
'unused'
|
||||||
|
else
|
||||||
|
'unavailable'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
- units = order_article.units
|
- units = order_article.units
|
||||||
- total_net += units * unit_quantity * net_price
|
- total_net += units * unit_quantity * net_price
|
||||||
- total_gross += units * unit_quantity * gross_price
|
- total_gross += units * unit_quantity * gross_price
|
||||||
- cssclass = (units > 0 ? 'used' : (order_article.quantity > 0 ? 'unused' : 'unavailable'))
|
%tr{:class => cycle('even', 'odd', :name => 'articles') + ' ' + order_article_class(order_article)}
|
||||||
%tr{:class => cycle('even', 'odd', :name => 'articles') + ' ' + cssclass}
|
|
||||||
%td.name=h order_article.article.name
|
%td.name=h order_article.article.name
|
||||||
%td= order_article.article.unit
|
%td= order_article.article.unit
|
||||||
%td= "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}"
|
%td= "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue