Skip to content

Commit d1a5844

Browse files
committed
feat(finance-module): enhance rate card import logic for man day calculations
- Added functionality to convert hourly rates to man day rates during rate card import based on the selected calculation method. - Implemented conditional logic to handle existing man day rates and ensure accurate data mapping for job roles. - Updated the import process to maintain consistency in financial calculations across projects.
1 parent 8e8c1a7 commit d1a5844

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

worklenz-frontend/src/features/finance/ratecard-drawer/import-ratecards-drawer.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { insertProjectRateCardRoles } from '../project-finance-slice';
99
import { useParams } from 'react-router-dom';
1010
import { adminCenterApiService } from '@/api/admin-center/admin-center.api.service';
1111
import { IOrganization } from '@/types/admin-center/admin-center.types';
12+
import { hourlyRateToManDayRate } from '@/utils/man-days-utils';
1213

1314
const ImportRatecardsDrawer: React.FC = () => {
1415
const dispatch = useAppDispatch();
@@ -130,16 +131,42 @@ const ImportRatecardsDrawer: React.FC = () => {
130131
return;
131132
}
132133
if (drawerRatecard?.jobRolesList?.length) {
134+
const isProjectManDays = calculationMethod === 'man_days';
135+
const hoursPerDay = organization?.hours_per_day || 8;
133136
dispatch(
134137
insertProjectRateCardRoles({
135138
project_id: projectId,
136139
roles: drawerRatecard.jobRolesList
137140
.filter((role) => typeof role.rate !== 'undefined' && role.job_title_id)
138-
.map((role) => ({
139-
...role,
140-
job_title_id: role.job_title_id!,
141-
rate: Number(role.rate),
142-
})),
141+
.map((role) => {
142+
if (isProjectManDays) {
143+
// If the imported rate card is hourly, convert rate to man_day_rate
144+
if ((role.man_day_rate === undefined || role.man_day_rate === 0) && role.rate) {
145+
return {
146+
...role,
147+
job_title_id: role.job_title_id!,
148+
man_day_rate: hourlyRateToManDayRate(Number(role.rate), hoursPerDay),
149+
rate: 0,
150+
};
151+
} else {
152+
// Already has man_day_rate
153+
return {
154+
...role,
155+
job_title_id: role.job_title_id!,
156+
man_day_rate: Number(role.man_day_rate) || 0,
157+
rate: 0,
158+
};
159+
}
160+
} else {
161+
// Project is hourly, import as is
162+
return {
163+
...role,
164+
job_title_id: role.job_title_id!,
165+
rate: Number(role.rate) || 0,
166+
man_day_rate: Number(role.man_day_rate) || 0,
167+
};
168+
}
169+
}),
143170
})
144171
);
145172
}

0 commit comments

Comments
 (0)