-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Admin | ||
class ReportsController < BaseAdminController | ||
before_action :ensure_service_operator | ||
|
||
def index | ||
@reports = Report.all | ||
end | ||
|
||
def show | ||
respond_to do |format| | ||
format.csv { | ||
report = Report.find(params[:id]) | ||
send_data report.csv, filename: "#{report.name.parameterize(separator: "_")}_#{report.created_at.iso8601}.csv" | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class ReportsJob < CronJob | ||
self.cron_expression = "0 6 * * 2#2" # second Tuesday of the month | ||
|
||
def perform | ||
Rails.logger.info "Generating Ops reports" | ||
|
||
Report.create!(name: Reports::DuplicateClaims::NAME, csv: Reports::DuplicateClaims.new.to_csv) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Report < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require "csv" | ||
require "excel_utils" | ||
|
||
module Reports | ||
class DuplicateClaims | ||
include Admin::ClaimsHelper | ||
|
||
NAME = "Duplicate Approved Claims" | ||
HEADERS = [ | ||
"Claim reference", | ||
"Teacher reference number", | ||
"Full name", | ||
"Policy name", | ||
"Claim amount", | ||
"Claim status", | ||
"Decision date", | ||
"Decision agent" | ||
].freeze | ||
|
||
def initialize | ||
@claims = Claim.approved.select { |claim| Claim::MatchingAttributeFinder.new(claim).matching_claims.any? } | ||
end | ||
|
||
def to_csv | ||
CSV.generate(write_headers: true, headers: HEADERS) do |csv| | ||
@claims.each do |claim| | ||
csv << row( | ||
claim.reference, | ||
claim.eligibility.teacher_reference_number, | ||
claim.full_name, | ||
claim.policy, | ||
claim.award_amount, | ||
status(claim), | ||
claim.latest_decision.created_at, | ||
claim.latest_decision.created_by.full_name | ||
) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def row(*entries) | ||
entries.map { |entry| ExcelUtils.escape_formulas(entry) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "csv" | ||
require "excel_utils" | ||
|
||
module Reports | ||
class FailedProviderCheckClaims | ||
NAME = "Claims with failed provider check" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require "csv" | ||
require "excel_utils" | ||
|
||
module Reports | ||
class FailedQualificationClaims | ||
NAME = "Claims with failed qualification status" | ||
HEADERS = [ | ||
"Claim reference", | ||
"Teacher reference number", | ||
"Policy name", | ||
"Decision date", | ||
"Decision agent" | ||
].freeze | ||
|
||
def initialize | ||
@claims = Claim.approved.select { |claim| Claim::MatchingAttributeFinder.new(claim).matching_claims.any? } | ||
end | ||
|
||
def to_csv | ||
CSV.generate(write_headers: true, headers: HEADERS) do |csv| | ||
@claims.each do |claim| | ||
csv << row( | ||
claim.reference, | ||
claim.eligibility.teacher_reference_number, | ||
claim.policy, | ||
claim.latest_decision.created_at, | ||
claim.latest_decision.created_by.full_name | ||
) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def row(*entries) | ||
entries.map { |entry| ExcelUtils.escape_formulas(entry) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<% content_for(:page_title) { page_title("Download Reports") } %> | ||
|
||
<% content_for :back_link do %> | ||
<%= govuk_back_link href: admin_root_path %> | ||
<% end %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-full"> | ||
<h1 class="govuk-heading-xl"> | ||
Reports | ||
</h1> | ||
|
||
<table class="govuk-table"> | ||
<thead class="govuk-table__head"> | ||
<tr class="govuk-table__row"> | ||
<th scope="col" class="govuk-table__header">Name</th> | ||
<th scope="col" class="govuk-table__header">Created At</th> | ||
</tr> | ||
</thead> | ||
<tbody class="govuk-table__body"> | ||
<% @reports.each do |report| %> | ||
<tr class="govuk-table__row"> | ||
<td class="govuk-table__cell"><%= govuk_link_to report.name, admin_report_path(report, format: :csv) %></td> | ||
<td class="govuk-table__cell"><%= l(report.created_at) %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,3 +131,9 @@ | |
- verification | ||
:journeys_sessions: | ||
- answers | ||
:reports: | ||
- id | ||
- name | ||
- csv | ||
- created_at | ||
- updated_at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateReports < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :reports, id: :uuid do |t| | ||
t.string :name | ||
t.text :csv | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters