<?php

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

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

		 extract($_REQUEST);

        //echo $val;

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

      
			$icondn=" where booking_type='1'";

			$table="<table style='width:100%;'><tr><td align='center'><b><span>அருள்மிகு மீனாட்சி சுந்தரேசுவரர் திருக்கோவில் <br>மதுரை</span> </b></td></tr><tr><td align='center'><b><span>CURRENT BOOKING CONSOLIDATED DATEWISE REPORT</span></b></td></tr><tr><td align='center'><b><span>$fdateDisplay To  $tdateDisplay</span></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%'>	
										  <thead>			
												<tr>
																									
													<th align='left' class='pdftbl' style='text-align:left;'>TicketName</th>

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

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

													<th align='right' class='pdftbl' style='text-align:right;'>End No.</th>
													
													<th align='right' class='pdftbl' style='text-align:right;'>Sold</th>
												
													<th align='right' class='pdftbl' style='text-align:right;'>Total</th>
																								
													</thead>";

			$cashCondn=" where booking_date between '$fdate' and '$tdate'";	

			$getOverAllTotalDetails=$db->select(CB,"sum(amount)",$cashCondn);
		
			$getOverAllTotalDetailsFetch=$db->fetch($getOverAllTotalDetails);

			$overAllTotal=$getOverAllTotalDetailsFetch[0];

			

			$getdetails_code=$db->select(TM,"*",$icondn);
			
            while($getdetails_fetch=$db->fetch($getdetails_code))
            {
   
						$ticketName=$getdetails_fetch["tname_tam"];

						$ticketId=$getdetails_fetch["tid"];

						$getSoldInfoCondn=" where tid='$ticketId' and booking_date between '$fdate' and '$tdate'";

					
						$getSoldInfo=$db->select(CB,"sum(qty)",$getSoldInfoCondn);

						$getSoldInfoFetch=$db->fetch($getSoldInfo);

						$sold=$getSoldInfoFetch[0];

						if($sold=="")
				{
		
						$sold=0;

				}

						$priceCondn=" where tid='$ticketId' order by lastupdated_date desc";

						$getrateFromMaster=$db->select(TR,"*",$priceCondn);

						$getrateFromMasterFetch=$db->fetch($getrateFromMaster);

						$displayPrice=$getrateFromMasterFetch["rate"];

						$getrateInfo=$db->select(CB,"rate",$getSoldInfoCondn);

						$getrateInfoFetch=$db->fetch($getrateInfo);

						$rate=$getrateInfoFetch[0];

						if($rate=="")
				{

						$price=$displayPrice;	

				}
				else
				{

						$price=$rate;	
				}

						



						if($sold==0)
						{

							$nextStartNoCondn=" where tid='$ticketId'";
							
							$getnextStartNo=$db->select(CB,"max(end_no)",$nextStartNoCondn);

							$getnextStartNoFetch=$db->fetch($getnextStartNo);

							$getnextStartNo=$getnextStartNoFetch[0]+1;

							$startNo=$getnextStartNo;

							$endNo="";

						}
						else
						{
								
	$getStartEndInfo=$db->select(CB,"min(start_no),max(end_no)",$getSoldInfoCondn);

								$getStartEndInfoFetch=$db->fetch($getStartEndInfo);

								$startNo=$getStartEndInfoFetch[0];

								$endNo=$getStartEndInfoFetch[1];

						}

						$totalAmt=$sold*$price;
							
						$totalAmt=number_format($totalAmt,2);

						$table=$table."<tr><td>$ticketName</td><td align='right'>$price</td><td align='right'>$startNo</td><td align='right'>$endNo</td><td align='right'>$sold</td><td align='right'>$totalAmt</td></tr>";
			
   
            }

						

						$overAllTotal=number_format($overAllTotal,2);
			
				$table=$table."<tr><td colspan='5' align='right'>Total</td><td align='right'>$overAllTotal</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('', 'A4-L', 0, '', 12.7, 12.7, 14, 12.7, 8, 8);
$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;
//==============================================================
//==============================================================
//==============================================================


?>