<?php

      include "../include/mysql.php";

        include "../include/common.php";

		 extract($_REQUEST);

        $exp=explode("***",$val);

        $itemid=$exp[0];

        $fdate=date("Y-m-d",strtotime($exp[1]));

        $tdate=date("Y-m-d",strtotime($exp[2]));

		$fdateDisplay=date("d/m/Y",strtotime($exp[1]));

		$tdateDisplay=date("d/m/Y",strtotime($exp[2]));

			$tcondn=" where tid='$itemid'";

						$TMDetails=$db->select(TM,"*",$tcondn);

						$TMDetails_Fetch=$db->fetch($TMDetails);

						$tickName=$TMDetails_Fetch["tname_tam"];

		
     $getCategoryCondn=" where tid='$itemid'";
						
						$getCategoryInfo=$db->select(TM,"*",$getCategoryCondn);

						$getCategoryInfoFetch=$db->fetch($getCategoryInfo);

						$ticketcategory=$getCategoryInfoFetch["ticketcategory"];

			$table="<table style='width:100%;'><tr><td align='center'><b><span>அருள்மிகு மீனாட்சி சுந்தரேசுவரர் திருக்கோவில் <br>மதுரை</span> </b></td></tr><tr><td align='center'><b><span>ADVANCED BOOKING FUNCTION REPORT</span></b></td></tr><tr><td align='center'><b><span>$fdateDisplay To  $tdateDisplay</span></b></td></tr><tr><td align='center'><b>$tickName</b></td></tr></table><br />";	

           	 $table=$table."<table id='$field_display_table' width='850px;'  border='0' class='price1' cellpadding='8' cellspacing='6' style='border-collapse:collapse;'>
											<col style='width: 20%' class='col1'>
											<col style='width: 20%'>
											<col style='width: 20%'>
											<col style='width: 20%'>
											<col style='width: 20%'>	
											<col style='width: 20%'>	
											<col style='width: 20%'>
											<col style='width: 20%'>	
											<col style='width: 20%'>	
										  <thead>			
												<tr>
													<th align='right' class='pdftbl' style='text-align:right;' width='12%'>TMR No.</th>

													<th align='right' class='pdftbl' style='text-align:right;'>TktNo.</th>

													<th align='left' class='pdftbl' style='text-align:left;'>Issue Date</th>
													<th align='left' class='pdftbl' style='text-align:left;'>Category</th>
											
													<th align='left' class='pdftbl' style='text-align:left;'>Contact Details</th>";
if($ticketcategory==3)
{

$table=$table."<th align='left' class='pdftbl' style='text-align:left;'>Details</th><th align='left' class='pdftbl' style='text-align:left;' >User</th>";
}
else
{
		$table=$table."<th align='left' class='pdftbl' style='text-align:left;'>Function</th><th align='right' class='pdftbl' style='text-align:right;'>User</th><th align='right' class='pdftbl' style='text-align:right;' >Amount</th>";
													
}													
													$table=$table."</thead>";

				if($itemid=="All")
				{
			
					$cashdateCondn=" where bdate between '$fdate' and '$tdate' and  (cancel='0' or cancel is NULL) order by bdate";


				}
				else
				{
						
						
						if($ticketcategory==3)
					{

						$cashdateCondn=" where created_date between '$fdate' and '$tdate' and tid='$itemid' and (cancel='0' or cancel is NULL) order by bdate";


					}
					else
					{
							$cashdateCondn=" where bdate between '$fdate' and '$tdate' and tid='$itemid' and (cancel='0' or cancel is NULL) order by bdate";
					}

				}



			$getOverAllTotalDetails=$db->select(AB,"sum(rate)",$cashdateCondn);
		
			$getOverAllTotalDetailsFetch=$db->fetch($getOverAllTotalDetails);

			$overAllTotalCash=$getOverAllTotalDetailsFetch[0];

			$getdetails_code=$db->select(AB,"*",$cashdateCondn);

			while($getdetails_fetch=$db->fetch($getdetails_code))
            {
				
						$tmrno=$getdetails_fetch["tmrno"];

						$ticketno=$getdetails_fetch["ticketno"];

						$created_date=date("d-m-Y",strtotime($getdetails_fetch["created_date"]));

						
						if($getdetails_fetch["bdate"]=="")
				{
						$b_date=$created_date;
				}
				else
				{
					$b_date=date("d-m-Y",strtotime($getdetails_fetch["bdate"]));
				}

						$created_time=$getdetails_fetch["created_time"];

						$tid=$getdetails_fetch["tid"];

						$name=$getdetails_fetch["name"];

						$address=stripslashes($getdetails_fetch["address"]);

						$mobileno=$getdetails_fetch["mobileno"];

						$description=stripslashes($getdetails_fetch["description"]);

						$rate=$getdetails_fetch["rate"];

						$advbooktype=$getdetails_fetch["advbooktype"];

						$created_by=$getdetails_fetch["created_by"];

						$tmid=$getdetails_fetch["tmid"];

						$ucondn=" where aid='$created_by'"; 	

						$getuser=$db->select(ADMIN,"*",$ucondn);

						$getuserFetch=$db->fetch($getuser);

						$anameUser=$getuserFetch["aname"]; 
						
						

						$timCondn=" where tmid='$tmid'";

						$getTime=$db->select(TMM,"*",$timCondn);

						$getTimeFetch=$db->fetch($getTime);

						$timeval=$getTimeFetch["timeval"];

						if($advbooktype==1)
						{
							
							$cat="Annathanam";

						}
						else if($advbooktype==2)
						{
							
							$cat="General";

						}
						else if($advbooktype==3)
						{
							
							$cat="Kanikai";

						}
						else if($advbooktype==4)
						{

							$cat="Prasatha Kanikai";
						}
				
					

						$cinfo=$name."<br>".$address."<br>".$mobileno;
					
						$table=$table."<tr><td align='right' valign='top'>$tmrno</td><td align='right' valign='top'>$ticketno</td><td valign='top'>$created_date<br>$created_time</td><td valign='top'>$cat</td><td valign='top'>$cinfo</td>";
					if($ticketcategory==3)
{
							$table=$table."<td valign='top'>$description</td><td valign='top'>$anameUser</td>";
}	
else
				{
$table=$table."<td valign='top'>$b_date<br>$timeval</td><td valign='top'>$anameUser</td><td align='right' valign='top'>$rate</td>";
				}
						$table=$table."</tr>";

			}

			if($ticketcategory==3)
			{
				$table=$table."</table><br><br><br><table border='0' width='100%' style='font-weight:bold'><tr><td align='center'>உதவியாளர்</td><td align='center'>பேஷ்கார்</td><td align='center'>கண்காணிப்பாளர்</td></tr></table><br><br><table border='0' width='100%' style='font-weight:bold'><tr><td align='right'>கணக்காளர்</td><td align='right'>முதுநிலை கணக்கு அலுவலர்</td><td align='right'>இணை ஆணையர் / நிர்வாக அதிகாரி</td></tr></table>";  	
				

			}
			else
			{
				$table=$table."<tr><td colspan='7' align='right'><b>Total</b></td><td align='right'><b>$overAllTotalCash</b></td></tr></table><br><br><br><table border='0' width='100%' style='font-weight:bold'><tr><td align='center'>உதவியாளர்</td><td align='center'>பேஷ்கார்</td><td align='center'>கண்காணிப்பாளர்</td></tr></table><br><br><table border='0' width='100%' style='font-weight:bold'><tr><td align='right'>கணக்காளர்</td><td align='right'>முதுநிலை கணக்கு அலுவலர்</td><td align='right'>இணை ஆணையர் / நிர்வாக அதிகாரி</td></tr></table>";
			}	
				

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

include("mpdf.php");

$mpdf=new mPDF(); 

$mpdf->SetDefaultFontSize("12");
$mpdf->useAdobeCJK = true;		// Default setting in config.php
						// You can set this to false if you have defined other CJK fonts

$mpdf->SetAutoFont(AUTOFONT_ALL);	//	AUTOFONT_CJK | AUTOFONT_THAIVIET | AUTOFONT_RTL | AUTOFONT_INDIC	// AUTOFONT_ALL
						// () = default ALL, 0 turns OFF (default initially)

//$mpdf->mirrorMargins = 1;


/*$mpdf->pagenumPrefix = 'Page number ';
$mpdf->pagenumSuffix = ' - ';
$mpdf->nbpgPrefix = ' out of ';
$mpdf->nbpgSuffix = ' pages';

$mpdf->SetFooter('{PAGENO}{nbpg}');*/

$mpdf->WriteHTML($table);

$mpdf->Output(); 

exit;
//==============================================================
//==============================================================
//==============================================================


?>