Refactor: extract scope_date_status method to find how to scope the periods.
This commit is contained in:
1 parent
362610dc77
commit
12fffee314
1 file changed
+59
-52
@@ -84,36 +84,33 @@ class RetainerDeliverable < HourlyDeliverable
|
|||||||
end
|
end
|
||||||
|
|
||||||
def labor_budget_total(date=nil)
|
def labor_budget_total(date=nil)
|
||||||
if date
|
case scope_date_status(date)
|
||||||
if within_date_range?(date)
|
when :in
|
||||||
labor_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month})
|
labor_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month})
|
||||||
else
|
when :out
|
||||||
0 # outside of range
|
0
|
||||||
end
|
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def overhead_budget_total(date=nil)
|
def overhead_budget_total(date=nil)
|
||||||
if date
|
case scope_date_status(date)
|
||||||
if within_date_range?(date)
|
when :in
|
||||||
overhead_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month})
|
overhead_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month})
|
||||||
else
|
when :out
|
||||||
0 # outside of range
|
0
|
||||||
end
|
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def labor_budget_hours(date=nil)
|
def labor_budget_hours(date=nil)
|
||||||
if date
|
case scope_date_status(date)
|
||||||
if within_date_range?(date)
|
when :in
|
||||||
labor_budgets.sum(:hours, :conditions => {:year => date.year, :month => date.month})
|
labor_budgets.sum(:hours, :conditions => {:year => date.year, :month => date.month})
|
||||||
else
|
when :out
|
||||||
0 # outside of range
|
0
|
||||||
end
|
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
@@ -192,53 +189,49 @@ class RetainerDeliverable < HourlyDeliverable
|
|||||||
end
|
end
|
||||||
|
|
||||||
def labor_budget_spent(date=nil)
|
def labor_budget_spent(date=nil)
|
||||||
if date
|
case scope_date_status(date)
|
||||||
if within_date_range?(date)
|
when :in
|
||||||
labor_budget_spent_with_filter do
|
labor_budget_spent_with_filter do
|
||||||
issue_ids = self.issues.collect(&:id)
|
issue_ids = self.issues.collect(&:id)
|
||||||
if issue_ids.present?
|
if issue_ids.present?
|
||||||
TimeEntry.all(:conditions => ["#{Issue.table_name}.id IN (:issue_ids) AND tyear = (:year) AND tmonth = (:month)",
|
TimeEntry.all(:conditions => ["#{Issue.table_name}.id IN (:issue_ids) AND tyear = (:year) AND tmonth = (:month)",
|
||||||
{:issue_ids => issue_ids,
|
{:issue_ids => issue_ids,
|
||||||
:year => date.year,
|
:year => date.year,
|
||||||
:month => date.month}
|
:month => date.month}
|
||||||
],
|
],
|
||||||
:include => :issue)
|
:include => :issue)
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
0 # outside of range
|
|
||||||
end
|
end
|
||||||
|
when :out
|
||||||
|
0
|
||||||
else
|
else
|
||||||
labor_budget_spent_with_filter
|
labor_budget_spent_with_filter
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def overhead_spent(date=nil)
|
def overhead_spent(date=nil)
|
||||||
if date
|
case scope_date_status(date)
|
||||||
if within_date_range?(date)
|
when :in
|
||||||
overhead_spent_with_filter do
|
overhead_spent_with_filter do
|
||||||
issue_ids = self.issues.collect(&:id)
|
issue_ids = self.issues.collect(&:id)
|
||||||
if issue_ids.present?
|
if issue_ids.present?
|
||||||
TimeEntry.all(:conditions => ["#{Issue.table_name}.id IN (:issue_ids) AND tyear = (:year) AND tmonth = (:month)",
|
TimeEntry.all(:conditions => ["#{Issue.table_name}.id IN (:issue_ids) AND tyear = (:year) AND tmonth = (:month)",
|
||||||
{:issue_ids => issue_ids,
|
{:issue_ids => issue_ids,
|
||||||
:year => date.year,
|
:year => date.year,
|
||||||
:month => date.month}
|
:month => date.month}
|
||||||
],
|
],
|
||||||
:include => :issue)
|
:include => :issue)
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
0 # outside of range
|
|
||||||
end
|
end
|
||||||
|
when :out
|
||||||
|
0
|
||||||
else
|
else
|
||||||
overhead_spent_with_filter
|
overhead_spent_with_filter
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_budgets_for_periods
|
def create_budgets_for_periods
|
||||||
@@ -349,4 +342,18 @@ class RetainerDeliverable < HourlyDeliverable
|
|||||||
def create_new_overhead_budget_based_on_existing_budget(existing_overhead_budget, attributes={})
|
def create_new_overhead_budget_based_on_existing_budget(existing_overhead_budget, attributes={})
|
||||||
overhead_budgets.create(existing_overhead_budget.attributes.except('id').merge(attributes))
|
overhead_budgets.create(existing_overhead_budget.attributes.except('id').merge(attributes))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def scope_date_status(date)
|
||||||
|
if date
|
||||||
|
if within_date_range?(date)
|
||||||
|
status = :in
|
||||||
|
else
|
||||||
|
status = :out # outside of range
|
||||||
|
end
|
||||||
|
else
|
||||||
|
status = :no_date
|
||||||
|
end
|
||||||
|
|
||||||
|
status
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user