<?php

function project_project_cumulative_profit_loss_graph_display(&$pg0, $project_id, $from_month_display_order, $to_month_display_order)
{
    project_project_cumulative_profit_loss_graph_set_values($pg0, $project_id, $from_month_display_order, $to_month_display_order);

    $random_id = 'ppcplg_'.$project_id."_".$from_month_display_order."_".time();
    
    $pg0->axis_value_names_angle = -30;
    
    $data = array();
    $data['title'] = "Project Cumulative Profit & Loss";
    $data['x_axis_name'] = "Month";
    $data['y_axis_name'] = "Value";
    $data['graph1_name'] = "Profit";
    $data['graph2_name'] = "";
    $data['graph3_name'] = "";
    
    
    //echo "<a href='".$path_to_root."/admin/dashboard_uda_level_1.php?month_id=".$month_id."&division_code=UDA_0001&level=".$level."'>";
    display_graph($pg0, $data, 1, $random_id);//line graph = 4
//    source_graphic($today, $title, , $pg0, "Target", _("Achievement"), 1, $random_id, "Trend");
    //echo "</a>";
}

function project_project_cumulative_profit_loss_graph_set_values(&$pg0, $project_id, $from_month_display_order, $to_month_display_order) 
{
    $title = "";
    
    $project = get_project_record($project_id);
    
        $result = get_months_range_by_display_order($from_month_display_order, $to_month_display_order);
        $i = $profit = 0;
        while ($month = db_fetch($result)) {

            $name = $month["description"];
            if ($pg0 != null) {
                $pg0->x[$i] = $name;
                
                $invoices = get_project_income_month_total($project_id, $month['display_order']);
                $expenses = get_project_expenses_month_total($project_id, $month['display_order']);                
                $overhead = get_project_overhead_month_total($project, $expenses);            
                $profit +=  $invoices - ($expenses + $overhead);         
//                $profit = -2500000;
                $pg0->y[$i] = $profit;
//                $pg0->z[$i] = $invoices;
//                $pg0->z1[$i] = $profit;
                
                $pg0->colour_type[$i] = set_bar_colour_type($invoices);
                
            }
            
            
            $i++;
            
//            if($i == 1 && $myrow['achievement'] == null){
//                $title = "No data for ".$myrow['division_name'];
//            }
//            else{
//                $title = $myrow['division_name'];
//            }
        }

        return $title;

}





































































































