diff --git a/backend/app.py b/backend/app.py index 6f22104..aefd467 100644 --- a/backend/app.py +++ b/backend/app.py @@ -3076,6 +3076,32 @@ def invoices(): "client_id": client_id, "limit": limit_count, } + for inv in invoices: + inv["paid_via"] = "-" + + if str(inv.get("status") or "").lower() not in {"paid", "partial"}: + continue + + pay_conn = get_db_connection() + pay_cursor = pay_conn.cursor(dictionary=True) + pay_cursor.execute(""" + SELECT payment_method, payment_currency + FROM payments + WHERE invoice_id = %s + AND payment_status = 'confirmed' + ORDER BY COALESCE(received_at, created_at) DESC, id DESC + LIMIT 1 + """, (inv["id"],)) + last_payment = pay_cursor.fetchone() + pay_conn.close() + + if last_payment: + inv["paid_via"] = payment_method_label( + last_payment.get("payment_method"), + last_payment.get("payment_currency"), + ) + + return render_template("invoices/list.html", invoices=invoices, filters=filters, clients=clients) diff --git a/templates/invoices/list.html b/templates/invoices/list.html index 7f99aa0..fa0df91 100644 --- a/templates/invoices/list.html +++ b/templates/invoices/list.html @@ -130,6 +130,7 @@ select {