<?php

include "../../plugin/SVGGraph/SVGGraph.php";

$cell_width="100";


    echo "<section class='view_header'>";

    //echo $_SESSION["data_site"];
    echo "</section>";


    echo "<section class='view_content'>";



$month_text[1]="JAN";
$month_text[2]="FEB";
$month_text[3]="MAR";
$month_text[4]="APR";
$month_text[5]="MAY";
$month_text[6]="JUN";
$month_text[7]="JUL";
$month_text[8]="AUG";
$month_text[9]="SEP";
$month_text[10]="OCT";
$month_text[11]="NOV";
$month_text[12]="DEC";



$month_text2[1]="January";
$month_text2[2]="February";
$month_text2[3]="March";
$month_text2[4]="April";
$month_text2[5]="May";
$month_text2[6]="June";
$month_text2[7]="July";
$month_text2[8]="August";
$month_text2[9]="September";
$month_text2[10]="October";
$month_text2[11]="November";
$month_text2[12]="December";


//======================================================================================




//device library:
$query_device="select * from t_".$key_table_prefix."_device ";
$result_device = mysqli_query($dbconn,$query_device);
while($line_device = mysqli_fetch_array($result_device,MYSQLI_ASSOC))
{
	
	$device_data[$line_device["dev_android_id"]]=$line_device["dev_name"];
}



$query_staff="select * from t_".$key_table_prefix."_staff ";
$result_staff = mysqli_query($dbconn,$query_staff);
while($line_staff = mysqli_fetch_array($result_staff,MYSQLI_ASSOC))
{
	
	$sales_person_data[$line_staff["stf_code"]]=$line_staff["stf_name"];
}

$sales_person_data[""]="Unspecified";



if($_REQUEST["y"]!="")
{
	$_SESSION["calendar_y"]=$_REQUEST["y"];
}

if($_REQUEST["m"]!="")
{
	$_SESSION["calendar_m"]=$_REQUEST["m"];
}



//======================================================================================

if($_SESSION["calendar_y"]=="")
{
	$_SESSION["calendar_y"]=date("Y");
}

if($_SESSION["calendar_m"]=="")
{
	$_SESSION["calendar_m"]=date("m");
}







echo "<div class='cal_menu_panel'>";
    echo "<div class='cal_menu_box'>";
    for($y=2010;$y<=2030;$y++)
    {
        if($_SESSION["calendar_y"]==$y)
        {
            echo "<div class='cal_menu_active' ";
        }
        else
        {
            echo "<div class='cal_menu_inactive' ";
        }
        echo " onclick=\"mon_send_get('mod/welcome/index.php','?tab=".$_REQUEST["tab"]."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."&y=".$y."".$tab_extra_url."','div_main')\">".$y."</div>";
    }
    echo "</div>";

    echo "<div class='cal_menu_box'>";
    for($m=1;$m<=12;$m++)
    {
        if($_SESSION["calendar_m"]==$m)
        {
            echo "<div class='cal_menu_active' ";
        }
        else
        {
            echo "<div class='cal_menu_inactive' ";
        }
        echo " onclick=\"mon_send_get('mod/welcome/index.php','?tab=".$_REQUEST["tab"]."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."&m=".substr($m+100,1,2)."".$tab_extra_url."','div_main')\" >".$month_text[$m]."</div>";
    }
    echo "</div>";



echo "</div>";


$total_of_days = date("t",mktime(0,0,0,$_SESSION["calendar_m"],1,$_SESSION["calendar_y"]));

$selected_date_start=$_SESSION["calendar_y"]."-".$_SESSION["calendar_m"]."-01 00:00:00";
$selected_date_end=$_SESSION["calendar_y"]."-".$_SESSION["calendar_m"]."-".$total_of_days." 23:59:59";


$selected_date_start_simple=$_SESSION["calendar_y"]."-".$_SESSION["calendar_m"]."-01";
$selected_date_end_simple=$_SESSION["calendar_y"]."-".$_SESSION["calendar_m"]."-".$total_of_days."";

$selected_date_start_year=$_SESSION["calendar_y"]."-01-01 00:00:00";
$selected_date_end_year=$_SESSION["calendar_y"]."-12-31 23:59:59";






$selected_date = $_SESSION["calendar_y"]."-".$_SESSION["calendar_m"]."";

echo "<font size=1 color=#34495E style='float:left;width:100%;' >Showing data of period ".$selected_date_start." - ".$selected_date_end."</font><br><br><br>";


echo "<br>&nbsp;";







//====================================================top 10 in month==============================================================


echo "<div class='data_display_content'>";	

	echo "<font size=3 style='float:left;padding:15px;color:#000;'><b><span class='fa fa-arrow-up fa-lg'></span> Top 10 Product(s) of ".$month_text2[$_SESSION["calendar_m"]+0]." ".$_SESSION["calendar_y"]."</b></font>";
	
	echo "<br>";
	//echo "<input style='float:left;' type=button class='button button-blue' value='Print' onclick=\"print_page('print/sales_report_month/?start=".$selected_date_start_simple."&end=".$selected_date_end_simple."&part=SUM_DEV_PDT')\">";


	echo "<div class='view_list_title_row'>";
		echo "<div class='view_list_title_content'>";
			
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Product Code</b>";
			echo "</div>";
			
			echo "<div style='width:200px;' class='view_list_title_content_object'  >";
				echo "<b>Product Name</b>";
			echo "</div>";
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Quantity</b>";
			echo "</div>";
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Total Discount</b>";
			echo "</div>";
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Total Amount</b>";
			echo "</div>";
			
		echo "</div>";
	echo "</div>";
			
			
			$sum_product_quantity=0;
			$sum_product_discount = 0;
			$sum_product_amount = 0;
			
			
	$query="select 
			
			sum(ivi_quantity) as ivi_quantity,
			sum(ivi_discount_total) as ivi_discount_total,
			sum(ivi_total_amount) as ivi_total_amount,
			
			ivi_product_code, ivi_product_name
			
			
			from t_".$key_table_prefix."_invoice_header h, t_".$key_table_prefix."_invoice_item i 
			where ivh_doc_no = ivi_doc_no
			and h.device_id = i.device_id 
			and ivh_status = 'POSTED'
			
			
			
			and h.created_date >= '".$selected_date_start."'
			and h.created_date <= '".$selected_date_end."'
			
			group by  ivi_product_code, ivi_product_name
			order by ivi_total_amount desc
			limit 0, 10
			
			";		
	$result = mysqli_query($dbconn,$query);
	while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
	{
		
		$report_data_product["ALL"][$line["ivi_product_code"]] = $line;	
		
		
		
			
		
	}
	
			


			 
			
	$counter=1;
	foreach($report_data_product as $sub_key => $report_data_product2)
	{
		
		/*
		echo "<div class='view_row'>";
			echo "<div style='width:200px;text-align:left;' class='view_row_content_object'  >";
				echo "<font class='view_row_content_label'></font>";
				echo "<font class='view_row_content_text'>";
					echo "<font color=#000>".$sub_key."</font>";
				echo "</font><br>";			
			echo "</div>";
		
			echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
			echo "</div>";
			
		echo "</div>";
		
		*/
		
		$sub_sum_product_quantity=0;
		$sub_sum_product_discount=0;
		$sub_sum_product_amount=0;
		
		
		
		foreach($report_data_product[$sub_key] as $product_code => $report_data_product3)
		{
	
			echo "<div class='view_row'>";
				echo "<div style='width:100px;text-align:left;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$counter."</font>";
					echo "<font class='view_row_content_text'>";
						echo "".$product_code."";
					echo "</font><br>";			
				echo "</div>";
			
				echo "<div style='width:200px;text-align:left;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Product Name</font>";
					echo "<font class='view_row_content_text'>";
						echo $report_data_product3["ivi_product_name"];
						
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Before GST</font>";
					echo "<font class='view_row_content_text'>";
						
						echo number_format($report_data_product3["ivi_quantity"],2,".",",");
						
						$sum_product_quantity = $sum_product_quantity + $report_data_product3["ivi_quantity"];
						$sub_sum_product_quantity = $sub_sum_product_quantity + $report_data_product3["ivi_quantity"];
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Discount</font>";
					echo "<font class='view_row_content_text'>";
						echo number_format($report_data_product3["ivi_discount"],2,".",",");
						$sum_product_discount = $sum_product_discount + $report_data_product3["ivi_discount"];
						$sub_sum_product_discount = $sub_sum_product_discount + $report_data_product3["ivi_discount"];
					echo "</font><br>";			
				echo "</div>";
				
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Amount</font>";
					echo "<font class='view_row_content_text'>";
						echo number_format($report_data_product3["ivi_total_amount"],2,".",",");
						$sum_product_amount = $sum_product_amount+ $report_data_product3["ivi_total_amount"];
						$sub_sum_product_amount = $sub_sum_product_amount+ $report_data_product3["ivi_total_amount"];
					echo "</font><br>";			
				echo "</div>";
				
					
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
				echo "</div>";
				
				
				$chart_value[$report_data_product3["ivi_product_code"]]=$report_data_product3["ivi_total_amount"];
				
				
				
			echo "</div>";
			$counter++;
			
		}
		
		
		//print_r($chart_value);
		/*
			//sub_total
			echo "<div class='view_row'>";
				echo "<div style='width:100px;text-align:left;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$counter."</font>";
					echo "<font class='view_row_content_text'>";
					
					echo "</font><br>";			
				echo "</div>";
			
				echo "<div style='width:200px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'></font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000><b>Sub Total</b></font>";
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Quantity</font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000 ><b>".number_format($sub_sum_product_quantity,2,".",",")."</b>";
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>GST Amount</font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000 ><b>".number_format($sub_sum_product_discount,2,".",",")."</b>";
					echo "</font><br>";			
				echo "</div>";
					
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Amount</font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000 ><b>".number_format($sub_sum_product_amount,2,".",",")."</b>";
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
				echo "</div>";
				
			echo "</div>";
			
			*/
			
			
			
	}


	//total
	echo "<div class='view_row'>";
		echo "<div style='width:100px;text-align:left;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>".$counter."</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000><b>Total</b></font>";
			echo "</font><br>";			
		echo "</div>";
	
		echo "<div style='width:200px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'></font>";
			echo "<font class='view_row_content_text'>";
			echo "</font><br>";			
		echo "</div>";
		
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>Total Quantity</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000 ><b>".number_format($sum_product_quantity,2,".",",")."</b>";
			echo "</font><br>";			
		echo "</div>";
		
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>GST Amount</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000 ><b>".number_format($sum_product_discount,2,".",",")."</b>";
			echo "</font><br>";			
		echo "</div>";
			
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>Total Amount</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000 ><b>".number_format($sum_product_amount,2,".",",")."</b>";
			echo "</font><br>";			
		echo "</div>";
		
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
		echo "</div>";
		
	echo "</div>";
	
echo "</div>";




echo "<div class='data_display_content' style='float:left;width:800px;'>";	

$settings = array(
'back_colour' => '#fff',  'stroke_colour' => '',
'back_stroke_width' => 0, 'back_stroke_colour' => '#ECF0F1',
'axis_colour' => '#6C7A89',  'axis_overlap' => 0,
'axis_font' => 'Arial', 'axis_font_size' => 10,
'grid_colour' => '#ECF0F1',  'label_colour' => '#000',
'pad_right' => 20,        'pad_left' => 20,
'link_base' => '/',       'link_target' => '_top',
'project_angle' => 40,    'minimum_grid_spacing' => 20,
'bar_width' => 50
);

$values = array(
array('Dough' => 30, 'Ray' => 50, 'Me' => 40, 'So' => 25, 'Far' => 45, 'Lard' => 35)
);

$colours = array('#0ED2F7');
//$links = array('Dough' => 'jpegsaver.php', 'Ray' => 'crcdropper.php','Me' => 'svggraph.php');

$graph = new SVGGraph(800, 300, $settings);
$graph->colours = $colours;

$graph->Values($chart_value);
$graph->Links($links);
$graph->Render('BarGraph');

echo "</div>";


echo "<br>&nbsp;<br>&nbsp;";
echo "<br>&nbsp;<br>&nbsp;";




//====================================================top 10 in year ==============================================================


echo "<div class='data_display_content'>";	

	echo "<font size=3 style='float:left;padding:15px;color:#000;'><b><span class='fa fa-arrow-up fa-lg'></span> Top 10 Product(s) of ".$_SESSION["calendar_y"]."</b></font>";
	
	echo "<br>";
	//echo "<input style='float:left;' type=button class='button button-blue' value='Print' onclick=\"print_page('print/sales_report_month/?start=".$selected_date_start_simple."&end=".$selected_date_end_simple."&part=SUM_DEV_PDT')\">";


	echo "<div class='view_list_title_row'>";
		echo "<div class='view_list_title_content'>";
			
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Product Code</b>";
			echo "</div>";
			
			echo "<div style='width:200px;' class='view_list_title_content_object'  >";
				echo "<b>Product Name</b>";
			echo "</div>";
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Quantity</b>";
			echo "</div>";
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Total Discount</b>";
			echo "</div>";
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Total Amount</b>";
			echo "</div>";
			
		echo "</div>";
	echo "</div>";
			
			
			$sum_product_quantity=0;
			$sum_product_discount = 0;
			$sum_product_amount = 0;
			
			
	$query="select 
			
			sum(ivi_quantity) as ivi_quantity,
			sum(ivi_discount_total) as ivi_discount_total,
			sum(ivi_total_amount) as ivi_total_amount,
			
			ivi_product_code, ivi_product_name
			
			
			from t_".$key_table_prefix."_invoice_header h, t_".$key_table_prefix."_invoice_item i 
			where ivh_doc_no = ivi_doc_no
			and h.device_id = i.device_id 
			and ivh_status = 'POSTED'
			
			
			
			and h.created_date >= '".$selected_date_start_year."'
			and h.created_date <= '".$selected_date_end_year."'
			
			group by  ivi_product_code, ivi_product_name
			order by ivi_total_amount desc
			limit 0, 10
			
			";		
	$result = mysqli_query($dbconn,$query);
	while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
	{
		
		$report_data_product["ALL"][$line["ivi_product_code"]] = $line;		
		
	}
	
			


			
			
	$counter=1;
	foreach($report_data_product as $sub_key => $report_data_product2)
	{
		
		/*
		echo "<div class='view_row'>";
			echo "<div style='width:200px;text-align:left;' class='view_row_content_object'  >";
				echo "<font class='view_row_content_label'></font>";
				echo "<font class='view_row_content_text'>";
					echo "<font color=#000>".$sub_key."</font>";
				echo "</font><br>";			
			echo "</div>";
		
			echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
			echo "</div>";
			
		echo "</div>";
		
		*/
		
		$sub_sum_product_quantity=0;
		$sub_sum_product_discount=0;
		$sub_sum_product_amount=0;
		
		
		
		foreach($report_data_product[$sub_key] as $product_code => $report_data_product3)
		{
	
			echo "<div class='view_row'>";
				echo "<div style='width:100px;text-align:left;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$counter."</font>";
					echo "<font class='view_row_content_text'>";
						echo "".$product_code."";
					echo "</font><br>";			
				echo "</div>";
			
				echo "<div style='width:200px;text-align:left;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Product Name</font>";
					echo "<font class='view_row_content_text'>";
						echo $report_data_product3["ivi_product_name"];
						
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Before GST</font>";
					echo "<font class='view_row_content_text'>";
						
						echo number_format($report_data_product3["ivi_quantity"],2,".",",");
						
						$sum_product_quantity = $sum_product_quantity + $report_data_product3["ivi_quantity"];
						$sub_sum_product_quantity = $sub_sum_product_quantity + $report_data_product3["ivi_quantity"];
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Discount</font>";
					echo "<font class='view_row_content_text'>";
						echo number_format($report_data_product3["ivi_discount"],2,".",",");
						$sum_product_discount = $sum_product_discount + $report_data_product3["ivi_discount"];
						$sub_sum_product_discount = $sub_sum_product_discount + $report_data_product3["ivi_discount"];
					echo "</font><br>";			
				echo "</div>";
				
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Amount</font>";
					echo "<font class='view_row_content_text'>";
						echo number_format($report_data_product3["ivi_total_amount"],2,".",",");
						$sum_product_amount = $sum_product_amount+ $report_data_product3["ivi_total_amount"];
						$sub_sum_product_amount = $sub_sum_product_amount+ $report_data_product3["ivi_total_amount"];
					echo "</font><br>";			
				echo "</div>";
				
					
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
				echo "</div>";
				
				
				$chart_value_year[$report_data_product3["ivi_product_code"]]=$report_data_product3["ivi_total_amount"];
				
				
			echo "</div>";
			$counter++;
			
		}
		
		
		/*
			//sub_total
			echo "<div class='view_row'>";
				echo "<div style='width:100px;text-align:left;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$counter."</font>";
					echo "<font class='view_row_content_text'>";
					
					echo "</font><br>";			
				echo "</div>";
			
				echo "<div style='width:200px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'></font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000><b>Sub Total</b></font>";
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Quantity</font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000 ><b>".number_format($sub_sum_product_quantity,2,".",",")."</b>";
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>GST Amount</font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000 ><b>".number_format($sub_sum_product_discount,2,".",",")."</b>";
					echo "</font><br>";			
				echo "</div>";
					
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Amount</font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000 ><b>".number_format($sub_sum_product_amount,2,".",",")."</b>";
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
				echo "</div>";
				
			echo "</div>";
			
			*/
			
			
			
	}


	//total
	echo "<div class='view_row'>";
		echo "<div style='width:100px;text-align:left;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>".$counter."</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000><b>Total</b></font>";
			echo "</font><br>";			
		echo "</div>";
	
		echo "<div style='width:200px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'></font>";
			echo "<font class='view_row_content_text'>";
			echo "</font><br>";			
		echo "</div>";
		
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>Total Quantity</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000 ><b>".number_format($sum_product_quantity,2,".",",")."</b>";
			echo "</font><br>";			
		echo "</div>";
		
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>GST Amount</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000 ><b>".number_format($sum_product_discount,2,".",",")."</b>";
			echo "</font><br>";			
		echo "</div>";
			
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>Total Amount</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000 ><b>".number_format($sum_product_amount,2,".",",")."</b>";
			echo "</font><br>";			
		echo "</div>";
		
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
		echo "</div>";
		
	echo "</div>";
	
echo "</div>";



echo "<br>&nbsp;<br>&nbsp;";
echo "<br>&nbsp;<br>&nbsp;";



echo "<div class='data_display_content' style='float:left;width:800px;'>";	

$settings = array(
'back_colour' => '#fff',  'stroke_colour' => '',
'back_stroke_width' => 0, 'back_stroke_colour' => '#ECF0F1',
'axis_colour' => '#6C7A89',  'axis_overlap' => 0,
'axis_font' => 'Arial', 'axis_font_size' => 10,
'grid_colour' => '#ECF0F1',  'label_colour' => '#000',
'pad_right' => 20,        'pad_left' => 20,
'link_base' => '/',       'link_target' => '_top',
'project_angle' => 40,    'minimum_grid_spacing' => 20,
'bar_width' => 50
);

$values = array(
array('Dough' => 30, 'Ray' => 50, 'Me' => 40, 'So' => 25, 'Far' => 45, 'Lard' => 35)
);

//$colours = array(array('#0ED2F7','#1fbad6'));
$colours = array('#0ED2F7');
//$links = array('Dough' => 'jpegsaver.php', 'Ray' => 'crcdropper.php','Me' => 'svggraph.php');

$graph = new SVGGraph(800, 300, $settings);
$graph->colours = $colours;

$graph->Values($chart_value_year);
$graph->Links($links);
$graph->Render('BarGraph');

echo "</div>";


echo "<br>&nbsp;<br>&nbsp;";
echo "<br>&nbsp;<br>&nbsp;";



















//====================================================product distribution==============================================================


echo "<div class='data_display_content'>";	

	echo "<font size=3 style='float:left;padding:15px;color:#000;'><b><span class='fa fa-arrow-up fa-lg'></span> Product Sales Distribution by Amount for  ".$_SESSION["calendar_y"]."</b></font>";
	
	echo "<br>";
	//echo "<input style='float:left;' type=button class='button button-blue' value='Print' onclick=\"print_page('print/sales_report_month/?start=".$selected_date_start_simple."&end=".$selected_date_end_simple."&part=SUM_DEV_PDT')\">";


	echo "<div class='view_list_title_row'>";
		echo "<div class='view_list_title_content'>";
			
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Product Code</b>";
			echo "</div>";
			
			echo "<div style='width:200px;' class='view_list_title_content_object'  >";
				echo "<b>Product Name</b>";
			echo "</div>";
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Quantity</b>";
			echo "</div>";
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Total Discount</b>";
			echo "</div>";
			
			echo "<div style='width:100px;' class='view_list_title_content_object'  >";
				echo "<b>Total Amount</b>";
			echo "</div>";
			
		echo "</div>";
	echo "</div>";
			
			
			$sum_product_quantity=0;
			$sum_product_discount = 0;
			$sum_product_amount = 0;
			
			
	$query="select 
			
			sum(ivi_quantity) as ivi_quantity,
			sum(ivi_discount_total) as ivi_discount_total,
			sum(ivi_total_amount) as ivi_total_amount,
			
			ivi_product_code, ivi_product_name
			
			
			from t_".$key_table_prefix."_invoice_header h, t_".$key_table_prefix."_invoice_item i 
			where ivh_doc_no = ivi_doc_no
			and h.device_id = i.device_id 
			and ivh_status = 'POSTED'
			
			
			
			and h.created_date >= '".$selected_date_start_year."'
			and h.created_date <= '".$selected_date_end_year."'
			
			group by  ivi_product_code, ivi_product_name
			order by ivi_total_amount desc
			
			
			";		
	$result = mysqli_query($dbconn,$query);
	while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
	{
		
		$report_data_product["ALL"][$line["ivi_product_code"]] = $line;		
		
	}
	
			


			
			
	$counter=1;
	foreach($report_data_product as $sub_key => $report_data_product2)
	{
		
		/*
		echo "<div class='view_row'>";
			echo "<div style='width:200px;text-align:left;' class='view_row_content_object'  >";
				echo "<font class='view_row_content_label'></font>";
				echo "<font class='view_row_content_text'>";
					echo "<font color=#000>".$sub_key."</font>";
				echo "</font><br>";			
			echo "</div>";
		
			echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
			echo "</div>";
			
		echo "</div>";
		
		*/
		
		$sub_sum_product_quantity=0;
		$sub_sum_product_discount=0;
		$sub_sum_product_amount=0;
		
		
		
		foreach($report_data_product[$sub_key] as $product_code => $report_data_product3)
		{
	
			echo "<div class='view_row'>";
				echo "<div style='width:100px;text-align:left;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$counter."</font>";
					echo "<font class='view_row_content_text'>";
						echo "".$product_code."";
					echo "</font><br>";			
				echo "</div>";
			
				echo "<div style='width:200px;text-align:left;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Product Name</font>";
					echo "<font class='view_row_content_text'>";
						echo $report_data_product3["ivi_product_name"];
						
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Before GST</font>";
					echo "<font class='view_row_content_text'>";
						
						echo number_format($report_data_product3["ivi_quantity"],2,".",",");
						
						$sum_product_quantity = $sum_product_quantity + $report_data_product3["ivi_quantity"];
						$sub_sum_product_quantity = $sub_sum_product_quantity + $report_data_product3["ivi_quantity"];
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Discount</font>";
					echo "<font class='view_row_content_text'>";
						echo number_format($report_data_product3["ivi_discount"],2,".",",");
						$sum_product_discount = $sum_product_discount + $report_data_product3["ivi_discount"];
						$sub_sum_product_discount = $sub_sum_product_discount + $report_data_product3["ivi_discount"];
					echo "</font><br>";			
				echo "</div>";
				
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Amount</font>";
					echo "<font class='view_row_content_text'>";
						echo number_format($report_data_product3["ivi_total_amount"],2,".",",");
						$sum_product_amount = $sum_product_amount+ $report_data_product3["ivi_total_amount"];
						$sub_sum_product_amount = $sub_sum_product_amount+ $report_data_product3["ivi_total_amount"];
					echo "</font><br>";			
				echo "</div>";
				
					
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
				echo "</div>";
				
				
				$chart_value_year_distribution[$report_data_product3["ivi_product_code"]]=$report_data_product3["ivi_total_amount"];
				
				
			echo "</div>";
			$counter++;
			
		}
		
		
		/*
			//sub_total
			echo "<div class='view_row'>";
				echo "<div style='width:100px;text-align:left;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$counter."</font>";
					echo "<font class='view_row_content_text'>";
					
					echo "</font><br>";			
				echo "</div>";
			
				echo "<div style='width:200px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'></font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000><b>Sub Total</b></font>";
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Quantity</font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000 ><b>".number_format($sub_sum_product_quantity,2,".",",")."</b>";
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>GST Amount</font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000 ><b>".number_format($sub_sum_product_discount,2,".",",")."</b>";
					echo "</font><br>";			
				echo "</div>";
					
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>Total Amount</font>";
					echo "<font class='view_row_content_text'>";
						echo "<font color=#000 ><b>".number_format($sub_sum_product_amount,2,".",",")."</b>";
					echo "</font><br>";			
				echo "</div>";
				
				echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
				echo "</div>";
				
			echo "</div>";
			
			*/
			
			
			
	}


	//total
	echo "<div class='view_row'>";
		echo "<div style='width:100px;text-align:left;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>".$counter."</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000><b>Total</b></font>";
			echo "</font><br>";			
		echo "</div>";
	
		echo "<div style='width:200px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'></font>";
			echo "<font class='view_row_content_text'>";
			echo "</font><br>";			
		echo "</div>";
		
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>Total Quantity</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000 ><b>".number_format($sum_product_quantity,2,".",",")."</b>";
			echo "</font><br>";			
		echo "</div>";
		
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>GST Amount</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000 ><b>".number_format($sum_product_discount,2,".",",")."</b>";
			echo "</font><br>";			
		echo "</div>";
			
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";
			echo "<font class='view_row_content_label'>Total Amount</font>";
			echo "<font class='view_row_content_text'>";
				echo "<font color=#000 ><b>".number_format($sum_product_amount,2,".",",")."</b>";
			echo "</font><br>";			
		echo "</div>";
		
		echo "<div style='width:".$cell_width."px;text-align:right;' class='view_row_content_object'  >";	
		echo "</div>";
		
	echo "</div>";
	
echo "</div>";



echo "<br>&nbsp;<br>&nbsp;";
echo "<br>&nbsp;<br>&nbsp;";
















echo "<div class='data_display_content' style='float:left;width:800px;'>";	
$settings = array(
'back_colour' => '#fff',   'stroke_colour' => '',
'back_stroke_width' => 0,  'back_stroke_colour' => '#eee',
'pad_right' => 20,         'pad_left' => 20,
'link_base' => '/',        'link_target' => '_top',
'show_labels' => true,     'show_label_amount' => true,
'label_font' => 'Arial', 'label_font_size' => '11',
'label_colour' => '#fff', 
'sort' => false
);

$values = array('Dough' => 30, 'Ray' => 50, 'Me' => 40, 'So' => 25, 'Far' => 45,
'Lard' => 35);

$colours = array('#ccf','#699','#93c','#996','#f39','#0f3','#339');
$links = array('Dough' => 'jpegsaver.php', 'Ray' => 'crcdropper.php',
'Me' => 'svggraph.php');

$graph = new SVGGraph(600, 600, $settings);
$graph->colours = $colours;

$graph->Values($chart_value_year_distribution);
$graph->Links($links);
$graph->Render('DonutGraph');

echo "</div>";


echo "<br>&nbsp;<br>&nbsp;";
echo "<br>&nbsp;<br>&nbsp;";
echo "<br>&nbsp;<br>&nbsp;";

    echo "</section>";





?>