<?php

function dashboard_view_sales_pnl($from_date, $to_date, $entry_type_id, $type=-1) {   
    global $systypes_array;

    display_heading('Sales P&L');
        br();
        
        if ($entry_type_id > 0) {
            $entry_type_name = get_listvalue_name_by_id($entry_type_id);
            display_heading($entry_type_name);
            br();
        }
        
        start_table(TABLESTYLE, "width=80%");

            $th = array("Date", "Type", "#", "Reference", "Project", "Entry Type", "Amount"); 
            
                table_header($th);
                
                    $k = $total_amount = $amount = 0;
                    $result = view_dashboard_sales_pnl_details($from_date, $to_date, $entry_type_id, $type);
                        while($row = db_fetch($result)) {
                            
                            alt_table_row_color($k);
                                label_cell(sql2date($row['date']),"align=center");
                                label_cell($systypes_array[$row['trans_type']]);
                                $str = get_trans_view_str($row['trans_type'], $row['trans_no']);
                                label_cell($str, 'align=center');
                                label_cell($row['reference']);
                                
                                $project_name = get_project_formatted_name($row['project_id']);
                                label_cell($project_name);
                                label_cell($row['entry_type_name']);
                                
                                $amount = $row['amount'];
                                amount_cell($amount);
                            end_row();

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


?>