Skip to content

Conversation

@vankiru
Copy link
Contributor

@vankiru vankiru commented Nov 18, 2025

Roadmap Task

👉 Spec
👉 Dive In

Context

This PR is part of the Invoice Issuing Date preferences updates.

Description

This PR implements the logic for subscription_invoice_issuing_date_anchor and subscription_invoice_issuing_date_adjustment. These settings only apply to recurring invoices – meaning invoices with type = "subscription" and invoicing_reason = "subscription_periodic". They don't affect invoices created when a subscription starts or terminated, or any other invoice types.

Basic idea

subscription_invoice_issuing_date_anchor can be either current_period_end or next_period_start
subscription_invoice_issuing_date_adjustment can be either align_with_finalization or keep_anchor

Billing period: from – to

  1. current_period_end + align_with_finalization
issuing_date = to + grace_period + 1.day
  1. current_period_end + keep_anchor
issuing_date = to
  1. next_period_start + align_with_finalization
issuing_date = to + grace_period + 1.day
  1. next_period_start + keep_anchor
issuing_date = to + 1.day

The extra + 1.day in cases 1 and 3 matches how grace periods currently behave.

Example

Billing period: Oct 1 – Oct 31, 2025
Grace period: 3 days

  1. current_period_end + align_with_finalization → Nov 4, 2025
  2. current_period_end + keep_anchor → Oct 31, 2025
  3. next_period_start + align_with_finalization → Nov 4, 2025
  4. next_period_start + keep_anchor → Nov 1, 2025

Notes

Right now, invoices are actually generated on the first day of the next billing period, so the code is based on to + 1.day instead of just to. The implementation is adjusted to match this behavior.

Invoice::IssuingDateService

Invoices::IssuingDateService returns an "adjustment" for the issuing date, which it calculates using all three issuing date settings (anchor, adjustment, and grace period). It can take both customer and billing entity as objects or hashes. We use the object version when calculating adjustments for new invoices, and the hash version when updating settings on the customer or billing entity, so we can still calculate adjustments using the old values.

For the current_period_end + align_with_finalization_date setup: if the grace period is 0, we need to fall back to the actual end date of the current period – that’s why we do -1 in that case.

Other changes

Renamed and updated all the UpdateInvoiceGracePeriodFromBillingEntity-style services and jobs to UpdateInvoiceIssuingDateFromBillingEntity, so they now update the issuing date based on all the settings, not just the grace period.

@vankiru vankiru marked this pull request as ready for review November 18, 2025 06:46
@vankiru vankiru force-pushed the feat/invoice-issuing-date-4-logic branch from eecc812 to bfe79b8 Compare November 21, 2025 06:42
@vankiru vankiru force-pushed the feat/invoice-issuing-date-4-logic branch from f9ff7a2 to aa9c06f Compare November 26, 2025 16:54
…_date (#4667)

👉
[Spec](https://www.notion.so/getlago/Spec-Define-the-issuing-date-preferences-of-subscription-invoices-2a0ef63110d2807d860cc22ced334bfb)
👉 [Dive
In](https://www.notion.so/getlago/BE-Dive-In-Define-the-issuing-date-preferences-of-subscription-invoices-2a3ef63110d2800e8620fb5687f0edf9?d=2a3ef63110d2808f96fd001cbc71298b#2a3ef63110d2807abf14f498b984ac57)

This PR is part of the Invoice Issuing Date preferences updates.

With the new issuing date adjustment setting, `issuing_date` might skip
using `invoice_grace_period` (when the adjustment set to "keep_anchor").
But we still need to factor in `invoice_grace_period` when finalizing
invoices.

This PR adds a new field, `expected_finalization_date`, which stores the
date when a draft invoice should be auto-finalized. It's basically:
```
expected_finalization_date = invoice creation date + invoice_grace_period.days
```

The `expected_finalization_date` field is mostly for internal use. We
only expose it in GraphQL so we can show the right message about when a
draft invoice will be finalized. It's not available in the REST API or
in the SDK clients.
@vankiru vankiru force-pushed the feat/invoice-issuing-date-4-logic branch from 0a00f8c to 917afaf Compare December 9, 2025 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants