Version 1.0 · 15 Aug 2026 · PaidHR
Companion: brd.md · Baseline: core-backend-service origin/staging, web-app working tree, dev stored-procedure dump of 14 Aug 2026 (437 procedures).
Line references are to
origin/stagingand will drift — re-verify per phase. A 297-commit local drift already produced one incorrect finding during analysis.
Three decisions frame everything below.
RequestService. It is 13,990 lines carrying all seven request types, and leave has no service of its own. Leave gets dedicated services; the generic request engine keeps only what is genuinely generic.| Location | Defect | Fix |
|---|---|---|
RequestService.cs:4717, 5853, 6920, 7845, 8595, 9841, 10928 |
Editable-status guard is wrong at 7 sites. StatusId > IAPPROVED admits Declined (2) as well as New (3). Live-proven: editing a declined leave credits the days a second time — employee gains 2 days per cycle, repeatable, no approver involved. |
Replace with an explicit == INEW allow-list at all seven. Highest-priority change in the programme. |
RequestService.cs:4779–4791 |
Edit path has no balance validation. Credits the old day count and debits the new with no affordability check; that check exists only on create. | Apply the create path's balance check after computing new working days. |
RequestService.cs:1312–1327 |
Dead decline block. Runs after spReviewEmployeeRequest has already restored; fetches one row into two variables and does −N then +N. |
Delete it. Do not "repair" it to a single += — that would double-restore every declined leave. |
| Location | Defect | Fix |
|---|---|---|
RequestService.cs:11976 |
ESS create dereferences a missing balance. Admin path guarded at :4909; self-service was not. |
Add the same if (elbModel == null) branch. |
AdminRequestService.GetLeaveBalance |
"No entitlement" and "zero days" return identically — empty model with HTTP 200. Misleads employees, support, and this analysis. | Return an explicit not-entitled state. |
RequestService.cs:4390 |
A balance cannot be set to zero. current_balance > 0 skips the write and reports success. |
>= 0, with a separate null/parse check. |
RequestService.cs:4747, 4905, 11972 |
NRE on unpaid leave when DailyNet is null (no paygrade, mid-onboarding). |
Null-guard with a clear message. |
EmployeeRequestRepository.cs:42–55 |
Overlap check is per-policy and skipped on edit. An employee can hold annual and sick leave on the same dates. | Drop the policy filter (BR-06); call from the edit path too. |
EmployeeLeaveBalance |
No concurrency token. Read-modify-write in C# and SELECT-then-UPDATE in SQL both race. |
Add a rowversion token; folded into §2.3. |
AdminRequestService.cs:629 |
Delete_LeaveRequest is implemented but unroutable — no controller action, CanDeleteLeaveRequests applied nowhere. |
Decide: expose it with the permission, or remove the dead method and its 262-line procedure. |
| Location | Defect | Fix |
|---|---|---|
GetWorkingDays:13624, AddWorkingDays:80, getWeekdaysBetweenDates ×2 |
Three incompatible holiday conventions for one number — what is charged, what the picker allows, what the employee sees. | Consolidate into LeaveCalendarService; see §2.4. |
RequestService.cs:13624 |
Bare catch returns 0. A malformed holiday row becomes a zero-day request that passes validation and deducts nothing. |
Let it throw; 0 must mean only "invalid range". |
RequestService.cs:13639 |
Workplace holidays commented out while every caller still passes office_address_id. |
Re-enable — already written. |
spUpdateEmployeeLeaveBalance| Defect | Fix |
|---|---|
| Every employee accrues at the last policy item's rate. The person loop sits outside the item loop and reads scalars left from the final iteration. Breaks every multi-paygrade policy. | Restructure set-based, joining each person to their own governing policy item. |
#tmpPerson never cleared between policies — the person set accumulates across the policy loop. |
Scope the temp table per policy, or eliminate it in the rewrite. |
@HireDate assigned only inside the waiting-period branch, so anniversary accrual reads a stale or NULL date and can silently never fire. |
Resolve hire date per person unconditionally. |
No idempotency, no catch-up. Every trigger is an exact = @Date test: a missed night is skipped forever, a repeated run double-accrues. |
Record accrual per person per period; make runs idempotent and replayable. |
@Payperiod leaks across iterations into log descriptions — 'Accrued in ' + @Payperiod can name a previous employee's period, or be NULL. |
Resolved by the typed ledger (§2.3). |
Monthly accrual produces fractions that cannot be spent. WorkingDays / 12 is rarely whole, and half-days are ruled out. |
Cumulative rounding so intermediate balances are whole and the annual total exact — 20 days accrues 2,2,1,2,2,1,… = 20. |
| Item | Disposition |
|---|---|
Decimal balances truncated to INT on decline and delete |
By design. Balances are whole days on those paths. Confirmed 15 Aug; do not re-raise. The knock-on — accrual creating unspendable fractions — is handled by cumulative rounding above. |
| "Leave allowance in lieu" is disconnected from leave | Product question, not a defect. spProcessLeaveAllowanceInLieu pays on months of service and never reads a leave balance. Flagged for product to confirm intent. |