<?php

function dashboard_asset_utility_expenses($from_month_display_order, $to_month_display_order, $expense_type_id=0) {
    
//    display_heading2('(Based on Goods Received Notes and Tax Free Item Costs)');    
    br();
    
    $month_ranges_array = dashboard_get_month_ranges_array($from_month_display_order, $to_month_display_order);
    $table_width = dashboard_calculate_table_width($month_ranges_array);
    
    start_table(TABLESTYLE, "width=$table_width%");
        
        $th = array("Asset");
            foreach ($month_ranges_array as $month) {
                $th[] = $month['month_name'];
            }
            $th[] = "Total";

            table_header($th);
            
            $from_month = get_month_by_display_order($from_month_display_order);
            $to_month = get_month_by_display_order($to_month_display_order);
            
            $from_date = $from_month['month_begin_date'];
            $to_date = $to_month['month_end_date'];
            
            $assets_res = dashboard_get_asset_utility_expense_assets($from_date, $to_date, $expense_type_id, -1, EC_ASSET_MAINTENANCE);
            
            $k = 0;
            
            
            while ($asset = db_fetch($assets_res)) {
                alt_table_row_color($k);

                $asset_id = $asset['asset_id'];
                $asset_name = get_asset_formatted_name($asset_id);
                label_cell($asset_name);
                
                foreach ($month_ranges_array as $month) {
                    
                    $from_date = $month['month_begin'];
                    $to_date = $month['month_end'];
//                    $expense_type_id = $exp['expense_type_id'];
//                    expc
//                    expi
//                    expt
                    $parameters = "expc=".EC_ASSET_MAINTENANCE."&expi=".$asset_id."&expt=".$expense_type_id."&from_date=$from_date&to_date=$to_date";
                    $total = dashboard_get_asset_period_utility_expense_type_total($from_date, $to_date, $expense_type_id, -1, EC_ASSET_MAINTENANCE, $asset_id);

                    if($total != 0){
                        $str_count = get_dashboard_view_str(DASH_SC_UTILITY_EXPENSES, $parameters, number_format($total,2));
                    }else{
//                        $str_count = number_format($total,2);
                        $str_count = "";
                    }
                    label_cell($str_count, 'align=right');
                }   
                
                label_cell(number_format($asset['grand_total'],2), 'align=right');
                end_row();
            }
        
                
            
    end_table(2);
}
