Last active
January 3, 2016 19:48
-
-
Save JackPott/8510513 to your computer and use it in GitHub Desktop.
This doesn't feel very Ruby? Basically groups and counts the total number of connectors used in project and is displays a report
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Reports#connectors_total</h1> | |
<p>Find me in app/views/reports/connectors_total.html.erb</p> | |
<table> | |
<tr> | |
<th>Connector</th> | |
<th class=align-right>Total</th> | |
<th class=align-right>Total cost</th> | |
<th>Order code</th> | |
</tr> | |
<% @connectors_total.each do |connector| %> | |
<tr> | |
<td><%= connector[:connector_type][:name] %></td> | |
<td class=align-right><%= connector[:count] %></td> | |
<td class=align-right><%= number_to_currency((connector[:total_cost]), unit: "£") %></td> | |
<td><%= connector[:connector_type][:part_code] %> | |
</tr> | |
<% end %> | |
</table> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Each termination has a connector | |
class Termination < ActiveRecord::Base | |
# Returns an array of connectors | |
def self.connectors_total(project) | |
Termination.where(project: project).group(:connector_type_id).count(:connector_type_id).map do |id, value| | |
connector_type = ConnectorType.find(id) | |
{ connector_type: connector_type, count: value, total_cost: value*connector_type.cost } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment