[#4420] Changed the approach for Retainer calculations by using an optional parameter.

This commit is contained in:
Eric Davis
2010-09-08 17:49:51 -07:00
parent c8b86db4c4
commit 82dec74eb7
6 changed files with 127 additions and 70 deletions
+12 -8
View File
@@ -54,20 +54,20 @@ class Deliverable < ActiveRecord::Base
end
end
def labor_budget_total
def labor_budget_total(date=nil)
labor_budgets.sum(:budget)
end
def labor_budget_total_for_date(date=nil) #Used on subclasses
labor_budget_total
end
def overhead_budget_total
def overhead_budget_total(date=nil)
overhead_budgets.sum(:budget)
end
def overhead_budget_total_for_date(date=nil) #Used on subclasses
overhead_budget_total
def profit_budget(date=nil)
nil
end
def labor_budget_hours(date=nil)
labor_budgets.sum(:hours)
end
# Total number of hours estimated in the Deliverable's budgets
@@ -81,6 +81,10 @@ class Deliverable < ActiveRecord::Base
issues.inject(0) {|total, issue| total += issue.spent_hours }
end
def filter_by_date(date=nil, &block)
block.call
end
def retainer?
type == "RetainerDeliverable"
end
+4 -4
View File
@@ -11,7 +11,7 @@ class FixedDeliverable < Deliverable
'F'
end
def total
def total(date=nil)
read_attribute(:total) || 0.0
end
@@ -22,9 +22,9 @@ class FixedDeliverable < Deliverable
# The amount of profit that is budgeted for this deliverable.
# Profit = Total - ( Labor + Overhead + Fixed + Markup )
def profit_budget
budgets = labor_budget_total + overhead_budget_total
(total || 0.0) - budgets
def profit_budget(date=nil)
budgets = labor_budget_total(date) + overhead_budget_total(date)
(total(date) || 0.0) - budgets
end
# The amount of money remaining after expenses have been taken out
+5 -5
View File
@@ -14,12 +14,12 @@ class HourlyDeliverable < Deliverable
'H'
end
def total
def total(date=nil)
return 0 if contract.nil?
return 0 if contract.billable_rate.blank?
return 0 if labor_budgets.count == 0 && overhead_budgets.count == 0
return contract.billable_rate * labor_budgets.sum(:hours)
return contract.billable_rate * labor_budget_hours(date)
end
# Total amount to be billed on the deliverable, using the total time logged
@@ -49,9 +49,9 @@ class HourlyDeliverable < Deliverable
# The amount of profit that is budgeted for this deliverable
# Profit = Total - ( Labor + Overhead + Fixed + Markup )
def profit_budget
budgets = labor_budget_total + overhead_budget_total
(total || 0.0) - budgets
def profit_budget(date=nil)
budgets = labor_budget_total(date) + overhead_budget_total(date)
(total(date) || 0.0) - budgets
end
# The amount of money remaining after expenses have been taken out
+16 -4
View File
@@ -75,7 +75,7 @@ class RetainerDeliverable < HourlyDeliverable
budgets
end
def labor_budget_total_for_date(date=nil)
def labor_budget_total(date=nil)
if date
if within_date_range?(date)
labor_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month})
@@ -83,11 +83,11 @@ class RetainerDeliverable < HourlyDeliverable
0 # outside of range
end
else
labor_budgets.sum(:budget)
super
end
end
def overhead_budget_total_for_date(date=nil)
def overhead_budget_total(date=nil)
if date
if within_date_range?(date)
overhead_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month})
@@ -95,7 +95,19 @@ class RetainerDeliverable < HourlyDeliverable
0 # outside of range
end
else
overhead_budgets.sum(:budget)
super
end
end
def labor_budget_hours(date=nil)
if date
if within_date_range?(date)
labor_budgets.sum(:hours, :conditions => {:year => date.year, :month => date.month})
else
0 # outside of range
end
else
super
end
end