Module: CompaniesHouseInputGateway::Validations

Defined in:
lib/companies_house_input_gateway/validations/form_submission.rb,
lib/companies_house_input_gateway/validations/company_data_request.rb,
lib/companies_house_input_gateway/validations/get_submission_status.rb,
lib/companies_house_input_gateway/validations/confirmation_statement.rb,
lib/companies_house_input_gateway/validations/returnof_allotment_shares.rb

Constant Summary collapse

FormSubmission =
Dry::Validation.Schema do
  configure do
    config.messages_file = File.join(Base.root, './errors.yml')

    def company_number_format?(value)
      value ? value.match(/^([\d]*\d){8}$/) : true
    end
  end

  required(:date_signed).filled(:date?)
  required(:company_number).filled(:str?)
  required(:company_name).filled(:str?)
  required(:company_authentication_code).filled(:str?)
  required(:package_reference).filled(:str?)
  required(:submission_number).filled(:str?, size?: 6)
  required(:company_number).filled(:company_number_format?)
end
CompanyDataRequest =
Dry::Validation.Schema do
  configure do
    config.messages_file = File.join(Base.root, './errors.yml')

    def company_number_format?(value)
      value ? value.match(/^([\d]*\d){8}$/) : true
    end
  end

  required(:company_number).filled(:str?)
  required(:company_authentication_code).filled(:str?, size?: 6)
  required(:made_up_date).filled(:date?)
  required(:company_number).filled(:company_number_format?)
end
GetSubmissionStatus =
Dry::Validation.Schema do
  configure do
    config.messages_file = File.join(Base.root, './errors.yml')

    def company_number_format?(value)
      value ? value.match(/^([\d]*\d){8}$/) : true
    end
  end

  optional(:company_number).maybe(:str?)
  optional(:submission_number).filled(:str?)
  required(:presenter_id).filled(:str?)
  optional(:company_number).filled(:company_number_format?)

  rule(company_number_or_submission_number_presence: %i[company_number submission_number]) do |company_number, submission_number|
    company_number.filled?.then(submission_number.none?) & submission_number.filled?.then(company_number.none?)
  end
end
ConfirmationStatement =
Dry::Validation.Schema do
  configure do
    config.messages_file = File.join(Base.root, './errors.yml')

    def shareholders_names_presence?(shareholdings)
      check = shareholdings.map do |holdings|
        holdings[:shareholders].any? do |i|
          ((i[:name][:surname] && i[:name][:forename]) && !i[:name][:amalgamated_name]) ||
            (!(i[:name][:surname] || i[:name][:forename]) && i[:name][:amalgamated_name])
        end
      end
      check.all?
    end

    def other_foreign_country?(shareholdings)
      check = shareholdings.map do |holdings|
        check = holdings[:shareholders].any? do |i|
          next true unless i[:address]

          !(i[:address][:country] && i[:address][:other_foreign_country])
        end
      end
      check.all?
    end
  end

  optional(:trading_on_market).filled(:bool?)
  optional(:dtr_5_applies).filled(:bool?)
  optional(:psc_exempt_as_trading_on_regulated_market).filled(:bool?)
  optional(:psc_exempt_as_shares_admitted_on_market).filled(:bool?)
  optional(:psc_exempt_as_trading_on_uk_regulated_market).filled(:bool?)
  required(:review_date).filled(:date?)

  optional(:sic_codes).schema do
    required(:sic_code).each(:str?)
  end
  # optional(:statement_of_capital).schema do
  #   required(:capital).each do
  #     schema do
  #       required(:total_amount_unpaid).filled(:decimal?)
  #       required(:total_number_of_issued_shares).filled(:decimal?)
  #       required(:share_currency).filled(:str?)
  #       required(:total_aggregate_nominal_value).filled(:decimal?)
  #       required(:shares).each do
  #         schema do
  #           required(:share_class).filled(:str?)
  #           required(:prescribed_particulars).filled(:str?)
  #           required(:num_shares).filled(:decimal?)
  #           required(:aggregate_nominal_value).filled(:decimal?)
  #         end
  #       end
  #     end
  #   end
  # end

  # required(:shareholdings).each do
  #   schema do
  #     required(:share_class).filled(:str?)
  #     required(:number_held).filled(:decimal?)
  #     required(:transfers).each do
  #       schema do
  #         required(:date_of_transfer).filled(:date?)
  #         required(:number_shares_transferred).filled(:decimal?)
  #       end
  #     end
  #
  #     optional(:shareholders).each do
  #       schema do
  #         required(:name).schema do
  #           optional(:surname).filled(:str?)
  #           optional(:forename).filled(:str?)
  #           optional(:amalgamated_name).filled(:str?)
  #         end
  #         optional(:address).schema do
  #           required(:premise).filled(:str?)
  #           required(:street).filled(:str?)
  #           required(:thoroughfare).filled(:str?)
  #           required(:post_town).filled(:str?)
  #           required(:county).filled(:str?)
  #           optional(:country).filled(included_in?: CompaniesHouseInputGateway::Constants::COUNTRIES)
  #           optional(:other_foreign_country).filled(:str?)
  #         end
  #       end
  #     end
  #   end
  # end
  required(:state_confirmation).filled(:bool?)
  # required(:shareholdings).filled(:shareholders_names_presence?)
  # required(:shareholdings).filled(:other_foreign_country?)
end
ReturnofAllotmentShares =
Dry::Validation.Schema do
  required(:start_period_shares_allotted).filled(:date?)
  optional(:end_period_shares_allotted).filled(:date?)

  required(:statement_of_capital).schema do
    required(:capital).each do
      schema do
        required(:total_amount_unpaid).filled(:str?)
        required(:total_number_of_issued_shares).filled(:str?)
        required(:share_currency).filled(:str?)
        required(:total_aggregate_nominal_value).filled(:str?)
        required(:shares).each do
          schema do
            required(:share_class).filled(:str?)
            required(:prescribed_particulars).filled(:str?)
            required(:num_shares).filled(:str?)
            required(:aggregate_nominal_value).filled(:str?)
          end
        end
      end
    end
  end

  required(:allotment).each do
    schema do
      required(:share_class).filled(:str?)
      required(:num_shares).filled(:str?)
      required(:amount_paid_due_per_share).filled(:str?)
      required(:amount_unpaid_per_share).filled(:str?)
      required(:share_currency).filled(:str?)
      required(:share_value).filled(:str?)
      optional(:consideration).filled(:str?)
    end
  end
end