Skip to content

Commit

Permalink
[CPDLP-3840] Remove NPQ importers
Browse files Browse the repository at this point in the history
  • Loading branch information
leandroalemao committed Dec 19, 2024
1 parent 6ab489b commit fde1522
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 1,374 deletions.
3 changes: 1 addition & 2 deletions app/services/importers/create_cohort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def create_cohort(row)
start_year:,
registration_start_date: safe_parse(row["registration-start-date"]),
academic_year_start_date: safe_parse(row["academic-year-start-date"]),
npq_registration_start_date: safe_parse(row["npq-registration-start-date"]),
automatic_assignment_period_end_date: safe_parse(row["automatic-assignment-period-end-date"]) || default_automatic_assignment_period_end_date,
payments_frozen_at: safe_parse(row["payments-frozen-at"]).presence,
created_at: Time.zone.now,
Expand All @@ -60,7 +59,7 @@ def safe_parse(date)
end

def check_headers!
unless %w[start-year registration-start-date academic-year-start-date npq-registration-start-date automatic-assignment-period-end-date payments-frozen-at].all? { |header| rows.headers.include?(header) }
unless %w[start-year registration-start-date academic-year-start-date automatic-assignment-period-end-date payments-frozen-at].all? { |header| rows.headers.include?(header) }
raise NameError, "Invalid headers"
end
end
Expand Down
29 changes: 0 additions & 29 deletions app/services/importers/create_new_npq_cohort.rb

This file was deleted.

32 changes: 0 additions & 32 deletions app/services/importers/create_new_npq_course.rb

This file was deleted.

110 changes: 0 additions & 110 deletions app/services/importers/create_npq_contract.rb

This file was deleted.

51 changes: 0 additions & 51 deletions app/services/importers/create_npq_course.rb

This file was deleted.

48 changes: 1 addition & 47 deletions app/services/importers/create_statement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def call

ActiveRecord::Base.transaction do
create_ecf_statements!
create_npq_statements!
end

logger.info "CreateStatement: Finished!"
Expand Down Expand Up @@ -66,40 +65,6 @@ def create_ecf_statements!
end
end

def create_npq_statements!
npq_statements.each do |statement_data|
npq_lead_providers_with_contracts_for(cohort: statement_data.cohort).each do |npq_lead_provider|
cpd_lead_provider = npq_lead_provider.cpd_lead_provider

logger.info "CreateStatement: Creating #{statement_data.cohort.start_year} cohort NPQ statements for #{cpd_lead_provider.name}"

statement = Finance::Statement::NPQ.find_by(
name: statement_data.name,
cpd_lead_provider:,
cohort: statement_data.cohort,
)

next if statement

contract_version = Finance::Statement::NPQ.where(cpd_lead_provider:, cohort: statement_data.cohort).order(payment_date: :desc).first&.contract_version
contract_version ||= "0.0.1"

Finance::Statement::NPQ.create!(
name: statement_data.name,
cpd_lead_provider:,
deadline_date: statement_data.deadline_date,
payment_date: statement_data.payment_date,
cohort: statement_data.cohort,
output_fee: statement_data.output_fee,
type: class_for(statement_data, namespace: statement_data.type),
contract_version:,
)

logger.info "CreateStatement: #{statement_data.cohort.start_year} cohort NPQ statements for #{cpd_lead_provider.name} successfully created!"
end
end
end

def class_for(statment_data, namespace:)
return namespace::Paid if statment_data[:payment_date] < Date.current
return namespace::Payable if Date.current.between?(statment_data[:deadline_date], statment_data[:payment_date])
Expand All @@ -111,9 +76,7 @@ def statement_converter
lambda do |value, field_info|
case field_info.header
when "type"
return Finance::Statement::ECF if value.downcase == "ecf"

Finance::Statement::NPQ if value.downcase == "npq"
Finance::Statement::ECF if value.downcase == "ecf"
when "deadline_date", "payment_date"
Date.parse(value)
when "output_fee"
Expand Down Expand Up @@ -145,18 +108,9 @@ def ecf_statements
@ecf_statements ||= rows.map { |hash| OpenStruct.new(hash) }.select { |row| row.type == Finance::Statement::ECF }
end

def npq_statements
@npq_statements ||= rows.map { |hash| OpenStruct.new(hash) }.select { |row| row.type == Finance::Statement::NPQ }
end

def lead_providers_with_ecf_contracts_for(cohort:)
@ecf_contracts ||= {}
@ecf_contracts[cohort.id] ||= CallOffContract.includes(lead_provider: :cpd_lead_provider).where(cohort:).map(&:lead_provider)
end

def npq_lead_providers_with_contracts_for(cohort:)
@npq_contracts ||= {}
@npq_contracts[cohort.id] ||= NPQContract.includes(npq_lead_provider: :cpd_lead_provider).where(cohort:).map(&:npq_lead_provider)
end
end
end
5 changes: 1 addition & 4 deletions app/services/importers/ecf_manual_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ def get_profile(id)

def prepare_profile(participant_profile)
# reset TRN if present on teacher profile to avoid "different trn" errors
# unless already set via NPQ
teacher_profile = participant_profile.teacher_profile
if teacher_profile.trn.present? && teacher_profile.participant_profiles.npqs.none?
teacher_profile.update!(trn: nil)
end
teacher_profile.update!(trn: nil) if teacher_profile.trn.present?

# remove any existing eligibilty
participant_profile.ecf_participant_eligibility&.destroy!
Expand Down
48 changes: 0 additions & 48 deletions app/services/importers/npq_manual_validation.rb

This file was deleted.

Loading

0 comments on commit fde1522

Please sign in to comment.