Skip to content

Commit

Permalink
fix invoice template
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pochet committed Aug 26, 2024
1 parent d671316 commit bc430eb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/services/credits/progressive_billing_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def call
.invoices
.progressive_billing
.finalized
.where(issuing_date: invoice_subscription.charges_from_datetime...invoice_subscription.charges_to_datetime)
.where(created_at: invoice_subscription.charges_from_datetime...invoice_subscription.charges_to_datetime)
.order(issuing_date: :asc)

total_subscription_amount = invoice.fees.charge.where(subscription: subscription).sum(:amount_cents)
Expand Down Expand Up @@ -63,7 +63,7 @@ def should_create_progressive_billing_credit?
invoice.invoice_subscriptions.any? do |invoice_subscription|
invoice_subscription.subscription.invoices.progressive_billing
.finalized
.where(issuing_date: invoice_subscription.charges_from_datetime...invoice_subscription.charges_to_datetime)
.where(created_at: invoice_subscription.charges_from_datetime...invoice_subscription.charges_to_datetime)
.exists?
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/views/templates/invoices/v4.slim
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,10 @@ html
.invoice-resume.mb-24.overflow-auto
- if credit?
== SlimHelper.render('templates/invoices/v4/_credit', self)
- elsif subscriptions.count == 1
== SlimHelper.render('templates/invoices/v4/_subscription_details', self)
- elsif progressive_billing?
== SlimHelper.render('templates/invoices/v4/_progressive_billing_details', self)
- elsif subscriptions.count == 1
== SlimHelper.render('templates/invoices/v4/_subscription_details', self)
- else
== SlimHelper.render('templates/invoices/v4/_subscriptions_summary', self)

Expand All @@ -465,7 +465,7 @@ html
- if progressive_billing?
p.body-3.mb-24
- applied_usage_threshold = applied_usage_thresholds.order(created_at: :asc).last
= I18n.t('invoice.reached_usage_threshold', usage_amount: MoneyHelper. applied_usage_threshold.lifetime_usage_amount, threshold_amount: MoneyHelper.format(applied_usage_threshold.threshold.amount_cents))
= I18n.t('invoice.reached_usage_threshold', usage_amount: MoneyHelper.format(applied_usage_threshold.lifetime_usage_amount), threshold_amount: MoneyHelper.format(applied_usage_threshold.usage_threshold.amount))

p.body-3.mb-24 = LineBreakHelper.break_lines(organization.invoice_footer)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
table.total-table width="100%"
tr
td.body-2
td.body-2 I18.t('invoice.progressive_billing_credit')
td.body-2 = I18n.t('invoice.progressive_billing_credit')
td.body-2 = '-' + MoneyHelper.format(progressive_billing_credit_amount)

- if coupons_amount_cents.positive?
Expand Down
4 changes: 2 additions & 2 deletions app/views/templates/invoices/v4/_subscription_details.slim
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
- if progressive_billing_credit_amount_cents.positive?
tr
td.body-2
td.body-2 I18.t('invoice.progressive_billing_credit')
td.body-2 = I18n.t('invoice.progressive_billing_credit')
td.body-2 = '-' + MoneyHelper.format(progressive_billing_credit_amount)

- if coupons_amount_cents.positive?
Expand Down Expand Up @@ -191,7 +191,7 @@
- if credits.present?
tr
td.body-2
td.body-2 I18.t('invoice.progressive_billing_credit')
td.body-2 = I18n.t('invoice.progressive_billing_credit')
td.body-2 = '-' + MoneyHelper.format(credits.sum(&:amount))
tr
td.body-2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ table.total-table width="100%"
- if progressive_billing_credit_amount_cents.positive?
tr
td.body-2
td.body-2 I18.t('invoice.progressive_billing_credit')
td.body-2 = I18n.t('invoice.progressive_billing_credit')
td.body-2 = '-' + MoneyHelper.format(progressive_billing_credit_amount)

- if coupons_amount_cents.positive?
Expand Down
7 changes: 7 additions & 0 deletions spec/services/credits/progressive_billing_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
invoice_type: :progressive_billing,
subscriptions: [subscription],
issuing_date: invoice.issuing_date - 1.day,
created_at: invoice.issuing_date - 1.day,
fees_amount_cents: 20
)
end
Expand Down Expand Up @@ -84,6 +85,7 @@
invoice_type: :progressive_billing,
subscriptions: [subscription],
issuing_date: invoice.issuing_date - 2.days,
created_at: invoice.issuing_date - 2.days,
fees_amount_cents: 20
)
end
Expand All @@ -97,6 +99,7 @@
invoice_type: :progressive_billing,
subscriptions: [subscription],
issuing_date: invoice.issuing_date - 1.day,
created_at: invoice.issuing_date - 1.day,
fees_amount_cents: 200
)
end
Expand Down Expand Up @@ -134,6 +137,7 @@
invoice_type: :progressive_billing,
subscriptions: [subscription],
issuing_date: invoice.issuing_date - 3.days,
created_at: invoice.issuing_date - 3.days,
fees_amount_cents: 20
)
end
Expand All @@ -147,6 +151,7 @@
invoice_type: :progressive_billing,
subscriptions: [subscription],
issuing_date: invoice.issuing_date - 2.days,
created_at: invoice.issuing_date - 2.days,
fees_amount_cents: 1000
)
end
Expand All @@ -160,6 +165,7 @@
invoice_type: :progressive_billing,
subscriptions: [subscription],
issuing_date: invoice.issuing_date - 1.day,
created_at: invoice.issuing_date - 1.day,
fees_amount_cents: 200
)
end
Expand Down Expand Up @@ -207,6 +213,7 @@
invoice_type: :progressive_billing,
subscriptions: [subscription],
issuing_date: invoice.issuing_date - 1.day,
created_at: invoice.issuing_date - 1.day,
fees_amount_cents: 20
)
end
Expand Down

0 comments on commit bc430eb

Please sign in to comment.