[#4602] Show overage values in red
This commit is contained in:
1 parent
d3f9255eef
commit
0f9308267c
4 files changed
+113
-16
No files matched your search
@@ -9,10 +9,16 @@ module ContractsHelper
|
||||
|
||||
def format_budget_for_deliverable(deliverable, spent, total, options={})
|
||||
extra_css_class = options[:class] || ''
|
||||
|
||||
|
||||
if total > 0 || spent > 0
|
||||
content_tag(:td, h(format_value_field_for_contracts(spent)), :class => 'spent-amount ' + extra_css_class) +
|
||||
content_tag(:td, h(format_value_field_for_contracts(total)), :class => 'total-amount white ' + extra_css_class)
|
||||
spent_css_classes = 'spent-amount'
|
||||
spent_css_classes << " #{overage_class(spent, total)}"
|
||||
spent_css_classes << ' ' << extra_css_class
|
||||
total_css_classes = 'total-amount white'
|
||||
total_css_classes << ' ' << extra_css_class
|
||||
|
||||
content_tag(:td, h(format_value_field_for_contracts(spent)), :class => spent_css_classes) +
|
||||
content_tag(:td, h(format_value_field_for_contracts(total)), :class => total_css_classes)
|
||||
else
|
||||
content_tag(:td, '----', :colspan => '2', :class => 'no-value ' + extra_css_class)
|
||||
end
|
||||
@@ -61,12 +67,16 @@ module ContractsHelper
|
||||
def show_budget_field(object, spent_field, total_field, options={})
|
||||
|
||||
formatter = options[:format] || :number_to_currency
|
||||
spent_content = send(formatter, object.send(spent_field))
|
||||
total_content = send(formatter, object.send(total_field))
|
||||
spent_value = object.send(spent_field)
|
||||
total_value = object.send(total_field)
|
||||
spent_content = send(formatter, spent_value)
|
||||
total_content = send(formatter, total_value)
|
||||
|
||||
reverse_overage = spent_field.to_s.match(/profit/i)
|
||||
|
||||
show_field(object, spent_field, options.merge(:raw => true, :wrap_in_td => false)) do
|
||||
|
||||
content_tag(:td, h(spent_content), :class => 'spent') +
|
||||
content_tag(:td, h(spent_content), :class => "spent #{overage_class(spent_value, total_value, :reverse => reverse_overage)}") +
|
||||
content_tag(:td, h(total_content), :class => 'budget')
|
||||
end
|
||||
end
|
||||
@@ -164,4 +174,27 @@ module ContractsHelper
|
||||
return '' unless (1..5).include?(version)
|
||||
image_tag("todo#{version}.png", :plugin => 'redmine_contracts', :title => "Coming in release #{version}. #{message}")
|
||||
end
|
||||
|
||||
# Overage occurs when spent is negative or spent is greater than budget
|
||||
#
|
||||
# :reverse - spent is reverse, it is overage when it's less than budget
|
||||
def overage?(spent, budget, options={})
|
||||
return false unless spent && budget
|
||||
return true if spent < 0
|
||||
|
||||
if options[:reverse]
|
||||
spent.to_f < budget.to_f
|
||||
else
|
||||
spent.to_f > budget.to_f
|
||||
end
|
||||
end
|
||||
|
||||
def overage_class(spent, budget, options={})
|
||||
if overage?(spent, budget, options)
|
||||
'overage'
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -52,18 +52,22 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="l"><a href="#"><strong><%= l(:field_labor) %></strong></a><%= release(3, "Deliverable lightbox") %></td>
|
||||
<td class="labor_budget_spent"><%= h(format_value_field_for_contracts(deliverable.labor_budget_spent(validated_period))) %></td>
|
||||
<td class="labor_budget_spent <%= overage_class(deliverable.labor_budget_spent(validated_period), deliverable.labor_budget_total(validated_period)) %>">
|
||||
<%= h(format_value_field_for_contracts(deliverable.labor_budget_spent(validated_period))) %>
|
||||
</td>
|
||||
<td class="labor_budget_total"><%= h(format_value_field_for_contracts(deliverable.labor_budget_total(validated_period))) %></td>
|
||||
<td class="labor_hours">
|
||||
<%= h(format_value_field_for_contracts(deliverable.labor_hours_spent_total(validated_period))) %>/<%= h(format_value_field_for_contracts(deliverable.labor_budget_hours(validated_period))) %> <%= l(:text_short_hours) %>
|
||||
<span class="<%= overage_class(deliverable.labor_hours_spent_total(validated_period), deliverable.labor_budget_hours(validated_period)) %>"><%= h(format_value_field_for_contracts(deliverable.labor_hours_spent_total(validated_period))) %></span>/<%= h(format_value_field_for_contracts(deliverable.labor_budget_hours(validated_period))) %> <%= l(:text_short_hours) %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="l"><a href="#"><strong><%= l(:field_overhead) %></strong></a><%= release(3, "Deliverable lightbox") %></td>
|
||||
<td class="overhead_budget_spent"><%= h(format_value_field_for_contracts(deliverable.overhead_spent(validated_period))) %></td>
|
||||
<td class="overhead_budget_spent <%= overage_class(deliverable.overhead_spent(validated_period), deliverable.overhead_budget_total(validated_period)) %>">
|
||||
<%= h(format_value_field_for_contracts(deliverable.overhead_spent(validated_period))) %>
|
||||
</td>
|
||||
<td class="overhead_budget_total"><%= h(format_value_field_for_contracts(deliverable.overhead_budget_total(validated_period))) %></td>
|
||||
<td class="overhead_hours">
|
||||
<%= h(format_value_field_for_contracts(deliverable.overhead_hours_spent_total(validated_period))) %>/<%= h(format_value_field_for_contracts(deliverable.overhead_budget_hours(validated_period))) %> <%= l(:text_short_hours) %>
|
||||
<span class="<%= overage_class(deliverable.overhead_hours_spent_total(validated_period), deliverable.overhead_budget_hours(validated_period)) %>"><%= h(format_value_field_for_contracts(deliverable.overhead_hours_spent_total(validated_period))) %></span>/<%= h(format_value_field_for_contracts(deliverable.overhead_budget_hours(validated_period))) %> <%= l(:text_short_hours) %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -71,7 +75,9 @@
|
||||
<% 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"><%= h(format_value_field_for_contracts(fixed_budget.budget_spent)) %></td>
|
||||
<td class="fixed_budget_spent <%= overage_class(fixed_budget.budget_spent, fixed_budget.budget) %>">
|
||||
<%= 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>
|
||||
@@ -80,7 +86,9 @@
|
||||
<% if show_markup_for?(deliverable, validated_period) %>
|
||||
<tr>
|
||||
<td class="l"><%= l(:field_markup) %></td>
|
||||
<td class="fixed_markup_budget_spent"><%= h(format_value_field_for_contracts(deliverable.fixed_markup_budget_total_spent(validated_period))) %></td>
|
||||
<td class="fixed_markup_budget_spent <%= overage_class(deliverable.fixed_markup_budget_total_spent(validated_period), deliverable.fixed_markup_budget_total(validated_period)) %>">
|
||||
<%= h(format_value_field_for_contracts(deliverable.fixed_markup_budget_total_spent(validated_period))) %>
|
||||
</td>
|
||||
<td class="fixed_markup_budget_total"><%= h(format_value_field_for_contracts(deliverable.fixed_markup_budget_total(validated_period))) %></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
@@ -88,17 +96,24 @@
|
||||
|
||||
<tr>
|
||||
<td class="l"><%= l(:field_profit) %></td>
|
||||
<td><%= h(format_value_field_for_contracts(deliverable.profit_left(validated_period))) %></td>
|
||||
<td><%= h(format_value_field_for_contracts(deliverable.profit_budget(validated_period))) %></td>
|
||||
<td class="profit_spent <%= overage_class(deliverable.profit_left(validated_period), deliverable.profit_budget(validated_period), :reverse => true) %>">
|
||||
<%= h(format_value_field_for_contracts(deliverable.profit_left(validated_period))) %>
|
||||
</td>
|
||||
<td class="profit_total"><%= h(format_value_field_for_contracts(deliverable.profit_budget(validated_period))) %></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="total">
|
||||
<td class="l"><strong><%= l(:field_total) %>:</strong></td>
|
||||
<td class="total_spent"><strong><%= h(format_value_field_for_contracts(deliverable.total_spent(validated_period))) %></strong></td>
|
||||
<td class="total_spent <%= overage_class(deliverable.total_spent(validated_period), deliverable.total(validated_period)) %>">
|
||||
<strong>
|
||||
<%= h(format_value_field_for_contracts(deliverable.total_spent(validated_period))) %>
|
||||
</strong>
|
||||
</td>
|
||||
<td class="total"><strong><%= h(format_value_field_for_contracts(deliverable.total(validated_period))) %></strong></td>
|
||||
<td class="total_hours">
|
||||
<strong>
|
||||
<%= h(format_value_field_for_contracts(deliverable.hours_spent_total(validated_period))) %>/<%= h(format_value_field_for_contracts(deliverable.estimated_hour_budget_total(validated_period))) %> <%= l(:text_short_hours) %>
|
||||
<span class="<%= overage_class(deliverable.hours_spent_total(validated_period), deliverable.estimated_hour_budget_total(validated_period)) %>">
|
||||
<%= h(format_value_field_for_contracts(deliverable.hours_spent_total(validated_period))) %></span>/<%= h(format_value_field_for_contracts(deliverable.estimated_hour_budget_total(validated_period))) %> <%= l(:text_short_hours) %>
|
||||
</strong>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in new issue
Block a user