<?php session_start();
		if (isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
			include ('../scripts/classes.php'); if ($_SESSION['lang']=="EN"){include ('../lang/en.php');}elseif ($_SESSION['lang']=="GR"){include ('../lang/gr.php');}else {include ('../lang/en.php');}		
			include("../scripts/pchart/pChart/pData.class");
 			include("../scripts/pchart/pChart/pChart.class");	
			$mode=$lbl_business_analysis_area.": ".$lbl_sales;
			$page_title =$lbl_business_analytics; //Assign Page Title
			$array = getGlobalSettings(); foreach ($array as $settings){extract($settings);}
			$year = isset($_GET['selected_year']) ? $_GET['selected_year'] : @date("Y");
			$prev_year = $year-1;
			$graph_mode = $_GET['graph_mode'];
			if ($_GET['splot']=='toggle') {if(isset($_SESSION['plot']) && $_SESSION['plot'] == $lbl_show_labels){$_SESSION['plot'] = $lbl_hide_labels;}else{$_SESSION['plot'] = $lbl_show_labels;}}
			$plot = $_SESSION['plot'];
            ##get reported branch
            $selected_branch = $_GET['selected_branch'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title ?></title>
<link rel="shortcut icon" href="../img/favicon.png" />
<link href="../cms1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script>top.document.title=self.document.title;</script>
		<fieldset>
		<legend><?php echo $mode ?></legend>
		<div>
		<div class="completed">
		  <ul><li>
		          <form name="frmUpStat" action="reports_update.php" method="get" style="padding-top:10px;" >
                  <span class="pad-left-right-10"><?php echo $lbl_statistics_are_updated; ?></span>
			        <input type="hidden" value="monthly" name="rpt" />
                    <input type="submit" name="btnUpdate" value="<?php echo $lbl_update_statistics; ?>" class="button"/>
		          </form>
		  </li></ul>
	    </div>
        <div class="like-a-message">            
                <form name="frmBranch" action="reports_monthly.php?splot=<?php echo $plot ?>" method="get">
                <span class="pad-left-right-10"><?php echo _BRANCH_SELECTION;  ?></span>
                <input type="hidden" name="graph_mode" value="<?php echo $graph_mode ?>" />
                 <select name="selected_branch" id="selected_branch" class="addform_drop_1">
    			<?php
    				$sql_d = "SELECT id AS branch_code, branch_name FROM cls_branches ORDER BY branch_name ASC";   
    				$result_d = mysqli_query($mysqli, $sql_d) or die("Query failed : " . mysqli_error($mysqli));
    				if (mysqli_num_rows($result_d) == 0){
    					echo $error002;
    					}else{	
                            echo "<option ".(($_GET['selected_branch'] == '') ? "selected" : "")." value=''>-- "._ALL_BRANCHES." --</option>";
    						while ($line_2 = mysqli_fetch_array($result_d, MYSQLI_ASSOC)) {
    							echo "<option ".(($_GET['selected_branch'] == $line_2['branch_code']) ? "selected" : "")." value='".$line_2['branch_code']."'>".$line_2['branch_name']."</option>";
    					}
    				}   			          
    			?>
    			</select>
                <input type="submit" name="btnSubmit" value="<?php echo $lbl_view; ?>" class="button"/>  
		      </form>
         </div>
         </div>
		<div style="width:99%; padding-bottom:10px;float:left">
		<span style="padding-left:5px;"><font size="6"><?php echo (($selected_branch != '') ? $lbl_monthly_sales.' ('.getBranchName($selected_branch).')' : $lbl_monthly_sales) ?></font></span>
		</div>
		 <?php
 $DataSales = new pData;
      	$Requete2 = "SELECT bi_year AS years, 
					SUM(IF(bi_month = '1', 1, 0) * ROUND(sales_amount,0)) AS jan,
					SUM(IF(bi_month = '2', 1, 0) * ROUND(sales_amount,0)) AS feb,
					SUM(IF(bi_month = '3', 1, 0) * ROUND(sales_amount,0)) AS mar,
					SUM(IF(bi_month= '4', 1, 0) * ROUND(sales_amount,0)) AS apr,
					SUM(IF(bi_month = '5', 1, 0) * ROUND(sales_amount,0)) AS may,
					SUM(IF(bi_month = '6', 1, 0) * ROUND(sales_amount,0)) AS jun,
					SUM(IF(bi_month = '7', 1, 0) * ROUND(sales_amount,0)) AS jul,
					SUM(IF(bi_month = '8', 1, 0) * ROUND(sales_amount,0)) AS aug,
					SUM(IF(bi_month = '9', 1, 0) * ROUND(sales_amount,0)) AS sep,
					SUM(IF(bi_month = '10', 1, 0) * ROUND(sales_amount,0)) AS oct,
					SUM(IF(bi_month = '11', 1, 0) * ROUND(sales_amount,0)) AS nov,
					SUM(IF(bi_month = '12', 1, 0) * ROUND(sales_amount,0)) AS 'dec',
					SUM(ROUND(sales_amount,0)) AS year_totals
					FROM bi_sales
					WHERE bi_year='$year'
                    ".(($selected_branch != "") ? " AND branch_id ='".$selected_branch."'" : "")."
					GROUP BY years
		";				
    	$result2  = mysqli_query($mysqli, $Requete2)or die("Query failed : " . mysqli_error($mysqli));  
		while ($row = mysqli_fetch_array($result2))  
     	{
		$sales_jan_c=$row["jan"]; $sales_feb_c=$row["feb"]; $sales_mar_c=$row["mar"]; $sales_apr_c=$row["apr"]; $sales_may_c=$row["may"]; $sales_jun_c=$row["jun"];  			 		$sales_jul_c=$row["jul"]; $sales_aug_c=$row["aug"]; $sales_sep_c=$row["sep"]; $sales_oct_c=$row["oct"]; $sales_nov_c=$row["nov"]; $sales_dec_c=$row["dec"];
		if ($year==date('Y')){
			if ($row["jan"]> 0 || date("m")>=1) $DataSales->AddPoint($row["jan"], "Serie1"); 
			if ($row["feb"]> 0 || date("m")>=2) $DataSales->AddPoint($row["feb"], "Serie1");
			if ($row["mar"]> 0 || date("m")>=3) $DataSales->AddPoint($row["mar"], "Serie1");
			if ($row["apr"]> 0 || date("m")>=4) $DataSales->AddPoint($row["apr"], "Serie1");
			if ($row["may"]> 0 || date("m")>=5) $DataSales->AddPoint($row["may"], "Serie1");
			if ($row["jun"]> 0 || date("m")>=6) $DataSales->AddPoint($row["jun"], "Serie1");
			if ($row["jul"]> 0 || date("m")>=7) $DataSales->AddPoint($row["jul"], "Serie1");
			if ($row["aug"]> 0 || date("m")>=8) $DataSales->AddPoint($row["aug"], "Serie1");
			if ($row["sep"]> 0 || date("m")>=9) $DataSales->AddPoint($row["sep"], "Serie1");
			if ($row["oct"]> 0 || date("m")>=10)$DataSales->AddPoint($row["oct"], "Serie1");
			if ($row["nov"]> 0 || date("m")>=11)$DataSales->AddPoint($row["nov"], "Serie1");
			if ($row["dec"]> 0 || date("m")>=12)$DataSales->AddPoint($row["dec"], "Serie1");
		}else{
			$DataSales->AddPoint($row["jan"], "Serie1"); $DataSales->AddPoint($row["feb"], "Serie1"); $DataSales->AddPoint($row["mar"], "Serie1");
			$DataSales->AddPoint($row["apr"], "Serie1"); $DataSales->AddPoint($row["may"], "Serie1"); $DataSales->AddPoint($row["jun"], "Serie1");
			$DataSales->AddPoint($row["jul"], "Serie1"); $DataSales->AddPoint($row["aug"], "Serie1"); $DataSales->AddPoint($row["sep"], "Serie1");
			$DataSales->AddPoint($row["oct"], "Serie1"); $DataSales->AddPoint($row["nov"], "Serie1"); $DataSales->AddPoint($row["dec"], "Serie1");		
			}
		}		 	
		$DataSales->AddPoint(array($lbl_january, $lbl_february, $lbl_march, $lbl_april, $lbl_may, $lbl_june, $lbl_july, $lbl_august, $lbl_september, $lbl_oktober,$lbl_november, $lbl_december),"Serie2");
		//$DataSales->AddAllSeries(); 
		$DataSales->AddSerie('Serie1');
		$DataSales->SetSerieName($lbl_sales." ".$year,"Serie1");
		$DataSales->SetAbsciseLabelSerie("Serie2"); 
		$DataSales->SetYAxisName($lbl_turnover);  
		$DataSales->SetYAxisUnit($currency);     		
		// Initialise the graph
		$SalesGraph = new pChart(1000,245);
		$SalesGraph->setFontProperties("../scripts/pchart/Fonts/tahoma.ttf",8);
		$SalesGraph->setGraphArea(90,35,800,200); // $SalesGraph->setGraphArea(40,30,680,200);
		$SalesGraph->drawGraphArea(252,252,252,TRUE);
		$SalesGraph->drawFilledRoundedRectangle(0,0,850,240,5,242,242,230);  
		$SalesGraph->drawRoundedRectangle(0,5,850,225,5,242,242,230); 
		$SalesGraph->setColorPalette(0,30,183,178 ); //$SalesGraph->setColorPalette(1,63,223,63)
		//$SalesGraph->setColorPalette(1,63,223,63);// $SalesGraph->setColorPalette(1,155,181,189);
		// Draw the line graph
		//$SalesGraph->reportWarnings(); 

if ($graph_mode=='' || $graph_mode==filledlinegraph){	
		$SalesGraph->drawScale($DataSales->GetData(),$DataSales->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
		$SalesGraph->drawGrid(4,TRUE,230,230,230,70);
		$SalesGraph->drawPlotGraph($DataSales->GetData(),$DataSales->GetDataDescription(),3,2,244,249,251);
		$SalesGraph->drawFilledLineGraph($DataSales->GetData(),$DataSales->GetDataDescription(),50,TRUE); 
}
if ($graph_mode==linegraph){	
		$SalesGraph->drawScale($DataSales->GetData(),$DataSales->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
		$SalesGraph->drawGrid(4,TRUE,230,230,230,70);
		$SalesGraph->drawPlotGraph($DataSales->GetData(),$DataSales->GetDataDescription(),3,2,244,249,251);
		$SalesGraph->drawLineGraph($DataSales->GetData(),$DataSales->GetDataDescription());
}
if ($graph_mode==cubiccurve){	
		$SalesGraph->drawScale($DataSales->GetData(),$DataSales->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
		$SalesGraph->drawGrid(4,TRUE,230,230,230,70);
		$SalesGraph->drawCubicCurve($DataSales->GetData(),$DataSales->GetDataDescription());
}
if ($graph_mode==bargraph){	
		$SalesGraph->drawScale($DataSales->GetData(),$DataSales->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,0,TRUE,1,FALSE);
		$SalesGraph->drawGrid(4,TRUE,230,230,230,70);
		$SalesGraph->drawBarGraph($DataSales->GetData(),$DataSales->GetDataDescription(),TRUE,50);	
}
if (!isset($_SESSION['plot']) || $plot== $lbl_show_labels){	
        if ($year==date('Y')){	
        if ($sales_jan_c >0 || date("m")>=1) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_january,$sales_jan_c, 254,254,177); 
        if ($sales_feb_c >0 || date("m")>=2) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_february,$sales_feb_c, 254,254,177);
        if ($sales_mar_c >0 || date("m")>=3) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_march,$sales_mar_c, 254,254,177);
        if ($sales_apr_c >0 || date("m")>=4) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_april,$sales_apr_c, 254,254,177);
        if ($sales_may_c >0 || date("m")>=5) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_may,$sales_may_c, 254,254,177);
        if ($sales_jun_c >0 || date("m")>=6) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_june,$sales_jun_c, 254,254,177);
        if ($sales_jul_c >0 || date("m")>=7) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_july,$sales_jul_c, 254,254,177);
        if ($sales_aug_c >0 || date("m")>=8) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_august,$sales_aug_c, 254,254,177);
        if ($sales_sep_c >0 || date("m")>=9) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_september,$sales_sep_c, 254,254,177);
        if ($sales_oct_c >0 || date("m")>=10) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_oktober,$sales_oct_c, 254,254,177);
        if ($sales_nov_c >0 || date("m")>=11) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_november,$sales_nov_c, 254,254,177);
        if ($sales_dec_c >0 || date("m")>=12) $SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_december,$sales_dec_c, 254,254,177);
	}else {
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_january,$sales_jan_c, 254,254,177); 
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_february,$sales_feb_c, 254,254,177);
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_march,$sales_mar_c, 254,254,177);
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_april,$sales_apr_c, 254,254,177);
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_may,$sales_may_c, 254,254,177);
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_june,$sales_jun_c, 254,254,177);
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_july,$sales_jul_c, 254,254,177);
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_august,$sales_aug_c, 254,254,177);
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_september,$sales_sep_c, 254,254,177);
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_oktober,$sales_oct_c, 254,254,177);
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_november,$sales_nov_c, 254,254,177);
		$SalesGraph->setLabel($DataSales->GetData(),$DataSales->GetDataDescription(),"Serie1",$lbl_december,$sales_dec_c, 254,254,177);
	}
}
		// Finish the graph
		$SalesGraph->setFontProperties("../scripts/pchart/Fonts/tahoma.ttf",8);
		$SalesGraph->drawLegend(860,0,$DataSales->GetDataDescription(),242,242,230);
		$SalesGraph->setFontProperties("../scripts/pchart/Fonts/tahoma.ttf",10);
		$SalesGraph->drawTitle(60,22,$lbl_monthly_sales_plural.(($selected_branch != '') ? " (".getBranchName($selected_branch).")" : "")." ".$year,50,50,50,800);		
		// Render the graph  
        (($selected_branch != "") ? $image_name = 'monthly_sales.png' : $image_name = 'monthly_sales'.$selected_branch.'.png');
		$SalesGraph->Render("graphs/".$image_name."");				
flush();
?>
		<div style="width:99%; padding-left:5px; float:left; border-radius:3px;">
		<img src="graphs/<?php echo $image_name ?>" alt="<?php echo $lbl_monthly_sales?>" title="<?php echo $lbl_monthly_sales ?>"/>
		</div>			
		<div style="float:left; padding-top:10px">
	<?php
	$current_year = date("Y");
	$current_month = date("m");
	if (date("m")-1==0) {$previous_month=12; $year_prev_month=$current_year-1;}else{$previous_month=date("m")-1; $year_prev_month=$current_year;};
	//echo "pr minas".$previous_month;
	//echo "pr mina etos".$year_prev_month;
	$current_day = date("d");
	######################### cummulative months comparison
				$sql_cum_c = "SELECT SUM(amount) AS cum_totals FROM cls_transactions
							WHERE created_on 
							BETWEEN CONCAT('$current_year','-','$current_month','-',01,' ','00:00:00') 
							AND CONCAT('$current_year','-','$current_month','-','$current_day',' ','23:59:59')
							AND transaction_type<>'Εξαργύρωση'
                            AND ISNULL(is_reversed)
                            AND ISNULL(reversal)
                            ".(($selected_branch != "") ? " AND branch_id ='".$selected_branch."'" : "")."
                            ";   
				$result_cum_c = mysqli_query($mysqli, $sql_cum_c) or die("Query failed : " . mysqli_error($mysqli));
				if (mysqli_num_rows($result_cum_c) == 0){echo $error001; 
				}else{$line = mysqli_fetch_array($result_cum_c, MYSQLI_ASSOC); $cum_c = $line['cum_totals'];} 
	################previous
				$sql_cum_p = "SELECT SUM(amount) AS cum_totals_p FROM cls_transactions
							WHERE created_on 
							BETWEEN CONCAT('$year_prev_month','-','$previous_month','-',01,' ','00:00:00') 
							AND CONCAT('$year_prev_month','-','$previous_month','-','$current_day',' ','23:59:59')
							AND transaction_type<>'Εξαργύρωση'
                            AND ISNULL(is_reversed)
                            AND ISNULL(reversal)
                            ".(($selected_branch != "") ? " AND branch_id ='".$selected_branch."'" : "")."
                            ";   
				$result_cum_p = mysqli_query($mysqli, $sql_cum_p) or die("Query failed : " . mysqli_error($mysqli));
				if (mysqli_num_rows($result_cum_p) == 0){echo $error001;
				}else{$line = mysqli_fetch_array($result_cum_p, MYSQLI_ASSOC); $cum_p=$line['cum_totals_p'];} 
				//echo  $cum_p;
	###############################################	
	#calculate variation rate
	if ($cum_p>0){
		$variation = number_format(((($cum_c - $cum_p)/$cum_p)*100),0);
	}elseif ($cum_p<=0){
		$variation=0;
	}
	//echo $variation;
	//echo  $cum_p." - ". $cum_c;
	###############################################
 ?>		
 		<div style="width:99%; padding-left:5px; margin-bottom:10px; float:left">
		&raquo; <?php echo $lbl_setup ?> 
		<a href="reports_monthly.php?selected_year=<?php echo $current_year ?>&splot=toggle&graph_mode=<?php echo $graph_mode ?>&selected_branch=<?php echo $selected_branch ?>">
		<?php if ($plot==$lbl_hide_labels){echo $lbl_show_labels;}else{echo $lbl_hide_labels;}?></a><br />
		&raquo; <?php echo $lbl_view_options ?> 
		<a href="reports_monthly.php?graph=<?php echo $graph?>&graph_mode=filledlinegraph&selected_year=<?php echo $current_year?>&selected_branch=<?php echo $selected_branch ?>"><?php echo $lbl_filled_line_graph?></a> |
		<a href="reports_monthly.php?graph=<?php echo $graph?>&graph_mode=linegraph&selected_year=<?php echo $current_year ?>&selected_branch=<?php echo $selected_branch ?>"><?php echo $lbl_simple_line_graph ?></a> |
		<a href="reports_monthly.php?graph=<?php echo $graph?>&graph_mode=cubiccurve&selected_year=<?php echo $current_year ?>&selected_branch=<?php echo $selected_branch ?>"><?php echo $lbl_cubic_curve_graph ?></a> | 
		<a href="reports_monthly.php?graph=<?php echo $graph?>&graph_mode=bargraph&selected_year=<?php echo $current_year ?>&selected_branch=<?php echo $selected_branch ?>"><?php echo $lbl_bar_graph ?></a> <br />
		</div>
 		<div style="width:99%; padding-left:5px; float:left; border-radius:3px;">
		<div>
		<div style="float:left; background-color:#F2F2E6; padding:5px; border-radius:3px; margin-top:3px; height:56px; border:1px #CCCCCC solid; color:#666666">
				<?php 
				if ($variation<0){
					echo "<img src='../img/down _arrow.gif' alt='' /><font size='50'>".$variation."%</font>";
				}elseif ($variation>0){
					echo "<img src='../img/up_arrow.gif' alt='' /><font size='50'>".$variation."%</font>";
				}elseif ($variation==0){
					echo "<font size='50'>".$variation."%</font>";
				}
				?>
		  </div>
			  <div style="float:left;background-color:#F2F2E6; padding:5px; width:200px; height:56px; font:tahoma; font-size:11px; border-radius:3px; margin-left:5px; margin-top:3px; border:1px #CCCCCC solid; margin-right:5px;color:#666666">
			<img src="../img/info.gif" /> <?php echo $lbl_variation_from_last_month ?>
			</div>
		  </div>
		</div>
		
		<div style="width:850px; float:left; padding-left:5px;" class="align-left">
		<?php    

    ################################################################################
    ## +---------------------------------------------------------------------------+
    ## | 1. Creating & Calling:                                                    | 
    ## +---------------------------------------------------------------------------+
      define ("DATAGRID_DIR", "../datagrid/");                     /* Ex.: "datagrid/" */ 
      define ("PEAR_DIR", "../datagrid/pear/");                    /* Ex.: "datagrid/pear/" */
      require_once(DATAGRID_DIR.'datagrid.class.php');
      require_once(PEAR_DIR.'PEAR.php');
      require_once(PEAR_DIR.'DB.php');
      include_once('../datagrid/config.inc.php');
      ob_start();
      $db_conn = DB::factory('mysql');  /* don't forget to change on appropriate db type */
      $result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
      if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }  
      
    ################################################################################   
      $sql = "SELECT bi_year AS years, 
				SUM(IF(bi_month = '1', 1, 0) * ROUND(sales_amount,0)) AS jan,
				SUM(IF(bi_month = '2', 1, 0) * ROUND(sales_amount,0)) AS feb,
				SUM(IF(bi_month = '3', 1, 0) * ROUND(sales_amount,0)) AS mar,
				SUM(IF(bi_month= '4', 1, 0) * ROUND(sales_amount,0)) AS apr,
				SUM(IF(bi_month = '5', 1, 0) * ROUND(sales_amount,0)) AS may,
				SUM(IF(bi_month = '6', 1, 0) * ROUND(sales_amount,0)) AS jun,
				SUM(IF(bi_month = '7', 1, 0) * ROUND(sales_amount,0)) AS jul,
				SUM(IF(bi_month = '8', 1, 0) * ROUND(sales_amount,0)) AS aug,
				SUM(IF(bi_month = '9', 1, 0) * ROUND(sales_amount,0)) AS sep,
				SUM(IF(bi_month = '10', 1, 0) * ROUND(sales_amount,0)) AS oct,
				SUM(IF(bi_month = '11', 1, 0) * ROUND(sales_amount,0)) AS nov,
				SUM(IF(bi_month = '12', 1, 0) * ROUND(sales_amount,0)) AS 'dec',
				SUM(ROUND(sales_amount,0)) AS year_totals
				FROM bi_sales
				WHERE bi_year='$current_year'
                ".(($selected_branch != "") ? " AND branch_id ='".$selected_branch."'" : "")."
				GROUP BY years";         
	        
    ##  *** set needed options and create a new class instance 
      $debug_mode = false;        /* display SQL statements while processing */    
      $messaging = true;          /* display system messages on a screen */ 
      $unique_prefix = "op1_";    /* prevent overlays - must be started with a letter */
      $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
      $dgrid->SetCssClass("default");
      $dgrid->DisplayLoadingImage("true");
      $dgrid->AllowPaging(false, "", "");
    ##  *** set data source with needed options
      $default_order_field = "years";
      $default_order_type = "DESC";
      $dgrid->DataSource($db_conn, $sql, $default_order_field, $default_order_type);
    ##  *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
     $modes = array(
     );
     $dgrid->SetModes($modes);
    ##  *** set DataGrid caption
     //$dg_caption = $lbl_new_customers_for_the_year." ".$year;
    // $dgrid->SetCaption($dg_caption);
     $dgrid->AllowPrinting(true);
     $dgrid->AllowSorting(false);
     $dgrid->AllowHighlighting(true);
	//webnail language handling
	if ($_SESSION['lang']=="EN"){$dg_language = "en";}elseif ($_SESSION['lang']=="GR"){$dg_language = "gk";}else{$dg_language = "en";}
	$dgrid->SetInterfaceLang($dg_language);  
     
	$paging_option = false;
    $dropdown_paging = true;
    $dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign, $dropdown_paging);
    ##  *** set paging settings
    $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
   // $top_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
    $pages_array = array("5"=>"5", "10"=>"10", "50"=>"50");
    $default_page_size = 5;
    $paging_arrows = array("first"=>"|&lt;&lt;", "previous"=>"&lt;&lt;", "next"=>"&gt;&gt;", "last"=>"&gt;&gt;|");
    $dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size, $paging_arrows);
		 ## +---------------------------------------------------------------------------+
	## | 3. Printing & Exporting Settings:                                         | 
	## +---------------------------------------------------------------------------+
	##  *** set printing option: true(default) or false 
	  $printing_option = true;
	  $dgrid->AllowPrinting($printing_option);
	  $exporting_option = true;
		$exporting_directory = "../exports/";               
		$export_all = true;
		$dgrid->AllowExporting($exporting_option, $exporting_directory, $export_all);
		$exporting_types = array("excel"=>"true", "pdf"=>"false", "xml"=>"false");
		$dgrid->AllowExportingTypes($exporting_types);
		
    ## +---------------------------------------------------------------------------+
    ## | 6. View Mode Settings:                                                    | 
    ## +---------------------------------------------------------------------------+
    ##  *** set view mode table properties
     $vm_table_properties = array("width"=>"850px");
     $dgrid->SetViewModeTableProperties($vm_table_properties);  
     $vm_colimns = array(  
	 	"years"=>array("header"=>$lbl_year, "type"=>"label", "header_align"=>"center",  "align"=>"right", "width"=>"100px", "wrap"=>"nowrap", "visible"=>"true", ),
        "jan"  =>array("header"=>$lbl_Jan, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),
        "feb"  =>array("header"=>$lbl_Feb, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),
        "mar"  =>array("header"=>$lbl_Mar, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),
        "apr"  =>array("header"=>$lbl_Apr, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),
        "may"  =>array("header"=>$lbl_May, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),
        "jun"  =>array("header"=>$lbl_Jun, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),
        "jul"  =>array("header"=>$lbl_Jul, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),
        "aug"  =>array("header"=>$lbl_Aug, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),
        "sep"  =>array("header"=>$lbl_Sep, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),
        "oct"  =>array("header"=>$lbl_Oct, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),
        "nov"  =>array("header"=>$lbl_Nov, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),
        "dec"  =>array("header"=>$lbl_Dec, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),	
        "year_totals"  =>array("header"=>$lbl_year_totals, "type"=>"money", "header_align"=>"center","tooltip"=>"true", "summarize"=>"false", "sign"=>$currency, "sign_place"=>"before", "decimal_places"=>"0", "dec_separator"=>",", "thousands_separator"=>".", "align"=>"right", "width"=>"", "wrap"=>"nowrap"),				
     );
     $dgrid->SetColumnsInViewMode($vm_colimns);
	 //$dgrid->SetSummarizeNumberFormat("0", ",", ".");
	 $dgrid->DisplayLoadingImage();
    
    ## +---------------------------------------------------------------------------+
    ## | 8. Bind the DataGrid:                                                     | 
    ## +---------------------------------------------------------------------------+
    ##  *** bind the DataGrid and draw it on the screen
      $dgrid->Bind();        
      //ob_end_flush();
    ##
    ################################################################################   
	?>
		</div>
	</div>	
	</fieldset>
</body>
</html>
<?php
} else {
    header('Location: login.php');
}
?>

