From b776098c7de7f44cee6bdf82e0d5f69cfbe075ab Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Thu, 19 Jun 2008 15:29:02 -0700 Subject: [PATCH] Changed profit to take into account the overhead along with the total labor cost when profit is a % * Fixed Models * Fixed JS Calculator * Cleaned up specs to access attributes directly #1349 --- app/models/deliverable.rb | 10 ++++++++++ app/models/fixed_deliverable.rb | 2 +- app/models/hourly_deliverable.rb | 4 +++- app/views/deliverables/_form.html.erb | 3 ++- spec/models/deliverable_spec.rb | 10 +++++----- spec/models/fixed_deliverable_spec.rb | 11 ++++++++--- spec/models/hourly_deliverable_spec.rb | 11 ++++++++--- 7 files changed, 37 insertions(+), 14 deletions(-) diff --git a/app/models/deliverable.rb b/app/models/deliverable.rb index e171eb1..a49964f 100644 --- a/app/models/deliverable.rb +++ b/app/models/deliverable.rb @@ -68,8 +68,16 @@ class Deliverable < ActiveRecord::Base return ((self.spent / self.budget) * 100).round end + def overhead + return read_attribute(:overhead) unless read_attribute(:overhead).nil? + return ((read_attribute(:overhead_percent).to_f / 100.0) * self.labor_budget) unless read_attribute(:overhead_percent).nil? + return 0 + end + # Setter for the overhead to take an Dollar amount or a %. def overhead=(v) + return if v.nil? + if v.match(/%/) # Clear amount since this is a % write_attribute(:overhead, nil) @@ -84,6 +92,8 @@ class Deliverable < ActiveRecord::Base # Setter for the materials to take an Dollar amount or a %. def materials=(v) + return if v.nil? + if v.match(/%/) # Clear amount since this is a % write_attribute(:materials, nil) diff --git a/app/models/fixed_deliverable.rb b/app/models/fixed_deliverable.rb index 35d9b41..5ca869d 100644 --- a/app/models/fixed_deliverable.rb +++ b/app/models/fixed_deliverable.rb @@ -16,7 +16,7 @@ class FixedDeliverable < Deliverable if read_attribute(:profit_percent).nil? return super else - return (read_attribute(:profit_percent).to_f / 100.0) * read_attribute(:fixed_cost) + return (read_attribute(:profit_percent).to_f / 100.0) * (read_attribute(:fixed_cost) + self.overhead) end end diff --git a/app/models/hourly_deliverable.rb b/app/models/hourly_deliverable.rb index d7c4589..84b82f9 100644 --- a/app/models/hourly_deliverable.rb +++ b/app/models/hourly_deliverable.rb @@ -35,7 +35,9 @@ class HourlyDeliverable < Deliverable if read_attribute(:profit_percent).nil? return super else - return (read_attribute(:profit_percent).to_f / 100.0) * (read_attribute(:cost_per_hour) * read_attribute(:total_hours)) + labor = (read_attribute(:cost_per_hour) * read_attribute(:total_hours)) + + return (read_attribute(:profit_percent).to_f / 100.0) * (labor + self.overhead) end end diff --git a/app/views/deliverables/_form.html.erb b/app/views/deliverables/_form.html.erb index f556fd6..0bb38d6 100644 --- a/app/views/deliverables/_form.html.erb +++ b/app/views/deliverables/_form.html.erb @@ -150,8 +150,9 @@ Object.extend(BudgetModule.prototype, { var materials_subtotal = Budget.toAmount($('deliverable_materials').value); } + // Profit uses labor cost and overhead if ($('deliverable_profit').value.match('%')) { - var profit_subtotal = (Budget.toAmount($('deliverable_profit').value) / 100) * cost; + var profit_subtotal = (Budget.toAmount($('deliverable_profit').value) / 100) * (cost + overhead_subtotal); } else { var profit_subtotal = Budget.toAmount($('deliverable_profit').value); } diff --git a/spec/models/deliverable_spec.rb b/spec/models/deliverable_spec.rb index 342be0f..f188bbd 100644 --- a/spec/models/deliverable_spec.rb +++ b/spec/models/deliverable_spec.rb @@ -20,7 +20,7 @@ describe Deliverable, 'associations' do end end -describe Deliverable, '.overhead' do +describe Deliverable, '.overhead=' do before(:each) do @deliverable = Deliverable.new({ :subject => 'test' }) end @@ -28,24 +28,24 @@ describe Deliverable, '.overhead' do describe 'with a dollar amount' do it 'should store the dollar amount' do @deliverable.overhead = "$1, 000.10" - @deliverable.overhead.should eql(1000.1) + @deliverable.read_attribute(:overhead).should eql(1000.1) end it 'should clear the .overhead_percent' do @deliverable.overhead = "$1, 000.10" - @deliverable.overhead_percent.should eql(nil) + @deliverable.read_attribute(:overhead_percent).should eql(nil) end end describe 'with a percentage' do it 'should store the % of the amount to .overhead_percent' do @deliverable.overhead = "100 %" - @deliverable.overhead_percent.should eql(100) + @deliverable.read_attribute(:overhead_percent).should eql(100) end it 'should clean the .overhead' do @deliverable.overhead = "100 %" - @deliverable.overhead.should eql(nil) + @deliverable.read_attribute(:overhead).should eql(nil) end end end diff --git a/spec/models/fixed_deliverable_spec.rb b/spec/models/fixed_deliverable_spec.rb index 46ea144..56016e3 100644 --- a/spec/models/fixed_deliverable_spec.rb +++ b/spec/models/fixed_deliverable_spec.rb @@ -17,8 +17,13 @@ describe FixedDeliverable, '.spent' do end describe FixedDeliverable, '.profit as a %' do - it 'should return the % of the fixed bid amount' do - @deliverable = FixedDeliverable.new({ :subject => 'test', :profit_percent => 50, :fixed_cost => 1000.0 }) - @deliverable.profit.should eql(500.0) + it 'should return the % of the fixed bid and overhead amount' do + @deliverable = FixedDeliverable.new({ :subject => 'test', :profit_percent => 50, :fixed_cost => 1000.0, :overhead => "1000.00", :overhead_percent => nil }) + @deliverable.profit.should eql(1000.0) + end + + it 'should return the % of the fixed bid and overhead percentage' do + @deliverable = FixedDeliverable.new({ :subject => 'test', :profit_percent => 50, :fixed_cost => 1000.0, :overhead => nil, :overhead_percent => 100 }) + @deliverable.profit.should eql(1000.0) end end diff --git a/spec/models/hourly_deliverable_spec.rb b/spec/models/hourly_deliverable_spec.rb index 5bcd084..0d4a0dc 100644 --- a/spec/models/hourly_deliverable_spec.rb +++ b/spec/models/hourly_deliverable_spec.rb @@ -28,8 +28,13 @@ describe HourlyDeliverable, '.spent' do end describe HourlyDeliverable, '.profit as a %' do - it 'should return the % of the hours mutipled by the cost per hour amount' do - @deliverable = HourlyDeliverable.new({ :subject => 'test', :profit_percent => 50, :cost_per_hour => 100.0, :total_hours => 10 }) - @deliverable.profit.should eql(500.0) + it 'should return the % of the hours mutipled by the cost per hour amount plus the overhead' do + @deliverable = HourlyDeliverable.new({ :subject => 'test', :profit_percent => 50, :cost_per_hour => 100.0, :total_hours => 10, :overhead => '1000.00', :overhead_percent => nil }) + @deliverable.profit.should eql(1000.0) + end + + it 'should return the % of the hours mutipled by the cost per hour amount plus the overhead percentage' do + @deliverable = HourlyDeliverable.new({ :subject => 'test', :profit_percent => 50, :cost_per_hour => 100.0, :total_hours => 10, :overhead => nil, :overhead_percent => 100 }) + @deliverable.profit.should eql(1000.0) end end