[#4420] Working on creating labor budgets for each retainer month.

This commit is contained in:
Eric Davis
2010-08-23 16:15:57 -07:00
parent f899b4e623
commit 7d43ab7d74
5 changed files with 125 additions and 26 deletions
+34
View File
@@ -14,6 +14,7 @@ class RetainerDeliverable < HourlyDeliverable
# Accessors
# Callbacks
after_save :create_budgets_for_periods
def short_type
'R'
@@ -23,6 +24,39 @@ class RetainerDeliverable < HourlyDeliverable
'TODO'
end
def beginning_date
start_date && start_date.beginning_of_month
end
def ending_date
end_date && end_date.end_of_month
end
def months
month_acc = []
current_date = beginning_date
while current_date < ending_date do
month_acc << current_date
current_date = current_date.advance(:months => 1)
end
month_acc
end
def create_budgets_for_periods
# For each month in the time span
months.each do |month|
# Iterate over all un-dated budgets, created dated versions
undated_labor_budgets = labor_budgets.all(:conditions => ["#{LaborBudget.table_name}.year IS NULL AND #{LaborBudget.table_name}.month IS NULL"])
undated_labor_budgets.each do |template_budget|
labor_budgets.create(template_budget.attributes.merge(:year => month.year, :month => month.month))
end
end
# Destroy origional un-dated budgets
labor_budgets.all(:conditions => ["#{LaborBudget.table_name}.year IS NULL AND #{LaborBudget.table_name}.month IS NULL"]).collect(&:destroy)
end
def self.frequencies_to_select
ValidFrequencies.collect {|f| [l("text_#{f}"), f]}
end