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>
This commit is contained in:
2026-06-02 17:31:49 +02:00
parent b073ded6c1
commit 964e3f472c
13 changed files with 341 additions and 54 deletions

View File

@@ -14,6 +14,41 @@ module Billing
scope :recent, -> { order(paid_at: :desc, created_at: :desc) }
# Pagamenti pagati senza PDF fattura caricato (da gestire in admin).
scope :awaiting_invoice_pdf, lambda {
where(status: "paid").where(
<<~SQL.squish,
NOT EXISTS (
SELECT 1 FROM billing_invoices bi
INNER JOIN active_storage_attachments asa
ON asa.record_type = 'Billing::Invoice'
AND asa.record_id = bi.id
AND asa.name = 'pdf'
WHERE bi.billing_payment_id = billing_payments.id
)
SQL
)
}
scope :with_invoice_pdf, lambda {
where(status: "paid").where(
<<~SQL.squish,
EXISTS (
SELECT 1 FROM billing_invoices bi
INNER JOIN active_storage_attachments asa
ON asa.record_type = 'Billing::Invoice'
AND asa.record_id = bi.id
AND asa.name = 'pdf'
WHERE bi.billing_payment_id = billing_payments.id
)
SQL
)
}
def awaiting_invoice_pdf?
status == "paid" && !invoice&.pdf&.attached?
end
def amount_euros
amount_cents / 100.0
end