2023-11-03 16:37:43 +01:00
|
|
|
class SepaAccountHolder < ApplicationRecord
|
|
|
|
belongs_to :group
|
|
|
|
belongs_to :user
|
|
|
|
|
2023-11-28 16:39:24 +01:00
|
|
|
validates_with SEPA::IBANValidator, field_name: :iban, if: -> { iban.present? }
|
|
|
|
validates_with SEPA::BICValidator, field_name: :bic, if: -> { bic.present? }
|
|
|
|
|
|
|
|
before_validation :strip_whitespace_from_bic_and_iban
|
|
|
|
|
2023-11-03 16:37:43 +01:00
|
|
|
def all_fields_present?
|
|
|
|
iban.present? && bic.present? && mandate_id.present? && user_id.present? && mandate_date_of_signature.present? && group_id.present?
|
|
|
|
end
|
2023-11-28 16:39:24 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def strip_whitespace_from_bic_and_iban
|
|
|
|
self.iban = iban&.gsub(/\s+/, "")
|
|
|
|
self.bic = bic&.gsub(/\s+/, "")
|
|
|
|
end
|
2023-11-03 16:37:43 +01:00
|
|
|
end
|