diff --git a/app/helpers/deliverables_helper.rb b/app/helpers/deliverables_helper.rb index 410ffd4..f366df4 100644 --- a/app/helpers/deliverables_helper.rb +++ b/app/helpers/deliverables_helper.rb @@ -63,4 +63,10 @@ module DeliverablesHelper ) end + + def number_or_percent(number_field, percent_field) + return number_to_currency(number_field, :precision => 0) unless number_field.blank? + return number_to_percentage(percent_field, :precision => 0) unless percent_field.blank? + return "$0" + end end diff --git a/app/models/fixed_deliverable.rb b/app/models/fixed_deliverable.rb index 84dae4a..35d9b41 100644 --- a/app/models/fixed_deliverable.rb +++ b/app/models/fixed_deliverable.rb @@ -22,7 +22,7 @@ class FixedDeliverable < Deliverable # Budget for the labor, excluding overhead, profit, and materials def labor_budget - return read_attribute(:fixed_cost) + return read_attribute(:fixed_cost) || 0.0 end end diff --git a/app/models/hourly_deliverable.rb b/app/models/hourly_deliverable.rb index 9f91e72..d7c4589 100644 --- a/app/models/hourly_deliverable.rb +++ b/app/models/hourly_deliverable.rb @@ -41,7 +41,7 @@ class HourlyDeliverable < Deliverable # Budget for the labor, excluding overhead, profit, and materials def labor_budget - return read_attribute(:cost_per_hour).to_f * read_attribute(:total_hours).to_f + return (read_attribute(:cost_per_hour).to_f * read_attribute(:total_hours).to_f) || 0.0 end end diff --git a/app/views/deliverables/_deliverable.html.erb b/app/views/deliverables/_deliverable.html.erb index e5638c1..581f206 100644 --- a/app/views/deliverables/_deliverable.html.erb +++ b/app/views/deliverables/_deliverable.html.erb @@ -7,7 +7,7 @@ <%= content_tag(:td, deliverable.id) %> <%= content_tag(:td, h(deliverable.score.to_i), :class => 'score') if allowed_management? %> <%= content_tag(:td, h(deliverable.subject), :class => 'subject') %> - <%= content_tag(:td, number_to_currency(deliverable.labor_budget, :precision => 0), :class => 'budget') %> + <%= content_tag(:td, number_to_currency(deliverable.labor_budget || 0.0, :precision => 0), :class => 'budget') %> <%= content_tag(:td, number_to_currency(deliverable.spent, :precision => 0), :class => 'spent') if allowed_management? %> <%= content_tag(:td, format_date(deliverable.due), :class => 'due_date') %> <%= content_tag(:td, progress_bar(deliverable.progress, :width => '100%', :class => 'dont_ratio')) %> @@ -45,10 +45,10 @@ <%= paragraph_with_data("Total Budget: ", number_to_currency(deliverable.budget, :precision => 0)) -%> <% if allowed_management? %> - <%= paragraph_with_data("Labor: ", number_to_currency(deliverable.labor_budget, :precision => 0)) -%> - <%= paragraph_with_data("Overhead: ", number_to_currency(deliverable.overhead, :precision => 0)) -%> - <%= paragraph_with_data("Materials: ", number_to_currency(deliverable.materials, :precision => 0)) -%> - <%= paragraph_with_data("Profit: ", number_to_currency(deliverable.profit, :precision => 0)) -%> + <%= paragraph_with_data("Labor: ", number_to_currency(deliverable.labor_budget || 0.0, :precision => 0)) -%> + <%= paragraph_with_data("Overhead: ", number_or_percent(deliverable.overhead, deliverable.overhead_percent)) -%> + <%= paragraph_with_data("Materials: ", number_or_percent(deliverable.materials, deliverable.materials_percent)) -%> + <%= paragraph_with_data("Profit: ", number_or_percent(deliverable.profit, deliverable.profit_percent)) -%> <% end %>