Add balance adjustments (M8)
- New balance_adjustments table with CRUD store, sync logging, and service methods
- SQL migrations restructured: embed fs.FS from internal/store/migrations/, apply in order via user_version
- WeekService.Balance combines closed-weeks delta + adjustments delta; BalanceSummary breakdown
- Four REST routes: GET/POST /api/balance/adjustments, PUT/DELETE /api/balance/adjustments/{id}
- Dexie schema v2 + sync apply cases for balance_adjustments
- API client: BalanceAdjustment type, balance namespace (list/create/update/delete)
- utils: composeDeltaMs / decomposeDeltaMs helpers + 8 new Vitest tests (19 total, all passing)
- History page: balance card breakdown line + full adjustments section with inline add/edit/delete
This commit is contained in:
31
PLAN.md
31
PLAN.md
@@ -88,13 +88,25 @@ CREATE TABLE settings_history (
|
||||
|
||||
-- Sync event log (last-write-wins per entity row)
|
||||
CREATE TABLE sync_log (
|
||||
entity TEXT NOT NULL, -- 'entries' | 'closed_days' | 'closed_weeks'
|
||||
entity TEXT NOT NULL, -- 'entries' | 'closed_days' | 'closed_weeks' | 'balance_adjustments'
|
||||
entity_id TEXT NOT NULL,
|
||||
op TEXT NOT NULL, -- 'upsert' | 'delete'
|
||||
version INTEGER NOT NULL, -- monotonic server-assigned
|
||||
payload TEXT NOT NULL, -- JSON snapshot
|
||||
PRIMARY KEY (entity, entity_id, version)
|
||||
);
|
||||
|
||||
-- Balance adjustments: manual corrective entries that modify the overall overtime balance
|
||||
-- without touching week math. Signed delta_ms (positive = credit, negative = debit).
|
||||
CREATE TABLE balance_adjustments (
|
||||
id TEXT PRIMARY KEY, -- client-generated UUIDv7 (sync-friendly)
|
||||
delta_ms INTEGER NOT NULL, -- signed; non-zero enforced at service layer
|
||||
note TEXT NOT NULL DEFAULT '', -- optional free-text reason
|
||||
effective_at INTEGER NOT NULL, -- unix ms; backdatable
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
CREATE INDEX idx_balance_adjustments_effective_at ON balance_adjustments(effective_at);
|
||||
```
|
||||
|
||||
### API Surface (REST/JSON)
|
||||
@@ -118,6 +130,13 @@ DELETE /api/days/{day_key}/close (reopen day)
|
||||
GET /api/weeks?from=YYYY-Www&to=YYYY-Www
|
||||
POST /api/weeks/{week_key}/close -> ClosedWeek
|
||||
DELETE /api/weeks/{week_key}/close (reopen week)
|
||||
GET /api/weeks/balance -> BalanceSummary
|
||||
|
||||
# Balance adjustments
|
||||
GET /api/balance/adjustments -> []BalanceAdjustment
|
||||
POST /api/balance/adjustments { delta_ms, note?, effective_at } -> BalanceAdjustment
|
||||
PUT /api/balance/adjustments/{id} { delta_ms, note?, effective_at } -> BalanceAdjustment
|
||||
DELETE /api/balance/adjustments/{id}
|
||||
|
||||
# Settings
|
||||
GET /api/settings # current effective settings
|
||||
@@ -243,7 +262,11 @@ Staged implementation:
|
||||
| 4 | Backend guard: reject future-day intervals | pending |
|
||||
| 5 | Bottom nav Today shortcut; delete /today route | pending |
|
||||
|
||||
### M8 — Future
|
||||
### M8 — Balance adjustments ✅
|
||||
|
||||
Manual corrective entries on the History page that adjust the overall overtime balance without touching week math. Separate `balance_adjustments` table with signed `delta_ms`, optional `note`, and `effective_at` (backdatable). Balance summary combines `Σ closed_weeks.delta_ms + Σ balance_adjustments.delta_ms`.
|
||||
|
||||
### M9 — Future
|
||||
CSV/JSON export, monthly summary view.
|
||||
|
||||
## 7. Decisions & Rationale
|
||||
@@ -260,5 +283,7 @@ CSV/JSON export, monthly summary view.
|
||||
| Week close settings | Use close-time date, not week Monday | Settings changed mid-week apply to that week's close |
|
||||
| weekDayKeys formula | `(weekday+6)%7` for days-since-Monday | Avoids sign bug when Jan 4 is Sunday (affects year 2026) |
|
||||
| Merged Today+Week | Single `/week` route with day selection | Reduces duplication; week context always visible |
|
||||
| Future intervals | Rejected by server (400) | Nonsensical to track time that hasn't happened |
|
||||
| Balance adjustments | Separate `balance_adjustments` table | Avoids conflating measured deltas with manual corrections; preserves week math invariant (`delta_ms = worked - expected`) |
|
||||
| Balance adjustment scope | Closed weeks only for auto balance | In-progress week delta shown separately in week view; mixing would make balance jitter |
|
||||
| Balance adjustment IDs | TEXT (UUIDv7, client-generated) | Consistent with `entries`; allows offline creation and sync |
|
||||
| Test framework | Vitest (frontend) + Go testing (backend) | Automated coverage for capability logic and key utilities |
|
||||
|
||||
Reference in New Issue
Block a user