Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop into main #1125

Merged
merged 8 commits into from
Mar 14, 2022
2 changes: 1 addition & 1 deletion app/forms/waste_carriers_engine/check_your_answers_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CheckYourAnswersForm < ::WasteCarriersEngine::BaseForm

delegate :business_type, :company_name, :company_no, :contact_address, :contact_email, to: :transient_registration
delegate :first_name, :last_name, :location, :main_people, :phone_number, to: :transient_registration
delegate :registration_type, :relevant_people, :tier, to: :transient_registration
delegate :registered_company_name, :registration_type, :relevant_people, :tier, to: :transient_registration
delegate :registered_address, :declared_convictions, to: :transient_registration
delegate :lower_tier?, :upper_tier?, :company_no_required?, to: :transient_registration

Expand Down
2 changes: 1 addition & 1 deletion app/forms/waste_carriers_engine/company_name_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module WasteCarriersEngine
class CompanyNameForm < ::WasteCarriersEngine::BaseForm
delegate :business_type, :company_name, to: :transient_registration
delegate :business_type, :company_name, :registered_company_name, :tier, to: :transient_registration

validates :company_name, "waste_carriers_engine/company_name": true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ module CanHaveRegistrationAttributes
field :phoneNumber, as: :phone_number, type: String
field :receipt_email, type: String
field :regIdentifier, as: :reg_identifier, type: String
field :registeredCompanyName, as: :registered_company_name, type: String
field :companiesHouseUpdatedAt, as: :companies_house_updated_at, type: DateTime
field :registrationType, as: :registration_type, type: String
field :reg_uuid, type: String # Used by waste-carriers-frontend
field :uuid, type: String
Expand Down
21 changes: 18 additions & 3 deletions app/models/waste_carriers_engine/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,33 @@ def self.create_from_os_places_data(data)
end

def assign_house_number_and_address_lines(data)
lines = data["lines"]
lines = data["lines"].clone

# buildingNumber and dependentThoroughfare are part of the "lines" logic
# but OS places does not include them in the "lines" array.
# If either or both are present, insert them before the thoroughFareName value.
if data["thoroughfareName"].present? && (insert_position = lines.index(data["thoroughfareName"]))
add_line_at?(lines, insert_position, data["dependentThoroughfare"])
add_line_at?(lines, insert_position, data["buildingName"])
end

lines.reject!(&:blank?)

address_attributes = %i[house_number
address_line_1
address_line_2
address_line_3
address_line_4]
lines.reject!(&:blank?)
address_line_4
address_line_5]

# Assign lines one at a time until we run out of lines to assign
write_attribute(address_attributes.shift, lines.shift) until lines.empty?
end

def add_line_at?(lines, insert_position, insert_value)
lines.insert(insert_position, insert_value) if insert_value.present?
end

def manually_entered?
address_mode == "manual-foreign" || address_mode == "manual-uk"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

module WasteCarriersEngine

# This module contains shared presentation logic for carrier names.
# This is similar to a model concern, but for presenters.
module CanPresentEntityDisplayName

# For sole traders, we want to display the name of the trader. There
# will only be one person, but the list_main_people method still works for
# finding and formatting that single person.
def entity_display_name
if upper_tier_sole_trader?
list_main_people
else
company_registered_and_or_trading_name
end
end

def list_main_people
list = main_people.map do |person|
format("%<first>s %<last>s", first: person.first_name, last: person.last_name)
end
list.join("<br>").html_safe
end

private

def upper_tier_sole_trader?
upper_tier? && business_type == "soleTrader"
end

def company_registered_and_or_trading_name
if company_name.present?
if registered_company_name.present?
"#{registered_company_name} trading as #{company_name}"
else
company_name
end
else
registered_company_name
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

module WasteCarriersEngine
# This is a minimal presenter using shared logic to return the presentation name for the carrier.
class CarrierNamePresenter < BasePresenter
include WasteCarriersEngine::CanPresentEntityDisplayName
end
end
23 changes: 1 addition & 22 deletions app/presenters/waste_carriers_engine/certificate_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@
module WasteCarriersEngine
class CertificatePresenter < BasePresenter
include WasteCarriersEngine::ApplicationHelper
include WasteCarriersEngine::CanPresentEntityDisplayName

LOCALES_KEY = ".waste_carriers_engine.pdfs.certificate"

# For sole traders, we want to display the name of the trader. There
# will only be one person, but the list_main_people method still works for
# finding and formatting that single person.
def carrier_name
if upper_tier_sole_trader?
list_main_people
else
company_name
end
end

# If it's an upper tier sole trader or partnership, we need to display an
# extra section. For partners, it's a list of their names, and for sole
# traders, it's their business name.
Expand Down Expand Up @@ -52,13 +42,6 @@ def tier_and_registration_type
end
end

def list_main_people
list = main_people.map do |person|
format("%<first>s %<last>s", first: person.first_name, last: person.last_name)
end
list.join("<br>").html_safe
end

def renewal_message
if lower_tier?
I18n.t("#{LOCALES_KEY}.lower_renewal")
Expand All @@ -84,10 +67,6 @@ def expires_after_pluralized
)
end

def upper_tier_sole_trader?
upper_tier? && business_type == "soleTrader"
end

def upper_tier_partnership?
upper_tier? && business_type == "partnership"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module WasteCarriersEngine
class CheckYourAnswersFormPresenter < ResourceTypeFormPresenter
include WasteCarriersEngine::CanPresentEntityDisplayName
def show_smart_answers_results?
return false if charity?
return false if new_registration? && tier_known?
Expand Down
8 changes: 8 additions & 0 deletions app/presenters/waste_carriers_engine/edit_form_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def company_name
transient_registration.company_name
end

def registered_company_name
transient_registration.registered_company_name
end

def companies_house_updated_at
transient_registration.companies_house_updated_at.try(:to_formatted_s, :day_month_year)
end

def company_no
transient_registration.company_no
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def base_personalisation
{
contact_name: contact_name,
reg_identifier: @registration.reg_identifier,
company_name: @registration.company_name,
company_name: company_name,
registered_address: registered_address,
phone_number: @registration.phone_number,
date_registered: date_registered
Expand All @@ -50,6 +50,10 @@ def contact_name
"#{@registration.first_name} #{@registration.last_name}"
end

def company_name
CarrierNamePresenter.new(@registration).entity_display_name
end

def address_lines
address_values = [
contact_name,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require "defra_ruby_companies_house"

module WasteCarriersEngine
class RefreshCompaniesHouseNameService < WasteCarriersEngine::BaseService
def run(reg_identifier:)
registration = Registration.find_by(reg_identifier: reg_identifier)

company_name = DefraRubyCompaniesHouse.new(registration.company_no).company_name
registration.registered_company_name = company_name
registration.companies_house_updated_at = Time.current
registration.save!

true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ def validate_each(record, attribute, value)
def value_is_present?(record, attribute, value)
return true if value.present?

return true if attribute == :company_name && record.registered_company_name.present?

add_validation_error(record, attribute, :blank)
false
end

def value_is_not_too_long?(record, attribute, value)
return true if value.length < 256
return true if value.nil? || value.length < 256

add_validation_error(record, attribute, :too_long)
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@

<hr>

<h2 class="govuk-heading-m"><%= t(".subheadings.public_register") %></h2>
<p class="govuk-body"><%= @presenter.entity_display_name %></p>

<hr>

<h2 class="govuk-heading-m"><%= t(".subheadings.contact_details") %></h2>

<ul class="govuk-list">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% content_for :title, t(".heading.#{@company_name_form.business_type}").html_safe %>
<% content_for :title, t(".heading.#{@company_name_form.business_type}.#{@company_name_form.tier}").html_safe %>
<%= render("waste_carriers_engine/shared/back", back_path: back_company_name_forms_path(@company_name_form.token)) %>

<div class="govuk-grid-row">
Expand All @@ -8,7 +8,7 @@
<%= f.govuk_text_field :company_name,
width: "one-half",
label: {
text: t(".heading.#{@company_name_form.business_type}"),
text: t(".heading.#{@company_name_form.business_type}.#{@company_name_form.tier}"),
tag: "h1", size: "l"
},
hint: {
Expand Down
19 changes: 19 additions & 0 deletions app/views/waste_carriers_engine/edit_forms/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,26 @@
<%= t(".edit_links.no_edit") %>
</td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">
<%= t(".sections.business.labels.registered_company_name") %>
</th>
<td class="govuk-table__cell">
<%= @presenter.registered_company_name %>
<% if @presenter.companies_house_updated_at %>
<br>
<span class="govuk-body-s">
<%= t(".sections.business.labels.registered_company_name_last_updated",
last_updated: @presenter.companies_house_updated_at) %>
</span>
<% end %>
</td>
<td class="govuk-table__cell govuk-table__cell--numeric">
<%= t(".edit_links.no_edit") %>
</td>
</tr>
<% end %>

<% if @presenter.main_people_with_roles.any? %>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">
Expand Down
4 changes: 2 additions & 2 deletions app/views/waste_carriers_engine/pdfs/certificate.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
</thead>
<tbody>
<tr>
<td class="table-column-text"><%=t ".carrier_name" %></td>
<td><%= @presenter.carrier_name %></td>
<td class="table-column-text"><%=t ".entity_display_name" %></td>
<td><%= @presenter.entity_display_name %></td>
</tr>
<% if @presenter.complex_organisation_details? %>
<tr>
Expand Down
3 changes: 2 additions & 1 deletion config/locales/forms/check_your_answers_forms/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ en:
subheadings:
you_told_us: "You told us:"
registration: "Registration"
business: "Business"
business: "Business details"
public_register: "Name displayed on public register"
contact_details: "Contact details"
contact_address: "Contact address"
business_owners:
Expand Down
42 changes: 30 additions & 12 deletions config/locales/forms/company_name_forms/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,37 @@ en:
new:
title: Business or organisation name
heading:
localAuthority: What's the name of the local authority or public body?
limitedCompany: What's the name of the company?
limitedLiabilityPartnership: What's the name of the limited liability partnership?
overseas: What's the name of the business or organisation?
partnership: What's the name of the partnership?
soleTrader: What's the name of the business?
charity: What's the name of the charity or trust?
authority: What's the name of the local authority?
publicBody: What's the name of the public body?
localAuthority:
UPPER: &value "What's the name of the local authority or public body?"
LOWER: *value
limitedCompany:
UPPER: Do you trade under a different name? (optional)
LOWER: What's the name of the company?
limitedLiabilityPartnership:
UPPER: Do you trade under a different name? (optional)
LOWER: What's the name of the limited liability partnership?
overseas:
UPPER: &value What's the name of the business or organisation?
LOWER: *value
partnership:
UPPER: &value What's the name of the partnership?
LOWER: *value
soleTrader:
UPPER: &value What's the name of the business?
LOWER: *value
charity:
UPPER: &value What's the name of the charity or trust?
LOWER: *value
authority:
UPPER: &value What's the name of the local authority?
LOWER: *value
publicBody:
UPPER: &value What's the name of the public body?
LOWER: *value
company_name_label:
localAuthority: Enter your local authority or public body name
limitedCompany: Enter your company trading name
limitedLiabilityPartnership: Enter your partnership trading name
limitedCompany: Enter a business or trading name. This will be displayed on the public register.
limitedLiabilityPartnership: Enter a business or trading name. This will be displayed on the public register.
overseas: Enter your trading name
partnership: Enter your partnership trading name
soleTrader: Enter your business trading name
Expand All @@ -31,7 +49,7 @@ en:
waste_carriers_engine/company_name_form:
attributes:
company_name:
blank: "Enter a trading name"
blank: "Enter a business or trading name. This will be displayed on the public register."
too_long: "Enter a shorter trading name with no more than 255 characters"
reg_identifier:
invalid_format: "The registration ID is not in a valid format"
Expand Down
5 changes: 4 additions & 1 deletion config/locales/forms/edit_forms/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ en:
heading: Waste carrier business details
labels:
business_type: Type
company_name: Name
company_name: Business name
company_no: Company number
registered_company_name: Registered company name
registered_company_name_last_updated: (refreshed on %{last_updated})
refresh_registered_company_name_html: Update&nbsp;from<br>com. house
main_people: Main people
registered_address: Address
contact:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/pdfs/certificate.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ en:
nccc_number: "03708 506506"
certify_message: "The Environment Agency certify that the following information is entered in the register which they maintain under regulation 28 of the Waste (England and Wales) Regulations 2011."
carrier_table_heading: "Carriers details"
carrier_name: "Name of registered carrier"
entity_display_name: "Name of registered carrier"
business_name_if_applicable: "Business name (if applicable)"
partners: "Partners"
registered: "Registered as"
Expand Down