Billing Stripe, link regia mobile e staff solo trasmissione.
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>
This commit is contained in:
43
backend/app/models/billing/invoice.rb
Normal file
43
backend/app/models/billing/invoice.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
module Billing
|
||||
class Invoice < ApplicationRecord
|
||||
self.table_name = "billing_invoices"
|
||||
|
||||
STATUSES = %w[draft issued sent cancelled].freeze
|
||||
SOURCES = %w[aruba manual].freeze
|
||||
|
||||
belongs_to :club
|
||||
belongs_to :billing_payment, class_name: "Billing::Payment", optional: true
|
||||
has_one_attached :pdf
|
||||
|
||||
validates :number, presence: true, uniqueness: { scope: :club_id }
|
||||
validates :issued_on, presence: true
|
||||
validates :amount_cents, numericality: { greater_than: 0 }
|
||||
validates :currency, presence: true
|
||||
validates :status, inclusion: { in: STATUSES }
|
||||
validates :source, inclusion: { in: SOURCES }
|
||||
validate :pdf_present_when_issued
|
||||
|
||||
scope :recent, -> { order(issued_on: :desc, created_at: :desc) }
|
||||
|
||||
def amount_euros
|
||||
amount_cents / 100.0
|
||||
end
|
||||
|
||||
def formatted_amount
|
||||
format("%.2f €", amount_euros)
|
||||
end
|
||||
|
||||
def downloadable?
|
||||
pdf.attached?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def pdf_present_when_issued
|
||||
return unless status.in?(%w[issued sent])
|
||||
return if pdf.attached?
|
||||
|
||||
errors.add(:pdf, "è obbligatorio per le fatture emesse")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user