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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user