<?php

function dashboard_view_utility_expenses($from_date, $to_date, $expense_type_id, $project_id=-1, $expense_category_id=0, $expense_item_id=''){   
    global $expense_categories, $systypes_array;
    
    
        display_heading('Utility Expenses');
        br();
        
        if($expense_type_id > 0){
            $ut_etp = get_utility_expense_type($expense_type_id);
            display_heading($ut_etp['description']);
            br();
        }
        
        
        $expense_item_name = get_expense_category_expense_item_name($expense_category_id, $expense_item_id);
        display_heading($expense_item_name);
        br();
        
        
        
        start_table(TABLESTYLE, "width=90%");

            $th = array("Date", "Type", "#", "Project", "Bill No", "Bill Reference", "Expense Category", "Description", "Amount"); 
            
                table_header($th);
                
                    $k = $total_amount = $amount = 0;
                    $result = view_dashboard_utility_expenses_details($from_date, $to_date, $expense_type_id, $project_id, $expense_category_id, $expense_item_id);
                        while($row = db_fetch($result)) {
                            
                            alt_table_row_color($k);
                                label_cell(sql2date($row['date']),"align=center");
                                label_cell($systypes_array[$row['trans_type']],"align=center");
                                $str = get_journal_trans_view_str($row['trans_type'], $row['trans_no']);
                                label_cell($str, 'align=center');
                                
                                $project_name = get_project_formatted_name($row['project_id']);
                                label_cell($project_name);
                                label_cell($row['bill_no']);
                                label_cell($row['bill_reference']);
                                label_cell($expense_categories[$row["expense_category_id"]]);
                                label_cell($row['description']);
                                
                                $amount = $row['amount'];
                                amount_cell($amount);
                            end_row();

                            $total_amount += $amount;
                        }
                        
                        start_row();
                            label_cell(text_bold("Total"),"align=right colspan=8");
                            label_cell(text_bold(number_format($total_amount, 2)),"align=right"); 
                        end_row();
                
        end_table(2);
}


?>