Billing: fatture manuali, profilo obbligatorio e piani Stripe mensile/annuale.
Rimuove link al portale Stripe in area cliente, aggiunge flusso admin per PDF fattura e email, blocca checkout senza dati di fatturazione, allinea prezzi a €4,90/€39,90 e €9,90/€69,90, locale italiano e documentazione deploy. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,7 +3,7 @@ module Billing
|
||||
self.table_name = "billing_invoices"
|
||||
|
||||
STATUSES = %w[draft issued sent cancelled].freeze
|
||||
SOURCES = %w[aruba manual].freeze
|
||||
SOURCES = %w[manual aruba].freeze
|
||||
|
||||
belongs_to :club
|
||||
belongs_to :billing_payment, class_name: "Billing::Payment", optional: true
|
||||
@@ -15,7 +15,8 @@ module Billing
|
||||
validates :currency, presence: true
|
||||
validates :status, inclusion: { in: STATUSES }
|
||||
validates :source, inclusion: { in: SOURCES }
|
||||
validate :pdf_present_when_issued
|
||||
validates :billing_payment_id, uniqueness: true, allow_nil: true
|
||||
validate :pdf_present_when_issued, on: :issue
|
||||
|
||||
scope :recent, -> { order(issued_on: :desc, created_at: :desc) }
|
||||
|
||||
@@ -28,16 +29,35 @@ module Billing
|
||||
end
|
||||
|
||||
def downloadable?
|
||||
pdf.attached?
|
||||
pdf.attached? && status.in?(%w[issued sent])
|
||||
end
|
||||
|
||||
def draft?
|
||||
status == "draft"
|
||||
end
|
||||
|
||||
def display_number
|
||||
n = number.to_s.strip
|
||||
cleaned = n.gsub(/\baruba[-_\s]*/i, "").strip
|
||||
cleaned.presence || n
|
||||
end
|
||||
|
||||
def display_status
|
||||
{
|
||||
"draft" => "In preparazione",
|
||||
"issued" => "Emessa",
|
||||
"sent" => "Inviata",
|
||||
"cancelled" => "Annullata"
|
||||
}[status] || status
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def pdf_present_when_issued
|
||||
return unless status.in?(%w[issued sent])
|
||||
return unless validation_context == :issue
|
||||
return if pdf.attached?
|
||||
|
||||
errors.add(:pdf, "è obbligatorio per le fatture emesse")
|
||||
errors.add(:pdf, "è obbligatorio per emettere la fattura")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user