From ba2b831cd6a09f651ee587d3e92ab719dda23ec8 Mon Sep 17 00:00:00 2001 From: Rob Martinsen Date: Fri, 13 Nov 2026 12:19:13 -0500 Subject: [PATCH 1/5] Report PI payroll on FTE line 241 instead of 242 v_TransactionSfn moves a UCPath row from FTE line 242 to 241 when the employee is the PI of record on any project in the cycle project list. This brings back last year's sp_Adjust241FTE without the self certify title code list. Co-Authored-By: Claude Fable 5.2 --- database/data/Views/v_TransactionSfn.sql | 28 +++++++-- server/ExpenseReview/ExpenseReviewService.cs | 4 +- ...uildAutoAssociationsSqlIntegrationTests.cs | 56 ++++++++++++++++++ .../TransactionSfnViewSqlIntegrationTests.cs | 57 +++++++++++++++++++ 4 files changed, 140 insertions(+), 5 deletions(-) diff --git a/database/data/Views/v_TransactionSfn.sql b/database/data/Views/v_TransactionSfn.sql index 3712587a..e994cb1a 100644 --- a/database/data/Views/v_TransactionSfn.sql +++ b/database/data/Views/v_TransactionSfn.sql @@ -26,6 +26,12 @@ AS -- missing link is NULL. Fringe rows carry the backfilled job code so they -- resolve like their salary rows. AE rows are always NULL. -- +-- PI rule: when the title's line is 242 (Professional Support) and the +-- employee is the PI of record on any project in the cycle project list +-- (data.Projects.UcpEmployeeId), the line is 241 (Scientist). This is last +-- year's sp_Adjust241FTE without the self certify title code list. Projects +-- excluded under $100 still count. No other line is adjusted. +-- -- LaborTransactionId and AeTransactionId carry the native keys so consumers -- can join on an indexed column; TransactionId is the text form shared with -- v_TransactionOrgR. @@ -56,6 +62,12 @@ PgmAwardSfn AS GROUP BY [ProjectNumber] HAVING COUNT(DISTINCT [PgmSfn]) = 1 ), +ProjectPis AS +( + SELECT DISTINCT [UcpEmployeeId] + FROM [data].[Projects] + WHERE [UcpEmployeeId] IS NOT NULL +), Transactions AS ( SELECT @@ -64,7 +76,8 @@ Transactions AS u.[LaborTransactionId] AS [LaborTransactionId], CAST(NULL AS BIGINT) AS [AeTransactionId], u.[Fund], u.[Project], - u.[JobCode] + u.[JobCode], + u.[EmployeeId] FROM [data].[UcPathTransactions] u UNION ALL @@ -75,7 +88,8 @@ Transactions AS CAST(NULL AS NVARCHAR(125)) AS [LaborTransactionId], a.[Id] AS [AeTransactionId], a.[Fund], a.[Project], - CAST(NULL AS NVARCHAR(4)) AS [JobCode] + CAST(NULL AS NVARCHAR(4)) AS [JobCode], + CAST(NULL AS NVARCHAR(10)) AS [EmployeeId] FROM [data].[AETransactions] a ) SELECT @@ -96,7 +110,11 @@ SELECT WHEN fs.[Sfn] = 'Multiple' AND pa.[Sfn] IS NOT NULL THEN N'PgmAward' ELSE NULL END AS NVARCHAR(20)) AS [ExpenseSfnSource], - CAST(CASE WHEN t.[Source] = N'UCPath' THEN st.[FteSfn] END AS NVARCHAR(10)) AS [FteSfn] + CAST(CASE + WHEN t.[Source] <> N'UCPath' THEN NULL + WHEN st.[FteSfn] = '242' AND pis.[UcpEmployeeId] IS NOT NULL THEN '241' + ELSE st.[FteSfn] + END AS NVARCHAR(10)) AS [FteSfn] FROM Transactions t LEFT JOIN FundSfn fs ON fs.[Fund] = t.[Fund] @@ -107,4 +125,6 @@ LEFT JOIN PgmAwardSfn pa LEFT JOIN [data].[Titles] ti ON t.[Source] = N'UCPath' AND ti.[TitleCode] = t.[JobCode] LEFT JOIN [data].[StaffTypes] st - ON st.[StaffTypeCode] = ti.[StaffTypeCode]; + ON st.[StaffTypeCode] = ti.[StaffTypeCode] +LEFT JOIN ProjectPis pis + ON t.[Source] = N'UCPath' AND pis.[UcpEmployeeId] = t.[EmployeeId]; diff --git a/server/ExpenseReview/ExpenseReviewService.cs b/server/ExpenseReview/ExpenseReviewService.cs index 3d9b1c74..4cd5777d 100644 --- a/server/ExpenseReview/ExpenseReviewService.cs +++ b/server/ExpenseReview/ExpenseReviewService.cs @@ -580,7 +580,9 @@ private static string Qualify(string expression, string alias) // they cannot split a job code's rows any further: Source is always // UCPath here, OrgR follows the job code and financial department // (v_TransactionOrgR), ExpenseSfn follows the fund and project - // (v_TransactionSfn), and FteSfn follows the job code. + // (v_TransactionSfn), and FteSfn follows the job code and the employee + // (the PI rule in v_TransactionSfn moves a PI from 242 to 241, never to + // or from NULL). public const string UnmatchedJobCodesSql = """ WITH SummaryRows AS ( diff --git a/tests/server.tests/SqlIntegration/BuildAutoAssociationsSqlIntegrationTests.cs b/tests/server.tests/SqlIntegration/BuildAutoAssociationsSqlIntegrationTests.cs index 977054ff..5533acd8 100644 --- a/tests/server.tests/SqlIntegration/BuildAutoAssociationsSqlIntegrationTests.cs +++ b/tests/server.tests/SqlIntegration/BuildAutoAssociationsSqlIntegrationTests.cs @@ -145,6 +145,62 @@ public async Task Summary_total_equals_expense_review_included_total() summaryTotal.Should().Be(reviewTotal); } + [Fact] + public async Task Pi_on_a_242_title_is_built_on_line_241_and_rule_220_takes_their_state_payroll() + { + await fixture.ClearDataTablesAsync(); + await SeedScenarioAsync(); + + await using var connection = new SqlConnection(fixture.ConnectionString); + await connection.OpenAsync(); + + await connection.ExecuteAsync( + """ + INSERT INTO [data].[StaffTypes] ([StaffTypeCode], [FteSfn], [Description]) VALUES ('SUPP', '242', 'Professional Support'); + INSERT INTO [data].[Titles] ([TitleCode], [StaffTypeCode], [Name]) VALUES ('3300', 'SUPP', 'Specialist'); + + INSERT INTO [data].[UcPathTransactions] + ([LaborTransactionId], [Entity], [Fund], [FinancialDepartment], [ParentDepartment], [Account], + [Purpose], [Program], [Project], [Activity], [ErnCode], [EmployeeId], [EmployeeName], [PositionNumber], [JobCode], + [Hours], [Amount], [CalculatedFte], [PayPeriodEndDate], [FringeBenefitSalaryCd], + [FiscalYear], [Period], [EmpRcd], [EffSeq], [ExcludedByDate], [AccountNotInAE]) + VALUES + ('ucp-13u02-e2-242', '3310', '13U02', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-C', 'AC1', 'REG', 'E2', 'PI Two', 'POS2', '3300', 10, 100, 0.100000, '2024-11-15', 'S', 2025, '5', 0, 0, 0, 0), + ('ucp-13u02-e7-242', '3310', '13U02', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-C', 'AC1', 'REG', 'E7', 'PI Seven', 'POS7', '3300', 10, 50, 0.050000, '2024-11-15', 'S', 2025, '5', 0, 0, 0, 0), + ('ucp-13u02-e8-242', '3310', '13U02', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-C', 'AC1', 'REG', 'E8', 'Not A PI', 'POS8', '3300', 10, 70, 0.070000, '2024-11-15', 'S', 2025, '5', 0, 0, 0, 0); + """); + + await connection.ExecuteAsync( + "EXEC [data].[BuildAutoAssociations] @cycleStart, @cycleEnd", + new { cycleStart = CycleStart, cycleEnd = CycleEnd }); + + var summary = (await connection.QueryAsync( + "SELECT [ExpenseId], [Source], [OrgR], [Project], [Fund], [EmployeeId], [ExpenseSfn], [FteSfn], [Expenses], [Fte], [RuleExclusion] FROM [data].[ExpenseSummary] WHERE [Fund] = '13U02' AND [EmployeeId] IN ('E2', 'E7', 'E8')")) + .ToDictionary(row => row.EmployeeId!); + + summary["E2"].FteSfn.Should().Be("241"); + summary["E7"].FteSfn.Should().Be("241"); + summary["E8"].FteSfn.Should().Be("242"); + + var staged = (await connection.QueryAsync( + """ + SELECT s.[Rule], s.[AccessionNumber], s.[OrgR], s.[AeProject], s.[ExpenseSfn], s.[Expenses], s.[Fte], s.[FteSfn], e.[Source], e.[Project], e.[Fund], e.[EmployeeId] + FROM [data].[StagedAssociations] s + JOIN [data].[ExpenseSummary] e ON e.[ExpenseId] = s.[ExpenseId] + WHERE e.[Fund] = '13U02' AND e.[EmployeeId] IN ('E2', 'E7', 'E8') + """)).ToList(); + + // E2's state payroll follows them to their one project on line 241. + // E7 is a PI but their only project is excluded under $100; E8 is not a PI. + var row = staged.Should().ContainSingle().Subject; + row.Rule.Should().Be("220"); + row.EmployeeId.Should().Be("E2"); + row.AccessionNumber.Should().Be("1000006"); + row.Expenses.Should().Be(100m); + row.Fte.Should().Be(0.100000m); + row.FteSfn.Should().Be("241"); + } + private async Task SeedScenarioAsync() { await using var connection = new SqlConnection(fixture.ConnectionString); diff --git a/tests/server.tests/SqlIntegration/TransactionSfnViewSqlIntegrationTests.cs b/tests/server.tests/SqlIntegration/TransactionSfnViewSqlIntegrationTests.cs index beeaa849..e930da23 100644 --- a/tests/server.tests/SqlIntegration/TransactionSfnViewSqlIntegrationTests.cs +++ b/tests/server.tests/SqlIntegration/TransactionSfnViewSqlIntegrationTests.cs @@ -114,6 +114,63 @@ FROM [data].[v_TransactionSfn] aeRow.FteSfn.Should().BeNull(); } + [Fact] + public async Task FteSfn_moves_a_pi_from_line_242_to_241_and_leaves_everyone_else() + { + await fixture.ClearDataTablesAsync(); + await SeedReferenceDataAsync(); + + await using var connection = new SqlConnection(fixture.ConnectionString); + await connection.OpenAsync(); + + // PI1 directs two projects so a careless join would double their rows. + await connection.ExecuteAsync( + """ + INSERT INTO [data].[StaffTypes] ([StaffTypeCode], [FteSfn], [Description]) + VALUES ('SUPP', '242', 'Professional Support'), ('TECH', '243', 'Technical Support'); + + INSERT INTO [data].[Titles] ([TitleCode], [StaffTypeCode], [Name]) + VALUES ('3300', 'SUPP', 'Specialist'), ('4000', 'TECH', 'Technician'); + + INSERT INTO [data].[Projects] + ([AccessionNumber], [NifaProjectNumber], [UcpEmployeeId], [Is204], [Sfn], [AEProjectNumber]) + VALUES + ('1000101', 'CA-D-ABC-1101-H', 'PI1', 0, '201', NULL), + ('1000102', 'CA-D-ABC-1102-H', 'PI1', 0, '201', NULL); + + INSERT INTO [data].[UcPathTransactions] + ([LaborTransactionId], [Entity], [Fund], [FinancialDepartment], [ParentDepartment], [Account], + [Purpose], [Program], [Project], [Activity], [ErnCode], [EmployeeId], [PositionNumber], [JobCode], + [Hours], [Amount], [CalculatedFte], [PayPeriodEndDate], [FringeBenefitSalaryCd], + [FiscalYear], [Period], [EmpRcd], [EffSeq]) + VALUES + ('pi-242', '3310', 'F201', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-204', 'AC1', 'REG', 'PI1', 'POS1', '3300', 1, 1, 0.1, '2024-11-15', 'S', 2025, '5', 0, 0), + ('pi-242-fringe', '3310', 'F201', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-204', 'AC1', 'XXX', 'PI1', 'POS1', '3300', 0, 1, 0, '2024-11-15', 'F', 2025, '5', 0, 0), + ('non-pi-242', '3310', 'F201', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-204', 'AC1', 'REG', 'X1', 'POS2', '3300', 1, 1, 0.1, '2024-11-15', 'S', 2025, '5', 0, 0), + ('pi-243', '3310', 'F201', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-204', 'AC1', 'REG', 'PI1', 'POS1', '4000', 1, 1, 0.1, '2024-11-15', 'S', 2025, '5', 0, 0), + ('pi-241', '3310', 'F201', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-204', 'AC1', 'REG', 'PI1', 'POS1', '1234', 1, 1, 0.1, '2024-11-15', 'S', 2025, '5', 0, 0), + ('pi-no-line', '3310', 'F201', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-204', 'AC1', 'REG', 'PI1', 'POS1', '9999', 1, 1, 0.1, '2024-11-15', 'S', 2025, '5', 0, 0), + ('pi-no-title', '3310', 'F201', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-204', 'AC1', 'REG', 'PI1', 'POS1', '0000', 1, 1, 0.1, '2024-11-15', 'S', 2025, '5', 0, 0); + """); + + var rows = (await connection.QueryAsync( + """ + SELECT [TransactionId], [ExpenseSfn], [FteSfn] + FROM [data].[v_TransactionSfn] + WHERE [Source] = N'UCPath' + """)).ToList(); + + rows.Should().HaveCount(7); + var byId = rows.ToDictionary(row => row.TransactionId); + byId["pi-242"].FteSfn.Should().Be("241"); + byId["pi-242-fringe"].FteSfn.Should().Be("241"); + byId["non-pi-242"].FteSfn.Should().Be("242"); + byId["pi-243"].FteSfn.Should().Be("243"); + byId["pi-241"].FteSfn.Should().Be("241"); + byId["pi-no-line"].FteSfn.Should().BeNull(); + byId["pi-no-title"].FteSfn.Should().BeNull(); + } + private async Task SeedReferenceDataAsync() { await using var connection = new SqlConnection(fixture.ConnectionString); From 2e6f5aa6f99f6777f12dc9b60ab65552a9e86c26 Mon Sep 17 00:00:00 2001 From: Rob Martinsen Date: Fri, 13 Nov 2026 12:21:51 -0500 Subject: [PATCH 2/5] Add PI FTE adjustments report endpoint GET /api/autoassociations/pi-fte-adjustments lists expense summary rows on FTE line 241 whose title's staff type line is 242, grouped by employee and job code. Review only. Co-Authored-By: Claude Fable 5.2 --- .../AutoAssociationReportService.cs | 30 ++++++++++++ .../IAutoAssociationReportService.cs | 1 + .../Controllers/AutoAssociationsController.cs | 4 ++ .../AutoAssociations/AutoAssociationDtos.cs | 2 + ...ciationReportServiceSqlIntegrationTests.cs | 49 +++++++++++++++++++ .../AutoAssociationsControllerTests.cs | 7 +++ 6 files changed, 93 insertions(+) diff --git a/server/AutoAssociations/AutoAssociationReportService.cs b/server/AutoAssociations/AutoAssociationReportService.cs index 417d90b0..62ba9785 100644 --- a/server/AutoAssociations/AutoAssociationReportService.cs +++ b/server/AutoAssociations/AutoAssociationReportService.cs @@ -289,6 +289,36 @@ ORDER BY SUM([Fte]) DESC, [EmployeeId] return rows.ToList(); } + // PI payroll that v_TransactionSfn moved from FTE line 242 to 241. The + // summary stores only the adjusted line, so a moved row is one on 241 + // whose title's staff type line is 242; the PI rule is the only way that + // happens. Review only. + public async Task> GetPiFteAdjustmentsAsync(CancellationToken cancellationToken) + { + await using var connection = await OpenAsync(cancellationToken); + // Column order matches the record's constructor; Dapper maps by position. + var rows = await connection.QueryAsync(Command( + """ + SELECT + e.[EmployeeId], + MAX(e.[EmployeeName]) AS [EmployeeName], + e.[JobCode], + MAX(ti.[Name]) AS [TitleName], + st.[FteSfn] AS [TitleFteSfn], + e.[FteSfn], + SUM(e.[Expenses]) AS [Expenses], + SUM(e.[Fte]) AS [Fte], + COUNT(*) AS [RowCount] + FROM [data].[ExpenseSummary] e + JOIN [data].[Titles] ti ON ti.[TitleCode] = e.[JobCode] + JOIN [data].[StaffTypes] st ON st.[StaffTypeCode] = ti.[StaffTypeCode] + WHERE e.[FteSfn] = '241' AND st.[FteSfn] = '242' + GROUP BY e.[EmployeeId], e.[JobCode], st.[FteSfn], e.[FteSfn] + ORDER BY MAX(e.[EmployeeName]), e.[EmployeeId], e.[JobCode] + """, cancellationToken)); + return rows.ToList(); + } + public async Task> GetPreAssociationTotalsAsync(CancellationToken cancellationToken) { await using var connection = await OpenAsync(cancellationToken); diff --git a/server/AutoAssociations/IAutoAssociationReportService.cs b/server/AutoAssociations/IAutoAssociationReportService.cs index 99b80cfc..6ac1a5cc 100644 --- a/server/AutoAssociations/IAutoAssociationReportService.cs +++ b/server/AutoAssociations/IAutoAssociationReportService.cs @@ -10,5 +10,6 @@ public interface IAutoAssociationReportService Task GetRule220Async(CancellationToken cancellationToken); Task> GetExcludedProjectsAsync(CancellationToken cancellationToken); Task> GetFteOverOneAsync(CancellationToken cancellationToken); + Task> GetPiFteAdjustmentsAsync(CancellationToken cancellationToken); Task> GetPreAssociationTotalsAsync(CancellationToken cancellationToken); } diff --git a/server/Controllers/AutoAssociationsController.cs b/server/Controllers/AutoAssociationsController.cs index 85a6f0c2..1b283543 100644 --- a/server/Controllers/AutoAssociationsController.cs +++ b/server/Controllers/AutoAssociationsController.cs @@ -36,6 +36,10 @@ public Task ExcludedProjects(CancellationToken cancellationToken) public Task FteOverOne(CancellationToken cancellationToken) => ReportAsync(reports.GetFteOverOneAsync, cancellationToken); + [HttpGet("pi-fte-adjustments")] + public Task PiFteAdjustments(CancellationToken cancellationToken) => + ReportAsync(reports.GetPiFteAdjustmentsAsync, cancellationToken); + [HttpGet("pre-association-totals")] public Task PreAssociationTotals(CancellationToken cancellationToken) => ReportAsync(reports.GetPreAssociationTotalsAsync, cancellationToken); diff --git a/server/Models/AutoAssociations/AutoAssociationDtos.cs b/server/Models/AutoAssociations/AutoAssociationDtos.cs index d622a9b0..d9d3b75c 100644 --- a/server/Models/AutoAssociations/AutoAssociationDtos.cs +++ b/server/Models/AutoAssociations/AutoAssociationDtos.cs @@ -4,6 +4,8 @@ public sealed record AutoAssociationReportResponse(string FiscalYear, DateOnl public sealed record AutoAssociationBuildDto(int BuildId, DateOnly CycleStart, DateOnly CycleEnd, DateTimeOffset BuiltAt, int SummaryRows, int AssociationRows, int ExcludedProjects, int Misclassified204Rows); public sealed record ExcludedProjectDto(string AccessionNumber, string NifaProjectNumber, string? Title, string? ProjectDirector, string? AeProjects, decimal Total); public sealed record FteOverOneDto(string EmployeeId, string? EmployeeName, decimal Fte, int RowCount); +/// PI payroll the FTE line rule moved: TitleFteSfn is the line the title gives (242), FteSfn the line it reports on (241). +public sealed record PiFteAdjustmentDto(string EmployeeId, string? EmployeeName, string JobCode, string? TitleName, string TitleFteSfn, string FteSfn, decimal Expenses, decimal Fte, int RowCount); public sealed record PreAssociationTotalDto(string OrgR, string? FinancialDepartment, string? FinancialDepartmentName, string? ExpenseSfn, string? SfnLabel, decimal Expenses, decimal Fte); public sealed record AssociatedProjectDto(string AccessionNumber, string NifaProjectNumber, string? Title, string? ProjectDirector, string? AeProjects, decimal Expenses, decimal Fte); /// Reason is one of: Misclassified204, ProjectExcluded, NoRuleMatched, NoEmployee, NoProject, NoFteLine, NoAeProject. diff --git a/tests/server.tests/AutoAssociations/AutoAssociationReportServiceSqlIntegrationTests.cs b/tests/server.tests/AutoAssociations/AutoAssociationReportServiceSqlIntegrationTests.cs index 11db38be..4a413295 100644 --- a/tests/server.tests/AutoAssociations/AutoAssociationReportServiceSqlIntegrationTests.cs +++ b/tests/server.tests/AutoAssociations/AutoAssociationReportServiceSqlIntegrationTests.cs @@ -3,6 +3,7 @@ using Microsoft.Data.SqlClient; using Microsoft.Extensions.Configuration; using Server.AutoAssociations; +using Server.Models.AutoAssociations; using Server.Tests.SqlIntegration; namespace Server.Tests.AutoAssociations; @@ -66,6 +67,54 @@ public async Task Fte_over_one_lists_employees_whose_summary_fte_exceeds_one() row.RowCount.Should().Be(3); } + [Fact] + public async Task Pi_fte_adjustments_is_empty_when_no_pi_sits_on_line_242() + { + await fixture.ClearDataTablesAsync(); + await SeedAndBuildAsync(); + + var rows = await CreateService().GetPiFteAdjustmentsAsync(CancellationToken.None); + + rows.Should().BeEmpty(); + } + + [Fact] + public async Task Pi_fte_adjustments_lists_pi_payroll_moved_from_242_by_employee_and_job_code() + { + await fixture.ClearDataTablesAsync(); + await SeedAndBuildAsync(); + + await using var connection = new SqlConnection(fixture.ConnectionString); + await connection.OpenAsync(); + await connection.ExecuteAsync( + """ + INSERT INTO [data].[StaffTypes] ([StaffTypeCode], [FteSfn], [Description]) VALUES ('SUPP', '242', 'Professional Support'); + INSERT INTO [data].[Titles] ([TitleCode], [StaffTypeCode], [Name]) + VALUES ('3300', 'SUPP', 'Specialist'), ('3310', 'SUPP', 'Associate Specialist'); + + INSERT INTO [data].[UcPathTransactions] + ([LaborTransactionId], [Entity], [Fund], [FinancialDepartment], [ParentDepartment], [Account], + [Purpose], [Program], [Project], [Activity], [ErnCode], [EmployeeId], [EmployeeName], [PositionNumber], [JobCode], + [Hours], [Amount], [CalculatedFte], [PayPeriodEndDate], [FringeBenefitSalaryCd], + [FiscalYear], [Period], [EmpRcd], [EffSeq], [ExcludedByDate], [AccountNotInAE]) + VALUES + ('ucp-13u02-e2-3300', '3310', '13U02', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-C', 'AC1', 'REG', 'E2', 'PI Two', 'POS2', '3300', 10, 100, 0.100000, '2024-11-15', 'S', 2025, '5', 0, 0, 0, 0), + ('ucp-201-e2-3300', '3310', 'F201', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-C', 'AC1', 'REG', 'E2', 'PI Two', 'POS2', '3300', 10, 40, 0.040000, '2024-11-15', 'S', 2025, '5', 0, 0, 0, 0), + ('ucp-201-e2-3310', '3310', 'F201', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-C', 'AC1', 'REG', 'E2', 'PI Two', 'POS2', '3310', 10, 25, 0.025000, '2024-11-15', 'S', 2025, '5', 0, 0, 0, 0), + ('ucp-13u02-e8-3300', '3310', '13U02', 'D1', 'D1', 'A1', 'P1', NULL, 'AE-C', 'AC1', 'REG', 'E8', 'Not A PI', 'POS8', '3300', 10, 70, 0.070000, '2024-11-15', 'S', 2025, '5', 0, 0, 0, 0); + EXEC [data].[BuildAutoAssociations] @cycleStart, @cycleEnd; + """, + new { cycleStart = CycleStart, cycleEnd = CycleEnd }); + + var rows = await CreateService().GetPiFteAdjustmentsAsync(CancellationToken.None); + + // E2's two 3300 summary rows (13U02 and F201) collapse to one line. E2's + // own 1234 payroll is on a 241 title, E1 is on 241 and E8 is not a PI. + rows.Should().Equal( + new PiFteAdjustmentDto("E2", "PI Two", "3300", "Specialist", "242", "241", 140m, 0.140000m, 2), + new PiFteAdjustmentDto("E2", "PI Two", "3310", "Associate Specialist", "242", "241", 25m, 0.025000m, 1)); + } + [Fact] public async Task Pre_association_totals_group_by_orgr_department_and_sfn() { diff --git a/tests/server.tests/AutoAssociations/AutoAssociationsControllerTests.cs b/tests/server.tests/AutoAssociations/AutoAssociationsControllerTests.cs index 70caed96..3692a4f9 100644 --- a/tests/server.tests/AutoAssociations/AutoAssociationsControllerTests.cs +++ b/tests/server.tests/AutoAssociations/AutoAssociationsControllerTests.cs @@ -22,6 +22,7 @@ public async Task Every_report_conflicts_when_no_confirmed_workflow_cycle_exists (await controller.Rule220(CancellationToken.None)).Should().BeOfType(); (await controller.ExcludedProjects(CancellationToken.None)).Should().BeOfType(); (await controller.FteOverOne(CancellationToken.None)).Should().BeOfType(); + (await controller.PiFteAdjustments(CancellationToken.None)).Should().BeOfType(); (await controller.PreAssociationTotals(CancellationToken.None)).Should().BeOfType(); service.Calls.Should().Be(0); } @@ -93,6 +94,12 @@ public Task> GetFteOverOneAsync(CancellationToken c return Task.FromResult>([]); } + public Task> GetPiFteAdjustmentsAsync(CancellationToken cancellationToken) + { + Calls++; + return Task.FromResult>([]); + } + public Task> GetPreAssociationTotalsAsync(CancellationToken cancellationToken) { Calls++; From 12da484da795ec85f61ccc7ccd7ad3f1405798c8 Mon Sep 17 00:00:00 2001 From: Rob Martinsen Date: Fri, 13 Nov 2026 12:23:16 -0500 Subject: [PATCH 3/5] Add PI FTE to 241 tab to Auto-Associations A review only tab after FTE over 1.0 lists the PI payroll reported on FTE line 241 instead of 242, by employee and job code, with CSV export. Co-Authored-By: Claude Fable 5.2 --- .../AutoAssociationsStage.tsx | 3 ++ .../autoAssociations/PiFteAdjustmentsTab.tsx | 47 +++++++++++++++++++ .../autoAssociations/autoAssociationsTabs.ts | 6 +++ client/src/queries/autoAssociations.ts | 21 +++++++++ .../autoAssociationsTabs.test.ts | 1 + .../(authenticated)/autoAssociations.test.tsx | 40 ++++++++++++++++ 6 files changed, 118 insertions(+) create mode 100644 client/src/components/autoAssociations/PiFteAdjustmentsTab.tsx diff --git a/client/src/components/autoAssociations/AutoAssociationsStage.tsx b/client/src/components/autoAssociations/AutoAssociationsStage.tsx index f350e063..ed66d8c0 100644 --- a/client/src/components/autoAssociations/AutoAssociationsStage.tsx +++ b/client/src/components/autoAssociations/AutoAssociationsStage.tsx @@ -6,6 +6,7 @@ import { } from './autoAssociationsTabs.ts'; import { ExcludedProjectsTab } from './ExcludedProjectsTab.tsx'; import { FteOverOneTab } from './FteOverOneTab.tsx'; +import { PiFteAdjustmentsTab } from './PiFteAdjustmentsTab.tsx'; import { PreAssociationTotalsTab } from './PreAssociationTotalsTab.tsx'; import { Rule20xTab } from './Rule20xTab.tsx'; import { Rule204Tab } from './Rule204Tab.tsx'; @@ -106,6 +107,8 @@ export function AutoAssociationsStage({ status }: { status: WorkflowStageStatus ) : activeId === 'fte' ? ( + ) : activeId === 'pi-fte' ? ( + ) : activeId === 'totals' ? ( ) : ( diff --git a/client/src/components/autoAssociations/PiFteAdjustmentsTab.tsx b/client/src/components/autoAssociations/PiFteAdjustmentsTab.tsx new file mode 100644 index 00000000..f626a45f --- /dev/null +++ b/client/src/components/autoAssociations/PiFteAdjustmentsTab.tsx @@ -0,0 +1,47 @@ +import { amountColumn, fteColumn, LoadState, ReportSection } from './reportTables.tsx'; +import type { CsvColumn } from '@/lib/csv.ts'; +import { type PiFteAdjustment, piFteAdjustmentsQueryOptions } from '@/queries/autoAssociations.ts'; +import { useQuery } from '@tanstack/react-query'; +import type { ColumnDef } from '@tanstack/react-table'; + +const piFteAdjustmentColumns: ColumnDef[] = [ + { accessorKey: 'employeeId', header: 'Employee ID' }, + { accessorKey: 'employeeName', header: 'Employee' }, + { accessorKey: 'jobCode', header: 'Job code' }, + { accessorKey: 'titleName', header: 'Title' }, + { accessorKey: 'titleFteSfn', header: 'Was' }, + { accessorKey: 'fteSfn', header: 'Now' }, + amountColumn('Expenses', 'expenses'), + fteColumn('FTE', 'fte'), + { accessorKey: 'rowCount', header: 'Rows', meta: { cellClassName: 'text-right', headerClassName: 'text-right' } }, +]; + +const piFteAdjustmentCsv: CsvColumn[] = [ + { header: 'Employee ID', key: 'employeeId' }, + { header: 'Employee', key: 'employeeName' }, + { header: 'Job code', key: 'jobCode' }, + { header: 'Title', key: 'titleName' }, + { header: 'Was', key: 'titleFteSfn' }, + { header: 'Now', key: 'fteSfn' }, + { format: 'currency', header: 'Expenses', key: 'expenses' }, + { header: 'FTE', key: 'fte' }, + { header: 'Rows', key: 'rowCount' }, +]; + +export function PiFteAdjustmentsTab() { + const { data, error, isError, isLoading } = useQuery(piFteAdjustmentsQueryOptions()); + if (isLoading || isError || !data) { + return ; + } + return ( +
+ +
+ ); +} diff --git a/client/src/components/autoAssociations/autoAssociationsTabs.ts b/client/src/components/autoAssociations/autoAssociationsTabs.ts index a6b94311..13cfb906 100644 --- a/client/src/components/autoAssociations/autoAssociationsTabs.ts +++ b/client/src/components/autoAssociations/autoAssociationsTabs.ts @@ -8,6 +8,7 @@ export type AutoAssociationsTabId = | 'rule-220' | 'excluded' | 'fte' + | 'pi-fte' | 'totals' | 'job-codes'; @@ -57,6 +58,11 @@ export const AUTO_ASSOCIATIONS_TABS: AutoAssociationsTab[] = [ label: 'FTE over 1.0', note: 'Employees whose included payroll FTE adds up to more than 1.0. Review only.', }, + { + id: 'pi-fte', + label: 'PI FTE to 241', + note: 'PIs whose title puts their payroll on FTE line 242 (Professional Support). It is reported on 241 (Scientist) instead, so their State Appropriations (13U02) payroll is prorated across their projects. Review only.', + }, { id: 'totals', label: 'Pre-association totals', diff --git a/client/src/queries/autoAssociations.ts b/client/src/queries/autoAssociations.ts index 6356b2b9..3d8b5aed 100644 --- a/client/src/queries/autoAssociations.ts +++ b/client/src/queries/autoAssociations.ts @@ -102,6 +102,20 @@ export interface FteOverOne { rowCount: number; } +// PI payroll the FTE line rule moved: titleFteSfn is the line the title gives +// (242), fteSfn the line it reports on (241). +export interface PiFteAdjustment { + employeeId: string; + employeeName: string | null; + expenses: number; + fte: number; + fteSfn: string; + jobCode: string; + rowCount: number; + titleFteSfn: string; + titleName: string | null; +} + export interface PreAssociationTotal { expenses: number; expenseSfn: string | null; @@ -135,6 +149,7 @@ export const AUTO_ASSOCIATIONS_KEYS = { excluded: ['autoAssociations', 'excluded'] as const, fte: ['autoAssociations', 'fte'] as const, jobCodes: ['autoAssociations', 'jobCodes'] as const, + piFte: ['autoAssociations', 'piFte'] as const, rule204: ['autoAssociations', 'rule204'] as const, rule20x: ['autoAssociations', 'rule20x'] as const, rule220: ['autoAssociations', 'rule220'] as const, @@ -179,6 +194,12 @@ export const fteOverOneQueryOptions = () => queryKey: AUTO_ASSOCIATIONS_KEYS.fte, }); +export const piFteAdjustmentsQueryOptions = () => + queryOptions({ + queryFn: () => report('/api/autoassociations/pi-fte-adjustments'), + queryKey: AUTO_ASSOCIATIONS_KEYS.piFte, + }); + export const preAssociationTotalsQueryOptions = () => queryOptions({ queryFn: () => report('/api/autoassociations/pre-association-totals'), diff --git a/client/src/test/components/autoAssociations/autoAssociationsTabs.test.ts b/client/src/test/components/autoAssociations/autoAssociationsTabs.test.ts index 36136f1c..4908c70e 100644 --- a/client/src/test/components/autoAssociations/autoAssociationsTabs.test.ts +++ b/client/src/test/components/autoAssociations/autoAssociationsTabs.test.ts @@ -16,6 +16,7 @@ describe('autoAssociationsTabs', () => { 'rule-220', 'excluded', 'fte', + 'pi-fte', 'totals', 'job-codes', ]); diff --git a/client/src/test/routes/(authenticated)/autoAssociations.test.tsx b/client/src/test/routes/(authenticated)/autoAssociations.test.tsx index 8fea592f..4f8dc486 100644 --- a/client/src/test/routes/(authenticated)/autoAssociations.test.tsx +++ b/client/src/test/routes/(authenticated)/autoAssociations.test.tsx @@ -206,6 +206,23 @@ function mockApi(options: { completeFails?: boolean; failingReport?: boolean; ha envelope([{ employeeId: 'E1', employeeName: 'PI One', fte: 1.3, rowCount: 3 }]) ) ), + http.get('/api/autoassociations/pi-fte-adjustments', () => + HttpResponse.json( + envelope([ + { + employeeId: 'E2', + employeeName: 'PI Two', + expenses: 140, + fte: 0.14, + fteSfn: '241', + jobCode: '3300', + rowCount: 2, + titleFteSfn: '242', + titleName: 'Specialist', + }, + ]) + ) + ), http.get('/api/autoassociations/pre-association-totals', () => HttpResponse.json( envelope([ @@ -364,6 +381,12 @@ describe('Auto-Associations stage', () => { await user.click(screen.getByRole('tab', { name: 'FTE over 1.0' })); expect(await screen.findByText('1.300')).toBeInTheDocument(); + await user.click(screen.getByRole('tab', { name: 'PI FTE to 241' })); + expect(await screen.findByText('Specialist')).toBeInTheDocument(); + expect(screen.getByText('3300')).toBeInTheDocument(); + expect(screen.getByText('242')).toBeInTheDocument(); + expect(screen.getByText('$140.00')).toBeInTheDocument(); + await user.click(screen.getByRole('tab', { name: 'Pre-association totals' })); expect(await screen.findByText('Dept One')).toBeInTheDocument(); @@ -374,6 +397,23 @@ describe('Auto-Associations stage', () => { } }); + it('shows an empty PI FTE table when nobody moved', async () => { + mockApi({ hasBuild: true }); + server.use( + http.get('/api/autoassociations/pi-fte-adjustments', () => HttpResponse.json(envelope([]))) + ); + const user = userEvent.setup(); + const { cleanup } = renderRoute({ initialPath: '/workflow/auto-associations' }); + + try { + await user.click(await screen.findByRole('tab', { name: 'PI FTE to 241' })); + expect(await screen.findByRole('heading', { name: 'PI payroll moved to line 241' })).toBeInTheDocument(); + expect(screen.queryByRole('alert')).not.toBeInTheDocument(); + } finally { + cleanup(); + } + }); + it('starts each SFN tab on its first page', async () => { mockApi({ hasBuild: true }); // 201 fills more than one page of PIs; 202 has a single PI. From 30867b392d385498e03884cf7b75ddec4be0af07 Mon Sep 17 00:00:00 2001 From: Rob Martinsen Date: Fri, 13 Nov 2026 12:33:17 -0500 Subject: [PATCH 4/5] Make the PI FTE tab note match what the list covers The list shows a PI's 242 payroll on every fund, so the note no longer says all of it is prorated. Also state the reference data assumption in the report query comment. Co-Authored-By: Claude Fable 5.2 --- .../src/components/autoAssociations/autoAssociationsTabs.ts | 2 +- .../src/test/routes/(authenticated)/autoAssociations.test.tsx | 4 ++++ server/AutoAssociations/AutoAssociationReportService.cs | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/client/src/components/autoAssociations/autoAssociationsTabs.ts b/client/src/components/autoAssociations/autoAssociationsTabs.ts index 13cfb906..2815ba0a 100644 --- a/client/src/components/autoAssociations/autoAssociationsTabs.ts +++ b/client/src/components/autoAssociations/autoAssociationsTabs.ts @@ -61,7 +61,7 @@ export const AUTO_ASSOCIATIONS_TABS: AutoAssociationsTab[] = [ { id: 'pi-fte', label: 'PI FTE to 241', - note: 'PIs whose title puts their payroll on FTE line 242 (Professional Support). It is reported on 241 (Scientist) instead, so their State Appropriations (13U02) payroll is prorated across their projects. Review only.', + note: 'PIs whose title puts their payroll on FTE line 242 (Professional Support). It is reported on 241 (Scientist) instead. Any State Appropriations (13U02) payroll they have can then be prorated across their projects. Review only.', }, { id: 'totals', diff --git a/client/src/test/routes/(authenticated)/autoAssociations.test.tsx b/client/src/test/routes/(authenticated)/autoAssociations.test.tsx index 4f8dc486..6b378ef6 100644 --- a/client/src/test/routes/(authenticated)/autoAssociations.test.tsx +++ b/client/src/test/routes/(authenticated)/autoAssociations.test.tsx @@ -383,6 +383,10 @@ describe('Auto-Associations stage', () => { await user.click(screen.getByRole('tab', { name: 'PI FTE to 241' })); expect(await screen.findByText('Specialist')).toBeInTheDocument(); + // The list covers every fund, so the note must not promise proration for all of it. + expect(screen.getByRole('note')).toHaveTextContent( + 'Any State Appropriations (13U02) payroll they have can then be prorated across their projects.' + ); expect(screen.getByText('3300')).toBeInTheDocument(); expect(screen.getByText('242')).toBeInTheDocument(); expect(screen.getByText('$140.00')).toBeInTheDocument(); diff --git a/server/AutoAssociations/AutoAssociationReportService.cs b/server/AutoAssociations/AutoAssociationReportService.cs index 62ba9785..45935b26 100644 --- a/server/AutoAssociations/AutoAssociationReportService.cs +++ b/server/AutoAssociations/AutoAssociationReportService.cs @@ -292,7 +292,8 @@ ORDER BY SUM([Fte]) DESC, [EmployeeId] // PI payroll that v_TransactionSfn moved from FTE line 242 to 241. The // summary stores only the adjusted line, so a moved row is one on 241 // whose title's staff type line is 242; the PI rule is the only way that - // happens. Review only. + // happens, as long as Titles and StaffTypes are unchanged since the + // build. Review only. public async Task> GetPiFteAdjustmentsAsync(CancellationToken cancellationToken) { await using var connection = await OpenAsync(cancellationToken); From 3638cc61c9b221fba382292ce472050d63fb8a72 Mon Sep 17 00:00:00 2001 From: Rob Martinsen Date: Wed, 18 Nov 2026 13:56:42 -0500 Subject: [PATCH 5/5] Narrow the PI FTE tab note to the payroll rule 220 prorates The note said any 13U02 payroll a listed PI has can be prorated. A second job on another FTE line is not prorated, and a PI whose only project is excluded has no project to prorate across. Co-Authored-By: Claude Fable 5.2 --- .../src/components/autoAssociations/autoAssociationsTabs.ts | 2 +- .../test/routes/(authenticated)/autoAssociations.test.tsx | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/client/src/components/autoAssociations/autoAssociationsTabs.ts b/client/src/components/autoAssociations/autoAssociationsTabs.ts index 2815ba0a..461181af 100644 --- a/client/src/components/autoAssociations/autoAssociationsTabs.ts +++ b/client/src/components/autoAssociations/autoAssociationsTabs.ts @@ -61,7 +61,7 @@ export const AUTO_ASSOCIATIONS_TABS: AutoAssociationsTab[] = [ { id: 'pi-fte', label: 'PI FTE to 241', - note: 'PIs whose title puts their payroll on FTE line 242 (Professional Support). It is reported on 241 (Scientist) instead. Any State Appropriations (13U02) payroll they have can then be prorated across their projects. Review only.', + note: "PIs whose title puts their payroll on FTE line 242 (Professional Support). It is reported on 241 (Scientist) instead. Rule 220 prorates the adjusted State Appropriations (13U02) payroll across the PI's eligible projects. Review only.", }, { id: 'totals', diff --git a/client/src/test/routes/(authenticated)/autoAssociations.test.tsx b/client/src/test/routes/(authenticated)/autoAssociations.test.tsx index 6b378ef6..71a148b5 100644 --- a/client/src/test/routes/(authenticated)/autoAssociations.test.tsx +++ b/client/src/test/routes/(authenticated)/autoAssociations.test.tsx @@ -383,9 +383,10 @@ describe('Auto-Associations stage', () => { await user.click(screen.getByRole('tab', { name: 'PI FTE to 241' })); expect(await screen.findByText('Specialist')).toBeInTheDocument(); - // The list covers every fund, so the note must not promise proration for all of it. + // The list covers every fund and PIs with no eligible project, so the note + // must only promise proration for the adjusted 13U02 payroll. expect(screen.getByRole('note')).toHaveTextContent( - 'Any State Appropriations (13U02) payroll they have can then be prorated across their projects.' + "Rule 220 prorates the adjusted State Appropriations (13U02) payroll across the PI's eligible projects." ); expect(screen.getByText('3300')).toBeInTheDocument(); expect(screen.getByText('242')).toBeInTheDocument();