Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -106,6 +107,8 @@ export function AutoAssociationsStage({ status }: { status: WorkflowStageStatus
<ExcludedProjectsTab />
) : activeId === 'fte' ? (
<FteOverOneTab />
) : activeId === 'pi-fte' ? (
<PiFteAdjustmentsTab />
) : activeId === 'totals' ? (
<PreAssociationTotalsTab />
) : (
Expand Down
47 changes: 47 additions & 0 deletions client/src/components/autoAssociations/PiFteAdjustmentsTab.tsx
Original file line number Diff line number Diff line change
@@ -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<PiFteAdjustment>[] = [
{ 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<PiFteAdjustment>('Expenses', 'expenses'),
fteColumn<PiFteAdjustment>('FTE', 'fte'),
{ accessorKey: 'rowCount', header: 'Rows', meta: { cellClassName: 'text-right', headerClassName: 'text-right' } },
];

const piFteAdjustmentCsv: CsvColumn<PiFteAdjustment>[] = [
{ 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 <LoadState error={error} isError={isError} isLoading={isLoading} label="the PI FTE report" />;
}
return (
<div className="space-y-6">
<ReportSection
columns={piFteAdjustmentColumns}
csv={piFteAdjustmentCsv}
data={data}
filename="auto-associations-pi-fte-adjustments.csv"
title="PI payroll moved to line 241"
/>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type AutoAssociationsTabId =
| 'rule-220'
| 'excluded'
| 'fte'
| 'pi-fte'
| 'totals'
| 'job-codes';

Expand Down Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions client/src/queries/autoAssociations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -179,6 +194,12 @@ export const fteOverOneQueryOptions = () =>
queryKey: AUTO_ASSOCIATIONS_KEYS.fte,
});

export const piFteAdjustmentsQueryOptions = () =>
queryOptions({
queryFn: () => report<PiFteAdjustment[]>('/api/autoassociations/pi-fte-adjustments'),
queryKey: AUTO_ASSOCIATIONS_KEYS.piFte,
});

export const preAssociationTotalsQueryOptions = () =>
queryOptions({
queryFn: () => report<PreAssociationTotal[]>('/api/autoassociations/pre-association-totals'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('autoAssociationsTabs', () => {
'rule-220',
'excluded',
'fte',
'pi-fte',
'totals',
'job-codes',
]);
Expand Down
45 changes: 45 additions & 0 deletions client/src/test/routes/(authenticated)/autoAssociations.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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();

Expand All @@ -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.
Expand Down
28 changes: 24 additions & 4 deletions database/data/Views/v_TransactionSfn.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand 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
Expand All @@ -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]
Expand All @@ -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];
31 changes: 31 additions & 0 deletions server/AutoAssociations/AutoAssociationReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IReadOnlyList<PiFteAdjustmentDto>> 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<PiFteAdjustmentDto>(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<IReadOnlyList<PreAssociationTotalDto>> GetPreAssociationTotalsAsync(CancellationToken cancellationToken)
{
await using var connection = await OpenAsync(cancellationToken);
Expand Down
1 change: 1 addition & 0 deletions server/AutoAssociations/IAutoAssociationReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface IAutoAssociationReportService
Task<Rule220ReportDto> GetRule220Async(CancellationToken cancellationToken);
Task<IReadOnlyList<ExcludedProjectDto>> GetExcludedProjectsAsync(CancellationToken cancellationToken);
Task<IReadOnlyList<FteOverOneDto>> GetFteOverOneAsync(CancellationToken cancellationToken);
Task<IReadOnlyList<PiFteAdjustmentDto>> GetPiFteAdjustmentsAsync(CancellationToken cancellationToken);
Task<IReadOnlyList<PreAssociationTotalDto>> GetPreAssociationTotalsAsync(CancellationToken cancellationToken);
}
4 changes: 4 additions & 0 deletions server/Controllers/AutoAssociationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public Task<IActionResult> ExcludedProjects(CancellationToken cancellationToken)
public Task<IActionResult> FteOverOne(CancellationToken cancellationToken) =>
ReportAsync(reports.GetFteOverOneAsync, cancellationToken);

[HttpGet("pi-fte-adjustments")]
public Task<IActionResult> PiFteAdjustments(CancellationToken cancellationToken) =>
ReportAsync(reports.GetPiFteAdjustmentsAsync, cancellationToken);

[HttpGet("pre-association-totals")]
public Task<IActionResult> PreAssociationTotals(CancellationToken cancellationToken) =>
ReportAsync(reports.GetPreAssociationTotalsAsync, cancellationToken);
Expand Down
4 changes: 3 additions & 1 deletion server/ExpenseReview/ExpenseReviewService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down
2 changes: 2 additions & 0 deletions server/Models/AutoAssociations/AutoAssociationDtos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public sealed record AutoAssociationReportResponse<T>(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);
/// <summary>PI payroll the FTE line rule moved: TitleFteSfn is the line the title gives (242), FteSfn the line it reports on (241).</summary>
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);
/// <summary>Reason is one of: Misclassified204, ProjectExcluded, NoRuleMatched, NoEmployee, NoProject, NoFteLine, NoAeProject.</summary>
Expand Down
Loading
Loading