Skip to content

Commit

Permalink
Merge pull request #161 from sparc-request/kg-invoice_report_sort_filter
Browse files Browse the repository at this point in the history
KG - Invoice Report Sorting (2.2.0)
  • Loading branch information
kyle-glick committed May 5, 2016
2 parents 74f494f + b2654ac commit 0bb918e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def reports_params
:end_date,
:time_zone,
:protocol_id,
:sort_by,
:sort_order,
:participant_id,
:documentable_id,
:documentable_type,
Expand Down
21 changes: 21 additions & 0 deletions app/views/reports/_invoice_report.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@
.form-group.hidden
= label_tag "protocol", t(:reports)[:protocols], class: "col-sm-3 control-label"
.col-sm-9#protocol_section
= select_tag "protocol_ids", truncated_options_from_collection_for_select(current_identity.protocols, "id", "short_title_with_sparc_id"), multiple: true, 'data-live-search' => true, 'data-actions-box' => true, title: t(:reports)[:all_protocols], class: "selectpicker form-control"
.form-group
= label_tag "sort_by", t(:reports)[:sort_by], class: "col-sm-3 control-label"
.col-sm-3
%label.radio-inline
= radio_button_tag "sort_by", t(:reports)[:protocol_id], true
= t(:reports)[:protocol_id]
.col-sm-3
%label.radio-inline
= radio_button_tag "sort_by", t(:reports)[:primary_pi]
= t(:reports)[:primary_pi]
.form-group
= label_tag "sort_order", t(:reports)[:sort_order], class: "col-sm-3 control-label"
.col-sm-3
%label.radio-inline
= radio_button_tag "sort_order", t(:reports)[:asc], true
= t(:reports)[:ascending]
.col-sm-3
%label.radio-inline
= radio_button_tag "sort_order", t(:reports)[:desc]
= t(:reports)[:descending]
.modal-footer
.center-block
%button.btn.btn-default{type: 'button', data: {dismiss: 'modal'}}= t(:actions)[:close]
Expand Down
8 changes: 8 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -298,19 +298,27 @@ en:
updates: "Updates"

reports:
asc: "ASC"
ascending: "Ascending"
all_protocols: "All Protocols"
auditing_report: "Auditing Report"
desc: "DESC"
descending: "Descending"
invoice_report: "Invoice Report"
end_date: "End Date"
incomplete_visit_report: "Incomplete Visit Report"
organization: "Organization(s)"
page_title: "All Reports"
participant: "Participant"
participant_report: "Participant Report"
primary_pi: "Primary PI"
project_summary_report: "Project Summary Report"
protocol: "Protocol"
protocols: "Protocol(s)"
protocol_id: "Protocol ID"
request_report: "Request Report"
sort_by: "Sort By"
sort_order: "Sort Order"
start_date: "Start Date"

services:
Expand Down
18 changes: 15 additions & 3 deletions lib/reports/invoice_report.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class InvoiceReport < Report

VALIDATES_PRESENCE_OF = [:title, :start_date, :end_date].freeze
VALIDATES_PRESENCE_OF = [:title, :start_date, :end_date, :sort_by, :sort_order].freeze
VALIDATES_NUMERICALITY_OF = [].freeze

require 'csv'
Expand All @@ -26,9 +26,21 @@ def generate(document)
csv << [""]

if @params[:protocol_ids].present?
protocols = Protocol.find(@params[:protocol_ids])
if @params[:sort_by] == "Protocol ID"
protocols = Protocol.where(id: @params[:protocol_ids]).sort_by(&:sparc_id)
else
protocols = Protocol.where(id: @params[:protocol_ids]).sort_by{ |protocol| protocol.pi.full_name }
end
else
protocols = Identity.find(@params[:identity_id]).protocols
if @params[:sort_by] == "Protocol ID"
protocols = Identity.find(@params[:identity_id]).protocols.sort_by(&:sparc_id)
else
protocols = Identity.find(@params[:identity_id]).protocols.sort_by{ |protocol| protocol.pi.full_name }
end
end

if @params[:sort_order] == "DESC"
protocols.reverse!
end

protocols.each do |protocol|
Expand Down

0 comments on commit 0bb918e

Please sign in to comment.