feat(project-finance): enhance fixed cost calculations and parent task updates

- Updated SQL queries in ProjectFinanceController to aggregate fixed costs from current tasks and their descendants, improving financial accuracy.
- Introduced a new async thunk to update task fixed costs with recalculation, ensuring UI responsiveness and accurate parent task totals.
- Implemented recursive functions in the project finance slice to maintain accurate financial data for parent tasks based on subtasks.
- Enhanced the FinanceTable component to support these updates, ensuring totals reflect the latest calculations across task hierarchies.
This commit is contained in:
chamikaJ
2025-06-09 17:03:09 +05:30
parent e3e1b2dc14
commit e0a290c18f
4 changed files with 297 additions and 49 deletions

View File

@@ -174,7 +174,15 @@ export default class ProjectfinanceController extends WorklenzControllerBase {
tc.phase_id,
tc.assignees,
tc.billable,
tc.fixed_cost,
-- Fixed cost aggregation: include current task + all descendants
CASE
WHEN tc.level = 0 AND tc.sub_tasks_count > 0 THEN (
SELECT SUM(sub_tc.fixed_cost)
FROM task_costs sub_tc
WHERE sub_tc.root_id = tc.id
)
ELSE tc.fixed_cost
END as fixed_cost,
tc.sub_tasks_count,
-- For parent tasks, sum values from descendants only (exclude parent task itself)
CASE
@@ -688,7 +696,15 @@ export default class ProjectfinanceController extends WorklenzControllerBase {
tc.phase_id,
tc.assignees,
tc.billable,
tc.fixed_cost,
-- Fixed cost aggregation: include current task + all descendants
CASE
WHEN tc.level = 0 AND tc.sub_tasks_count > 0 THEN (
SELECT SUM(sub_tc.fixed_cost)
FROM task_costs sub_tc
WHERE sub_tc.root_id = tc.id
)
ELSE tc.fixed_cost
END as fixed_cost,
tc.sub_tasks_count,
-- For subtasks that have their own sub-subtasks, sum values from descendants only
CASE
@@ -932,7 +948,15 @@ export default class ProjectfinanceController extends WorklenzControllerBase {
tc.phase_id,
tc.assignees,
tc.billable,
tc.fixed_cost,
-- Fixed cost aggregation: include current task + all descendants
CASE
WHEN tc.level = 0 AND tc.sub_tasks_count > 0 THEN (
SELECT SUM(sub_tc.fixed_cost)
FROM task_costs sub_tc
WHERE sub_tc.root_id = tc.id
)
ELSE tc.fixed_cost
END as fixed_cost,
tc.sub_tasks_count,
-- For parent tasks, sum values from descendants only (exclude parent task itself)
CASE