Late fees on overdue invoices

Ruby · Rails · beginner · modification

Adds per-account late fees, so an overdue invoice shows the fee in its amount due. The migration adds `late_fee_percent` to `accounts` (integer, not null, default 0, with a check constraint keeping it between 0 and 100). `Invoice` gains `late_fee_cents`, which is 0 unless the invoice is late and otherwise takes the account's percentage of the invoice amount, and `amount_due_cents` now adds it for unpaid invoices. `test/models/invoice_test.rb` adds model tests for the new methods.

Ruby 4.0, Rails 8.1. SQLite in development and test, PostgreSQL 16 in production; nothing here depends on the database beyond the column and its check constraint. `amount_cents` is a positive Integer (validated, and a DB check constraint), `due_on` is a required date, and `paid_at` is set when the invoice is paid. `Invoice#late?` and `Invoice#paid?` are existing and unchanged; `Date.current` uses the app's configured time zone. `Account has_many :invoices` and `Invoice belongs_to :account` (existing). The invoice page and the invoice JSON (`InvoicesController#show`, existing, unchanged, scoped to `Current.account`) already render `amount_due_cents`. The setting is edited from the account settings form, which ships separately and validates the same 0 to 100 range; until then support sets it in the console.

Requirements

Files touched

Review this PR

Ruby practice