Skip to content

Commit

Permalink
Showing request cost and final approval date (#913)
Browse files Browse the repository at this point in the history
* Showing request cost and final approval date

* Fixed tests

* Removed unneded line

---------

Co-authored-by: Ryan Laddusaw <[email protected]>
  • Loading branch information
rladdusaw and Ryan Laddusaw authored Jul 24, 2023
1 parent 46509ac commit 421a4d6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
24 changes: 23 additions & 1 deletion app/decorators/report_list_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def report_json
'status': request.latest_status,
'staff': request.full_name,
'department': request.department.name,
'event_format': request.event_format
'event_format': request.event_format,
'approval_date': approval_date(request),
'total': total(request)
}
end.to_json
end
Expand Down Expand Up @@ -112,4 +114,24 @@ def title(request)
"#{request.title} (#{request.hours_requested} hours)"
end
end

def approval_date(request)
if request.status == "approved"
request.updated_at.strftime("%B %-d, %Y")
else
""
end
end

def total(request)
if request.is_a?(TravelRequestDecorator)
total = 0.00
request.estimates.each do |est|
total += est.amount * est.recurrence
end
format("%.2f", total)
else
"0.00"
end
end
end
4 changes: 3 additions & 1 deletion app/views/requests/_report_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
{ 'name': 'status', 'display_name': 'Status', 'sortable': true},
{ 'name': 'staff', 'display_name': 'Staff', 'sortable': true},
{ 'name': 'department', 'display_name': 'Department', 'sortable': true},
{ 'name': 'event_format', 'display_name': 'Event format', 'sortable': true}]"
{ 'name': 'event_format', 'display_name': 'Event format', 'sortable': true},
{ 'name': 'approval_date', 'display_name': 'Approval Date', 'sortable': true},
{ 'name': 'total', 'display_name': 'Total', 'sortable': true, datatype: 'currency'}]"
:json-data="<%= @requests.report_json %>"/>
</article>
</grid-item>
Expand Down
6 changes: 4 additions & 2 deletions spec/decorators/report_list_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,15 @@
"\"end_date\":\"#{absence_request.end_date.strftime('%B %-d, %Y')}\"," \
"\"status\":\"Pending\",\"staff\":\"#{absence_request.creator.full_name}\"," \
"\"department\":\"#{absence_request.department.name}\"," \
"\"event_format\":\"#{absence_request.event_format}\"}," \
"\"event_format\":\"#{absence_request.event_format}\"," \
"\"approval_date\":\"\",\"total\":\"0.00\"}," \
"{\"id\":#{travel_request.id},\"request_type\":{\"value\":\"#{travel_request.title}\",\"link\":\"http://localhost:3000/travel_requests/#{travel_request.id}\"}," \
"\"start_date\":\"#{travel_request.start_date.strftime('%B %-d, %Y')}\"," \
"\"end_date\":\"#{travel_request.end_date.strftime('%B %-d, %Y')}\"," \
"\"status\":\"Pending\",\"staff\":\"#{travel_request.creator.full_name}\"," \
"\"department\":\"#{travel_request.department.name}\"," \
"\"event_format\":\"#{travel_request.event_format}\"}]"
"\"event_format\":\"#{travel_request.event_format}\"," \
"\"approval_date\":\"\",\"total\":\"0.00\"}]"
)
end
end
Expand Down
19 changes: 13 additions & 6 deletions spec/features/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
sign_in user
end

after do
Timecop.return
end

scenario "I can filter reports" do
Timecop.freeze(Time.utc(2019, "oct", 20))

direct_report = FactoryBot.create :staff_profile, supervisor: staff_profile, department: staff_profile.department, given_name: "Sally", surname: "Smith"
FactoryBot.create(:absence_request, creator: staff_profile.supervisor, start_date: Date.parse("2019-10-12"), end_date: Date.parse("2019-10-13"))
FactoryBot.create(:absence_request, creator: staff_profile, start_date: Date.parse("2019-10-12"), end_date: Date.parse("2019-10-13"), hours_requested: 10.3)
Expand All @@ -26,8 +32,9 @@
FactoryBot.create(:travel_request, creator: staff_profile, action: "approve", start_date: Date.parse("2020-10-20"), end_date: Date.parse("2012-10-23"), event_requests: [event_request2])
recurring_event3 = FactoryBot.create(:recurring_event, name: "Wow", description: "Wow you must go!!!")
event_request3 = FactoryBot.build(:event_request, recurring_event: recurring_event3, start_date: Date.parse("2020-05-21"), end_date: Date.parse("2020-05-23"))
FactoryBot.create(:travel_request, creator: staff_profile, action: "approve",
travel_category: "professional_development", start_date: Date.parse("2020-05-21"), end_date: Date.parse("2020-05-23"), event_requests: [event_request3])
FactoryBot.create(:travel_request, :with_note_and_estimate, creator: staff_profile, action: "approve",
travel_category: "professional_development", start_date: Date.parse("2020-05-21"),
end_date: Date.parse("2020-05-23"), event_requests: [event_request3])

visit "/"

Expand All @@ -36,12 +43,12 @@

Percy.snapshot(page, name: "Reports - show", widths: [375, 768, 1440])
assert_selector ".my-request tr", count: Request.count # header row included in count
expect(page).to have_content "Wow 2020, Location (05/21/2020 to 05/23/2020) May 21, 2020 May 23, 2020 Approved Pat Doe ITIMS In-person\n"
expect(page).to have_content "Wow 2020, Location (05/21/2020 to 05/23/2020) May 21, 2020 May 23, 2020 Approved Pat Doe ITIMS In-person October 20, 2019 150.00"
expect(page).to have_content "Best Event Ever 2020, Location (10/21/2020 to 10/23/2020) October 20, 2020 October 23, 2012 Approved Pat Doe ITIMS"
expect(page).to have_content "Awesome Event 2019, Location (10/21/2019 to 10/23/2019) October 21, 2019 October 23, 2019 Pending Pat Doe ITIMS In-person\n"
expect(page).to have_content "Sick Leave (17.3 hours) October 15, 2019 October 16, 2019 Approved Pat Doe ITIMS"
expect(page).to have_content "Awesome Event 2019, Location (10/21/2019 to 10/23/2019) October 21, 2019 October 23, 2019 Pending Pat Doe ITIMS In-person 0.00\n"
expect(page).to have_content "Sick Leave (17.3 hours) October 15, 2019 October 16, 2019 Approved Pat Doe ITIMS October 20, 2019"
expect(page).to have_content "Sick Leave (10.0 hours) October 14, 2019 October 15, 2019 Pending Pat Doe ITIMS"
expect(page).to have_content "Vacation (15.5 hours) October 13, 2019 October 14, 2019 Approved Sally Smith ITIMS\n"
expect(page).to have_content "Vacation (15.5 hours) October 13, 2019 October 14, 2019 Approved Sally Smith ITIMS October 20, 2019"
expect(page).to have_content "Vacation (10.3 hours) October 12, 2019 October 13, 2019 Pending Pat Doe ITIMS"

select_drop_down(menu: "#status-menu", item: "Approved")
Expand Down

0 comments on commit 421a4d6

Please sign in to comment.