Added MemberSpent class to help create the fields for getting the amounts per member. #1190

This commit is contained in:
Eric Davis
2008-06-09 16:32:26 -07:00
parent b571a1f338
commit 211fc5879d
4 changed files with 52 additions and 2 deletions

View File

@@ -105,6 +105,10 @@ class Deliverable < ActiveRecord::Base
0
end
def members_spent
[]
end
def left
return self.budget - self.spent
end

View File

@@ -23,6 +23,10 @@ class HourlyDeliverable < Deliverable
end
def members_spent
return MemberSpent.find_all_by_deliverable(self)
end
def profit
if read_attribute(:profit_percent).nil?
return super

View File

@@ -0,0 +1,40 @@
class MemberSpent
attr_accessor :user
attr_accessor :hours
attr_accessor :spent
def initialize(options = { })
self.user = options[:user] || nil
self.hours = options[:hours] || 0.0
self.spent = options[:spent] || 0.0
end
def self.find_all_by_deliverable(deliverable)
membership = []
return membership unless deliverable.issues.size > 0
project = deliverable.project
time_entries = deliverable.issues.collect(&:time_entries).flatten
project.members.each do |member|
member_time_entries = time_entries.select { |tl| tl.user_id == member.user.id}
hours = member_time_entries.collect(&:hours).sum || 0.0
unless member.rate.nil?
spent = hours.to_f * member.rate
else
spent = 0.0
end
membership << MemberSpent.new({
:user => member.user,
:hours => hours,
:spent => spent
}) unless hours == 0.0
end
return membership
end
end

View File

@@ -29,8 +29,10 @@
<%= paragraph_with_data("Progress: ", deliverable.progress) -%>
<%= paragraph_with_data("Hours Estimated: ", deliverable.total_hours) if allowed_management? -%>
<%= paragraph_with_data("Hours Used: ", deliverable.hours_used) if allowed_management? -%>
TODO: Each person
<% deliverable.members_spent.each do |person| %>
<p><%= h person.user.name -%>: <%= h(person.hours) %> <%= number_to_currency(person.spent, :precision => 0) %></p>
<% end %>
</td>
<td colspan="3">