<?php




function monthly_sales_graph_display(&$pg, $company_code, $from_month_display_order, $to_month_display_order)
{
    monthly_sales_graph_set_values($pg, $company_code, $from_month_display_order, $to_month_display_order);

    $random_id = 'msgd_'.$company_code."_".$from_month_display_order."_".time();

    $pg->axis_value_names_angle = -30;
    
    $data = array();
    $data['title'] = "Monthly Direct Sales";
    $data['x_axis_name'] = "Months";
    $data['y_axis_name'] = "Rs.";
    $data['graph1_name'] = "Sales";
    $data['graph2_name'] = "Costs";
    $data['graph3_name'] = "Profit";
    
    
    //echo "<a href='".$path_to_root."/admin/dashboard_uda_level_1.php?month_id=".$month_id."&division_code=UDA_0001&level=".$level."'>";
    display_graph($pg, $data, 1, $random_id);
//    source_graphic($today, $title, , $pg, "Target", _("Achievement"), 1, $random_id, "Trend");
    //echo "</a>";
}


function monthly_sales_graph_set_values(&$pg, $group_company_code, $from_month_display_order, $to_month_display_order) 
{

        $company_codes_in = "''"; 
    
        $value_types_in = SCVT_SALES_INVOICES.",".SCVT_SALES_CREDIT_NOTES;
        
//        $result = get_group_company_all_list_values($group_company_code, 'DEPARTMENTS', "'Y'");
        
        $i = $sales_total = 0;
        
        $result = get_months_range_by_display_order($from_month_display_order, $to_month_display_order);
        while ($month = db_fetch($result)) {
//            if($department['id'] == 284){
//                $sss = 90;
//            }
            $name = $month["description"];
  
            $sales = get_summary_sales_value_total($month['id'], $value_types_in);
            
            $pg->x[$i] = $name;
            $pg->y[$i] = $sales['order_total'] - $sales['discounts_total'];
            $pg->z[$i] = $sales['costs_total'];
            $pg->z1[$i] = $sales['order_total'] - $sales['discounts_total'] - $sales['costs_total'];
                
//                $pg->y[$i] = $myrow['target'];
//                $pg->z1[$i] = $pg->z[$i]; // for trend calculation
            $pg->colour_type[$i] = set_bar_colour_type($sales_total);

            $i++;
        }
        

            
            
            


}

