|
|
@ -159,23 +159,23 @@ class CostReportsController < ApplicationController |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
## |
|
|
|
## |
|
|
|
# FIXME: Split, also ugly |
|
|
|
# Determine active cost types, the currently selected unit and corresponding cost type |
|
|
|
# This method does three things: |
|
|
|
def set_cost_types |
|
|
|
# set the @unit_id -> this is used in the index for determining the active unit tab |
|
|
|
set_active_cost_types |
|
|
|
# set the @cost_types -> this is used to determine which tabs to display |
|
|
|
|
|
|
|
# possibly set the @cost_type -> this is used to select the proper units for display |
|
|
|
|
|
|
|
def set_cost_types(value = nil) |
|
|
|
|
|
|
|
@cost_types = session[:cost_query][:filters][:values][:cost_type_id].try(:collect, &:to_i) || (-1..CostType.count) |
|
|
|
|
|
|
|
set_unit |
|
|
|
set_unit |
|
|
|
set_cost_type |
|
|
|
set_cost_type |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Determine the currently active unit from the parameters or session |
|
|
|
|
|
|
|
# sets the @unit_id -> this is used in the index for determining the active unit tab |
|
|
|
def set_unit |
|
|
|
def set_unit |
|
|
|
@unit_id = value || params[:unit].try(:to_i) || session[:unit_id].to_i |
|
|
|
@unit_id = params[:unit].try(:to_i) || session[:unit_id].to_i |
|
|
|
@unit_id = 0 unless @cost_types.include? @unit_id |
|
|
|
@unit_id = 0 unless @cost_types.include? @unit_id |
|
|
|
session[:unit_id] = @unit_id |
|
|
|
session[:unit_id] = @unit_id |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Determine the active cost type, if it is not labor or money, and add a hidden filter to the query |
|
|
|
|
|
|
|
# sets the @cost_type -> this is used to select the proper units for display |
|
|
|
def set_cost_type |
|
|
|
def set_cost_type |
|
|
|
if @unit_id != 0 |
|
|
|
if @unit_id != 0 |
|
|
|
@query.filter :cost_type_id, :operator => '=', :value => @unit_id.to_s, :display => false |
|
|
|
@query.filter :cost_type_id, :operator => '=', :value => @unit_id.to_s, :display => false |
|
|
@ -183,6 +183,12 @@ class CostReportsController < ApplicationController |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# set the @cost_types -> this is used to determine which tabs to display |
|
|
|
|
|
|
|
def set_active_cost_types |
|
|
|
|
|
|
|
@cost_types = session[:cost_query][:filters][:values][:cost_type_id].try(:collect, &:to_i) |
|
|
|
|
|
|
|
@cost_types ||= (-1..CostType.count) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def load_all |
|
|
|
def load_all |
|
|
|
CostQuery::GroupBy.all |
|
|
|
CostQuery::GroupBy.all |
|
|
|
CostQuery::Filter.all |
|
|
|
CostQuery::Filter.all |
|
|
|