The refactor that changed behaviour
A cleanup PR converts a callback-based function to async/await.
invoices.forEach(async (invoice) => {
await finalize(invoice);
});
await markPeriodClosed(periodId);forEach doesn't wait for async callbacks, so markPeriodClosed runs before invoices are finalized — the old version finalized them first. Use for...of or await Promise.all(invoices.map(finalize)).
Result: A 'harmless' modernisation doesn't close billing periods with unfinalised invoices.