feat(budget): make a settle-up payment's date editable

The settle-up form only exposed from/to/amount and silently dated the
payment by created_at, unlike a regular expense which has an editable
date. Add a settled_at column (independent of created_at, same split as
expense_date) through the schema, migration, service, REST and MCP
surfaces, and the desktop + mobile forms; the ledger groups a payment by
settled_at, falling back to created_at for rows recorded before the
column existed.
This commit is contained in:
RemEx
2026-09-11 15:04:51 +00:00
committed by Maurice
parent 76e182f44e
commit bd46089450
16 changed files with 200 additions and 36 deletions
+14
View File
@@ -4576,6 +4576,20 @@ function runMigrations(db: Database.Database): void {
const inherit = db.prepare('INSERT OR IGNORE INTO roadtrip_preferences (trip_id, key, value) SELECT t.id, s.key, s.value FROM trips t JOIN settings s ON s.user_id = t.user_id WHERE s.key = ? AND s.value IS NOT NULL');
for (const key of ROADTRIP_PREFERENCE_KEYS) inherit.run(key);
},
// A settle-up payment's date was silently `created_at` (when it was recorded),
// not editable like a regular expense's `expense_date`. Add the same split:
// settled_at is the calendar day the transfer actually happened, independent
// of when someone got around to logging it. NULL on legacy rows and rows
// whose caller didn't set it; the read side falls back to created_at's date.
//
// Appended LAST: the array is index-addressed against schema_version.
() => {
const cols = db.prepare("SELECT name FROM pragma_table_info('budget_settlements')").all() as Array<{ name: string }>;
if (!cols.some(c => c.name === 'settled_at')) {
db.exec('ALTER TABLE budget_settlements ADD COLUMN settled_at TEXT');
}
},
];
if (currentVersion < migrations.length) {