Aggiunge fatturazione club, pagina regia condivisibile senza account, roster squadre e rimuove la modalità controller dall'app (v1.1.0). Co-authored-by: Cursor <cursoragent@cursor.com>
48 lines
1.6 KiB
Ruby
48 lines
1.6 KiB
Ruby
module ClubBillingProfile
|
|
extend ActiveSupport::Concern
|
|
|
|
BILLING_ENTITY_TYPES = {
|
|
"company" => "Società / ASD con P.IVA",
|
|
"individual" => "Persona fisica",
|
|
"nonprofit" => "Associazione senza scopo di lucro"
|
|
}.freeze
|
|
|
|
included do
|
|
validates :billing_entity_type, inclusion: { in: BILLING_ENTITY_TYPES.keys }, allow_nil: true
|
|
validates :billing_email, format: { with: URI::MailTo::EMAIL_REGEXP }, allow_blank: true
|
|
validates :billing_recipient_code, length: { is: 7 }, allow_blank: true
|
|
validates :billing_province, length: { is: 2 }, allow_blank: true
|
|
validates :billing_country, length: { is: 2 }, allow_blank: true
|
|
validate :billing_profile_for_invoicing, on: :billing_profile
|
|
end
|
|
|
|
def billing_profile_complete?
|
|
billing_profile_errors.empty?
|
|
end
|
|
|
|
def billing_profile_errors
|
|
errors = []
|
|
errors << "Ragione sociale o nome intestatario" if billing_legal_name.blank?
|
|
errors << "Email di fatturazione" if billing_email.blank?
|
|
errors << "Indirizzo" if billing_address_line.blank?
|
|
errors << "Città" if billing_city.blank?
|
|
errors << "CAP" if billing_postal_code.blank?
|
|
errors << "P.IVA o Codice Fiscale" if billing_vat_number.blank? && billing_fiscal_code.blank?
|
|
errors << "Codice destinatario SDI o PEC" if billing_recipient_code.blank? && billing_pec.blank?
|
|
errors
|
|
end
|
|
|
|
def billing_profile_summary
|
|
parts = [billing_legal_name.presence, billing_vat_number.presence && "P.IVA #{billing_vat_number}"]
|
|
parts.compact.join(" · ")
|
|
end
|
|
|
|
private
|
|
|
|
def billing_profile_for_invoicing
|
|
billing_profile_errors.each do |message|
|
|
errors.add(:base, message)
|
|
end
|
|
end
|
|
end
|