<?php

function department_department_cumulative_profit_loss_graph_display(&$pg1, $department_id, $from_month_display_order, $to_month_display_order)
{
    department_department_cumulative_profit_loss_graph_set_values($pg1, $department_id, $from_month_display_order, $to_month_display_order);

    $random_id = 'ddcplg_'.$department_id."_".$from_month_display_order."_".time();
    
    $pg1->axis_value_names_angle = -30;
    
    $data = array();
    $data['title'] = "Department Cumulative Profit & Loss";
    $data['x_axis_name'] = "Month";
    $data['y_axis_name'] = "Value";
    $data['graph1_name'] = "Profit";
    $data['graph2_name'] = "";
    $data['graph3_name'] = "";

    display_graph($pg1, $data, 1, $random_id);//line graph = 4
}

function department_department_cumulative_profit_loss_graph_set_values(&$pg1, $department_id, $from_month_display_order, $to_month_display_order) 
{
    $title = "";
    
        $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 ($pg1 != null) {
                $pg1->x[$i] = $name;
                
                $invoices = get_department_invoices_month_total($department_id, $month['display_order']);
                $expenses = get_department_expenses_month_total($department_id, $month['display_order']);                
                $overhead = get_department_overhead_month_total($expenses);            
                $profit +=  $invoices - ($expenses + $overhead);         
                $pg1->y[$i] = $profit;
//                $pg1->z[$i] = $invoices;
//                $pg1->z1[$i] = $profit;
                
                $pg1->colour_type[$i] = set_bar_colour_type($invoices);               
            }
            $i++;
        }
        return $title;
}

?>