Files
MatchLiveTv/backend/app/services/billing/attach_payment_invoice.rb
Emiliano Frascaro 964e3f472c Admin fatturazione: coda pagamenti senza PDF e upload diretto.
Lista globale dei pagamenti da fatturare con dati intestazione, caricamento
PDF per riga che crea la fattura e invia email; rimuove il flusso bozza manuale.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 17:31:49 +02:00

38 lines
945 B
Ruby

module Billing
class AttachPaymentInvoice
class Error < StandardError; end
def self.call(payment:, pdf:)
new(payment: payment, pdf: pdf).call
end
def initialize(payment:, pdf:)
@payment = payment
@pdf = pdf
end
def call
raise Error, "Seleziona un file PDF" if @pdf.blank?
raise Error, "Pagamento non valido" unless @payment.status == "paid"
club = @payment.club
invoice = @payment.invoice || build_invoice!(club)
IssueInvoice.call(invoice: invoice, pdf: @pdf)
end
private
def build_invoice!(club)
club.billing_invoices.create!(
number: InvoiceNumber.next_for(club),
issued_on: @payment.paid_at&.to_date || Date.current,
amount_cents: @payment.amount_cents,
currency: @payment.currency.presence || "eur",
status: "draft",
source: "manual",
billing_payment: @payment
)
end
end
end