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
This commit is contained in:
Eric Davis committed 2008-06-19 15:29:02 -07:00
1 parent 5431df3d8d
commit b776098c7d
7 files changed
+37 -14

No files matched your search

+10
View File
@@ -68,8 +68,16 @@ class Deliverable < ActiveRecord::Base
return ((self.spent / self.budget) * 100).round return ((self.spent / self.budget) * 100).round
end 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 %. # Setter for the overhead to take an Dollar amount or a %.
def overhead=(v) def overhead=(v)
return if v.nil?
if v.match(/%/) if v.match(/%/)
# Clear amount since this is a % # Clear amount since this is a %
write_attribute(:overhead, nil) write_attribute(:overhead, nil)
@@ -84,6 +92,8 @@ class Deliverable < ActiveRecord::Base
# Setter for the materials to take an Dollar amount or a %. # Setter for the materials to take an Dollar amount or a %.
def materials=(v) def materials=(v)
return if v.nil?
if v.match(/%/) if v.match(/%/)
# Clear amount since this is a % # Clear amount since this is a %
write_attribute(:materials, nil) write_attribute(:materials, nil)
+1 -1
View File
@@ -16,7 +16,7 @@ class FixedDeliverable < Deliverable
if read_attribute(:profit_percent).nil? if read_attribute(:profit_percent).nil?
return super return super
else 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
end end
+3 -1
View File
@@ -35,7 +35,9 @@ class HourlyDeliverable < Deliverable
if read_attribute(:profit_percent).nil? if read_attribute(:profit_percent).nil?
return super return super
else 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
end end
+2 -1
View File
@@ -150,8 +150,9 @@ Object.extend(BudgetModule.prototype, {
var materials_subtotal = Budget.toAmount($('deliverable_materials').value); var materials_subtotal = Budget.toAmount($('deliverable_materials').value);
} }
// Profit uses labor cost and overhead
if ($('deliverable_profit').value.match('%')) { 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 { } else {
var profit_subtotal = Budget.toAmount($('deliverable_profit').value); var profit_subtotal = Budget.toAmount($('deliverable_profit').value);
} }
+5 -5
View File
@@ -20,7 +20,7 @@ describe Deliverable, 'associations' do
end end
end end
describe Deliverable, '.overhead' do describe Deliverable, '.overhead=' do
before(:each) do before(:each) do
@deliverable = Deliverable.new({ :subject => 'test' }) @deliverable = Deliverable.new({ :subject => 'test' })
end end
@@ -28,24 +28,24 @@ describe Deliverable, '.overhead' do
describe 'with a dollar amount' do describe 'with a dollar amount' do
it 'should store the dollar amount' do it 'should store the dollar amount' do
@deliverable.overhead = "$1, 000.10" @deliverable.overhead = "$1, 000.10"
@deliverable.overhead.should eql(1000.1) @deliverable.read_attribute(:overhead).should eql(1000.1)
end end
it 'should clear the .overhead_percent' do it 'should clear the .overhead_percent' do
@deliverable.overhead = "$1, 000.10" @deliverable.overhead = "$1, 000.10"
@deliverable.overhead_percent.should eql(nil) @deliverable.read_attribute(:overhead_percent).should eql(nil)
end end
end end
describe 'with a percentage' do describe 'with a percentage' do
it 'should store the % of the amount to .overhead_percent' do it 'should store the % of the amount to .overhead_percent' do
@deliverable.overhead = "100 %" @deliverable.overhead = "100 %"
@deliverable.overhead_percent.should eql(100) @deliverable.read_attribute(:overhead_percent).should eql(100)
end end
it 'should clean the .overhead' do it 'should clean the .overhead' do
@deliverable.overhead = "100 %" @deliverable.overhead = "100 %"
@deliverable.overhead.should eql(nil) @deliverable.read_attribute(:overhead).should eql(nil)
end end
end end
end end
+8 -3
View File
@@ -17,8 +17,13 @@ describe FixedDeliverable, '.spent' do
end end
describe FixedDeliverable, '.profit as a %' do describe FixedDeliverable, '.profit as a %' do
it 'should return the % of the fixed bid amount' do it 'should return the % of the fixed bid and overhead amount' do
@deliverable = FixedDeliverable.new({ :subject => 'test', :profit_percent => 50, :fixed_cost => 1000.0 }) @deliverable = FixedDeliverable.new({ :subject => 'test', :profit_percent => 50, :fixed_cost => 1000.0, :overhead => "1000.00", :overhead_percent => nil })
@deliverable.profit.should eql(500.0) @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
end end
+8 -3
View File
@@ -28,8 +28,13 @@ describe HourlyDeliverable, '.spent' do
end end
describe HourlyDeliverable, '.profit as a %' do describe HourlyDeliverable, '.profit as a %' do
it 'should return the % of the hours mutipled by the cost per hour amount' do 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 }) @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(500.0) @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
end end