Skip to content

Commit

Permalink
Add Kpi status breakdown
Browse files Browse the repository at this point in the history
  • Loading branch information
fumimowdan committed Sep 22, 2023
1 parent 9bf72a6 commit bfa77d1
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/kpis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ def time_to_banking_approval
def time_to_payment_confirmation
TimeToPaymentConfirmationQuery.new.call
end

def status_breakdown
StatusBreakdownQuery.call
end
end
22 changes: 22 additions & 0 deletions app/queries/status_breakdown_query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class StatusBreakdownQuery
def self.call
new.execute
end

def execute
ordered_with_defaults(status_breakdown)
end

private

def status_breakdown
ApplicationProgress.group(:status).count
end

def ordered_with_defaults(breakdown)
ApplicationProgress.statuses.each_with_object({}) do |(key, _), hsh|
hsh[key] = breakdown.fetch(key, 0)
hsh
end
end
end
13 changes: 13 additions & 0 deletions app/views/system_admin/dashboard/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,17 @@
</table>
</div>

<div class="kpi-widget status-breakdown">
<h3 class="title">Statuses</h3>
<table class="kpi-table">
<% @kpis.status_breakdown.each do |k,v|%>
<tr>
<td><%= link_to(k.titleize, applicants_path(search: nil, status: k)) %></td>
<td><%= v %></td>
</tr>
<% end %>
</table>
</div>


</div>
45 changes: 45 additions & 0 deletions spec/queries/status_breakdown_query_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require "rails_helper"

RSpec.describe StatusBreakdownQuery, type: :service do
subject(:breakdown) { described_class.call }

describe ".call" do
let(:expected_breakdown) do
{
"initial_checks" => 0,
"home_office_checks" => 0,
"school_checks" => 0,
"bank_approval" => 0,
"payment_confirmation" => 0,
"paid" => 0,
"rejected" => 0,
}
end

it "returns the ordered application status breakdown" do
expect(breakdown).to include(expected_breakdown)
end

context "with data" do
before do
create(:application, :with_initial_checks_completed)
end

let(:expected_breakdown) do
{
"initial_checks" => 0,
"home_office_checks" => 1,
"school_checks" => 0,
"bank_approval" => 0,
"payment_confirmation" => 0,
"paid" => 0,
"rejected" => 0,
}
end

it "returns the ordered application status breakdown" do
expect(breakdown).to include(expected_breakdown)
end
end
end
end

0 comments on commit bfa77d1

Please sign in to comment.