<?php

$addon_path="../../";

include $addon_path."includes/config.php";
include $addon_path."includes/database.php";
include $addon_path."includes/keyword.php";
include $addon_path."includes/function.php";

$addon_path="";


require('../fpdf16/fpdf.php');


//============Date Gathering start===================================================================


//formating-----------------------------------------------------------------------------------
$doc_paper_size=$_REQUEST["s"]; //A4 or Letter

//parameter-----------------------------------------------------------------------------------	
$selected_date_start_simple = $_REQUEST["start"];
$selected_date_end_simple = $_REQUEST["end"];


$selected_date_start=$selected_date_start_simple." 00:00:00";
$selected_date_end=$selected_date_end_simple." 23:59:59";



//title---------------------------------------------------------------------------------------
$doc_title="Monthly Sales Summary Report";


//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"];
}


//device library:
$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))
{
	
	$staff_data[$line_staff["stf_code"]]=$line_staff["stf_name"];
}





$i=0;



//=============================A; Summary by Device====================================================================
if(($_REQUEST["part"]=="")or($_REQUEST["part"]=="SUM_DEV"))
{
	$query="select 
			sum(ivh_discount_total) as ivh_discount_total,
			sum(ivh_total_before_gst) as ivh_total_before_gst,
			sum(ivh_gst_amount) as ivh_gst_amount,
			sum(ivh_total_amount) as ivh_total_amount,
			
			sum(ivh_rounding_amount) as ivh_rounding_amount,
			sum(ivh_total_amount_rounded) as ivh_total_amount_rounded,
			device_id 
			
			from t_".$key_table_prefix."_invoice_header 
			where ivh_status = 'POSTED'
			and ivh_date >= '".$selected_date_start_simple."'
			and ivh_date <= '".$selected_date_end_simple."'
			group by device_id
			
			";		
	$result = mysqli_query($dbconn,$query);
	while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
	{
		$report_data[$line["device_id"]] = $line;
				
	}
	
	
	$data[$i][0] = "";
	$i++;
	
	$data_width_this_part[0]=40;
	$data_width_this_part[1]=25;
	$data_width_this_part[2]=25;
	$data_width_this_part[3]=25;
	$data_width_this_part[4]=25;
	$data_width_this_part[5]=25;
	$data_width_this_part[6]=25;
	//$data_width_this_part[7]=20;
	//$data_width_this_part[8]=20;
	//$data_width_this_part[9]=20;
	
	$data_align_this_part[0]="L";
	$data_align_this_part[1]="R";
	$data_align_this_part[2]="R";
	$data_align_this_part[3]="R";
	$data_align_this_part[4]="R";
	$data_align_this_part[5]="R";
	$data_align_this_part[6]="R";
	//$data_width_this_part[7]=20;
	//$data_width_this_part[8]=20;
	//$data_width_this_part[9]=20;
	
	
	//---------------------------------------------------------------------------
	//title:
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;
	
	$data_font_size[$i]="BIG";
	$data_bold[$i]="YES";
	$data[$i][0] = "Sales Summary by Device";
	$i++;
	
	
	$data[$i][0] = "<line>";
	$i++;	
	
	//header----
	$data_bold[$i]="YES";
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;
	
	$data[$i][0] = "Device";
	$data[$i][1] = "Discount Amount";
	$data[$i][2] = "Before Tax";
	
	$data[$i][3] = "Tax Amount";
	$data[$i][4] = "Total Amount";
	$data[$i][5] = "Rounding Amount";
	$data[$i][6] = "Amount Rounded";
	$i++;
		
		
	$data[$i][0] = "<line>";
	$i++;	
	
	foreach($report_data as $report_key => $report_value)
	{
		$data_width[$i] = $data_width_this_part;
		$data_align[$i] = $data_align_this_part;
		
		
		$data[$i][0] = $device_data[$report_key];
		$data[$i][1] = $report_value["ivh_discount_total"];
		$data[$i][2] = $report_value["ivh_total_before_gst"];
		
		$data[$i][3] = $report_value["ivh_gst_amount"];
		$data[$i][4] = $report_value["ivh_total_amount"];
		$data[$i][5] = $report_value["ivh_rounding_amount"];
		$data[$i][6] = $report_value["ivh_total_amount_rounded"];
		
		
		
		$sum_discount_total = $sum_discount_total + $report_value["ivh_discount_total"];
		$sum_total_before_gst = $sum_total_before_gst + $report_value["ivh_total_before_gst"];
		$sum_gst_amount = $sum_gst_amount + $report_value["ivh_gst_amount"];
		$sum_total_amount = $sum_total_amount + $report_value["ivh_total_amount"];
		$sum_rounding_amount = $sum_rounding_amount + $report_value["ivh_rounding_amount"];
		$sum_total_amount_rounded = $sum_total_amount_rounded + $report_value["ivh_total_amount_rounded"];
		
		
		$counter++;
		$i++;
		
	}	
	
	
	//footer----
	$data[$i][0] = "<line>";
	$i++;	
	
	
	$data_bold[$i]="YES";
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;
	
	$data[$i][0] = "Total";
	$data[$i][1] = number_format($sum_discount_total,2,".",",");
	$data[$i][2] = number_format($sum_total_before_gst,2,".",",");
	
	$data[$i][3] = number_format($sum_gst_amount,2,".",",");
	$data[$i][4] = number_format($sum_total_amount,2,".",",");
	$data[$i][5] = number_format($sum_rounding_amount,2,".",",");
	$data[$i][6] = number_format($sum_total_amount_rounded,2,".",",");
	$i++;
		
		
	$data[$i][0] = "<line>";
	$i++;	
	
	
	
}
	
	
	
	
	
//=============================B: Summary by Staff====================================================================
if(($_REQUEST["part"]=="")or($_REQUEST["part"]=="SUM_STF"))
{
	unset($report_data_salesperson);	
			
	$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_salesperson
			
			
			from t_".$key_table_prefix."_invoice_item
			where ivi_status = 'POSTED'
			and created_date >= '".$selected_date_start."'
			and created_date <= '".$selected_date_end."'
			group by ivi_salesperson
			order by ivi_salesperson
			
			";		
			
			
			
			
	$result = mysqli_query($dbconn,$query);
	while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
	{
		if($line["ivi_salesperson"]=="")
		{
			$line["ivi_salesperson"]="Unspecified";
		}
	
		$report_data_salesperson[$line["ivi_salesperson"]] = $line;		
			
			
			
	}

	
	
	$data_width[$i] = $data_width_this_part;
	$data[$i][0] = "";
	$i++;
	
	$data_width[$i] = $data_width_this_part;
	$data[$i][0] = "";
	$i++;
	
	$data_width_this_part[0]=40;
	$data_width_this_part[1]=25;
	$data_width_this_part[2]=25;
	$data_width_this_part[3]=25;
	//$data_width_this_part[4]=25;
	//$data_width_this_part[5]=25;
	//$data_width_this_part[6]=25;
	//$data_width_this_part[7]=20;
	//$data_width_this_part[8]=20;
	//$data_width_this_part[9]=20;
	
	$data_align_this_part[0]="L";
	$data_align_this_part[1]="R";
	$data_align_this_part[2]="R";
	$data_align_this_part[3]="R";
	//$data_align_this_part[4]="R";
	//$data_align_this_part[5]="R";
	//$data_align_this_part[6]="R";
	//$data_width_this_part[7]=20;
	//$data_width_this_part[8]=20;
	//$data_width_this_part[9]=20;
	
	
	//---------------------------------------------------------------------------
	//title:
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;
	
	$data_font_size[$i]="BIG";
	$data_bold[$i]="YES";
	$data[$i][0] = "Sales Summary by Staff";
	$i++;
	
	
	$data[$i][0] = "<line>";
	$data[$i][1] = 115;
	$i++;	
	
	//header----
	$data_bold[$i]="YES";
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;
	
	$data[$i][0] = "Staff Code";
	$data[$i][1] = "Quantity";
	$data[$i][2] = "Total Discount";
	$data[$i][3] = "Total Amount";
	$i++;
		
		
	$data[$i][0] = "<line>";
	$data[$i][1] = 115;
	$i++;	
	
	$sum_product_quantity=0;
	$sum_product_discount=0;
	$sum_product_amount=0;
	
	
	foreach($report_data_salesperson as $salesperson_key => $report_data_product2)
	{
		$data_width[$i] = $data_width_this_part;
		$data_align[$i] = $data_align_this_part;
		
		
		
			
		$data[$i][0] = $salesperson_key." ".$staff_data[$salesperson_key];
		$data[$i][1] = $report_data_product2["ivi_quantity"];
		$data[$i][2] = $report_data_product2["ivi_discount"];
		$data[$i][3] = $report_data_product2["ivi_total_amount"];
		
		$sum_product_quantity = $sum_product_quantity + $report_data_product2["ivi_quantity"];
		$sum_product_discount = $sum_product_discount + $report_data_product2["ivi_discount"];
		$sum_product_amount = $sum_product_amount+ $report_data_product2["ivi_total_amount"];
	
		
		$counter++;
		$i++;
		
	}	
	
	
	//footer----
	$data[$i][0] = "<line>";
	$data[$i][1] = 115;
	$i++;	
	
	
	$data_bold[$i]="YES";
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;
	
	$data[$i][0] = "Total";
	$data[$i][1] = number_format($sum_product_quantity,2,".",",");
	$data[$i][2] = number_format($sum_product_discount,2,".",",");
	$data[$i][3] = number_format($sum_product_amount,2,".",",");
	
	$i++;
		
		
	$data[$i][0] = "<line>";
	$data[$i][1] = 115;
	$i++;	
	
	
	
}
	
	    
	   


//=============================C: Summary by Device/Product====================================================================
if(($_REQUEST["part"]=="")or($_REQUEST["part"]=="SUM_DEV_PDT"))
{
	$query="select 
			
			sum(ivi_quantity) as ivi_quantity,
			sum(ivi_discount_total) as ivi_discount_total,
			sum(ivi_total_amount) as ivi_total_amount,
			
			
			device_id, ivi_product_code, ivi_product_name
			
			
			from t_".$key_table_prefix."_invoice_item
			where ivi_status = 'POSTED'
			and created_date >= '".$selected_date_start."'
			and created_date <= '".$selected_date_end."'
			group by device_id, ivi_product_code, ivi_product_name
			order by device_id, ivi_product_code, ivi_product_name
			
			";		
	$result = mysqli_query($dbconn,$query);
	while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
	{
		
		$report_data_product[$line["device_id"]][$line["ivi_product_code"]] = $line;		
		
	}


$data_width[$i] = $data_width_this_part;
$data[$i][0] = "";
$i++;

$data_width[$i] = $data_width_this_part;
$data[$i][0] = "";
$i++;

$data_width_this_part[0]=40;
$data_width_this_part[1]=75;
$data_width_this_part[2]=25;
$data_width_this_part[3]=25;
$data_width_this_part[4]=25;
//$data_width_this_part[5]=25;
//$data_width_this_part[6]=25;
//$data_width_this_part[7]=20;
//$data_width_this_part[8]=20;
//$data_width_this_part[9]=20;

$data_align_this_part[0]="L";
$data_align_this_part[1]="L";
$data_align_this_part[2]="R";
$data_align_this_part[3]="R";
$data_align_this_part[4]="R";
//$data_align_this_part[4]="R";
//$data_align_this_part[5]="R";
//$data_align_this_part[6]="R";
//$data_width_this_part[7]=20;
//$data_width_this_part[8]=20;
//$data_width_this_part[9]=20;


//---------------------------------------------------------------------------
//title:
$data_width[$i] = $data_width_this_part;
$data_align[$i] = $data_align_this_part;

$data_font_size[$i]="BIG";
$data_bold[$i]="YES";
$data[$i][0] = "Sales Summary by Device/Product";
$i++;


$data[$i][0] = "<line>";
$data[$i][1] = 190;
$i++;	

//header----
$data_bold[$i]="YES";
$data_width[$i] = $data_width_this_part;
$data_align[$i] = $data_align_this_part;

$data[$i][0] = "Product Code";
$data[$i][1] = "Product Name";
$data[$i][2] = "Quantity";
$data[$i][3] = "Total Discount";
$data[$i][4] = "Total Amount";
$i++;
	
	
$data[$i][0] = "<line>";
$data[$i][1] = 190;
$i++;	


	

		$sum_product_quantity=0;
		$sum_product_discount=0;
		$sum_product_amount=0;
		
		
		
		
foreach($report_data_product as $device_key => $report_data_product2)
{
	
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;
	
	$data_bold[$i]="YES";
	$data[$i][0] = $device_data[$device_key];
	$i++;
	
	
	
	
	$sub_sum_product_quantity=0;
	$sub_sum_product_discount=0;
	$sub_sum_product_amount=0;
	
	
	foreach($report_data_product[$device_key] as $product_code => $report_data_product3)
	{
		
		$data_width[$i] = $data_width_this_part;
		$data_align[$i] = $data_align_this_part;
		
		
		
			
		$data[$i][0] = $product_code;
		$data[$i][1] = $report_data_product3["ivi_product_name"];
		$data[$i][2] = $report_data_product3["ivi_quantity"];
		$data[$i][3] = $report_data_product3["ivi_discount"];
		$data[$i][4] = $report_data_product3["ivi_total_amount"];
		
		$sum_product_quantity = $sum_product_quantity + $report_data_product3["ivi_quantity"];
		$sub_sum_product_quantity = $sub_sum_product_quantity + $report_data_product3["ivi_quantity"];

		$sum_product_discount = $sum_product_discount + $report_data_product3["ivi_discount"];
		$sub_sum_product_discount = $sub_sum_product_discount + $report_data_product3["ivi_discount"];

		$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"];


		
		$counter++;
		$i++;
		
	}
	
	
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;
	
	$data_bold[$i]="YES";
	$data[$i][0] = "";
	$data[$i][1] = "Sub-Total";
	$data[$i][2] = number_format($sub_sum_product_quantity,2,".",",");
	$data[$i][3] = number_format($sub_sum_product_discount,2,".",",");
	$data[$i][4] = number_format($sub_sum_product_amount,2,".",",");
	
	$i++;
	
	
	
	
	
}	


//footer----
$data[$i][0] = "<line>";
$data[$i][1] = 190;
$i++;	

$data_bold[$i]="YES";
$data_width[$i] = $data_width_this_part;
$data_align[$i] = $data_align_this_part;

$data[$i][0] = "Total";
$data[$i][1] = "";
$data[$i][2] = number_format($sum_product_quantity,2,".",",");
$data[$i][3] = number_format($sum_product_discount,2,".",",");
$data[$i][4] = number_format($sum_product_amount,2,".",",");

$i++;
	
	
$data[$i][0] = "<line>";
$data[$i][1] = 190;
$i++;	



}

    
   
	
	    

















//=============================D: Summary by Staff/Product====================================================================
if(($_REQUEST["part"]=="")or($_REQUEST["part"]=="SUM_STF_PDT"))
{
	
	
	unset($report_data_salesperson);
	
		
	$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_salesperson, ivi_product_code, ivi_product_name
			
			
			from t_".$key_table_prefix."_invoice_item
			where ivi_status = 'POSTED'
			and created_date >= '".$selected_date_start."'
			and created_date <= '".$selected_date_end."'
			group by ivi_salesperson, ivi_product_code, ivi_product_name
			order by ivi_salesperson, ivi_product_code, ivi_product_name
			
			";		
	$result = mysqli_query($dbconn,$query);
	while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
	{
		
		$report_data_salesperson[$line["ivi_salesperson"]][$line["ivi_product_code"]] = $line;		
		
	}




	$data_width[$i] = $data_width_this_part;
	$data[$i][0] = "";
	$i++;

	$data_width[$i] = $data_width_this_part;
	$data[$i][0] = "";
	$i++;

	$data_width_this_part[0]=40;
	$data_width_this_part[1]=75;
	$data_width_this_part[2]=25;
	$data_width_this_part[3]=25;
	$data_width_this_part[4]=25;
	//$data_width_this_part[5]=25;
	//$data_width_this_part[6]=25;
	//$data_width_this_part[7]=20;
	//$data_width_this_part[8]=20;
	//$data_width_this_part[9]=20;

	$data_align_this_part[0]="L";
	$data_align_this_part[1]="L";
	$data_align_this_part[2]="R";
	$data_align_this_part[3]="R";
	$data_align_this_part[4]="R";
	//$data_align_this_part[4]="R";
	//$data_align_this_part[5]="R";
	//$data_align_this_part[6]="R";
	//$data_width_this_part[7]=20;
	//$data_width_this_part[8]=20;
	//$data_width_this_part[9]=20;


	//---------------------------------------------------------------------------
	//title:
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;

	$data_font_size[$i]="BIG";
	$data_bold[$i]="YES";
	$data[$i][0] = "Sales Summary by Staff/Product";
	$i++;


	$data[$i][0] = "<line>";
	$data[$i][1] = 190;
	$i++;	

	//header----
	$data_bold[$i]="YES";
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;

	$data[$i][0] = "Staff Code";
	$data[$i][1] = "Product Name";
	$data[$i][2] = "Quantity";
	$data[$i][3] = "Total Discount";
	$data[$i][4] = "Total Amount";
	$i++;


	$data[$i][0] = "<line>";
	$data[$i][1] = 190;
	$i++;	




	 $sum_product_quantity=0;
	 $sum_product_discount=0;
	 $sum_product_amount=0;
	 
	 
	 
	 
	 foreach($report_data_salesperson as $salesperson_key => $report_data_product2)
	 {

		$data_width[$i] = $data_width_this_part;
		$data_align[$i] = $data_align_this_part;

		$data_bold[$i]="YES";
		$data[$i][0] = $salesperson_key." ".$staff_data[$salesperson_key];
		$i++;




		$sub_sum_product_quantity=0;
		$sub_sum_product_discount=0;
		$sub_sum_product_amount=0;


		foreach($report_data_salesperson[$salesperson_key] as $product_code => $report_data_product3)
		{
		 
		 $data_width[$i] = $data_width_this_part;
		 $data_align[$i] = $data_align_this_part;
		 
		 
		 
			 
		 $data[$i][0] = $product_code;
		 $data[$i][1] = $report_data_product3["ivi_product_name"];
		 $data[$i][2] = $report_data_product3["ivi_quantity"];
		 $data[$i][3] = $report_data_product3["ivi_discount"];
		 $data[$i][4] = $report_data_product3["ivi_total_amount"];
		 
		 $sum_product_quantity = $sum_product_quantity + $report_data_product3["ivi_quantity"];
		 $sub_sum_product_quantity = $sub_sum_product_quantity + $report_data_product3["ivi_quantity"];

		 $sum_product_discount = $sum_product_discount + $report_data_product3["ivi_discount"];
		 $sub_sum_product_discount = $sub_sum_product_discount + $report_data_product3["ivi_discount"];

		 $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"];


		 
		 $counter++;
		 $i++;
		 
		}


		$data_width[$i] = $data_width_this_part;
		$data_align[$i] = $data_align_this_part;

		$data_bold[$i]="YES";
		$data[$i][0] = "";
		$data[$i][1] = "Sub-Total";
		$data[$i][2] = number_format($sub_sum_product_quantity,2,".",",");
		$data[$i][3] = number_format($sub_sum_product_discount,2,".",",");
		$data[$i][4] = number_format($sub_sum_product_amount,2,".",",");

		$i++;





		}	


	//footer----
	$data[$i][0] = "<line>";
	$data[$i][1] = 190;
	$i++;	
	
	$data_bold[$i]="YES";
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;

	$data[$i][0] = "Total";
	$data[$i][1] = "";
	$data[$i][2] = number_format($sum_product_quantity,2,".",",");
	$data[$i][3] = number_format($sum_product_discount,2,".",",");
	$data[$i][4] = number_format($sum_product_amount,2,".",",");

	$i++;


	$data[$i][0] = "<line>";
	$data[$i][1] = 190;
	$i++;	



}










//=============================A; Summary by Device====================================================================
if(($_REQUEST["part"]=="")or($_REQUEST["part"]=="SUM_DAY"))
{
	unset($report_data);
	
	
	$sum_discount_total= 0;
	$sum_total_before_gst = 0;
	
	$sum_gst_amount = 0;
	$sum_total_amount = 0;
	$sum_rounding_amount = 0;
	$sum_total_amount_rounded = 0;
	
	
	
	
	$data_width[$i] = $data_width_this_part;
	$data[$i][0] = "";
	$i++;

	$data_width[$i] = $data_width_this_part;
	$data[$i][0] = "";
	$i++;
	
	
	$query="select 
			sum(ivh_discount_total) as ivh_discount_total,
			sum(ivh_total_before_gst) as ivh_total_before_gst,
			sum(ivh_gst_amount) as ivh_gst_amount,
			sum(ivh_total_amount) as ivh_total_amount,
			
			sum(ivh_rounding_amount) as ivh_rounding_amount,
			sum(ivh_total_amount_rounded) as ivh_total_amount_rounded,
			ivh_date 
			
			from t_".$key_table_prefix."_invoice_header 
			where ivh_status = 'POSTED'
			and ivh_date >= '".$selected_date_start_simple."'
			and ivh_date <= '".$selected_date_end_simple."'
			group by ivh_date
			order by ivh_date
			
			";		
	$result = mysqli_query($dbconn,$query);
	while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
	{
		$report_data[$line["ivh_date"]] = $line;
				
	}
	
	
	$data[$i][0] = "";
	$i++;
	
	$data_width_this_part[0]=40;
	$data_width_this_part[1]=25;
	$data_width_this_part[2]=25;
	$data_width_this_part[3]=25;
	$data_width_this_part[4]=25;
	$data_width_this_part[5]=25;
	$data_width_this_part[6]=25;
	//$data_width_this_part[7]=20;
	//$data_width_this_part[8]=20;
	//$data_width_this_part[9]=20;
	
	$data_align_this_part[0]="L";
	$data_align_this_part[1]="R";
	$data_align_this_part[2]="R";
	$data_align_this_part[3]="R";
	$data_align_this_part[4]="R";
	$data_align_this_part[5]="R";
	$data_align_this_part[6]="R";
	//$data_width_this_part[7]=20;
	//$data_width_this_part[8]=20;
	//$data_width_this_part[9]=20;
	
	
	//---------------------------------------------------------------------------
	//title:
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;
	
	$data_font_size[$i]="BIG";
	$data_bold[$i]="YES";
	$data[$i][0] = "Sales Summary by Day";
	$i++;
	
	
	$data[$i][0] = "<line>";
	$i++;	
	
	//header----
	$data_bold[$i]="YES";
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;
	
	$data[$i][0] = "Day";
	$data[$i][1] = "Discount Amount";
	$data[$i][2] = "Before GST";
	
	$data[$i][3] = "GST Amount";
	$data[$i][4] = "Total Amount";
	$data[$i][5] = "Rounding Amount";
	$data[$i][6] = "Amount Rounded";
	$i++;
		
		
	$data[$i][0] = "<line>";
	$i++;	
	
	foreach($report_data as $report_key => $report_value)
	{
		$data_width[$i] = $data_width_this_part;
		$data_align[$i] = $data_align_this_part;
		
		
		$data[$i][0] = $report_key;
		$data[$i][1] = $report_value["ivh_discount_total"];
		$data[$i][2] = $report_value["ivh_total_before_gst"];
		
		$data[$i][3] = $report_value["ivh_gst_amount"];
		$data[$i][4] = $report_value["ivh_total_amount"];
		$data[$i][5] = $report_value["ivh_rounding_amount"];
		$data[$i][6] = $report_value["ivh_total_amount_rounded"];
		
		
		
		$sum_discount_total = $sum_discount_total + $report_value["ivh_discount_total"];
		$sum_total_before_gst = $sum_total_before_gst + $report_value["ivh_total_before_gst"];
		$sum_gst_amount = $sum_gst_amount + $report_value["ivh_gst_amount"];
		$sum_total_amount = $sum_total_amount + $report_value["ivh_total_amount"];
		$sum_rounding_amount = $sum_rounding_amount + $report_value["ivh_rounding_amount"];
		$sum_total_amount_rounded = $sum_total_amount_rounded + $report_value["ivh_total_amount_rounded"];
		
		
		$counter++;
		$i++;
		
	}	
	
	
	//footer----
	$data[$i][0] = "<line>";
	$i++;	
	
	
	$data_bold[$i]="YES";
	$data_width[$i] = $data_width_this_part;
	$data_align[$i] = $data_align_this_part;
	
	$data[$i][0] = "Total";
	$data[$i][1] = number_format($sum_discount_total,2,".",",");
	$data[$i][2] = number_format($sum_total_before_gst,2,".",",");
	
	$data[$i][3] = number_format($sum_gst_amount,2,".",",");
	$data[$i][4] = number_format($sum_total_amount,2,".",",");
	$data[$i][5] = number_format($sum_rounding_amount,2,".",",");
	$data[$i][6] = number_format($sum_total_amount_rounded,2,".",",");
	$i++;
		
		
	$data[$i][0] = "<line>";
	$i++;	
	
	
	
}
	
	
	
	

//bottom----------------------------------------------------------------------------------------
$doc_time_stamp=date("Y-m-d H:m:s");
$doc_user=$CurrentUserFullName;






//technical--------------------------------------------------------------------------------------
$doc_debug_line=0;




//============printing start===================================================================
class PDF extends FPDF
{
		
		//Page header
		function Header()
		{
			global $sys_system_master_setting_line;
			global $doc_debug_line;
			global $doc_title;
			global $selected_date_start_simple, $selected_date_end_simple;
		 	
			global $dbconn;
		 	global $table_header;
		 	global $key_table_prefix;
		 	global $data,$data_bold;
		 	 
		 	 
			//include '../letter_head.php';    
			//$this->Ln(5);
		
		    //line 1======================
			
		   	$this->SetFont('Arial','',13);
		   	$this->SetFont('','B');
			$this->Cell(190,5,$doc_title,$doc_debug_line,10,'L');
			$this->SetFont('','');
			$this->Ln(0);
		    
		  
			 
			//Draw Line Item Table Header====================================== 
		 	$this->SetFillColor(255,255,255);
			$this->SetTextColor(0);
			    //$this->SetDrawColor(128,0,0);
			$this->SetDrawColor(0,0,0);		    
			
			$this->SetLineWidth(.3);
			$this->SetFont('','B');
			//Header

			
			$this->SetFont('Arial','',8);
			$this->Ln(0);
			$this->Cell(190,5,"From ".$selected_date_start_simple." To ".$selected_date_end_simple."","0",0,'L',true);
			
			$this->Ln(5);
		    
		    
		}

		//Page footer
		function Footer()
		{	
		 
			global $doc_time_stamp,$doc_user,$doc_print_count;
		 	
			//Position at 1.5 cm from bottom
			$this->SetY(-15);
		    
			//Arial italic 8
			$this->SetFont('Arial','I',8);
			
			//Footer (Page Number / timestamp)
			$this->Cell(100,10,"Printed on ".$doc_time_stamp." ".$doc_user.'',0,0,'L');
			$this->Cell(90,10,"Page: ".$this->PageNo()." of {nb}",0,0,'R');
		    
		}
		

		
		function render_grid()
		{
			global $data;			
			global $data_bold;
			global $data_font_size;
			global $data_width;
			global $data_align;
			
			
			
			
			
			$this->SetLineWidth(.3);
			$this->SetFillColor(245,245,245);
			$this->SetTextColor(0);
			$this->SetFont('Arial','',9);
			
			
			
			$fill=false;
			foreach($data as $key=>$row)
			{
				
				$w = $data_width[$key];
				$align = $data_align[$key];
				
				
				
				
				if($row[0]=="<line>")
				{
					if($row[0]!="")
					{
						$length = $row[1];	
					}
					else {
						$length = 190;
					}
					
					$fill=false;
					$this->Cell($length,0,"","B",0,'L',$fill);
					$this->Ln();	
					$item_text_line++;
				}
				else
				{
					
					if($data_bold[$key]=="YES")
					{
						$this->SetFont('Arial','B',7);
						if($data_font_size[$key] =="SMALL")
						{
							$this->SetFont('Arial','B',6);	
						}
						if($data_font_size[$key] =="BIG")
						{
							$this->SetFont('Arial','B',10);	
						}
					}
					else
					{
						$this->SetFont('Arial','',7);
						if($data_font_size[$key] =="SMALL")
						{
							$this->SetFont('Arial','',6);	
						}
						if($data_font_size[$key] =="BIG")
						{
							$this->SetFont('Arial','',10);	
						}
					}
					
					
					
					
					foreach($row as $col => $col_value)
					{
						if($w[$col]>0)
						{
								$this->Cell($w[$col],5,$row[$col],"0",0,$align[$col],$fill);
						}
						
						
					}
					
					$this->Ln();	
					
							
					$item_text_line++;
					//$fill=!$fill;
				}
							
				
					
			
			
			  
			}
			//$this->Cell(array_sum($w),0,'','T');
		}

}

//Instanciation of inherited class


$pdf=new PDF();

$pdf->AliasNbPages();
$pdf->AddPage('P',$doc_paper_size);
$pdf->SetFont('Arial','',8);





$pdf->SetFont('Arial','',8);


$pdf->render_grid();



$pdf->Ln();
//Draw Line Item Table Header====================================== 
$pdf->SetFillColor(255,255,255);
$pdf->SetTextColor(0);
    //$this->SetDrawColor(128,0,0);
$pdf->SetDrawColor(0,0,0);		    

$pdf->SetLineWidth(.3);
$pdf->SetFont('','B');
//Header
/*
$w=array(170,20);
$pdf->Cell($w[0],7,$table_footer[0],"T",0,'R',true);
$pdf->Cell($w[1],7,$table_footer[1],"T",0,'R',true);
$pdf->Ln(7);
*/		    
		    
$pdf->Ln(10);
    
		    
$pdf->Output();




?>