Merge pull request #1378 from consul/recounting

Final recounts info to Admin
This commit is contained in:
Raimond Garcia
2017-01-30 21:54:35 +01:00
committed by GitHub
13 changed files with 101 additions and 27 deletions

View File

@@ -24,7 +24,7 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController
def show
@poll = ::Poll.find(params[:poll_id])
@booth_assignment = @poll.booth_assignments.includes(:recounts, :voters, officer_assignments: [officer: [:user]]).find(params[:id])
@booth_assignment = @poll.booth_assignments.includes(:recounts, :final_recounts, :voters, officer_assignments: [officer: [:user]]).find(params[:id])
@voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date}
end

View File

@@ -4,7 +4,7 @@ class Officing::FinalRecountsController < Officing::BaseController
def new
@officer_assignments = ::Poll::OfficerAssignment.
includes(:final_recounts, booth_assignment: :booth).
includes(:final_recounts, booth_assignment: [:booth]).
joins(:booth_assignment).
final.
where(id: current_user.poll_officer.officer_assignment_ids).

View File

@@ -16,4 +16,13 @@ module OfficingHelper
options_for_select(options)
end
def recount_to_compare_with_final_recount(final_recount)
recount = final_recount.booth_assignment.recounts.select {|r| r.date == final_recount.date}.first
recount.present? ? recount.count : "-"
end
def system_recount_to_compare_with_final_recount(final_recount)
final_recount.booth_assignment.voters.select {|v| v.created_at.to_date == final_recount.date}.size
end
end

View File

@@ -0,0 +1,7 @@
module PollFinalRecountsHelper
def final_recount_for_date(final_recounts, date)
final_recounts.select {|f| f.date == date}.first
end
end

View File

@@ -1,7 +1,7 @@
module PollRecountsHelper
def recount_for_date(recounts, date)
recounts.select {|r| r.date.to_date == date}.first
recounts.select {|r| r.date == date}.first
end
end

View File

@@ -55,26 +55,30 @@
<tr>
<th><%= t("admin.poll_booth_assignments.show.date") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_by_officer") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_final") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_by_system") %></th>
</tr>
</thead>
<tbody>
<% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %>
<% recount = recount_for_date(@booth_assignment.recounts, voting_date) %>
<% final_recount = final_recount_for_date(@booth_assignment.final_recounts, voting_date) %>
<% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %>
<% if recount.present? %>
<tr id="recount_<%= recount.id %>" class="<%= 'count-error' if recount.count != system_count %>">
<td><%= l voting_date %></td>
<td class="text-center" title="<%= recount.officer_assignment.officer.name %>"><%= recount.count %></td>
<td class="text-center"><%= system_count %></td>
</tr>
<% else %>
<tr id="recount_<%= voting_date.strftime('%Y%m%d') %>">
<td><%= l voting_date %></td>
<tr id="recounting_<%= voting_date.strftime('%Y%m%d') %>">
<td><%= l voting_date %></td>
<% if recount.present? %>
<td class="text-center <%= 'count-error' if recount.count != system_count %>" title="<%= recount.officer_assignment.officer.name %>"><%= recount.count %></td>
<% else %>
<td class="text-center" title=""> - </td>
<td class="text-center"><%= system_count %></td>
</tr>
<% end %>
<% end %>
<% if final_recount.present? %>
<td class="text-center <%= 'count-error' if final_recount.count != system_count %>" title="<%= final_recount.officer_assignment.officer.name %>"><%= final_recount.count %></td>
<% else %>
<td class="text-center" title=""> - </td>
<% end %>
<td class="text-center"><%= system_count %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -52,6 +52,8 @@
<th><%= t("officing.final_recounts.new.date") %></th>
<th><%= t("officing.final_recounts.new.booth") %></th>
<th><%= t("officing.final_recounts.new.count") %></th>
<th><%= "Recuento diario anterior" %></th>
<th><%= "Recuento del sistema" %></th>
</thead>
<tbody>
<% @final_recounts.each do |final_recount| %>
@@ -65,6 +67,12 @@
<td>
<strong><%= final_recount.count %></strong>
</td>
<td>
<strong><%= recount_to_compare_with_final_recount final_recount %></strong>
</td>
<td>
<strong><%= system_recount_to_compare_with_final_recount final_recount %></strong>
</td>
</tr>
<% end %>
</tbody>