Skip to content

Commit

Permalink
Merge branch 'main' into CRM457-198/fix-routing
Browse files Browse the repository at this point in the history
  • Loading branch information
David Henry authored Jun 28, 2023
2 parents 9da3c9f + ce3c862 commit f64afb0
Show file tree
Hide file tree
Showing 25 changed files with 599 additions and 15 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ app/assets/builds/*
.vscode
.idea
.DS_Store

34 changes: 34 additions & 0 deletions app/controllers/steps/disbursement_cost_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Steps
class DisbursementCostController < Steps::BaseStepController
before_action :ensure_disbursement

def edit
@form_object = DisbursementCostForm.build(
disbursement,
application: current_application,
)
end

def update
update_and_advance(DisbursementCostForm, as: :disbursement_type, record: disbursement)
end

private

def decision_tree_class
Decisions::SimpleDecisionTree
end

def disbursement
@disbursement ||= current_application.disbursements.find_by(id: params[:disbursement_id])
end

def ensure_disbursement
disbursement || redirect_to(edit_steps_work_items_path(current_application))
end

def additional_permitted_params
[:apply_vat]
end
end
end
80 changes: 80 additions & 0 deletions app/forms/steps/disbursement_cost_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'steps/base_form_object'

module Steps
class DisbursementCostForm < Steps::BaseFormObject
include ActionView::Helpers::NumberHelper
attr_writer :apply_vat

attribute :miles, :decimal, precision: 10, scale: 3
attribute :total_cost_without_vat, :decimal, precision: 10, scale: 2
attribute :details, :string
attribute :prior_authority, :value_object, source: YesNoAnswer

validates :miles, presence: true, numericality: { greater_than: 1 }, unless: :other_disbursement_type?
validates :total_cost_without_vat, presence: true, numericality: { greater_than: 1 }, if: :other_disbursement_type?
validates :details, presence: true
validates :prior_authority, presence: true, inclusion: { in: YesNoAnswer.values }, if: :auth_required?

def other_disbursement_type?
record.disbursement_type == DisbursementTypes::OTHER.to_s
end

def apply_vat
@apply_vat.nil? ? record.vat_amount.to_f.positive? : @apply_vat == 'true'
end

def calculation_rows
[
[translate(:before_vat), translate(:after_vat)],
[number_to_currency(total_cost || 0, unit: '£'), number_to_currency((total_cost || 0) + vat, unit: '£')],
]
end

def vat_rate
pricing[:vat]
end

# we return 1 here when no pricing data exists to simplify the FE
def multiplier
pricing[record.disbursement_type] || 1.0
end

private

def translate(key)
I18n.t("steps.disbursement_cost.edit.#{key}")
end

def persist!
record.update!(attributes_with_resets)
end

def attributes_with_resets
attributes.merge(
'miles' => other_disbursement_type? ? nil : miles,
'total_cost_without_vat' => total_cost,
'vat_amount' => vat,
)
end

def total_cost
@total_cost ||= if other_disbursement_type?
total_cost_without_vat
elsif miles
miles.to_f * multiplier
end
end

def vat
apply_vat && total_cost ? total_cost * vat_rate : 0.0
end

def auth_required?
total_cost && total_cost >= 100
end

def pricing
@pricing ||= Pricing.for(application)
end
end
end
4 changes: 1 addition & 3 deletions app/forms/steps/disbursement_type_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

module Steps
class DisbursementTypeForm < Steps::BaseFormObject
attr_writer :apply_uplift

attribute :disbursement_date, :multiparam_date
attribute :disbursement_type, :value_object, source: DisbursementTypes
attribute :other_type, :value_object, source: OtherDisbursementTypes
Expand All @@ -21,7 +19,7 @@ def persist!
end

def attributes_with_resets
attributes.merge(other_type: other_disbursement_type? ? other_type : nil)
attributes.merge('other_type' => other_disbursement_type? ? other_type : nil)
end

def other_disbursement_type?
Expand Down
2 changes: 1 addition & 1 deletion app/forms/steps/letters_calls_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def persist!
end

def attributes_with_resets
attributes.merge(letters_calls_uplift: apply_uplift ? letters_calls_uplift : nil)
attributes.merge('letters_calls_uplift' => apply_uplift ? letters_calls_uplift : nil)
end
end
end
2 changes: 1 addition & 1 deletion app/forms/steps/work_item_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def persist!
end

def attributes_with_resets
attributes.merge(uplift: apply_uplift ? uplift : nil)
attributes.merge('uplift' => apply_uplift ? uplift : nil)
end
end
end
2 changes: 2 additions & 0 deletions app/lib/pricing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def data
car
motorcycle
bike

vat
].freeze

attr_reader(*FIELDS)
Expand Down
8 changes: 6 additions & 2 deletions app/presenters/tasks/disbursements.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module Tasks
class Disbursements < Generic
PREVIOUS_TASK = LettersCalls
FORMS = [Steps::DisbursementTypeForm].freeze
FORMS = [
Steps::DisbursementTypeForm,
Steps::DisbursementCostForm,
].freeze

def path
if application.disbursements.count.positive?
Expand All @@ -16,7 +19,8 @@ def path
# TODO: is this inefficient? do we care?
def in_progress?
[
edit_steps_disbursement_type_path(id: application.id, disbursement_id: '')
edit_steps_disbursement_type_path(id: application.id, disbursement_id: ''),
edit_steps_disbursement_cost_path(id: application.id, disbursement_id: ''),
].any? do |path|
application.navigation_stack.any? { |stack| stack.start_with?(path) }
end
Expand Down
4 changes: 4 additions & 0 deletions app/services/decisions/simple_decision_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,9 @@ def direct(page:, summary_page:, nested_id:, scope:, options: { edit_when_one: f
edit(summary_page)
end
end

def after_disbursement_type
edit(:disbursement_cost, disbursement_id: form_object.record.id)
end
end
end
28 changes: 28 additions & 0 deletions app/views/steps/disbursement_cost/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<% title t('.page_title') %>
<% step_header %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l"><%= t('.heading') %></h1>
<%= govuk_error_summary(@form_object) %>
<%= step_form @form_object do |f| %>
<% if @form_object.other_disbursement_type? %>
<%= f.govuk_number_field :total_cost_without_vat, min: 1, step: 0.01, width: 5 %>
<% else %>
<%= f.govuk_number_field :miles, min: 1, step: 1, width: 3, suffix_text: 'Miles' %>
<% end %>
<%= f.govuk_text_area :details %>
<%= f.govuk_radio_buttons_fieldset :prior_authority, legend: { size: 's' } do %>
<%= f.govuk_radio_button :prior_authority, YesNoAnswer::YES.to_s %>
<%= f.govuk_radio_button :prior_authority, YesNoAnswer::NO.to_s %>
<% end%>
<%= f.govuk_check_box :apply_vat, 'true', 'false', multiple: false %>
<%= f.refresh_button %>
<%= govuk_table(rows: @form_object.calculation_rows, caption: t('.calculation')) %>
<%= f.continue_button %>
<% end %>
</div>
</div>
19 changes: 19 additions & 0 deletions config/locales/en/helpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ en:
steps_disbursement_type_form:
disbursement_date: Date
disbursement_type: Which disbursement type is this is for?
steps_disbursement_cost_form:
prior_authority: Have you been granted prior authority for this disbursement?
hint:
steps_claim_type_form:
rep_order_date: For example, 27 3 2007
Expand Down Expand Up @@ -109,6 +111,12 @@ en:
motorcycle: '%{rate} per mile'
bike: '%{rate} per mile'
other_type: Enter the name of disbursement type, or select one from the suggestions that appear when you start to enter the name.
steps_disbursement_cost_form:
miles: For example, 2.5 miles
total_cost_without_vat: Enter the cost, not including VAT, for example £301.55
details: For example, why this disbursement was needed
prior_authority_options:
'yes': We’ll ask you to upload evidence of this before you submit this claim

label:
steps_claim_type_form:
Expand Down Expand Up @@ -224,13 +232,24 @@ en:
motorcycle: Motorcycle
bike: bike
other: Other disbursement type
steps_disbursement_cost_form:
miles: Number of miles
total_cost_without_vat: Disbursement cost
details: Enter details of this disbursement
prior_authority_options:
'yes': 'Yes'
'no': 'No'
apply_vat_options:
'true': Apply 20% VAT to this work


steps_other_info_form:
other_info: For example, justification for the time spent on the case, or for any uplift claimed
concluded_options:
'yes': 'Yes'
'no': 'No'
conclusion: Tell us why you did not make this claim within 3 months of the conclusion of the proceedings

other_disbursement_type:
accident_reconstruction_report: Accident Reconstruction Report
accident_emergency_report: Accident & Emergency Report
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en/steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ en:
disbursement_type:
edit:
heading: Disbursement type
disbursement_cost:
edit:
heading: Disbursement cost
calculation: Calculation
before_vat: Before VAT
after_vat: After VAT

cost_summary:
show:
heading: Check your payment claim
Expand Down
8 changes: 6 additions & 2 deletions config/pricing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ from_start:
# letters and calls
letters: 3.56
calls: 3.56
# disbursements
# disbursement type
car: 0.45
motorcycle: 0.45
bike: 0.25
# disbursement cost
vat: 0.2
from_20220930:
# working types
preparation: 52.15
Expand All @@ -24,7 +26,9 @@ from_20220930:
# letters and calls
letters: 4.09
calls: 4.09
# disbursements
# disbursement type
car: 0.45
motorcycle: 0.45
bike: 0.25
# disbursement cost
vat: 0.2
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def show_step(name)
edit_step :work_items
crud_step :work_item_delete, param: :work_item_id, except: [:destroy]
crud_step :disbursement_type, param: :disbursement_id, except: [:destroy]
crud_step :disbursement_cost, param: :disbursement_id, except: [:destroy]
show_step :cost_summary
edit_step :other_info

Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20230623103721_add_vat_amount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class AddVatAmount < ActiveRecord::Migration[7.0]
def change
add_column :disbursements, :vat_amount, :decimal, precision: 10, scale: 2
rename_column :disbursements, :total_cost, :total_cost_without_vat
reversible do |direction|
change_table :disbursements do |t|
direction.up do
t.change :total_cost_without_vat, :decimal, precision: 10, scale: 2
t.change :miles, 'decimal(10,3) USING CAST(miles AS decimal)'
end
direction.down do
t.change :total_cost_without_vat, :float
t.change :miles, :string
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def update_and_advance(form_class, opts = {})
# Validations will not be run when saving a draft
@form_object.save!
redirect_to after_commit_path(current_application)
elsif params.key?(:save_and_refresh)
@form_object.save!
render opts.fetch(:render, :edit)
elsif @form_object.save
redirect_to decision_tree_class.new(@form_object, as: opts.fetch(:as)).destination, flash: opts[:flash]
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def govuk_period_field(attribute_name, hint: {}, legend: {}, caption: {}, widths
end
# rubocop:enable Metrics/ParameterLists

def refresh_button(button: :update_calculation, opts: {})
submit_button(button, opts.merge(secondary: true, name: 'save_and_refresh'))
end

def continue_button(primary: :save_and_continue, secondary: :save_and_come_back_later,
primary_opts: {}, secondary_opts: {})
submit_button(primary, primary_opts) do
Expand Down
1 change: 1 addition & 0 deletions gems/laa_multi_step_forms/config/locales/en/helpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ en:
find_address: Find address
try_again: Try again
apply_in_eforms: Apply in eForms
update_calculation: Update the calculation
time_period: &period
missing: 'Not set'
hours:
Expand Down
Loading

0 comments on commit f64afb0

Please sign in to comment.