Status: Accepted (in force). Reconstructed from implementation.
Context
Payroll must be reviewed before it's real. Admins need to see exact take-home and company cost, adjust (add changes, skip people), and re-check — all without producing live records or moving money.
Decision
A two-phase model:
- Prepare computes everything into
TempPayrollItems / TempPayrollItemSummaries (preview/staging). Nothing live changes. Re-preparing calls spRollbackPayrollPreview to wipe the temp set and recompute.
- Submit copies the preview into the live
PayrollItems / PayrollItemSummaries and enters approval + payment.
Read endpoints come in matched pairs — a live family (Select…PayrollItem…) and a preview family with a Temp infix (Select…TempPayrollItem…).
Consequences
Good:
- Safe, repeatable review; edits never risk live data.
- Clean rollback of a preview (just clear temp tables).
- The UI's "What Employees Take Home / What Company Pays" can render straight from preview before commit.
Bad / costs:
- Duplicated surface — nearly every read endpoint exists twice (live + Temp), doubling API and maintenance.
- Developers must always ask "am I reading live or preview?" — a common source of "the data isn't there" confusion (it's still in Temp, not Submitted).
- Temp tables must be kept in sync and cleaned up.
Alternatives considered
- Compute-on-read preview (no staging tables) — rejected: recomputing on every read is expensive and non-deterministic across edits.
- Status flag on live rows instead of separate tables — rejected: risks live/preview data mixing and complicates queries and payments.