Skip to content

Commit

Permalink
feat(crm): updating precision in support case columns
Browse files Browse the repository at this point in the history
  • Loading branch information
DevMagnataur committed Sep 10, 2024
1 parent 5fa08b1 commit ea3877a
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def new
def create
@case_additional_contact_form = CaseAdditionalContactForm.from_validation(validation)
@current_case = Support::Case.find(case_additional_contact_form_params[:support_case_id]) if @current_case.blank?
@emails = @current_case.case_additional_contacts&.pluck(:email)
if validation.success? && !@emails.include?(case_additional_contact_form_params[:email])
Support::CaseAdditionalContact.create!(case_additional_contact_form_params)
redirect_to support_case_additional_contacts_path(case_id: @current_case.id), notice: I18n.t("support.case_contact_details.flash.success")
Expand All @@ -30,7 +29,6 @@ def edit

def update
@case_additional_contact_form = CaseAdditionalContactForm.from_validation(validation)
@emails.delete(@additional_contact.email)
if validation.success? && !@emails.include?(case_additional_contact_form_params[:email])
@additional_contact.update!(case_additional_contact_form_params)
redirect_to support_case_additional_contacts_path(case_id: @current_case.id), notice: I18n.t("support.case_contact_details.flash.update_success") if @additional_contact.update(case_additional_contact_form_params)
Expand Down
20 changes: 12 additions & 8 deletions app/controllers/support/cases/summaries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ def edit

def update
@case_summary = CaseSummaryPresenter.new(current_case.summary(summary_params))
if @case_summary.value.to_i > 99999999
@case_summary.errors.add(:value, I18n.t("framework_request.errors.rules.procurement_amount.too_large"))
render :edit
else
if @case_summary.valid?
return render :update if submit_action == "confirm"
return render :edit if submit_action == "change"

if @case_summary.valid?
return render :update if submit_action == "confirm"
return render :edit if submit_action == "change"

@case_summary.save!
@case_summary.save!

redirect_to support_case_path(@current_case, anchor: "case-details")
else
render :edit
redirect_to support_case_path(@current_case, anchor: "case-details")
else
render :edit
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/support/establishments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def index
def list_for_non_participating_establishment
respond_to do |format|
format.json do
render json: EstablishmentSearch.omnisearch(params[:q]).where("establishment_type not in (?)", ["Federation", "Trust", "Single-academy Trust", "Multi-academy Trust", "Umbrella trust"]).as_json(methods: %i[autocomplete_template])
render json: EstablishmentSearch.omnisearch(params[:q]).where("establishment_type not in (?)", ["Federation", "Trust", "Single-academy Trust", "Multi-academy Trust", "Umbrella trust", "Local authority"]).as_json(methods: %i[autocomplete_template])
end
end
end
Expand Down
1 change: 1 addition & 0 deletions app/forms/support/case_contracts_form_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CaseContractsFormSchema < ::Support::Schema

rule :spend do
key.failure(:invalid) if value == ""
key.failure(:too_large) if value.to_i > 99999999.999
end

rule :started_at do
Expand Down
9 changes: 9 additions & 0 deletions app/forms/support/case_savings_form_schema.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Support
class CaseSavingsFormSchema < Dry::Validation::Contract
include Concerns::TranslatableFormSchema
config.messages.top_namespace = :case_savings_form

params do
optional(:savings_status).value(:symbol)
Expand All @@ -9,5 +10,13 @@ class CaseSavingsFormSchema < Dry::Validation::Contract
optional(:savings_estimate).maybe(:decimal)
optional(:savings_actual).maybe(:decimal)
end

rule :savings_estimate do
key.failure(:too_large) if value.to_i > 99999999.999
end

rule :savings_actual do
key.failure(:too_large) if value.to_i > 99999999.999
end
end
end
6 changes: 3 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ en:
supplier:
header: Existing contract supplier
flash:
updated: Successfully changed case contracts
updated: Case contract successfully changed
new:
edit:
duration:
Expand Down Expand Up @@ -1579,7 +1579,7 @@ en:
unrealised: Not realised
submit: Continue
flash:
updated: Successfully changed case savings
updated: Case savings successfully changed
show:
header: Savings details
link: change
Expand Down Expand Up @@ -1928,7 +1928,7 @@ en:
header: Start date of the procurement
submit: Continue
flash:
updated: Successfully changed procurement details
updated: Procurement details successfully changed
reasons_for_route_to_market:
better_than_dfe: Better Spec / Terms than DfE Deal
dfe_deal: DfE Deal / Framework Selected
Expand Down
12 changes: 12 additions & 0 deletions config/locales/validation/support/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ en:
request_text: "" # Omitted
procurement_amount: "" # Omitted


errors:
rules:
request_type:
Expand Down Expand Up @@ -236,7 +237,18 @@ en:
invalid: is invalid
spend:
invalid: is invalid
too_large: cannot be larger than 99,999,999.99

case_savings_form:
rules:
savings_estimate: Saving estimate value
savings_actual: Saving actual value
errors:
rules:
savings_estimate:
too_large: cannot be larger than 99,999,999.99
savings_actual:
too_large: cannot be larger than 99,999,999.99

case_search_form:
rules:
Expand Down
21 changes: 21 additions & 0 deletions db/migrate/20240903101832_update_precision_in_support_cases.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class UpdatePrecisionInSupportCases < ActiveRecord::Migration[7.1]
def up
execute "DROP VIEW IF EXISTS support_tower_cases CASCADE;"
change_column :support_cases, :value, :decimal, precision: 10, scale: 2
change_column :support_contracts, :spend, :decimal, precision: 10, scale: 2
change_column :support_cases, :savings_estimate, :decimal, precision: 10, scale: 2
change_column :support_cases, :savings_actual, :decimal, precision: 10, scale: 2
create_view :support_tower_cases, version: 4
create_view :support_case_data, version: 11
end

def down
execute "DROP VIEW IF EXISTS support_tower_cases CASCADE;"
change_column :support_cases, :savings_actual, :decimal, precision: 9, scale: 2
change_column :support_contracts, :spend, :decimal, precision: 9, scale: 2
change_column :support_cases, :savings_estimate, :decimal, precision: 9, scale: 2
change_column :support_cases, :savings_actual, :decimal, precision: 9, scale: 2
create_view :support_tower_cases, version: 4
create_view :support_case_data, version: 11
end
end
48 changes: 24 additions & 24 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_08_18_210639) do
ActiveRecord::Schema[7.1].define(version: 2024_09_03_101832) do
create_sequence "evaluation_refs"
create_sequence "framework_refs"

Expand Down Expand Up @@ -589,11 +589,11 @@
t.integer "savings_status"
t.integer "savings_estimate_method"
t.integer "savings_actual_method"
t.decimal "savings_estimate", precision: 9, scale: 2
t.decimal "savings_actual", precision: 9, scale: 2
t.decimal "savings_estimate", precision: 10, scale: 2
t.decimal "savings_actual", precision: 10, scale: 2
t.boolean "action_required", default: false
t.string "organisation_type"
t.decimal "value", precision: 9, scale: 2
t.decimal "value", precision: 10, scale: 2
t.integer "closure_reason"
t.string "extension_number"
t.string "other_category"
Expand All @@ -615,8 +615,8 @@
t.integer "discovery_method"
t.string "discovery_method_other_text"
t.string "project"
t.boolean "is_evaluator", default: false
t.string "other_school_urns", default: [], array: true
t.boolean "is_evaluator", default: false
t.index ["category_id"], name: "index_support_cases_on_category_id"
t.index ["existing_contract_id"], name: "index_support_cases_on_existing_contract_id"
t.index ["new_contract_id"], name: "index_support_cases_on_new_contract_id"
Expand Down Expand Up @@ -652,7 +652,7 @@
t.date "started_at"
t.date "ended_at"
t.interval "duration"
t.decimal "spend", precision: 9, scale: 2
t.decimal "spend", precision: 10, scale: 2
end

create_table "support_documents", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
Expand Down Expand Up @@ -1117,24 +1117,6 @@
LEFT JOIN support_establishment_searches ses ON (((sc.organisation_id = ses.id) AND ((sc.organisation_type)::text = ses.source))))
LEFT JOIN support_categories cat ON ((sc.category_id = cat.id)));
SQL
create_view "support_tower_cases", sql_definition: <<-SQL
SELECT sc.id,
sc.state,
sc.value,
sc.procurement_id,
sc.organisation_id,
(sc.procurement_stage_id)::text AS procurement_stage_id,
COALESCE(sc.support_level, 99) AS support_level,
COALESCE(tow.title, 'No Tower'::character varying) AS tower_name,
lower(replace((COALESCE(tow.title, 'No Tower'::character varying))::text, ' '::text, '-'::text)) AS tower_slug,
tow.id AS tower_id,
sc.created_at,
sc.updated_at
FROM ((support_cases sc
LEFT JOIN support_categories cat ON ((sc.category_id = cat.id)))
LEFT JOIN support_towers tow ON ((cat.support_tower_id = tow.id)))
WHERE (sc.state = ANY (ARRAY[0, 1, 3]));
SQL
create_view "support_message_threads", sql_definition: <<-SQL
SELECT DISTINCT ON (se.outlook_conversation_id, se.ticket_id) se.outlook_conversation_id AS conversation_id,
se.case_id,
Expand Down Expand Up @@ -1235,6 +1217,24 @@
FROM frameworks_evaluations ffe
GROUP BY ffe.framework_id) evals ON ((evals.framework_id = ff.id)));
SQL
create_view "support_tower_cases", sql_definition: <<-SQL
SELECT sc.id,
sc.state,
sc.value,
sc.procurement_id,
sc.organisation_id,
(sc.procurement_stage_id)::text AS procurement_stage_id,
COALESCE(sc.support_level, 99) AS support_level,
COALESCE(tow.title, 'No Tower'::character varying) AS tower_name,
lower(replace((COALESCE(tow.title, 'No Tower'::character varying))::text, ' '::text, '-'::text)) AS tower_slug,
tow.id AS tower_id,
sc.created_at,
sc.updated_at
FROM ((support_cases sc
LEFT JOIN support_categories cat ON ((sc.category_id = cat.id)))
LEFT JOIN support_towers tow ON ((cat.support_tower_id = tow.id)))
WHERE (sc.state = ANY (ARRAY[0, 1, 3]));
SQL
create_view "support_case_data", sql_definition: <<-SQL
SELECT sc.id AS case_id,
sc.ref AS case_ref,
Expand Down

0 comments on commit ea3877a

Please sign in to comment.