-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into CRM457-198/fix-routing
- Loading branch information
Showing
25 changed files
with
599 additions
and
15 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 |
---|---|---|
|
@@ -47,4 +47,3 @@ app/assets/builds/* | |
.vscode | ||
.idea | ||
.DS_Store | ||
|
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,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 |
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,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 |
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
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 |
---|---|---|
|
@@ -28,6 +28,8 @@ def data | |
car | ||
motorcycle | ||
bike | ||
|
||
vat | ||
].freeze | ||
|
||
attr_reader(*FIELDS) | ||
|
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
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,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> |
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
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
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 @@ | ||
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 |
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
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
Oops, something went wrong.