Hi Carlos,
The budgeted cost is stored in the following table -> fin_financials , for respective investment objects, in combination with columns Primary_Object_Instance_Code & Secondary_Object_Instance_Code
When you are looking for a rolled up budgeted cost (i.e. Parent budgeted cost + Child(s) budgeted cost), you will need to consider all the hierarchy, that is self record for the parent and then individual records for the children, with respect to budgeted cost.
Hence, you will need to consider the inv_flat_hierarchies tables. You will need to reference this table , along with Fin_Financials, twice, once for the parent and once for the child.
Example:
Considering the following program, the parent is having the budget (self) -> 990,000 and the respective children as shown below:
Hence, for the DB we will need to get the above respective calculation for the Self and the child projects. You can refer to the following query, which respectively traverses the tables from parent as well as from child and finally adds the data to give the consolidated budget. You can explore similar options
select
inv_parent.code,
inv_parent.name,
(NVL(SUM(DISTINCT(fin.budget_cst_total)),0) + NVL(SUM(fin_second.budget_cst_total),0)) program_budgeted_cost
from fin_financials fin,
fin_financials fin_second,
inv_investments inv_parent,
inv_investments i_child,
odf_object_instance_mapping obj_parent,
odf_object_instance_mapping obj_child,
inv_flat_hierarchies flat
where obj_parent.primary_object_instance_code = 'project'
and obj_parent.secondary_object_instance_code = 'financials'
and inv_parent.id = obj_parent.primary_object_instance_id
and fin.id = obj_parent.secondary_object_instance_id
and flat.parent_id = inv_parent.id
and inv_parent.odf_object_code ='project'
and flat.parent_id != flat.child_id
and inv_parent.id = 5001080
and i_child.id = obj_child.primary_object_instance_id
and fin_second.id = obj_child.secondary_object_instance_id
and obj_child.primary_object_instance_code = 'project'
and obj_child.secondary_object_instance_code = 'financials'
and flat.child_id = i_child.id
group by inv_parent.code, inv_parent.name
Output:
Hope this helps.
Regards,
Samik