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

KG - Step 2B: Calendar Query and Rendering Need Improvement Part 5 - OTF Quantities #997

Merged
merged 8 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from 5 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
22 changes: 16 additions & 6 deletions app/assets/javascripts/service_calendar.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,28 @@ $(document).ready ->
line_item:
quantity: params.value
service_request_id: getSRId()
sub_service_request_id: getSSRId()
}
success: ->
scroll = $(this).parents('.scrolling-div').length > 0
reload_calendar($(this).data('armId'), scroll)
success: (data) ->
# Replace Study Total
$(this).parent().siblings('.total-per-study').replaceWith(data['total_per_study'])

# Replace Totals
$('.total-direct-one-time-fee-cost-per-study').replaceWith(data['max_total_direct'])
$('.total-one-time-fee-cost-per-study').replaceWith(data['total_costs'])

$('.edit-units-per-qty').editable
params: (params) ->
{
line_item:
units_per_quantity: params.value
service_request_id: getSRId()
sub_service_request_id: getSSRId()
}
success: ->
scroll = $(this).parents('.scrolling-div').length > 0
reload_calendar($(this).data('armId'), scroll)
success: (data) ->
# Replace Study Total
$(this).parent().siblings('.total-per-study').replaceWith(data['total_per_study'])

# Replace Totals
$('.total-direct-one-time-fee-cost-per-study').replaceWith(data['max_total_direct'])
$('.total-one-time-fee-cost-per-study').replaceWith(data['total_costs'])
18 changes: 11 additions & 7 deletions app/controllers/line_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ class LineItemsController < ApplicationController

# Used for x-editable update and validations
def update
@line_item = LineItem.find( params[:id] )
@service_request = ServiceRequest.find( params[:srid] )
line_item = LineItem.find(params[:id])

if @line_item.update_attributes(line_item_params)
@service_request.update_attributes(status: 'draft')
@line_item.sub_service_request.update_attributes(status: 'draft')
render nothing: true
if line_item.update_attributes(line_item_params)
@service_request.update_attribute(:status, 'draft')
line_item.sub_service_request.update_attribute(:status, 'draft')

render json: {
total_per_study: render_to_string(partial: 'service_calendars/master_calendar/otf/total_per_study', locals: { line_item: line_item }),
max_total_direct: render_to_string(partial: 'service_calendars/master_calendar/otf/totals/max_total_direct_one_time_fee', locals: { service_request: @service_request }),
total_costs: render_to_string(partial: 'service_calendars/master_calendar/otf/totals/total_cost_per_study', locals: { service_request: @service_request })
}
else
render json: @line_item.errors, status: :unprocessable_entity
render json: line_item.errors, status: :unprocessable_entity
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
- else
%a.edit-qty{ href: 'javascript:void(0)', data: { name: 'quantity', title: t(:calendars)[:otf][:editable_fields][:quantity], value: line_item.quantity, url: line_item_path(line_item, srid: service_request.id) } }

%td.total-per-study.text-center
%strong
= display_one_time_fee_direct_cost(line_item)
= render 'service_calendars/master_calendar/otf/total_per_study', line_item: line_item

- unless review
= render 'service_calendars/master_calendar/otf/otf_totals', service_request: service_request
= render 'service_calendars/master_calendar/otf/totals/otf_totals', service_request: service_request
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-# Copyright © 2011 MUSC Foundation for Research Development
-# All rights reserved.

-# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

-# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

-# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
-# disclaimer in the documentation and/or other materials provided with the distribution.

-# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
-# derived from this software without specific prior written permission.

-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
-# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%td.total-per-study.text-center
%strong
= display_one_time_fee_direct_cost(line_item)
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,3 @@
%td.text-center
%strong
= display_total_direct_cost_per_study_otfs(service_request, service_request.line_items)
%tr.total-one-time-fee-cost-per-study
%th.total-one-time-fee-width{ colspan: 10 }
= t(:calendars)[:otf][:totals][:total_costs]
%td.text-center
%strong
= display_total_cost_per_study_otfs(service_request, service_request.line_items)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-# Copyright © 2011 MUSC Foundation for Research Development
-# All rights reserved.

-# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

-# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

-# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
-# disclaimer in the documentation and/or other materials provided with the distribution.

-# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
-# derived from this software without specific prior written permission.

-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
-# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
= render 'service_calendars/master_calendar/otf/totals/max_total_direct_one_time_fee', service_request: service_request
= render 'service_calendars/master_calendar/otf/totals/total_cost_per_study', service_request: service_request
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-# Copyright © 2011 MUSC Foundation for Research Development
-# All rights reserved.

-# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

-# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

-# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
-# disclaimer in the documentation and/or other materials provided with the distribution.

-# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
-# derived from this software without specific prior written permission.

-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
-# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%tr.total-one-time-fee-cost-per-study
%th.total-one-time-fee-width{ colspan: 10 }
= t(:calendars)[:otf][:totals][:total_costs]
%td.text-center
%strong
= display_total_cost_per_study_otfs(service_request, service_request.line_items)
51 changes: 12 additions & 39 deletions spec/controllers/line_items/put_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
let!(:logged_in_user) { create(:identity) }

describe '#update' do

before :each do
session[:identity_id] = logged_in_user.id
end

it 'should call before_filter #initialize_service_request' do
expect(before_filters.include?(:initialize_service_request)).to eq(true)
end
Expand All @@ -34,42 +39,6 @@
expect(before_filters.include?(:authorize_identity)).to eq(true)
end

it 'should assign @line_item' do
protocol = create(:protocol_without_validations, primary_pi: logged_in_user)
sr = create(:service_request_without_validations, protocol: protocol)
org = create(:organization)
ssr = create(:sub_service_request_without_validations, service_request: sr, organization: org)
service = create(:service, one_time_fee: true)
li = create(:line_item_without_validations, sub_service_request: ssr, service: service, service_request: sr)
li_params = { quantity: 2 }

xhr :put, :update, {
id: li.id,
srid: sr.id,
line_item: li_params
}

expect(assigns(:line_item)).to eq(li)
end

it 'should assign @service_request' do
protocol = create(:protocol_without_validations, primary_pi: logged_in_user)
sr = create(:service_request_without_validations, protocol: protocol)
org = create(:organization)
ssr = create(:sub_service_request_without_validations, service_request: sr, organization: org)
service = create(:service, one_time_fee: true)
li = create(:line_item_without_validations, sub_service_request: ssr, service: service, service_request: sr)
li_params = { quantity: 2 }

xhr :put, :update, {
id: li.id,
srid: sr.id,
line_item: li_params
}

expect(assigns(:service_request)).to eq(sr)
end

context 'line item valid' do
it 'should update line item' do
protocol = create(:protocol_without_validations, primary_pi: logged_in_user)
Expand Down Expand Up @@ -125,7 +94,7 @@
expect(ssr.reload.status).to eq('draft')
end

it 'should render nothing' do
it 'should render totals JSON' do
protocol = create(:protocol_without_validations, primary_pi: logged_in_user)
sr = create(:service_request_without_validations, protocol: protocol)
org = create(:organization)
Expand All @@ -140,7 +109,11 @@
line_item: li_params
}

expect(response.body).to be_blank
json = JSON.parse(response.body)

expect(json['total_per_study']).to be
expect(json['max_total_direct']).to be
expect(json['total_costs']).to be
end

it 'should respond ok' do
Expand Down Expand Up @@ -178,7 +151,7 @@
line_item: li_params
}

expect(JSON.parse(response.body)).to be
expect(JSON.parse(response.body)['quantity']).to be
end

it 'should respond unprocessable_entity' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

require 'rails_helper'

RSpec.describe '/service_calendar/master_calendar/otf/_otf_totals', type: :view do
RSpec.describe '/service_calendar/master_calendar/otf/totals/_otf_totals', type: :view do

let_there_be_lane

Expand All @@ -31,20 +31,20 @@

it 'should display total direct costs for Non-clinical services if USE_INDIRECT_COST is true' do
stub_const("USE_INDIRECT_COST", true)
render "/service_calendars/master_calendar/otf/otf_totals", service_request: @service_request
render "/service_calendars/master_calendar/otf/totals/otf_totals", service_request: @service_request

expect(response).to have_content('Total Direct Costs (Non-clinical Services) Per Study')
end

it 'should not display total direct costs for Non-clinical services if USE_INDIRECT_COST is false' do
stub_const("USE_INDIRECT_COST", false)
render "/service_calendars/master_calendar/otf/otf_totals", service_request: @service_request
render "/service_calendars/master_calendar/otf/totals/otf_totals", service_request: @service_request

expect(response).to_not have_content('Total Direct Costs (Non-clinical Services) Per Study')
end

it 'should display total Non-clinicals costs' do
render "/service_calendars/master_calendar/otf/otf_totals", service_request: @service_request
render "/service_calendars/master_calendar/otf/totals/otf_totals", service_request: @service_request

expect(response).to have_content('Total Costs (Non-clinical Services) Per Study')
end
Expand Down