OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/app/views/hooks/_view_issues_show_details_b...

51 lines
2.0 KiB

<%-
def summarized_cost_entries(cost_entries)
last_cost_type = ""
result = cost_entries.sort_by(&:id).inject(Hash.new) do |result, entry|
if entry.cost_type.id.to_s == last_cost_type
result[last_cost_type][:units] += entry.units
else
last_cost_type = entry.cost_type.id.to_s
result[last_cost_type] = {}
result[last_cost_type][:units] = entry.units
result[last_cost_type][:unit] = entry.cost_type.unit
result[last_cost_type][:unit_plural] = entry.cost_type.unit_plural
end
result
end
return "-" if result.empty?
str_array = []
options = {:class => 'icon icon-box'}
result.each do |k, v|
str_array << link_to(pluralize(v[:units], v[:unit], v[:unit_plural]), {:controller => 'costlog', :action => 'details', :project_id => @issue.project, :issue_id => @issue, :cost_type_id => k}, options)
options = {} # options apply only for first element
end
str_array.join(", ")
end
-%>
<% if @project.module_enabled? :costs_module %>
<%# Only render this partial, if the plugin is enabled for the current project %>
<tr>
<td><b><%= l(:label_cost_object) %>:</b></td>
<td><% if @issue.cost_object.nil? %>-<%else%><%= link_to h(@issue.cost_object.subject), {:controller => "cost_objects", :action => "show", :id => @issue.cost_object, :project_id => @project} %><% end %></td>
<% if User.current.allowed_to?(:view_cost_entries, @project) %>
<td><b><%= l(:label_spent_units) %>:</b></td>
<td>
<%= summarized_cost_entries(@issue.cost_entries) %>
</td>
<% end %>
</tr>
<% if User.current.allowed_to?(:view_unit_price, @project) && User.current.allowed_to?(:view_all_rates, @project)%>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><b><%= l(:label_overall_costs) %>:</b></td>
<td><% if @issue.overall_costs > 0 %><%= link_to number_to_currency(@issue.overall_costs), {:controller => 'costlog', :action => 'details', :project_id => @issue.project, :issue_id => @issue}, :class => 'icon icon-money' %><% else %>-<%end%></td>
</tr>
<% end %>
<% end %>