From 7e6282a40461b8c09035ef8d4958e28a9ff4aff2 Mon Sep 17 00:00:00 2001 From: hjust Date: Mon, 19 Oct 2009 16:04:25 +0000 Subject: [PATCH] added logic to display only selected types of entries (only cost_entries, only time_entries or both) git-svn-id: https://dev.finn.de/svn/cockpit/trunk@209 7926756e-e54e-46e6-9721-ed318f58905e --- app/controllers/cost_reports_controller.rb | 35 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/app/controllers/cost_reports_controller.rb b/app/controllers/cost_reports_controller.rb index 31002489aa..7a939db20b 100644 --- a/app/controllers/cost_reports_controller.rb +++ b/app/controllers/cost_reports_controller.rb @@ -106,11 +106,7 @@ private def get_entries(limit) cost_statement = @query.statement(:cost_entries) time_statement = @query.statement(:time_entries) - - @entry_count = CostEntry.count(:conditions => cost_statement) + - TimeEntry.count(:conditions => time_statement) - @entry_pages = Paginator.new self, @entry_count, limit, params['page'] - + # at first get the entry ids to match the current query unless sort_clause.nil? (sort_column, sort_order) = sort_clause.split(" ") @@ -134,7 +130,34 @@ private time_sort_column_sql += "," end end + + + if @query.display_time_entries && !@query.display_cost_entries + @entry_count = TimeEntry.count(cost_statement) + @entry_pages = Paginator.new self, @entry_count, limit, params['page'] + + @entries = TimeEntry.find :all, {:order => (sort_clause if time_sort_column), + :include => [:issue, :activity, :user], + :conditions => cost_statement, + :limit => limit, + :offset => @entry_pages.current.offset} + + return + elsif @query.display_cost_entries && !@query.display_time_entries + @entry_count = CostEntry.count(cost_statement) + @entry_pages = Paginator.new self, @entry_count, limit, params['page'] + + @entries = CostEntry.find :all, {:order => (sort_clause if cost_sort_column), + :include => [:issue, :cost_type, :user], + :conditions => cost_statement, + :limit => limit, + :offset => @entry_pages.current.offset} + return + end + @entry_count = CostEntry.count(:conditions => cost_statement) + + TimeEntry.count(:conditions => time_statement) + @entry_pages = Paginator.new self, @entry_count, limit, params['page'] # TAKE extra care for SQL injection here!!! sql = " SELECT id, #{cost_sort_column_sql} 'cost_entry' AS entry_type" @@ -169,7 +192,7 @@ private :conditions => {:id => cost_entry_ids}} time_entries = TimeEntry.find :all, {:order => (sort_clause if time_sort_column), - :include => [:issue, :user], + :include => [:issue, :activity, :user], :conditions => {:id => time_entry_ids}}