The vacation ledger sync carried entitled_days verbatim on existing open rows while re-deriving accrued and taken, so a stale entitled value (for example the flat 25 stored before Semesterlagen 7 § pro-rating existed) survived every sync. The recompute loop now re-derives entitled the same way the lazy-seed path does, with the opening-balance cutover still outranking recomputation for the year containing cutover_date. Opening balances could also not record paid vacation days already taken in the cutover year under the previous payroll system. New additive column employee_opening_balances.vacation_days_taken_this_year (NUMERIC NOT NULL DEFAULT 0, CHECK 0..40) threaded through the shared service, the Zod schema, the MCP staging tool (schema + mergeable fields), the staged-operation executor, the v1 REST routes, and the employee editor form. Ledger semantics for the cutover year, on both seed and recompute paths: entitled = remaining + taken_this_year, taken = booked-run taken + taken_this_year, so remaining keeps meaning remaining and the seeded value survives every subsequent sync. Fixes #1347 Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
24 lines
1.2 KiB
SQL
24 lines
1.2 KiB
SQL
-- Migration: employee_opening_balances.vacation_days_taken_this_year
|
|
-- (issue #1347: opening balances could not record already-taken days).
|
|
--
|
|
-- A company switching to Accounted mid-year may have paid vacation days
|
|
-- already taken in the current vacation year under the previous payroll
|
|
-- system. Those days are invisible to the ledger sync, which re-derives
|
|
-- taken_days purely from BOOKED Accounted runs, so the cutover-year row
|
|
-- understated both entitled and taken.
|
|
--
|
|
-- Ledger semantics for the vacation year containing cutover_date:
|
|
-- entitled_days = vacation_paid_days_remaining + vacation_days_taken_this_year
|
|
-- taken_days = taken in booked runs + vacation_days_taken_this_year
|
|
-- vacation_paid_days_remaining keeps meaning "remaining at cutover"
|
|
-- (backward compatible: the public v1 REST API already exposes it).
|
|
--
|
|
-- The column rides the existing enforce_opening_balances_lock trigger:
|
|
-- editable until the employee appears in a booked salary run.
|
|
|
|
ALTER TABLE public.employee_opening_balances
|
|
ADD COLUMN vacation_days_taken_this_year NUMERIC NOT NULL DEFAULT 0
|
|
CHECK (vacation_days_taken_this_year >= 0 AND vacation_days_taken_this_year <= 40);
|
|
|
|
NOTIFY pgrst, 'reload schema';
|