[#4477] Added the amounts spent for FixedBudgets
This commit is contained in:
+11
-3
@@ -36,8 +36,6 @@ class Contract < ActiveRecord::Base
|
||||
named_scope :by_name, {:order => "#{Contract.table_name}.name ASC"}
|
||||
|
||||
[:status, :contract_type,
|
||||
:fixed_spent,
|
||||
:fixed_markup_spent,
|
||||
:discount_spent, :discount_budget
|
||||
].each do |mthd|
|
||||
define_method(mthd) { "TODO in later release" }
|
||||
@@ -100,12 +98,22 @@ class Contract < ActiveRecord::Base
|
||||
def fixed_budget
|
||||
deliverables.inject(0) {|total, deliverable| total += deliverable.fixed_budget_total }
|
||||
end
|
||||
|
||||
|
||||
# OPTIMIZE: N+1
|
||||
def fixed_spent
|
||||
deliverables.inject(0) {|total, deliverable| total += deliverable.fixed_budget_total_spent }
|
||||
end
|
||||
|
||||
# OPTIMIZE: N+1
|
||||
def fixed_markup_budget
|
||||
deliverables.inject(0) {|total, deliverable| total += deliverable.fixed_markup_budget_total }
|
||||
end
|
||||
|
||||
# OPTIMIZE: N+1
|
||||
def fixed_markup_spent
|
||||
deliverables.inject(0) {|total, deliverable| total += deliverable.fixed_markup_budget_total_spent }
|
||||
end
|
||||
|
||||
def after_initialize
|
||||
self.executed = false unless self.executed.present?
|
||||
end
|
||||
|
||||
@@ -92,11 +92,20 @@ class Deliverable < ActiveRecord::Base
|
||||
fixed_budgets.sum(:budget)
|
||||
end
|
||||
|
||||
def fixed_budget_total_spent(date=nil)
|
||||
fixed_budgets.paid.sum(:budget)
|
||||
end
|
||||
|
||||
# OPTIMIZE: N+1
|
||||
def fixed_markup_budget_total(date=nil)
|
||||
fixed_budgets.inject(0) {|total, fixed_budget| total += fixed_budget.markup_value }
|
||||
end
|
||||
|
||||
# OPTIMIZE: N+1
|
||||
def fixed_markup_budget_total_spent(date=nil)
|
||||
fixed_budgets.paid.inject(0) {|total, fixed_budget| total += fixed_budget.markup_value }
|
||||
end
|
||||
|
||||
def filter_by_date(date=nil, &block)
|
||||
block.call
|
||||
end
|
||||
|
||||
@@ -23,6 +23,8 @@ class FixedBudget < ActiveRecord::Base
|
||||
end
|
||||
}
|
||||
|
||||
named_scope :paid, {:conditions => {:paid => true}}
|
||||
|
||||
def markup_value
|
||||
return 0 if budget.blank? || markup.blank?
|
||||
|
||||
@@ -38,6 +40,14 @@ class FixedBudget < ActiveRecord::Base
|
||||
|
||||
end
|
||||
|
||||
def budget_spent
|
||||
if paid?
|
||||
budget
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
def percent_markup?
|
||||
markup && markup.match(/%/)
|
||||
end
|
||||
|
||||
@@ -133,6 +133,17 @@ class RetainerDeliverable < HourlyDeliverable
|
||||
end
|
||||
end
|
||||
|
||||
def fixed_budget_total_spent(date=nil)
|
||||
case scope_date_status(date)
|
||||
when :in
|
||||
fixed_budgets.paid.sum(:budget, :conditions => {:year => date.year, :month => date.month})
|
||||
when :out
|
||||
0
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def fixed_markup_budget_total(date=nil)
|
||||
case scope_date_status(date)
|
||||
when :in
|
||||
@@ -145,6 +156,21 @@ class RetainerDeliverable < HourlyDeliverable
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def fixed_markup_budget_total_spent(date=nil)
|
||||
case scope_date_status(date)
|
||||
when :in
|
||||
fixed_budgets.
|
||||
paid.
|
||||
all(:conditions => {:year => date.year, :month => date.month}).
|
||||
inject(0) {|total, fixed_budget| total += fixed_budget.markup_value }
|
||||
when :out
|
||||
0
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def total_spent(date=nil)
|
||||
case scope_date_status(date)
|
||||
when :in
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
<td width="15%" class="manager"><%= h deliverable.manager.try(:name) %></td>
|
||||
<%= format_budget_for_deliverable(deliverable, deliverable.labor_budget_spent, deliverable.labor_budget_total, :class => 'labor') %>
|
||||
<%= format_budget_for_deliverable(deliverable, deliverable.overhead_spent, deliverable.overhead_budget_total, :class => 'overhead') %>
|
||||
<%= format_budget_for_deliverable(deliverable, 0, deliverable.fixed_budget_total, :class => 'fixed') %>
|
||||
<%= format_budget_for_deliverable(deliverable, deliverable.fixed_budget_total_spent, deliverable.fixed_budget_total, :class => 'fixed') %>
|
||||
<% end %>
|
||||
|
||||
<tr id="deliverable_details_<%= h(deliverable.id) %>" class="ign">
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
<% next if fixed_budget.blank_record? %>
|
||||
<tr id="fixed_budget_<%= fixed_budget.id %>">
|
||||
<td class="l fixed_title" title="<%= h(fixed_budget.description) %>"><%= h(fixed_budget.title) %></td>
|
||||
<td class="fixed_budget_spent">0</td>
|
||||
<td class="fixed_budget_spent"><%= h(format_value_field_for_contracts(fixed_budget.budget_spent)) %></td>
|
||||
<td class="fixed_budget_total"><%= h(format_value_field_for_contracts(fixed_budget.budget)) %></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
@@ -75,7 +75,7 @@
|
||||
|
||||
<tr>
|
||||
<td class="l"><%= l(:field_markup) %></td>
|
||||
<td class="fixed_markup_budget_spent">0</td>
|
||||
<td class="fixed_markup_budget_spent"><%= h(format_value_field_for_contracts(deliverable.fixed_markup_budget_total_spent(period))) %></td>
|
||||
<td class="fixed_markup_budget_total"><%= h(format_value_field_for_contracts(deliverable.fixed_markup_budget_total(period))) %></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user