diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index a2b8c11..d5e8a10 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -26,6 +26,12 @@ def show @meta_keywords = @category.meta_keywords @category_expenditures_total = Item.where(:category_id => @category.subtree_ids).where(:is_expense => true).sum(:total) @category_revenues_total = Item.where(:category_id => @category.subtree_ids).where(:is_expense => false).sum(:total) + @child_categories = @category.children + @categories_by_total = Hash.new + @child_categories.each do |cat| + @categories_by_total[cat.expenditure_items_total] = cat + end + @categories_by_total = Hash[@categories_by_total.sort.reverse] end def update diff --git a/app/views/categories/show.html.slim b/app/views/categories/show.html.slim index a3354c8..a0265df 100644 --- a/app/views/categories/show.html.slim +++ b/app/views/categories/show.html.slim @@ -100,16 +100,19 @@ hr div class="row" div class="span6 barchart-widget" h2 Sub-Categories - - unless @category.children.empty? - - for child_category in @category.children + - unless @category.children.empty? + + - @categories_by_total.each_pair do |total,child_category| div class="bar-container" div class="bar-category-text" = link_to child_category.name, organization_project_category_path(@organization, @project, child_category) ' - = number_to_currency(child_category.expenditure_items_total, :precision => 0) + = number_to_currency(total, :precision => 0) div class="progress progress-danger" - if @category_expenditures_total > 0 - div class="bar" style="width: #{((child_category.expenditure_items_total/@category_expenditures_total)*100).to_i}%;" + div class="bar" style="width: #{((total/@category_expenditures_total)*100).to_i}%;" + + - else | No sub-categories found