# ad_return_complaint 1 [im_ad_hoc_query -format html $subtotals_sql]
# Get the list of all cost types. Do not check for enabled_p here.
set cost_type_list [util_memoize [list db_list cost_type_category_list "select category_id from im_categories where category_type='Intranet Cost Type'"]]
if {![info exists subtotals([im_cost_type_expense_planned])]}{ set subtotals([im_cost_type_expense_planned]) 0 }
if {![info exists subtotals([im_cost_type_timesheet_budget])]}{ set subtotals([im_cost_type_timesheet_budget]) 0 }
# Calculate the subtotals per cost type
# Roll up the category hierarchy
# Fraber 2023-03-22: Don't roll-up! The portlet shows all cost types separately.
# Don't!: Roll up the category hierarchy
db_foreach subtotals $subtotals_sql {
if {"" == $amount_converted}{ set amount_converted 0.0 }
set super_cost_type_ids [util_memoize [list db_list super_cats "select distinct category_id from (select $cost_type_id as category_id UNION select parent_id as category_id from im_category_hierarchy where child_id = $cost_type_id) t"]]
set super_cost_type_ids [util_memoize [list db_list super_cats "
select distinct category_id
from (select $cost_type_id as category_id
-- Do not include super-categories!
-- UNION select parent_id as category_id from im_category_hierarchy where child_id = $cost_type_id
) t
"]]
foreach id $super_cost_type_ids {
set subtotals($id)[expr$amount_converted + $subtotals($id)]