Skip to content

Commit

Permalink
Merge pull request #226 from sparc-request/jtm_invoice_report_subsidy
Browse files Browse the repository at this point in the history
Jtm invoice report subsidy
  • Loading branch information
jleonardw9 committed Dec 5, 2016
2 parents 0a881fb + d6ae0f2 commit bd7cddb
Showing 1 changed file with 8 additions and 1 deletion.
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

0 comments on commit bd7cddb

Please sign in to comment.