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
|
||||
|
||||
@@ -53,6 +53,22 @@ module ClubBillingProfile
|
||||
parts.compact.join(" · ")
|
||||
end
|
||||
|
||||
# Righe per intestazione fattura in admin (etichetta, valore).
|
||||
def billing_profile_invoice_lines
|
||||
lines = []
|
||||
lines << ["Tipo", BILLING_ENTITY_TYPES[billing_entity_type]] if billing_entity_type.present?
|
||||
lines << ["Intestatario", billing_legal_name]
|
||||
lines << ["P.IVA", billing_vat_number] if billing_vat_number.present?
|
||||
lines << ["Codice fiscale", billing_fiscal_code] if billing_fiscal_code.present?
|
||||
lines << ["Email fatturazione", billing_email]
|
||||
lines << ["Telefono", billing_phone] if billing_phone.present?
|
||||
addr = [billing_address_line, billing_postal_code, billing_city, billing_province, billing_country].compact.join(", ")
|
||||
lines << ["Indirizzo", addr] if addr.present?
|
||||
lines << ["SDI", billing_recipient_code] if billing_recipient_code.present?
|
||||
lines << ["PEC", billing_pec] if billing_pec.present?
|
||||
lines
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def billing_profile_for_invoicing
|
||||
|
||||
Reference in New Issue
Block a user