diff --git a/app/models/deliverable.rb b/app/models/deliverable.rb index a0665e2..c167cdb 100644 --- a/app/models/deliverable.rb +++ b/app/models/deliverable.rb @@ -58,6 +58,10 @@ class Deliverable < ActiveRecord::Base labor_budgets.sum(:budget) end + def labor_budget_total_for_date(date=nil) #Used on subclasses + labor_budget_total + end + def overhead_budget_total overhead_budgets.sum(:budget) end diff --git a/app/models/retainer_deliverable.rb b/app/models/retainer_deliverable.rb index 3f96077..f5b191e 100644 --- a/app/models/retainer_deliverable.rb +++ b/app/models/retainer_deliverable.rb @@ -31,6 +31,14 @@ class RetainerDeliverable < HourlyDeliverable end_date && end_date.end_of_month.to_date end + def date_range + (beginning_date..ending_date) + end + + def within_date_range?(date) + date_range.include?(date) + end + def months month_acc = [] @@ -67,6 +75,18 @@ class RetainerDeliverable < HourlyDeliverable budgets end + def labor_budget_total_for_date(date=nil) + if date + if within_date_range?(date) + labor_budgets.sum(:budget, :conditions => {:year => date.year, :month => date.month}) + else + 0 # outside of range + end + else + labor_budgets.sum(:budget) + end + end + def create_budgets_for_periods # For each month in the time span months.each do |month| diff --git a/test/unit/deliverable_test.rb b/test/unit/deliverable_test.rb index b03611d..cb937ee 100644 --- a/test/unit/deliverable_test.rb +++ b/test/unit/deliverable_test.rb @@ -33,4 +33,38 @@ class DeliverableTest < ActiveSupport::TestCase assert_equal 20100.00, d.total.to_f end end + + context "#labor_budget_spent_for_period" do + should "use all periods" + end + + context "#labor_budget_total_for_period" do + should "use all periods" + end + + context "#overhead_spent_for_period" do + should "use all periods" + end + + context "#overhead_budget_total_for_period" do + should "use all periods" + end + + context "#profit_left_for_period" do + should "use all periods" + end + + context "#profit_budget_for_period" do + should "use all periods" + end + + context "#total_spent_for_period" do + should "use all periods" + end + + context "#total_for_period" do + should "use all periods" + end + + end diff --git a/test/unit/retainer_deliverable_test.rb b/test/unit/retainer_deliverable_test.rb index 4fbbe73..5abf8b0 100644 --- a/test/unit/retainer_deliverable_test.rb +++ b/test/unit/retainer_deliverable_test.rb @@ -79,5 +79,57 @@ class RetainerDeliverableTest < ActiveSupport::TestCase end end - + + context "#labor_budget_spent_for_date" do + context "with a empty period" do + should "use all periods" + end + + context "with a period out of the retainer range" do + should "use all periods" + end + + context "with a period in the retainer range" do + should "filter the records" + end + end + + context "#labor_budget_total_for_date" do + setup do + @deliverable = RetainerDeliverable.generate!(:start_date => '2010-01-01', :end_date => '2010-03-31') + @deliverable.labor_budgets << LaborBudget.spawn(:budget => 100, :hours => 10) + @deliverable.save! + end + + context "with a empty period" do + should "use all periods" do + assert_equal 300.0, @deliverable.labor_budget_total_for_date(nil) + end + end + + context "with a period out of the retainer range" do + should "filter the records" do + assert_equal 0, @deliverable.labor_budget_total_for_date(Date.new(2011,1,1)) + end + end + + context "with an invalid period" do + should "return 0" do + assert_equal 0, @deliverable.labor_budget_total_for_date('1') + end + end + + context "with a period in the retainer range" do + should "filter the records" do + assert_equal 100.0, @deliverable.labor_budget_total_for_date(Date.new(2010,2,1)) + end + end + end + + # context "#overhead_spent_for_date" + # context "#overhead_budget_total_for_date" + # context "#profit_left_for_date" + # context "#profit_budget_for_date" + # context "#total_spent_for_date" + # context "#total_for_date" end