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

Jtm invoice report subsidy #226

Merged
merged 7 commits into from
Dec 5, 2016
9 changes: 8 additions & 1 deletion lib/reports/invoice_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def generate(document)

protocols.each do |protocol|
total = 0
total_with_subsidy = 0

fulfillments = protocol.fulfillments.fulfilled_in_date_range(@start_date, @end_date)
procedures = protocol.procedures.completed_r_in_date_range(@start_date, @end_date)
Expand Down Expand Up @@ -108,6 +109,7 @@ def generate(document)
]

total += fulfillment.total_cost
total_with_subsidy += protocol.sub_service_request.subsidy ? fulfillment.total_cost * (1 - protocol.sub_service_request.subsidy.percent_subsidy) : fulfillment.total_cost
end
end

Expand All @@ -130,6 +132,7 @@ def generate(document)
"Quantity Completed",
"Research Rate",
"",
protocol.sub_service_request.subsidy ? "Percent Subsidy" : "",
"Total Cost"
]
csv << [""]
Expand Down Expand Up @@ -158,9 +161,12 @@ def generate(document)
service_group.size,
display_cost(procedure.service_cost),
"",
"#{protocol.sub_service_request.subsidy ? protocol.sub_service_request.subsidy.percent_subsidy * 100 : 0}%",
display_cost(service_group.size * procedure.service_cost.to_f)
]
total += service_group.size * procedure.service_cost.to_f
service_cost = service_group.size * procedure.service_cost.to_f
total += service_cost
total_with_subsidy += protocol.sub_service_request.subsidy ? service_cost * (1 - protocol.sub_service_request.subsidy.percent_subsidy) : service_cost
end
end
end
Expand All @@ -169,6 +175,7 @@ def generate(document)
if fulfillments.any? or procedures.any?
csv << [""]
csv << ["", "", "", "", "", "", "", "", "", "", "", "", "Study Level and Per Patient Total:", display_cost(total)]
csv << ["", "", "", "", "", "", "", "", "", "", "", "", "Total Cost after Subsidy:", display_cost(total_with_subsidy)] if protocol.sub_service_request.subsidy
csv << [""]
csv << [""]
end
Expand Down