Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for totals #166

Merged
merged 1 commit into from
May 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 13 additions & 8 deletions lib/reports/invoice_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def generate(document)
protocols.each do |protocol|
total = 0

if protocol.fulfillments.fulfilled_in_date_range(@start_date, @end_date).any?
fulfillments = protocol.fulfillments.fulfilled_in_date_range(@start_date, @end_date)
procedures = protocol.procedures.completed_r_in_date_range(@start_date, @end_date)

if fulfillments.any?
csv << ["Study Level Charges:"]
csv << [
"Protocol ID",
Expand All @@ -65,7 +68,7 @@ def generate(document)
]
csv << [""]

protocol.fulfillments.fulfilled_in_date_range(@start_date, @end_date).joins(:line_item).order("line_items.quantity_type, fulfilled_at").each do |fulfillment|
fulfillments.joins(:line_item).order("line_items.quantity_type, fulfilled_at").each do |fulfillment|
csv << [
format_protocol_id_column(protocol),
protocol.sparc_protocol.short_title,
Expand All @@ -86,7 +89,7 @@ def generate(document)
end
end

if protocol.procedures.completed_r_in_date_range(@start_date, @end_date).any?
if procedures.any?
csv << [""]
csv << [""]

Expand All @@ -106,7 +109,7 @@ def generate(document)
"Total Cost"
]
csv << [""]
protocol.procedures.completed_r_in_date_range(@start_date, @end_date).group_by(&:appointment).each do |appointment, appointment_procedures|
procedures.group_by(&:appointment).each do |appointment, appointment_procedures|
participant = appointment.participant

appointment_procedures.group_by(&:service_name).each do |service_name, service_procedures|
Expand All @@ -130,10 +133,12 @@ def generate(document)
end
end
end
csv << [""]
csv << ["", "", "", "", "", "", "", "", "", "", "Study Level and Per Patient Total:", display_cost(total)]
csv << [""]
csv << [""]
if fulfillments.any? or procedures.any?
csv << [""]
csv << ["", "", "", "", "", "", "", "", "", "", "Study Level and Per Patient Total:", display_cost(total)]
csv << [""]
csv << [""]
end
end
end
end
Expand Down