<?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
if($_REQUEST["s"]=="A4")
{
	$doc_table_format=''; //COLOR or blank
}
else
{
	$doc_table_format=''; //COLOR or blank
}

$doc_title="Event Order";

//bottom----------------------------------------------------------------------------------------

$doc_time_stamp=date("Y-m-d H:m:s");







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

//============printing start===================================================================

class PDF extends FPDF
{
		
		//Page header
		function Header()
		{
			global $doc_title;
			$this->Ln(0);
		   	$this->SetFont('Arial','',16);
		   	$this->SetFont('','B');
			$this->SetLineWidth(0.3);
			$this->Cell(190,10,$doc_title,"B",10,'C');
			$this->SetFont('','');
			$this->Ln(0);
			$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);
			$this->Cell(100,10,"Printed on ".$doc_time_stamp."  ".$doc_user.'',0,0,'L');
			$this->Cell(90,10,"Page ".$this->PageNo()." of {nb}",$doc_debug_line,10,'R');
		}
		



		function DrawContent()
		{
			
			global $key_table_prefix;
			global $currency_symbol;
			
			
			
			$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"];
				
			}
			
			
			
			$query_session="select * from t_".$key_table_prefix."_event_session 
			    where ses_event_id = '".$_REQUEST["evt_id"]."' ";
		    $result_session = mysqli_query($dbconn,$query_session);
		    while($line_session = mysqli_fetch_array($result_session,MYSQLI_ASSOC))
		    {
			    
			    $session_date[$line_session["ses_id"]] = $line_session["ses_date"];
			    
		    }
		    
			
			
		    
		 
			
			$query = "select * from t_".$key_table_prefix."_event_order where evt_id = '".$_REQUEST["evt_id"]."' ";
			$result = mysqli_query($dbconn,$query);
			if($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
			{
				
				
				
				//=================================================================================
				if($_REQUEST["show_event_order"]=="YES")
				{	
					
					$this->AddPage('P',$doc_paper_size);
					
					
					$line_height=4;
					
					$this->SetLineWidth(.3);
					$this->SetFillColor(245,245,245);
					$this->SetTextColor(0);
					
					
					$this->SetFillColor(230,230,230);
					
					$this->SetLineWidth(0.2);
					$this->SetFont('Arial','',9);
					
					
					$this->Cell(40,$line_height,"Event Order:","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_doc_no"],"TRB",0,'L',false);
					$this->Cell(40,$line_height,"Event Order Status:","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_status"],"TRB",0,'L',false);
					$this->Ln();		
					
					
					$this->Cell(40,$line_height,"Date","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_start_date"]." to ".$line["evt_end_date"]."","TRB",0,'L',false);
					$this->Cell(95,$line_height,"Organizer: ".$line["evt_customer_name"],"1",0,'L',false);
					$this->Ln();		
					
					
					
					
					$evt_y=substr($line["evt_start_date"],4,0);
					$evt_m=substr($line["evt_start_date"],5,2);
					$evt_d=substr($line["evt_start_date"],8,2);
					
					
					
					
					
					$event_day=date("l",mktime(0,0,0,$evt_y,$evt_y,$evt_y));
					
					$address_line1="1232131";
					$address_line2="312321";
					
					$this->Cell(40,$line_height,"Day","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"<content>","TRB",0,'L',false);
					$this->Cell(25,$line_height,"Address: ","TRL",0,'L',false);
					$this->Cell(70,$line_height,$address_line1,"TRL",0,'L',false);
					$this->Ln();		
					
					$this->Cell(40,$line_height,"Venue","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,$line["evt_venue_name"],"TRB",0,'L',false);
					$this->Cell(25,$line_height," ","BLR",0,'L',false);
					$this->Cell(70,$line_height,$address_line2,"BLR",0,'L',false);
					$this->Ln();		
					
					
					$this->Cell(40,$line_height,"Time","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_start_time"]." to ".$line["evt_end_time"]."","TRB",0,'L',false);
					$this->Cell(45,$line_height,"Tel. No.","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'L',false);
					$this->Cell(45,$line_height,$line["evt_customer_mobile_no"]." / ".$line["evt_customer_telephone_no"],"TBR",0,'L',false);
					$this->Ln();		
					
					
					$this->Cell(40,$line_height,"Nature","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,$line["evt_nature_name"],"TRB",0,'L',false);
					$this->Cell(45,$line_height,"Fax No.","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'L',false);
					$this->Cell(45,$line_height,$line["evt_customer_fax_no"],"TBR",0,'L',false);
					$this->Ln();		
					
					$this->Cell(40,$line_height,"No. Table Guaranteed","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,$line["evt_table_qty_guaranteed"],"TRB",0,'L',false);
					$this->Cell(45,$line_height,"Person In-Charge","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'L',false);
					$this->Cell(45,$line_height,$line["evt_customer_contact_person"],"TBR",0,'L',false);
					$this->Ln();		
					
					
					
					$this->Cell(40,$line_height,"No. Table Expected","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,$line["evt_table_qty_expected"],"TRB",0,'L',false);
					$this->Cell(45,$line_height,"Reservation Made By","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'L',false);
					$this->Cell(45,$line_height,$line["evt_reservation_made_person"],"TBR",0,'L',false);
					$this->Ln();	
					
					$this->Cell(40,$line_height,"","0",0,'L',false);
					$this->Cell(5,$line_height,"","0",0,'c',false);
					$this->Cell(50,$line_height,"","0",0,'L',false);
					$this->Cell(45,$line_height,"Accepted By","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'L',false);
					$this->Cell(45,$line_height,$line["evt_reservation_accept_person"],"TBR",0,'L',false);
					$this->Ln();	
					
					
					$this->Cell(40,$line_height,"","0",0,'L',false);
					$this->Cell(5,$line_height,"","0",0,'c',false);
					$this->Cell(50,$line_height,"","0",0,'L',false);
					$this->Cell(45,$line_height,"Cancelled By","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'L',false);
					$this->Cell(45,$line_height,$line["evt_reservation_cancel_person"],"TBR",0,'L',false);
					$this->Ln();	
					
					
					
					
					
					
					//================================================================================
					$this->Ln();
					
					$this->SetFont('Arial','B',10);
					$this->SetFillColor(210,210,210);
					
					$this->Cell(95,$line_height,"Billing Instruction","1",0,'C',true);
					$this->Cell(95,$line_height,"Cost Breakdown","1",0,'C',true);
					$this->Ln();
					
					
					$this->SetFont('Arial','',9);
					$this->SetFillColor(230,230,230);
					
					
					$this->Cell(40,$line_height,"Bill to","TL",0,'L',false);
					$this->Cell(5,$line_height,":","T",0,'c',false);
					$this->Cell(50,$line_height,$line["evt_bill_to_name"],"TR",0,'L',false);
					$this->Cell(95,$line_height,"","TLR",0,'L',false);
					$this->Ln();
					
					
					$this->Cell(40,$line_height,"","BL",0,'L',false);
					$this->Cell(5,$line_height,"","B",0,'c',false);
					$this->Cell(50,$line_height,"","BR",0,'L',false);
					$this->Cell(95,$line_height,"","BLR",0,'L',false);
					$this->Ln();
					
					
					$query_payment_mode ="select pym_name from t_".$key_table_prefix."_payment_mode where pym_code = '".$line["evt_payment_mode"]."' ";
					$result_payment_mode = mysqli_query($dbconn,$query_payment_mode);
					if($line_payment_mode = mysqli_fetch_array($result_payment_mode,MYSQLI_ASSOC))
					{
						
						$pym_name=$line_payment_mode["pym_name"];
					}
					
					
					
					$this->Cell(40,$line_height,"Payment Mode","1",0,'L',true);
					$this->Cell(5,$line_height,":","1",0,'c',false);
					$this->Cell(50,$line_height,$pym_name,"1",0,'L',false);
					$this->SetFont('Arial','B',10);
					$this->SetFont('Arial','B',10);
					$this->SetFillColor(210,210,210);
					
					$this->Cell(95,$line_height,"BACKDROP","1",0,'C',true);
					$this->SetFont('Arial','',9);
					$this->Ln();	
					
				
				
					$this->SetFillColor(230,230,230);
					
					
					$first_payment="";
					
					$query_payment="select * from t_".$key_table_prefix."_event_collection
							where ecl_event_id = '".$line["evt_id"]."' order by ecl_id limit 0, 1 ";
					$result_payment = mysqli_query($dbconn,$query_payment);	
					if($line_payment = mysqli_fetch_array($result_payment , MYSQLI_ASSOC))
					{
						
						$first_payment= $currency_symbol." ".$line_payment["ecl_amount"]." (".$line_payment["ecl_date"].")";
						
					}	
				
					
					$this->Cell(40,$line_height,"Deposit/Collection","1",0,'L',true);
					$this->Cell(5,$line_height,":","1",0,'c',false);
					$this->Cell(50,$line_height,$first_payment,"1",0,'L',false);
					$this->Cell(95,$line_height,"","BLR",0,'L',false);
					$this->Ln();	
					
					
					
					
					//================================================================================
					
					
					
					$this->Ln();
					$this->SetFont('Arial','B',10);
					$this->SetFillColor(210,210,210);
					$this->Cell(95,$line_height,"Task/Requirement","1",0,'C',true);
					$this->Cell(95,$line_height,"Menu","1",0,'C',true);
					$this->Ln();
					$this->SetFont('Arial','',9);
					
					
					unset($task_row_data);
					$tsk_ct=0;
					$query_task = "select * from t_".$key_table_prefix."_event_order_task
							    where etk_status = 'YES'
							    and etk_event_order_id = '".$line["evt_id"]."'
							    ";
				    $query_task = $query_task." order by etk_department_code , etk_default_staff , etk_reminder_date  "; 
				    $result_task = mysqli_query($dbconn,$query_task);
				    while($line_task = mysqli_fetch_array($result_task, MYSQLI_ASSOC))
				    {
					   
					   
					   if($temp_department_code != $line_task["etk_department_code"])
					   {
						   
						   $task_row_data[$tsk_ct]="-----------------------".$line_task["etk_department_code"]."-----------------------";
						   $tsk_ct++;
						    
						    $temp_reminder_date="";
					   }
					   
					   if($temp_reminder_date != $line_task["etk_reminder_date"])
					   {
						   //$task_row_data[$tsk_ct]="Reminder:".$line_task["etk_reminder_date"];
						   //$tsk_ct++;
						   
						   
					   }
					  
					   
					   
						$task_row_data[$tsk_ct] = $line_task["etk_name"];	   
						if($line_task["etk_chargable"]=="YES")
						{
							//$task_row_data[$tsk_ct]=$task_row_data[$tsk_ct]." (".$currency_symbol." ".$line_task["etk_price"].")";
						}
						$tsk_ct++;
							   
						if($line_task["etk_remark"]!="")
						{
							$task_row_data[$tsk_ct]=" - ".$line_task["etk_remark"];
						   	$tsk_ct++;   	
						}
						
						
						
					    
					   
					    $temp_department_code = $line_task["etk_department_code"];
					    $temp_reminder_date = $line_task["etk_reminder_date"];
					   
					   
					   
				    }
				    
				    
				    
				    
				    
					    
					    unset($menu_row_data);
					    $menu_ct=0;
					    $query_menu = "select * from t_".$key_table_prefix."_event_product_menu
								   where  emn_event_id = '".$line["evt_id"]."'
							   order by emn_session_id, emn_mode desc, emn_package_code desc, emn_product_code 
							   ";
				   
					   $result_menu = mysqli_query($dbconn,$query_menu);
					   while($line_menu = mysqli_fetch_array($result_menu, MYSQLI_ASSOC))
					   {
					  
					  
						  if($temp_session != $line_menu["emn_session_id"])
						  {
							  
							  if($temp_session!="")
							  {
								  
								 $menu_row_data[$menu_ct]="";
								 $menu_ct++;
							  }
							  
							  
							 
							
							if($line_menu["emn_session_id"]=="0")
							{
								$menu_row_data[$menu_ct]="-----------------------Main Event-----------------------";
								$menu_ct++;
							}
							else {
								
								$session_date = '';
							 	$query_session="select * from t_".$key_table_prefix."_event_session 
									    where ses_id = '".$line_menu["emn_session_id"]."' ";
							    $result_session = mysqli_query($dbconn,$query_session);
							    if($line_session = mysqli_fetch_array($result_session,MYSQLI_ASSOC))
							    {
								    
								    $session_date = $line_session["ses_date"];
							    }
							    
								$menu_row_data[$menu_ct]="-----------------------".$session_date."-----------------------";
								$menu_ct++;
							}
							  
							
							  
							
							   
							 
						  }
					  
					  
						  if(($temp_package != $line_menu["emn_package_name"])and($line_menu["emn_package_name"]!=""))
						  {
							  
							  $menu_row_data[$menu_ct] = "[".$line_menu["emn_package_name"]." x ".$line_menu["emn_quantity"]."]";	   
							  $menu_ct++;
						  }
						  
					  
				
					  
					  
					  
					  	if($line_menu["emn_mode"]=="STANDARD")
						{
							
							$menu_row_data[$menu_ct] = " - ".$line_menu["emn_product_name"];
						   	$menu_ct++;
						}
						else {
							$menu_row_data[$menu_ct] = $line_menu["emn_product_name"]." x ".$line_menu["emn_quantity"];	   
						   	$menu_ct++;
						}
					   
					    
					    
							  
					   	$temp_session = $line_menu["emn_session_id"];
					   	$temp_package = $line_menu["emn_package_name"];
					   
					  
				   		}
				   
				   
					   if($tsk_ct>$menu_ct)
					   {
						   	$row_limit=$tsk_ct;
						   
					   }
					   else {
					   	$row_limit=$menu_ct;
					   }
						
					for($row=0;$row<=$row_limit+2;$row++)
					{
						
						
						$this->Cell(95,$line_height,$task_row_data[$row],"LR",0,'L',false);
						$this->Cell(95,$line_height,$menu_row_data[$row],"LR",0,'L',false);
						$this->Ln();	
						
						
					}
					
					$this->Cell(95,$line_height,"","BLR",0,'L',false);
					$this->Cell(95,$line_height,"","BLR",0,'L',false);
					$this->Ln();	
					
					
					
					
					
				}
					
				//==========================================================================================================
					
				if($_REQUEST["show_event_change_log"]=="YES")
				{			
					
					
					$this->AddPage('P',"");
					
					$line_height=4;
					
					$this->SetLineWidth(.3);
					$this->SetFillColor(245,245,245);
					$this->SetTextColor(0);
					
					
					$this->SetFillColor(230,230,230);
					
					$this->SetLineWidth(0.2);
					$this->SetFont('Arial','',9);
					
					
					$this->SetFont('Arial','B',10);
					$this->SetFillColor(210,210,210);
					$this->Cell(190,$line_height,"Event Change Log","1",0,'C',true);
					$this->Ln();
					
					
					
					$this->Cell(40,$line_height,"Event Order:","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_doc_no"],"TRB",0,'L',false);
					$this->Cell(40,$line_height,"Event Order Status:","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_status"],"TRB",0,'L',false);
					$this->Ln();		
					
					
					$this->Cell(40,$line_height,"Date","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_start_date"]." to ".$line["evt_end_date"]."","TRB",0,'L',false);
					$this->Cell(95,$line_height,"Organizer: ".$line["evt_customer_name"],"1",0,'L',false);
					$this->Ln();	
					
					
					$exclude_field[0]="id";
					$exclude_field[1]="evt_lock";
					$exclude_field[2]="evt_lock_datetime";
					$exclude_field[3]="modified_date";
					$exclude_field[4]="modified_by";
					
					
					unset($changelog_row_data);
					$chglog_ct=0;
					$query_history="select * from t_".$key_table_prefix."_event_order_history 
							where evt_id = '".$line["evt_id"]."' 
							order by evt_lock_datetime ";
					$result_history = mysqli_query($dbconn,$query_history);
					while($line_history = mysqli_fetch_array($result_history,MYSQLI_ASSOC))
					{
						
						$changelog_row_data[$chglog_ct] = "[Version ".$line_history["evt_lock_datetime"]."]";
						$chglog_ct++;
						
						if(isset($last_array))
						{		
							$diffresult = array_diff($line_history, $last_array);
							
							foreach($diffresult as $diff_key=>$diff_value)
							{
								if(in_array($diff_key,$exclude_field))
								{
									
								}
								else {
									$changelog_row_data[$chglog_ct] = " - ".$diff_key." = ".$diff_value;
									$chglog_ct++;									
								}
								
							}
						}
						
						$last_array = $line_history;
						
					}
					
					
					
					$changelog_row_data[$chglog_ct] = "[Version Current]";
					$chglog_ct++;
					
					if(isset($last_array))
					{		
						$diffresult = array_diff($line, $last_array);
						
						foreach($diffresult as $diff_key=>$diff_value)
						{
							if(in_array($diff_key,$exclude_field))
							{
								
							}
							else {
								$changelog_row_data[$chglog_ct] = " - ".$diff_key." = ".$diff_value;
								$chglog_ct++;									
							}
							
						}
					}
					
					
					$this->SetFont('Arial','',9);
					for($row=0;$row<=$chglog_ct+2;$row++)
					{
						$this->Cell(190,$line_height,$changelog_row_data[$row],"LR",0,'L',false);
						$this->Ln();	
						
					}
					
					
					$this->Cell(190,$line_height,"","BLR",0,'L',false);
					$this->Ln();	
					
					
				}
					
					
					
					
					
					
					
					
					
					
					
					
				//==========================================================================================================
			
				if($_REQUEST["show_menu_change_log"]=="YES")
				{				
						
					$this->AddPage('P',"");
					
					
					$line_height=4;
					
					$this->SetLineWidth(.3);
					$this->SetFillColor(245,245,245);
					$this->SetTextColor(0);
					
					
					$this->SetFillColor(230,230,230);
					
					$this->SetLineWidth(0.2);
					$this->SetFont('Arial','',9);
					
					
					
					$this->SetFont('Arial','B',10);
					$this->SetFillColor(210,210,210);
					$this->Cell(190,$line_height,"Menu Change Log","1",0,'C',true);
					$this->Ln();
					
					
					
					$this->Cell(40,$line_height,"Event Order:","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_doc_no"],"TRB",0,'L',false);
					$this->Cell(40,$line_height,"Event Order Status:","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_status"],"TRB",0,'L',false);
					$this->Ln();		
					
					
					$this->Cell(40,$line_height,"Date","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_start_date"]." to ".$line["evt_end_date"]."","TRB",0,'L',false);
					$this->Cell(95,$line_height,"Organizer: ".$line["evt_customer_name"],"1",0,'L',false);
					$this->Ln();	
					
					
					
					$exclude_field[0]="id";
					$exclude_field[1]="evt_lock";
					$exclude_field[2]="evt_lock_datetime";
					$exclude_field[3]="modified_date";
					$exclude_field[4]="modified_by";
					
					
					unset($menuchangelog_row_data);
					unset($last_array);
					
					$menuchglog_ct=0;
					$query_history="select * from t_".$key_table_prefix."_event_order_history 
							where evt_id = '".$line["evt_id"]."' 
							order by evt_lock_datetime ";
					$result_history = mysqli_query($dbconn,$query_history);
					while($line_history = mysqli_fetch_array($result_history,MYSQLI_ASSOC))
					{
						
						unset($menu_history);
						$menuchglog_ct++;
						$menuchangelog_row_data[$menuchglog_ct] = "[Version ".$line_history["evt_lock_datetime"]."]";
						$menuchglog_ct++;
						
						$query_menu="select * from t_".$key_table_prefix."_event_product_menu_history 
								where emn_event_id = '".$line["evt_id"]."' 
								and emn_lock_datetime = '".$line_history["evt_lock_datetime"]."' 
								order by emn_id  ";
						$result_menu = mysqli_query($dbconn,$query_menu);
						echo mysqli_error($dbconn);
						while($line_menu = mysqli_fetch_array($result_menu,MYSQLI_ASSOC))
						{
							$concat_string = $session_date[$line_menu["emn_session_id"]];
							$concat_string = $concat_string." ".$line_menu["emn_mode"];
							$concat_string = $concat_string." ".$line_menu["emn_package_name"];
							$concat_string = $concat_string." ".$line_menu["emn_product_name"];
							$concat_string = $concat_string." ".$line_menu["emn_product_option_code"];
							$concat_string = $concat_string." ".$line_menu["emn_quantity"];
							
							$menu_history[$concat_string]=$concat_string;
						}
						
						if(isset($last_menu_array))
						{		
						
							
							$diffresult_remove = array_diff( $last_menu_array,$menu_history);	
							foreach($diffresult_remove as $diff_key=>$diff_value)
							{
								$menuchangelog_row_data[$menuchglog_ct] = " - ".$diff_value;
								$menuchglog_ct++;		
							}
							
							$diffresult_added = array_diff($menu_history, $last_menu_array);	
							foreach($diffresult_added as $diff_key=>$diff_value)
							{
								$menuchangelog_row_data[$menuchglog_ct] = " + ".$diff_value;
								$menuchglog_ct++;		
							}
						}
						
						$last_menu_array = $menu_history;
						
					}
					
					
					
					$query_menu="select * from t_".$key_table_prefix."_event_product_menu
							where emn_event_id = '".$line["evt_id"]."' 
							order by emn_id  ";
					$result_menu = mysqli_query($dbconn,$query_menu);
					echo mysqli_error($dbconn);
					while($line_menu = mysqli_fetch_array($result_menu,MYSQLI_ASSOC))
					{
						$concat_string = $session_date[$line_menu["emn_session_id"]];
						$concat_string = $concat_string." ".$line_menu["emn_mode"];
						$concat_string = $concat_string." ".$line_menu["emn_package_name"];
						$concat_string = $concat_string." ".$line_menu["emn_product_name"];
						$concat_string = $concat_string." ".$line_menu["emn_product_option_code"];
						$concat_string = $concat_string." ".$line_menu["emn_quantity"];
						
						$menu_current[$concat_string]=$concat_string;
					}
					
					$menuchglog_ct++;
					$menuchangelog_row_data[$menuchglog_ct] = "[Version Current]";
					$menuchglog_ct++;
					
					if(isset($last_menu_array))
					{		
						
					
						
						$diffresult_remove = array_diff( $last_menu_array,$menu_current);	
						foreach($diffresult_remove as $diff_key=>$diff_value)
						{
							$menuchangelog_row_data[$menuchglog_ct] = " - ".$diff_value;
							$menuchglog_ct++;		
						}
						
						$diffresult_added = array_diff($menu_current, $last_menu_array);	
						foreach($diffresult_added as $diff_key=>$diff_value)
						{
							$menuchangelog_row_data[$menuchglog_ct] = " + ".$diff_value;
							$menuchglog_ct++;		
						}
					}
					
					
					
					$this->SetFont('Arial','',9);
					for($row=0;$row<=$menuchglog_ct+2;$row++)
					{
						$this->Cell(190,$line_height,$menuchangelog_row_data[$row],"LR",0,'L',false);
						$this->Ln();	
						
					}
					
					
					$this->Cell(190,$line_height,"","BLR",0,'L',false);
					$this->Ln();	
					
					
					
					
					
					$this->Ln();
					$this->SetFont('Arial','',9);
					
					
				}
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
				//==========================================================================================================
			
				if($_REQUEST["show_menu_change_memo"]=="YES")
				{				
						
					$this->AddPage('P',"");
					
					
					$line_height=4;
					
					$this->SetLineWidth(.3);
					$this->SetFillColor(245,245,245);
					$this->SetTextColor(0);
					
					
					$this->SetFillColor(230,230,230);
					
					$this->SetLineWidth(0.2);
					$this->SetFont('Arial','',9);
					
					
					
					$this->SetFont('Arial','B',10);
					$this->SetFillColor(210,210,210);
					$this->Cell(190,$line_height,"Menu Change Memo","0",0,'C',false);
					$this->Ln();
					
					
					
					$this->Cell(40,$line_height,"Event Order:","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_doc_no"],"TRB",0,'L',false);
					$this->Cell(40,$line_height,"Event Order Status:","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_status"],"TRB",0,'L',false);
					$this->Ln();		
					
					
					$this->Cell(40,$line_height,"Date","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_start_date"]." to ".$line["evt_end_date"]."","TRB",0,'L',false);
					$this->Cell(95,$line_height,"Organizer: ".$line["evt_customer_name"],"1",0,'L',false);
					$this->Ln();	
					
					
					$this->Ln();
					
					
					
					
					$exclude_field[0]="id";
					$exclude_field[1]="evt_lock";
					$exclude_field[2]="evt_lock_datetime";
					$exclude_field[3]="modified_date";
					$exclude_field[4]="modified_by";
					
					
					unset($menuchangelog_row_data);
					unset($last_array);
					
					unset($last_menu_array);
					
					$query_history="select * from t_".$key_table_prefix."_event_order_history 
							where evt_id = '".$line["evt_id"]."' 
							order by evt_lock_datetime ";
					$result_history = mysqli_query($dbconn,$query_history);
					while($line_history = mysqli_fetch_array($result_history,MYSQLI_ASSOC))
					{
						
						
						unset($menu_history);
						
						$this->Ln();
						$this->Ln();
						$this->SetFont('Arial','',10);
						$this->SetFillColor(210,210,210);
						$this->Cell(190,$line_height,"[Version ".$line_history["evt_lock_datetime"]."]","0",0,'L',false);
						
						$this->Ln();
						
						
						
						$this->SetFont('Arial','B',10);
						$this->SetFillColor(210,210,210);
						$this->Cell(95,$line_height,"Current Arrangement","1",0,'C',true);
						$this->Cell(95,$line_height,"New Arrangement","1",0,'C',true);
						$this->Ln();
						
						unset($menuchangelog_row_data_left);
						unset($menuchangelog_row_data_right);
						
						
						$menuchglog_left_side=0;
						$menuchglog_right_side=0;
						
						$menuchglog_both=0;
						
						
						$query_menu="select * from t_".$key_table_prefix."_event_product_menu_history 
								where emn_event_id = '".$line["evt_id"]."' 
								and emn_lock_datetime = '".$line_history["evt_lock_datetime"]."' 
								order by emn_id  ";
						$result_menu = mysqli_query($dbconn,$query_menu);
						echo mysqli_error($dbconn);
						while($line_menu = mysqli_fetch_array($result_menu,MYSQLI_ASSOC))
						{
							
							
							
							$concat_string = $session_date[$line_menu["emn_session_id"]];
							$concat_string = $concat_string." ".$line_menu["emn_mode"];
							$concat_string = $concat_string." ".$line_menu["emn_package_name"];
							$concat_string = $concat_string." ".$line_menu["emn_product_name"];
							$concat_string = $concat_string." ".$line_menu["emn_product_option_code"];
							$concat_string = $concat_string." x ".$line_menu["emn_quantity"];
							
							$menu_history[$concat_string]=$concat_string;
						}
						
						if(isset($last_menu_array))
						{		
						
							$diffresult_remove = array_diff( $last_menu_array,$menu_history);	
							foreach($diffresult_remove as $diff_key=>$diff_value)
							{
								$menuchangelog_row_data_left[$menuchglog_left_side] = " - ".$diff_value;
								$menuchglog_left_side++;		
								
							}
							
							$diffresult_added = array_diff($menu_history, $last_menu_array);	
							foreach($diffresult_added as $diff_key=>$diff_value)
							{
								$menuchangelog_row_data_right[$menuchglog_right_side] = " + ".$diff_value;
								$menuchglog_right_side++;		
								
							}
							
						}
						
						
						if($menuchglog_left_side>$menuchglog_right_side)
						{
							$menuchglog_both=$menuchglog_left_side;
						}
						else {
							$menuchglog_both=$menuchglog_right_side;
						}
						
						unset($last_menu_array);
						$last_menu_array = $menu_history;
						
						
						
						
						$this->SetFont('Arial','',9);
						for($row=0;$row<=$menuchglog_both;$row++)
						{
							
							$this->SetFont('Arial','',7);
							$this->SetFillColor(210,210,210);
							$this->Cell(95,$line_height,$menuchangelog_row_data_left[$row],"LR",0,'L',false);
							$this->Cell(95,$line_height,$menuchangelog_row_data_right[$row],"LR",0,'L',false);
							$this->Ln();
							
						}
						
						
						$this->Cell(190,$line_height,"","T",0,'C',false);
						$this->Ln();
						
						
					
						
						
						
						
						
						
					}
					
					
					unset($menu_current);
					
					$query_menu="select * from t_".$key_table_prefix."_event_product_menu
							where emn_event_id = '".$line["evt_id"]."' 
							order by emn_id  ";
					$result_menu = mysqli_query($dbconn,$query_menu);
					echo mysqli_error($dbconn);
					while($line_menu = mysqli_fetch_array($result_menu,MYSQLI_ASSOC))
					{
						$concat_string = $session_date[$line_menu["emn_session_id"]];
						$concat_string = $concat_string." ".$line_menu["emn_mode"];
						$concat_string = $concat_string." ".$line_menu["emn_package_name"];
						$concat_string = $concat_string." ".$line_menu["emn_product_name"];
						$concat_string = $concat_string." ".$line_menu["emn_product_option_code"];
						$concat_string = $concat_string." x ".$line_menu["emn_quantity"];
						
						$menu_current[$concat_string]=$concat_string;
						
						
					}
					
					unset($diffresult_remove);
					unset($diffresult_added);
					
					unset($menuchangelog_row_data_left);
					unset($menuchangelog_row_data_right);
					
					
					$menuchglog_left_side=0;
					$menuchglog_right_side=0;
					
					$menuchglog_both=0;
					
					if(isset($last_menu_array))
					{		
						
						
						
						
					
						$diffresult_remove = array_diff($last_menu_array,$menu_current);	
						foreach($diffresult_remove as $diff_key=>$diff_value)
						{
							$menuchangelog_row_data_left[$menuchglog_left_side] = " - ".$diff_value;
							$menuchglog_left_side++;		
							
						}
						
						$diffresult_added = array_diff($menu_current, $last_menu_array);	
						foreach($diffresult_added as $diff_key=>$diff_value)
						{
							$menuchangelog_row_data_right[$menuchglog_right_side] = " + ".$diff_value;
							$menuchglog_right_side++;		
							
						}
						
					}
					
					
					if($menuchglog_left_side>$menuchglog_right_side)
					{
						$menuchglog_both=$menuchglog_left_side;
					}
					else {
						$menuchglog_both=$menuchglog_right_side;
					}
					
					
					
					$this->Ln();
					$this->Ln();
					$this->SetFont('Arial','',10);
					$this->SetFillColor(210,210,210);
					$this->Cell(190,$line_height,"[Current Version]","0",0,'L',false);
					
					$this->Ln();
					
					
					
					$this->SetFont('Arial','B',10);
					$this->SetFillColor(210,210,210);
					$this->Cell(95,$line_height,"Current Arrangement","1",0,'C',true);
					$this->Cell(95,$line_height,"New Arrangement","1",0,'C',true);
					$this->Ln();
					
					
					$this->SetFont('Arial','',9);
					for($row=0;$row<=$menuchglog_both;$row++)
					{
						
						$this->SetFont('Arial','',7);
						$this->SetFillColor(210,210,210);
						$this->Cell(95,$line_height,$menuchangelog_row_data_left[$row],"LR",0,'L',false);
						$this->Cell(95,$line_height,$menuchangelog_row_data_right[$row],"LR",0,'L',false);
						$this->Ln();
						
					}
					
					
					$this->Cell(190,$line_height,"","T",0,'C',false);
					$this->Ln();
					
					
					
					
					
					
					
					$this->Ln();
					$this->SetFont('Arial','',9);
					
					
				}
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
					
				//==========================================================================================================
			
			
				if($_REQUEST["show_material_usage"]=="YES")
				{			
							
					$this->AddPage('P',"");
					
					$line_height=4;
					
					$this->SetLineWidth(.3);
					$this->SetFillColor(245,245,245);
					$this->SetTextColor(0);
					
					
					$this->SetFillColor(230,230,230);
					
					$this->SetLineWidth(0.2);
					$this->SetFont('Arial','',9);
					
					
					$this->SetFont('Arial','B',10);
					$this->SetFillColor(210,210,210);
					$this->Cell(190,$line_height,"Material Usage","1",0,'C',true);
					$this->Ln();
					
					
					
					
					$this->Cell(40,$line_height,"Event Order:","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_doc_no"],"TRB",0,'L',false);
					$this->Cell(40,$line_height,"Event Order Status:","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_status"],"TRB",0,'L',false);
					$this->Ln();		
					
					
					$this->Cell(40,$line_height,"Date","1",0,'L',true);
					$this->Cell(5,$line_height,":","TBL",0,'c',false);
					$this->Cell(50,$line_height,"".$line["evt_start_date"]." to ".$line["evt_end_date"]."","TRB",0,'L',false);
					$this->Cell(95,$line_height,"Organizer: ".$line["evt_customer_name"],"1",0,'L',false);
					$this->Ln();	
					
					
					$this->Ln();	
					$this->Ln();	
					
					
					
					
					$this->SetFont('Arial','B',10);
					$this->Cell(190,$line_height,"Main Session","TLR",0,'L',false);
					$this->Ln();	
				    
				    
				    
					$this->SetFont('Arial','B',9);
 				    
 				    $this->Cell(20,$line_height,"Code","1",0,'L',false);
 				    $this->Cell(80,$line_height,"Material Name","1",0,'L',false);
 				    $this->Cell(30,$line_height,"Unit Cost","1",0,'R',false);
 				    $this->Cell(30,$line_height,"Quantity","1",0,'R',false);
 				    $this->Cell(30,$line_height,"Total Cost","1",0,'R',false);
 				    $this->Ln();	
				    
				    
					
					$query_material="select * from t_".$key_table_prefix."_event_material_usage
							where emu_event_id = '".$line["evt_id"]."' 
							and emu_session_id = '0' 
							order by emu_id ";
					$result_material = mysqli_query($dbconn,$query_material);
					while($line_material = mysqli_fetch_array($result_material,MYSQLI_ASSOC))
					{
						$this->SetFont('Arial','',9);
						
						$this->Cell(20,$line_height,$line_material["emu_material_code"],"1",0,'L',false);
						$this->Cell(80,$line_height,$line_material["emu_material_name"],"1",0,'L',false);
						$this->Cell(30,$line_height,number_format($line_material["emu_unit_cost"],2,".","."),"1",0,'R',false);
						$this->Cell(30,$line_height,number_format($line_material["emu_quantity"],2,".","."),"1",0,'R',false);
						$this->Cell(30,$line_height,number_format($line_material["emu_total_cost"],2,".","."),"1",0,'R',false);
						
						$this->Ln();	
						
					}
					
					$this->Cell(190,$line_height,"","LR",0,'L',false);
					$this->Ln();
					
					
					
					$this->SetFont('Arial','',9);
					$query_session="select * from t_".$key_table_prefix."_event_session 
					    where ses_event_id = '".$_REQUEST["evt_id"]."' ";
				     $result_session = mysqli_query($dbconn,$query_session);
					echo mysqli_error($dbconn);
				     while($line_session = mysqli_fetch_array($result_session,MYSQLI_ASSOC))
				     {
						$this->SetFont('Arial','B',10);
						$this->Cell(190,$line_height,"Session Date: ".$line_session["ses_date"],"TLR",0,'L',false);
						$this->Ln();	
					    
					    
						$this->SetFont('Arial','B',9);
						   
						   $this->Cell(20,$line_height,"Code","1",0,'L',false);
						   $this->Cell(80,$line_height,"Material Name","1",0,'L',false);
						   $this->Cell(30,$line_height,"Unit Cost","1",0,'R',false);
						   $this->Cell(30,$line_height,"Quantity","1",0,'R',false);
						   $this->Cell(30,$line_height,"Total Cost","1",0,'R',false);
						   $this->Ln();	
						   
						   
						
   	  					$query_material="select * from t_".$key_table_prefix."_event_material_usage
   	  							where emu_event_id = '".$line["evt_id"]."' 
								and emu_session_id = '".$line_session["ses_id"]."' 
   	  							order by emu_id ";
   	  					$result_material = mysqli_query($dbconn,$query_material);
   	  					while($line_material = mysqli_fetch_array($result_material,MYSQLI_ASSOC))
   	  					{
							
						
							$this->SetFont('Arial','',9);
   	  						
							$this->Cell(20,$line_height,$line_material["emu_material_code"],"1",0,'L',false);
							$this->Cell(80,$line_height,$line_material["emu_material_name"],"1",0,'L',false);
							$this->Cell(30,$line_height,number_format($line_material["emu_unit_cost"],2,".","."),"1",0,'R',false);
							$this->Cell(30,$line_height,number_format($line_material["emu_quantity"],2,".","."),"1",0,'R',false);
							$this->Cell(30,$line_height,number_format($line_material["emu_total_cost"],2,".","."),"1",0,'R',false);
							
							
   	  						$this->Ln();	
   	  						
   	  					}
						
						$this->Cell(190,$line_height,"","LR",0,'L',false);
						$this->Ln();
					    
				     }
				    
				    
				    
				
				
					
				
					$this->Cell(190,$line_height,"","BLR",0,'L',false);
					$this->Ln();	
					
					
					$this->Ln();
					$this->SetFont('Arial','',9);
					
				}	
					
				//=============================================================================================	
					
					
					
					
					
					
					
					
					
					
					
			
			}
		
		
		
			
		}

}

//Instanciation of inherited class


$pdf=new PDF();

$pdf->AliasNbPages();

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





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


?>