Fixed bug in sorting articles in balancing view.
This commit is contained in:
parent
c4376f35bf
commit
0d3564492b
2 changed files with 25 additions and 17 deletions
|
@ -10,25 +10,22 @@ class Finance::BalancingController < Finance::BaseController
|
||||||
flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed?
|
flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed?
|
||||||
@comments = @order.comments
|
@comments = @order.comments
|
||||||
|
|
||||||
if params['sort']
|
|
||||||
sort = case params['sort']
|
|
||||||
when "name" then "articles.name"
|
|
||||||
when "order_number" then "articles.order_number"
|
|
||||||
when "name_reverse" then "articles.name DESC"
|
|
||||||
when "order_number_reverse" then "articles.order_number DESC"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
sort = "id"
|
|
||||||
end
|
|
||||||
|
|
||||||
@articles = @order.order_articles.ordered.includes(:order, :article_price,
|
@articles = @order.order_articles.ordered.includes(:order, :article_price,
|
||||||
group_order_articles: {group_order: :ordergroup}).order(sort)
|
group_order_articles: {group_order: :ordergroup})
|
||||||
|
|
||||||
if params[:sort] == "order_number"
|
sort_param = params['sort'] || 'name'
|
||||||
@articles = @articles.to_a.sort { |a,b| a.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> b.article.order_number.gsub(/[^[:digit:]]/, "").to_i }
|
@articles = case sort_param
|
||||||
elsif params[:sort] == "order_number_reverse"
|
when 'name' then
|
||||||
@articles = @articles.to_a.sort { |a,b| b.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> a.article.order_number.gsub(/[^[:digit:]]/, "").to_i }
|
OrderArticle.sort_by_name(@articles)
|
||||||
end
|
when 'name_reverse' then
|
||||||
|
OrderArticle.sort_by_name(@articles).reverse
|
||||||
|
when 'order_number' then
|
||||||
|
OrderArticle.sort_by_order_number(@articles)
|
||||||
|
when 'order_number_reverse' then
|
||||||
|
OrderArticle.sort_by_order_number(@articles).reverse
|
||||||
|
else
|
||||||
|
@articles
|
||||||
|
end
|
||||||
|
|
||||||
render layout: false if request.xhr?
|
render layout: false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,17 @@ class OrderArticle < ActiveRecord::Base
|
||||||
before_create :init_from_balancing
|
before_create :init_from_balancing
|
||||||
after_destroy :update_ordergroup_prices
|
after_destroy :update_ordergroup_prices
|
||||||
|
|
||||||
|
def self.sort_by_name(order_articles)
|
||||||
|
order_articles.sort { |a,b| a.article.name <=> b.article.name }
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.sort_by_order_number(order_articles)
|
||||||
|
order_articles.sort do |a,b|
|
||||||
|
a.article.order_number.to_s.gsub(/[^[:digit:]]/, "").to_i <=>
|
||||||
|
b.article.order_number.to_s.gsub(/[^[:digit:]]/, "").to_i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# This method returns either the ArticlePrice or the Article
|
# This method returns either the ArticlePrice or the Article
|
||||||
# The first will be set, when the the order is finished
|
# The first will be set, when the the order is finished
|
||||||
def price
|
def price
|
||||||
|
|
Loading…
Reference in a new issue