-
Notifications
You must be signed in to change notification settings - Fork 9
3604 maintenence tracking spending on project overview #3638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
a646f11
60954c7
a6d160d
d404ea8
0e5d66f
309ee76
22f2487
2b97432
cf2047d
c8aa259
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,235 @@ | ||||||||||||||||||||||||||
| import React, { useMemo } from 'react'; | ||||||||||||||||||||||||||
| import { Box, Typography, Link, LinearProgress, Card, CardContent, Grid, Chip } from '@mui/material'; | ||||||||||||||||||||||||||
| import { DataGrid, GridColDef, GridRenderCellParams } from '@mui/x-data-grid'; | ||||||||||||||||||||||||||
| import { useAllReimbursementRequests } from '../../hooks/finance.hooks'; | ||||||||||||||||||||||||||
| import { useSingleProject } from '../../hooks/projects.hooks'; | ||||||||||||||||||||||||||
| import { WbsNumber, ReimbursementRequest, WBSElementData, equalsWbsNumber } from 'shared'; | ||||||||||||||||||||||||||
| import LoadingIndicator from '../../components/LoadingIndicator'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| interface ProjectSpendingHistoryProps { | ||||||||||||||||||||||||||
| wbsNum: WbsNumber; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const ProjectSpendingHistory: React.FC<ProjectSpendingHistoryProps> = ({ wbsNum }) => { | ||||||||||||||||||||||||||
| const { data: allReimbursementRequests, isLoading: rrLoading, isError: rrError } = useAllReimbursementRequests(); | ||||||||||||||||||||||||||
| const { data: project, isLoading: projectLoading } = useSingleProject(wbsNum); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const reimbursementRequests = useMemo(() => { | ||||||||||||||||||||||||||
| if (!allReimbursementRequests || !project) return []; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return allReimbursementRequests.filter((rr) => { | ||||||||||||||||||||||||||
| const hasProjectProduct = rr.reimbursementProducts.some((product) => { | ||||||||||||||||||||||||||
| const reason = product.reimbursementProductReason; | ||||||||||||||||||||||||||
| if ((reason as WBSElementData).wbsNum) { | ||||||||||||||||||||||||||
| return equalsWbsNumber((reason as WBSElementData).wbsNum, { ...wbsNum, workPackageNumber: 0 }); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| return equalsWbsNumber((reason as WBSElementData).wbsNum, { ...wbsNum, workPackageNumber: 0 }); | |
| const reasonWbs = (reason as WBSElementData).wbsNum; | |
| return ( | |
| reasonWbs.carNumber === wbsNum.carNumber && | |
| reasonWbs.projectNumber === wbsNum.projectNumber | |
| ); |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The project dependency in the useMemo is unnecessary since project is only used for a null check and doesn't affect the filtering logic. The filter only depends on allReimbursementRequests and wbsNum. Removing the project dependency would prevent unnecessary recalculation when project data changes but the reimbursement requests haven't changed.
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The status is taken from the first element in the reimbursementStatuses array (index 0), but this may not be the most recent status. The array order should be verified - if statuses are ordered chronologically (oldest first), this would show the oldest status instead of the current status. Consider either sorting by dateCreated DESC or using the last element of the array to get the most recent status.
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The total spent calculation includes all reimbursement requests regardless of their status. This means pending, denied, or cancelled reimbursement requests would also be counted as "spent" budget. The calculation should filter to only include reimbursements with statuses that represent actual spending (e.g., REIMBURSED, or possibly PENDING_FINANCE/SUBMITTED_TO_SABO if those should count as committed funds).
| const totalSpent = reimbursementRequests.reduce((sum, rr) => sum + (rr.totalCost || 0), 0); | |
| // Only count reimbursement requests that represent actual spending. | |
| // Currently we treat REIMBURSED as "spent". Other statuses can be added here if needed. | |
| const spendingStatuses = ['REIMBURSED']; | |
| const spentReimbursementRequests = reimbursementRequests.filter( | |
| (rr) => | |
| rr.reimbursementStatuses?.some((status) => spendingStatuses.includes(status.type)) ?? false | |
| ); | |
| const totalSpent = spentReimbursementRequests.reduce((sum, rr) => sum + (rr.totalCost || 0), 0); |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The valueFormatter assumes params.value is always a number, but if totalAmount is null or undefined, this will cause a runtime error when calling toFixed(2). Add a null check or provide a default value to handle cases where totalAmount might be missing.
| valueFormatter: (params) => `$${params.value.toFixed(2)}` | |
| valueFormatter: (params) => { | |
| if (params.value == null) { | |
| return '$0.00'; | |
| } | |
| const value = | |
| typeof params.value === 'number' ? params.value : Number(params.value); | |
| if (Number.isNaN(value)) { | |
| return '$0.00'; | |
| } | |
| return `$${value.toFixed(2)}`; | |
| } |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pageSize and rowsPerPageOptions props are deprecated in newer versions of MUI DataGrid (v5+). These should be moved into the initialState.pagination object. Use initialState.pagination.pageSize instead of the pageSize prop, and paginationModel.pageSize with onPaginationModelChange for rowsPerPageOptions.
| pageSize={25} | |
| rowsPerPageOptions={[10, 25, 50, 100]} | |
| initialState={{ | |
| pageSizeOptions={[10, 25, 50, 100]} | |
| initialState={{ | |
| pagination: { | |
| paginationModel: { pageSize: 25 } | |
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tab ordering logic is incorrect. Tab index 7 is mapped to PartsReviewPage but should be mapped to ProjectSpendingHistory based on the tab array order. The new Budget tab is at index 7 (8th position starting from 0), but the conditional checks tab === 7 and renders PartsReviewPage instead. The correct logic should check tab === 7 for ProjectSpendingHistory and tab === 6 should remain for PartsReviewPage. Currently, the Budget tab (index 7) will incorrectly show PartsReviewPage.