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..461181af 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. Rule 220 prorates the adjusted State Appropriations (13U02) payroll across the PI's eligible 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..71a148b5 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,17 @@ 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();
+ // 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(
+ "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();
+ 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 +402,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.
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/AutoAssociations/AutoAssociationReportService.cs b/server/AutoAssociations/AutoAssociationReportService.cs
index 417d90b0..45935b26 100644
--- a/server/AutoAssociations/AutoAssociationReportService.cs
+++ b/server/AutoAssociations/AutoAssociationReportService.cs
@@ -289,6 +289,37 @@ 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, 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);
+ // 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/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/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++;
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);