<?php

function dashboard_asset_item_consumption($from_month_display_order, $to_month_display_order, $item_code='') {
    
    global $systypes_array;
//    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'];
            
            $item_codes_res = dashboard_get_asset_consumption_assets($from_date, $to_date, $item_code);
            
            $k = 0;
            
            $linked_field_type = IMLF_ASSET;            
            
            while ($asset = db_fetch($item_codes_res)) {
                alt_table_row_color($k);

//                $trans_type = $vehicle['trans_type'];
                $asset_id = $asset['asset_id'];
//                label_cell($systypes_array[$trans_type]);
                $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'];

//                    $parameters = "lftid=".$vehicle_id."&item=".$item_code."&from_date=$from_date&to_date=$to_date";
                    $parameters = "item=".$item_code."&from_date=$from_date&to_date=$to_date&lftid=$linked_field_type&lfid=$asset_id";
                    $total = dashboard_get_period_item_asset_consumption_total($from_date, $to_date, $asset_id, $item_code);

                    if($total != 0){
                        $str_count = get_dashboard_view_str(DASH_SC_INVENTORY_ITEM_CONSUMPTION, $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);
}
