summaryrefslogtreecommitdiffstats
path: root/app/models/time_entry.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/time_entry.rb')
-rw-r--r--app/models/time_entry.rb32
1 files changed, 12 insertions, 20 deletions
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb
index f4716d0ac..c5c1d39bc 100644
--- a/app/models/time_entry.rb
+++ b/app/models/time_entry.rb
@@ -53,10 +53,18 @@ class TimeEntry < ActiveRecord::Base
:include => :project,
:conditions => project.project_condition(include_subprojects)
}}
- named_scope :spent_between, lambda {|from, to| {
- :conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to]
- }}
-
+ named_scope :spent_between, lambda {|from, to|
+ if from && to
+ {:conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to]}
+ elsif from
+ {:conditions => ["#{TimeEntry.table_name}.spent_on >= ?", from]}
+ elsif to
+ {:conditions => ["#{TimeEntry.table_name}.spent_on <= ?", to]}
+ else
+ {}
+ end
+ }
+
def after_initialize
if new_record? && self.activity.nil?
if default_activity = TimeEntryActivity.default
@@ -96,20 +104,4 @@ class TimeEntry < ActiveRecord::Base
def editable_by?(usr)
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
end
-
- def self.earilest_date_for_project(project=nil)
- finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries))
- if project
- finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)]
- end
- TimeEntry.minimum(:spent_on, :include => :project, :conditions => finder_conditions.conditions)
- end
-
- def self.latest_date_for_project(project=nil)
- finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries))
- if project
- finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)]
- end
- TimeEntry.maximum(:spent_on, :include => :project, :conditions => finder_conditions.conditions)
- end
end