From dd9d9e392a3a683fa2745c11ae8679c0a9b2113d Mon Sep 17 00:00:00 2001 From: Ivan Novosad Date: Thu, 9 Jan 2025 14:15:28 +0100 Subject: [PATCH] feat(manual-payments): Add total paid and total due to pdf templates --- app/models/invoice.rb | 6 ++++++ .../templates/invoices/v3/_subscription_details.slim | 12 +++++++++++- .../invoices/v3/_subscriptions_summary.slim | 10 +++++++++- .../templates/invoices/v4/_subscription_details.slim | 12 +++++++++++- .../invoices/v4/_subscriptions_summary.slim | 10 +++++++++- config/locales/de/invoice.yml | 2 ++ config/locales/en/invoice.yml | 2 ++ config/locales/es/invoice.yml | 4 +++- config/locales/fr/invoice.yml | 2 ++ config/locales/it/invoice.yml | 2 ++ config/locales/nb/invoice.yml | 2 ++ config/locales/sv/invoice.yml | 4 +++- 12 files changed, 62 insertions(+), 6 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index efe55d7ba19..b7f97e18ec0 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -50,12 +50,14 @@ class Invoice < ApplicationRecord :sub_total_excluding_taxes_amount_cents, :sub_total_including_taxes_amount_cents, :total_amount_cents, + :total_paid_amount_cents, :taxes_amount_cents, with_model_currency: :currency # NOTE: Readonly fields monetize :charge_amount_cents, :subscription_amount_cents, + :total_due_amount_cents, disable_validation: true, allow_nil: true, with_model_currency: :currency @@ -254,6 +256,10 @@ def charge_pay_in_advance_proration_range(fee, timestamp) } end + def total_due_amount_cents + total_amount_cents - total_paid_amount_cents + end + # amount cents onto which we can issue a credit note def available_to_credit_amount_cents return 0 if version_number < CREDIT_NOTES_MIN_VERSION || draft? diff --git a/app/views/templates/invoices/v3/_subscription_details.slim b/app/views/templates/invoices/v3/_subscription_details.slim index 4f334e91944..8c4e715ef5c 100644 --- a/app/views/templates/invoices/v3/_subscription_details.slim +++ b/app/views/templates/invoices/v3/_subscription_details.slim @@ -186,9 +186,19 @@ td.body-2 = '-' + MoneyHelper.format(prepaid_credit_amount) tr td.body-2 - td.body-1 = I18n.t('invoice.total_due') + td.body-1 = I18n.t('invoice.total') td.body-1 = MoneyHelper.format(total_amount) + tr + td.body-2 + td.body-1 = I18n.t('invoice.total_paid_amount') + td.body-1 + = MoneyHelper.format(total_paid_amount) + tr + td.body-2 + td.body-1 = I18n.t('invoice.total_due_amount') + td.body-1 + = MoneyHelper.format(total_due_amount) - else tr td.body-2 diff --git a/app/views/templates/invoices/v3/_subscriptions_summary.slim b/app/views/templates/invoices/v3/_subscriptions_summary.slim index 796446c1844..328c6d9cc22 100644 --- a/app/views/templates/invoices/v3/_subscriptions_summary.slim +++ b/app/views/templates/invoices/v3/_subscriptions_summary.slim @@ -46,5 +46,13 @@ table.total-table width="100%" td.body-2 = '-' + MoneyHelper.format(prepaid_credit_amount) tr td.body-2 - td.body-1 = I18n.t('invoice.total_due') + td.body-1 = I18n.t('invoice.total') td.body-1 = MoneyHelper.format(total_amount) + tr + td.body-2 + td.body-1 = I18n.t('invoice.total_paid_amount') + td.body-1 = MoneyHelper.format(total_paid_amount) + tr + td.body-2 + td.body-1 = I18n.t('invoice.total_due_amount') + td.body-1 = MoneyHelper.format(total_due_amount) diff --git a/app/views/templates/invoices/v4/_subscription_details.slim b/app/views/templates/invoices/v4/_subscription_details.slim index 386818088c4..8037cdda5d3 100644 --- a/app/views/templates/invoices/v4/_subscription_details.slim +++ b/app/views/templates/invoices/v4/_subscription_details.slim @@ -183,9 +183,19 @@ td.body-2 = '-' + MoneyHelper.format(prepaid_credit_amount) tr td.body-2 - td.body-1 = I18n.t('invoice.total_due') + td.body-1 = I18n.t('invoice.total') td.body-1 = MoneyHelper.format(total_amount) + tr + td.body-2 + td.body-1 = I18n.t('invoice.total_paid_amount') + td.body-1 + = MoneyHelper.format(total_paid_amount) + tr + td.body-2 + td.body-1 = I18n.t('invoice.total_due_amount') + td.body-1 + = MoneyHelper.format(total_due_amount) - else - if progressive_billing_credit_amount_cents.positive? - credits = progressice_billing_credits(invoice_subscription.subscription).all diff --git a/app/views/templates/invoices/v4/_subscriptions_summary.slim b/app/views/templates/invoices/v4/_subscriptions_summary.slim index 6706c27b2e3..ba1b657b7d6 100644 --- a/app/views/templates/invoices/v4/_subscriptions_summary.slim +++ b/app/views/templates/invoices/v4/_subscriptions_summary.slim @@ -62,5 +62,13 @@ table.total-table width="100%" td.body-2 = '-' + MoneyHelper.format(prepaid_credit_amount) tr td.body-2 - td.body-1 = I18n.t('invoice.total_due') + td.body-1 = I18n.t('invoice.total') td.body-1 = MoneyHelper.format(total_amount) + tr + td.body-2 + td.body-1 = I18n.t('invoice.total_paid_amount') + td.body-1 = MoneyHelper.format(total_paid_amount) + tr + td.body-2 + td.body-1 = I18n.t('invoice.total_due_amount') + td.body-1 = MoneyHelper.format(total_due_amount) diff --git a/config/locales/de/invoice.yml b/config/locales/de/invoice.yml index 7de005c3c13..94ccc6b2751 100644 --- a/config/locales/de/invoice.yml +++ b/config/locales/de/invoice.yml @@ -87,7 +87,9 @@ de: total_credits: Gesamtguthaben total_credits_with_value: 'Gesamtguthaben: %{credit_amount} Credits' total_due: Insgesamt fällig + total_due_amount: Betrag fällig total_events: 'Ereignisse insgesamt: %{count}' + total_paid_amount: Betrag bezahlt total_unit: 'Gesamte Einheiten: %{units}' total_unit_interval: 'Gesamte Einheiten: %{events_count} Ereignisse für %{units}' true_up_details: Mindestausgabe von %{min_amount} anteilig an den Nutzungstagen diff --git a/config/locales/en/invoice.yml b/config/locales/en/invoice.yml index 859103b4121..a694ca68553 100644 --- a/config/locales/en/invoice.yml +++ b/config/locales/en/invoice.yml @@ -87,7 +87,9 @@ en: total_credits: Total credits total_credits_with_value: 'Total credits: %{credit_amount} credits' total_due: Total due + total_due_amount: Amount due total_events: 'Total events: %{count}' + total_paid_amount: Amount paid total_unit: 'Total unit: %{units}' total_unit_interval: 'Total unit: %{events_count} events for %{units}' true_up_details: Minimum spend of %{min_amount} prorated on days of usage diff --git a/config/locales/es/invoice.yml b/config/locales/es/invoice.yml index 33ba9e14ca1..d99a5adc598 100644 --- a/config/locales/es/invoice.yml +++ b/config/locales/es/invoice.yml @@ -85,7 +85,9 @@ es: total: Total total_credits_with_value: 'Total de créditos con valor: %{credit_amount} créditos' total_due: Total debido - total_event: Eventos totales + total_due_amount: Monto debido + total_events: 'Eventos totales: %{count}' + total_paid_amount: Monto pagado total_unit: 'Total de unidades: %{units}' total_unit_interval: 'Total de unidades: %{events_count} evento(s) para %{units}' true_up_details: Gasto mínimo de %{min_amount} prorrateado en días de uso diff --git a/config/locales/fr/invoice.yml b/config/locales/fr/invoice.yml index 5b4d376880e..39cb5366904 100644 --- a/config/locales/fr/invoice.yml +++ b/config/locales/fr/invoice.yml @@ -87,7 +87,9 @@ fr: total_credits: Total crédits total_credits_with_value: 'Nombre total de crédits: %{credit_amount} crédits' total_due: Total dû + total_due_amount: Montant dû total_events: 'Nombre total d''événements: %{count}' + total_paid_amount: Montant payé total_unit: 'Nombre total d''unités: %{units}' total_unit_interval: 'Nombre total d''unités: %{events_count} événement(s) pour %{units}' true_up_details: Dépense minimale de %{min_amount} au prorata des jours d'utilisation diff --git a/config/locales/it/invoice.yml b/config/locales/it/invoice.yml index c6e81028cb0..daf5fb8fe22 100644 --- a/config/locales/it/invoice.yml +++ b/config/locales/it/invoice.yml @@ -87,7 +87,9 @@ it: total_credits: Crediti totali total_credits_with_value: 'Crediti totali: %{credit_amount} crediti' total_due: Totale dovuto + total_due_amount: Importo dovuto total_events: 'Eventi totali: %{count}' + total_paid_amount: Importo pagato total_unit: 'Unità totale: %{units}' total_unit_interval: 'Unità totale: %{events_count} eventi per %{units}' true_up_details: Spesa minima di %{min_amount} proporzionata sui giorni di utilizzo diff --git a/config/locales/nb/invoice.yml b/config/locales/nb/invoice.yml index e46cd54791d..4aa243c90a0 100644 --- a/config/locales/nb/invoice.yml +++ b/config/locales/nb/invoice.yml @@ -87,7 +87,9 @@ nb: total_credits: Antall kreditter total_credits_with_value: 'Antall kreditter: %{credit_amount} kreditter' total_due: Å betale + total_due_amount: Skyldig beløp total_events: 'Totalt antall hendelser: %{count}' + total_paid_amount: Betalt beløp total_unit: 'Antall enheter: %{units}' total_unit_interval: 'Antall enheter: %{events_count} hendelser for %{units}' true_up_details: Minimumsutgift på %{min_amount} beregnet etter antall brukte dager diff --git a/config/locales/sv/invoice.yml b/config/locales/sv/invoice.yml index 4389f02e807..c754c8e6ffb 100644 --- a/config/locales/sv/invoice.yml +++ b/config/locales/sv/invoice.yml @@ -85,7 +85,9 @@ sv: total: Total total_credits_with_value: 'Totalt antal krediter med värde: %{credit_amount} krediter' total_due: Att betala - total_event: Totala händelser + total_due_amount: Att betala belopp + total_events: 'Totala händelser: %{count}' + total_paid_amount: Betalt belopp total_unit: 'Totalt antal enheter: %{units}' total_unit_interval: 'Totalt antal enheter: %{events_count} händelse(r) för %{units}' true_up_details: Minsta utgift på %{min_amount} fördelat på användningsdagar